Path: blob/master/src/hotspot/share/jfr/writers/jfrEncoding.hpp
41149 views
/*1* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_JFR_WRITERS_JFRENCODING_HPP25#define SHARE_JFR_WRITERS_JFRENCODING_HPP2627#include "jfr/writers/jfrEncoders.hpp"28#include "memory/allocation.hpp"29#include "utilities/globalDefinitions.hpp"3031enum JfrStringEncoding {32NULL_STRING = 0,33EMPTY_STRING,34STRING_CONSTANT,35UTF8,36UTF16,37LATIN1,38NOF_STRING_ENCODINGS39};4041template <typename IntegerEncoder, typename BaseEncoder>42class EncoderHost : public AllStatic {43public:44template <typename T>45static u1* be_write(T value, u1* pos) {46return be_write(&value, 1, pos);47}4849template <typename T>50static u1* be_write(const T* value, size_t len, u1* pos) {51assert(value != NULL, "invariant");52assert(pos != NULL, "invariant");53assert(len > 0, "invariant");54return pos + BaseEncoder::encode(value, len, pos);55}5657template <typename T>58static u1* write_padded(T value, u1* pos) {59assert(pos != NULL, "invariant");60return write_padded(&value, 1, pos);61}6263template <typename T>64static u1* write_padded(const T* value, size_t len, u1* pos) {65assert(value != NULL, "invariant");66assert(pos != NULL, "invariant");67assert(len > 0, "invariant");68return pos + IntegerEncoder::encode_padded(value, len, pos);69}7071template <typename T>72static u1* write(T value, u1* pos) {73return write(&value, 1, pos);74}7576template <typename T>77static u1* write(const T* value, size_t len, u1* pos) {78assert(value != NULL, "invariant");79assert(pos != NULL, "invariant");80assert(len > 0, "invariant");81return pos + IntegerEncoder::encode(value, len, pos);82}8384static u1* write(bool value, u1* pos) {85return be_write((u1)value, pos);86}8788static u1* write(float value, u1* pos) {89return be_write(*(u4*)&(value), pos);90}9192static u1* write(double value, u1* pos) {93return be_write(*(u8*)&(value), pos);94}9596static u1* write(const char* value, u1* pos) {97u2 len = 0;98if (value != NULL) {99len = MIN2<u2>(max_jushort, (jushort)strlen(value));100}101pos = write(len, pos);102if (len > 0) {103pos = be_write(value, len, pos);104}105return pos;106}107108static u1* write(char* value, u1* pos) {109return write(const_cast<const char*>(value), pos);110}111};112113typedef EncoderHost<BigEndianEncoderImpl, BigEndianEncoderImpl> BigEndianEncoder;114typedef EncoderHost<Varint128EncoderImpl, BigEndianEncoderImpl> CompressedIntegerEncoder;115116#endif // SHARE_JFR_WRITERS_JFRENCODING_HPP117118119