author | dsamersoff |
Sun, 01 May 2016 12:47:00 +0300 | |
changeset 38152 | 80e5da81fb2c |
parent 35128 | bb8baf284c67 |
child 40059 | c2304140ed64 |
permissions | -rw-r--r-- |
35128
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
1 |
/* |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
4 |
* |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
8 |
* |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
13 |
* accompanied this code). |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
14 |
* |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
18 |
* |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
21 |
* questions. |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
22 |
*/ |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
23 |
|
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
24 |
package compiler.calls.common; |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
25 |
|
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
26 |
import java.io.FileInputStream; |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
27 |
import java.io.IOException; |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
28 |
import java.lang.invoke.CallSite; |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
29 |
import java.lang.invoke.MethodHandles; |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
30 |
import java.lang.invoke.MethodType; |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
31 |
import java.net.URISyntaxException; |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
32 |
import java.nio.file.Files; |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
33 |
import java.nio.file.Path; |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
34 |
import java.nio.file.Paths; |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
35 |
import java.nio.file.StandardOpenOption; |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
36 |
import jdk.internal.org.objectweb.asm.ClassReader; |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
37 |
import jdk.internal.org.objectweb.asm.ClassVisitor; |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
38 |
import jdk.internal.org.objectweb.asm.ClassWriter; |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
39 |
import jdk.internal.org.objectweb.asm.Handle; |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
40 |
import jdk.internal.org.objectweb.asm.Label; |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
41 |
import jdk.internal.org.objectweb.asm.MethodVisitor; |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
42 |
import jdk.internal.org.objectweb.asm.Opcodes; |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
43 |
|
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
44 |
/** |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
45 |
* A class which patch InvokeDynamic class bytecode with invokydynamic |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
46 |
instruction, rewriting "caller" method to call "callee" method using |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
47 |
invokedynamic |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
48 |
*/ |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
49 |
public class InvokeDynamicPatcher extends ClassVisitor { |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
50 |
|
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
51 |
private static final String CLASS = InvokeDynamic.class.getName() |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
52 |
.replace('.', '/'); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
53 |
private static final String CALLER_METHOD_NAME = "caller"; |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
54 |
private static final String CALLEE_METHOD_NAME = "callee"; |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
55 |
private static final String NATIVE_CALLEE_METHOD_NAME = "calleeNative"; |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
56 |
private static final String BOOTSTRAP_METHOD_NAME = "bootstrapMethod"; |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
57 |
private static final String CALL_NATIVE_FIELD = "nativeCallee"; |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
58 |
private static final String CALL_NATIVE_FIELD_DESC = "Z"; |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
59 |
private static final String CALLEE_METHOD_DESC |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
60 |
= "(L" + CLASS + ";IJFDLjava/lang/String;)Z"; |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
61 |
private static final String ASSERTTRUE_METHOD_DESC |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
62 |
= "(ZLjava/lang/String;)V"; |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
63 |
private static final String ASSERTS_CLASS = "jdk/test/lib/Asserts"; |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
64 |
private static final String ASSERTTRUE_METHOD_NAME = "assertTrue"; |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
65 |
|
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
66 |
public static void main(String args[]) { |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
67 |
ClassReader cr; |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
68 |
Path filePath; |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
69 |
try { |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
70 |
filePath = Paths.get(InvokeDynamic.class.getProtectionDomain().getCodeSource() |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
71 |
.getLocation().toURI()).resolve(CLASS + ".class"); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
72 |
} catch (URISyntaxException ex) { |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
73 |
throw new Error("TESTBUG: Can't get code source" + ex, ex); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
74 |
} |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
75 |
try (FileInputStream fis = new FileInputStream(filePath.toFile())) { |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
76 |
cr = new ClassReader(fis); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
77 |
} catch (IOException e) { |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
78 |
throw new Error("Error reading file", e); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
79 |
} |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
80 |
ClassWriter cw = new ClassWriter(cr, |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
81 |
ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
82 |
cr.accept(new InvokeDynamicPatcher(Opcodes.ASM5, cw), 0); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
83 |
try { |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
84 |
Files.write(filePath, cw.toByteArray(), |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
85 |
StandardOpenOption.WRITE); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
86 |
} catch (IOException e) { |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
87 |
throw new Error(e); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
88 |
} |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
89 |
} |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
90 |
|
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
91 |
public InvokeDynamicPatcher(int api, ClassWriter cw) { |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
92 |
super(api, cw); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
93 |
} |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
94 |
|
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
95 |
@Override |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
96 |
public MethodVisitor visitMethod(final int access, final String name, |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
97 |
final String desc, final String signature, |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
98 |
final String[] exceptions) { |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
99 |
/* a code generate looks like |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
100 |
* 0: aload_0 |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
101 |
* 1: ldc #125 // int 1 |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
102 |
* 3: ldc2_w #126 // long 2l |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
103 |
* 6: ldc #128 // float 3.0f |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
104 |
* 8: ldc2_w #129 // double 4.0d |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
105 |
* 11: ldc #132 // String 5 |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
106 |
* 13: aload_0 |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
107 |
* 14: getfield #135 // Field nativeCallee:Z |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
108 |
* 17: ifeq 28 |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
109 |
* 20: invokedynamic #181, 0 // InvokeDynamic #1:calleeNative:(Lcompiler/calls/common/InvokeDynamic;IJFDLjava/lang/String;)Z |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
110 |
* 25: goto 33 |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
111 |
* 28: invokedynamic #183, 0 // InvokeDynamic #1:callee:(Lcompiler/calls/common/InvokeDynamic;IJFDLjava/lang/String;)Z |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
112 |
* 33: ldc #185 // String Call insuccessfull |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
113 |
* 35: invokestatic #191 // Method jdk/test/lib/Asserts.assertTrue:(ZLjava/lang/String;)V |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
114 |
* 38: return |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
115 |
* |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
116 |
* or, using java-like pseudo-code |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
117 |
* if (this.nativeCallee == false) { |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
118 |
* invokedynamic-call-return-value = invokedynamic-of-callee |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
119 |
* } else { |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
120 |
* invokedynamic-call-return-value = invokedynamic-of-nativeCallee |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
121 |
* } |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
122 |
* Asserts.assertTrue(invokedynamic-call-return-value, error-message); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
123 |
* return; |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
124 |
*/ |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
125 |
if (name.equals(CALLER_METHOD_NAME)) { |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
126 |
MethodVisitor mv = cv.visitMethod(access, name, desc, |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
127 |
signature, exceptions); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
128 |
Label nonNativeLabel = new Label(); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
129 |
Label checkLabel = new Label(); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
130 |
MethodType mtype = MethodType.methodType(CallSite.class, |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
131 |
MethodHandles.Lookup.class, String.class, MethodType.class); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
132 |
Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, CLASS, |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
133 |
BOOTSTRAP_METHOD_NAME, mtype.toMethodDescriptorString()); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
134 |
mv.visitCode(); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
135 |
// push callee parameters onto stack |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
136 |
mv.visitVarInsn(Opcodes.ALOAD, 0);//push "this" |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
137 |
mv.visitLdcInsn(1); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
138 |
mv.visitLdcInsn(2L); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
139 |
mv.visitLdcInsn(3.0f); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
140 |
mv.visitLdcInsn(4.0d); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
141 |
mv.visitLdcInsn("5"); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
142 |
// params loaded. let's decide what method to call |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
143 |
mv.visitVarInsn(Opcodes.ALOAD, 0); // push "this" |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
144 |
// get nativeCallee field |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
145 |
mv.visitFieldInsn(Opcodes.GETFIELD, CLASS, CALL_NATIVE_FIELD, |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
146 |
CALL_NATIVE_FIELD_DESC); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
147 |
// if nativeCallee == false goto nonNativeLabel |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
148 |
mv.visitJumpInsn(Opcodes.IFEQ, nonNativeLabel); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
149 |
// invokedynamic nativeCalleeMethod using bootstrap method |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
150 |
mv.visitInvokeDynamicInsn(NATIVE_CALLEE_METHOD_NAME, |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
151 |
CALLEE_METHOD_DESC, bootstrap); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
152 |
// goto checkLabel |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
153 |
mv.visitJumpInsn(Opcodes.GOTO, checkLabel); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
154 |
// label: nonNativeLabel |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
155 |
mv.visitLabel(nonNativeLabel); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
156 |
// invokedynamic calleeMethod using bootstrap method |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
157 |
mv.visitInvokeDynamicInsn(CALLEE_METHOD_NAME, CALLEE_METHOD_DESC, |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
158 |
bootstrap); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
159 |
mv.visitLabel(checkLabel); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
160 |
mv.visitLdcInsn(CallsBase.CALL_ERR_MSG); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
161 |
mv.visitMethodInsn(Opcodes.INVOKESTATIC, ASSERTS_CLASS, |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
162 |
ASSERTTRUE_METHOD_NAME, ASSERTTRUE_METHOD_DESC, false); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
163 |
// label: return |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
164 |
mv.visitInsn(Opcodes.RETURN); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
165 |
mv.visitMaxs(0, 0); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
166 |
mv.visitEnd(); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
167 |
return null; |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
168 |
} |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
169 |
return super.visitMethod(access, name, desc, signature, exceptions); |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
170 |
} |
bb8baf284c67
8141351: Create tests for direct invoke instructions testing
dpochepk
parents:
diff
changeset
|
171 |
} |