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