Skip to content

Commit a1f8dd2

Browse files
author
Christian Wimmer
committed
[GR-45627] Remove obsolete annotation support.
PullRequest: graal/14341
2 parents 03b59f2 + 155ba6e commit a1f8dd2

14 files changed

+89
-1912
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateAnnotationInvocationHandler.java

Lines changed: 0 additions & 57 deletions
This file was deleted.

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@
247247
import com.oracle.svm.hosted.analysis.NativeImageReachabilityAnalysisEngine;
248248
import com.oracle.svm.hosted.analysis.SVMAnalysisMetaAccess;
249249
import com.oracle.svm.hosted.analysis.SubstrateUnsupportedFeatures;
250-
import com.oracle.svm.hosted.annotation.AnnotationSupport;
251250
import com.oracle.svm.hosted.annotation.SubstrateAnnotationExtractor;
252251
import com.oracle.svm.hosted.c.CAnnotationProcessorCache;
253252
import com.oracle.svm.hosted.c.CConstantValueSupportImpl;
@@ -982,8 +981,7 @@ public static AnalysisUniverse createAnalysisUniverse(OptionValues options, Targ
982981
SnippetReflectionProvider originalSnippetReflection, AnnotationSubstitutionProcessor annotationSubstitutions, SubstitutionProcessor cEnumProcessor,
983982
ClassInitializationSupport classInitializationSupport, List<SubstitutionProcessor> additionalSubstitutions) {
984983
UnsafeAutomaticSubstitutionProcessor automaticSubstitutions = createAutomaticUnsafeSubstitutions(options, originalSnippetReflection, annotationSubstitutions);
985-
SubstitutionProcessor aSubstitutions = createAnalysisSubstitutionProcessor(originalMetaAccess, originalSnippetReflection, cEnumProcessor, automaticSubstitutions,
986-
annotationSubstitutions, additionalSubstitutions);
984+
SubstitutionProcessor aSubstitutions = createAnalysisSubstitutionProcessor(cEnumProcessor, automaticSubstitutions, annotationSubstitutions, additionalSubstitutions);
987985

988986
SVMHost hostVM = HostedConfiguration.instance().createHostVM(options, loader.getClassLoader(), classInitializationSupport, automaticSubstitutions, loader.platform);
989987

@@ -1014,13 +1012,12 @@ public static UnsafeAutomaticSubstitutionProcessor createAutomaticUnsafeSubstitu
10141012
return new UnsafeAutomaticSubstitutionProcessor(options, annotationSubstitutions, originalSnippetReflection);
10151013
}
10161014

1017-
public static SubstitutionProcessor createAnalysisSubstitutionProcessor(MetaAccessProvider originalMetaAccess, SnippetReflectionProvider originalSnippetReflection,
1015+
public static SubstitutionProcessor createAnalysisSubstitutionProcessor(
10181016
SubstitutionProcessor cEnumProcessor, SubstitutionProcessor automaticSubstitutions, SubstitutionProcessor annotationSubstitutions,
10191017
List<SubstitutionProcessor> additionalSubstitutionProcessors) {
10201018
List<SubstitutionProcessor> allProcessors = new ArrayList<>();
10211019
SubstitutionProcessor cFunctionSubstitutions = new CFunctionSubstitutionProcessor();
1022-
allProcessors.addAll(Arrays.asList(new AnnotationSupport(originalMetaAccess, originalSnippetReflection),
1023-
annotationSubstitutions, cFunctionSubstitutions, automaticSubstitutions, cEnumProcessor));
1020+
allProcessors.addAll(Arrays.asList(annotationSubstitutions, cFunctionSubstitutions, automaticSubstitutions, cEnumProcessor));
10241021
allProcessors.addAll(additionalSubstitutionProcessors);
10251022
return SubstitutionProcessor.chainUpInOrder(allProcessors.toArray(new SubstitutionProcessor[0]));
10261023
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright (c) 2023, 2023, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.oracle.svm.hosted.annotation;
26+
27+
import java.lang.annotation.Annotation;
28+
import java.lang.reflect.Array;
29+
import java.lang.reflect.Proxy;
30+
import java.util.Set;
31+
import java.util.concurrent.ConcurrentHashMap;
32+
33+
import org.graalvm.nativeimage.ImageSingletons;
34+
import org.graalvm.nativeimage.impl.ConfigurationCondition;
35+
import org.graalvm.nativeimage.impl.RuntimeReflectionSupport;
36+
37+
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
38+
import com.oracle.svm.core.feature.InternalFeature;
39+
import com.oracle.svm.hosted.reflect.ReflectionDataBuilder;
40+
41+
@AutomaticallyRegisteredFeature
42+
public class AnnotationFeature implements InternalFeature {
43+
44+
private RuntimeReflectionSupport runtimeReflectionSupport;
45+
private final Set<Class<? extends Annotation>> processedTypes = ConcurrentHashMap.newKeySet();
46+
47+
@Override
48+
public void duringSetup(DuringSetupAccess access) {
49+
runtimeReflectionSupport = ImageSingletons.lookup(RuntimeReflectionSupport.class);
50+
access.registerObjectReplacer(this::registerDeclaredMethods);
51+
}
52+
53+
/**
54+
* For annotations that are materialized at image run time, all necessary methods are registered
55+
* for reflection in {@link ReflectionDataBuilder#registerTypesForAnnotation}. But if an
56+
* annotation type is only used by an annotation that is already in the image heap, then we need
57+
* to also register its methods for reflection. This is done here by inspecting every image heap
58+
* object and checking if it is an annotation that was materialized by the JDK, i.e., implements
59+
* the {@link Annotation} interface and is a {@link Proxy}.
60+
*/
61+
private Object registerDeclaredMethods(Object obj) {
62+
if (obj instanceof Annotation annotation && Proxy.isProxyClass(annotation.getClass())) {
63+
Class<? extends Annotation> annotationType = annotation.annotationType();
64+
if (processedTypes.add(annotationType)) {
65+
runtimeReflectionSupport.registerAllDeclaredMethodsQuery(ConfigurationCondition.alwaysTrue(), false, annotationType);
66+
}
67+
}
68+
return obj;
69+
}
70+
71+
@Override
72+
public void beforeAnalysis(BeforeAnalysisAccess access) {
73+
access.registerSubtypeReachabilityHandler(this::registerArrayClass, Annotation.class);
74+
}
75+
76+
/*
77+
* The JDK implementation of repeatable annotations always instantiates an array of a requested
78+
* annotation. We need to mark arrays of all reachable annotations as in heap.
79+
*/
80+
private void registerArrayClass(DuringAnalysisAccess access, Class<?> subclass) {
81+
if (subclass.isAnnotation()) {
82+
Class<?> arrayClass = Array.newInstance(subclass, 0).getClass();
83+
access.registerAsInHeap(arrayClass);
84+
}
85+
}
86+
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/AnnotationSubstitutionField.java

Lines changed: 0 additions & 161 deletions
This file was deleted.

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/AnnotationSubstitutionMethod.java

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)