Skip to content

Commit

Permalink
[GR-46073] Injecting a field breaks automatic substitutions.
Browse files Browse the repository at this point in the history
PullRequest: graal/14540
  • Loading branch information
peter-hofer committed May 10, 2023
2 parents 0017f25 + a66ac17 commit 431ecf7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,24 +239,22 @@ public Optional<ResolvedJavaField> findSubstitution(ResolvedJavaField field) {
return Optional.ofNullable(fieldSubstitutions.get(field));
}

public Optional<ResolvedJavaType> findSubstitution(ResolvedJavaType type) {
public Optional<ResolvedJavaType> findFullSubstitution(ResolvedJavaType type) {
/*
* When a type is substituted there is a mapping from the original type to the substitution
* type (and another mapping from the annotated type to the substitution type).
*/
return Optional.ofNullable(findTypeSubstitution(type));
ResolvedJavaType subst = findTypeSubstitution(type);
return (subst instanceof SubstitutionType) ? Optional.of(subst) : Optional.empty();
}

public boolean isAliased(ResolvedJavaType type) {
/*
* When a type is aliased there is a mapping from the alias type to the original type. There
* is no mapping from the original type to the annotated type since that would be wrong, the
* original type is not substituted by the annotated type.
*
* If the type is an array type then it's alias is constructed on demand, but there should
* be a mapping from the aliased component type to the original component type.
* When a type is aliased there is a mapping from the alias type to the original type. If
* the type is an array type then its alias is constructed on demand, but there should be a
* mapping from the aliased component type to the original component type.
*/
if (type instanceof SubstitutionType || type instanceof InjectedFieldsType) {
if (type instanceof SubstitutionType) {
return false;
}
return typeSubstitutions.containsValue(type) || typeSubstitutions.containsValue(type.getElementalType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.Arrays;

import com.oracle.graal.pointsto.infrastructure.OriginalClassProvider;
import com.oracle.svm.core.annotate.Inject;
import com.oracle.svm.core.util.VMError;
import com.oracle.svm.hosted.annotation.AnnotationWrapper;

Expand All @@ -39,6 +40,12 @@
import jdk.vm.ci.meta.ResolvedJavaMethod;
import jdk.vm.ci.meta.ResolvedJavaType;

/**
* Type which {@linkplain Inject injects} individual members into its original type (and can alias
* or delete other members).
*
* @see SubstitutionType
*/
public class InjectedFieldsType implements ResolvedJavaType, OriginalClassProvider, AnnotationWrapper {

private final ResolvedJavaType original;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Arrays;

import com.oracle.graal.pointsto.infrastructure.OriginalClassProvider;
import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.util.VMError;
import com.oracle.svm.hosted.annotation.AnnotationWrapper;

Expand All @@ -40,6 +41,11 @@
import jdk.vm.ci.meta.ResolvedJavaMethod;
import jdk.vm.ci.meta.ResolvedJavaType;

/**
* Type which fully substitutes its original type, i.e. @{@link Substitute} on the class level.
*
* @see InjectedFieldsType
*/
public class SubstitutionType implements ResolvedJavaType, OriginalClassProvider, AnnotationWrapper {

private final ResolvedJavaType original;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public void computeSubstitutions(SVMHost hostVM, ResolvedJavaType hostType) {
return;
}

if (annotationSubstitutions.findSubstitution(hostType).isPresent()) {
if (annotationSubstitutions.findFullSubstitution(hostType).isPresent()) {
/* If the class is substituted clinit will be eliminated, so bail early. */
reportSkippedSubstitution(hostType);
return;
Expand Down Expand Up @@ -1108,8 +1108,8 @@ private void reportUnsuccessfulAutomaticRecomputation(ResolvedJavaType type, Res
} else if (isAliased(type)) {
msg += "is aliased";
} else {
ResolvedJavaType substitutionType = findSubstitutionType(type);
msg += "is substituted by " + substitutionType.toJavaName();
ResolvedJavaType substitutionType = findFullSubstitutionType(type);
msg += "is fully substituted by " + substitutionType.toJavaName();
}
msg += ".)";
}
Expand Down Expand Up @@ -1138,15 +1138,15 @@ private static String kindAsString(Kind substitutionKind) {
}

private boolean suppressWarningsFor(ResolvedJavaType type) {
return warningsAreWhiteListed(type) || isAliased(type) || findSubstitutionType(type) != null;
return warningsAreWhiteListed(type) || isAliased(type) || findFullSubstitutionType(type) != null;
}

private boolean warningsAreWhiteListed(ResolvedJavaType type) {
return suppressWarnings.contains(type);
}

private ResolvedJavaType findSubstitutionType(ResolvedJavaType type) {
Optional<ResolvedJavaType> substTypeOptional = annotationSubstitutions.findSubstitution(type);
private ResolvedJavaType findFullSubstitutionType(ResolvedJavaType type) {
Optional<ResolvedJavaType> substTypeOptional = annotationSubstitutions.findFullSubstitution(type);
return substTypeOptional.orElse(null);
}

Expand Down

0 comments on commit 431ecf7

Please sign in to comment.