Skip to content

Commit

Permalink
Fix writing of unnamed module (oracle#24)
Browse files Browse the repository at this point in the history
* Fix writing of unnamed module

* Ignore empty package; serialize null-class-loader as 'bootstrap'

* Fix checkstyle complaint

* Handle null string in JfrSymbolRepository as 0 ID/reference

* Don't special-case 'null' module name, serialize it as 0
  • Loading branch information
Roman Kennke authored Apr 30, 2021
1 parent 864e7d2 commit df7062a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ public long getSymbolId(String imageHeapString, boolean previousEpoch) {

@Uninterruptible(reason = "Epoch must not change while in this method.")
public long getSymbolId(String imageHeapString, boolean previousEpoch, boolean replaceDotWithSlash) {

if (imageHeapString == null) {
return 0;
}

assert Heap.getHeap().isInImageHeap(imageHeapString);

JfrSymbol symbol = StackValue.get(JfrSymbol.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private void visitClass(TypeInfo typeInfo, Class<?> clazz) {
}

private void visitPackage(TypeInfo typeInfo, Package pkg, Module module) {
if (pkg != null && typeInfo.addPackage(pkg, module)) {
if (pkg != null && !"".equals(pkg.getName()) && typeInfo.addPackage(pkg, module)) {
visitModule(typeInfo, module);
}
}
Expand All @@ -176,7 +176,8 @@ private void visitModule(TypeInfo typeInfo, Module module) {
}

private void visitClassLoader(TypeInfo typeInfo, ClassLoader classLoader) {
if (classLoader != null && typeInfo.addClassLoader(classLoader)) {
// Note: null class-loader is ok, we serialize it as "bootstrap" class-loader.
if (typeInfo.addClassLoader(classLoader) && classLoader != null) {
visitClass(typeInfo, classLoader.getClass());
}
}
Expand Down Expand Up @@ -244,8 +245,8 @@ private void writeModule(JfrChunkWriter writer, TypeInfo typeInfo, Module module
JfrSymbolRepository symbolRepo = SubstrateJVM.getSymbolRepository();
writer.writeCompressedLong(id);
writer.writeCompressedLong(symbolRepo.getSymbolId(module.getName(), true));
writer.writeCompressedLong(0); // Version?
writer.writeCompressedLong(0); // Location?
writer.writeCompressedLong(0); // Version? E.g. "11.0.10-internal"
writer.writeCompressedLong(0); // Location? E.g. "jrt:/java.base"
writer.writeCompressedLong(typeInfo.getClassLoaderId(module.getClassLoader()));
}

Expand All @@ -267,7 +268,12 @@ private int writeClassLoaders(JfrChunkWriter writer, TypeInfo typeInfo) throws I
private void writeClassLoader(JfrChunkWriter writer, ClassLoader cl, long id) throws IOException {
JfrSymbolRepository symbolRepo = SubstrateJVM.getSymbolRepository();
writer.writeCompressedLong(id);
writer.writeCompressedLong(JfrTraceId.getTraceId(cl.getClass()));
writer.writeCompressedLong(symbolRepo.getSymbolId(cl.getName(), true));
if (cl == null) {
writer.writeCompressedLong(0);
writer.writeCompressedLong(symbolRepo.getSymbolId("bootstrap", true));
} else {
writer.writeCompressedLong(JfrTraceId.getTraceId(cl.getClass()));
writer.writeCompressedLong(symbolRepo.getSymbolId(cl.getName(), true));
}
}
}

0 comments on commit df7062a

Please sign in to comment.