| 1 | /* |
| 2 | * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | * accompanied this code). |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License version |
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | * or visit www.oracle.com if you need additional information or have any |
| 21 | * questions. |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #ifndef SHARE_JFR_WRITERS_JFRWRITERHOST_HPP |
| 26 | #define SHARE_JFR_WRITERS_JFRWRITERHOST_HPP |
| 27 | |
| 28 | #include "jni.h" |
| 29 | #include "utilities/globalDefinitions.hpp" |
| 30 | #include "jfr/utilities/jfrTime.hpp" |
| 31 | |
| 32 | class ClassLoaderData; |
| 33 | class Klass; |
| 34 | class Method; |
| 35 | class ModuleEntry; |
| 36 | class PackageEntry; |
| 37 | class Symbol; |
| 38 | class Thread; |
| 39 | |
| 40 | // BE == Base Encoder |
| 41 | // IE == Integer Encoder |
| 42 | template <typename BE, typename IE, typename WriterPolicyImpl > |
| 43 | class WriterHost : public WriterPolicyImpl { |
| 44 | private: |
| 45 | const bool _compressed_integers; |
| 46 | |
| 47 | template <typename T> |
| 48 | void write_padded(T value); |
| 49 | template <typename T> |
| 50 | void write_padded(const T* value, size_t len); |
| 51 | template <typename T> |
| 52 | u1* write_padded(const T* value, size_t len, u1* pos); |
| 53 | template <typename T> |
| 54 | void write(const T* value, size_t len); |
| 55 | template <typename T> |
| 56 | u1* write(const T* value, size_t len, u1* pos); |
| 57 | void write_utf8(const char* value); |
| 58 | void write_utf16(const jchar* value, jint len); |
| 59 | |
| 60 | protected: |
| 61 | template <typename T> |
| 62 | void be_write(T value); |
| 63 | template <typename T> |
| 64 | void be_write(const T* value, size_t len); |
| 65 | template <typename StorageType> |
| 66 | WriterHost(StorageType* storage, Thread* thread); |
| 67 | template <typename StorageType> |
| 68 | WriterHost(StorageType* storage, size_t size); |
| 69 | WriterHost(Thread* thread); |
| 70 | u1* ensure_size(size_t requested_size); |
| 71 | |
| 72 | public: |
| 73 | template <typename T> |
| 74 | void write(T value); |
| 75 | void write(bool value); |
| 76 | void write(float value); |
| 77 | void write(double value); |
| 78 | void write(const char* value); |
| 79 | void write(char* value); |
| 80 | void write(jstring value); |
| 81 | void write(const ClassLoaderData* cld); |
| 82 | void write(const Klass* klass); |
| 83 | void write(const Method* method); |
| 84 | void write(const ModuleEntry* module); |
| 85 | void write(const PackageEntry* package); |
| 86 | void write(const Symbol* symbol); |
| 87 | void write(const Ticks& time); |
| 88 | void write(const Tickspan& time); |
| 89 | void write(const JfrTicks& time); |
| 90 | void write(const JfrTickspan& time); |
| 91 | void bytes(const void* buf, size_t len); |
| 92 | void write_utf8_u2_len(const char* value); |
| 93 | template <typename T> |
| 94 | void write_padded_at_offset(T value, int64_t offset); |
| 95 | template <typename T> |
| 96 | void write_at_offset(T value, int64_t offset); |
| 97 | template <typename T> |
| 98 | void write_be_at_offset(T value, int64_t offset); |
| 99 | int64_t reserve(size_t size); |
| 100 | }; |
| 101 | |
| 102 | #endif // SHARE_JFR_WRITERS_JFRWRITERHOST_HPP |
| 103 | |