Skip to content

Commit

Permalink
Remove ClassLoader, Package and Module tracking from trace-ID infra
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman Kennke committed Mar 12, 2021
1 parent 91af37b commit ec7a26a
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 289 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import java.util.function.BooleanSupplier;
import java.util.function.Predicate;

import com.oracle.svm.core.annotate.Inject;
import org.graalvm.compiler.core.common.SuppressFBWarnings;
import org.graalvm.compiler.replacements.nodes.BinaryMathIntrinsicNode;
import org.graalvm.compiler.replacements.nodes.BinaryMathIntrinsicNode.BinaryOperation;
Expand Down Expand Up @@ -790,6 +791,26 @@ static void callRunnableOfThread(Thread thread) {
}
}

@TargetClass(java.lang.Package.class)
final class Target_java_lang_Package {

@Alias
@SuppressWarnings({"unused"})
Target_java_lang_Package(String name,
String spectitle, String specversion, String specvendor,
String impltitle, String implversion, String implvendor,
URL sealbase, ClassLoader loader) {
}

@Substitute
@TargetElement(onlyWith = JDK8OrEarlier.class)
private static Package getSystemPackage(String name) {
Target_java_lang_Package pkg = new Target_java_lang_Package(name, null, null, null,
null, null, null, null, null);
return SubstrateUtil.cast(pkg, Package.class);
}
}

@TargetClass(java.lang.NullPointerException.class)
final class Target_java_lang_NullPointerException {

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@

import com.oracle.svm.core.annotate.Alias;
import com.oracle.svm.core.annotate.Delete;
import com.oracle.svm.core.annotate.Inject;
import com.oracle.svm.core.annotate.RecomputeFieldValue;
import com.oracle.svm.core.annotate.RecomputeFieldValue.Kind;
import com.oracle.svm.core.annotate.Substitute;
Expand Down Expand Up @@ -187,7 +186,7 @@ private Enumeration<URL> getResources(String name) {

@TargetClass(ClassLoader.class)
@SuppressWarnings("static-method")
public final class Target_java_lang_ClassLoader {
final class Target_java_lang_ClassLoader {

/**
* This field can be safely deleted, but that would require substituting the entire constructor
Expand Down Expand Up @@ -216,10 +215,6 @@ public final class Target_java_lang_ClassLoader {
@Alias //
private static ClassLoader scl;

@Inject
@RecomputeFieldValue(kind = Kind.Custom, declClass = JfrIDRecomputation.class)
public int jfrID;

@Substitute
public static ClassLoader getSystemClassLoader() {
VMError.guarantee(scl != null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,12 @@
import java.util.List;

import com.oracle.svm.core.annotate.Delete;
import com.oracle.svm.core.annotate.Inject;
import com.oracle.svm.core.annotate.RecomputeFieldValue;
import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;
import com.oracle.svm.core.annotate.TargetElement;

@TargetClass(className = "java.lang.Module", onlyWith = JDK11OrLater.class)
public final class Target_java_lang_Module {

@Inject
@RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Custom, declClass = JfrIDRecomputation.class)
public int jfrID;

@SuppressWarnings("static-method")
@Substitute
@TargetElement(name = "getResourceAsStream")
Expand Down Expand Up @@ -96,4 +89,5 @@ public boolean canRead(Target_java_lang_Module other) {
@TargetClass(className = "java.lang.Module", innerClass = "ReflectionData", onlyWith = JDK11OrLater.class)
public static final class ReflectionData {
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,10 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.oracle.svm.core.hub.DynamicHub;
import com.oracle.svm.core.jdk.JfrIDRecomputation;
import com.oracle.svm.core.meta.SharedType;
import com.oracle.svm.jfr.traceid.JfrTraceId;
import com.oracle.svm.jfr.traceid.JfrTraceIdMap;
Expand Down Expand Up @@ -122,75 +119,34 @@ public void beforeAnalysis(Feature.BeforeAnalysisAccess access) {
runtime.addShutdownHook(manager::teardown);
}

private static class JfrMetadataCollection {
final Map<Class<?>, Integer> classToIndex = new HashMap<>();
final Set<Package> packages = new HashSet<>();
final Set<Module> modules = new HashSet<>();
final Set<ClassLoader> classLoaders = new HashSet<>();
int mapSize = 1; // First field is error-catcher
}

private void assignClass(JfrMetadataCollection metadata, Class<?> clazz, int id) {
metadata.classToIndex.put(clazz, id);
metadata.mapSize++;
Package pkg = clazz.getPackage();
if (pkg != null && !metadata.packages.contains(pkg)) {
metadata.packages.add(pkg);
metadata.mapSize++;
}
Module module = clazz.getModule();
if (module != null && !metadata.modules.contains(module)) {
metadata.modules.add(module);
metadata.mapSize++;
}
ClassLoader cl = clazz.getClassLoader();
if (cl != null && !metadata.classLoaders.contains(cl)) {
metadata.classLoaders.add(cl);
metadata.mapSize++;
}
}

@Override
public void beforeCompilation(BeforeCompilationAccess a) {

final JfrMetadataCollection metadata = new JfrMetadataCollection();
Map<Class<?>, Integer> classToIndex = new HashMap<>();

// Scan all classes and build sets of packages, modules and class-loaders. Count all items.
Collection<? extends SharedType> types = ((FeatureImpl.CompilationAccessImpl) a).getTypes();
int mapSize = 1; // Reserve slot 0 for error-catcher.
for (SharedType type : types) {
DynamicHub hub = type.getHub();
assignClass(metadata, hub.getHostedJavaClass(), hub.getTypeID());
classToIndex.put(hub.getHostedJavaClass(), hub.getTypeID());
mapSize++;
}

// Create trace-ID map with fixed size.
JfrTraceIdMap map = new JfrTraceIdMap(metadata.mapSize);
JfrTraceIdMap map = new JfrTraceIdMap(mapSize);
ImageSingletons.lookup(JfrRuntimeAccess.class).setTraceIdMap(map);

// Assign each class, package, module and class-loader a unique index.
int idx = metadata.classToIndex.size() + 1;
for (Class<?> clazz : metadata.classToIndex.keySet()) {
if (metadata.classToIndex.get(clazz) + 1 >= idx) {
int idx = classToIndex.size() + 1;
for (Class<?> clazz : classToIndex.keySet()) {
if (classToIndex.get(clazz) + 1 >= idx) {
throw new ArrayIndexOutOfBoundsException();
}
if (!clazz.isPrimitive()) {
JfrTraceId.assign(clazz, metadata.classToIndex);
JfrTraceId.assign(clazz, classToIndex);
}
}
long traceId = 0;
for (Package pkg : metadata.packages) {
JfrIDRecomputation.setJfrID(pkg, idx);
JfrTraceId.assign(pkg, idx++, traceId++);
}
traceId = 0;
for (Module module : metadata.modules) {
JfrIDRecomputation.setJfrID(module, idx);
JfrTraceId.assign(module, idx++, traceId++);
}
traceId = 0;
for (ClassLoader cl : metadata.classLoaders) {
JfrIDRecomputation.setJfrID(cl, idx);
JfrTraceId.assign(cl, idx++, traceId++);
}

// TODO: get the method count
int methodCount = 0;
Expand Down
Loading

0 comments on commit ec7a26a

Please sign in to comment.