--- a/src/jdk.jfr/share/classes/jdk/jfr/consumer/RecordingFile.java Wed Oct 30 16:14:56 2019 +0100
+++ b/src/jdk.jfr/share/classes/jdk/jfr/consumer/RecordingFile.java Wed Oct 30 19:43:52 2019 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -32,7 +32,6 @@
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashSet;
import java.util.List;
@@ -40,8 +39,9 @@
import jdk.jfr.internal.MetadataDescriptor;
import jdk.jfr.internal.Type;
import jdk.jfr.internal.consumer.ChunkHeader;
+import jdk.jfr.internal.consumer.ChunkParser;
+import jdk.jfr.internal.consumer.FileAccess;
import jdk.jfr.internal.consumer.RecordingInput;
-import jdk.jfr.internal.consumer.RecordingInternals;
/**
* A recording file.
@@ -62,27 +62,6 @@
* @since 9
*/
public final class RecordingFile implements Closeable {
- static{
- RecordingInternals.INSTANCE = new RecordingInternals() {
- public List<Type> readTypes(RecordingFile file) throws IOException {
- return file.readTypes();
- }
-
- public boolean isLastEventInChunk(RecordingFile file) {
- return file.isLastEventInChunk;
- }
-
- @Override
- public Object getOffsetDataTime(RecordedObject event, String name) {
- return event.getOffsetDateTime(name);
- }
-
- @Override
- public void sort(List<RecordedEvent> events) {
- Collections.sort(events, (e1, e2) -> Long.compare(e1.endTime, e2.endTime));
- }
- };
- }
private boolean isLastEventInChunk;
private final File file;
@@ -104,7 +83,7 @@
*/
public RecordingFile(Path file) throws IOException {
this.file = file.toFile();
- this.input = new RecordingInput(this.file);
+ this.input = new RecordingInput(this.file, FileAccess.UNPRIVILIGED);
findNext();
}
@@ -154,14 +133,15 @@
*/
public List<EventType> readEventTypes() throws IOException {
ensureOpen();
+ MetadataDescriptor previous = null;
List<EventType> types = new ArrayList<>();
HashSet<Long> foundIds = new HashSet<>();
- try (RecordingInput ri = new RecordingInput(file)) {
+ try (RecordingInput ri = new RecordingInput(file, FileAccess.UNPRIVILIGED)) {
ChunkHeader ch = new ChunkHeader(ri);
- aggregateEventTypeForChunk(ch, types, foundIds);
+ aggregateEventTypeForChunk(ch, null, types, foundIds);
while (!ch.isLastChunk()) {
ch = ch.nextHeader();
- aggregateEventTypeForChunk(ch, types, foundIds);
+ previous = aggregateEventTypeForChunk(ch, previous, types, foundIds);
}
}
return types;
@@ -169,37 +149,41 @@
List<Type> readTypes() throws IOException {
ensureOpen();
+ MetadataDescriptor previous = null;
List<Type> types = new ArrayList<>();
HashSet<Long> foundIds = new HashSet<>();
- try (RecordingInput ri = new RecordingInput(file)) {
+ try (RecordingInput ri = new RecordingInput(file, FileAccess.UNPRIVILIGED)) {
ChunkHeader ch = new ChunkHeader(ri);
- aggregateTypeForChunk(ch, types, foundIds);
+ ch.awaitFinished();
+ aggregateTypeForChunk(ch, null, types, foundIds);
while (!ch.isLastChunk()) {
ch = ch.nextHeader();
- aggregateTypeForChunk(ch, types, foundIds);
+ previous = aggregateTypeForChunk(ch, previous, types, foundIds);
}
}
return types;
}
- private void aggregateTypeForChunk(ChunkHeader ch, List<Type> types, HashSet<Long> foundIds) throws IOException {
- MetadataDescriptor m = ch.readMetadata();
+ private MetadataDescriptor aggregateTypeForChunk(ChunkHeader ch, MetadataDescriptor previous, List<Type> types, HashSet<Long> foundIds) throws IOException {
+ MetadataDescriptor m = ch.readMetadata(previous);
for (Type t : m.getTypes()) {
if (!foundIds.contains(t.getId())) {
types.add(t);
foundIds.add(t.getId());
}
}
+ return m;
}
- private static void aggregateEventTypeForChunk(ChunkHeader ch, List<EventType> types, HashSet<Long> foundIds) throws IOException {
- MetadataDescriptor m = ch.readMetadata();
+ private static MetadataDescriptor aggregateEventTypeForChunk(ChunkHeader ch, MetadataDescriptor previous, List<EventType> types, HashSet<Long> foundIds) throws IOException {
+ MetadataDescriptor m = ch.readMetadata(previous);
for (EventType t : m.getEventTypes()) {
if (!foundIds.contains(t.getId())) {
types.add(t);
foundIds.add(t.getId());
}
}
+ return m;
}
/**
@@ -246,6 +230,17 @@
}
}
+ // package protected
+ File getFile() {
+ return file;
+ }
+
+ // package protected
+ boolean isLastEventInChunk() {
+ return isLastEventInChunk;
+ }
+
+
// either sets next to an event or sets eof to true
private void findNext() throws IOException {
while (nextEvent == null) {