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_VM_JFR_RECORDER_CHECKPOINT_JFRCHECKPOINTWRITER_HPP 26 #define SHARE_VM_JFR_RECORDER_CHECKPOINT_JFRCHECKPOINTWRITER_HPP 27 28 #include "jfr/recorder/checkpoint/jfrCheckpointBlob.hpp" 29 #include "jfr/utilities/jfrTraceTime.hpp" 30 #include "jfr/writers/jfrEventWriterHost.inline.hpp" 31 #include "jfr/writers/jfrMemoryWriterHost.inline.hpp" 32 #include "jfr/writers/jfrStorageAdapter.hpp" 33 #include "tracefiles/traceTypes.hpp" 34 35 class Thread; 36 37 class JfrCheckpointFlush : public StackObj { 38 public: 39 typedef JfrBuffer Type; 40 JfrCheckpointFlush(Type* old, size_t used, size_t requested, Thread* t); 41 Type* result() { return _result; } 42 private: 43 Type* _result; 44 }; 45 46 typedef Adapter<JfrCheckpointFlush> JfrCheckpointAdapter; 47 typedef AcquireReleaseMemoryWriterHost<JfrCheckpointAdapter, StackObj > JfrTransactionalCheckpointWriter; 48 typedef EventWriterHost<BigEndianEncoder, CompressedIntegerEncoder, JfrTransactionalCheckpointWriter> JfrCheckpointWriterBase; 49 50 struct JfrCheckpointContext { 51 jlong offset; 52 juint count; 53 }; 54 55 class JfrCheckpointWriter : public JfrCheckpointWriterBase { 56 friend class JfrSerializerRegistration; 57 private: 58 JfrTraceTime _time; 59 jlong _offset; 60 juint _count; 61 bool _flushpoint; 62 bool _header; 63 64 juint count() const; 65 void set_count(juint count); 66 void increment(); 67 void set_flushpoint(bool flushpoint); 68 bool is_flushpoint() const; 69 const u1* session_data(size_t* size, const JfrCheckpointContext* ctx = NULL); 70 void release(); 71 72 public: 73 JfrCheckpointWriter(bool flushpoint, bool header, Thread* thread); 74 ~JfrCheckpointWriter(); 75 void write_constant_type(JfrConstantTypeId constant_type_id); 76 void write_number_of_constants(u4 nof_entries); 77 void write_number_of_constants(u4 nof_entries, jlong offset); 78 void write_key(u8 key); 79 const JfrCheckpointContext context() const; 80 void set_context(const JfrCheckpointContext ctx); 81 bool has_data() const; 82 JfrCheckpointBlobHandle checkpoint_blob(); 83 JfrCheckpointBlobHandle copy(const JfrCheckpointContext* ctx = NULL); 84 JfrCheckpointBlobHandle move(const JfrCheckpointContext* ctx = NULL); 85 }; 86 87 #endif // SHARE_VM_JFR_RECORDER_CHECKPOINT_JFRCHECKPOINTWRITER_HPP