equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. |
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. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
23 */ |
23 */ |
24 |
24 |
25 #include "precompiled.hpp" |
25 #include "precompiled.hpp" |
26 #include "jfr/recorder/checkpoint/jfrCheckpointManager.hpp" |
26 #include "jfr/recorder/checkpoint/jfrCheckpointManager.hpp" |
27 #include "jfr/recorder/checkpoint/jfrCheckpointWriter.hpp" |
27 #include "jfr/recorder/checkpoint/jfrCheckpointWriter.hpp" |
|
28 #include "jfr/utilities/jfrBlob.hpp" |
28 #include "jfr/writers/jfrBigEndianWriter.hpp" |
29 #include "jfr/writers/jfrBigEndianWriter.hpp" |
29 |
30 |
30 JfrCheckpointFlush::JfrCheckpointFlush(Type* old, size_t used, size_t requested, Thread* t) : |
31 JfrCheckpointFlush::JfrCheckpointFlush(Type* old, size_t used, size_t requested, Thread* t) : |
31 _result(JfrCheckpointManager::flush(old, used, requested, t)) {} |
32 _result(JfrCheckpointManager::flush(old, used, requested, t)) {} |
32 |
33 |
124 |
125 |
125 void JfrCheckpointWriter::write_count(u4 nof_entries, int64_t offset) { |
126 void JfrCheckpointWriter::write_count(u4 nof_entries, int64_t offset) { |
126 write_padded_at_offset(nof_entries, offset); |
127 write_padded_at_offset(nof_entries, offset); |
127 } |
128 } |
128 |
129 |
129 const u1* JfrCheckpointWriter::session_data(size_t* size, const JfrCheckpointContext* ctx /* 0 */) { |
130 const u1* JfrCheckpointWriter::session_data(size_t* size, bool move /* false */, const JfrCheckpointContext* ctx /* 0 */) { |
130 assert(this->is_acquired(), "wrong state!"); |
131 assert(this->is_acquired(), "wrong state!"); |
131 if (!this->is_valid()) { |
132 if (!this->is_valid()) { |
132 *size = 0; |
133 *size = 0; |
133 return NULL; |
134 return NULL; |
134 } |
135 } |
138 return session_start_pos; |
139 return session_start_pos; |
139 } |
140 } |
140 *size = this->used_size(); |
141 *size = this->used_size(); |
141 assert(this->start_pos() + *size == this->current_pos(), "invariant"); |
142 assert(this->start_pos() + *size == this->current_pos(), "invariant"); |
142 write_checkpoint_header(const_cast<u1*>(this->start_pos()), this->used_offset(), _time, is_flushpoint(), count()); |
143 write_checkpoint_header(const_cast<u1*>(this->start_pos()), this->used_offset(), _time, is_flushpoint(), count()); |
143 this->seek(_offset + (_header ? sizeof(JfrCheckpointEntry) : 0)); |
144 _header = false; // the header was just written |
144 set_count(0); |
145 if (move) { |
|
146 this->seek(_offset); |
|
147 } |
145 return this->start_pos(); |
148 return this->start_pos(); |
146 } |
149 } |
147 |
150 |
148 const JfrCheckpointContext JfrCheckpointWriter::context() const { |
151 const JfrCheckpointContext JfrCheckpointWriter::context() const { |
149 JfrCheckpointContext ctx; |
152 JfrCheckpointContext ctx; |
158 } |
161 } |
159 bool JfrCheckpointWriter::has_data() const { |
162 bool JfrCheckpointWriter::has_data() const { |
160 return this->used_size() > sizeof(JfrCheckpointEntry); |
163 return this->used_size() > sizeof(JfrCheckpointEntry); |
161 } |
164 } |
162 |
165 |
163 JfrCheckpointBlobHandle JfrCheckpointWriter::checkpoint_blob() { |
166 JfrBlobHandle JfrCheckpointWriter::copy(const JfrCheckpointContext* ctx /* 0 */) { |
164 size_t size = 0; |
167 size_t size = 0; |
165 const u1* data = session_data(&size); |
168 const u1* data = session_data(&size, false, ctx); |
166 return JfrCheckpointBlob::make(data, size); |
169 return JfrBlob::make(data, size); |
167 } |
170 } |
168 |
171 |
169 JfrCheckpointBlobHandle JfrCheckpointWriter::copy(const JfrCheckpointContext* ctx /* 0 */) { |
172 JfrBlobHandle JfrCheckpointWriter::move(const JfrCheckpointContext* ctx /* 0 */) { |
170 if (ctx == NULL) { |
|
171 return checkpoint_blob(); |
|
172 } |
|
173 size_t size = 0; |
173 size_t size = 0; |
174 const u1* data = session_data(&size, ctx); |
174 const u1* data = session_data(&size, true, ctx); |
175 return JfrCheckpointBlob::make(data, size); |
175 JfrBlobHandle blob = JfrBlob::make(data, size); |
176 } |
|
177 |
|
178 JfrCheckpointBlobHandle JfrCheckpointWriter::move(const JfrCheckpointContext* ctx /* 0 */) { |
|
179 JfrCheckpointBlobHandle data = copy(ctx); |
|
180 if (ctx != NULL) { |
176 if (ctx != NULL) { |
181 const_cast<JfrCheckpointContext*>(ctx)->count = 0; |
177 const_cast<JfrCheckpointContext*>(ctx)->count = 0; |
182 set_context(*ctx); |
178 set_context(*ctx); |
183 } |
179 } |
184 return data; |
180 return blob; |
185 } |
181 } |