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