author | egahlin |
Mon, 16 Sep 2019 09:57:26 +0200 | |
branch | JEP-349-branch |
changeset 58146 | 9f3aadcaa430 |
parent 58145 | bc54ed8d908a |
child 58197 | 0ef79bd7fb5c |
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. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
58145
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58129
diff
changeset
|
26 |
package jdk.jfr.internal.consumer; |
50113 | 27 |
|
28 |
import java.io.IOException; |
|
29 |
import java.util.Collection; |
|
30 |
import java.util.List; |
|
57360 | 31 |
import java.util.StringJoiner; |
50113 | 32 |
|
33 |
import jdk.jfr.EventType; |
|
58145
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58129
diff
changeset
|
34 |
import jdk.jfr.consumer.RecordedEvent; |
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58129
diff
changeset
|
35 |
import jdk.jfr.consumer.RecordedObject; |
50113 | 36 |
import jdk.jfr.internal.LogLevel; |
37 |
import jdk.jfr.internal.LogTag; |
|
38 |
import jdk.jfr.internal.Logger; |
|
57373 | 39 |
import jdk.jfr.internal.LongMap; |
50113 | 40 |
import jdk.jfr.internal.MetadataDescriptor; |
41 |
import jdk.jfr.internal.Type; |
|
57360 | 42 |
import jdk.jfr.internal.Utils; |
50113 | 43 |
|
44 |
/** |
|
45 |
* Parses a chunk. |
|
46 |
* |
|
47 |
*/ |
|
58145
bc54ed8d908a
Move implementation into jdk.jfr.internal.consumer
egahlin
parents:
58129
diff
changeset
|
48 |
public final class ChunkParser { |
58129 | 49 |
|
50 |
static final class ParserConfiguration { |
|
51 |
final boolean reuse; |
|
52 |
final boolean ordered; |
|
58146 | 53 |
final ParserFilter eventFilter; |
58129 | 54 |
|
55 |
long filterStart; |
|
56 |
long filterEnd; |
|
57 |
||
58146 | 58 |
public ParserConfiguration(long filterStart, long filterEnd, boolean reuse, boolean ordered, ParserFilter filter) { |
58129 | 59 |
this.filterStart = filterStart; |
60 |
this.filterEnd = filterEnd; |
|
61 |
this.reuse = reuse; |
|
62 |
this.ordered = ordered; |
|
63 |
this.eventFilter = filter; |
|
64 |
} |
|
65 |
||
66 |
public ParserConfiguration() { |
|
58146 | 67 |
this(0, Long.MAX_VALUE, false, false, ParserFilter.ACCEPT_ALL); |
58129 | 68 |
} |
69 |
} |
|
70 |
||
57883
90e867ac8c37
Add parser support for checkpoint cetagorization bits
egahlin
parents:
57870
diff
changeset
|
71 |
// Checkpoint that finishes a flush segment |
90e867ac8c37
Add parser support for checkpoint cetagorization bits
egahlin
parents:
57870
diff
changeset
|
72 |
static final byte CHECKPOINT_FLUSH_MASK = 1; |
90e867ac8c37
Add parser support for checkpoint cetagorization bits
egahlin
parents:
57870
diff
changeset
|
73 |
// Checkpoint contains chunk header information in the first pool |
90e867ac8c37
Add parser support for checkpoint cetagorization bits
egahlin
parents:
57870
diff
changeset
|
74 |
static final byte CHECKPOINT_CHUNK_HEADER_MASK = 2; |
90e867ac8c37
Add parser support for checkpoint cetagorization bits
egahlin
parents:
57870
diff
changeset
|
75 |
// Checkpoint contains only statics that will not change from chunk to chunk |
90e867ac8c37
Add parser support for checkpoint cetagorization bits
egahlin
parents:
57870
diff
changeset
|
76 |
static final byte CHECKPOINT_STATICS_MASK = 4; |
58020
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
77 |
// Checkpoint contains thread related information |
57883
90e867ac8c37
Add parser support for checkpoint cetagorization bits
egahlin
parents:
57870
diff
changeset
|
78 |
static final byte CHECKPOINT_THREADS_MASK = 8; |
90e867ac8c37
Add parser support for checkpoint cetagorization bits
egahlin
parents:
57870
diff
changeset
|
79 |
|
50113 | 80 |
private static final long CONSTANT_POOL_TYPE_ID = 1; |
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:
57861
diff
changeset
|
81 |
private static final String CHUNKHEADER = "jdk.types.ChunkHeader"; |
50113 | 82 |
private final RecordingInput input; |
83 |
private final ChunkHeader chunkHeader; |
|
84 |
private final MetadataDescriptor metadata; |
|
85 |
private final TimeConverter timeConverter; |
|
57360 | 86 |
private final MetadataDescriptor previousMetadata; |
87 |
private final long pollInterval; |
|
88 |
private final LongMap<ConstantLookup> constantLookups; |
|
89 |
||
90 |
private LongMap<Type> typeMap; |
|
91 |
private LongMap<Parser> parsers; |
|
92 |
private boolean chunkFinished; |
|
58129 | 93 |
|
57861 | 94 |
private Runnable flushOperation; |
58129 | 95 |
private ParserConfiguration configuration; |
50113 | 96 |
|
58129 | 97 |
public ChunkParser(RecordingInput input) throws IOException { |
98 |
this(input, new ParserConfiguration()); |
|
99 |
} |
|
100 |
||
101 |
public ChunkParser(RecordingInput input, ParserConfiguration pc) throws IOException { |
|
102 |
this(new ChunkHeader(input), null, pc); |
|
57376 | 103 |
} |
104 |
||
57427 | 105 |
public ChunkParser(ChunkParser previous) throws IOException { |
58129 | 106 |
this(new ChunkHeader(previous.input), previous, new ParserConfiguration()); |
57427 | 107 |
} |
50113 | 108 |
|
58129 | 109 |
private ChunkParser(ChunkHeader header, ChunkParser previous, ParserConfiguration pc) throws IOException { |
110 |
this.configuration = pc; |
|
50113 | 111 |
this.input = header.getInput(); |
112 |
this.chunkHeader = header; |
|
57360 | 113 |
if (previous == null) { |
57459 | 114 |
this.pollInterval = 1000; |
57360 | 115 |
this.constantLookups = new LongMap<>(); |
116 |
this.previousMetadata = null; |
|
117 |
} else { |
|
118 |
this.constantLookups = previous.constantLookups; |
|
119 |
this.previousMetadata = previous.metadata; |
|
120 |
this.pollInterval = previous.pollInterval; |
|
58129 | 121 |
this.configuration = previous.configuration; |
57360 | 122 |
} |
123 |
this.metadata = header.readMetadata(previousMetadata); |
|
52850 | 124 |
this.timeConverter = new TimeConverter(chunkHeader, metadata.getGMTOffset()); |
57360 | 125 |
if (metadata != previousMetadata) { |
126 |
ParserFactory factory = new ParserFactory(metadata, constantLookups, timeConverter); |
|
127 |
parsers = factory.getParsers(); |
|
128 |
typeMap = factory.getTypeMap(); |
|
58129 | 129 |
updateConfiguration(); |
57360 | 130 |
} else { |
131 |
parsers = previous.parsers; |
|
132 |
typeMap = previous.typeMap; |
|
133 |
} |
|
134 |
constantLookups.forEach(c -> c.newPool()); |
|
135 |
fillConstantPools(0); |
|
136 |
constantLookups.forEach(c -> c.getLatestPool().setResolving()); |
|
137 |
constantLookups.forEach(c -> c.getLatestPool().resolve()); |
|
138 |
constantLookups.forEach(c -> c.getLatestPool().setResolved()); |
|
50113 | 139 |
|
140 |
input.position(chunkHeader.getEventStart()); |
|
141 |
} |
|
142 |
||
58129 | 143 |
public ChunkParser nextChunkParser() throws IOException { |
144 |
return new ChunkParser(chunkHeader.nextHeader(), this, configuration); |
|
145 |
} |
|
146 |
||
147 |
private void updateConfiguration() { |
|
148 |
updateConfiguration(configuration, false); |
|
57360 | 149 |
} |
150 |
||
58129 | 151 |
public void updateConfiguration(ParserConfiguration configuration, boolean resetEventCache) { |
152 |
this.configuration = configuration; |
|
153 |
parsers.forEach(p -> { |
|
154 |
if (p instanceof EventParser) { |
|
155 |
EventParser ep = (EventParser) p; |
|
156 |
if (resetEventCache) { |
|
157 |
ep.resetCache(); |
|
158 |
} |
|
159 |
String name = ep.getEventType().getName(); |
|
160 |
ep.setOrdered(configuration.ordered); |
|
161 |
ep.setReuse(configuration.reuse); |
|
162 |
ep.setFilterStart(configuration.filterStart); |
|
163 |
ep.setFilterEnd(configuration.filterEnd); |
|
164 |
long threshold = configuration.eventFilter.getThreshold(name); |
|
165 |
if (threshold >= 0) { |
|
166 |
ep.setEnabled(true); |
|
167 |
ep.setThresholdNanos(threshold); |
|
168 |
} else { |
|
169 |
ep.setEnabled(false); |
|
170 |
ep.setThresholdNanos(Long.MAX_VALUE); |
|
171 |
} |
|
172 |
} |
|
173 |
}); |
|
57360 | 174 |
} |
175 |
||
176 |
/** |
|
177 |
* Reads an event and returns null when segment or chunk ends. |
|
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
57467
diff
changeset
|
178 |
* |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
57467
diff
changeset
|
179 |
* @param awaitNewEvents wait for new data. |
57360 | 180 |
*/ |
181 |
public RecordedEvent readStreamingEvent(boolean awaitNewEvents) throws IOException { |
|
182 |
long absoluteChunkEnd = chunkHeader.getEnd(); |
|
183 |
while (true) { |
|
184 |
RecordedEvent event = readEvent(); |
|
185 |
if (event != null) { |
|
186 |
return event; |
|
187 |
} |
|
188 |
if (!awaitNewEvents) { |
|
189 |
return null; |
|
190 |
} |
|
191 |
long lastValid = absoluteChunkEnd; |
|
192 |
long metadataPoistion = chunkHeader.getMetataPosition(); |
|
193 |
long contantPosition = chunkHeader.getConstantPoolPosition(); |
|
194 |
chunkFinished = awaitUpdatedHeader(absoluteChunkEnd); |
|
195 |
if (chunkFinished) { |
|
196 |
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "At chunk end"); |
|
197 |
return null; |
|
198 |
} |
|
199 |
absoluteChunkEnd = chunkHeader.getEnd(); |
|
200 |
// Read metadata and constant pools for the next segment |
|
201 |
if (chunkHeader.getMetataPosition() != metadataPoistion) { |
|
202 |
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Found new metadata in chunk. Rebuilding types and parsers"); |
|
203 |
MetadataDescriptor metadata = chunkHeader.readMetadata(previousMetadata); |
|
204 |
ParserFactory factory = new ParserFactory(metadata, constantLookups, timeConverter); |
|
205 |
parsers = factory.getParsers(); |
|
206 |
typeMap = factory.getTypeMap(); |
|
58129 | 207 |
updateConfiguration();; |
57360 | 208 |
} |
209 |
if (contantPosition != chunkHeader.getConstantPoolPosition()) { |
|
210 |
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Found new constant pool data. Filling up pools with new values"); |
|
211 |
constantLookups.forEach(c -> c.getLatestPool().setAllResolved(false)); |
|
212 |
fillConstantPools(contantPosition + chunkHeader.getAbsoluteChunkStart()); |
|
213 |
constantLookups.forEach(c -> c.getLatestPool().setResolving()); |
|
214 |
constantLookups.forEach(c -> c.getLatestPool().resolve()); |
|
215 |
constantLookups.forEach(c -> c.getLatestPool().setResolved()); |
|
216 |
} |
|
217 |
input.position(lastValid); |
|
218 |
} |
|
219 |
} |
|
220 |
||
221 |
/** |
|
222 |
* Reads an event and returns null when the chunk ends |
|
223 |
*/ |
|
50113 | 224 |
public RecordedEvent readEvent() throws IOException { |
57360 | 225 |
long absoluteChunkEnd = chunkHeader.getEnd(); |
50113 | 226 |
while (input.position() < absoluteChunkEnd) { |
227 |
long pos = input.position(); |
|
228 |
int size = input.readInt(); |
|
229 |
if (size == 0) { |
|
230 |
throw new IOException("Event can't have zero size"); |
|
231 |
} |
|
232 |
long typeId = input.readLong(); |
|
57861 | 233 |
|
234 |
if (typeId != 0) { // Not metadata event |
|
57360 | 235 |
Parser p = parsers.get(typeId); |
236 |
if (p instanceof EventParser) { |
|
237 |
EventParser ep = (EventParser) p; |
|
238 |
RecordedEvent event = ep.parse(input); |
|
239 |
if (event != null) { |
|
240 |
input.position(pos + size); |
|
241 |
return event; |
|
242 |
} |
|
50113 | 243 |
} |
57861 | 244 |
if (typeId == 1 && flushOperation != null) { // checkpoint event |
245 |
parseCheckpoint(); |
|
246 |
} |
|
50113 | 247 |
} |
248 |
input.position(pos + size); |
|
249 |
} |
|
250 |
return null; |
|
251 |
} |
|
252 |
||
57861 | 253 |
private void parseCheckpoint() throws IOException { |
254 |
// Content has been parsed previously. This |
|
58020
f082177c5023
Improved handling of Thread.interrupt() + cleanup
egahlin
parents:
57985
diff
changeset
|
255 |
// is to trigger flush |
57861 | 256 |
input.readLong(); // timestamp |
257 |
input.readLong(); // duration |
|
258 |
input.readLong(); // delta |
|
57883
90e867ac8c37
Add parser support for checkpoint cetagorization bits
egahlin
parents:
57870
diff
changeset
|
259 |
byte c = input.readByte(); |
90e867ac8c37
Add parser support for checkpoint cetagorization bits
egahlin
parents:
57870
diff
changeset
|
260 |
if ((c & CHECKPOINT_FLUSH_MASK)== 1) { |
57861 | 261 |
flushOperation.run(); |
262 |
} |
|
263 |
} |
|
264 |
||
57360 | 265 |
private boolean awaitUpdatedHeader(long absoluteChunkEnd) throws IOException { |
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
57467
diff
changeset
|
266 |
if (Logger.shouldLog(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO)) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
57467
diff
changeset
|
267 |
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Waiting for more data (streaming). Read so far: " + chunkHeader.getChunkSize() + " bytes"); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
57467
diff
changeset
|
268 |
} |
57360 | 269 |
while (true) { |
270 |
chunkHeader.refresh(); |
|
271 |
if (absoluteChunkEnd != chunkHeader.getEnd()) { |
|
272 |
return false; |
|
273 |
} |
|
274 |
if (chunkHeader.isFinished()) { |
|
275 |
return true; |
|
276 |
} |
|
57459 | 277 |
Utils.waitFlush(pollInterval); |
57360 | 278 |
} |
279 |
} |
|
280 |
||
281 |
private void fillConstantPools(long abortCP) throws IOException { |
|
282 |
long thisCP = chunkHeader.getConstantPoolPosition() + chunkHeader.getAbsoluteChunkStart(); |
|
283 |
long lastCP = -1; |
|
284 |
long delta = -1; |
|
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
57467
diff
changeset
|
285 |
boolean logTrace = Logger.shouldLog(LogTag.JFR_SYSTEM_PARSER, LogLevel.TRACE); |
57360 | 286 |
while (thisCP != abortCP && delta != 0) { |
287 |
input.position(thisCP); |
|
288 |
lastCP = thisCP; |
|
50113 | 289 |
int size = input.readInt(); // size |
290 |
long typeId = input.readLong(); |
|
291 |
if (typeId != CONSTANT_POOL_TYPE_ID) { |
|
57360 | 292 |
throw new IOException("Expected check point event (id = 1) at position " + lastCP + ", but found type id = " + typeId); |
50113 | 293 |
} |
294 |
input.readLong(); // timestamp |
|
295 |
input.readLong(); // duration |
|
57360 | 296 |
delta = input.readLong(); |
297 |
thisCP += delta; |
|
50113 | 298 |
boolean flush = input.readBoolean(); |
299 |
int poolCount = input.readInt(); |
|
57360 | 300 |
final long logLastCP = lastCP; |
301 |
final long logDelta = delta; |
|
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
57467
diff
changeset
|
302 |
if (logTrace) { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
57467
diff
changeset
|
303 |
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.TRACE, () -> { |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
57467
diff
changeset
|
304 |
return "New constant pool: startPosition=" + logLastCP + ", size=" + size + ", deltaToNext=" + logDelta + ", flush=" + flush + ", poolCount=" + poolCount; |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
57467
diff
changeset
|
305 |
}); |
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
57467
diff
changeset
|
306 |
} |
50113 | 307 |
for (int i = 0; i < poolCount; i++) { |
308 |
long id = input.readLong(); // type id |
|
57360 | 309 |
ConstantLookup lookup = constantLookups.get(id); |
50113 | 310 |
Type type = typeMap.get(id); |
57360 | 311 |
if (lookup == null) { |
50113 | 312 |
if (type == null) { |
57360 | 313 |
throw new IOException( |
314 |
"Error parsing constant pool type " + getName(id) + " at position " + input.position() + " at check point between [" + lastCP + ", " + lastCP + size + "]"); |
|
50113 | 315 |
} |
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:
57861
diff
changeset
|
316 |
if (type.getName() != CHUNKHEADER) { |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57861
diff
changeset
|
317 |
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Found constant pool(" + id + ") that is never used"); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57861
diff
changeset
|
318 |
} |
57360 | 319 |
ConstantMap pool = new ConstantMap(ObjectFactory.create(type, timeConverter), type.getName()); |
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:
57861
diff
changeset
|
320 |
lookup = new ConstantLookup(pool, type); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57861
diff
changeset
|
321 |
constantLookups.put(type.getId(), lookup); |
50113 | 322 |
} |
57360 | 323 |
Parser parser = parsers.get(id); |
50113 | 324 |
if (parser == null) { |
325 |
throw new IOException("Could not find constant pool type with id = " + id); |
|
326 |
} |
|
327 |
try { |
|
328 |
int count = input.readInt(); |
|
57360 | 329 |
if (count == 0) { |
330 |
throw new InternalError("Pool " + type.getName() + " must contain at least one element "); |
|
331 |
} |
|
57604
838f9a7635b6
Cleaner stream reconfiguration + reduced allocation in JFR framework
egahlin
parents:
57467
diff
changeset
|
332 |
if (logTrace) { |
57360 | 333 |
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.TRACE, "Constant Pool " + i + ": " + type.getName()); |
334 |
} |
|
50113 | 335 |
for (int j = 0; j < count; j++) { |
336 |
long key = input.readLong(); |
|
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:
57861
diff
changeset
|
337 |
Object resolved = lookup.getPreviousResolved(key); |
00860d9caf4d
New metadata system for oldobjects built on top of simplified tagging model. Caching and serialization improvements. Flushpoint checkpoint with chunkheader contents.
mgronlun
parents:
57861
diff
changeset
|
338 |
if (resolved == null) { |
57360 | 339 |
Object v = parser.parse(input); |
340 |
logConstant(key, v, false); |
|
341 |
lookup.getLatestPool().put(key, v); |
|
57467 | 342 |
} else { |
343 |
parser.skip(input); |
|
344 |
logConstant(key, resolved, true); |
|
345 |
lookup.getLatestPool().putResolved(key, resolved); |
|
346 |
} |
|
50113 | 347 |
} |
348 |
} catch (Exception e) { |
|
57360 | 349 |
throw new IOException("Error parsing constant pool type " + getName(id) + " at position " + input.position() + " at check point between [" + lastCP + ", " + lastCP + size + "]", |
350 |
e); |
|
50113 | 351 |
} |
352 |
} |
|
57360 | 353 |
if (input.position() != lastCP + size) { |
50113 | 354 |
throw new IOException("Size of check point event doesn't match content"); |
355 |
} |
|
356 |
} |
|
357 |
} |
|
358 |
||
57360 | 359 |
private void logConstant(long key, Object v, boolean preresolved) { |
360 |
if (!Logger.shouldLog(LogTag.JFR_SYSTEM_PARSER, LogLevel.TRACE)) { |
|
361 |
return; |
|
362 |
} |
|
363 |
String valueText; |
|
364 |
if (v.getClass().isArray()) { |
|
365 |
Object[] array = (Object[]) v; |
|
366 |
StringJoiner sj = new StringJoiner(", ", "{", "}"); |
|
367 |
for (int i = 0; i < array.length; i++) { |
|
368 |
sj.add(textify(array[i])); |
|
369 |
} |
|
370 |
valueText = sj.toString(); |
|
371 |
} else { |
|
372 |
valueText = textify(v); |
|
373 |
} |
|
374 |
String suffix = preresolved ? " (presolved)" :""; |
|
375 |
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.TRACE, "Constant: " + key + " = " + valueText + suffix); |
|
376 |
} |
|
377 |
||
378 |
private String textify(Object o) { |
|
379 |
if (o == null) { // should not happen |
|
380 |
return "null"; |
|
381 |
} |
|
382 |
if (o instanceof String) { |
|
383 |
return "\"" + String.valueOf(o) + "\""; |
|
384 |
} |
|
385 |
if (o instanceof RecordedObject) { |
|
386 |
return o.getClass().getName(); |
|
387 |
} |
|
388 |
if (o.getClass().isArray()) { |
|
389 |
Object[] array = (Object[]) o; |
|
390 |
if (array.length > 0) { |
|
391 |
return textify(array[0]) + "[]"; // can it be recursive? |
|
392 |
} |
|
393 |
} |
|
394 |
return String.valueOf(o); |
|
395 |
} |
|
396 |
||
50113 | 397 |
private String getName(long id) { |
398 |
Type type = typeMap.get(id); |
|
52850 | 399 |
return type == null ? ("unknown(" + id + ")") : type.getName(); |
50113 | 400 |
} |
401 |
||
402 |
public Collection<Type> getTypes() { |
|
403 |
return metadata.getTypes(); |
|
404 |
} |
|
405 |
||
406 |
public List<EventType> getEventTypes() { |
|
407 |
return metadata.getEventTypes(); |
|
408 |
} |
|
409 |
||
57360 | 410 |
public boolean isLastChunk() throws IOException { |
50113 | 411 |
return chunkHeader.isLastChunk(); |
412 |
} |
|
413 |
||
57427 | 414 |
public ChunkParser newChunkParser() throws IOException { |
415 |
return new ChunkParser(this); |
|
416 |
} |
|
417 |
||
57360 | 418 |
public boolean isChunkFinished() { |
419 |
return chunkFinished; |
|
50113 | 420 |
} |
57380
6a7e7743b82f
setOrdered and setReuse implemented for file stream, incl. unit tests
egahlin
parents:
57377
diff
changeset
|
421 |
|
57861 | 422 |
public void setFlushOperation(Runnable flushOperation) { |
423 |
this.flushOperation = flushOperation; |
|
424 |
} |
|
425 |
||
57640
46a77fccd251
Fix first(...), next(...) and last() path from RepositoryFiles
egahlin
parents:
57604
diff
changeset
|
426 |
public long getChunkDuration() { |
46a77fccd251
Fix first(...), next(...) and last() path from RepositoryFiles
egahlin
parents:
57604
diff
changeset
|
427 |
return chunkHeader.getDurationNanos(); |
46a77fccd251
Fix first(...), next(...) and last() path from RepositoryFiles
egahlin
parents:
57604
diff
changeset
|
428 |
} |
57690
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57640
diff
changeset
|
429 |
|
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57640
diff
changeset
|
430 |
public long getStartNanos() { |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57640
diff
changeset
|
431 |
return chunkHeader.getStartNanos(); |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57640
diff
changeset
|
432 |
} |
58129 | 433 |
|
50113 | 434 |
} |