author | jrose |
Sat, 05 Oct 2013 05:30:40 -0700 | |
changeset 20535 | cc85c8626435 |
parent 19816 | 4136f2a0645d |
child 20872 | 8e486b70dff8 |
permissions | -rw-r--r-- |
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 |
|
14595
69a527af467a
8001885: JSR 292 classes should use jdk.internal.org.objectweb.asm
twisti
parents:
14089
diff
changeset
|
37 |
import jdk.internal.org.objectweb.asm.*; |
13423
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) { |
14089
0a41b980d62a
8000989: smaller code changes to make future JSR 292 backports easier
twisti
parents:
13610
diff
changeset
|
141 |
throw newInternalError(e); |
13423
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) { |
14089
0a41b980d62a
8000989: smaller code changes to make future JSR 292 backports easier
twisti
parents:
13610
diff
changeset
|
165 |
throw newInternalError(ex); |
13423
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 |
private MemberName loadMethod(byte[] classFile) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
247 |
Class<?> invokerClass = loadAndInitializeInvokerClass(classFile, cpPatches(classFile)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
248 |
return resolveInvokerMember(invokerClass, invokerName, invokerType); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
249 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
250 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
251 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
252 |
* 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
|
253 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
254 |
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
|
255 |
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
|
256 |
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
|
257 |
return invokerClass; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
258 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
259 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
260 |
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
|
261 |
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
|
262 |
//System.out.println("resolveInvokerMember => "+member); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
263 |
//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
|
264 |
try { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
265 |
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
|
266 |
} catch (ReflectiveOperationException e) { |
14089
0a41b980d62a
8000989: smaller code changes to make future JSR 292 backports easier
twisti
parents:
13610
diff
changeset
|
267 |
throw newInternalError(e); |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
268 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
269 |
//System.out.println("resolveInvokerMember => "+member); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
270 |
return member; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
271 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
272 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
273 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
274 |
* Set up class file generation. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
275 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
276 |
private void classFilePrologue() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
277 |
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
|
278 |
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
|
279 |
cw.visitSource(sourceFile, null); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
280 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
281 |
String invokerDesc = invokerType.toMethodDescriptorString(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
282 |
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
|
283 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
284 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
285 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
286 |
* Tear down class file generation. |
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 |
private void classFileEpilogue() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
289 |
mv.visitMaxs(0, 0); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
290 |
mv.visitEnd(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
291 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
292 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
293 |
/* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
294 |
* Low-level emit helpers. |
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 |
private void emitConst(Object con) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
297 |
if (con == null) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
298 |
mv.visitInsn(Opcodes.ACONST_NULL); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
299 |
return; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
300 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
301 |
if (con instanceof Integer) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
302 |
emitIconstInsn((int) con); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
303 |
return; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
304 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
305 |
if (con instanceof Long) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
306 |
long x = (long) con; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
307 |
if (x == (short) x) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
308 |
emitIconstInsn((int) x); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
309 |
mv.visitInsn(Opcodes.I2L); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
310 |
return; |
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 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
313 |
if (con instanceof Float) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
314 |
float x = (float) con; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
315 |
if (x == (short) x) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
316 |
emitIconstInsn((int) x); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
317 |
mv.visitInsn(Opcodes.I2F); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
318 |
return; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
319 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
320 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
321 |
if (con instanceof Double) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
322 |
double x = (double) con; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
323 |
if (x == (short) x) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
324 |
emitIconstInsn((int) x); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
325 |
mv.visitInsn(Opcodes.I2D); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
326 |
return; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
327 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
328 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
329 |
if (con instanceof Boolean) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
330 |
emitIconstInsn((boolean) con ? 1 : 0); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
331 |
return; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
332 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
333 |
// fall through: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
334 |
mv.visitLdcInsn(con); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
335 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
336 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
337 |
private void emitIconstInsn(int i) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
338 |
int opcode; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
339 |
switch (i) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
340 |
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
|
341 |
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
|
342 |
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
|
343 |
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
|
344 |
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
|
345 |
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
|
346 |
default: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
347 |
if (i == (byte) i) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
348 |
mv.visitIntInsn(Opcodes.BIPUSH, i & 0xFF); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
349 |
} else if (i == (short) i) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
350 |
mv.visitIntInsn(Opcodes.SIPUSH, (char) i); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
351 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
352 |
mv.visitLdcInsn(i); |
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 |
return; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
355 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
356 |
mv.visitInsn(opcode); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
357 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
358 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
359 |
/* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
360 |
* 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
|
361 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
362 |
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
|
363 |
int opcode; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
364 |
switch (type) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
365 |
case 'I': opcode = Opcodes.ILOAD; break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
366 |
case 'J': opcode = Opcodes.LLOAD; break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
367 |
case 'F': opcode = Opcodes.FLOAD; break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
368 |
case 'D': opcode = Opcodes.DLOAD; break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
369 |
case 'L': opcode = Opcodes.ALOAD; break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
370 |
default: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
371 |
throw new InternalError("unknown type: " + type); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
372 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
373 |
mv.visitVarInsn(opcode, localsMap[index]); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
374 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
375 |
private void emitAloadInsn(int index) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
376 |
emitLoadInsn('L', index); |
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 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
379 |
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
|
380 |
int opcode; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
381 |
switch (type) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
382 |
case 'I': opcode = Opcodes.ISTORE; break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
383 |
case 'J': opcode = Opcodes.LSTORE; break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
384 |
case 'F': opcode = Opcodes.FSTORE; break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
385 |
case 'D': opcode = Opcodes.DSTORE; break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
386 |
case 'L': opcode = Opcodes.ASTORE; break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
387 |
default: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
388 |
throw new InternalError("unknown type: " + type); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
389 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
390 |
mv.visitVarInsn(opcode, localsMap[index]); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
391 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
392 |
private void emitAstoreInsn(int index) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
393 |
emitStoreInsn('L', index); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
394 |
} |
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 |
* Emit a boxing call. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
398 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
399 |
* @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
|
400 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
401 |
private void emitBoxing(Class<?> type) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
402 |
Wrapper wrapper = Wrapper.forPrimitiveType(type); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
403 |
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
|
404 |
String name = "valueOf"; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
405 |
String desc = "(" + wrapper.basicTypeChar() + ")L" + owner + ";"; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
406 |
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
|
407 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
408 |
|
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 |
* 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
|
411 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
412 |
* @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
|
413 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
414 |
private void emitUnboxing(Class<?> type) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
415 |
Wrapper wrapper = Wrapper.forWrapperType(type); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
416 |
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
|
417 |
String name = wrapper.primitiveSimpleName() + "Value"; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
418 |
String desc = "()" + wrapper.basicTypeChar(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
419 |
mv.visitTypeInsn(Opcodes.CHECKCAST, owner); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
420 |
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
|
421 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
422 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
423 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
424 |
* Emit an implicit conversion. |
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 |
* @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
|
427 |
* @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
|
428 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
429 |
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
|
430 |
switch (ptype) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
431 |
case 'L': |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
432 |
if (VerifyType.isNullConversion(Object.class, pclass)) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
433 |
return; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
434 |
if (isStaticallyNameable(pclass)) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
435 |
mv.visitTypeInsn(Opcodes.CHECKCAST, getInternalName(pclass)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
436 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
437 |
mv.visitLdcInsn(constantPlaceholder(pclass)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
438 |
mv.visitTypeInsn(Opcodes.CHECKCAST, CLS); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
439 |
mv.visitInsn(Opcodes.SWAP); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
440 |
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
|
441 |
if (pclass.isArray()) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
442 |
mv.visitTypeInsn(Opcodes.CHECKCAST, OBJARY); |
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 |
return; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
445 |
case 'I': |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
446 |
if (!VerifyType.isNullConversion(int.class, pclass)) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
447 |
emitPrimCast(ptype, Wrapper.basicTypeChar(pclass)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
448 |
return; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
449 |
case 'J': |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
450 |
assert(pclass == long.class); |
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 |
case 'F': |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
453 |
assert(pclass == float.class); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
454 |
return; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
455 |
case 'D': |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
456 |
assert(pclass == double.class); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
457 |
return; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
458 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
459 |
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
|
460 |
} |
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 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
463 |
* 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
|
464 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
465 |
private void emitReturnInsn(Class<?> type) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
466 |
int opcode; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
467 |
switch (Wrapper.basicTypeChar(type)) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
468 |
case 'I': opcode = Opcodes.IRETURN; break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
469 |
case 'J': opcode = Opcodes.LRETURN; break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
470 |
case 'F': opcode = Opcodes.FRETURN; break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
471 |
case 'D': opcode = Opcodes.DRETURN; break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
472 |
case 'L': opcode = Opcodes.ARETURN; break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
473 |
case 'V': opcode = Opcodes.RETURN; break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
474 |
default: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
475 |
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
|
476 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
477 |
mv.visitInsn(opcode); |
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 |
private static String getInternalName(Class<?> c) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
481 |
assert(VerifyAccess.isTypeVisible(c, Object.class)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
482 |
return c.getName().replace('.', '/'); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
483 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
484 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
485 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
486 |
* 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
|
487 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
488 |
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
|
489 |
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
|
490 |
return g.loadMethod(g.generateCustomizedCodeBytes()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
491 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
492 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
493 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
494 |
* 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
|
495 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
496 |
private byte[] generateCustomizedCodeBytes() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
497 |
classFilePrologue(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
498 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
499 |
// 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
|
500 |
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
|
501 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
502 |
// 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
|
503 |
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
|
504 |
|
14852 | 505 |
// Force inlining of this invoker method. |
506 |
mv.visitAnnotation("Ljava/lang/invoke/ForceInline;", true); |
|
507 |
||
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
508 |
// 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
|
509 |
// 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
|
510 |
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
|
511 |
Name name = lambdaForm.names[i]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
512 |
MemberName member = name.function.member(); |
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 |
if (isSelectAlternative(member)) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
515 |
// selectAlternative idiom |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
516 |
// 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
|
517 |
emitSelectAlternative(name, lambdaForm.names[i + 1]); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
518 |
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
|
519 |
} else if (isStaticallyInvocable(member)) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
520 |
emitStaticInvoke(member, name); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
521 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
522 |
emitInvoke(name); |
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 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
525 |
// 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
|
526 |
// (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
|
527 |
// 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
|
528 |
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
|
529 |
// return value - do nothing |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
530 |
} else if (name.type != 'V') { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
531 |
// non-void: actually assign |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
532 |
emitStoreInsn(name.type, name.index()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
533 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
534 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
535 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
536 |
// return statement |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
537 |
emitReturn(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
538 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
539 |
classFileEpilogue(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
540 |
bogusMethod(lambdaForm); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
541 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
542 |
final byte[] classFile = cw.toByteArray(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
543 |
maybeDump(className, classFile); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
544 |
return classFile; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
545 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
546 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
547 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
548 |
* 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
|
549 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
550 |
void emitInvoke(Name name) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
551 |
if (true) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
552 |
// push receiver |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
553 |
MethodHandle target = name.function.resolvedHandle; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
554 |
assert(target != null) : name.exprString(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
555 |
mv.visitLdcInsn(constantPlaceholder(target)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
556 |
mv.visitTypeInsn(Opcodes.CHECKCAST, MH); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
557 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
558 |
// load receiver |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
559 |
emitAloadInsn(0); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
560 |
mv.visitTypeInsn(Opcodes.CHECKCAST, MH); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
561 |
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
|
562 |
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
|
563 |
// TODO more to come |
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 |
// push arguments |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
567 |
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
|
568 |
emitPushArgument(name, i); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
569 |
} |
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 |
// invocation |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
572 |
MethodType type = name.function.methodType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
573 |
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
|
574 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
575 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
576 |
static private Class<?>[] STATICALLY_INVOCABLE_PACKAGES = { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
577 |
// 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
|
578 |
java.lang.Object.class, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
579 |
java.util.Arrays.class, |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
580 |
sun.misc.Unsafe.class |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
581 |
//MethodHandle.class already covered |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
582 |
}; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
583 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
584 |
static boolean isStaticallyInvocable(MemberName member) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
585 |
if (member == null) return false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
586 |
if (member.isConstructor()) return false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
587 |
Class<?> cls = member.getDeclaringClass(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
588 |
if (cls.isArray() || cls.isPrimitive()) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
589 |
return false; // FIXME |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
590 |
if (cls.isAnonymousClass() || cls.isLocalClass()) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
591 |
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
|
592 |
if (cls.getClassLoader() != MethodHandle.class.getClassLoader()) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
593 |
return false; // not on BCP |
19816
4136f2a0645d
8024283: 10 nashorn tests fail with similar stack trace InternalError with cause being NoClassDefFoundError
rfield
parents:
14852
diff
changeset
|
594 |
MethodType mtype = member.getMethodOrFieldType(); |
4136f2a0645d
8024283: 10 nashorn tests fail with similar stack trace InternalError with cause being NoClassDefFoundError
rfield
parents:
14852
diff
changeset
|
595 |
if (!isStaticallyNameable(mtype.returnType())) |
4136f2a0645d
8024283: 10 nashorn tests fail with similar stack trace InternalError with cause being NoClassDefFoundError
rfield
parents:
14852
diff
changeset
|
596 |
return false; |
4136f2a0645d
8024283: 10 nashorn tests fail with similar stack trace InternalError with cause being NoClassDefFoundError
rfield
parents:
14852
diff
changeset
|
597 |
for (Class<?> ptype : mtype.parameterArray()) |
4136f2a0645d
8024283: 10 nashorn tests fail with similar stack trace InternalError with cause being NoClassDefFoundError
rfield
parents:
14852
diff
changeset
|
598 |
if (!isStaticallyNameable(ptype)) |
4136f2a0645d
8024283: 10 nashorn tests fail with similar stack trace InternalError with cause being NoClassDefFoundError
rfield
parents:
14852
diff
changeset
|
599 |
return false; |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
600 |
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
|
601 |
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
|
602 |
if (member.isPublic() && isStaticallyNameable(cls)) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
603 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
604 |
return false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
605 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
606 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
607 |
static boolean isStaticallyNameable(Class<?> cls) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
608 |
while (cls.isArray()) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
609 |
cls = cls.getComponentType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
610 |
if (cls.isPrimitive()) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
611 |
return true; // int[].class, for example |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
612 |
if (cls.getClassLoader() != Object.class.getClassLoader()) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
613 |
return false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
614 |
if (VerifyAccess.isSamePackage(MethodHandle.class, cls)) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
615 |
return true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
616 |
if (!Modifier.isPublic(cls.getModifiers())) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
617 |
return false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
618 |
for (Class<?> pkgcls : STATICALLY_INVOCABLE_PACKAGES) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
619 |
if (VerifyAccess.isSamePackage(pkgcls, cls)) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
620 |
return true; |
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 |
return false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
623 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
624 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
625 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
626 |
* 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
|
627 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
628 |
void emitStaticInvoke(MemberName member, Name name) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
629 |
assert(member.equals(name.function.member())); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
630 |
String cname = getInternalName(member.getDeclaringClass()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
631 |
String mname = member.getName(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
632 |
String mtype; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
633 |
byte refKind = member.getReferenceKind(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
634 |
if (refKind == REF_invokeSpecial) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
635 |
// 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
|
636 |
assert(member.canBeStaticallyBound()) : member; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
637 |
refKind = REF_invokeVirtual; |
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 |
// push arguments |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
641 |
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
|
642 |
emitPushArgument(name, i); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
643 |
} |
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 |
// invocation |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
646 |
if (member.isMethod()) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
647 |
mtype = member.getMethodType().toMethodDescriptorString(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
648 |
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
|
649 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
650 |
mtype = MethodType.toFieldDescriptorString(member.getFieldType()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
651 |
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
|
652 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
653 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
654 |
int refKindOpcode(byte refKind) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
655 |
switch (refKind) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
656 |
case REF_invokeVirtual: return Opcodes.INVOKEVIRTUAL; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
657 |
case REF_invokeStatic: return Opcodes.INVOKESTATIC; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
658 |
case REF_invokeSpecial: return Opcodes.INVOKESPECIAL; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
659 |
case REF_invokeInterface: return Opcodes.INVOKEINTERFACE; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
660 |
case REF_getField: return Opcodes.GETFIELD; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
661 |
case REF_putField: return Opcodes.PUTFIELD; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
662 |
case REF_getStatic: return Opcodes.GETSTATIC; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
663 |
case REF_putStatic: return Opcodes.PUTSTATIC; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
664 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
665 |
throw new InternalError("refKind="+refKind); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
666 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
667 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
668 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
669 |
* 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
|
670 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
671 |
private boolean isSelectAlternative(MemberName member) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
672 |
return member != null && |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
673 |
member.getDeclaringClass() == MethodHandleImpl.class && |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
674 |
member.getName().equals("selectAlternative"); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
675 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
676 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
677 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
678 |
* Emit bytecode for the selectAlternative idiom. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
679 |
* |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
680 |
* The pattern looks like (Cf. MethodHandleImpl.makeGuardWithTest): |
20535
cc85c8626435
8024438: JSR 292 API specification maintenance for JDK 8
jrose
parents:
19816
diff
changeset
|
681 |
* <blockquote><pre>{@code |
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
682 |
* Lambda(a0:L,a1:I)=>{ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
683 |
* t2:I=foo.test(a1:I); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
684 |
* 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
|
685 |
* t4:I=MethodHandle.invokeBasic(t3:L,a1:I);t4:I} |
20535
cc85c8626435
8024438: JSR 292 API specification maintenance for JDK 8
jrose
parents:
19816
diff
changeset
|
686 |
* }</pre></blockquote> |
13423
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 |
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
|
689 |
MethodType type = selectAlternativeName.function.methodType(); |
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 |
Name receiver = (Name) invokeBasicName.arguments[0]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
692 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
693 |
Label L_fallback = new Label(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
694 |
Label L_done = new Label(); |
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 |
// load test result |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
697 |
emitPushArgument(selectAlternativeName, 0); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
698 |
mv.visitInsn(Opcodes.ICONST_1); |
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 |
// if_icmpne L_fallback |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
701 |
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
|
702 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
703 |
// invoke selectAlternativeName.arguments[1] |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
704 |
MethodHandle target = (MethodHandle) selectAlternativeName.arguments[1]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
705 |
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
|
706 |
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
|
707 |
emitInvoke(invokeBasicName); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
708 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
709 |
// goto L_done |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
710 |
mv.visitJumpInsn(Opcodes.GOTO, L_done); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
711 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
712 |
// L_fallback: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
713 |
mv.visitLabel(L_fallback); |
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 |
// invoke selectAlternativeName.arguments[2] |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
716 |
MethodHandle fallback = (MethodHandle) selectAlternativeName.arguments[2]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
717 |
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
|
718 |
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
|
719 |
emitInvoke(invokeBasicName); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
720 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
721 |
// L_done: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
722 |
mv.visitLabel(L_done); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
723 |
} |
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 |
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
|
726 |
Object arg = name.arguments[paramIndex]; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
727 |
char ptype = name.function.parameterType(paramIndex); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
728 |
MethodType mtype = name.function.methodType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
729 |
if (arg instanceof Name) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
730 |
Name n = (Name) arg; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
731 |
emitLoadInsn(n.type, n.index()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
732 |
emitImplicitConversion(n.type, mtype.parameterType(paramIndex)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
733 |
} 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
|
734 |
emitConst(arg); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
735 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
736 |
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
|
737 |
emitConst(arg); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
738 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
739 |
mv.visitLdcInsn(constantPlaceholder(arg)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
740 |
emitImplicitConversion('L', mtype.parameterType(paramIndex)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
741 |
} |
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 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
744 |
|
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 |
* 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
|
747 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
748 |
private void emitReturn() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
749 |
// return statement |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
750 |
if (lambdaForm.result == -1) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
751 |
// void |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
752 |
mv.visitInsn(Opcodes.RETURN); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
753 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
754 |
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
|
755 |
char rtype = Wrapper.basicTypeChar(invokerType.returnType()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
756 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
757 |
// 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
|
758 |
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
|
759 |
emitLoadInsn(rn.type, lambdaForm.result); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
760 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
761 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
762 |
// potentially generate cast |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
763 |
// 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
|
764 |
// 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
|
765 |
if (rtype != rn.type) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
766 |
// need cast |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
767 |
if (rtype == 'L') { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
768 |
// 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
|
769 |
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
|
770 |
if (boxedType != rn.type) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
771 |
emitPrimCast(rn.type, boxedType); |
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 |
// cast primitive to reference ("boxing") |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
774 |
emitBoxing(invokerType.returnType()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
775 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
776 |
// to-primitive cast |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
777 |
if (rn.type != 'L') { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
778 |
// prim-to-prim cast |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
779 |
emitPrimCast(rn.type, rtype); |
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 |
// ref-to-prim cast ("unboxing") |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
782 |
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
|
783 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
784 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
785 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
786 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
787 |
// generate actual return statement |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
788 |
emitReturnInsn(invokerType.returnType()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
789 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
790 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
791 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
792 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
793 |
* 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
|
794 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
795 |
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
|
796 |
// Here's how. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
797 |
// - indicates forbidden |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
798 |
// <-> indicates implicit |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
799 |
// 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
|
800 |
// from boolean <-> - - - - - - - |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
801 |
// byte - <-> i2s i2c <-> i2l i2f i2d |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
802 |
// short - i2b <-> i2c <-> i2l i2f i2d |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
803 |
// char - i2b i2s <-> <-> i2l i2f i2d |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
804 |
// 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
|
805 |
// 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
|
806 |
// 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
|
807 |
// 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
|
808 |
if (from == to) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
809 |
// 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
|
810 |
return; |
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 |
Wrapper wfrom = Wrapper.forBasicType(from); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
813 |
Wrapper wto = Wrapper.forBasicType(to); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
814 |
if (wfrom.isSubwordOrInt()) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
815 |
// 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
|
816 |
emitI2X(to); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
817 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
818 |
// 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
|
819 |
if (wto.isSubwordOrInt()) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
820 |
// cast to {byte,short,char,int} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
821 |
emitX2I(from); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
822 |
if (wto.bitWidth() < 32) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
823 |
// 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
|
824 |
emitI2X(to); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
825 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
826 |
} else { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
827 |
// 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
|
828 |
boolean error = false; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
829 |
switch (from) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
830 |
case 'J': |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
831 |
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
|
832 |
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
|
833 |
else error = true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
834 |
break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
835 |
case 'F': |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
836 |
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
|
837 |
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
|
838 |
else error = true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
839 |
break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
840 |
case 'D': |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
841 |
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
|
842 |
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
|
843 |
else error = true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
844 |
break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
845 |
default: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
846 |
error = true; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
847 |
break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
848 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
849 |
if (error) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
850 |
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
|
851 |
} |
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 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
854 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
855 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
856 |
private void emitI2X(char type) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
857 |
switch (type) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
858 |
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
|
859 |
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
|
860 |
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
|
861 |
case 'I': /* naught */ break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
862 |
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
|
863 |
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
|
864 |
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
|
865 |
case 'Z': |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
866 |
// For compatibility with ValueConversions and explicitCastArguments: |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
867 |
mv.visitInsn(Opcodes.ICONST_1); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
868 |
mv.visitInsn(Opcodes.IAND); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
869 |
break; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
870 |
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
|
871 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
872 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
873 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
874 |
private void emitX2I(char type) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
875 |
switch (type) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
876 |
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
|
877 |
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
|
878 |
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
|
879 |
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
|
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 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
|
884 |
StringBuilder buf = new StringBuilder(prefix); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
885 |
for (Class<?> ptype : type.parameterList()) |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
886 |
buf.append(Wrapper.forBasicType(ptype).basicTypeChar()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
887 |
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
|
888 |
return buf.toString(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
889 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
890 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
891 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
892 |
* 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
|
893 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
894 |
static MemberName generateLambdaFormInterpreterEntryPoint(String sig) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
895 |
assert(LambdaForm.isValidSignature(sig)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
896 |
//System.out.println("generateExactInvoker "+sig); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
897 |
// compute method type |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
898 |
// first parameter and return type |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
899 |
char tret = LambdaForm.signatureReturn(sig); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
900 |
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
|
901 |
// other parameter types |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
902 |
int arity = LambdaForm.signatureArity(sig); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
903 |
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
|
904 |
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
|
905 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
906 |
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
|
907 |
return g.loadMethod(g.generateLambdaFormInterpreterEntryPointBytes()); |
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 byte[] generateLambdaFormInterpreterEntryPointBytes() { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
911 |
classFilePrologue(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
912 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
913 |
// 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
|
914 |
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
|
915 |
|
14852 | 916 |
// Don't inline the interpreter entry. |
917 |
mv.visitAnnotation("Ljava/lang/invoke/DontInline;", true); |
|
918 |
||
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
919 |
// create parameter array |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
920 |
emitIconstInsn(invokerType.parameterCount()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
921 |
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
|
922 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
923 |
// fill parameter array |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
924 |
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
|
925 |
Class<?> ptype = invokerType.parameterType(i); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
926 |
mv.visitInsn(Opcodes.DUP); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
927 |
emitIconstInsn(i); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
928 |
emitLoadInsn(Wrapper.basicTypeChar(ptype), i); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
929 |
// box if primitive type |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
930 |
if (ptype.isPrimitive()) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
931 |
emitBoxing(ptype); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
932 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
933 |
mv.visitInsn(Opcodes.AASTORE); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
934 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
935 |
// invoke |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
936 |
emitAloadInsn(0); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
937 |
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
|
938 |
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
|
939 |
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
|
940 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
941 |
// maybe unbox |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
942 |
Class<?> rtype = invokerType.returnType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
943 |
if (rtype.isPrimitive() && rtype != void.class) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
944 |
emitUnboxing(Wrapper.asWrapperType(rtype)); |
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 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
947 |
// return statement |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
948 |
emitReturnInsn(rtype); |
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 |
classFileEpilogue(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
951 |
bogusMethod(invokerType); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
952 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
953 |
final byte[] classFile = cw.toByteArray(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
954 |
maybeDump(className, classFile); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
955 |
return classFile; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
956 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
957 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
958 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
959 |
* Generate bytecode for a NamedFunction invoker. |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
960 |
*/ |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
961 |
static MemberName generateNamedFunctionInvoker(MethodTypeForm typeForm) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
962 |
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
|
963 |
String invokerName = basicTypeCharSignature("invoke_", typeForm.erasedType()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
964 |
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
|
965 |
return g.loadMethod(g.generateNamedFunctionInvokerImpl(typeForm)); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
966 |
} |
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 |
static int nfi = 0; |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
969 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
970 |
private byte[] generateNamedFunctionInvokerImpl(MethodTypeForm typeForm) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
971 |
MethodType dstType = typeForm.erasedType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
972 |
classFilePrologue(); |
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 |
// 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
|
975 |
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
|
976 |
|
14852 | 977 |
// Force inlining of this invoker method. |
978 |
mv.visitAnnotation("Ljava/lang/invoke/ForceInline;", true); |
|
979 |
||
13423
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
980 |
// Load receiver |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
981 |
emitAloadInsn(0); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
982 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
983 |
// Load arguments from array |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
984 |
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
|
985 |
emitAloadInsn(1); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
986 |
emitIconstInsn(i); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
987 |
mv.visitInsn(Opcodes.AALOAD); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
988 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
989 |
// Maybe unbox |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
990 |
Class<?> dptype = dstType.parameterType(i); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
991 |
if (dptype.isPrimitive()) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
992 |
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
|
993 |
Wrapper dstWrapper = Wrapper.forBasicType(dptype); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
994 |
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
|
995 |
emitUnboxing(srcWrapper.wrapperType()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
996 |
emitPrimCast(srcWrapper.basicTypeChar(), dstWrapper.basicTypeChar()); |
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 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1000 |
// Invoke |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1001 |
String targetDesc = dstType.basicType().toMethodDescriptorString(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1002 |
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
|
1003 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1004 |
// Box primitive types |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1005 |
Class<?> rtype = dstType.returnType(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1006 |
if (rtype != void.class && rtype.isPrimitive()) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1007 |
Wrapper srcWrapper = Wrapper.forBasicType(rtype); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1008 |
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
|
1009 |
// boolean casts not allowed |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1010 |
emitPrimCast(srcWrapper.basicTypeChar(), dstWrapper.basicTypeChar()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1011 |
emitBoxing(dstWrapper.primitiveType()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1012 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1013 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1014 |
// 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
|
1015 |
if (rtype == void.class) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1016 |
mv.visitInsn(Opcodes.ACONST_NULL); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1017 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1018 |
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
|
1019 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1020 |
classFileEpilogue(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1021 |
bogusMethod(dstType); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1022 |
|
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1023 |
final byte[] classFile = cw.toByteArray(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1024 |
maybeDump(className, classFile); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1025 |
return classFile; |
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 |
/** |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1029 |
* 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
|
1030 |
* for debugging purposes. |
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 |
private void bogusMethod(Object... os) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1033 |
if (DUMP_CLASS_FILES) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1034 |
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
|
1035 |
for (Object o : os) { |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1036 |
mv.visitLdcInsn(o.toString()); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1037 |
mv.visitInsn(Opcodes.POP); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1038 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1039 |
mv.visitInsn(Opcodes.RETURN); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1040 |
mv.visitMaxs(0, 0); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1041 |
mv.visitEnd(); |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1042 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1043 |
} |
17843fff200d
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
diff
changeset
|
1044 |
} |