43972
|
1 |
/*
|
58877
|
2 |
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
|
43972
|
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.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
50858
|
23 |
|
|
24 |
|
43972
|
25 |
package org.graalvm.compiler.api.replacements;
|
|
26 |
|
|
27 |
import java.lang.annotation.ElementType;
|
|
28 |
import java.lang.annotation.Retention;
|
|
29 |
import java.lang.annotation.RetentionPolicy;
|
|
30 |
import java.lang.annotation.Target;
|
48861
|
31 |
import java.lang.reflect.Array;
|
43972
|
32 |
|
|
33 |
import jdk.vm.ci.meta.Signature;
|
|
34 |
|
|
35 |
/**
|
|
36 |
* Denotes a method whose body is used by a compiler as the substitute (or intrinsification) of
|
48861
|
37 |
* another method. The exact mechanism used to do the substitution is compiler dependent but every
|
58877
|
38 |
* compiler should require substitute methods to be annotated with {@link MethodSubstitution}.
|
48861
|
39 |
*
|
|
40 |
* A compiler may support partial intrinsification where only a part of a method is implemented by
|
|
41 |
* the compiler. The unsupported path is expressed by a call to either the original or substitute
|
|
42 |
* method from within the substitute method. Such as call is a <i>partial intrinsic exit</i>.
|
|
43 |
*
|
|
44 |
* For example, here's a HotSpot specific intrinsic for {@link Array#newInstance(Class, int)} that
|
|
45 |
* only handles the case where the VM representation of the array class to be instantiated already
|
|
46 |
* exists:
|
|
47 |
*
|
|
48 |
* <pre>
|
|
49 |
* @MethodSubstitution
|
|
50 |
* public static Object newInstance(Class<?> componentType, int length) {
|
|
51 |
* if (componentType == null || loadKlassFromObject(componentType, arrayKlassOffset(INJECTED_VMCONFIG), CLASS_ARRAY_KLASS_LOCATION).isNull()) {
|
|
52 |
* // Array class not yet created - exit the intrinsic and call the original method
|
|
53 |
* return newInstance(componentType, length);
|
|
54 |
* }
|
|
55 |
* return DynamicNewArrayNode.newArray(GraalDirectives.guardingNonNull(componentType), length, JavaKind.Object);
|
|
56 |
* }
|
|
57 |
* </pre>
|
|
58 |
*
|
|
59 |
* Here's the same intrinsification where the exit is expressed as a call to the original method:
|
|
60 |
*
|
|
61 |
* <pre>
|
|
62 |
* @MethodSubstitution
|
|
63 |
* public static Object newInstance(Class<?> componentType, int length) {
|
|
64 |
* if (componentType == null || loadKlassFromObject(componentType, arrayKlassOffset(INJECTED_VMCONFIG), CLASS_ARRAY_KLASS_LOCATION).isNull()) {
|
|
65 |
* // Array class not yet created - exit the intrinsic and call the original method
|
|
66 |
* return java.lang.reflect.newInstance(componentType, length);
|
|
67 |
* }
|
|
68 |
* return DynamicNewArrayNode.newArray(GraalDirectives.guardingNonNull(componentType), length, JavaKind.Object);
|
|
69 |
* }
|
|
70 |
* </pre>
|
|
71 |
*
|
|
72 |
* A condition for a partial intrinsic exit is that it is uses the unmodified parameters of the
|
|
73 |
* substitute as arguments to the partial intrinsic exit call. There must also be no side effecting
|
|
74 |
* instruction between the start of the substitute method and the partial intrinsic exit.
|
43972
|
75 |
*/
|
|
76 |
@Retention(RetentionPolicy.RUNTIME)
|
|
77 |
@Target(ElementType.METHOD)
|
|
78 |
public @interface MethodSubstitution {
|
|
79 |
|
|
80 |
/**
|
|
81 |
* Gets the name of the original method.
|
|
82 |
* <p>
|
|
83 |
* If the default value is specified for this element, then the name of the original method is
|
|
84 |
* same as the substitute method.
|
|
85 |
*/
|
|
86 |
String value() default "";
|
|
87 |
|
|
88 |
/**
|
|
89 |
* Determines if the original method is static.
|
|
90 |
*/
|
|
91 |
boolean isStatic() default true;
|
|
92 |
|
|
93 |
/**
|
|
94 |
* Gets the {@linkplain Signature#toMethodDescriptor signature} of the original method.
|
|
95 |
* <p>
|
|
96 |
* If the default value is specified for this element, then the signature of the original method
|
|
97 |
* is the same as the substitute method.
|
|
98 |
*/
|
|
99 |
String signature() default "";
|
|
100 |
|
|
101 |
/**
|
|
102 |
* Determines if the substitution is for a method that may not be part of the runtime. For
|
|
103 |
* example, a method introduced in a later JDK version. Substitutions for such methods are
|
|
104 |
* omitted if the original method cannot be found.
|
|
105 |
*/
|
|
106 |
boolean optional() default false;
|
|
107 |
}
|