author | mgronlun |
Wed, 30 Oct 2019 19:43:52 +0100 | |
changeset 58863 | c16ac7a2eba4 |
parent 58132 | caa25ab47aca |
permissions | -rw-r--r-- |
50113 | 1 |
/* |
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
53897
diff
changeset
|
2 |
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. |
50113 | 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 |
#include "precompiled.hpp" |
|
26 |
#include "jfr/recorder/checkpoint/jfrCheckpointManager.hpp" |
|
27 |
#include "jfr/recorder/checkpoint/jfrCheckpointWriter.hpp" |
|
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
53897
diff
changeset
|
28 |
#include "jfr/utilities/jfrBlob.hpp" |
50113 | 29 |
#include "jfr/writers/jfrBigEndianWriter.hpp" |
30 |
||
31 |
JfrCheckpointFlush::JfrCheckpointFlush(Type* old, size_t used, size_t requested, Thread* t) : |
|
32 |
_result(JfrCheckpointManager::flush(old, used, requested, t)) {} |
|
33 |
||
58863 | 34 |
JfrCheckpointWriter::JfrCheckpointWriter(JfrCheckpointType type /* GENERIC */) : |
35 |
JfrCheckpointWriterBase(JfrCheckpointManager::lease_buffer(Thread::current()), Thread::current()), |
|
50113 | 36 |
_time(JfrTicks::now()), |
37 |
_offset(0), |
|
38 |
_count(0), |
|
58863 | 39 |
_type(type), |
40 |
_header(true) { |
|
41 |
assert(this->is_acquired(), "invariant"); |
|
42 |
assert(0 == this->current_offset(), "invariant"); |
|
43 |
if (_header) { |
|
44 |
reserve(sizeof(JfrCheckpointEntry)); |
|
45 |
} |
|
46 |
} |
|
47 |
||
48 |
JfrCheckpointWriter::JfrCheckpointWriter(Thread* t, bool header /* true */, JfrCheckpointType type /* GENERIC */) : |
|
49 |
JfrCheckpointWriterBase(JfrCheckpointManager::lease_buffer(t), t), |
|
50 |
_time(JfrTicks::now()), |
|
51 |
_offset(0), |
|
52 |
_count(0), |
|
53 |
_type(type), |
|
50113 | 54 |
_header(header) { |
55 |
assert(this->is_acquired(), "invariant"); |
|
56 |
assert(0 == this->current_offset(), "invariant"); |
|
57 |
if (_header) { |
|
58 |
reserve(sizeof(JfrCheckpointEntry)); |
|
59 |
} |
|
60 |
} |
|
61 |
||
58863 | 62 |
JfrCheckpointWriter::JfrCheckpointWriter(Thread* t, JfrBuffer* buffer, JfrCheckpointType type /* GENERIC */) : |
63 |
JfrCheckpointWriterBase(buffer, t), |
|
64 |
_time(JfrTicks::now()), |
|
65 |
_offset(0), |
|
66 |
_count(0), |
|
67 |
_type(type), |
|
68 |
_header(true) { |
|
69 |
assert(this->is_acquired(), "invariant"); |
|
70 |
assert(0 == this->current_offset(), "invariant"); |
|
71 |
if (_header) { |
|
72 |
reserve(sizeof(JfrCheckpointEntry)); |
|
73 |
} |
|
74 |
} |
|
75 |
||
76 |
static void write_checkpoint_header(u1* pos, int64_t size, jlong time, u4 checkpoint_type, u4 type_count) { |
|
50113 | 77 |
assert(pos != NULL, "invariant"); |
78 |
JfrBigEndianWriter be_writer(pos, sizeof(JfrCheckpointEntry)); |
|
79 |
be_writer.write(size); |
|
80 |
be_writer.write(time); |
|
81 |
be_writer.write(JfrTicks::now().value() - time); |
|
58863 | 82 |
be_writer.write(checkpoint_type); |
50113 | 83 |
be_writer.write(type_count); |
84 |
assert(be_writer.is_valid(), "invariant"); |
|
85 |
} |
|
86 |
||
87 |
JfrCheckpointWriter::~JfrCheckpointWriter() { |
|
88 |
assert(this->is_acquired(), "invariant"); |
|
89 |
if (!this->is_valid() || !_header) { |
|
90 |
release(); |
|
91 |
return; |
|
92 |
} |
|
93 |
if (0 == count()) { |
|
94 |
assert(this->used_size() == sizeof(JfrCheckpointEntry), "invariant"); |
|
95 |
this->seek(_offset); |
|
96 |
release(); |
|
97 |
return; |
|
98 |
} |
|
99 |
assert(_header, "invariant"); |
|
100 |
assert(this->is_valid(), "invariant"); |
|
101 |
assert(count() > 0, "invariant"); |
|
102 |
assert(this->used_size() > sizeof(JfrCheckpointEntry), "invariant"); |
|
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
50113
diff
changeset
|
103 |
const int64_t size = this->current_offset(); |
50113 | 104 |
assert(size + this->start_pos() == this->current_pos(), "invariant"); |
58863 | 105 |
write_checkpoint_header(const_cast<u1*>(this->start_pos()), size, _time, (u4)_type, count()); |
50113 | 106 |
release(); |
107 |
} |
|
108 |
||
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
50113
diff
changeset
|
109 |
u4 JfrCheckpointWriter::count() const { |
50113 | 110 |
return _count; |
111 |
} |
|
112 |
||
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
50113
diff
changeset
|
113 |
void JfrCheckpointWriter::set_count(u4 count) { |
50113 | 114 |
_count = count; |
115 |
} |
|
116 |
||
117 |
void JfrCheckpointWriter::release() { |
|
118 |
assert(this->is_acquired(), "invariant"); |
|
119 |
if (!this->is_valid() || this->used_size() == 0) { |
|
120 |
return; |
|
121 |
} |
|
122 |
assert(this->used_size() > 0, "invariant"); |
|
123 |
// write through to backing storage |
|
124 |
this->commit(); |
|
125 |
assert(0 == this->current_offset(), "invariant"); |
|
126 |
} |
|
127 |
||
128 |
void JfrCheckpointWriter::write_type(JfrTypeId type_id) { |
|
129 |
assert(type_id < TYPES_END, "invariant"); |
|
130 |
write<u8>(type_id); |
|
131 |
increment(); |
|
132 |
} |
|
133 |
||
134 |
void JfrCheckpointWriter::write_key(u8 key) { |
|
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
50113
diff
changeset
|
135 |
write(key); |
50113 | 136 |
} |
137 |
||
138 |
void JfrCheckpointWriter::increment() { |
|
139 |
++_count; |
|
140 |
} |
|
141 |
||
142 |
void JfrCheckpointWriter::write_count(u4 nof_entries) { |
|
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
50113
diff
changeset
|
143 |
write(nof_entries); |
50113 | 144 |
} |
145 |
||
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
50113
diff
changeset
|
146 |
void JfrCheckpointWriter::write_count(u4 nof_entries, int64_t offset) { |
50113 | 147 |
write_padded_at_offset(nof_entries, offset); |
148 |
} |
|
149 |
||
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
53897
diff
changeset
|
150 |
const u1* JfrCheckpointWriter::session_data(size_t* size, bool move /* false */, const JfrCheckpointContext* ctx /* 0 */) { |
50113 | 151 |
assert(this->is_acquired(), "wrong state!"); |
152 |
if (!this->is_valid()) { |
|
153 |
*size = 0; |
|
154 |
return NULL; |
|
155 |
} |
|
156 |
if (ctx != NULL) { |
|
157 |
const u1* session_start_pos = this->start_pos() + ctx->offset; |
|
158 |
*size = this->current_pos() - session_start_pos; |
|
159 |
return session_start_pos; |
|
160 |
} |
|
161 |
*size = this->used_size(); |
|
162 |
assert(this->start_pos() + *size == this->current_pos(), "invariant"); |
|
58863 | 163 |
write_checkpoint_header(const_cast<u1*>(this->start_pos()), this->used_offset(), _time, (u4)_type, count()); |
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
53897
diff
changeset
|
164 |
_header = false; // the header was just written |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
53897
diff
changeset
|
165 |
if (move) { |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
53897
diff
changeset
|
166 |
this->seek(_offset); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
53897
diff
changeset
|
167 |
} |
50113 | 168 |
return this->start_pos(); |
169 |
} |
|
170 |
||
171 |
const JfrCheckpointContext JfrCheckpointWriter::context() const { |
|
172 |
JfrCheckpointContext ctx; |
|
173 |
ctx.offset = this->current_offset(); |
|
174 |
ctx.count = this->count(); |
|
175 |
return ctx; |
|
176 |
} |
|
177 |
||
178 |
void JfrCheckpointWriter::set_context(const JfrCheckpointContext ctx) { |
|
179 |
this->seek(ctx.offset); |
|
180 |
set_count(ctx.count); |
|
181 |
} |
|
182 |
bool JfrCheckpointWriter::has_data() const { |
|
183 |
return this->used_size() > sizeof(JfrCheckpointEntry); |
|
184 |
} |
|
185 |
||
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
53897
diff
changeset
|
186 |
JfrBlobHandle JfrCheckpointWriter::copy(const JfrCheckpointContext* ctx /* 0 */) { |
50113 | 187 |
size_t size = 0; |
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
53897
diff
changeset
|
188 |
const u1* data = session_data(&size, false, ctx); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
53897
diff
changeset
|
189 |
return JfrBlob::make(data, size); |
50113 | 190 |
} |
191 |
||
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
53897
diff
changeset
|
192 |
JfrBlobHandle JfrCheckpointWriter::move(const JfrCheckpointContext* ctx /* 0 */) { |
50113 | 193 |
size_t size = 0; |
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
53897
diff
changeset
|
194 |
const u1* data = session_data(&size, true, ctx); |
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
53897
diff
changeset
|
195 |
JfrBlobHandle blob = JfrBlob::make(data, size); |
50113 | 196 |
if (ctx != NULL) { |
197 |
const_cast<JfrCheckpointContext*>(ctx)->count = 0; |
|
198 |
set_context(*ctx); |
|
199 |
} |
|
58132
caa25ab47aca
8225797: OldObjectSample event creates unexpected amount of checkpoint data
mgronlun
parents:
53897
diff
changeset
|
200 |
return blob; |
50113 | 201 |
} |