Skip to content

Commit

Permalink
[GR-50385] Include all reflection queries for registered classes
Browse files Browse the repository at this point in the history
PullRequest: graal/16234
  • Loading branch information
loicottet committed Jun 5, 2024
2 parents 9c0f742 + 3fc9b9a commit 9f1232f
Show file tree
Hide file tree
Showing 20 changed files with 256 additions and 193 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

import org.graalvm.collections.EconomicMap;
import org.graalvm.collections.Equivalence;
Expand Down Expand Up @@ -71,6 +72,14 @@ public static <T> FrequencyEncoder<T> createEqualityEncoder() {
return new FrequencyEncoder<>(EconomicMap.create(Equivalence.DEFAULT));
}

/*
* Creates an encoder that uses {@link Object#equals(Object)} object equality and calls the
* provided verifier before adding an element.
*/
public static <T> FrequencyEncoder<T> createVerifyingEqualityEncoder(Consumer<T> verifier) {
return new VerifyingFrequencyEncoder<>(EconomicMap.create(Equivalence.DEFAULT), verifier);
}

protected FrequencyEncoder(EconomicMap<T, Entry<T>> map) {
this.map = map;
}
Expand Down Expand Up @@ -159,4 +168,19 @@ public T[] encodeAll(T[] allObjects) {
encoded = true;
return allObjects;
}

static class VerifyingFrequencyEncoder<T> extends FrequencyEncoder<T> {
private final Consumer<T> verifier;

VerifyingFrequencyEncoder(EconomicMap<T, Entry<T>> map, Consumer<T> verifier) {
super(map);
this.verifier = verifier;
}

@Override
public boolean addObject(T object) {
verifier.accept(object);
return super.addObject(object);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,10 @@ protected int onLoadCallback(JNIJavaVM vm, JvmtiEnv jvmti, JvmtiEventCallbacks c
}
}

if (tracer != null) {
tracer.traceTrackReflectionMetadata(trackReflectionMetadata);
}

try {
BreakpointInterceptor.onLoad(jvmti, callbacks, tracer, this, interceptedStateSupplier,
experimentalClassLoaderSupport, experimentalClassDefineSupport, experimentalUnsafeAllocationSupport, trackReflectionMetadata);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ public void tracePhaseChange(String phase) {
traceEntry(entry);
}

public void traceTrackReflectionMetadata(boolean trackReflectionMetadata) {
EconomicMap<String, Object> entry = EconomicMap.create();
entry.put("tracer", "meta");
entry.put("event", "track_reflection_metadata");
entry.put("track", trackReflectionMetadata);
traceEntry(entry);
}

/**
* Trace a call to a function or method. {@link Object} arguments are represented as strings by
* calling {@link Object#toString()} on them unless they are {@link #EXPLICIT_NULL},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,13 @@ private static void doTestExpectedMissingTypes(TypeConfiguration typeConfig) {

private static void doTestTypeFlags(TypeConfiguration typeConfig) {
ConfigurationType flagTestHasDeclaredType = getConfigTypeOrFail(typeConfig, "FlagTestC");
Assert.assertTrue(ConfigurationType.TestBackdoor.haveAllDeclaredClasses(flagTestHasDeclaredType) || ConfigurationType.TestBackdoor.haveAllDeclaredFields(flagTestHasDeclaredType) ||
Assert.assertTrue(ConfigurationType.TestBackdoor.haveAllDeclaredClasses(flagTestHasDeclaredType) ||
ConfigurationType.TestBackdoor.getAllDeclaredFields(flagTestHasDeclaredType) == ConfigurationMemberAccessibility.ACCESSED ||
ConfigurationType.TestBackdoor.getAllDeclaredConstructors(flagTestHasDeclaredType) == ConfigurationMemberAccessibility.ACCESSED);

ConfigurationType flagTestHasPublicType = getConfigTypeOrFail(typeConfig, "FlagTestD");
Assert.assertTrue(ConfigurationType.TestBackdoor.haveAllPublicClasses(flagTestHasPublicType) || ConfigurationType.TestBackdoor.haveAllPublicFields(flagTestHasPublicType) ||
Assert.assertTrue(ConfigurationType.TestBackdoor.haveAllPublicClasses(flagTestHasPublicType) ||
ConfigurationType.TestBackdoor.getAllPublicFields(flagTestHasPublicType) == ConfigurationMemberAccessibility.ACCESSED ||
ConfigurationType.TestBackdoor.getAllPublicConstructors(flagTestHasPublicType) == ConfigurationMemberAccessibility.ACCESSED);
}

Expand Down Expand Up @@ -281,13 +283,13 @@ void setFlags(ConfigurationType config) {
config.setAllDeclaredClasses();
config.setAllDeclaredConstructors(ConfigurationMemberAccessibility.ACCESSED);
config.setAllDeclaredMethods(ConfigurationMemberAccessibility.ACCESSED);
config.setAllDeclaredFields();
config.setAllDeclaredFields(ConfigurationMemberAccessibility.ACCESSED);
}
if (methodKind.equals(ConfigurationMemberDeclaration.PUBLIC) || methodKind.equals(ConfigurationMemberDeclaration.DECLARED_AND_PUBLIC)) {
config.setAllPublicClasses();
config.setAllPublicConstructors(ConfigurationMemberAccessibility.ACCESSED);
config.setAllPublicMethods(ConfigurationMemberAccessibility.ACCESSED);
config.setAllPublicFields();
config.setAllPublicFields(ConfigurationMemberAccessibility.ACCESSED);
}
}

Expand Down
Loading

0 comments on commit 9f1232f

Please sign in to comment.