jdk/src/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java
author jrose
Fri, 17 Aug 2012 13:42:25 -0700
changeset 13610 28122b96858e
parent 13425 a8d96a0eda69
child 14089 0a41b980d62a
permissions -rw-r--r--
7191102: nightly failures after JSR 292 lazy method handle update (round 3) Reviewed-by: twisti, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
     1
/*
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
     4
 *
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    10
 *
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    15
 * accompanied this code).
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    16
 *
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    20
 *
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    23
 * questions.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    24
 */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    25
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    26
package java.lang.invoke;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    27
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    28
import sun.invoke.util.VerifyAccess;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    29
import java.lang.invoke.LambdaForm.Name;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    30
import java.lang.invoke.MethodHandles.Lookup;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    31
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    32
import sun.invoke.util.Wrapper;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    33
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    34
import java.io.*;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    35
import java.util.*;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    36
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    37
import com.sun.xml.internal.ws.org.objectweb.asm.*;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    38
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    39
import java.lang.reflect.*;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    40
import static java.lang.invoke.MethodHandleStatics.*;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    41
import static java.lang.invoke.MethodHandleNatives.Constants.*;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    42
import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    43
import sun.invoke.util.ValueConversions;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    44
import sun.invoke.util.VerifyType;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    45
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    46
/**
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    47
 * Code generation backend for LambdaForm.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    48
 * <p>
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    49
 * @author John Rose, JSR 292 EG
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    50
 */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    51
class InvokerBytecodeGenerator {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    52
    /** Define class names for convenience. */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    53
    private static final String MH      = "java/lang/invoke/MethodHandle";
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    54
    private static final String BMH     = "java/lang/invoke/BoundMethodHandle";
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    55
    private static final String LF      = "java/lang/invoke/LambdaForm";
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    56
    private static final String LFN     = "java/lang/invoke/LambdaForm$Name";
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    57
    private static final String CLS     = "java/lang/Class";
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    58
    private static final String OBJ     = "java/lang/Object";
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    59
    private static final String OBJARY  = "[Ljava/lang/Object;";
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    60
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    61
    private static final String LF_SIG  = "L" + LF + ";";
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    62
    private static final String LFN_SIG = "L" + LFN + ";";
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    63
    private static final String LL_SIG  = "(L" + OBJ + ";)L" + OBJ + ";";
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    64
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    65
    /** Name of its super class*/
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    66
    private static final String superName = LF;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    67
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    68
    /** Name of new class */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    69
    private final String className;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    70
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    71
    /** Name of the source file (for stack trace printing). */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    72
    private final String sourceFile;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    73
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    74
    private final LambdaForm lambdaForm;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    75
    private final String     invokerName;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    76
    private final MethodType invokerType;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    77
    private final int[] localsMap;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    78
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    79
    /** ASM bytecode generation. */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    80
    private ClassWriter cw;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    81
    private MethodVisitor mv;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    82
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    83
    private static final MemberName.Factory MEMBERNAME_FACTORY = MemberName.getFactory();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    84
    private static final Class<?> HOST_CLASS = LambdaForm.class;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    85
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    86
    private InvokerBytecodeGenerator(LambdaForm lambdaForm, int localsMapSize,
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    87
                                     String className, String invokerName, MethodType invokerType) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    88
        if (invokerName.contains(".")) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    89
            int p = invokerName.indexOf(".");
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    90
            className = invokerName.substring(0, p);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    91
            invokerName = invokerName.substring(p+1);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    92
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    93
        if (DUMP_CLASS_FILES) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    94
            className = makeDumpableClassName(className);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    95
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    96
        this.className  = superName + "$" + className;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    97
        this.sourceFile = "LambdaForm$" + className;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    98
        this.lambdaForm = lambdaForm;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
    99
        this.invokerName = invokerName;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   100
        this.invokerType = invokerType;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   101
        this.localsMap = new int[localsMapSize];
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   102
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   103
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   104
    private InvokerBytecodeGenerator(String className, String invokerName, MethodType invokerType) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   105
        this(null, invokerType.parameterCount(),
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   106
             className, invokerName, invokerType);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   107
        // Create an array to map name indexes to locals indexes.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   108
        for (int i = 0; i < localsMap.length; i++) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   109
            localsMap[i] = invokerType.parameterSlotCount() - invokerType.parameterSlotDepth(i);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   110
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   111
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   112
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   113
    private InvokerBytecodeGenerator(String className, LambdaForm form, MethodType invokerType) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   114
        this(form, form.names.length,
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   115
             className, form.debugName, invokerType);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   116
        // Create an array to map name indexes to locals indexes.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   117
        Name[] names = form.names;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   118
        for (int i = 0, index = 0; i < localsMap.length; i++) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   119
            localsMap[i] = index;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   120
            index += Wrapper.forBasicType(names[i].type).stackSlots();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   121
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   122
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   123
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   124
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   125
    /** instance counters for dumped classes */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   126
    private final static HashMap<String,Integer> DUMP_CLASS_FILES_COUNTERS;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   127
    /** debugging flag for saving generated class files */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   128
    private final static File DUMP_CLASS_FILES_DIR;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   129
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   130
    static {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   131
        if (DUMP_CLASS_FILES) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   132
            DUMP_CLASS_FILES_COUNTERS = new HashMap<>();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   133
            try {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   134
                File dumpDir = new File("DUMP_CLASS_FILES");
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   135
                if (!dumpDir.exists()) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   136
                    dumpDir.mkdirs();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   137
                }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   138
                DUMP_CLASS_FILES_DIR = dumpDir;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   139
                System.out.println("Dumping class files to "+DUMP_CLASS_FILES_DIR+"/...");
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   140
            } catch (Exception e) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   141
                throw new InternalError(e);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   142
            }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   143
        } else {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   144
            DUMP_CLASS_FILES_COUNTERS = null;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   145
            DUMP_CLASS_FILES_DIR = null;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   146
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   147
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   148
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   149
    static void maybeDump(final String className, final byte[] classFile) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   150
        if (DUMP_CLASS_FILES) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   151
            System.out.println("dump: " + className);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   152
            java.security.AccessController.doPrivileged(
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   153
            new java.security.PrivilegedAction<Void>() {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   154
                public Void run() {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   155
                    try {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   156
                        String dumpName = className;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   157
                        //dumpName = dumpName.replace('/', '-');
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   158
                        File dumpFile = new File(DUMP_CLASS_FILES_DIR, dumpName+".class");
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   159
                        dumpFile.getParentFile().mkdirs();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   160
                        FileOutputStream file = new FileOutputStream(dumpFile);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   161
                        file.write(classFile);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   162
                        file.close();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   163
                        return null;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   164
                    } catch (IOException ex) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   165
                        throw new InternalError(ex);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   166
                    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   167
                }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   168
            });
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   169
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   170
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   171
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   172
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   173
    private static String makeDumpableClassName(String className) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   174
        Integer ctr;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   175
        synchronized (DUMP_CLASS_FILES_COUNTERS) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   176
            ctr = DUMP_CLASS_FILES_COUNTERS.get(className);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   177
            if (ctr == null)  ctr = 0;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   178
            DUMP_CLASS_FILES_COUNTERS.put(className, ctr+1);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   179
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   180
        String sfx = ctr.toString();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   181
        while (sfx.length() < 3)
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   182
            sfx = "0"+sfx;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   183
        className += sfx;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   184
        return className;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   185
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   186
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   187
    class CpPatch {
13610
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13425
diff changeset
   188
        final int index;
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13425
diff changeset
   189
        final String placeholder;
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13425
diff changeset
   190
        final Object value;
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13425
diff changeset
   191
        CpPatch(int index, String placeholder, Object value) {
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   192
            this.index = index;
13610
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13425
diff changeset
   193
            this.placeholder = placeholder;
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   194
            this.value = value;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   195
        }
13610
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13425
diff changeset
   196
        public String toString() {
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13425
diff changeset
   197
            return "CpPatch/index="+index+",placeholder="+placeholder+",value="+value;
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13425
diff changeset
   198
        }
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   199
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   200
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   201
    Map<Object, CpPatch> cpPatches = new HashMap<>();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   202
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   203
    int cph = 0;  // for counting constant placeholders
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   204
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   205
    String constantPlaceholder(Object arg) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   206
        String cpPlaceholder = "CONSTANT_PLACEHOLDER_" + cph++;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   207
        if (DUMP_CLASS_FILES) cpPlaceholder += " <<" + arg.toString() + ">>";  // debugging aid
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   208
        if (cpPatches.containsKey(cpPlaceholder)) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   209
            throw new InternalError("observed CP placeholder twice: " + cpPlaceholder);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   210
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   211
        // insert placeholder in CP and remember the patch
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   212
        int index = cw.newConst((Object) cpPlaceholder);  // TODO check if aready in the constant pool
13610
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13425
diff changeset
   213
        cpPatches.put(cpPlaceholder, new CpPatch(index, cpPlaceholder, arg));
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   214
        return cpPlaceholder;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   215
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   216
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   217
    Object[] cpPatches(byte[] classFile) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   218
        int size = getConstantPoolSize(classFile);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   219
        Object[] res = new Object[size];
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   220
        for (CpPatch p : cpPatches.values()) {
13610
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13425
diff changeset
   221
            if (p.index >= size)
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13425
diff changeset
   222
                throw new InternalError("in cpool["+size+"]: "+p+"\n"+Arrays.toString(Arrays.copyOf(classFile, 20)));
28122b96858e 7191102: nightly failures after JSR 292 lazy method handle update (round 3)
jrose
parents: 13425
diff changeset
   223
            res[p.index] = p.value;
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   224
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   225
        return res;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   226
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   227
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   228
    /**
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   229
     * Extract the number of constant pool entries from a given class file.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   230
     *
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   231
     * @param classFile the bytes of the class file in question.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   232
     * @return the number of entries in the constant pool.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   233
     */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   234
    private static int getConstantPoolSize(byte[] classFile) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   235
        // The first few bytes:
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   236
        // u4 magic;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   237
        // u2 minor_version;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   238
        // u2 major_version;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   239
        // u2 constant_pool_count;
13425
a8d96a0eda69 7190416: JSR 292: typo in InvokerBytecodeGenerator.getConstantPoolSize
twisti
parents: 13423
diff changeset
   240
        return ((classFile[8] & 0xFF) << 8) | (classFile[9] & 0xFF);
13423
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   241
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   242
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   243
    /**
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   244
     * Extract the MemberName of a newly-defined method.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   245
     *
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   246
     * @param classFile
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   247
     * @return
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   248
     */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   249
    private MemberName loadMethod(byte[] classFile) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   250
        Class<?> invokerClass = loadAndInitializeInvokerClass(classFile, cpPatches(classFile));
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   251
        return resolveInvokerMember(invokerClass, invokerName, invokerType);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   252
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   253
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   254
    /**
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   255
     * Define a given class as anonymous class in the runtime system.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   256
     *
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   257
     * @param classBytes
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   258
     * @param patches
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   259
     * @return
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   260
     */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   261
    private static Class<?> loadAndInitializeInvokerClass(byte[] classBytes, Object[] patches) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   262
        Class<?> invokerClass = UNSAFE.defineAnonymousClass(HOST_CLASS, classBytes, patches);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   263
        UNSAFE.ensureClassInitialized(invokerClass);  // Make sure the class is initialized; VM might complain.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   264
        return invokerClass;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   265
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   266
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   267
    /**
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   268
     * TODO
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   269
     *
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   270
     * @param invokerClass
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   271
     * @param name
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   272
     * @param type
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   273
     * @return
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   274
     */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   275
    private static MemberName resolveInvokerMember(Class<?> invokerClass, String name, MethodType type) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   276
        MemberName member = new MemberName(invokerClass, name, type, REF_invokeStatic);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   277
        //System.out.println("resolveInvokerMember => "+member);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   278
        //for (Method m : invokerClass.getDeclaredMethods())  System.out.println("  "+m);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   279
        try {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   280
            member = MEMBERNAME_FACTORY.resolveOrFail(REF_invokeStatic, member, HOST_CLASS, ReflectiveOperationException.class);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   281
        } catch (ReflectiveOperationException e) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   282
            throw new InternalError(e);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   283
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   284
        //System.out.println("resolveInvokerMember => "+member);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   285
        return member;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   286
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   287
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   288
    /**
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   289
     * Set up class file generation.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   290
     */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   291
    private void classFilePrologue() {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   292
        cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   293
        cw.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER, className, null, superName, null);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   294
        cw.visitSource(sourceFile, null);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   295
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   296
        String invokerDesc = invokerType.toMethodDescriptorString();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   297
        mv = cw.visitMethod(Opcodes.ACC_STATIC, invokerName, invokerDesc, null, null);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   298
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   299
        // Force inlining of this invoker method.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   300
        mv.visitAnnotation("Ljava/lang/invoke/ForceInline;", true);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   301
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   302
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   303
    /**
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   304
     * Tear down class file generation.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   305
     */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   306
    private void classFileEpilogue() {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   307
        mv.visitMaxs(0, 0);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   308
        mv.visitEnd();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   309
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   310
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   311
    /*
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   312
     * Low-level emit helpers.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   313
     */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   314
    private void emitConst(Object con) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   315
        if (con == null) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   316
            mv.visitInsn(Opcodes.ACONST_NULL);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   317
            return;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   318
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   319
        if (con instanceof Integer) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   320
            emitIconstInsn((int) con);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   321
            return;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   322
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   323
        if (con instanceof Long) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   324
            long x = (long) con;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   325
            if (x == (short) x) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   326
                emitIconstInsn((int) x);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   327
                mv.visitInsn(Opcodes.I2L);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   328
                return;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   329
            }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   330
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   331
        if (con instanceof Float) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   332
            float x = (float) con;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   333
            if (x == (short) x) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   334
                emitIconstInsn((int) x);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   335
                mv.visitInsn(Opcodes.I2F);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   336
                return;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   337
            }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   338
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   339
        if (con instanceof Double) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   340
            double x = (double) con;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   341
            if (x == (short) x) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   342
                emitIconstInsn((int) x);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   343
                mv.visitInsn(Opcodes.I2D);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   344
                return;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   345
            }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   346
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   347
        if (con instanceof Boolean) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   348
            emitIconstInsn((boolean) con ? 1 : 0);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   349
            return;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   350
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   351
        // fall through:
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   352
        mv.visitLdcInsn(con);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   353
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   354
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   355
    private void emitIconstInsn(int i) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   356
        int opcode;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   357
        switch (i) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   358
        case 0:  opcode = Opcodes.ICONST_0;  break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   359
        case 1:  opcode = Opcodes.ICONST_1;  break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   360
        case 2:  opcode = Opcodes.ICONST_2;  break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   361
        case 3:  opcode = Opcodes.ICONST_3;  break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   362
        case 4:  opcode = Opcodes.ICONST_4;  break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   363
        case 5:  opcode = Opcodes.ICONST_5;  break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   364
        default:
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   365
            if (i == (byte) i) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   366
                mv.visitIntInsn(Opcodes.BIPUSH, i & 0xFF);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   367
            } else if (i == (short) i) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   368
                mv.visitIntInsn(Opcodes.SIPUSH, (char) i);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   369
            } else {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   370
                mv.visitLdcInsn(i);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   371
            }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   372
            return;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   373
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   374
        mv.visitInsn(opcode);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   375
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   376
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   377
    /*
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   378
     * NOTE: These load/store methods use the localsMap to find the correct index!
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   379
     */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   380
    private void emitLoadInsn(char type, int index) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   381
        int opcode;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   382
        switch (type) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   383
        case 'I':  opcode = Opcodes.ILOAD;  break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   384
        case 'J':  opcode = Opcodes.LLOAD;  break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   385
        case 'F':  opcode = Opcodes.FLOAD;  break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   386
        case 'D':  opcode = Opcodes.DLOAD;  break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   387
        case 'L':  opcode = Opcodes.ALOAD;  break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   388
        default:
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   389
            throw new InternalError("unknown type: " + type);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   390
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   391
        mv.visitVarInsn(opcode, localsMap[index]);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   392
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   393
    private void emitAloadInsn(int index) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   394
        emitLoadInsn('L', index);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   395
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   396
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   397
    private void emitStoreInsn(char type, int index) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   398
        int opcode;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   399
        switch (type) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   400
        case 'I':  opcode = Opcodes.ISTORE;  break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   401
        case 'J':  opcode = Opcodes.LSTORE;  break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   402
        case 'F':  opcode = Opcodes.FSTORE;  break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   403
        case 'D':  opcode = Opcodes.DSTORE;  break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   404
        case 'L':  opcode = Opcodes.ASTORE;  break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   405
        default:
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   406
            throw new InternalError("unknown type: " + type);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   407
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   408
        mv.visitVarInsn(opcode, localsMap[index]);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   409
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   410
    private void emitAstoreInsn(int index) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   411
        emitStoreInsn('L', index);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   412
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   413
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   414
    /**
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   415
     * Emit a boxing call.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   416
     *
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   417
     * @param type primitive type class to box.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   418
     */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   419
    private void emitBoxing(Class<?> type) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   420
        Wrapper wrapper = Wrapper.forPrimitiveType(type);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   421
        String owner = "java/lang/" + wrapper.wrapperType().getSimpleName();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   422
        String name  = "valueOf";
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   423
        String desc  = "(" + wrapper.basicTypeChar() + ")L" + owner + ";";
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   424
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, owner, name, desc);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   425
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   426
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   427
    /**
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   428
     * Emit an unboxing call (plus preceding checkcast).
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   429
     *
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   430
     * @param type wrapper type class to unbox.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   431
     */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   432
    private void emitUnboxing(Class<?> type) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   433
        Wrapper wrapper = Wrapper.forWrapperType(type);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   434
        String owner = "java/lang/" + wrapper.wrapperType().getSimpleName();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   435
        String name  = wrapper.primitiveSimpleName() + "Value";
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   436
        String desc  = "()" + wrapper.basicTypeChar();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   437
        mv.visitTypeInsn(Opcodes.CHECKCAST, owner);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   438
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, owner, name, desc);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   439
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   440
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   441
    /**
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   442
     * Emit an implicit conversion.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   443
     *
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   444
     * @param ptype type of value present on stack
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   445
     * @param pclass type of value required on stack
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   446
     */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   447
    private void emitImplicitConversion(char ptype, Class<?> pclass) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   448
        switch (ptype) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   449
        case 'L':
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   450
            if (VerifyType.isNullConversion(Object.class, pclass))
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   451
                return;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   452
            if (isStaticallyNameable(pclass)) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   453
                mv.visitTypeInsn(Opcodes.CHECKCAST, getInternalName(pclass));
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   454
            } else {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   455
                mv.visitLdcInsn(constantPlaceholder(pclass));
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   456
                mv.visitTypeInsn(Opcodes.CHECKCAST, CLS);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   457
                mv.visitInsn(Opcodes.SWAP);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   458
                mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, CLS, "cast", LL_SIG);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   459
                if (pclass.isArray())
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   460
                    mv.visitTypeInsn(Opcodes.CHECKCAST, OBJARY);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   461
            }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   462
            return;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   463
        case 'I':
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   464
            if (!VerifyType.isNullConversion(int.class, pclass))
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   465
                emitPrimCast(ptype, Wrapper.basicTypeChar(pclass));
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   466
            return;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   467
        case 'J':
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   468
            assert(pclass == long.class);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   469
            return;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   470
        case 'F':
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   471
            assert(pclass == float.class);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   472
            return;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   473
        case 'D':
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   474
            assert(pclass == double.class);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   475
            return;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   476
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   477
        throw new InternalError("bad implicit conversion: tc="+ptype+": "+pclass);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   478
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   479
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   480
    /**
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   481
     * Emits an actual return instruction conforming to the given return type.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   482
     */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   483
    private void emitReturnInsn(Class<?> type) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   484
        int opcode;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   485
        switch (Wrapper.basicTypeChar(type)) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   486
        case 'I':  opcode = Opcodes.IRETURN;  break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   487
        case 'J':  opcode = Opcodes.LRETURN;  break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   488
        case 'F':  opcode = Opcodes.FRETURN;  break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   489
        case 'D':  opcode = Opcodes.DRETURN;  break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   490
        case 'L':  opcode = Opcodes.ARETURN;  break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   491
        case 'V':  opcode = Opcodes.RETURN;   break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   492
        default:
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   493
            throw new InternalError("unknown return type: " + type);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   494
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   495
        mv.visitInsn(opcode);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   496
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   497
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   498
    private static String getInternalName(Class<?> c) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   499
        assert(VerifyAccess.isTypeVisible(c, Object.class));
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   500
        return c.getName().replace('.', '/');
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   501
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   502
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   503
    /**
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   504
     * Generate customized bytecode for a given LambdaForm.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   505
     *
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   506
     * @param form
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   507
     * @param invokerType
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   508
     * @return
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   509
     */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   510
    static MemberName generateCustomizedCode(LambdaForm form, MethodType invokerType) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   511
        InvokerBytecodeGenerator g = new InvokerBytecodeGenerator("MH", form, invokerType);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   512
        return g.loadMethod(g.generateCustomizedCodeBytes());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   513
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   514
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   515
    /**
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   516
     * Generate an invoker method for the passed {@link LambdaForm}.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   517
     */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   518
    private byte[] generateCustomizedCodeBytes() {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   519
        classFilePrologue();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   520
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   521
        // Suppress this method in backtraces displayed to the user.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   522
        mv.visitAnnotation("Ljava/lang/invoke/LambdaForm$Hidden;", true);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   523
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   524
        // Mark this method as a compiled LambdaForm
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   525
        mv.visitAnnotation("Ljava/lang/invoke/LambdaForm$Compiled;", true);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   526
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   527
        // iterate over the form's names, generating bytecode instructions for each
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   528
        // start iterating at the first name following the arguments
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   529
        for (int i = lambdaForm.arity; i < lambdaForm.names.length; i++) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   530
            Name name = lambdaForm.names[i];
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   531
            MemberName member = name.function.member();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   532
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   533
            if (isSelectAlternative(member)) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   534
                // selectAlternative idiom
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   535
                // FIXME: make sure this idiom is really present!
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   536
                emitSelectAlternative(name, lambdaForm.names[i + 1]);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   537
                i++;  // skip MH.invokeBasic of the selectAlternative result
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   538
            } else if (isStaticallyInvocable(member)) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   539
                emitStaticInvoke(member, name);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   540
            } else {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   541
                emitInvoke(name);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   542
            }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   543
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   544
            // store the result from evaluating to the target name in a local if required
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   545
            // (if this is the last value, i.e., the one that is going to be returned,
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   546
            // avoid store/load/return and just return)
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   547
            if (i == lambdaForm.names.length - 1 && i == lambdaForm.result) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   548
                // return value - do nothing
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   549
            } else if (name.type != 'V') {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   550
                // non-void: actually assign
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   551
                emitStoreInsn(name.type, name.index());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   552
            }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   553
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   554
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   555
        // return statement
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   556
        emitReturn();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   557
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   558
        classFileEpilogue();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   559
        bogusMethod(lambdaForm);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   560
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   561
        final byte[] classFile = cw.toByteArray();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   562
        maybeDump(className, classFile);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   563
        return classFile;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   564
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   565
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   566
    /**
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   567
     * Emit an invoke for the given name.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   568
     *
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   569
     * @param name
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   570
     */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   571
    void emitInvoke(Name name) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   572
        if (true) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   573
            // push receiver
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   574
            MethodHandle target = name.function.resolvedHandle;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   575
            assert(target != null) : name.exprString();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   576
            mv.visitLdcInsn(constantPlaceholder(target));
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   577
            mv.visitTypeInsn(Opcodes.CHECKCAST, MH);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   578
        } else {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   579
            // load receiver
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   580
            emitAloadInsn(0);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   581
            mv.visitTypeInsn(Opcodes.CHECKCAST, MH);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   582
            mv.visitFieldInsn(Opcodes.GETFIELD, MH, "form", LF_SIG);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   583
            mv.visitFieldInsn(Opcodes.GETFIELD, LF, "names", LFN_SIG);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   584
            // TODO more to come
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   585
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   586
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   587
        // push arguments
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   588
        for (int i = 0; i < name.arguments.length; i++) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   589
            emitPushArgument(name, i);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   590
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   591
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   592
        // invocation
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   593
        MethodType type = name.function.methodType();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   594
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, MH, "invokeBasic", type.basicType().toMethodDescriptorString());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   595
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   596
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   597
    static private Class<?>[] STATICALLY_INVOCABLE_PACKAGES = {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   598
        // Sample classes from each package we are willing to bind to statically:
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   599
        java.lang.Object.class,
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   600
        java.util.Arrays.class,
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   601
        sun.misc.Unsafe.class
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   602
        //MethodHandle.class already covered
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   603
    };
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   604
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   605
    static boolean isStaticallyInvocable(MemberName member) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   606
        if (member == null)  return false;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   607
        if (member.isConstructor())  return false;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   608
        Class<?> cls = member.getDeclaringClass();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   609
        if (cls.isArray() || cls.isPrimitive())
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   610
            return false;  // FIXME
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   611
        if (cls.isAnonymousClass() || cls.isLocalClass())
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   612
            return false;  // inner class of some sort
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   613
        if (cls.getClassLoader() != MethodHandle.class.getClassLoader())
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   614
            return false;  // not on BCP
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   615
        if (!member.isPrivate() && VerifyAccess.isSamePackage(MethodHandle.class, cls))
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   616
            return true;   // in java.lang.invoke package
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   617
        if (member.isPublic() && isStaticallyNameable(cls))
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   618
            return true;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   619
        return false;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   620
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   621
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   622
    static boolean isStaticallyNameable(Class<?> cls) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   623
        while (cls.isArray())
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   624
            cls = cls.getComponentType();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   625
        if (cls.isPrimitive())
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   626
            return true;  // int[].class, for example
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   627
        if (cls.getClassLoader() != Object.class.getClassLoader())
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   628
            return false;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   629
        if (VerifyAccess.isSamePackage(MethodHandle.class, cls))
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   630
            return true;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   631
        if (!Modifier.isPublic(cls.getModifiers()))
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   632
            return false;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   633
        for (Class<?> pkgcls : STATICALLY_INVOCABLE_PACKAGES) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   634
            if (VerifyAccess.isSamePackage(pkgcls, cls))
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   635
                return true;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   636
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   637
        return false;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   638
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   639
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   640
    /**
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   641
     * Emit an invoke for the given name, using the MemberName directly.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   642
     *
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   643
     * @param name
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   644
     */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   645
    void emitStaticInvoke(MemberName member, Name name) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   646
        assert(member.equals(name.function.member()));
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   647
        String cname = getInternalName(member.getDeclaringClass());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   648
        String mname = member.getName();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   649
        String mtype;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   650
        byte refKind = member.getReferenceKind();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   651
        if (refKind == REF_invokeSpecial) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   652
            // in order to pass the verifier, we need to convert this to invokevirtual in all cases
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   653
            assert(member.canBeStaticallyBound()) : member;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   654
            refKind = REF_invokeVirtual;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   655
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   656
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   657
        // push arguments
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   658
        for (int i = 0; i < name.arguments.length; i++) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   659
            emitPushArgument(name, i);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   660
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   661
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   662
        // invocation
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   663
        if (member.isMethod()) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   664
            mtype = member.getMethodType().toMethodDescriptorString();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   665
            mv.visitMethodInsn(refKindOpcode(refKind), cname, mname, mtype);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   666
        } else {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   667
            mtype = MethodType.toFieldDescriptorString(member.getFieldType());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   668
            mv.visitFieldInsn(refKindOpcode(refKind), cname, mname, mtype);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   669
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   670
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   671
    int refKindOpcode(byte refKind) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   672
        switch (refKind) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   673
        case REF_invokeVirtual:      return Opcodes.INVOKEVIRTUAL;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   674
        case REF_invokeStatic:       return Opcodes.INVOKESTATIC;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   675
        case REF_invokeSpecial:      return Opcodes.INVOKESPECIAL;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   676
        case REF_invokeInterface:    return Opcodes.INVOKEINTERFACE;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   677
        case REF_getField:           return Opcodes.GETFIELD;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   678
        case REF_putField:           return Opcodes.PUTFIELD;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   679
        case REF_getStatic:          return Opcodes.GETSTATIC;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   680
        case REF_putStatic:          return Opcodes.PUTSTATIC;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   681
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   682
        throw new InternalError("refKind="+refKind);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   683
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   684
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   685
    /**
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   686
     * Check if MemberName is a call to MethodHandleImpl.selectAlternative.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   687
     *
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   688
     * @param member
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   689
     * @return true if member is a call to MethodHandleImpl.selectAlternative
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   690
     */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   691
    private boolean isSelectAlternative(MemberName member) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   692
        return member != null &&
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   693
               member.getDeclaringClass() == MethodHandleImpl.class &&
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   694
               member.getName().equals("selectAlternative");
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   695
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   696
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   697
    /**
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   698
     * Emit bytecode for the selectAlternative idiom.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   699
     *
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   700
     * The pattern looks like (Cf. MethodHandleImpl.makeGuardWithTest):
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   701
     *
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   702
     *   Lambda(a0:L,a1:I)=>{
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   703
     *     t2:I=foo.test(a1:I);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   704
     *     t3:L=MethodHandleImpl.selectAlternative(t2:I,(MethodHandle(int)int),(MethodHandle(int)int));
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   705
     *     t4:I=MethodHandle.invokeBasic(t3:L,a1:I);t4:I}
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   706
     *
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   707
     * @param selectAlternativeName
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   708
     * @param invokeBasicName
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   709
     */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   710
    private void emitSelectAlternative(Name selectAlternativeName, Name invokeBasicName) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   711
        MethodType type = selectAlternativeName.function.methodType();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   712
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   713
        Name receiver = (Name) invokeBasicName.arguments[0];
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   714
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   715
        Label L_fallback = new Label();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   716
        Label L_done     = new Label();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   717
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   718
        // load test result
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   719
        emitPushArgument(selectAlternativeName, 0);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   720
        mv.visitInsn(Opcodes.ICONST_1);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   721
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   722
        // if_icmpne L_fallback
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   723
        mv.visitJumpInsn(Opcodes.IF_ICMPNE, L_fallback);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   724
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   725
        // invoke selectAlternativeName.arguments[1]
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   726
        MethodHandle target = (MethodHandle) selectAlternativeName.arguments[1];
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   727
        emitPushArgument(selectAlternativeName, 1);  // get 2nd argument of selectAlternative
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   728
        emitAstoreInsn(receiver.index());  // store the MH in the receiver slot
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   729
        emitInvoke(invokeBasicName);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   730
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   731
        // goto L_done
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   732
        mv.visitJumpInsn(Opcodes.GOTO, L_done);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   733
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   734
        // L_fallback:
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   735
        mv.visitLabel(L_fallback);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   736
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   737
        // invoke selectAlternativeName.arguments[2]
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   738
        MethodHandle fallback = (MethodHandle) selectAlternativeName.arguments[2];
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   739
        emitPushArgument(selectAlternativeName, 2);  // get 3rd argument of selectAlternative
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   740
        emitAstoreInsn(receiver.index());  // store the MH in the receiver slot
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   741
        emitInvoke(invokeBasicName);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   742
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   743
        // L_done:
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   744
        mv.visitLabel(L_done);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   745
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   746
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   747
    /**
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   748
     *
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   749
     * @param name
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   750
     * @param paramIndex
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   751
     */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   752
    private void emitPushArgument(Name name, int paramIndex) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   753
        Object arg = name.arguments[paramIndex];
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   754
        char ptype = name.function.parameterType(paramIndex);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   755
        MethodType mtype = name.function.methodType();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   756
        if (arg instanceof Name) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   757
            Name n = (Name) arg;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   758
            emitLoadInsn(n.type, n.index());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   759
            emitImplicitConversion(n.type, mtype.parameterType(paramIndex));
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   760
        } else if ((arg == null || arg instanceof String) && ptype == 'L') {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   761
            emitConst(arg);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   762
        } else {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   763
            if (Wrapper.isWrapperType(arg.getClass()) && ptype != 'L') {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   764
                emitConst(arg);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   765
            } else {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   766
                mv.visitLdcInsn(constantPlaceholder(arg));
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   767
                emitImplicitConversion('L', mtype.parameterType(paramIndex));
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   768
            }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   769
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   770
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   771
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   772
    /**
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   773
     * Emits a return statement from a LF invoker. If required, the result type is cast to the correct return type.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   774
     */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   775
    private void emitReturn() {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   776
        // return statement
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   777
        if (lambdaForm.result == -1) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   778
            // void
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   779
            mv.visitInsn(Opcodes.RETURN);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   780
        } else {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   781
            LambdaForm.Name rn = lambdaForm.names[lambdaForm.result];
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   782
            char rtype = Wrapper.basicTypeChar(invokerType.returnType());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   783
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   784
            // put return value on the stack if it is not already there
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   785
            if (lambdaForm.result != lambdaForm.names.length - 1) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   786
                emitLoadInsn(rn.type, lambdaForm.result);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   787
            }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   788
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   789
            // potentially generate cast
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   790
            // rtype is the return type of the invoker - generated code must conform to this
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   791
            // rn.type is the type of the result Name in the LF
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   792
            if (rtype != rn.type) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   793
                // need cast
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   794
                if (rtype == 'L') {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   795
                    // possibly cast the primitive to the correct type for boxing
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   796
                    char boxedType = Wrapper.forWrapperType(invokerType.returnType()).basicTypeChar();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   797
                    if (boxedType != rn.type) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   798
                        emitPrimCast(rn.type, boxedType);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   799
                    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   800
                    // cast primitive to reference ("boxing")
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   801
                    emitBoxing(invokerType.returnType());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   802
                } else {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   803
                    // to-primitive cast
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   804
                    if (rn.type != 'L') {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   805
                        // prim-to-prim cast
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   806
                        emitPrimCast(rn.type, rtype);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   807
                    } else {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   808
                        // ref-to-prim cast ("unboxing")
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   809
                        throw new InternalError("no ref-to-prim (unboxing) casts supported right now");
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   810
                    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   811
                }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   812
            }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   813
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   814
            // generate actual return statement
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   815
            emitReturnInsn(invokerType.returnType());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   816
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   817
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   818
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   819
    /**
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   820
     * Emit a type conversion bytecode casting from "from" to "to".
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   821
     */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   822
    private void emitPrimCast(char from, char to) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   823
        // Here's how.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   824
        // -   indicates forbidden
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   825
        // <-> indicates implicit
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   826
        //      to ----> boolean  byte     short    char     int      long     float    double
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   827
        // from boolean    <->        -        -        -        -        -        -        -
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   828
        //      byte        -       <->       i2s      i2c      <->      i2l      i2f      i2d
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   829
        //      short       -       i2b       <->      i2c      <->      i2l      i2f      i2d
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   830
        //      char        -       i2b       i2s      <->      <->      i2l      i2f      i2d
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   831
        //      int         -       i2b       i2s      i2c      <->      i2l      i2f      i2d
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   832
        //      long        -     l2i,i2b   l2i,i2s  l2i,i2c    l2i      <->      l2f      l2d
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   833
        //      float       -     f2i,i2b   f2i,i2s  f2i,i2c    f2i      f2l      <->      f2d
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   834
        //      double      -     d2i,i2b   d2i,i2s  d2i,i2c    d2i      d2l      d2f      <->
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   835
        if (from == to) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   836
            // no cast required, should be dead code anyway
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   837
            return;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   838
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   839
        Wrapper wfrom = Wrapper.forBasicType(from);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   840
        Wrapper wto   = Wrapper.forBasicType(to);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   841
        if (wfrom.isSubwordOrInt()) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   842
            // cast from {byte,short,char,int} to anything
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   843
            emitI2X(to);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   844
        } else {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   845
            // cast from {long,float,double} to anything
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   846
            if (wto.isSubwordOrInt()) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   847
                // cast to {byte,short,char,int}
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   848
                emitX2I(from);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   849
                if (wto.bitWidth() < 32) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   850
                    // targets other than int require another conversion
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   851
                    emitI2X(to);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   852
                }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   853
            } else {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   854
                // cast to {long,float,double} - this is verbose
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   855
                boolean error = false;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   856
                switch (from) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   857
                case 'J':
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   858
                         if (to == 'F') { mv.visitInsn(Opcodes.L2F); }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   859
                    else if (to == 'D') { mv.visitInsn(Opcodes.L2D); }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   860
                    else error = true;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   861
                    break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   862
                case 'F':
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   863
                         if (to == 'J') { mv.visitInsn(Opcodes.F2L); }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   864
                    else if (to == 'D') { mv.visitInsn(Opcodes.F2D); }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   865
                    else error = true;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   866
                    break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   867
                case 'D':
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   868
                         if (to == 'J') { mv.visitInsn(Opcodes.D2L); }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   869
                    else if (to == 'F') { mv.visitInsn(Opcodes.D2F); }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   870
                    else error = true;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   871
                    break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   872
                default:
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   873
                    error = true;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   874
                    break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   875
                }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   876
                if (error) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   877
                    throw new IllegalStateException("unhandled prim cast: " + from + "2" + to);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   878
                }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   879
            }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   880
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   881
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   882
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   883
    private void emitI2X(char type) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   884
        switch (type) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   885
        case 'B':  mv.visitInsn(Opcodes.I2B);  break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   886
        case 'S':  mv.visitInsn(Opcodes.I2S);  break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   887
        case 'C':  mv.visitInsn(Opcodes.I2C);  break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   888
        case 'I':  /* naught */                break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   889
        case 'J':  mv.visitInsn(Opcodes.I2L);  break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   890
        case 'F':  mv.visitInsn(Opcodes.I2F);  break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   891
        case 'D':  mv.visitInsn(Opcodes.I2D);  break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   892
        case 'Z':
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   893
            // For compatibility with ValueConversions and explicitCastArguments:
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   894
            mv.visitInsn(Opcodes.ICONST_1);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   895
            mv.visitInsn(Opcodes.IAND);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   896
            break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   897
        default:   throw new InternalError("unknown type: " + type);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   898
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   899
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   900
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   901
    private void emitX2I(char type) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   902
        switch (type) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   903
        case 'J':  mv.visitInsn(Opcodes.L2I);  break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   904
        case 'F':  mv.visitInsn(Opcodes.F2I);  break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   905
        case 'D':  mv.visitInsn(Opcodes.D2I);  break;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   906
        default:   throw new InternalError("unknown type: " + type);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   907
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   908
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   909
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   910
    private static String basicTypeCharSignature(String prefix, MethodType type) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   911
        StringBuilder buf = new StringBuilder(prefix);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   912
        for (Class<?> ptype : type.parameterList())
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   913
            buf.append(Wrapper.forBasicType(ptype).basicTypeChar());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   914
        buf.append('_').append(Wrapper.forBasicType(type.returnType()).basicTypeChar());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   915
        return buf.toString();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   916
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   917
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   918
    /**
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   919
     * Generate bytecode for a LambdaForm.vmentry which calls interpretWithArguments.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   920
     *
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   921
     * @param sig
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   922
     * @return
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   923
     */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   924
    static MemberName generateLambdaFormInterpreterEntryPoint(String sig) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   925
        assert(LambdaForm.isValidSignature(sig));
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   926
        //System.out.println("generateExactInvoker "+sig);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   927
        // compute method type
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   928
        // first parameter and return type
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   929
        char tret = LambdaForm.signatureReturn(sig);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   930
        MethodType type = MethodType.methodType(LambdaForm.typeClass(tret), MethodHandle.class);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   931
        // other parameter types
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   932
        int arity = LambdaForm.signatureArity(sig);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   933
        for (int i = 1; i < arity; i++) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   934
            type = type.appendParameterTypes(LambdaForm.typeClass(sig.charAt(i)));
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   935
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   936
        InvokerBytecodeGenerator g = new InvokerBytecodeGenerator("LFI", "interpret_"+tret, type);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   937
        return g.loadMethod(g.generateLambdaFormInterpreterEntryPointBytes());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   938
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   939
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   940
    private byte[] generateLambdaFormInterpreterEntryPointBytes() {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   941
        classFilePrologue();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   942
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   943
        // Suppress this method in backtraces displayed to the user.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   944
        mv.visitAnnotation("Ljava/lang/invoke/LambdaForm$Hidden;", true);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   945
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   946
        // create parameter array
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   947
        emitIconstInsn(invokerType.parameterCount());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   948
        mv.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/Object");
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   949
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   950
        // fill parameter array
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   951
        for (int i = 0; i < invokerType.parameterCount(); i++) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   952
            Class<?> ptype = invokerType.parameterType(i);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   953
            mv.visitInsn(Opcodes.DUP);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   954
            emitIconstInsn(i);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   955
            emitLoadInsn(Wrapper.basicTypeChar(ptype), i);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   956
            // box if primitive type
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   957
            if (ptype.isPrimitive()) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   958
                emitBoxing(ptype);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   959
            }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   960
            mv.visitInsn(Opcodes.AASTORE);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   961
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   962
        // invoke
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   963
        emitAloadInsn(0);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   964
        mv.visitFieldInsn(Opcodes.GETFIELD, MH, "form", "Ljava/lang/invoke/LambdaForm;");
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   965
        mv.visitInsn(Opcodes.SWAP);  // swap form and array; avoid local variable
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   966
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, LF, "interpretWithArguments", "([Ljava/lang/Object;)Ljava/lang/Object;");
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   967
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   968
        // maybe unbox
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   969
        Class<?> rtype = invokerType.returnType();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   970
        if (rtype.isPrimitive() && rtype != void.class) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   971
            emitUnboxing(Wrapper.asWrapperType(rtype));
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   972
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   973
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   974
        // return statement
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   975
        emitReturnInsn(rtype);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   976
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   977
        classFileEpilogue();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   978
        bogusMethod(invokerType);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   979
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   980
        final byte[] classFile = cw.toByteArray();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   981
        maybeDump(className, classFile);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   982
        return classFile;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   983
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   984
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   985
    /**
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   986
     * Generate bytecode for a NamedFunction invoker.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   987
     *
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   988
     * @param srcType
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   989
     * @param dstType
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   990
     * @return
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   991
     */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   992
    static MemberName generateNamedFunctionInvoker(MethodTypeForm typeForm) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   993
        MethodType invokerType = LambdaForm.NamedFunction.INVOKER_METHOD_TYPE;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   994
        String invokerName = basicTypeCharSignature("invoke_", typeForm.erasedType());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   995
        InvokerBytecodeGenerator g = new InvokerBytecodeGenerator("NFI", invokerName, invokerType);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   996
        return g.loadMethod(g.generateNamedFunctionInvokerImpl(typeForm));
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   997
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   998
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
   999
    static int nfi = 0;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1000
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1001
    private byte[] generateNamedFunctionInvokerImpl(MethodTypeForm typeForm) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1002
        MethodType dstType = typeForm.erasedType();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1003
        classFilePrologue();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1004
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1005
        // Suppress this method in backtraces displayed to the user.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1006
        mv.visitAnnotation("Ljava/lang/invoke/LambdaForm$Hidden;", true);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1007
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1008
        // Load receiver
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1009
        emitAloadInsn(0);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1010
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1011
        // Load arguments from array
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1012
        for (int i = 0; i < dstType.parameterCount(); i++) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1013
            emitAloadInsn(1);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1014
            emitIconstInsn(i);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1015
            mv.visitInsn(Opcodes.AALOAD);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1016
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1017
            // Maybe unbox
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1018
            Class<?> dptype = dstType.parameterType(i);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1019
            if (dptype.isPrimitive()) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1020
                Class<?> sptype = dstType.basicType().wrap().parameterType(i);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1021
                Wrapper dstWrapper = Wrapper.forBasicType(dptype);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1022
                Wrapper srcWrapper = dstWrapper.isSubwordOrInt() ? Wrapper.INT : dstWrapper;  // narrow subword from int
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1023
                emitUnboxing(srcWrapper.wrapperType());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1024
                emitPrimCast(srcWrapper.basicTypeChar(), dstWrapper.basicTypeChar());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1025
            }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1026
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1027
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1028
        // Invoke
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1029
        String targetDesc = dstType.basicType().toMethodDescriptorString();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1030
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, MH, "invokeBasic", targetDesc);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1031
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1032
        // Box primitive types
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1033
        Class<?> rtype = dstType.returnType();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1034
        if (rtype != void.class && rtype.isPrimitive()) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1035
            Wrapper srcWrapper = Wrapper.forBasicType(rtype);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1036
            Wrapper dstWrapper = srcWrapper.isSubwordOrInt() ? Wrapper.INT : srcWrapper;  // widen subword to int
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1037
            // boolean casts not allowed
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1038
            emitPrimCast(srcWrapper.basicTypeChar(), dstWrapper.basicTypeChar());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1039
            emitBoxing(dstWrapper.primitiveType());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1040
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1041
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1042
        // If the return type is void we return a null reference.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1043
        if (rtype == void.class) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1044
            mv.visitInsn(Opcodes.ACONST_NULL);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1045
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1046
        emitReturnInsn(Object.class);  // NOTE: NamedFunction invokers always return a reference value.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1047
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1048
        classFileEpilogue();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1049
        bogusMethod(dstType);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1050
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1051
        final byte[] classFile = cw.toByteArray();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1052
        maybeDump(className, classFile);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1053
        return classFile;
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1054
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1055
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1056
    /**
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1057
     * Emit a bogus method that just loads some string constants. This is to get the constants into the constant pool
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1058
     * for debugging purposes.
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1059
     */
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1060
    private void bogusMethod(Object... os) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1061
        if (DUMP_CLASS_FILES) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1062
            mv = cw.visitMethod(Opcodes.ACC_STATIC, "dummy", "()V", null, null);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1063
            for (Object o : os) {
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1064
                mv.visitLdcInsn(o.toString());
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1065
                mv.visitInsn(Opcodes.POP);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1066
            }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1067
            mv.visitInsn(Opcodes.RETURN);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1068
            mv.visitMaxs(0, 0);
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1069
            mv.visitEnd();
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1070
        }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1071
    }
17843fff200d 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff changeset
  1072
}