Skip to content

Commit 155ba6e

Browse files
author
Christian Wimmer
committed
Remove obsolete annotation support
1 parent eb3b334 commit 155ba6e

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
@@ -245,7 +245,6 @@
245245
import com.oracle.svm.hosted.analysis.NativeImageReachabilityAnalysisEngine;
246246
import com.oracle.svm.hosted.analysis.SVMAnalysisMetaAccess;
247247
import com.oracle.svm.hosted.analysis.SubstrateUnsupportedFeatures;
248-
import com.oracle.svm.hosted.annotation.AnnotationSupport;
249248
import com.oracle.svm.hosted.annotation.SubstrateAnnotationExtractor;
250249
import com.oracle.svm.hosted.c.CAnnotationProcessorCache;
251250
import com.oracle.svm.hosted.c.CConstantValueSupportImpl;
@@ -980,8 +979,7 @@ public static AnalysisUniverse createAnalysisUniverse(OptionValues options, Targ
980979
SnippetReflectionProvider originalSnippetReflection, AnnotationSubstitutionProcessor annotationSubstitutions, SubstitutionProcessor cEnumProcessor,
981980
ClassInitializationSupport classInitializationSupport, List<SubstitutionProcessor> additionalSubstitutions) {
982981
UnsafeAutomaticSubstitutionProcessor automaticSubstitutions = createAutomaticUnsafeSubstitutions(options, originalSnippetReflection, annotationSubstitutions);
983-
SubstitutionProcessor aSubstitutions = createAnalysisSubstitutionProcessor(originalMetaAccess, originalSnippetReflection, cEnumProcessor, automaticSubstitutions,
984-
annotationSubstitutions, additionalSubstitutions);
982+
SubstitutionProcessor aSubstitutions = createAnalysisSubstitutionProcessor(cEnumProcessor, automaticSubstitutions, annotationSubstitutions, additionalSubstitutions);
985983

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

@@ -1012,13 +1010,12 @@ public static UnsafeAutomaticSubstitutionProcessor createAutomaticUnsafeSubstitu
10121010
return new UnsafeAutomaticSubstitutionProcessor(options, annotationSubstitutions, originalSnippetReflection);
10131011
}
10141012

1015-
public static SubstitutionProcessor createAnalysisSubstitutionProcessor(MetaAccessProvider originalMetaAccess, SnippetReflectionProvider originalSnippetReflection,
1013+
public static SubstitutionProcessor createAnalysisSubstitutionProcessor(
10161014
SubstitutionProcessor cEnumProcessor, SubstitutionProcessor automaticSubstitutions, SubstitutionProcessor annotationSubstitutions,
10171015
List<SubstitutionProcessor> additionalSubstitutionProcessors) {
10181016
List<SubstitutionProcessor> allProcessors = new ArrayList<>();
10191017
SubstitutionProcessor cFunctionSubstitutions = new CFunctionSubstitutionProcessor();
1020-
allProcessors.addAll(Arrays.asList(new AnnotationSupport(originalMetaAccess, originalSnippetReflection),
1021-
annotationSubstitutions, cFunctionSubstitutions, automaticSubstitutions, cEnumProcessor));
1018+
allProcessors.addAll(Arrays.asList(annotationSubstitutions, cFunctionSubstitutions, automaticSubstitutions, cEnumProcessor));
10221019
allProcessors.addAll(additionalSubstitutionProcessors);
10231020
return SubstitutionProcessor.chainUpInOrder(allProcessors.toArray(new SubstitutionProcessor[0]));
10241021
}
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)