Skip to content

Commit

Permalink
[GR-6661] Add annotation arrays to the image.
Browse files Browse the repository at this point in the history
PullRequest: graal/820
  • Loading branch information
vjovanov committed Dec 29, 2017
2 parents 39557dc + a1cffc9 commit 66a2f6c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

import com.oracle.graal.pointsto.infrastructure.OriginalClassProvider;
import org.graalvm.compiler.graph.Node;
import org.graalvm.word.WordBase;

Expand All @@ -53,6 +52,7 @@
import com.oracle.graal.pointsto.flow.TypeFlow;
import com.oracle.graal.pointsto.flow.context.object.AnalysisObject;
import com.oracle.graal.pointsto.flow.context.object.ConstantContextSensitiveObject;
import com.oracle.graal.pointsto.infrastructure.OriginalClassProvider;
import com.oracle.graal.pointsto.infrastructure.WrappedJavaType;
import com.oracle.graal.pointsto.typestate.TypeState;

Expand Down Expand Up @@ -963,4 +963,12 @@ public boolean equals(Object obj) {
return this == obj;
}

/* Value copied from java.lang.Class. */
private static final int ANNOTATION = 0x00002000;

/* Method copied from java.lang.Class. */
public boolean isAnnotation() {
return (getModifiers() & ANNOTATION) != 0;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public JavaType lookupAllowUnresolved(JavaType rawType) {
if (!(rawType instanceof ResolvedJavaType)) {
return rawType;
}
assert !(rawType instanceof AnalysisType);
assert !(rawType instanceof AnalysisType) : "lookupAllowUnresolved does not support analysis types.";

ResolvedJavaType type = (ResolvedJavaType) rawType;
type = substitutions.lookup(type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.util.EconomicSet;

import com.oracle.graal.pointsto.meta.AnalysisType;
import com.oracle.graal.pointsto.meta.AnalysisUniverse;
import com.oracle.svm.core.annotate.AutomaticFeature;
import com.oracle.svm.core.hub.AnnotationTypeSupport;
Expand All @@ -56,7 +57,23 @@ public void afterRegistration(AfterRegistrationAccess access) {

@Override
public void duringAnalysis(DuringAnalysisAccess access) {
AnalysisUniverse universe = ((DuringAnalysisAccessImpl) access).getUniverse();
DuringAnalysisAccessImpl accessImpl = (DuringAnalysisAccessImpl) access;
AnalysisUniverse universe = accessImpl.getUniverse();

/*
* JDK implementation of repeatable annotations always instantiates an array of a requested
* annotation. We need to mark arrays of all reachable annotations as in heap.
*/
universe.getTypes().stream()
.filter(AnalysisType::isAnnotation)
.filter(AnalysisType::isInTypeCheck)
.map(type -> universe.lookup(type.getWrapped()).getArrayClass())
.filter(annotationArray -> !annotationArray.isInstantiated())
.forEach(annotationArray -> {
accessImpl.registerAsInHeap(annotationArray);
access.requireAnalysisIteration();
});

Stream<AnnotatedElement> allElements = Stream.concat(Stream.concat(universe.getFields().stream(), universe.getMethods().stream()), universe.getTypes().stream());
Stream<AnnotatedElement> newElements = allElements.filter(visitedElements::add);
newElements.forEach(this::reportAnnotation);
Expand Down

0 comments on commit 66a2f6c

Please sign in to comment.