Skip to content

Commit 2de0cb2

Browse files
Minor code refactors.
1 parent 9e7fa45 commit 2de0cb2

11 files changed

+53
-88
lines changed

substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/utils/JFRFileParser.java

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.util.HashMap;
3434

3535
import com.oracle.svm.core.jfr.JfrChunkWriter;
36+
import com.oracle.svm.core.jfr.JfrTicks;
3637
import com.oracle.svm.core.jfr.JfrTypes;
3738

3839
import com.oracle.svm.test.jfr.utils.poolparsers.ClassConstantPoolParser;
@@ -41,7 +42,6 @@
4142
import com.oracle.svm.test.jfr.utils.poolparsers.FrameTypeConstantPoolParser;
4243
import com.oracle.svm.test.jfr.utils.poolparsers.MethodConstantPoolParser;
4344
import com.oracle.svm.test.jfr.utils.poolparsers.ModuleConstantPoolParser;
44-
import com.oracle.svm.test.jfr.utils.poolparsers.NotFoundConstantPoolParser;
4545
import com.oracle.svm.test.jfr.utils.poolparsers.PackageConstantPoolParser;
4646
import com.oracle.svm.test.jfr.utils.poolparsers.StacktraceConstantPoolParser;
4747
import com.oracle.svm.test.jfr.utils.poolparsers.SymbolConstantPoolParser;
@@ -53,12 +53,10 @@
5353

5454
public class JFRFileParser {
5555

56-
private static final NotFoundConstantPoolParser notFoundConstantPoolParser;
5756
private static final HashMap<Long, ConstantPoolParser> supportedConstantPools;
5857

5958
static {
6059
supportedConstantPools = new HashMap<>();
61-
notFoundConstantPoolParser = new NotFoundConstantPoolParser();
6260

6361
supportedConstantPools.put(JfrTypes.Class.getId(), new ClassConstantPoolParser());
6462
supportedConstantPools.put(JfrTypes.ClassLoader.getId(), new ClassLoaderConstantPoolParser());
@@ -90,14 +88,16 @@ private static Positions parserFileHeader(RecordingInput input) throws IOExcepti
9088
long constantPoolPosition = input.readRawLong();
9189
assertTrue("Constant pool positions is invalid!", constantPoolPosition > 0);
9290
long metadataPosition = input.readRawLong();
93-
assertTrue("Metadata positions is equals to null!", metadataPosition > 0);
91+
assertTrue("Metadata positions is null!", metadataPosition != 0);
9492

95-
assertTrue("Starting time is invalid!", input.readRawLong() > 0); // Starting time.
93+
long startingTime = input.readRawLong();
94+
assertTrue("Starting time is invalid!", startingTime > 0); // Starting time.
95+
Assert.assertTrue("Starting time is bigger than current time!", startingTime < JfrTicks.currentTimeNanos());
9696
input.readRawLong(); // Duration.
9797
assertTrue("Chunk start tick is invalid!", input.readRawLong() > 0); // ChunkStartTick.
9898
assertTrue("Tick frequency is invalid!", input.readRawLong() > 0); // Tick frequency.
9999
int shouldUseCompressedInt = input.readRawInt();
100-
assertTrue("Compressed int can be either 0 or 1!", shouldUseCompressedInt == 0 || shouldUseCompressedInt == 1); // ChunkWriteTick.
100+
assertTrue("Compressed int must be either 0 or 1!", shouldUseCompressedInt == 0 || shouldUseCompressedInt == 1); // ChunkWriteTick.
101101

102102
return new Positions(constantPoolPosition, metadataPosition);
103103
}
@@ -116,12 +116,12 @@ private static void parseMetadata(RecordingInput input, long metadataPosition) t
116116
MetadataDescriptor.read(input);
117117
}
118118

119-
private static long parseConstantPoolsHeader(RecordingInput input, long constantPoolPosition) throws IOException {
119+
private static long parseConstantPoolHeader(RecordingInput input, long constantPoolPosition) throws IOException {
120120
input.position(constantPoolPosition); // Seek to starting position of constant pools.
121-
assertTrue("Constant pool size is invalid!", input.readInt() > 0); // Size of constant
122-
// pools.
123-
assertEquals(JfrChunkWriter.CONSTANT_POOL_TYPE_ID, input.readLong()); // Constant pools
124-
// region ID.
121+
// Size of constant pools.
122+
assertTrue("Constant pool size is invalid!", input.readInt() > 0);
123+
// Constant pools region ID.
124+
assertEquals(JfrChunkWriter.CONSTANT_POOL_TYPE_ID, input.readLong());
125125
assertTrue("Constant pool timestamp is invalid!", input.readLong() > 0); // Timestamp.
126126
input.readLong(); // Duration.
127127
long deltaNext = input.readLong(); // Offset to a next constant pools region.
@@ -131,29 +131,30 @@ private static long parseConstantPoolsHeader(RecordingInput input, long constant
131131

132132
private static void compareFoundAndExceptedIds() {
133133
for (ConstantPoolParser parser : supportedConstantPools.values()) {
134-
Assert.assertTrue("Number of expected IDs are not equals to the number of found during parsing " +
135-
"of " + parser + " constant pool!", parser.compare());
134+
parser.compareFoundAndExceptedIds();
136135
}
137136
}
138137

139-
private static void parseConstantPools(RecordingInput input, long constantPoolPosition) throws IOException {
140-
long deltaNext = parseConstantPoolsHeader(input, constantPoolPosition);
141-
long numberOfCPs = input.readInt();
142-
for (int i = 0; i < numberOfCPs; i++) {
143-
supportedConstantPools.getOrDefault(input.readLong(), notFoundConstantPoolParser).parse(input);
144-
}
145-
146-
compareFoundAndExceptedIds();
147-
148-
if (deltaNext != 0) {
149-
parseConstantPools(input, constantPoolPosition + deltaNext);
150-
}
138+
private static void verifyConstantPools(RecordingInput input, long constantPoolPosition) throws IOException {
139+
long deltaNext;
140+
long currentConstantPoolPosition = constantPoolPosition;
141+
do {
142+
deltaNext = parseConstantPoolHeader(input, currentConstantPoolPosition);
143+
long numberOfCPs = input.readInt();
144+
for (int i = 0; i < numberOfCPs; i++) {
145+
ConstantPoolParser constantPoolParser = supportedConstantPools.get(input.readLong());
146+
Assert.assertNotNull("Unknown constant pool!", constantPoolParser);
147+
constantPoolParser.parse(input);
148+
}
149+
compareFoundAndExceptedIds();
150+
currentConstantPoolPosition += deltaNext;
151+
} while (deltaNext != 0);
151152
}
152153

153154
public static void parse(Recording recording) throws IOException {
154155
RecordingInput input = new RecordingInput(recording.getDestination().toFile());
155156
Positions positions = parserFileHeader(input);
156-
parseConstantPools(input, positions.getConstantPoolPosition());
157+
verifyConstantPools(input, positions.getConstantPoolPosition());
157158
parseMetadata(input, positions.getMetadataPosition());
158159
}
159160

substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/utils/poolparsers/ClassConstantPoolParser.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ public void parse(RecordingInput input) throws IOException {
4141
int numberOfClasses = input.readInt();
4242
for (int i = 0; i < numberOfClasses; i++) {
4343
addFoundId(input.readLong()); // ClassId.
44-
addExpectedId(JfrTypes.ClassLoader.getId(), input.readLong()); // ClassLoaderId.
45-
addExpectedId(JfrTypes.Symbol.getId(), input.readLong()); // ClassName.
46-
addExpectedId(JfrTypes.Package.getId(), input.readLong()); // PackageId.
44+
addExpectedId(JfrTypes.ClassLoader, input.readLong()); // ClassLoaderId.
45+
addExpectedId(JfrTypes.Symbol, input.readLong()); // ClassName.
46+
addExpectedId(JfrTypes.Package, input.readLong()); // PackageId.
4747
Assert.assertTrue("Modifier value is not correct!", input.readLong() >= 0); // Modifier.
4848
if (JavaVersionUtil.JAVA_SPEC >= 17) {
4949
input.readBoolean(); // IsHiddenClass.

substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/utils/poolparsers/ClassLoaderConstantPoolParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public void parse(RecordingInput input) throws IOException {
3838
int numberOfClassLoaders = input.readInt();
3939
for (int i = 0; i < numberOfClassLoaders; i++) {
4040
addFoundId(input.readLong()); // ClassLoaderId.
41-
addExpectedId(JfrTypes.Class.getId(), input.readLong()); // ClassId.
42-
addExpectedId(JfrTypes.Symbol.getId(), input.readLong()); // ClassLoaderName.
41+
addExpectedId(JfrTypes.Class, input.readLong()); // ClassId.
42+
addExpectedId(JfrTypes.Symbol, input.readLong()); // ClassLoaderName.
4343
}
4444
}
4545
}

substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/utils/poolparsers/ConstantPoolParser.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030
import java.util.HashSet;
3131
import java.util.Set;
3232

33+
import com.oracle.svm.core.jfr.JfrTypes;
3334
import com.oracle.svm.test.jfr.utils.JFRFileParser;
3435
import com.oracle.svm.test.jfr.utils.RecordingInput;
36+
import org.junit.Assert;
3537

3638
public abstract class ConstantPoolParser {
3739

@@ -53,18 +55,17 @@ protected final void addFoundId(long id) {
5355
foundIds.add(id);
5456
}
5557

56-
protected static void addExpectedId(long typeId, long id) {
57-
ConstantPoolParser poolParser = JFRFileParser.getSupportedConstantPools().get(typeId);
58+
protected static void addExpectedId(JfrTypes typeId, long id) {
59+
ConstantPoolParser poolParser = JFRFileParser.getSupportedConstantPools().get(typeId.getId());
5860
poolParser.expectedIds.add(id);
5961
}
6062

61-
public boolean compare() {
62-
return foundIds.size() == 0 || foundIds.containsAll(expectedIds);
63+
public void compareFoundAndExceptedIds() {
64+
Assert.assertTrue("Error during parsing " + this + " constant pool!" +
65+
" Expected IDs: " + expectedIds +
66+
". Found IDs: " + foundIds, foundIds.size() == 0 || foundIds.containsAll(expectedIds));
6367
}
6468

65-
/**
66-
* Parse the constant pool, beginning for {@code input} position.
67-
*/
6869
public abstract void parse(RecordingInput input) throws IOException;
6970

7071
@Override

substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/utils/poolparsers/MethodConstantPoolParser.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public void parse(RecordingInput input) throws IOException {
3939
int numberOfMethods = input.readInt();
4040
for (int i = 0; i < numberOfMethods; i++) {
4141
addFoundId(input.readLong()); // MethodId.
42-
addExpectedId(JfrTypes.Class.getId(), input.readLong()); // ClassId.
43-
addExpectedId(JfrTypes.Symbol.getId(), input.readLong()); // MethodName.
44-
addExpectedId(JfrTypes.Symbol.getId(), input.readLong()); // Descriptor.
42+
addExpectedId(JfrTypes.Class, input.readLong()); // ClassId.
43+
addExpectedId(JfrTypes.Symbol, input.readLong()); // MethodName.
44+
addExpectedId(JfrTypes.Symbol, input.readLong()); // Descriptor.
4545
Assert.assertTrue("Modifier value is not correct!", input.readInt() >= 0); // Modifier.
4646
input.readBoolean(); // Hidden.
4747
}

substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/utils/poolparsers/ModuleConstantPoolParser.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ public void parse(RecordingInput input) throws IOException {
3838
int numberOfModules = input.readInt();
3939
for (int i = 0; i < numberOfModules; i++) {
4040
addFoundId(input.readLong()); // ModuleId.
41-
addExpectedId(JfrTypes.Symbol.getId(), input.readLong()); // ModuleName.
42-
addExpectedId(JfrTypes.Symbol.getId(), input.readLong()); // Version.
43-
addExpectedId(JfrTypes.Symbol.getId(), input.readLong()); // Location.
44-
addExpectedId(JfrTypes.ClassLoader.getId(), input.readLong()); // ClassLoaderId.
41+
addExpectedId(JfrTypes.Symbol, input.readLong()); // ModuleName.
42+
addExpectedId(JfrTypes.Symbol, input.readLong()); // Version.
43+
addExpectedId(JfrTypes.Symbol, input.readLong()); // Location.
44+
addExpectedId(JfrTypes.ClassLoader, input.readLong()); // ClassLoaderId.
4545
}
4646
}
4747
}

substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/utils/poolparsers/NotFoundConstantPoolParser.java

Lines changed: 0 additions & 37 deletions
This file was deleted.

substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/utils/poolparsers/PackageConstantPoolParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public void parse(RecordingInput input) throws IOException {
3838
int numberOfPackages = input.readInt();
3939
for (int i = 0; i < numberOfPackages; i++) {
4040
addFoundId(input.readLong()); // PackageId.
41-
addExpectedId(JfrTypes.Symbol.getId(), input.readLong()); // PackageName.
42-
addExpectedId(JfrTypes.Module.getId(), input.readLong()); // ModuleId.
41+
addExpectedId(JfrTypes.Symbol, input.readLong()); // PackageName.
42+
addExpectedId(JfrTypes.Module, input.readLong()); // ModuleId.
4343
input.readBoolean(); // IsExported.
4444
}
4545
}

substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/utils/poolparsers/StacktraceConstantPoolParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ public void parse(RecordingInput input) throws IOException {
4141
input.readBoolean(); // IsTruncated.
4242
int stackTraceSize = input.readInt(); // StackFrameSize.
4343
for (int j = 0; j < stackTraceSize; j++) {
44-
addExpectedId(JfrTypes.Method.getId(), input.readLong()); // MethodId.
44+
addExpectedId(JfrTypes.Method, input.readLong()); // MethodId.
4545
input.readInt(); // LineNumber.
4646
input.readInt(); // Bci.
47-
addExpectedId(JfrTypes.FrameType.getId(), input.readLong()); // FrameTypeId.
47+
addExpectedId(JfrTypes.FrameType, input.readLong()); // FrameTypeId.
4848
}
4949
}
5050
}

substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/utils/poolparsers/ThreadConstantPoolParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void parse(RecordingInput input) throws IOException {
4343
Assert.assertTrue("OSThreadId is not correct!", input.readLong() >= 0); // OSThreadId.
4444
input.readUTF(); // JavaThreadName.
4545
Assert.assertTrue("JavaThreadId is not correct!", input.readLong() >= 0); // JavaThreadId.
46-
addExpectedId(JfrTypes.ThreadGroup.getId(), input.readLong()); // ThreadGroupId.
46+
addExpectedId(JfrTypes.ThreadGroup, input.readLong()); // ThreadGroupId.
4747
}
4848
}
4949
}

0 commit comments

Comments
 (0)