package jdk.jfr.internal.consumer;
import java.io.IOException;
import jdk.jfr.internal.LogLevel;
import jdk.jfr.internal.LogTag;
import jdk.jfr.internal.Logger;
import jdk.jfr.internal.MetadataDescriptor;
import jdk.jfr.internal.Utils;
public final class {
static final long = 68;
static final byte = (byte) 255;
static final long = 8;
static final long = 40;
static final long = 64;
static final long = 67;
static final long = 0;
static final byte[] = { 'F', 'L', 'R', '\0' };
static final int = 1 << 1;
private final short ;
private final short ;
private final long ;
private final long ;
private final long ;
private final long ;
private final RecordingInput ;
private final long ;
private long ;
private long = 0;
private long = 0;
private long = 0;
private long ;
private long ;
private boolean ;
private boolean ;
private boolean ;
public (RecordingInput input) throws IOException {
this(input, 0, 0);
}
private (RecordingInput input, long absoluteChunkStart, long id) throws IOException {
this.absoluteChunkStart = absoluteChunkStart;
this.absoluteEventStart = absoluteChunkStart + HEADER_SIZE;
if (input.getFileSize() < HEADER_SIZE) {
throw new IOException("Not a complete Chunk header");
}
input.setValidSize(absoluteChunkStart + HEADER_SIZE);
input.position(absoluteChunkStart);
if (input.position() >= input.size()) {
throw new IOException("Chunk contains no data");
}
verifyMagic(input);
this.input = input;
this.id = id;
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Chunk: " + id);
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Chunk: file=" + input.getFilename());
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Chunk: startPosition=" + absoluteChunkStart);
major = input.readRawShort();
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Chunk: major=" + major);
minor = input.readRawShort();
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Chunk: minor=" + minor);
if (major != 1 && major != 2) {
throw new IOException("File version " + major + "." + minor + ". Only Flight Recorder files of version 1.x and 2.x can be read by this JDK.");
}
long c = input.readRawLong();
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Chunk: chunkSize=" + c);
input.readRawLong();
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Chunk: constantPoolPosition=" + constantPoolPosition);
input.readRawLong();
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Chunk: metadataPosition=" + metadataPosition);
chunkStartNanos = input.readRawLong();
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Chunk: startNanos=" + chunkStartNanos);
durationNanos = input.readRawLong();
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Chunk: durationNanos=" + durationNanos);
chunkStartTicks = input.readRawLong();
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Chunk: startTicks=" + chunkStartTicks);
ticksPerSecond = input.readRawLong();
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Chunk: ticksPerSecond=" + ticksPerSecond);
input.readRawInt();
refresh();
input.position(absoluteEventStart);
}
public void () throws IOException {
while (true) {
byte fileState1;
input.positionPhysical(absoluteChunkStart + FILE_STATE_POSITION);
while ((fileState1 = input.readPhysicalByte()) == UPDATING_CHUNK_HEADER) {
Utils.takeNap(1);
input.positionPhysical(absoluteChunkStart + FILE_STATE_POSITION);
}
input.positionPhysical(absoluteChunkStart + CHUNK_SIZE_POSITION);
long chunkSize = input.readPhysicalLong();
long constantPoolPosition = input.readPhysicalLong();
long metadataPosition = input.readPhysicalLong();
input.positionPhysical(absoluteChunkStart + DURATION_NANOS_POSITION);
long durationNanos = input.readPhysicalLong();
input.positionPhysical(absoluteChunkStart + FILE_STATE_POSITION);
byte fileState2 = input.readPhysicalByte();
input.positionPhysical(absoluteChunkStart + FLAG_BYTE_POSITION);
int flagByte = input.readPhysicalByte();
if (fileState1 == fileState2) {
finished = fileState1 == 0;
if (metadataPosition != 0) {
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Setting input size to " + (absoluteChunkStart + chunkSize));
if (finished) {
input.setValidSize(input.getFileSize());
} else {
input.setValidSize(absoluteChunkStart + chunkSize);
}
this.chunkSize = chunkSize;
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Chunk: chunkSize=" + chunkSize);
this.constantPoolPosition = constantPoolPosition;
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Chunk: constantPoolPosition=" + constantPoolPosition);
this.metadataPosition = metadataPosition;
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Chunk: metadataPosition=" + metadataPosition);
this.durationNanos = durationNanos;
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Chunk: durationNanos =" + durationNanos);
isFinished = fileState2 == 0;
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Chunk: generation=" + fileState2);
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Chunk: finished=" + isFinished);
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Chunk: fileSize=" + input.size());
this.finalChunk = (flagByte & MASK_FINAL_CHUNK) != 0;
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Chunk: finalChunk=" + finalChunk);
absoluteChunkEnd = absoluteChunkStart + chunkSize;
return;
}
}
}
}
public boolean (byte[] bytes, int count) throws IOException {
input.position(absoluteChunkStart);
for (int i = 0; i< count; i++) {
bytes[i] = input.readPhysicalByte();
}
return bytes[(int)FILE_STATE_POSITION] != UPDATING_CHUNK_HEADER;
}
public void () throws IOException {
if (finished) {
return;
}
long pos = input.position();
try {
input.positionPhysical(absoluteChunkStart + FILE_STATE_POSITION);
while (true) {
byte filestate = input.readPhysicalByte();
if (filestate == 0) {
finished = true;
return;
}
Utils.takeNap(1);
}
} finally {
input.position(pos);
}
}
public boolean () throws IOException {
awaitFinished();
return input.getFileSize() == absoluteChunkEnd;
}
public boolean () {
return finalChunk;
}
public boolean () throws IOException {
return isFinished;
}
public ChunkHeader () throws IOException {
return new ChunkHeader(input, absoluteChunkEnd, id + 1);
}
public MetadataDescriptor () throws IOException {
return readMetadata(null);
}
public MetadataDescriptor (MetadataDescriptor previous) throws IOException {
input.position(absoluteChunkStart + metadataPosition);
input.readInt();
long id = input.readLong();
if (id != METADATA_TYPE_ID) {
throw new IOException("Expected metadata event. Type id=" + id + ", should have been " + METADATA_TYPE_ID);
}
input.readLong();
input.readLong();
long metadataId = input.readLong();
if (previous != null && metadataId == previous.metadataId) {
return previous;
}
Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.TRACE, "New metadata id = " + metadataId);
MetadataDescriptor m = MetadataDescriptor.read(input);
m.metadataId = metadataId;
return m;
}
public short () {
return major;
}
public short () {
return minor;
}
public long () {
return absoluteChunkStart;
}
public long () {
return absoluteEventStart;
}
public long () {
return constantPoolPosition;
}
public long () {
return metadataPosition;
}
public long () {
return chunkStartTicks;
}
public long () {
return chunkSize;
}
public double () {
return ticksPerSecond;
}
public long () {
return chunkStartNanos;
}
public long () {
return absoluteChunkEnd;
}
public long () {
return chunkSize;
}
public long () {
return durationNanos;
}
public RecordingInput () {
return input;
}
private static void (RecordingInput input) throws IOException {
for (byte c : FILE_MAGIC) {
if (input.readByte() != c) {
throw new IOException("Not a Flight Recorder file");
}
}
}
public long () {
return absoluteEventStart;
}
static long () {
return HEADER_SIZE;
}
public long () {
return getStartNanos() + getDurationNanos();
}
}