jdk/src/share/classes/java/lang/invoke/MethodHandleNatives.java
author jrose
Tue, 14 Jun 2011 22:47:09 -0700
changeset 9859 47e26ad535c4
parent 9780 6fc3b49cfee4
child 10082 761643c9bebd
permissions -rw-r--r--
7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray Summary: Fix corner cases involving MethodHandles.permuteArguments with long or double argument lists. Reviewed-by: twisti, never
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
     1
/*
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8347
diff changeset
     2
 * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
     4
 *
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4537
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4537
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    10
 *
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    15
 * accompanied this code).
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    16
 *
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4537
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4537
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4537
diff changeset
    23
 * questions.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    24
 */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    25
8822
8145ab9f5f86 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8821
diff changeset
    26
package java.lang.invoke;
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    27
8822
8145ab9f5f86 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8821
diff changeset
    28
import java.lang.invoke.MethodHandles.Lookup;
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    29
import java.lang.reflect.AccessibleObject;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    30
import java.lang.reflect.Field;
8822
8145ab9f5f86 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8821
diff changeset
    31
import static java.lang.invoke.MethodHandleNatives.Constants.*;
8145ab9f5f86 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8821
diff changeset
    32
import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    33
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    34
/**
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    35
 * The JVM interface for the method handles package is all here.
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    36
 * This is an interface internal and private to an implemetantion of JSR 292.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    37
 * <em>This class is not part of the JSR 292 standard.</em>
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    38
 * @author jrose
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    39
 */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    40
class MethodHandleNatives {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    41
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    42
    private MethodHandleNatives() { } // static only
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    43
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    44
    /// MethodName support
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    45
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    46
    static native void init(MemberName self, Object ref);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    47
    static native void expand(MemberName self);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    48
    static native void resolve(MemberName self, Class<?> caller);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    49
    static native int getMembers(Class<?> defc, String matchName, String matchSig,
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    50
            int matchFlags, Class<?> caller, int skip, MemberName[] results);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    51
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    52
    /// MethodHandle support
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    53
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    54
    /** Initialize the method handle to adapt the call. */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    55
    static native void init(AdapterMethodHandle self, MethodHandle target, int argnum);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    56
    /** Initialize the method handle to call the correct method, directly. */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    57
    static native void init(BoundMethodHandle self, Object target, int argnum);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    58
    /** Initialize the method handle to call as if by an invoke* instruction. */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    59
    static native void init(DirectMethodHandle self, Object ref, boolean doDispatch, Class<?> caller);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    60
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    61
    /** Initialize a method type, once per form. */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    62
    static native void init(MethodType self);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    63
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    64
    /** Tell the JVM about a class's bootstrap method. */
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    65
    static native void registerBootstrap(Class<?> caller, MethodHandle bootstrapMethod);
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    66
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    67
    /** Ask the JVM about a class's bootstrap method. */
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    68
    static native MethodHandle getBootstrap(Class<?> caller);
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    69
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    70
    /** Tell the JVM that we need to change the target of an invokedynamic. */
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
    71
    static native void setCallSiteTarget(CallSite site, MethodHandle target);
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    72
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    73
    /** Fetch the vmtarget field.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    74
     *  It will be sanitized as necessary to avoid exposing non-Java references.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    75
     *  This routine is for debugging and reflection.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    76
     */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    77
    static native Object getTarget(MethodHandle self, int format);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    78
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    79
    /** Fetch the name of the handled method, if available.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    80
     *  This routine is for debugging and reflection.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    81
     */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    82
    static MemberName getMethodName(MethodHandle self) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    83
        return (MemberName) getTarget(self, ETF_METHOD_NAME);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    84
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    85
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    86
    /** Fetch the reflective version of the handled method, if available.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    87
     */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    88
    static AccessibleObject getTargetMethod(MethodHandle self) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    89
        return (AccessibleObject) getTarget(self, ETF_REFLECT_METHOD);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    90
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    91
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    92
    /** Fetch the target of this method handle.
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2764
diff changeset
    93
     *  If it directly targets a method, return a MemberName for the method.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    94
     *  If it is chained to another method handle, return that handle.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    95
     */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    96
    static Object getTargetInfo(MethodHandle self) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    97
        return getTarget(self, ETF_HANDLE_OR_METHOD_NAME);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    98
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
    99
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   100
    static Object[] makeTarget(Class<?> defc, String name, String sig, int mods, Class<?> refc) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   101
        return new Object[] { defc, name, sig, mods, refc };
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   102
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   103
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   104
    /** Fetch MH-related JVM parameter.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   105
     *  which=0 retrieves MethodHandlePushLimit
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   106
     *  which=1 retrieves stack slot push size (in address units)
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   107
     */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   108
    static native int getConstant(int which);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   109
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   110
    /** Java copy of MethodHandlePushLimit in range 2..255. */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   111
    static final int JVM_PUSH_LIMIT;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   112
    /** JVM stack motion (in words) after one slot is pushed, usually -1.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   113
     */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   114
    static final int JVM_STACK_MOVE_UNIT;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   115
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   116
    /** Which conv-ops are implemented by the JVM? */
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   117
    static final int CONV_OP_IMPLEMENTED_MASK;
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   118
    /** Derived mode flag.  Only false on some old JVM implementations. */
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   119
    static final boolean HAVE_RICOCHET_FRAMES;
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   120
9859
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents: 9780
diff changeset
   121
    static final int OP_ROT_ARGS_DOWN_LIMIT_BIAS;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents: 9780
diff changeset
   122
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   123
    private static native void registerNatives();
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   124
    static {
9859
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents: 9780
diff changeset
   125
        registerNatives();
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents: 9780
diff changeset
   126
        int k;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents: 9780
diff changeset
   127
        JVM_PUSH_LIMIT              = getConstant(Constants.GC_JVM_PUSH_LIMIT);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents: 9780
diff changeset
   128
        JVM_STACK_MOVE_UNIT         = getConstant(Constants.GC_JVM_STACK_MOVE_UNIT);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents: 9780
diff changeset
   129
        k                           = getConstant(Constants.GC_CONV_OP_IMPLEMENTED_MASK);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents: 9780
diff changeset
   130
        CONV_OP_IMPLEMENTED_MASK    = (k != 0) ? k : DEFAULT_CONV_OP_IMPLEMENTED_MASK;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents: 9780
diff changeset
   131
        k                           = getConstant(Constants.GC_OP_ROT_ARGS_DOWN_LIMIT_BIAS);
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents: 9780
diff changeset
   132
        OP_ROT_ARGS_DOWN_LIMIT_BIAS = (k != 0) ? (byte)k : -1;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents: 9780
diff changeset
   133
        HAVE_RICOCHET_FRAMES        = (CONV_OP_IMPLEMENTED_MASK & (1<<OP_COLLECT_ARGS)) != 0;
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents: 9780
diff changeset
   134
        //sun.reflect.Reflection.registerMethodsToFilter(MethodHandleImpl.class, "init");
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   135
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   136
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   137
    // All compile-time constants go here.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   138
    // There is an opportunity to check them against the JVM's idea of them.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   139
    static class Constants {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   140
        Constants() { } // static only
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   141
        // MethodHandleImpl
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   142
        static final int // for getConstant
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   143
                GC_JVM_PUSH_LIMIT = 0,
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   144
                GC_JVM_STACK_MOVE_UNIT = 1,
9859
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents: 9780
diff changeset
   145
                GC_CONV_OP_IMPLEMENTED_MASK = 2,
47e26ad535c4 7052202: JSR 292: Crash in sun.invoke.util.ValueConversions.fillArray
jrose
parents: 9780
diff changeset
   146
                GC_OP_ROT_ARGS_DOWN_LIMIT_BIAS = 3;
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   147
        static final int
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   148
                ETF_HANDLE_OR_METHOD_NAME = 0, // all available data (immediate MH or method)
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   149
                ETF_DIRECT_HANDLE         = 1, // ultimate method handle (will be a DMH, may be self)
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   150
                ETF_METHOD_NAME           = 2, // ultimate method as MemberName
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   151
                ETF_REFLECT_METHOD        = 3; // ultimate method as java.lang.reflect object (sans refClass)
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   152
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   153
        // MemberName
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   154
        // The JVM uses values of -2 and above for vtable indexes.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   155
        // Field values are simple positive offsets.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   156
        // Ref: src/share/vm/oops/methodOop.hpp
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   157
        // This value is negative enough to avoid such numbers,
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   158
        // but not too negative.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   159
        static final int
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   160
                MN_IS_METHOD           = 0x00010000, // method (not constructor)
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   161
                MN_IS_CONSTRUCTOR      = 0x00020000, // constructor
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   162
                MN_IS_FIELD            = 0x00040000, // field
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   163
                MN_IS_TYPE             = 0x00080000, // nested type
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   164
                MN_SEARCH_SUPERCLASSES = 0x00100000, // for MHN.getMembers
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   165
                MN_SEARCH_INTERFACES   = 0x00200000, // for MHN.getMembers
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   166
                VM_INDEX_UNINITIALIZED = -99;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   167
8822
8145ab9f5f86 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8821
diff changeset
   168
        // BoundMethodHandle
8145ab9f5f86 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8821
diff changeset
   169
        /** Constants for decoding the vmargslot field, which contains 2 values. */
8145ab9f5f86 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8821
diff changeset
   170
        static final int
8145ab9f5f86 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8821
diff changeset
   171
            ARG_SLOT_PUSH_SHIFT = 16,
8145ab9f5f86 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8821
diff changeset
   172
            ARG_SLOT_MASK = (1<<ARG_SLOT_PUSH_SHIFT)-1;
8145ab9f5f86 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8821
diff changeset
   173
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   174
        // AdapterMethodHandle
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   175
        /** Conversions recognized by the JVM.
8822
8145ab9f5f86 7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents: 8821
diff changeset
   176
         *  They must align with the constants in java.lang.invoke.AdapterMethodHandle,
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   177
         *  in the JVM file hotspot/src/share/vm/classfile/javaClasses.hpp.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   178
         */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   179
        static final int
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   180
            OP_RETYPE_ONLY   = 0x0, // no argument changes; straight retype
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   181
            OP_RETYPE_RAW    = 0x1, // straight retype, trusted (void->int, Object->T)
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2764
diff changeset
   182
            OP_CHECK_CAST    = 0x2, // ref-to-ref conversion; requires a Class argument
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2764
diff changeset
   183
            OP_PRIM_TO_PRIM  = 0x3, // converts from one primitive to another
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2764
diff changeset
   184
            OP_REF_TO_PRIM   = 0x4, // unboxes a wrapper to produce a primitive
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   185
            OP_PRIM_TO_REF   = 0x5, // boxes a primitive into a wrapper
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2764
diff changeset
   186
            OP_SWAP_ARGS     = 0x6, // swap arguments (vminfo is 2nd arg)
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2764
diff changeset
   187
            OP_ROT_ARGS      = 0x7, // rotate arguments (vminfo is displaced arg)
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2764
diff changeset
   188
            OP_DUP_ARGS      = 0x8, // duplicates one or more arguments (at TOS)
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2764
diff changeset
   189
            OP_DROP_ARGS     = 0x9, // remove one or more argument slots
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   190
            OP_COLLECT_ARGS  = 0xA, // combine arguments using an auxiliary function
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2764
diff changeset
   191
            OP_SPREAD_ARGS   = 0xB, // expand in place a varargs array (of known size)
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   192
            OP_FOLD_ARGS     = 0xC, // combine but do not remove arguments; prepend result
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   193
            //OP_UNUSED_13   = 0xD, // unused code, perhaps for reified argument lists
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2764
diff changeset
   194
            CONV_OP_LIMIT    = 0xE; // limit of CONV_OP enumeration
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   195
        /** Shift and mask values for decoding the AMH.conversion field.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   196
         *  These numbers are shared with the JVM for creating AMHs.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   197
         */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   198
        static final int
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   199
            CONV_OP_MASK     = 0xF00, // this nybble contains the conversion op field
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   200
            CONV_TYPE_MASK   = 0x0F,  // fits T_ADDRESS and below
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   201
            CONV_VMINFO_MASK = 0x0FF, // LSB is reserved for JVM use
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   202
            CONV_VMINFO_SHIFT     =  0, // position of bits in CONV_VMINFO_MASK
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   203
            CONV_OP_SHIFT         =  8, // position of bits in CONV_OP_MASK
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   204
            CONV_DEST_TYPE_SHIFT  = 12, // byte 2 has the adapter BasicType (if needed)
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   205
            CONV_SRC_TYPE_SHIFT   = 16, // byte 2 has the source BasicType (if needed)
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   206
            CONV_STACK_MOVE_SHIFT = 20, // high 12 bits give signed SP change
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   207
            CONV_STACK_MOVE_MASK  = (1 << (32 - CONV_STACK_MOVE_SHIFT)) - 1;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   208
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   209
        /** Which conv-ops are implemented by the JVM? */
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   210
        static final int DEFAULT_CONV_OP_IMPLEMENTED_MASK =
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   211
                // Value to use if the corresponding JVM query fails.
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   212
                ((1<<OP_RETYPE_ONLY)
4537
7c3c7f8d5195 6914665: update jdk code for JSR 292 (post 6858164)
jrose
parents: 2764
diff changeset
   213
                |(1<<OP_RETYPE_RAW)
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   214
                |(1<<OP_CHECK_CAST)
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   215
                |(1<<OP_PRIM_TO_PRIM)
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   216
                |(1<<OP_REF_TO_PRIM)
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   217
                |(1<<OP_SWAP_ARGS)
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   218
                |(1<<OP_ROT_ARGS)
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   219
                |(1<<OP_DUP_ARGS)
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   220
                |(1<<OP_DROP_ARGS)
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   221
                //|(1<<OP_SPREAD_ARGS)
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   222
                );
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   223
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   224
        /**
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   225
         * Basic types as encoded in the JVM.  These code values are not
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   226
         * intended for use outside this class.  They are used as part of
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   227
         * a private interface between the JVM and this class.
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   228
         */
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   229
        static final int
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   230
            T_BOOLEAN  =  4,
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   231
            T_CHAR     =  5,
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   232
            T_FLOAT    =  6,
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   233
            T_DOUBLE   =  7,
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   234
            T_BYTE     =  8,
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   235
            T_SHORT    =  9,
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   236
            T_INT      = 10,
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   237
            T_LONG     = 11,
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   238
            T_OBJECT   = 12,
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   239
            //T_ARRAY    = 13
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   240
            T_VOID     = 14,
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   241
            //T_ADDRESS  = 15
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   242
            T_ILLEGAL  = 99;
5726
72c9d793224b 6939203: JSR 292 needs method handle constants
jrose
parents: 5722
diff changeset
   243
72c9d793224b 6939203: JSR 292 needs method handle constants
jrose
parents: 5722
diff changeset
   244
        /**
72c9d793224b 6939203: JSR 292 needs method handle constants
jrose
parents: 5722
diff changeset
   245
         * Constant pool reference-kind codes, as used by CONSTANT_MethodHandle CP entries.
72c9d793224b 6939203: JSR 292 needs method handle constants
jrose
parents: 5722
diff changeset
   246
         */
72c9d793224b 6939203: JSR 292 needs method handle constants
jrose
parents: 5722
diff changeset
   247
        static final int
72c9d793224b 6939203: JSR 292 needs method handle constants
jrose
parents: 5722
diff changeset
   248
            REF_getField                = 1,
72c9d793224b 6939203: JSR 292 needs method handle constants
jrose
parents: 5722
diff changeset
   249
            REF_getStatic               = 2,
72c9d793224b 6939203: JSR 292 needs method handle constants
jrose
parents: 5722
diff changeset
   250
            REF_putField                = 3,
72c9d793224b 6939203: JSR 292 needs method handle constants
jrose
parents: 5722
diff changeset
   251
            REF_putStatic               = 4,
72c9d793224b 6939203: JSR 292 needs method handle constants
jrose
parents: 5722
diff changeset
   252
            REF_invokeVirtual           = 5,
72c9d793224b 6939203: JSR 292 needs method handle constants
jrose
parents: 5722
diff changeset
   253
            REF_invokeStatic            = 6,
72c9d793224b 6939203: JSR 292 needs method handle constants
jrose
parents: 5722
diff changeset
   254
            REF_invokeSpecial           = 7,
72c9d793224b 6939203: JSR 292 needs method handle constants
jrose
parents: 5722
diff changeset
   255
            REF_newInvokeSpecial        = 8,
72c9d793224b 6939203: JSR 292 needs method handle constants
jrose
parents: 5722
diff changeset
   256
            REF_invokeInterface         = 9;
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   257
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   258
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   259
    private static native int getNamedCon(int which, Object[] name);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   260
    static boolean verifyConstants() {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   261
        Object[] box = { null };
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   262
        for (int i = 0; ; i++) {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   263
            box[0] = null;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   264
            int vmval = getNamedCon(i, box);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   265
            if (box[0] == null)  break;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   266
            String name = (String) box[0];
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   267
            try {
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   268
                Field con = Constants.class.getDeclaredField(name);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   269
                int jval = con.getInt(null);
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   270
                if (jval == vmval)  continue;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   271
                String err = (name+": JVM has "+vmval+" while Java has "+jval);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   272
                if (name.equals("CONV_OP_LIMIT")) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   273
                    System.err.println("warning: "+err);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   274
                    continue;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   275
                }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   276
                throw new InternalError(err);
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   277
            } catch (Exception ex) {
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   278
                if (ex instanceof NoSuchFieldException) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   279
                    String err = (name+": JVM has "+vmval+" which Java does not define");
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   280
                    // ignore exotic ops the JVM cares about; we just wont issue them
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   281
                    if (name.startsWith("OP_") || name.startsWith("GC_")) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   282
                        System.err.println("warning: "+err);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   283
                        continue;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   284
                    }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   285
                }
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   286
                throw new InternalError(name+": access failed, got "+ex);
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   287
            }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   288
        }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   289
        return true;
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   290
    }
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   291
    static {
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   292
        assert(verifyConstants());
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   293
    }
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   294
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   295
    // Up-calls from the JVM.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   296
    // These must NOT be public.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   297
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   298
    /**
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   299
     * The JVM is linking an invokedynamic instruction.  Create a reified call site for it.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   300
     */
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   301
    static CallSite makeDynamicCallSite(MethodHandle bootstrapMethod,
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   302
                                        String name, MethodType type,
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   303
                                        Object info,
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   304
                                        MemberName callerMethod, int callerBCI) {
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8347
diff changeset
   305
        return CallSite.makeSite(bootstrapMethod, name, type, info, callerMethod, callerBCI);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8347
diff changeset
   306
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8347
diff changeset
   307
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8347
diff changeset
   308
    /**
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8347
diff changeset
   309
     * Called by the JVM to check the length of a spread array.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8347
diff changeset
   310
     */
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8347
diff changeset
   311
    static void checkSpreadArgument(Object av, int n) {
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8347
diff changeset
   312
        MethodHandleStatics.checkSpreadArgument(av, n);
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   313
    }
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   314
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   315
    /**
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   316
     * The JVM wants a pointer to a MethodType.  Oblige it by finding or creating one.
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   317
     */
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   318
    static MethodType findMethodHandleType(Class<?> rtype, Class<?>[] ptypes) {
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8347
diff changeset
   319
        return MethodType.makeImpl(rtype, ptypes, true);
5722
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   320
    }
4ada807383c8 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 4537
diff changeset
   321
5726
72c9d793224b 6939203: JSR 292 needs method handle constants
jrose
parents: 5722
diff changeset
   322
    /**
9645
dabb5e4edc4c 7034977: JSR 292 MethodHandle.invokeGeneric should be renamed MethodHandle.invoke
jrose
parents: 8822
diff changeset
   323
     * The JVM wants to use a MethodType with inexact invoke.  Give the runtime fair warning.
7554
8a0ad9757002 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 7052
diff changeset
   324
     */
8a0ad9757002 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 7052
diff changeset
   325
    static void notifyGenericMethodType(MethodType type) {
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8347
diff changeset
   326
        type.form().notifyGenericMethodType();
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8347
diff changeset
   327
    }
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8347
diff changeset
   328
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8347
diff changeset
   329
    /**
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8347
diff changeset
   330
     * The JVM wants to raise an exception.  Here's the path.
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8347
diff changeset
   331
     */
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8347
diff changeset
   332
    static void raiseException(int code, Object actual, Object required) {
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   333
        String message = null;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   334
        switch (code) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   335
        case 190: // arraylength
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   336
            try {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   337
                String reqLength = "";
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   338
                if (required instanceof AdapterMethodHandle) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   339
                    int conv = ((AdapterMethodHandle)required).getConversion();
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   340
                    int spChange = AdapterMethodHandle.extractStackMove(conv);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   341
                    reqLength = " of length "+(spChange+1);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   342
                }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   343
                int actualLength = actual == null ? 0 : java.lang.reflect.Array.getLength(actual);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   344
                message = "required array"+reqLength+", but encountered wrong length "+actualLength;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   345
                break;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   346
            } catch (IllegalArgumentException ex) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   347
            }
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   348
            required = Object[].class;  // should have been an array
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   349
            code = 192; // checkcast
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   350
            break;
9779
e3a8fbcb21fb 7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents: 9752
diff changeset
   351
        case 191: // athrow
e3a8fbcb21fb 7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents: 9752
diff changeset
   352
            // JVM is asking us to wrap an exception which happened during resolving
e3a8fbcb21fb 7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents: 9752
diff changeset
   353
            if (required == BootstrapMethodError.class) {
e3a8fbcb21fb 7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents: 9752
diff changeset
   354
                throw new BootstrapMethodError((Throwable) actual);
e3a8fbcb21fb 7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents: 9752
diff changeset
   355
            }
e3a8fbcb21fb 7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents: 9752
diff changeset
   356
            break;
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   357
        }
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8347
diff changeset
   358
        // disregard the identity of the actual object, if it is not a class:
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   359
        if (message == null) {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   360
            if (!(actual instanceof Class) && !(actual instanceof MethodType))
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   361
                actual = actual.getClass();
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   362
           if (actual != null)
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   363
               message = "required "+required+" but encountered "+actual;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   364
           else
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   365
               message = "required "+required;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   366
        }
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8347
diff changeset
   367
        switch (code) {
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   368
        case 190: // arraylength
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   369
            throw new ArrayIndexOutOfBoundsException(message);
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   370
        case 50: //_aaload
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   371
            throw new ClassCastException(message);
8821
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8347
diff changeset
   372
        case 192: // checkcast
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8347
diff changeset
   373
            throw new ClassCastException(message);
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8347
diff changeset
   374
        default:
2836ee97ee27 6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents: 8347
diff changeset
   375
            throw new InternalError("unexpected code "+code+": "+message);
7554
8a0ad9757002 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 7052
diff changeset
   376
        }
8a0ad9757002 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 7052
diff changeset
   377
    }
8a0ad9757002 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 7052
diff changeset
   378
8a0ad9757002 6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents: 7052
diff changeset
   379
    /**
5726
72c9d793224b 6939203: JSR 292 needs method handle constants
jrose
parents: 5722
diff changeset
   380
     * The JVM is resolving a CONSTANT_MethodHandle CP entry.  And it wants our help.
72c9d793224b 6939203: JSR 292 needs method handle constants
jrose
parents: 5722
diff changeset
   381
     * It will make an up-call to this method.  (Do not change the name or signature.)
72c9d793224b 6939203: JSR 292 needs method handle constants
jrose
parents: 5722
diff changeset
   382
     */
72c9d793224b 6939203: JSR 292 needs method handle constants
jrose
parents: 5722
diff changeset
   383
    static MethodHandle linkMethodHandleConstant(Class<?> callerClass, int refKind,
72c9d793224b 6939203: JSR 292 needs method handle constants
jrose
parents: 5722
diff changeset
   384
                                                 Class<?> defc, String name, Object type) {
7052
963a5baf2ba3 6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents: 5727
diff changeset
   385
        try {
963a5baf2ba3 6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents: 5727
diff changeset
   386
            Lookup lookup = IMPL_LOOKUP.in(callerClass);
9780
6fc3b49cfee4 7050328: (jsr-292) findConstructor throws ExceptionInInitializerError if run under SecurityManager
jrose
parents: 9779
diff changeset
   387
            return lookup.linkMethodHandleConstant(refKind, defc, name, type);
8347
e5daa5772ffd 7013730: JSR 292 reflective operations should report errors with standard exception types
jrose
parents: 7554
diff changeset
   388
        } catch (ReflectiveOperationException ex) {
7052
963a5baf2ba3 6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents: 5727
diff changeset
   389
            Error err = new IncompatibleClassChangeError();
963a5baf2ba3 6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents: 5727
diff changeset
   390
            err.initCause(ex);
963a5baf2ba3 6980096: JSR 292 reflective lookup should throw checked exceptions
jrose
parents: 5727
diff changeset
   391
            throw err;
5726
72c9d793224b 6939203: JSR 292 needs method handle constants
jrose
parents: 5722
diff changeset
   392
        }
72c9d793224b 6939203: JSR 292 needs method handle constants
jrose
parents: 5722
diff changeset
   393
    }
9646
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   394
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   395
    /**
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   396
     * This assertion marks code which was written before ricochet frames were implemented.
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   397
     * Such code will go away when the ports catch up.
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   398
     */
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   399
    static boolean workaroundWithoutRicochetFrames() {
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   400
        assert(!HAVE_RICOCHET_FRAMES) : "this code should not be executed if `-XX:+UseRicochetFrames is enabled";
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   401
        return true;
5ebbe5ab084f 6939861: JVM should handle more conversion operations
jrose
parents: 9645
diff changeset
   402
    }
2707
5a17df307cbc 6829144: JSR 292 JVM features need a provisional Java API
jrose
parents:
diff changeset
   403
}