Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,5 @@ public interface AnnotationExtractor {

<T extends Annotation> T extractAnnotation(AnnotatedElement element, Class<T> annotationType, boolean declaredOnly);

Annotation[] extractAnnotations(AnnotatedElement element, boolean declaredOnly);

Class<? extends Annotation>[] getAnnotationTypes(AnnotatedElement element);
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,6 @@ public <T extends Annotation> T extractAnnotation(AnnotatedElement element, Clas
}
}

@Override
public Annotation[] extractAnnotations(AnnotatedElement element, boolean declaredOnly) {
if (declaredOnly) {
return element.getDeclaredAnnotations();
} else {
return element.getAnnotations();
}
}

@SuppressWarnings("unchecked")
@Override
public Class<? extends Annotation>[] getAnnotationTypes(AnnotatedElement element) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.function.BiConsumer;
import java.util.function.Consumer;

import org.graalvm.compiler.debug.GraalError;
import org.graalvm.nativeimage.hosted.Feature.DuringAnalysisAccess;

import com.oracle.graal.pointsto.ObjectScanner;
Expand Down Expand Up @@ -68,12 +69,12 @@ public final <T extends Annotation> T getDeclaredAnnotation(Class<T> annotationC

@Override
public final Annotation[] getAnnotations() {
return getUniverse().getAnnotationExtractor().extractAnnotations(getWrapped(), false);
throw GraalError.shouldNotReachHere("Getting all annotations is not supported because it initializes all annotation classes and their dependencies");
}

@Override
public final Annotation[] getDeclaredAnnotations() {
return getUniverse().getAnnotationExtractor().extractAnnotations(getWrapped(), true);
throw GraalError.shouldNotReachHere("Getting all annotations is not supported because it initializes all annotation classes and their dependencies");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.impl.AnnotationExtractor;

import com.oracle.svm.core.util.VMError;

public interface AnnotationWrapper extends AnnotatedElement {
AnnotatedElement getAnnotationRoot();

Expand All @@ -54,11 +56,11 @@ default <T extends Annotation> T getDeclaredAnnotation(Class<T> annotationClass)

@Override
default Annotation[] getAnnotations() {
return ImageSingletons.lookup(AnnotationExtractor.class).extractAnnotations(this, false);
throw VMError.shouldNotReachHere("Getting all annotations is not supported because it initializes all annotation classes and their dependencies");
}

@Override
default Annotation[] getDeclaredAnnotations() {
return ImageSingletons.lookup(AnnotationExtractor.class).extractAnnotations(this, true);
throw VMError.shouldNotReachHere("Getting all annotations is not supported because it initializes all annotation classes and their dependencies");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@
*
* The {@link SubstrateAnnotationExtractor} is tightly coupled with {@link AnnotationAccess}, which
* provides implementations of {@link AnnotatedElement#isAnnotationPresent(Class)} and
* {@link AnnotatedElement#getAnnotation(Class)}. {@link AnnotatedElement#getAnnotations()} should
* in principle not be used during Native Image generation.
* {@link AnnotatedElement#getAnnotation(Class)}. {@link AnnotatedElement#getAnnotations()} must
* never be used during Native Image generation because it initializes all annotation classes and
* their dependencies.
*/
public class SubstrateAnnotationExtractor implements AnnotationExtractor {
private final Map<Class<?>, AnnotationValue[]> annotationCache = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -166,11 +167,6 @@ public Class<? extends Annotation>[] getAnnotationTypes(AnnotatedElement element
return Arrays.stream(getAnnotationData(element, false)).map(AnnotationValue::getType).filter(t -> t != null).toArray(Class[]::new);
}

@Override
public Annotation[] extractAnnotations(AnnotatedElement element, boolean declaredOnly) {
return Arrays.stream(getAnnotationData(element, declaredOnly)).map(v -> v.get(v.type)).toArray(Annotation[]::new);
}

public AnnotationValue[] getDeclaredAnnotationData(AnnotatedElement element) {
return getAnnotationData(element, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;

import com.oracle.svm.core.util.VMError;

public abstract class HostedElement implements AnnotatedElement {

protected abstract AnnotatedElement getWrapped();
Expand All @@ -48,11 +50,11 @@ public final <T extends Annotation> T getDeclaredAnnotation(Class<T> annotationC

@Override
public final Annotation[] getAnnotations() {
return getWrapped().getAnnotations();
throw VMError.shouldNotReachHere("Getting all annotations is not supported because it initializes all annotation classes and their dependencies");
}

@Override
public final Annotation[] getDeclaredAnnotations() {
return getWrapped().getDeclaredAnnotations();
throw VMError.shouldNotReachHere("Getting all annotations is not supported because it initializes all annotation classes and their dependencies");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ private static void initializeTruffleLibrariesAtBuildTime(AnalysisType type) {
/* Trigger computation of uncachedDispatch. */
factory.getUncached();
}
if (type.getDeclaredAnnotationsByType(ExportLibrary.class).length != 0) {
if (type.isAnnotationPresent(ExportLibrary.class) || type.isAnnotationPresent(ExportLibrary.Repeat.class)) {
/* Eagerly resolve receiver type. */
invokeStaticMethod("com.oracle.truffle.api.library.LibraryFactory$ResolvedDispatch", "lookup",
Collections.singleton(Class.class), type.getJavaClass());
Expand Down