Skip to content
Closed
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 @@ -397,7 +397,6 @@ public boolean add(String s) {
verifiers.add(new VerifyLoopInfo());
verifiers.add(new VerifyGuardsStageUsages());
verifiers.add(new VerifyAArch64RegisterUsages());
verifiers.add(new VerifyAnnotatedElementUsage());
VerifyAssertionUsage assertionUsages = null;
boolean checkAssertions = tool.checkAssertions();

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
import com.oracle.svm.shared.util.ReflectionUtil;
import com.oracle.svm.shared.util.StringUtil;
import com.oracle.svm.shared.util.VMError;
import com.oracle.svm.util.AnnotationUtil;
import com.oracle.svm.util.HostedModuleSupport;

import jdk.graal.compiler.debug.GraalError;
Expand Down Expand Up @@ -281,6 +282,7 @@ public boolean dynamicAccessSelectorsEmpty() {
modulepathModuleFinder = ModuleFinder.of(modulepath().toArray(Path[]::new));

annotationExtractor = new SubstrateAnnotationExtractor();
AnnotationUtil.installHostedAnnotationExtractor(annotationExtractor);

includeConfigSealed = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@
import java.util.function.Function;

import org.graalvm.nativeimage.ImageInfo;
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;
import org.graalvm.nativeimage.impl.AnnotationExtractor;
import org.graalvm.nativeimage.impl.ImageSingletonsSupport;

import com.oracle.svm.shared.util.ModuleSupport;

Expand All @@ -54,8 +52,7 @@
/**
* This complements {@link org.graalvm.nativeimage.AnnotationAccess} for use by SVM internal
* features and code. It avoids relying on JVMCI types (such as {@link ResolvedJavaType})
* implementing {@link java.lang.reflect.AnnotatedElement}. This inheritance is planned for removal
* (GR-69713) as part of reducing use of core reflection in Native Image.
* implementing {@link java.lang.reflect.AnnotatedElement}.
*/
public final class AnnotationUtil {

Expand All @@ -80,15 +77,38 @@ static class Lazy {
@Platforms(Platform.HOSTED_ONLY.class) //
private static Boolean instanceIsSingleton;

/**
* The hosted image builder creates the {@link AnnotationExtractor} before publishing it
* globally. Registering it here avoids transient fallback to {@link Lazy} in that startup
* window.
*/
@Platforms(Platform.HOSTED_ONLY.class) //
private static AnnotatedObjectAccess hostedAnnotationExtractor;

/*
* These accesses do not need synchronization: the hosted extractor is installed during the
* single-threaded image-builder bootstrap, and the fallback path only publishes immutable
* singletons while rejecting any attempt to mix the hosted and lazy variants in one VM.
*/
@Platforms(Platform.HOSTED_ONLY.class)
public static void installHostedAnnotationExtractor(AnnotatedObjectAccess extractor) {
Objects.requireNonNull(extractor);
if (instanceIsSingleton == null) {
instanceIsSingleton = true;
} else if (!instanceIsSingleton) {
throw new GraalError(Lazy.initLocation, "Cannot use image singleton AnnotatedObjectAccess after Lazy.instance initialized");
}
GraalError.guarantee(hostedAnnotationExtractor == null || hostedAnnotationExtractor == extractor,
"Conflicting hosted AnnotatedObjectAccess instances");
hostedAnnotationExtractor = extractor;
}

@Platforms(Platform.HOSTED_ONLY.class)
private static AnnotatedObjectAccess instance() {
if (ImageSingletonsSupport.isInstalled() && ImageSingletons.contains(AnnotationExtractor.class)) {
if (instanceIsSingleton == null) {
instanceIsSingleton = true;
} else if (!instanceIsSingleton) {
throw new GraalError(Lazy.initLocation, "Cannot use image singleton AnnotatedObjectAccess after Lazy.instance initialized");
}
return (AnnotatedObjectAccess) ImageSingletons.lookup(AnnotationExtractor.class);
if (hostedAnnotationExtractor != null) {
GraalError.guarantee(instanceIsSingleton == null || instanceIsSingleton, "Cannot use image singleton AnnotatedObjectAccess and Lazy.instance in one process");
instanceIsSingleton = true;
return hostedAnnotationExtractor;
}
// Fall back to singleton when no AnnotationExtractor singleton is available (e.g.,
// running `mx unittest com.oracle.graal.pointsto.standalone.test`).
Expand Down