Skip to content

Commit 7fa6473

Browse files
committed
Parse annotations without initializing them
1 parent 0a10263 commit 7fa6473

File tree

57 files changed

+2474
-928
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2474
-928
lines changed

compiler/mx.compiler/suite.py

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -455,27 +455,11 @@
455455
"workingSets" : "Graal",
456456
},
457457

458-
"org.graalvm.util" : {
458+
"org.graalvm.compiler.util.test" : {
459459
"subDir" : "src",
460460
"sourceDirs" : ["src"],
461461
"dependencies" : [
462462
"sdk:GRAAL_SDK",
463-
],
464-
"requiresConcealed" : {
465-
"java.base" : [
466-
"jdk.internal.module",
467-
]
468-
},
469-
"checkstyle" : "org.graalvm.compiler.graph",
470-
"javaCompliance" : "11+",
471-
"workingSets" : "API,Graal",
472-
},
473-
474-
"org.graalvm.util.test" : {
475-
"subDir" : "src",
476-
"sourceDirs" : ["src"],
477-
"dependencies" : [
478-
"org.graalvm.util",
479463
"org.graalvm.compiler.core.test",
480464
],
481465
"requiresConcealed" : {
@@ -1443,7 +1427,6 @@
14431427
"subDir" : "src",
14441428
"sourceDirs" : ["src"],
14451429
"dependencies" : [
1446-
"org.graalvm.util",
14471430
"org.graalvm.compiler.debug",
14481431
"sdk:GRAAL_SDK",
14491432
],
@@ -1485,7 +1468,7 @@
14851468
"sourceDirs" : ["src"],
14861469
"dependencies" : [
14871470
"org.graalvm.compiler.debug",
1488-
"org.graalvm.util",
1471+
"sdk:GRAAL_SDK",
14891472
"mx:JUNIT",
14901473
],
14911474
"requires" : [
@@ -1766,7 +1749,7 @@
17661749
"org.graalvm.libgraal",
17671750
"org.graalvm.compiler.truffle.runtime.hotspot",
17681751
"org.graalvm.compiler.truffle.common.hotspot.libgraal",
1769-
"org.graalvm.util",
1752+
"sdk:GRAAL_SDK",
17701753
],
17711754
"requiresConcealed" : {
17721755
"jdk.internal.vm.ci" : [
@@ -1946,7 +1929,7 @@
19461929
"org.graalvm.compiler.nodes.test",
19471930
"org.graalvm.compiler.phases.common.test",
19481931
"org.graalvm.compiler.truffle.test",
1949-
"org.graalvm.util.test",
1932+
"org.graalvm.compiler.util.test",
19501933
"org.graalvm.compiler.loop.test",
19511934
"org.graalvm.nativebridge.processor.test",
19521935
],
@@ -2049,7 +2032,6 @@
20492032
"org.graalvm.compiler.serviceprovider to jdk.internal.vm.compiler.management,org.graalvm.nativeimage.driver,org.graalvm.nativeimage.agent.jvmtibase,org.graalvm.nativeimage.agent.diagnostics",
20502033
"org.graalvm.compiler.truffle.jfr to jdk.internal.vm.compiler.truffle.jfr",
20512034
"org.graalvm.libgraal to jdk.internal.vm.compiler.management",
2052-
"org.graalvm.util to jdk.internal.vm.compiler.management",
20532035
],
20542036
"uses" : [
20552037
"com.oracle.truffle.api.impl.TruffleLocator",

compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/StructuredGraph.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import org.graalvm.compiler.nodes.spi.VirtualizableAllocation;
6565
import org.graalvm.compiler.nodes.util.GraphUtil;
6666
import org.graalvm.compiler.options.OptionValues;
67+
import org.graalvm.util.GuardedAnnotationAccess;
6768

6869
import jdk.vm.ci.code.BytecodeFrame;
6970
import jdk.vm.ci.meta.Assumptions;
@@ -508,7 +509,7 @@ private StructuredGraph(String name,
508509
private static boolean checkIsSubstitutionInvariants(ResolvedJavaMethod method, boolean isSubstitution) {
509510
if (!IS_IN_NATIVE_IMAGE) {
510511
if (method != null) {
511-
if (method.getAnnotation(Snippet.class) != null) {
512+
if (GuardedAnnotationAccess.isAnnotationPresent(method, Snippet.class)) {
512513
assert isSubstitution : "Graph for method " + method.format("%H.%n(%p)") +
513514
" annotated by " + Snippet.class.getName() +
514515
" must have its `isSubstitution` field set to true";

compiler/src/org.graalvm.util.test/src/org/graalvm/util/test/CollectionSizeTest.java renamed to compiler/src/org.graalvm.compiler.util.test/src/org/graalvm/compiler/util/test/CollectionSizeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* or visit www.oracle.com if you need additional information or have any
2323
* questions.
2424
*/
25-
package org.graalvm.util.test;
25+
package org.graalvm.compiler.util.test;
2626

2727
import static org.junit.Assert.assertEquals;
2828

compiler/src/org.graalvm.util.test/src/org/graalvm/util/test/CollectionUtilTest.java renamed to compiler/src/org.graalvm.compiler.util.test/src/org/graalvm/compiler/util/test/CollectionUtilTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* or visit www.oracle.com if you need additional information or have any
2323
* questions.
2424
*/
25-
package org.graalvm.util.test;
25+
package org.graalvm.compiler.util.test;
2626

2727
import java.util.ArrayList;
2828
import java.util.Arrays;

compiler/src/org.graalvm.util.test/src/org/graalvm/util/test/ObjectSizeEstimate.java renamed to compiler/src/org.graalvm.compiler.util.test/src/org/graalvm/compiler/util/test/ObjectSizeEstimate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* or visit www.oracle.com if you need additional information or have any
2323
* questions.
2424
*/
25-
package org.graalvm.util.test;
25+
package org.graalvm.compiler.util.test;
2626

2727
import java.lang.reflect.Field;
2828
import java.lang.reflect.Modifier;

compiler/src/org.graalvm.util.test/src/org/graalvm/util/test/OptionsEncoderTest.java renamed to compiler/src/org.graalvm.compiler.util.test/src/org/graalvm/compiler/util/test/OptionsEncoderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* or visit www.oracle.com if you need additional information or have any
2323
* questions.
2424
*/
25-
package org.graalvm.util.test;
25+
package org.graalvm.compiler.util.test;
2626

2727
import java.lang.annotation.ElementType;
2828
import static org.graalvm.util.OptionsEncoder.decode;

sdk/mx.sdk/suite.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,18 @@
330330
"javaCompliance" : "11+",
331331
"workingSets" : "API,SDK",
332332
},
333+
"org.graalvm.util" : {
334+
"subDir" : "src",
335+
"sourceDirs" : ["src"],
336+
"requiresConcealed" : {
337+
"java.base" : [
338+
"jdk.internal.module",
339+
]
340+
},
341+
"checkstyle" : "org.graalvm.word",
342+
"javaCompliance" : "11+",
343+
"workingSets" : "API,SDK",
344+
},
333345
},
334346
"licenses" : {
335347
"UPL" : {
@@ -359,6 +371,7 @@
359371
"org.graalvm.nativeimage",
360372
"org.graalvm.collections",
361373
"org.graalvm.home",
374+
"org.graalvm.util",
362375
],
363376
"distDependencies" : [],
364377
"javadocType": "api",
@@ -383,13 +396,15 @@
383396
"org.graalvm.polyglot.management",
384397
"org.graalvm.polyglot",
385398
"org.graalvm.options",
399+
"org.graalvm.util",
386400
"org.graalvm.word",
387401
"org.graalvm.polyglot.impl to org.graalvm.truffle, com.oracle.graal.graal_enterprise",
388402
"org.graalvm.word.impl to jdk.internal.vm.compiler",
389403
"org.graalvm.nativeimage.impl to org.graalvm.nativeimage.builder,org.graalvm.nativeimage.configure,com.oracle.svm.svm_enterprise",
390404
],
391405
"uses" : [
392-
"org.graalvm.polyglot.impl.AbstractPolyglotImpl"
406+
"org.graalvm.polyglot.impl.AbstractPolyglotImpl",
407+
"org.graalvm.util.AnnotationExtracter",
393408
],
394409
"opens" : [
395410
"org.graalvm.polyglot to org.graalvm.truffle"
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
package org.graalvm.util;
42+
43+
import java.lang.annotation.Annotation;
44+
import java.lang.reflect.AnnotatedElement;
45+
46+
public interface AnnotationExtracter {
47+
boolean isAnnotationPresent(AnnotatedElement element, Class<? extends Annotation> annotationType);
48+
49+
<T extends Annotation> T getAnnotation(AnnotatedElement element, Class<T> annotationType, boolean declaredOnly);
50+
}

compiler/src/org.graalvm.util/src/org/graalvm/util/CollectionsUtil.java renamed to sdk/src/org.graalvm.util/src/org/graalvm/util/CollectionsUtil.java

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,42 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
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.
5+
* The Universal Permissive License (UPL), Version 1.0
106
*
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).
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
1614
*
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.
15+
* (a) the Software, and
2016
*
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.
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
2440
*/
2541
package org.graalvm.util;
2642

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
package org.graalvm.util;
42+
43+
//Checkstyle: allow reflection
44+
import java.lang.annotation.Annotation;
45+
import java.lang.reflect.AnnotatedElement;
46+
47+
/**
48+
* Wrapper class for annotation access. The purpose of this class is to encapsulate the
49+
* AnnotatedElement.getAnnotation() to avoid the use of the "Checkstyle: allow direct annotation
50+
* access " and "Checkstyle: disallow direct annotation access" comments for situations where the
51+
* annotation access doesn't need to guarded, i.e., in runtime code or code that accesses annotation
52+
* on non-user types. See {@link GuardedAnnotationAccess} for details on these checkstyle rules.
53+
*/
54+
public class DirectAnnotationAccess {
55+
56+
public static <T extends Annotation> boolean isAnnotationPresent(AnnotatedElement element, Class<T> annotationClass) {
57+
return element.getAnnotation(annotationClass) != null;
58+
}
59+
60+
public static <T extends Annotation> T getAnnotation(AnnotatedElement element, Class<T> annotationType) {
61+
return element.getAnnotation(annotationType);
62+
}
63+
}

0 commit comments

Comments
 (0)