author | mgronlun |
Sat, 24 Aug 2019 14:30:27 +0200 | |
branch | JEP-349-branch |
changeset 57870 | 00860d9caf4d |
parent 57360 | 5d043a159d5c |
child 57882 | 562f598d303c |
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 |
||
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
|
33 |
JfrCheckpointWriter::JfrCheckpointWriter() : |
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), |
|
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
|
38 |
_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
|
39 |
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
|
40 |
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
|
41 |
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
|
42 |
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
|
43 |
} |
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 |
JfrCheckpointWriter::JfrCheckpointWriter(Thread* t, bool 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
|
47 |
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
|
48 |
_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
|
49 |
_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
|
50 |
_count(0), |
50113 | 51 |
_header(header) { |
52 |
assert(this->is_acquired(), "invariant"); |
|
53 |
assert(0 == this->current_offset(), "invariant"); |
|
54 |
if (_header) { |
|
55 |
reserve(sizeof(JfrCheckpointEntry)); |
|
56 |
} |
|
57 |
} |
|
58 |
||
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
|
59 |
JfrCheckpointWriter::JfrCheckpointWriter(Thread* t, JfrBuffer* buffer) : |
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
|
60 |
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
|
61 |
_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
|
62 |
_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
|
63 |
_count(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
|
64 |
_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
|
65 |
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
|
66 |
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
|
67 |
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
|
68 |
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
|
69 |
} |
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 |
} |
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 |
|
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 |
static void write_checkpoint_header(u1* pos, int64_t size, jlong time, u4 type_count) { |
50113 | 73 |
assert(pos != NULL, "invariant"); |
74 |
JfrBigEndianWriter be_writer(pos, sizeof(JfrCheckpointEntry)); |
|
75 |
be_writer.write(size); |
|
76 |
be_writer.write(time); |
|
77 |
be_writer.write(JfrTicks::now().value() - time); |
|
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
|
78 |
be_writer.write((u4)0); // not a flushpoint |
50113 | 79 |
be_writer.write(type_count); |
80 |
assert(be_writer.is_valid(), "invariant"); |
|
81 |
} |
|
82 |
||
83 |
JfrCheckpointWriter::~JfrCheckpointWriter() { |
|
84 |
assert(this->is_acquired(), "invariant"); |
|
85 |
if (!this->is_valid() || !_header) { |
|
86 |
release(); |
|
87 |
return; |
|
88 |
} |
|
89 |
if (0 == count()) { |
|
90 |
assert(this->used_size() == sizeof(JfrCheckpointEntry), "invariant"); |
|
91 |
this->seek(_offset); |
|
92 |
release(); |
|
93 |
return; |
|
94 |
} |
|
95 |
assert(_header, "invariant"); |
|
96 |
assert(this->is_valid(), "invariant"); |
|
97 |
assert(count() > 0, "invariant"); |
|
98 |
assert(this->used_size() > sizeof(JfrCheckpointEntry), "invariant"); |
|
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
50113
diff
changeset
|
99 |
const int64_t size = this->current_offset(); |
50113 | 100 |
assert(size + this->start_pos() == this->current_pos(), "invariant"); |
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
|
101 |
write_checkpoint_header(const_cast<u1*>(this->start_pos()), size, _time, count()); |
50113 | 102 |
release(); |
103 |
} |
|
104 |
||
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
50113
diff
changeset
|
105 |
u4 JfrCheckpointWriter::count() const { |
50113 | 106 |
return _count; |
107 |
} |
|
108 |
||
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
50113
diff
changeset
|
109 |
void JfrCheckpointWriter::set_count(u4 count) { |
50113 | 110 |
_count = count; |
111 |
} |
|
112 |
||
113 |
void JfrCheckpointWriter::release() { |
|
114 |
assert(this->is_acquired(), "invariant"); |
|
115 |
if (!this->is_valid() || this->used_size() == 0) { |
|
116 |
return; |
|
117 |
} |
|
118 |
assert(this->used_size() > 0, "invariant"); |
|
119 |
// write through to backing storage |
|
120 |
this->commit(); |
|
121 |
assert(0 == this->current_offset(), "invariant"); |
|
122 |
} |
|
123 |
||
124 |
void JfrCheckpointWriter::write_type(JfrTypeId type_id) { |
|
125 |
assert(type_id < TYPES_END, "invariant"); |
|
126 |
write<u8>(type_id); |
|
127 |
increment(); |
|
128 |
} |
|
129 |
||
130 |
void JfrCheckpointWriter::write_key(u8 key) { |
|
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
50113
diff
changeset
|
131 |
write(key); |
50113 | 132 |
} |
133 |
||
134 |
void JfrCheckpointWriter::increment() { |
|
135 |
++_count; |
|
136 |
} |
|
137 |
||
138 |
void JfrCheckpointWriter::write_count(u4 nof_entries) { |
|
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
50113
diff
changeset
|
139 |
write(nof_entries); |
50113 | 140 |
} |
141 |
||
53897
0abec72a3ac2
8217647: JFR: recordings on 32-bit systems unreadable
bulasevich
parents:
50113
diff
changeset
|
142 |
void JfrCheckpointWriter::write_count(u4 nof_entries, int64_t offset) { |
50113 | 143 |
write_padded_at_offset(nof_entries, offset); |
144 |
} |
|
145 |
||
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
|
146 |
const u1* JfrCheckpointWriter::session_data(size_t* size, bool move /* false */, const JfrCheckpointContext* ctx /* 0 */) { |
50113 | 147 |
assert(this->is_acquired(), "wrong state!"); |
148 |
if (!this->is_valid()) { |
|
149 |
*size = 0; |
|
150 |
return NULL; |
|
151 |
} |
|
152 |
if (ctx != NULL) { |
|
153 |
const u1* session_start_pos = this->start_pos() + ctx->offset; |
|
154 |
*size = this->current_pos() - session_start_pos; |
|
155 |
return session_start_pos; |
|
156 |
} |
|
157 |
*size = this->used_size(); |
|
158 |
assert(this->start_pos() + *size == this->current_pos(), "invariant"); |
|
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
|
159 |
write_checkpoint_header(const_cast<u1*>(this->start_pos()), this->used_offset(), _time, count()); |
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
|
160 |
_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
|
161 |
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
|
162 |
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
|
163 |
} |
50113 | 164 |
return this->start_pos(); |
165 |
} |
|
166 |
||
167 |
const JfrCheckpointContext JfrCheckpointWriter::context() const { |
|
168 |
JfrCheckpointContext ctx; |
|
169 |
ctx.offset = this->current_offset(); |
|
170 |
ctx.count = this->count(); |
|
171 |
return ctx; |
|
172 |
} |
|
173 |
||
174 |
void JfrCheckpointWriter::set_context(const JfrCheckpointContext ctx) { |
|
175 |
this->seek(ctx.offset); |
|
176 |
set_count(ctx.count); |
|
177 |
} |
|
178 |
bool JfrCheckpointWriter::has_data() const { |
|
179 |
return this->used_size() > sizeof(JfrCheckpointEntry); |
|
180 |
} |
|
181 |
||
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
|
182 |
JfrCheckpointBlobHandle JfrCheckpointWriter::copy(const JfrCheckpointContext* ctx /* 0 */) { |
50113 | 183 |
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
|
184 |
const u1* data = session_data(&size, false, ctx); |
50113 | 185 |
return JfrCheckpointBlob::make(data, size); |
186 |
} |
|
187 |
||
188 |
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
|
189 |
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
|
190 |
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
|
191 |
JfrCheckpointBlobHandle blob = JfrCheckpointBlob::make(data, size); |
50113 | 192 |
if (ctx != NULL) { |
193 |
const_cast<JfrCheckpointContext*>(ctx)->count = 0; |
|
194 |
set_context(*ctx); |
|
195 |
} |
|
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
|
196 |
return blob; |
50113 | 197 |
} |