Skip to content

Commit

Permalink
[GR-34003] Simplified metadata for non-reflection methods
Browse files Browse the repository at this point in the history
PullRequest: graal/9998
  • Loading branch information
loicottet committed Nov 9, 2021
2 parents a586f37 + 557ce47 commit 7b5f831
Show file tree
Hide file tree
Showing 41 changed files with 1,585 additions and 1,257 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,6 @@ public void addObject(T object) {
entry.frequency++;
}

/**
* Returns whether the given object has been previously added to the array.
*/
public boolean contains(T object) {
if (object == null && containsNull) {
return true;
}
Entry<T> entry = map.get(object);
return entry != null;
}

/**
* Returns the index of an object in the array. The object must have been
* {@link #addObject(Object) added} before.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,10 @@
public interface RuntimeReflectionSupport extends ReflectionRegistry {
// specific to java.lang.reflect reflection
Set<Executable> getQueriedOnlyMethods();

/*
* Returns the methods that shadow a superclass method registered for reflection, to be excluded
* from reflection queries.
*/
Set<?> getHidingMethods();
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,44 +40,22 @@ static Executable getJavaMethod(SnippetReflectionProvider reflectionProvider, Re
return ((OriginalMethodProvider) method).getJavaMethod();
}
try {
return getJavaMethodInternal(reflectionProvider, method);
ResolvedJavaMethod.Parameter[] parameters = method.getParameters();
Class<?>[] parameterTypes = new Class<?>[parameters.length];
ResolvedJavaType declaringClassType = method.getDeclaringClass();
for (int i = 0; i < parameterTypes.length; i++) {
parameterTypes[i] = OriginalClassProvider.getJavaClass(reflectionProvider, parameters[i].getType().resolve(declaringClassType));
}
Class<?> declaringClass = OriginalClassProvider.getJavaClass(reflectionProvider, declaringClassType);
if (method.isConstructor()) {
return declaringClass.getDeclaredConstructor(parameterTypes);
} else {
return declaringClass.getDeclaredMethod(method.getName(), parameterTypes);
}
} catch (NoSuchMethodException e) {
throw AnalysisError.shouldNotReachHere();
}
}

static boolean hasJavaMethod(SnippetReflectionProvider reflectionProvider, ResolvedJavaMethod method) {
if (method instanceof OriginalMethodProvider) {
return ((OriginalMethodProvider) method).hasJavaMethod();
}
try {
getJavaMethodInternal(reflectionProvider, method);
return true;
} catch (NoSuchMethodException | LinkageError | RuntimeException e) {
/*
* These exceptions may happen anytime during the lookup, so we can't simply use the
* result of getJavaMethodInternal.
*/
return false;
}
}

static Executable getJavaMethodInternal(SnippetReflectionProvider reflectionProvider, ResolvedJavaMethod method) throws NoSuchMethodException {
ResolvedJavaMethod.Parameter[] parameters = method.getParameters();
Class<?>[] parameterTypes = new Class<?>[parameters.length];
ResolvedJavaType declaringClassType = method.getDeclaringClass();
for (int i = 0; i < parameterTypes.length; i++) {
parameterTypes[i] = OriginalClassProvider.getJavaClass(reflectionProvider, parameters[i].getType().resolve(declaringClassType));
}
Class<?> declaringClass = OriginalClassProvider.getJavaClass(reflectionProvider, declaringClassType);
if (method.isConstructor()) {
return declaringClass.getDeclaredConstructor(parameterTypes);
} else {
return declaringClass.getDeclaredMethod(method.getName(), parameterTypes);
}
}

Executable getJavaMethod();

boolean hasJavaMethod();
}
Original file line number Diff line number Diff line change
Expand Up @@ -554,11 +554,6 @@ public Executable getJavaMethod() {
return OriginalMethodProvider.getJavaMethod(universe.getOriginalSnippetReflection(), wrapped);
}

@Override
public boolean hasJavaMethod() {
return OriginalMethodProvider.hasJavaMethod(universe.getOriginalSnippetReflection(), wrapped);
}

/**
* Unique, per method, context insensitive invoke. The context insensitive invoke uses the
* receiver type of the method, i.e., its declaring class. Therefore this invoke will link with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,6 @@ public Object replaceObject(Object source) {

private void collectMethodImplementations() {
for (AnalysisMethod method : methods.values()) {

Set<AnalysisMethod> implementations = getMethodImplementations(bb, method, false);
method.implementations = implementations.toArray(new AnalysisMethod[implementations.size()]);
}
Expand Down Expand Up @@ -613,7 +612,13 @@ private static boolean collectMethodImplementations(AnalysisMethod method, Analy
* method. The method cannot be marked as invoked.
*/
if (holderOrSubtypeInstantiated || method.isIntrinsicMethod()) {
AnalysisMethod aResolved = holder.resolveConcreteMethod(method, null);
AnalysisMethod aResolved;
try {
aResolved = holder.resolveConcreteMethod(method, null);
} catch (UnsupportedFeatureException e) {
/* An unsupported overriding method is not reachable. */
aResolved = null;
}
if (aResolved != null) {
/*
* aResolved == null means that the method in the base class was called, but never
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ void doTest() {
Assert.assertNotNull("Generated configuration type " + name + " does not exist. Has the test code changed?", configurationType);

for (Map.Entry<ConfigurationMethod, ConfigurationMemberDeclaration> methodEntry : methodsThatMustExist.entrySet()) {
ConfigurationMemberDeclaration kind = ConfigurationType.TestBackdoor.getMethodInfoIfPresent(configurationType, methodEntry.getKey()).getMemberKind();
ConfigurationMemberDeclaration kind = ConfigurationType.TestBackdoor.getMethodInfoIfPresent(configurationType, methodEntry.getKey()).getDeclaration();
Assert.assertNotNull("Method " + methodEntry.getKey() + " unexpectedly NOT found in the new configuration.", kind);
Assert.assertEquals("Method " + methodEntry.getKey() + " contains a different kind than expected in the new configuration.", kind, methodEntry.getValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ public final class ConfigurationMemberInfo {
}
}

private final ConfigurationMemberDeclaration memberKind;
private final ConfigurationMemberAccessibility accessKind;
private final ConfigurationMemberDeclaration declaration;
private final ConfigurationMemberAccessibility accessibility;

private ConfigurationMemberInfo(ConfigurationMemberDeclaration memberKind, ConfigurationMemberAccessibility accessKind) {
this.memberKind = memberKind;
this.accessKind = accessKind;
private ConfigurationMemberInfo(ConfigurationMemberDeclaration declaration, ConfigurationMemberAccessibility accessibility) {
this.declaration = declaration;
this.accessibility = accessibility;
}

public ConfigurationMemberDeclaration getMemberKind() {
return memberKind;
public ConfigurationMemberDeclaration getDeclaration() {
return declaration;
}

public ConfigurationMemberAccessibility getAccessKind() {
return accessKind;
public ConfigurationMemberAccessibility getAccessibility() {
return accessibility;
}

public static ConfigurationMemberInfo get(ConfigurationMemberDeclaration memberKind, ConfigurationMemberAccessibility accessKind) {
Expand Down Expand Up @@ -103,8 +103,19 @@ public boolean includes(ConfigurationMemberDeclaration other) {
}

public enum ConfigurationMemberAccessibility {
/**
* The member is not accessed reflectively.
*/
NONE,

/**
* The member is queried reflectively but never invoked (only for methods and constructors).
*/
QUERIED,

/**
* The member is fully accessed reflectively.
*/
ACCESSED;

public ConfigurationMemberAccessibility combine(ConfigurationMemberAccessibility other) {
Expand All @@ -121,14 +132,14 @@ public boolean includes(ConfigurationMemberAccessibility other) {
}

public ConfigurationMemberInfo intersect(ConfigurationMemberInfo other) {
return get(memberKind.intersect(other.memberKind), accessKind.combine(other.accessKind));
return get(declaration.intersect(other.declaration), accessibility.combine(other.accessibility));
}

public ConfigurationMemberInfo union(ConfigurationMemberInfo other) {
return get(memberKind.union(other.memberKind), accessKind.combine(other.accessKind));
return get(declaration.union(other.declaration), accessibility.combine(other.accessibility));
}

public boolean includes(ConfigurationMemberInfo other) {
return memberKind.includes(other.memberKind) && accessKind.includes(other.accessKind);
return declaration.includes(other.declaration) && accessibility.includes(other.accessibility);
}
}
Loading

0 comments on commit 7b5f831

Please sign in to comment.