Mercurial > hg > truffle
annotate src/share/vm/prims/methodHandles.cpp @ 3456:782e2bb60c41
7052494: Eclipse test fails on JDK 7 b142
Summary: Keep 'ne' test in Counted loop when we can't guarantee during compilation that init < limit.
Reviewed-by: never
author | kvn |
---|---|
date | Mon, 20 Jun 2011 16:45:35 -0700 |
parents | 38fa55e5e792 |
children | 81d815b05abb |
rev | line source |
---|---|
710 | 1 /* |
2116
d810e9a3fc33
7010180: JSR 292 InvokeDynamicPrintArgs fails with: assert(_adapter == NULL) failed: init'd to NULL
twisti
parents:
2088
diff
changeset
|
2 * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. |
710 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1508
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1508
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1508
diff
changeset
|
21 * questions. |
710 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "classfile/symbolTable.hpp" | |
27 #include "interpreter/interpreter.hpp" | |
3388
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
28 #include "interpreter/oopMapCache.hpp" |
1972 | 29 #include "memory/allocation.inline.hpp" |
30 #include "memory/oopFactory.hpp" | |
31 #include "prims/methodHandles.hpp" | |
3388
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
32 #include "prims/methodHandleWalk.hpp" |
1972 | 33 #include "runtime/javaCalls.hpp" |
34 #include "runtime/reflection.hpp" | |
35 #include "runtime/signature.hpp" | |
36 #include "runtime/stubRoutines.hpp" | |
37 | |
710 | 38 /* |
39 * JSR 292 reference implementation: method handles | |
40 */ | |
41 | |
42 bool MethodHandles::_enabled = false; // set true after successful native linkage | |
43 | |
44 MethodHandleEntry* MethodHandles::_entries[MethodHandles::_EK_LIMIT] = {NULL}; | |
45 const char* MethodHandles::_entry_names[_EK_LIMIT+1] = { | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
46 "raise_exception", |
710 | 47 "invokestatic", // how a MH emulates invokestatic |
48 "invokespecial", // ditto for the other invokes... | |
49 "invokevirtual", | |
50 "invokeinterface", | |
51 "bound_ref", // these are for BMH... | |
52 "bound_int", | |
53 "bound_long", | |
54 "bound_ref_direct", // (direct versions have a direct methodOop) | |
55 "bound_int_direct", | |
56 "bound_long_direct", | |
57 | |
58 // starting at _adapter_mh_first: | |
59 "adapter_retype_only", // these are for AMH... | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
60 "adapter_retype_raw", |
710 | 61 "adapter_check_cast", |
62 "adapter_prim_to_prim", | |
63 "adapter_ref_to_prim", | |
64 "adapter_prim_to_ref", | |
65 "adapter_swap_args", | |
66 "adapter_rot_args", | |
67 "adapter_dup_args", | |
68 "adapter_drop_args", | |
69 "adapter_collect_args", | |
70 "adapter_spread_args", | |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
71 "adapter_fold_args", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
72 "adapter_unused_13", |
710 | 73 |
74 // optimized adapter types: | |
75 "adapter_swap_args/1", | |
76 "adapter_swap_args/2", | |
77 "adapter_rot_args/1,up", | |
78 "adapter_rot_args/1,down", | |
79 "adapter_rot_args/2,up", | |
80 "adapter_rot_args/2,down", | |
81 "adapter_prim_to_prim/i2i", | |
82 "adapter_prim_to_prim/l2i", | |
83 "adapter_prim_to_prim/d2f", | |
84 "adapter_prim_to_prim/i2l", | |
85 "adapter_prim_to_prim/f2d", | |
86 "adapter_ref_to_prim/unboxi", | |
87 "adapter_ref_to_prim/unboxl", | |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
88 |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
89 // return value handlers for collect/filter/fold adapters: |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
90 "return/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
91 "return/int", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
92 "return/long", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
93 "return/float", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
94 "return/double", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
95 "return/void", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
96 "return/S0/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
97 "return/S1/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
98 "return/S2/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
99 "return/S3/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
100 "return/S4/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
101 "return/S5/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
102 "return/any", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
103 |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
104 // spreading (array length cases 0, 1, ...) |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
105 "adapter_spread/0", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
106 "adapter_spread/1/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
107 "adapter_spread/2/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
108 "adapter_spread/3/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
109 "adapter_spread/4/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
110 "adapter_spread/5/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
111 "adapter_spread/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
112 "adapter_spread/byte", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
113 "adapter_spread/char", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
114 "adapter_spread/short", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
115 "adapter_spread/int", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
116 "adapter_spread/long", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
117 "adapter_spread/float", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
118 "adapter_spread/double", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
119 |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
120 // blocking filter/collect conversions: |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
121 "adapter_collect/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
122 "adapter_collect/int", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
123 "adapter_collect/long", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
124 "adapter_collect/float", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
125 "adapter_collect/double", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
126 "adapter_collect/void", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
127 "adapter_collect/0/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
128 "adapter_collect/1/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
129 "adapter_collect/2/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
130 "adapter_collect/3/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
131 "adapter_collect/4/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
132 "adapter_collect/5/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
133 "adapter_filter/S0/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
134 "adapter_filter/S1/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
135 "adapter_filter/S2/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
136 "adapter_filter/S3/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
137 "adapter_filter/S4/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
138 "adapter_filter/S5/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
139 "adapter_collect/2/S0/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
140 "adapter_collect/2/S1/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
141 "adapter_collect/2/S2/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
142 "adapter_collect/2/S3/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
143 "adapter_collect/2/S4/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
144 "adapter_collect/2/S5/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
145 |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
146 // blocking fold conversions: |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
147 "adapter_fold/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
148 "adapter_fold/int", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
149 "adapter_fold/long", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
150 "adapter_fold/float", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
151 "adapter_fold/double", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
152 "adapter_fold/void", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
153 "adapter_fold/1/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
154 "adapter_fold/2/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
155 "adapter_fold/3/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
156 "adapter_fold/4/ref", |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
157 "adapter_fold/5/ref", |
710 | 158 |
159 NULL | |
160 }; | |
161 | |
1299
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
162 // Adapters. |
3442
f7d55ea6ee56
7045514: SPARC assembly code for JSR 292 ricochet frames
never
parents:
3417
diff
changeset
|
163 MethodHandlesAdapterBlob* MethodHandles::_adapter_code = NULL; |
1299
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
164 |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
165 jobject MethodHandles::_raise_exception_method; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
166 |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
167 address MethodHandles::_adapter_return_handlers[CONV_TYPE_MASK+1]; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
168 |
710 | 169 #ifdef ASSERT |
170 bool MethodHandles::spot_check_entry_names() { | |
171 assert(!strcmp(entry_name(_invokestatic_mh), "invokestatic"), ""); | |
172 assert(!strcmp(entry_name(_bound_ref_mh), "bound_ref"), ""); | |
173 assert(!strcmp(entry_name(_adapter_retype_only), "adapter_retype_only"), ""); | |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
174 assert(!strcmp(entry_name(_adapter_fold_args), "adapter_fold_args"), ""); |
710 | 175 assert(!strcmp(entry_name(_adapter_opt_unboxi), "adapter_ref_to_prim/unboxi"), ""); |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
176 assert(!strcmp(entry_name(_adapter_opt_spread_char), "adapter_spread/char"), ""); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
177 assert(!strcmp(entry_name(_adapter_opt_spread_double), "adapter_spread/double"), ""); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
178 assert(!strcmp(entry_name(_adapter_opt_collect_int), "adapter_collect/int"), ""); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
179 assert(!strcmp(entry_name(_adapter_opt_collect_0_ref), "adapter_collect/0/ref"), ""); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
180 assert(!strcmp(entry_name(_adapter_opt_collect_2_S3_ref), "adapter_collect/2/S3/ref"), ""); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
181 assert(!strcmp(entry_name(_adapter_opt_filter_S5_ref), "adapter_filter/S5/ref"), ""); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
182 assert(!strcmp(entry_name(_adapter_opt_fold_3_ref), "adapter_fold/3/ref"), ""); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
183 assert(!strcmp(entry_name(_adapter_opt_fold_void), "adapter_fold/void"), ""); |
710 | 184 return true; |
185 } | |
186 #endif | |
187 | |
1299
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
188 |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
189 //------------------------------------------------------------------------------ |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
190 // MethodHandles::generate_adapters |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
191 // |
2116
d810e9a3fc33
7010180: JSR 292 InvokeDynamicPrintArgs fails with: assert(_adapter == NULL) failed: init'd to NULL
twisti
parents:
2088
diff
changeset
|
192 void MethodHandles::generate_adapters() { |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
193 #ifdef TARGET_ARCH_NYI_6939861 |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
194 if (FLAG_IS_DEFAULT(UseRicochetFrames)) UseRicochetFrames = false; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
195 #endif |
2416
38fea01eb669
6817525: turn on method handle functionality by default for JSR 292
twisti
parents:
2357
diff
changeset
|
196 if (!EnableInvokeDynamic || SystemDictionary::MethodHandle_klass() == NULL) return; |
1299
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
197 |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
198 assert(_adapter_code == NULL, "generate only once"); |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
199 |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
200 ResourceMark rm; |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
201 TraceTime timer("MethodHandles adapters generation", TraceStartupTime); |
3442
f7d55ea6ee56
7045514: SPARC assembly code for JSR 292 ricochet frames
never
parents:
3417
diff
changeset
|
202 _adapter_code = MethodHandlesAdapterBlob::create(adapter_code_size); |
1299
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
203 if (_adapter_code == NULL) |
3442
f7d55ea6ee56
7045514: SPARC assembly code for JSR 292 ricochet frames
never
parents:
3417
diff
changeset
|
204 vm_exit_out_of_memory(adapter_code_size, "CodeCache: no room for MethodHandles adapters"); |
1748 | 205 CodeBuffer code(_adapter_code); |
1299
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
206 MethodHandlesAdapterGenerator g(&code); |
2116
d810e9a3fc33
7010180: JSR 292 InvokeDynamicPrintArgs fails with: assert(_adapter == NULL) failed: init'd to NULL
twisti
parents:
2088
diff
changeset
|
207 g.generate(); |
1299
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
208 } |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
209 |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
210 //------------------------------------------------------------------------------ |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
211 // MethodHandlesAdapterGenerator::generate |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
212 // |
2116
d810e9a3fc33
7010180: JSR 292 InvokeDynamicPrintArgs fails with: assert(_adapter == NULL) failed: init'd to NULL
twisti
parents:
2088
diff
changeset
|
213 void MethodHandlesAdapterGenerator::generate() { |
1299
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
214 // Generate generic method handle adapters. |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
215 for (MethodHandles::EntryKind ek = MethodHandles::_EK_FIRST; |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
216 ek < MethodHandles::_EK_LIMIT; |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
217 ek = MethodHandles::EntryKind(1 + (int)ek)) { |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
218 if (MethodHandles::ek_supported(ek)) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
219 StubCodeMark mark(this, "MethodHandle", MethodHandles::entry_name(ek)); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
220 MethodHandles::generate_method_handle_stub(_masm, ek); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
221 } |
1299
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
222 } |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
223 } |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
224 |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
225 |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
226 #ifdef TARGET_ARCH_NYI_6939861 |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
227 // these defs belong in methodHandles_<arch>.cpp |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
228 frame MethodHandles::ricochet_frame_sender(const frame& fr, RegisterMap *map) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
229 ShouldNotCallThis(); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
230 return fr; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
231 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
232 void MethodHandles::ricochet_frame_oops_do(const frame& fr, OopClosure* f, const RegisterMap* reg_map) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
233 ShouldNotCallThis(); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
234 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
235 #endif //TARGET_ARCH_NYI_6939861 |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
236 |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
237 |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
238 //------------------------------------------------------------------------------ |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
239 // MethodHandles::ek_supported |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
240 // |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
241 bool MethodHandles::ek_supported(MethodHandles::EntryKind ek) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
242 MethodHandles::EntryKind ek_orig = MethodHandles::ek_original_kind(ek); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
243 switch (ek_orig) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
244 case _adapter_unused_13: |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
245 return false; // not defined yet |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
246 case _adapter_prim_to_ref: |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
247 return UseRicochetFrames && conv_op_supported(java_lang_invoke_AdapterMethodHandle::OP_PRIM_TO_REF); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
248 case _adapter_collect_args: |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
249 return UseRicochetFrames && conv_op_supported(java_lang_invoke_AdapterMethodHandle::OP_COLLECT_ARGS); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
250 case _adapter_fold_args: |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
251 return UseRicochetFrames && conv_op_supported(java_lang_invoke_AdapterMethodHandle::OP_FOLD_ARGS); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
252 case _adapter_opt_return_any: |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
253 return UseRicochetFrames; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
254 #ifdef TARGET_ARCH_NYI_6939861 |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
255 // ports before 6939861 supported only three kinds of spread ops |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
256 case _adapter_spread_args: |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
257 // restrict spreads to three kinds: |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
258 switch (ek) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
259 case _adapter_opt_spread_0: |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
260 case _adapter_opt_spread_1: |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
261 case _adapter_opt_spread_more: |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
262 break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
263 default: |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
264 return false; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
265 break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
266 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
267 break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
268 #endif //TARGET_ARCH_NYI_6939861 |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
269 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
270 return true; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
271 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
272 |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
273 |
710 | 274 void MethodHandles::set_enabled(bool z) { |
275 if (_enabled != z) { | |
2416
38fea01eb669
6817525: turn on method handle functionality by default for JSR 292
twisti
parents:
2357
diff
changeset
|
276 guarantee(z && EnableInvokeDynamic, "can only enable once, and only if -XX:+EnableInvokeDynamic"); |
710 | 277 _enabled = z; |
278 } | |
279 } | |
280 | |
281 // Note: A method which does not have a TRAPS argument cannot block in the GC | |
282 // or throw exceptions. Such methods are used in this file to do something quick | |
283 // and local, like parse a data structure. For speed, such methods work on plain | |
284 // oops, not handles. Trapping methods uniformly operate on handles. | |
285 | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
286 methodHandle MethodHandles::decode_vmtarget(oop vmtarget, int vmindex, oop mtype, |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
287 KlassHandle& receiver_limit_result, int& decode_flags_result) { |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
288 if (vmtarget == NULL) return methodHandle(); |
710 | 289 assert(methodOopDesc::nonvirtual_vtable_index < 0, "encoding"); |
290 if (vmindex < 0) { | |
291 // this DMH performs no dispatch; it is directly bound to a methodOop | |
292 // A MemberName may either be directly bound to a methodOop, | |
293 // or it may use the klass/index form; both forms mean the same thing. | |
294 methodOop m = decode_methodOop(methodOop(vmtarget), decode_flags_result); | |
295 if ((decode_flags_result & _dmf_has_receiver) != 0 | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
296 && java_lang_invoke_MethodType::is_instance(mtype)) { |
710 | 297 // Extract receiver type restriction from mtype.ptypes[0]. |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
298 objArrayOop ptypes = java_lang_invoke_MethodType::ptypes(mtype); |
710 | 299 oop ptype0 = (ptypes == NULL || ptypes->length() < 1) ? oop(NULL) : ptypes->obj_at(0); |
300 if (java_lang_Class::is_instance(ptype0)) | |
301 receiver_limit_result = java_lang_Class::as_klassOop(ptype0); | |
302 } | |
303 if (vmindex == methodOopDesc::nonvirtual_vtable_index) { | |
304 // this DMH can be an "invokespecial" version | |
305 decode_flags_result &= ~_dmf_does_dispatch; | |
306 } else { | |
307 assert(vmindex == methodOopDesc::invalid_vtable_index, "random vmindex?"); | |
308 } | |
309 return m; | |
310 } else { | |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
311 assert(vmtarget->is_klass(), "must be class or interface"); |
710 | 312 decode_flags_result |= MethodHandles::_dmf_does_dispatch; |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
313 decode_flags_result |= MethodHandles::_dmf_has_receiver; |
710 | 314 receiver_limit_result = (klassOop)vmtarget; |
315 Klass* tk = Klass::cast((klassOop)vmtarget); | |
316 if (tk->is_interface()) { | |
317 // an itable linkage is <interface, itable index> | |
318 decode_flags_result |= MethodHandles::_dmf_from_interface; | |
319 return klassItable::method_for_itable_index((klassOop)vmtarget, vmindex); | |
320 } else { | |
321 if (!tk->oop_is_instance()) | |
1142 | 322 tk = instanceKlass::cast(SystemDictionary::Object_klass()); |
710 | 323 return ((instanceKlass*)tk)->method_at_vtable(vmindex); |
324 } | |
325 } | |
326 } | |
327 | |
328 // MemberName and DirectMethodHandle have the same linkage to the JVM internals. | |
329 // (MemberName is the non-operational name used for queries and setup.) | |
330 | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
331 methodHandle MethodHandles::decode_DirectMethodHandle(oop mh, KlassHandle& receiver_limit_result, int& decode_flags_result) { |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
332 oop vmtarget = java_lang_invoke_DirectMethodHandle::vmtarget(mh); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
333 int vmindex = java_lang_invoke_DirectMethodHandle::vmindex(mh); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
334 oop mtype = java_lang_invoke_DirectMethodHandle::type(mh); |
710 | 335 return decode_vmtarget(vmtarget, vmindex, mtype, receiver_limit_result, decode_flags_result); |
336 } | |
337 | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
338 methodHandle MethodHandles::decode_BoundMethodHandle(oop mh, KlassHandle& receiver_limit_result, int& decode_flags_result) { |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
339 assert(java_lang_invoke_BoundMethodHandle::is_instance(mh), ""); |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
340 assert(mh->klass() != SystemDictionary::AdapterMethodHandle_klass(), ""); |
710 | 341 for (oop bmh = mh;;) { |
342 // Bound MHs can be stacked to bind several arguments. | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
343 oop target = java_lang_invoke_MethodHandle::vmtarget(bmh); |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
344 if (target == NULL) return methodHandle(); |
710 | 345 decode_flags_result |= MethodHandles::_dmf_binds_argument; |
346 klassOop tk = target->klass(); | |
347 if (tk == SystemDictionary::BoundMethodHandle_klass()) { | |
348 bmh = target; | |
349 continue; | |
350 } else { | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
351 if (java_lang_invoke_MethodHandle::is_subclass(tk)) { |
710 | 352 //assert(tk == SystemDictionary::DirectMethodHandle_klass(), "end of BMH chain must be DMH"); |
353 return decode_MethodHandle(target, receiver_limit_result, decode_flags_result); | |
354 } else { | |
355 // Optimized case: binding a receiver to a non-dispatched DMH | |
356 // short-circuits directly to the methodOop. | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
357 // (It might be another argument besides a receiver also.) |
710 | 358 assert(target->is_method(), "must be a simple method"); |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
359 decode_flags_result |= MethodHandles::_dmf_binds_method; |
710 | 360 methodOop m = (methodOop) target; |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
361 if (!m->is_static()) |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
362 decode_flags_result |= MethodHandles::_dmf_has_receiver; |
710 | 363 return m; |
364 } | |
365 } | |
366 } | |
367 } | |
368 | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
369 methodHandle MethodHandles::decode_AdapterMethodHandle(oop mh, KlassHandle& receiver_limit_result, int& decode_flags_result) { |
710 | 370 assert(mh->klass() == SystemDictionary::AdapterMethodHandle_klass(), ""); |
371 for (oop amh = mh;;) { | |
372 // Adapter MHs can be stacked to convert several arguments. | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
373 int conv_op = adapter_conversion_op(java_lang_invoke_AdapterMethodHandle::conversion(amh)); |
710 | 374 decode_flags_result |= (_dmf_adapter_lsb << conv_op) & _DMF_ADAPTER_MASK; |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
375 oop target = java_lang_invoke_MethodHandle::vmtarget(amh); |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
376 if (target == NULL) return methodHandle(); |
710 | 377 klassOop tk = target->klass(); |
378 if (tk == SystemDictionary::AdapterMethodHandle_klass()) { | |
379 amh = target; | |
380 continue; | |
381 } else { | |
382 // must be a BMH (which will bind some more arguments) or a DMH (for the final call) | |
383 return MethodHandles::decode_MethodHandle(target, receiver_limit_result, decode_flags_result); | |
384 } | |
385 } | |
386 } | |
387 | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
388 methodHandle MethodHandles::decode_MethodHandle(oop mh, KlassHandle& receiver_limit_result, int& decode_flags_result) { |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
389 if (mh == NULL) return methodHandle(); |
710 | 390 klassOop mhk = mh->klass(); |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
391 assert(java_lang_invoke_MethodHandle::is_subclass(mhk), "must be a MethodHandle"); |
710 | 392 if (mhk == SystemDictionary::DirectMethodHandle_klass()) { |
393 return decode_DirectMethodHandle(mh, receiver_limit_result, decode_flags_result); | |
394 } else if (mhk == SystemDictionary::BoundMethodHandle_klass()) { | |
395 return decode_BoundMethodHandle(mh, receiver_limit_result, decode_flags_result); | |
396 } else if (mhk == SystemDictionary::AdapterMethodHandle_klass()) { | |
397 return decode_AdapterMethodHandle(mh, receiver_limit_result, decode_flags_result); | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
398 } else if (java_lang_invoke_BoundMethodHandle::is_subclass(mhk)) { |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
399 // could be a JavaMethodHandle (but not an adapter MH) |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
400 return decode_BoundMethodHandle(mh, receiver_limit_result, decode_flags_result); |
710 | 401 } else { |
402 assert(false, "cannot parse this MH"); | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
403 return methodHandle(); // random MH? |
710 | 404 } |
405 } | |
406 | |
407 methodOop MethodHandles::decode_methodOop(methodOop m, int& decode_flags_result) { | |
408 assert(m->is_method(), ""); | |
409 if (m->is_static()) { | |
410 // check that signature begins '(L' or '([' (not '(I', '()', etc.) | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
411 Symbol* sig = m->signature(); |
710 | 412 BasicType recv_bt = char2type(sig->byte_at(1)); |
413 // Note: recv_bt might be T_ILLEGAL if byte_at(2) is ')' | |
414 assert(sig->byte_at(0) == '(', "must be method sig"); | |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
415 // if (recv_bt == T_OBJECT || recv_bt == T_ARRAY) |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
416 // decode_flags_result |= _dmf_has_receiver; |
710 | 417 } else { |
418 // non-static method | |
419 decode_flags_result |= _dmf_has_receiver; | |
420 if (!m->can_be_statically_bound() && !m->is_initializer()) { | |
421 decode_flags_result |= _dmf_does_dispatch; | |
422 if (Klass::cast(m->method_holder())->is_interface()) | |
423 decode_flags_result |= _dmf_from_interface; | |
424 } | |
425 } | |
426 return m; | |
427 } | |
428 | |
429 | |
430 // A trusted party is handing us a cookie to determine a method. | |
431 // Let's boil it down to the method oop they really want. | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
432 methodHandle MethodHandles::decode_method(oop x, KlassHandle& receiver_limit_result, int& decode_flags_result) { |
710 | 433 decode_flags_result = 0; |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
434 receiver_limit_result = KlassHandle(); |
710 | 435 klassOop xk = x->klass(); |
436 if (xk == Universe::methodKlassObj()) { | |
437 return decode_methodOop((methodOop) x, decode_flags_result); | |
438 } else if (xk == SystemDictionary::MemberName_klass()) { | |
439 // Note: This only works if the MemberName has already been resolved. | |
440 return decode_MemberName(x, receiver_limit_result, decode_flags_result); | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
441 } else if (java_lang_invoke_MethodHandle::is_subclass(xk)) { |
710 | 442 return decode_MethodHandle(x, receiver_limit_result, decode_flags_result); |
1142 | 443 } else if (xk == SystemDictionary::reflect_Method_klass()) { |
710 | 444 oop clazz = java_lang_reflect_Method::clazz(x); |
445 int slot = java_lang_reflect_Method::slot(x); | |
446 klassOop k = java_lang_Class::as_klassOop(clazz); | |
447 if (k != NULL && Klass::cast(k)->oop_is_instance()) | |
448 return decode_methodOop(instanceKlass::cast(k)->method_with_idnum(slot), | |
449 decode_flags_result); | |
1142 | 450 } else if (xk == SystemDictionary::reflect_Constructor_klass()) { |
710 | 451 oop clazz = java_lang_reflect_Constructor::clazz(x); |
452 int slot = java_lang_reflect_Constructor::slot(x); | |
453 klassOop k = java_lang_Class::as_klassOop(clazz); | |
454 if (k != NULL && Klass::cast(k)->oop_is_instance()) | |
455 return decode_methodOop(instanceKlass::cast(k)->method_with_idnum(slot), | |
456 decode_flags_result); | |
457 } else { | |
458 // unrecognized object | |
459 assert(!x->is_method(), "already checked"); | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
460 assert(!java_lang_invoke_MemberName::is_instance(x), "already checked"); |
710 | 461 } |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
462 return methodHandle(); |
710 | 463 } |
464 | |
465 | |
466 int MethodHandles::decode_MethodHandle_stack_pushes(oop mh) { | |
467 if (mh->klass() == SystemDictionary::DirectMethodHandle_klass()) | |
468 return 0; // no push/pop | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
469 int this_vmslots = java_lang_invoke_MethodHandle::vmslots(mh); |
710 | 470 int last_vmslots = 0; |
471 oop last_mh = mh; | |
472 for (;;) { | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
473 oop target = java_lang_invoke_MethodHandle::vmtarget(last_mh); |
710 | 474 if (target->klass() == SystemDictionary::DirectMethodHandle_klass()) { |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
475 last_vmslots = java_lang_invoke_MethodHandle::vmslots(target); |
710 | 476 break; |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
477 } else if (!java_lang_invoke_MethodHandle::is_instance(target)) { |
710 | 478 // might be klass or method |
479 assert(target->is_method(), "must get here with a direct ref to method"); | |
480 last_vmslots = methodOop(target)->size_of_parameters(); | |
481 break; | |
482 } | |
483 last_mh = target; | |
484 } | |
485 // If I am called with fewer VM slots than my ultimate callee, | |
486 // it must be that I push the additionally needed slots. | |
487 // Likewise if am called with more VM slots, I will pop them. | |
488 return (last_vmslots - this_vmslots); | |
489 } | |
490 | |
491 | |
492 // MemberName support | |
493 | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
494 // import java_lang_invoke_MemberName.* |
710 | 495 enum { |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
496 IS_METHOD = java_lang_invoke_MemberName::MN_IS_METHOD, |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
497 IS_CONSTRUCTOR = java_lang_invoke_MemberName::MN_IS_CONSTRUCTOR, |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
498 IS_FIELD = java_lang_invoke_MemberName::MN_IS_FIELD, |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
499 IS_TYPE = java_lang_invoke_MemberName::MN_IS_TYPE, |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
500 SEARCH_SUPERCLASSES = java_lang_invoke_MemberName::MN_SEARCH_SUPERCLASSES, |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
501 SEARCH_INTERFACES = java_lang_invoke_MemberName::MN_SEARCH_INTERFACES, |
710 | 502 ALL_KINDS = IS_METHOD | IS_CONSTRUCTOR | IS_FIELD | IS_TYPE, |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
503 VM_INDEX_UNINITIALIZED = java_lang_invoke_MemberName::VM_INDEX_UNINITIALIZED |
710 | 504 }; |
505 | |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
506 Handle MethodHandles::new_MemberName(TRAPS) { |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
507 Handle empty; |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
508 instanceKlassHandle k(THREAD, SystemDictionary::MemberName_klass()); |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
509 if (!k->is_initialized()) k->initialize(CHECK_(empty)); |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
510 return Handle(THREAD, k->allocate_instance(THREAD)); |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
511 } |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
512 |
710 | 513 void MethodHandles::init_MemberName(oop mname_oop, oop target_oop) { |
1142 | 514 if (target_oop->klass() == SystemDictionary::reflect_Field_klass()) { |
710 | 515 oop clazz = java_lang_reflect_Field::clazz(target_oop); // fd.field_holder() |
516 int slot = java_lang_reflect_Field::slot(target_oop); // fd.index() | |
517 int mods = java_lang_reflect_Field::modifiers(target_oop); | |
518 klassOop k = java_lang_Class::as_klassOop(clazz); | |
519 int offset = instanceKlass::cast(k)->offset_from_fields(slot); | |
520 init_MemberName(mname_oop, k, accessFlags_from(mods), offset); | |
521 } else { | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
522 KlassHandle receiver_limit; int decode_flags = 0; |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
523 methodHandle m = MethodHandles::decode_method(target_oop, receiver_limit, decode_flags); |
710 | 524 bool do_dispatch = ((decode_flags & MethodHandles::_dmf_does_dispatch) != 0); |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
525 init_MemberName(mname_oop, m(), do_dispatch); |
710 | 526 } |
527 } | |
528 | |
529 void MethodHandles::init_MemberName(oop mname_oop, methodOop m, bool do_dispatch) { | |
530 int flags = ((m->is_initializer() ? IS_CONSTRUCTOR : IS_METHOD) | |
531 | (jushort)( m->access_flags().as_short() & JVM_RECOGNIZED_METHOD_MODIFIERS )); | |
532 oop vmtarget = m; | |
533 int vmindex = methodOopDesc::invalid_vtable_index; // implies no info yet | |
534 if (!do_dispatch || (flags & IS_CONSTRUCTOR) || m->can_be_statically_bound()) | |
535 vmindex = methodOopDesc::nonvirtual_vtable_index; // implies never any dispatch | |
536 assert(vmindex != VM_INDEX_UNINITIALIZED, "Java sentinel value"); | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
537 java_lang_invoke_MemberName::set_vmtarget(mname_oop, vmtarget); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
538 java_lang_invoke_MemberName::set_vmindex(mname_oop, vmindex); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
539 java_lang_invoke_MemberName::set_flags(mname_oop, flags); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
540 java_lang_invoke_MemberName::set_clazz(mname_oop, Klass::cast(m->method_holder())->java_mirror()); |
710 | 541 } |
542 | |
543 void MethodHandles::init_MemberName(oop mname_oop, klassOop field_holder, AccessFlags mods, int offset) { | |
544 int flags = (IS_FIELD | (jushort)( mods.as_short() & JVM_RECOGNIZED_FIELD_MODIFIERS )); | |
545 oop vmtarget = field_holder; | |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
546 int vmindex = offset; // determines the field uniquely when combined with static bit |
710 | 547 assert(vmindex != VM_INDEX_UNINITIALIZED, "bad alias on vmindex"); |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
548 java_lang_invoke_MemberName::set_vmtarget(mname_oop, vmtarget); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
549 java_lang_invoke_MemberName::set_vmindex(mname_oop, vmindex); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
550 java_lang_invoke_MemberName::set_flags(mname_oop, flags); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
551 java_lang_invoke_MemberName::set_clazz(mname_oop, Klass::cast(field_holder)->java_mirror()); |
710 | 552 } |
553 | |
554 | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
555 methodHandle MethodHandles::decode_MemberName(oop mname, KlassHandle& receiver_limit_result, int& decode_flags_result) { |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
556 methodHandle empty; |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
557 int flags = java_lang_invoke_MemberName::flags(mname); |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
558 if ((flags & (IS_METHOD | IS_CONSTRUCTOR)) == 0) return empty; // not invocable |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
559 oop vmtarget = java_lang_invoke_MemberName::vmtarget(mname); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
560 int vmindex = java_lang_invoke_MemberName::vmindex(mname); |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
561 if (vmindex == VM_INDEX_UNINITIALIZED) return empty; // not resolved |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
562 methodHandle m = decode_vmtarget(vmtarget, vmindex, NULL, receiver_limit_result, decode_flags_result); |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
563 oop clazz = java_lang_invoke_MemberName::clazz(mname); |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
564 if (clazz != NULL && java_lang_Class::is_instance(clazz)) { |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
565 klassOop klass = java_lang_Class::as_klassOop(clazz); |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
566 if (klass != NULL) receiver_limit_result = klass; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
567 } |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
568 return m; |
710 | 569 } |
570 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
571 // convert the external string or reflective type to an internal signature |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
572 Symbol* MethodHandles::convert_to_signature(oop type_str, bool polymorphic, TRAPS) { |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
573 if (java_lang_invoke_MethodType::is_instance(type_str)) { |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
574 return java_lang_invoke_MethodType::as_signature(type_str, polymorphic, CHECK_NULL); |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
575 } else if (java_lang_Class::is_instance(type_str)) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
576 return java_lang_Class::as_signature(type_str, false, CHECK_NULL); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
577 } else if (java_lang_String::is_instance(type_str)) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
578 if (polymorphic) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
579 return java_lang_String::as_symbol(type_str, CHECK_NULL); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
580 } else { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
581 return java_lang_String::as_symbol_or_null(type_str); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
582 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
583 } else { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
584 THROW_MSG_(vmSymbols::java_lang_InternalError(), "unrecognized type", NULL); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
585 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
586 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
587 |
710 | 588 // An unresolved member name is a mere symbolic reference. |
589 // Resolving it plants a vmtarget/vmindex in it, | |
590 // which refers dirctly to JVM internals. | |
591 void MethodHandles::resolve_MemberName(Handle mname, TRAPS) { | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
592 assert(java_lang_invoke_MemberName::is_instance(mname()), ""); |
710 | 593 #ifdef ASSERT |
594 // If this assert throws, renegotiate the sentinel value used by the Java code, | |
595 // so that it is distinct from any valid vtable index value, and any special | |
596 // values defined in methodOopDesc::VtableIndexFlag. | |
597 // The point of the slop is to give the Java code and the JVM some room | |
598 // to independently specify sentinel values. | |
599 const int sentinel_slop = 10; | |
600 const int sentinel_limit = methodOopDesc::highest_unused_vtable_index_value - sentinel_slop; | |
601 assert(VM_INDEX_UNINITIALIZED < sentinel_limit, "Java sentinel != JVM sentinels"); | |
602 #endif | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
603 if (java_lang_invoke_MemberName::vmindex(mname()) != VM_INDEX_UNINITIALIZED) |
710 | 604 return; // already resolved |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
605 Handle defc_oop(THREAD, java_lang_invoke_MemberName::clazz(mname())); |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
606 Handle name_str(THREAD, java_lang_invoke_MemberName::name( mname())); |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
607 Handle type_str(THREAD, java_lang_invoke_MemberName::type( mname())); |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
608 int flags = java_lang_invoke_MemberName::flags(mname()); |
710 | 609 |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
610 if (defc_oop.is_null() || name_str.is_null() || type_str.is_null()) { |
710 | 611 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "nothing to resolve"); |
612 } | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
613 |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
614 instanceKlassHandle defc; |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
615 { |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
616 klassOop defc_klassOop = java_lang_Class::as_klassOop(defc_oop()); |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
617 if (defc_klassOop == NULL) return; // a primitive; no resolution possible |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
618 if (!Klass::cast(defc_klassOop)->oop_is_instance()) { |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
619 if (!Klass::cast(defc_klassOop)->oop_is_array()) return; |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
620 defc_klassOop = SystemDictionary::Object_klass(); |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
621 } |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
622 defc = instanceKlassHandle(THREAD, defc_klassOop); |
710 | 623 } |
624 if (defc.is_null()) { | |
625 THROW_MSG(vmSymbols::java_lang_InternalError(), "primitive class"); | |
626 } | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
627 defc->link_class(CHECK); // possible safepoint |
710 | 628 |
629 // convert the external string name to an internal symbol | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
630 TempNewSymbol name = java_lang_String::as_symbol_or_null(name_str()); |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
631 if (name == NULL) return; // no such name |
3451
38fa55e5e792
7055355: JSR 292: crash while throwing WrongMethodTypeException
never
parents:
3449
diff
changeset
|
632 if (name == vmSymbols::class_initializer_name()) |
38fa55e5e792
7055355: JSR 292: crash while throwing WrongMethodTypeException
never
parents:
3449
diff
changeset
|
633 return; // illegal name |
710 | 634 |
1508
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
635 Handle polymorphic_method_type; |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
636 bool polymorphic_signature = false; |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
637 if ((flags & ALL_KINDS) == IS_METHOD && |
2001
f2da85a9b08e
7001363: java/dyn/InvokeDynamic should not be a well-known class in the JVM
twisti
parents:
1972
diff
changeset
|
638 (defc() == SystemDictionary::MethodHandle_klass() && |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
639 methodOopDesc::is_method_handle_invoke_name(name))) { |
1508
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
640 polymorphic_signature = true; |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
641 } |
1508
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
642 |
710 | 643 // convert the external string or reflective type to an internal signature |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
644 TempNewSymbol type = convert_to_signature(type_str(), polymorphic_signature, CHECK); |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
645 if (java_lang_invoke_MethodType::is_instance(type_str()) && polymorphic_signature) { |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
646 polymorphic_method_type = type_str; // preserve exactly |
710 | 647 } |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
648 if (type == NULL) return; // no such signature exists in the VM |
710 | 649 |
650 // Time to do the lookup. | |
651 switch (flags & ALL_KINDS) { | |
652 case IS_METHOD: | |
653 { | |
654 CallInfo result; | |
655 { | |
656 EXCEPTION_MARK; | |
657 if ((flags & JVM_ACC_STATIC) != 0) { | |
658 LinkResolver::resolve_static_call(result, | |
659 defc, name, type, KlassHandle(), false, false, THREAD); | |
660 } else if (defc->is_interface()) { | |
661 LinkResolver::resolve_interface_call(result, Handle(), defc, | |
662 defc, name, type, KlassHandle(), false, false, THREAD); | |
663 } else { | |
664 LinkResolver::resolve_virtual_call(result, Handle(), defc, | |
665 defc, name, type, KlassHandle(), false, false, THREAD); | |
666 } | |
667 if (HAS_PENDING_EXCEPTION) { | |
668 CLEAR_PENDING_EXCEPTION; | |
1508
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
669 break; // go to second chance |
710 | 670 } |
671 } | |
672 methodHandle m = result.resolved_method(); | |
673 oop vmtarget = NULL; | |
674 int vmindex = methodOopDesc::nonvirtual_vtable_index; | |
675 if (defc->is_interface()) { | |
676 vmindex = klassItable::compute_itable_index(m()); | |
677 assert(vmindex >= 0, ""); | |
678 } else if (result.has_vtable_index()) { | |
679 vmindex = result.vtable_index(); | |
680 assert(vmindex >= 0, ""); | |
681 } | |
682 assert(vmindex != VM_INDEX_UNINITIALIZED, ""); | |
683 if (vmindex < 0) { | |
684 assert(result.is_statically_bound(), ""); | |
685 vmtarget = m(); | |
686 } else { | |
687 vmtarget = result.resolved_klass()->as_klassOop(); | |
688 } | |
689 int mods = (m->access_flags().as_short() & JVM_RECOGNIZED_METHOD_MODIFIERS); | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
690 java_lang_invoke_MemberName::set_vmtarget(mname(), vmtarget); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
691 java_lang_invoke_MemberName::set_vmindex(mname(), vmindex); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
692 java_lang_invoke_MemberName::set_modifiers(mname(), mods); |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
693 DEBUG_ONLY(KlassHandle junk1; int junk2); |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
694 assert(decode_MemberName(mname(), junk1, junk2) == result.resolved_method(), |
710 | 695 "properly stored for later decoding"); |
696 return; | |
697 } | |
698 case IS_CONSTRUCTOR: | |
699 { | |
700 CallInfo result; | |
701 { | |
702 EXCEPTION_MARK; | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
703 if (name == vmSymbols::object_initializer_name()) { |
710 | 704 LinkResolver::resolve_special_call(result, |
705 defc, name, type, KlassHandle(), false, THREAD); | |
706 } else { | |
707 break; // will throw after end of switch | |
708 } | |
709 if (HAS_PENDING_EXCEPTION) { | |
710 CLEAR_PENDING_EXCEPTION; | |
711 return; | |
712 } | |
713 } | |
714 assert(result.is_statically_bound(), ""); | |
715 methodHandle m = result.resolved_method(); | |
716 oop vmtarget = m(); | |
717 int vmindex = methodOopDesc::nonvirtual_vtable_index; | |
718 int mods = (m->access_flags().as_short() & JVM_RECOGNIZED_METHOD_MODIFIERS); | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
719 java_lang_invoke_MemberName::set_vmtarget(mname(), vmtarget); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
720 java_lang_invoke_MemberName::set_vmindex(mname(), vmindex); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
721 java_lang_invoke_MemberName::set_modifiers(mname(), mods); |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
722 DEBUG_ONLY(KlassHandle junk1; int junk2); |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
723 assert(decode_MemberName(mname(), junk1, junk2) == result.resolved_method(), |
710 | 724 "properly stored for later decoding"); |
725 return; | |
726 } | |
727 case IS_FIELD: | |
728 { | |
729 // This is taken from LinkResolver::resolve_field, sans access checks. | |
730 fieldDescriptor fd; // find_field initializes fd if found | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
731 KlassHandle sel_klass(THREAD, instanceKlass::cast(defc())->find_field(name, type, &fd)); |
710 | 732 // check if field exists; i.e., if a klass containing the field def has been selected |
733 if (sel_klass.is_null()) return; | |
734 oop vmtarget = sel_klass->as_klassOop(); | |
735 int vmindex = fd.offset(); | |
736 int mods = (fd.access_flags().as_short() & JVM_RECOGNIZED_FIELD_MODIFIERS); | |
737 if (vmindex == VM_INDEX_UNINITIALIZED) break; // should not happen | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
738 java_lang_invoke_MemberName::set_vmtarget(mname(), vmtarget); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
739 java_lang_invoke_MemberName::set_vmindex(mname(), vmindex); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
740 java_lang_invoke_MemberName::set_modifiers(mname(), mods); |
710 | 741 return; |
742 } | |
1508
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
743 default: |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
744 THROW_MSG(vmSymbols::java_lang_InternalError(), "unrecognized MemberName format"); |
710 | 745 } |
1508
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
746 |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
747 // Second chance. |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
748 if (polymorphic_method_type.not_null()) { |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
749 // Look on a non-null class loader. |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
750 Handle cur_class_loader; |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
751 const int nptypes = java_lang_invoke_MethodType::ptype_count(polymorphic_method_type()); |
1508
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
752 for (int i = 0; i <= nptypes; i++) { |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
753 oop type_mirror; |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
754 if (i < nptypes) type_mirror = java_lang_invoke_MethodType::ptype(polymorphic_method_type(), i); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
755 else type_mirror = java_lang_invoke_MethodType::rtype(polymorphic_method_type()); |
1508
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
756 klassOop example_type = java_lang_Class::as_klassOop(type_mirror); |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
757 if (example_type == NULL) continue; |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
758 oop class_loader = Klass::cast(example_type)->class_loader(); |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
759 if (class_loader == NULL || class_loader == cur_class_loader()) continue; |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
760 cur_class_loader = Handle(THREAD, class_loader); |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
761 methodOop m = SystemDictionary::find_method_handle_invoke(name, |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
762 type, |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
763 KlassHandle(THREAD, example_type), |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
764 THREAD); |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
765 if (HAS_PENDING_EXCEPTION) { |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
766 CLEAR_PENDING_EXCEPTION; |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
767 m = NULL; |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
768 // try again with a different class loader... |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
769 } |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
770 if (m != NULL) { |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
771 int mods = (m->access_flags().as_short() & JVM_RECOGNIZED_METHOD_MODIFIERS); |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
772 java_lang_invoke_MemberName::set_vmtarget(mname(), m); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
773 java_lang_invoke_MemberName::set_vmindex(mname(), m->vtable_index()); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
774 java_lang_invoke_MemberName::set_modifiers(mname(), mods); |
1508
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
775 return; |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
776 } |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
777 } |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
778 } |
710 | 779 } |
780 | |
781 // Conversely, a member name which is only initialized from JVM internals | |
782 // may have null defc, name, and type fields. | |
783 // Resolving it plants a vmtarget/vmindex in it, | |
784 // which refers directly to JVM internals. | |
785 void MethodHandles::expand_MemberName(Handle mname, int suppress, TRAPS) { | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
786 assert(java_lang_invoke_MemberName::is_instance(mname()), ""); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
787 oop vmtarget = java_lang_invoke_MemberName::vmtarget(mname()); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
788 int vmindex = java_lang_invoke_MemberName::vmindex(mname()); |
710 | 789 if (vmtarget == NULL || vmindex == VM_INDEX_UNINITIALIZED) { |
790 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "nothing to expand"); | |
791 } | |
792 | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
793 bool have_defc = (java_lang_invoke_MemberName::clazz(mname()) != NULL); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
794 bool have_name = (java_lang_invoke_MemberName::name(mname()) != NULL); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
795 bool have_type = (java_lang_invoke_MemberName::type(mname()) != NULL); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
796 int flags = java_lang_invoke_MemberName::flags(mname()); |
710 | 797 |
798 if (suppress != 0) { | |
799 if (suppress & _suppress_defc) have_defc = true; | |
800 if (suppress & _suppress_name) have_name = true; | |
801 if (suppress & _suppress_type) have_type = true; | |
802 } | |
803 | |
804 if (have_defc && have_name && have_type) return; // nothing needed | |
805 | |
806 switch (flags & ALL_KINDS) { | |
807 case IS_METHOD: | |
808 case IS_CONSTRUCTOR: | |
809 { | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
810 KlassHandle receiver_limit; int decode_flags = 0; |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
811 methodHandle m = decode_vmtarget(vmtarget, vmindex, NULL, receiver_limit, decode_flags); |
710 | 812 if (m.is_null()) break; |
813 if (!have_defc) { | |
814 klassOop defc = m->method_holder(); | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
815 if (receiver_limit.not_null() && receiver_limit() != defc |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
816 && Klass::cast(receiver_limit())->is_subtype_of(defc)) |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
817 defc = receiver_limit(); |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
818 java_lang_invoke_MemberName::set_clazz(mname(), Klass::cast(defc)->java_mirror()); |
710 | 819 } |
820 if (!have_name) { | |
821 //not java_lang_String::create_from_symbol; let's intern member names | |
822 Handle name = StringTable::intern(m->name(), CHECK); | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
823 java_lang_invoke_MemberName::set_name(mname(), name()); |
710 | 824 } |
825 if (!have_type) { | |
826 Handle type = java_lang_String::create_from_symbol(m->signature(), CHECK); | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
827 java_lang_invoke_MemberName::set_type(mname(), type()); |
710 | 828 } |
829 return; | |
830 } | |
831 case IS_FIELD: | |
832 { | |
833 // This is taken from LinkResolver::resolve_field, sans access checks. | |
834 if (!vmtarget->is_klass()) break; | |
835 if (!Klass::cast((klassOop) vmtarget)->oop_is_instance()) break; | |
836 instanceKlassHandle defc(THREAD, (klassOop) vmtarget); | |
837 bool is_static = ((flags & JVM_ACC_STATIC) != 0); | |
838 fieldDescriptor fd; // find_field initializes fd if found | |
839 if (!defc->find_field_from_offset(vmindex, is_static, &fd)) | |
840 break; // cannot expand | |
841 if (!have_defc) { | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
842 java_lang_invoke_MemberName::set_clazz(mname(), defc->java_mirror()); |
710 | 843 } |
844 if (!have_name) { | |
845 //not java_lang_String::create_from_symbol; let's intern member names | |
846 Handle name = StringTable::intern(fd.name(), CHECK); | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
847 java_lang_invoke_MemberName::set_name(mname(), name()); |
710 | 848 } |
849 if (!have_type) { | |
850 Handle type = java_lang_String::create_from_symbol(fd.signature(), CHECK); | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
851 java_lang_invoke_MemberName::set_type(mname(), type()); |
710 | 852 } |
853 return; | |
854 } | |
855 } | |
856 THROW_MSG(vmSymbols::java_lang_InternalError(), "unrecognized MemberName format"); | |
857 } | |
858 | |
859 int MethodHandles::find_MemberNames(klassOop k, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
860 Symbol* name, Symbol* sig, |
710 | 861 int mflags, klassOop caller, |
862 int skip, objArrayOop results) { | |
863 DEBUG_ONLY(No_Safepoint_Verifier nsv); | |
864 // this code contains no safepoints! | |
865 | |
866 // %%% take caller into account! | |
867 | |
868 if (k == NULL || !Klass::cast(k)->oop_is_instance()) return -1; | |
869 | |
870 int rfill = 0, rlimit = results->length(), rskip = skip; | |
871 // overflow measurement: | |
872 int overflow = 0, overflow_limit = MAX2(1000, rlimit); | |
873 | |
874 int match_flags = mflags; | |
875 bool search_superc = ((match_flags & SEARCH_SUPERCLASSES) != 0); | |
876 bool search_intfc = ((match_flags & SEARCH_INTERFACES) != 0); | |
877 bool local_only = !(search_superc | search_intfc); | |
878 bool classes_only = false; | |
879 | |
880 if (name != NULL) { | |
881 if (name->utf8_length() == 0) return 0; // a match is not possible | |
882 } | |
883 if (sig != NULL) { | |
884 if (sig->utf8_length() == 0) return 0; // a match is not possible | |
885 if (sig->byte_at(0) == '(') | |
886 match_flags &= ~(IS_FIELD | IS_TYPE); | |
887 else | |
888 match_flags &= ~(IS_CONSTRUCTOR | IS_METHOD); | |
889 } | |
890 | |
891 if ((match_flags & IS_TYPE) != 0) { | |
892 // NYI, and Core Reflection works quite well for this query | |
893 } | |
894 | |
895 if ((match_flags & IS_FIELD) != 0) { | |
896 for (FieldStream st(k, local_only, !search_intfc); !st.eos(); st.next()) { | |
897 if (name != NULL && st.name() != name) | |
898 continue; | |
899 if (sig != NULL && st.signature() != sig) | |
900 continue; | |
901 // passed the filters | |
902 if (rskip > 0) { | |
903 --rskip; | |
904 } else if (rfill < rlimit) { | |
905 oop result = results->obj_at(rfill++); | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
906 if (!java_lang_invoke_MemberName::is_instance(result)) |
710 | 907 return -99; // caller bug! |
908 MethodHandles::init_MemberName(result, st.klass()->as_klassOop(), st.access_flags(), st.offset()); | |
909 } else if (++overflow >= overflow_limit) { | |
910 match_flags = 0; break; // got tired of looking at overflow | |
911 } | |
912 } | |
913 } | |
914 | |
915 if ((match_flags & (IS_METHOD | IS_CONSTRUCTOR)) != 0) { | |
916 // watch out for these guys: | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
917 Symbol* init_name = vmSymbols::object_initializer_name(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
918 Symbol* clinit_name = vmSymbols::class_initializer_name(); |
710 | 919 if (name == clinit_name) clinit_name = NULL; // hack for exposing <clinit> |
920 bool negate_name_test = false; | |
921 // fix name so that it captures the intention of IS_CONSTRUCTOR | |
922 if (!(match_flags & IS_METHOD)) { | |
923 // constructors only | |
924 if (name == NULL) { | |
925 name = init_name; | |
926 } else if (name != init_name) { | |
927 return 0; // no constructors of this method name | |
928 } | |
929 } else if (!(match_flags & IS_CONSTRUCTOR)) { | |
930 // methods only | |
931 if (name == NULL) { | |
932 name = init_name; | |
933 negate_name_test = true; // if we see the name, we *omit* the entry | |
934 } else if (name == init_name) { | |
935 return 0; // no methods of this constructor name | |
936 } | |
937 } else { | |
938 // caller will accept either sort; no need to adjust name | |
939 } | |
940 for (MethodStream st(k, local_only, !search_intfc); !st.eos(); st.next()) { | |
941 methodOop m = st.method(); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
942 Symbol* m_name = m->name(); |
710 | 943 if (m_name == clinit_name) |
944 continue; | |
945 if (name != NULL && ((m_name != name) ^ negate_name_test)) | |
946 continue; | |
947 if (sig != NULL && m->signature() != sig) | |
948 continue; | |
949 // passed the filters | |
950 if (rskip > 0) { | |
951 --rskip; | |
952 } else if (rfill < rlimit) { | |
953 oop result = results->obj_at(rfill++); | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
954 if (!java_lang_invoke_MemberName::is_instance(result)) |
710 | 955 return -99; // caller bug! |
956 MethodHandles::init_MemberName(result, m, true); | |
957 } else if (++overflow >= overflow_limit) { | |
958 match_flags = 0; break; // got tired of looking at overflow | |
959 } | |
960 } | |
961 } | |
962 | |
963 // return number of elements we at leasted wanted to initialize | |
964 return rfill + overflow; | |
965 } | |
966 | |
967 | |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
968 // Decode this java.lang.Class object into an instanceKlass, if possible. |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
969 // Throw IAE if not |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
970 instanceKlassHandle MethodHandles::resolve_instance_klass(oop java_mirror_oop, TRAPS) { |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
971 instanceKlassHandle empty; |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
972 klassOop caller = NULL; |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
973 if (java_lang_Class::is_instance(java_mirror_oop)) { |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
974 caller = java_lang_Class::as_klassOop(java_mirror_oop); |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
975 } |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
976 if (caller == NULL || !Klass::cast(caller)->oop_is_instance()) { |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
977 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), "not a class", empty); |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
978 } |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
979 return instanceKlassHandle(THREAD, caller); |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
980 } |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
981 |
710 | 982 |
983 | |
984 // Decode the vmtarget field of a method handle. | |
985 // Sanitize out methodOops, klassOops, and any other non-Java data. | |
986 // This is for debugging and reflection. | |
987 oop MethodHandles::encode_target(Handle mh, int format, TRAPS) { | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
988 assert(java_lang_invoke_MethodHandle::is_instance(mh()), "must be a MH"); |
710 | 989 if (format == ETF_HANDLE_OR_METHOD_NAME) { |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
990 oop target = java_lang_invoke_MethodHandle::vmtarget(mh()); |
710 | 991 if (target == NULL) { |
992 return NULL; // unformed MH | |
993 } | |
994 klassOop tklass = target->klass(); | |
1142 | 995 if (Klass::cast(tklass)->is_subclass_of(SystemDictionary::Object_klass())) { |
710 | 996 return target; // target is another MH (or something else?) |
997 } | |
998 } | |
999 if (format == ETF_DIRECT_HANDLE) { | |
1000 oop target = mh(); | |
1001 for (;;) { | |
1002 if (target->klass() == SystemDictionary::DirectMethodHandle_klass()) { | |
1003 return target; | |
1004 } | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1005 if (!java_lang_invoke_MethodHandle::is_instance(target)){ |
710 | 1006 return NULL; // unformed MH |
1007 } | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1008 target = java_lang_invoke_MethodHandle::vmtarget(target); |
710 | 1009 } |
1010 } | |
1011 // cases of metadata in MH.vmtarget: | |
1012 // - AMH can have methodOop for static invoke with bound receiver | |
1013 // - DMH can have methodOop for static invoke (on variable receiver) | |
1014 // - DMH can have klassOop for dispatched (non-static) invoke | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1015 KlassHandle receiver_limit; int decode_flags = 0; |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1016 methodHandle m = decode_MethodHandle(mh(), receiver_limit, decode_flags); |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1017 if (m.is_null()) return NULL; |
710 | 1018 switch (format) { |
1019 case ETF_REFLECT_METHOD: | |
1020 // same as jni_ToReflectedMethod: | |
1021 if (m->is_initializer()) { | |
1022 return Reflection::new_constructor(m, THREAD); | |
1023 } else { | |
1024 return Reflection::new_method(m, UseNewReflection, false, THREAD); | |
1025 } | |
1026 | |
1027 case ETF_HANDLE_OR_METHOD_NAME: // method, not handle | |
1028 case ETF_METHOD_NAME: | |
1029 { | |
1030 if (SystemDictionary::MemberName_klass() == NULL) break; | |
1031 instanceKlassHandle mname_klass(THREAD, SystemDictionary::MemberName_klass()); | |
1032 mname_klass->initialize(CHECK_NULL); | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1033 Handle mname = mname_klass->allocate_instance_handle(CHECK_NULL); // possible safepoint |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1034 java_lang_invoke_MemberName::set_vmindex(mname(), VM_INDEX_UNINITIALIZED); |
710 | 1035 bool do_dispatch = ((decode_flags & MethodHandles::_dmf_does_dispatch) != 0); |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1036 init_MemberName(mname(), m(), do_dispatch); |
710 | 1037 expand_MemberName(mname, 0, CHECK_NULL); |
1038 return mname(); | |
1039 } | |
1040 } | |
1041 | |
1042 // Unknown format code. | |
1043 char msg[50]; | |
1044 jio_snprintf(msg, sizeof(msg), "unknown getTarget format=%d", format); | |
1045 THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), msg); | |
1046 } | |
1047 | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1048 static const char* always_null_names[] = { |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1049 "java/lang/Void", |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1050 "java/lang/Null", |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1051 //"java/lang/Nothing", |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1052 "sun/dyn/empty/Empty", |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1053 "sun/invoke/empty/Empty", |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1054 NULL |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1055 }; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1056 |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1057 static bool is_always_null_type(klassOop klass) { |
2478
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1058 if (klass == NULL) return false; // safety |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1059 if (!Klass::cast(klass)->oop_is_instance()) return false; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1060 instanceKlass* ik = instanceKlass::cast(klass); |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1061 // Must be on the boot class path: |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1062 if (ik->class_loader() != NULL) return false; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1063 // Check the name. |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
1064 Symbol* name = ik->name(); |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1065 for (int i = 0; ; i++) { |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1066 const char* test_name = always_null_names[i]; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1067 if (test_name == NULL) break; |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
1068 if (name->equals(test_name)) |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1069 return true; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1070 } |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1071 return false; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1072 } |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1073 |
710 | 1074 bool MethodHandles::class_cast_needed(klassOop src, klassOop dst) { |
2478
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1075 if (dst == NULL) return true; |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1076 if (src == NULL) return (dst != SystemDictionary::Object_klass()); |
1142 | 1077 if (src == dst || dst == SystemDictionary::Object_klass()) |
710 | 1078 return false; // quickest checks |
1079 Klass* srck = Klass::cast(src); | |
1080 Klass* dstk = Klass::cast(dst); | |
1081 if (dstk->is_interface()) { | |
1082 // interface receivers can safely be viewed as untyped, | |
1083 // because interface calls always include a dynamic check | |
1142 | 1084 //dstk = Klass::cast(SystemDictionary::Object_klass()); |
710 | 1085 return false; |
1086 } | |
1087 if (srck->is_interface()) { | |
1088 // interface arguments must be viewed as untyped | |
1142 | 1089 //srck = Klass::cast(SystemDictionary::Object_klass()); |
710 | 1090 return true; |
1091 } | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1092 if (is_always_null_type(src)) { |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1093 // some source types are known to be never instantiated; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1094 // they represent references which are always null |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1095 // such null references never fail to convert safely |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1096 return false; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1097 } |
710 | 1098 return !srck->is_subclass_of(dstk->as_klassOop()); |
1099 } | |
1100 | |
1101 static oop object_java_mirror() { | |
1142 | 1102 return Klass::cast(SystemDictionary::Object_klass())->java_mirror(); |
710 | 1103 } |
1104 | |
3371
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
1105 bool MethodHandles::is_float_fixed_reinterpretation_cast(BasicType src, BasicType dst) { |
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
1106 if (src == T_FLOAT) return dst == T_INT; |
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
1107 if (src == T_INT) return dst == T_FLOAT; |
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
1108 if (src == T_DOUBLE) return dst == T_LONG; |
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
1109 if (src == T_LONG) return dst == T_DOUBLE; |
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
1110 return false; |
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
1111 } |
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
1112 |
710 | 1113 bool MethodHandles::same_basic_type_for_arguments(BasicType src, |
1114 BasicType dst, | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1115 bool raw, |
710 | 1116 bool for_return) { |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1117 if (for_return) { |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1118 // return values can always be forgotten: |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1119 if (dst == T_VOID) return true; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1120 if (src == T_VOID) return raw && (dst == T_INT); |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1121 // We allow caller to receive a garbage int, which is harmless. |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1122 // This trick is pulled by trusted code (see VerifyType.canPassRaw). |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1123 } |
710 | 1124 assert(src != T_VOID && dst != T_VOID, "should not be here"); |
1125 if (src == dst) return true; | |
1126 if (type2size[src] != type2size[dst]) return false; | |
1912
8213b0f5c92d
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
1849
diff
changeset
|
1127 if (src == T_OBJECT || dst == T_OBJECT) return false; |
8213b0f5c92d
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
1849
diff
changeset
|
1128 if (raw) return true; // bitwise reinterpretation; caller guarantees safety |
710 | 1129 // allow reinterpretation casts for integral widening |
1130 if (is_subword_type(src)) { // subwords can fit in int or other subwords | |
1131 if (dst == T_INT) // any subword fits in an int | |
1132 return true; | |
1133 if (src == T_BOOLEAN) // boolean fits in any subword | |
1134 return is_subword_type(dst); | |
1135 if (src == T_BYTE && dst == T_SHORT) | |
1136 return true; // remaining case: byte fits in short | |
1137 } | |
1138 // allow float/fixed reinterpretation casts | |
3371
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
1139 if (is_float_fixed_reinterpretation_cast(src, dst)) |
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
1140 return true; |
710 | 1141 return false; |
1142 } | |
1143 | |
1144 const char* MethodHandles::check_method_receiver(methodOop m, | |
1145 klassOop passed_recv_type) { | |
1146 assert(!m->is_static(), "caller resp."); | |
1147 if (passed_recv_type == NULL) | |
1148 return "receiver type is primitive"; | |
1149 if (class_cast_needed(passed_recv_type, m->method_holder())) { | |
1150 Klass* formal = Klass::cast(m->method_holder()); | |
1151 return SharedRuntime::generate_class_cast_message("receiver type", | |
1152 formal->external_name()); | |
1153 } | |
1154 return NULL; // checks passed | |
1155 } | |
1156 | |
1157 // Verify that m's signature can be called type-safely by a method handle | |
1158 // of the given method type 'mtype'. | |
1159 // It takes a TRAPS argument because it must perform symbol lookups. | |
1160 void MethodHandles::verify_method_signature(methodHandle m, | |
1161 Handle mtype, | |
1162 int first_ptype_pos, | |
1163 KlassHandle insert_ptype, | |
1164 TRAPS) { | |
2478
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1165 Handle mhi_type; |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1166 if (m->is_method_handle_invoke()) { |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1167 // use this more exact typing instead of the symbolic signature: |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1168 mhi_type = Handle(THREAD, m->method_handle_type()); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1169 } |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1170 objArrayHandle ptypes(THREAD, java_lang_invoke_MethodType::ptypes(mtype())); |
710 | 1171 int pnum = first_ptype_pos; |
1172 int pmax = ptypes->length(); | |
2478
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1173 int anum = 0; // method argument |
710 | 1174 const char* err = NULL; |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
1175 ResourceMark rm(THREAD); |
710 | 1176 for (SignatureStream ss(m->signature()); !ss.is_done(); ss.next()) { |
1177 oop ptype_oop = NULL; | |
1178 if (ss.at_return_type()) { | |
1179 if (pnum != pmax) | |
1180 { err = "too many arguments"; break; } | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1181 ptype_oop = java_lang_invoke_MethodType::rtype(mtype()); |
710 | 1182 } else { |
1183 if (pnum >= pmax) | |
1184 { err = "not enough arguments"; break; } | |
1185 if (pnum >= 0) | |
1186 ptype_oop = ptypes->obj_at(pnum); | |
1187 else if (insert_ptype.is_null()) | |
1188 ptype_oop = NULL; | |
1189 else | |
1190 ptype_oop = insert_ptype->java_mirror(); | |
1191 pnum += 1; | |
2478
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1192 anum += 1; |
710 | 1193 } |
2478
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1194 KlassHandle pklass; |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1195 BasicType ptype = T_OBJECT; |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1196 bool have_ptype = false; |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1197 // missing ptype_oop does not match any non-reference; use Object to report the error |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1198 pklass = SystemDictionaryHandles::Object_klass(); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1199 if (ptype_oop != NULL) { |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1200 have_ptype = true; |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1201 klassOop pklass_oop = NULL; |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1202 ptype = java_lang_Class::as_BasicType(ptype_oop, &pklass_oop); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1203 pklass = KlassHandle(THREAD, pklass_oop); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1204 } |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1205 ptype_oop = NULL; //done with this |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1206 KlassHandle aklass; |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1207 BasicType atype = ss.type(); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1208 if (atype == T_ARRAY) atype = T_OBJECT; // fold all refs to T_OBJECT |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1209 if (atype == T_OBJECT) { |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1210 if (!have_ptype) { |
710 | 1211 // null matches any reference |
1212 continue; | |
1213 } | |
2478
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1214 if (mhi_type.is_null()) { |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1215 // If we fail to resolve types at this point, we will usually throw an error. |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1216 TempNewSymbol name = ss.as_symbol_or_null(); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1217 if (name != NULL) { |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1218 instanceKlass* mk = instanceKlass::cast(m->method_holder()); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1219 Handle loader(THREAD, mk->class_loader()); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1220 Handle domain(THREAD, mk->protection_domain()); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1221 klassOop aklass_oop = SystemDictionary::resolve_or_null(name, loader, domain, CHECK); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1222 if (aklass_oop != NULL) |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1223 aklass = KlassHandle(THREAD, aklass_oop); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1224 } |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1225 } else { |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1226 // for method handle invokers we don't look at the name in the signature |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1227 oop atype_oop; |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1228 if (ss.at_return_type()) |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1229 atype_oop = java_lang_invoke_MethodType::rtype(mhi_type()); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1230 else |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1231 atype_oop = java_lang_invoke_MethodType::ptype(mhi_type(), anum-1); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1232 klassOop aklass_oop = NULL; |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1233 atype = java_lang_Class::as_BasicType(atype_oop, &aklass_oop); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1234 aklass = KlassHandle(THREAD, aklass_oop); |
1508
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
1235 } |
710 | 1236 } |
1237 if (!ss.at_return_type()) { | |
2478
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1238 err = check_argument_type_change(ptype, pklass(), atype, aklass(), anum); |
710 | 1239 } else { |
2478
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1240 err = check_return_type_change(atype, aklass(), ptype, pklass()); // note reversal! |
710 | 1241 } |
1242 if (err != NULL) break; | |
1243 } | |
1244 | |
1245 if (err != NULL) { | |
2478
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1246 #ifndef PRODUCT |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1247 if (PrintMiscellaneous && (Verbose || WizardMode)) { |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1248 tty->print("*** verify_method_signature failed: "); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1249 java_lang_invoke_MethodType::print_signature(mtype(), tty); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1250 tty->cr(); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1251 tty->print_cr(" first_ptype_pos = %d, insert_ptype = "UINTX_FORMAT, first_ptype_pos, insert_ptype()); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1252 tty->print(" Failing method: "); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1253 m->print(); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1254 } |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1255 #endif //PRODUCT |
710 | 1256 THROW_MSG(vmSymbols::java_lang_InternalError(), err); |
1257 } | |
1258 } | |
1259 | |
1260 // Main routine for verifying the MethodHandle.type of a proposed | |
1261 // direct or bound-direct method handle. | |
1262 void MethodHandles::verify_method_type(methodHandle m, | |
1263 Handle mtype, | |
1264 bool has_bound_recv, | |
1265 KlassHandle bound_recv_type, | |
1266 TRAPS) { | |
1267 bool m_needs_receiver = !m->is_static(); | |
1268 | |
1269 const char* err = NULL; | |
1270 | |
1271 int first_ptype_pos = m_needs_receiver ? 1 : 0; | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1272 if (has_bound_recv) { |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1273 first_ptype_pos -= 1; // ptypes do not include the bound argument; start earlier in them |
710 | 1274 if (m_needs_receiver && bound_recv_type.is_null()) |
1275 { err = "bound receiver is not an object"; goto die; } | |
1276 } | |
1277 | |
1278 if (m_needs_receiver && err == NULL) { | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1279 objArrayOop ptypes = java_lang_invoke_MethodType::ptypes(mtype()); |
710 | 1280 if (ptypes->length() < first_ptype_pos) |
1281 { err = "receiver argument is missing"; goto die; } | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1282 if (has_bound_recv) |
710 | 1283 err = check_method_receiver(m(), bound_recv_type->as_klassOop()); |
1284 else | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1285 err = check_method_receiver(m(), java_lang_Class::as_klassOop(ptypes->obj_at(first_ptype_pos-1))); |
710 | 1286 if (err != NULL) goto die; |
1287 } | |
1288 | |
1289 // Check the other arguments for mistypes. | |
1290 verify_method_signature(m, mtype, first_ptype_pos, bound_recv_type, CHECK); | |
1291 return; | |
1292 | |
1293 die: | |
1294 THROW_MSG(vmSymbols::java_lang_InternalError(), err); | |
1295 } | |
1296 | |
1297 void MethodHandles::verify_vmslots(Handle mh, TRAPS) { | |
1298 // Verify vmslots. | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1299 int check_slots = argument_slot_count(java_lang_invoke_MethodHandle::type(mh())); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1300 if (java_lang_invoke_MethodHandle::vmslots(mh()) != check_slots) { |
710 | 1301 THROW_MSG(vmSymbols::java_lang_InternalError(), "bad vmslots in BMH"); |
1302 } | |
1303 } | |
1304 | |
1305 void MethodHandles::verify_vmargslot(Handle mh, int argnum, int argslot, TRAPS) { | |
1306 // Verify that argslot points at the given argnum. | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1307 int check_slot = argument_slot(java_lang_invoke_MethodHandle::type(mh()), argnum); |
710 | 1308 if (argslot != check_slot || argslot < 0) { |
3412
88559690c95a
7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents:
3389
diff
changeset
|
1309 ResourceMark rm; |
710 | 1310 const char* fmt = "for argnum of %d, vmargslot is %d, should be %d"; |
1311 size_t msglen = strlen(fmt) + 3*11 + 1; | |
1312 char* msg = NEW_RESOURCE_ARRAY(char, msglen); | |
1313 jio_snprintf(msg, msglen, fmt, argnum, argslot, check_slot); | |
1314 THROW_MSG(vmSymbols::java_lang_InternalError(), msg); | |
1315 } | |
1316 } | |
1317 | |
1318 // Verify the correspondence between two method types. | |
1319 // Apart from the advertised changes, caller method type X must | |
1320 // be able to invoke the callee method Y type with no violations | |
1321 // of type integrity. | |
1322 // Return NULL if all is well, else a short error message. | |
1323 const char* MethodHandles::check_method_type_change(oop src_mtype, int src_beg, int src_end, | |
1324 int insert_argnum, oop insert_type, | |
1325 int change_argnum, oop change_type, | |
1326 int delete_argnum, | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1327 oop dst_mtype, int dst_beg, int dst_end, |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1328 bool raw) { |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1329 objArrayOop src_ptypes = java_lang_invoke_MethodType::ptypes(src_mtype); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1330 objArrayOop dst_ptypes = java_lang_invoke_MethodType::ptypes(dst_mtype); |
710 | 1331 |
1332 int src_max = src_ptypes->length(); | |
1333 int dst_max = dst_ptypes->length(); | |
1334 | |
1335 if (src_end == -1) src_end = src_max; | |
1336 if (dst_end == -1) dst_end = dst_max; | |
1337 | |
1338 assert(0 <= src_beg && src_beg <= src_end && src_end <= src_max, "oob"); | |
1339 assert(0 <= dst_beg && dst_beg <= dst_end && dst_end <= dst_max, "oob"); | |
1340 | |
1341 // pending actions; set to -1 when done: | |
1342 int ins_idx = insert_argnum, chg_idx = change_argnum, del_idx = delete_argnum; | |
1343 | |
1344 const char* err = NULL; | |
1345 | |
1346 // Walk along each array of parameter types, including a virtual | |
1347 // NULL end marker at the end of each. | |
1348 for (int src_idx = src_beg, dst_idx = dst_beg; | |
1349 (src_idx <= src_end && dst_idx <= dst_end); | |
1350 src_idx++, dst_idx++) { | |
1351 oop src_type = (src_idx == src_end) ? oop(NULL) : src_ptypes->obj_at(src_idx); | |
1352 oop dst_type = (dst_idx == dst_end) ? oop(NULL) : dst_ptypes->obj_at(dst_idx); | |
1353 bool fix_null_src_type = false; | |
1354 | |
1355 // Perform requested edits. | |
1356 if (ins_idx == src_idx) { | |
1357 // note that the inserted guy is never affected by a change or deletion | |
1358 ins_idx = -1; | |
1359 src_type = insert_type; | |
1360 fix_null_src_type = true; | |
1361 --src_idx; // back up to process src type on next loop | |
1362 src_idx = src_end; | |
1363 } else { | |
1364 // note that the changed guy can be immediately deleted | |
1365 if (chg_idx == src_idx) { | |
1366 chg_idx = -1; | |
1367 assert(src_idx < src_end, "oob"); | |
1368 src_type = change_type; | |
1369 fix_null_src_type = true; | |
1370 } | |
1371 if (del_idx == src_idx) { | |
1372 del_idx = -1; | |
1373 assert(src_idx < src_end, "oob"); | |
1374 --dst_idx; | |
1375 continue; // rerun loop after skipping this position | |
1376 } | |
1377 } | |
1378 | |
1379 if (src_type == NULL && fix_null_src_type) | |
1380 // explicit null in this case matches any dest reference | |
1381 src_type = (java_lang_Class::is_primitive(dst_type) ? object_java_mirror() : dst_type); | |
1382 | |
1383 // Compare the two argument types. | |
1384 if (src_type != dst_type) { | |
1385 if (src_type == NULL) return "not enough arguments"; | |
1386 if (dst_type == NULL) return "too many arguments"; | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1387 err = check_argument_type_change(src_type, dst_type, dst_idx, raw); |
710 | 1388 if (err != NULL) return err; |
1389 } | |
1390 } | |
1391 | |
1392 // Now compare return types also. | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1393 oop src_rtype = java_lang_invoke_MethodType::rtype(src_mtype); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1394 oop dst_rtype = java_lang_invoke_MethodType::rtype(dst_mtype); |
710 | 1395 if (src_rtype != dst_rtype) { |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1396 err = check_return_type_change(dst_rtype, src_rtype, raw); // note reversal! |
710 | 1397 if (err != NULL) return err; |
1398 } | |
1399 | |
1400 assert(err == NULL, ""); | |
1401 return NULL; // all is well | |
1402 } | |
1403 | |
1404 | |
1405 const char* MethodHandles::check_argument_type_change(BasicType src_type, | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1406 klassOop src_klass, |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1407 BasicType dst_type, |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1408 klassOop dst_klass, |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1409 int argnum, |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1410 bool raw) { |
710 | 1411 const char* err = NULL; |
3371
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
1412 const bool for_return = (argnum < 0); |
710 | 1413 |
1414 // just in case: | |
1415 if (src_type == T_ARRAY) src_type = T_OBJECT; | |
1416 if (dst_type == T_ARRAY) dst_type = T_OBJECT; | |
1417 | |
1418 // Produce some nice messages if VerifyMethodHandles is turned on: | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1419 if (!same_basic_type_for_arguments(src_type, dst_type, raw, for_return)) { |
710 | 1420 if (src_type == T_OBJECT) { |
3371
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
1421 if (raw && is_java_primitive(dst_type)) |
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
1422 return NULL; // ref-to-prim discards ref and returns zero |
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
1423 err = (!for_return |
710 | 1424 ? "type mismatch: passing a %s for method argument #%d, which expects primitive %s" |
1425 : "type mismatch: returning a %s, but caller expects primitive %s"); | |
1426 } else if (dst_type == T_OBJECT) { | |
3371
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
1427 err = (!for_return |
710 | 1428 ? "type mismatch: passing a primitive %s for method argument #%d, which expects %s" |
1429 : "type mismatch: returning a primitive %s, but caller expects %s"); | |
1430 } else { | |
3371
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
1431 err = (!for_return |
710 | 1432 ? "type mismatch: passing a %s for method argument #%d, which expects %s" |
1433 : "type mismatch: returning a %s, but caller expects %s"); | |
1434 } | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1435 } else if (src_type == T_OBJECT && dst_type == T_OBJECT && |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1436 class_cast_needed(src_klass, dst_klass)) { |
710 | 1437 if (!class_cast_needed(dst_klass, src_klass)) { |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1438 if (raw) |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1439 return NULL; // reverse cast is OK; the MH target is trusted to enforce it |
3371
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
1440 err = (!for_return |
710 | 1441 ? "cast required: passing a %s for method argument #%d, which expects %s" |
1442 : "cast required: returning a %s, but caller expects %s"); | |
1443 } else { | |
3371
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
1444 err = (!for_return |
710 | 1445 ? "reference mismatch: passing a %s for method argument #%d, which expects %s" |
1446 : "reference mismatch: returning a %s, but caller expects %s"); | |
1447 } | |
1448 } else { | |
1449 // passed the obstacle course | |
1450 return NULL; | |
1451 } | |
1452 | |
1453 // format, format, format | |
1454 const char* src_name = type2name(src_type); | |
1455 const char* dst_name = type2name(dst_type); | |
1456 if (src_name == NULL) src_name = "unknown type"; | |
1457 if (dst_name == NULL) dst_name = "unknown type"; | |
2478
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1458 if (src_type == T_OBJECT) |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1459 src_name = (src_klass != NULL) ? Klass::cast(src_klass)->external_name() : "an unresolved class"; |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1460 if (dst_type == T_OBJECT) |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1461 dst_name = (dst_klass != NULL) ? Klass::cast(dst_klass)->external_name() : "an unresolved class"; |
710 | 1462 |
1463 size_t msglen = strlen(err) + strlen(src_name) + strlen(dst_name) + (argnum < 10 ? 1 : 11); | |
1464 char* msg = NEW_RESOURCE_ARRAY(char, msglen + 1); | |
3371
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
1465 if (!for_return) { |
710 | 1466 assert(strstr(err, "%d") != NULL, ""); |
1467 jio_snprintf(msg, msglen, err, src_name, argnum, dst_name); | |
1468 } else { | |
1469 assert(strstr(err, "%d") == NULL, ""); | |
1470 jio_snprintf(msg, msglen, err, src_name, dst_name); | |
1471 } | |
1472 return msg; | |
1473 } | |
1474 | |
1475 // Compute the depth within the stack of the given argument, i.e., | |
1476 // the combined size of arguments to the right of the given argument. | |
1477 // For the last argument (ptypes.length-1) this will be zero. | |
1478 // For the first argument (0) this will be the size of all | |
1479 // arguments but that one. For the special number -1, this | |
1480 // will be the size of all arguments, including the first. | |
1481 // If the argument is neither -1 nor a valid argument index, | |
1482 // then return a negative number. Otherwise, the result | |
1483 // is in the range [0..vmslots] inclusive. | |
1484 int MethodHandles::argument_slot(oop method_type, int arg) { | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1485 objArrayOop ptypes = java_lang_invoke_MethodType::ptypes(method_type); |
710 | 1486 int argslot = 0; |
1487 int len = ptypes->length(); | |
1488 if (arg < -1 || arg >= len) return -99; | |
1489 for (int i = len-1; i > arg; i--) { | |
1490 BasicType bt = java_lang_Class::as_BasicType(ptypes->obj_at(i)); | |
1491 argslot += type2size[bt]; | |
1492 } | |
1493 assert(argument_slot_to_argnum(method_type, argslot) == arg, "inverse works"); | |
1494 return argslot; | |
1495 } | |
1496 | |
1497 // Given a slot number, return the argument number. | |
1498 int MethodHandles::argument_slot_to_argnum(oop method_type, int query_argslot) { | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1499 objArrayOop ptypes = java_lang_invoke_MethodType::ptypes(method_type); |
710 | 1500 int argslot = 0; |
1501 int len = ptypes->length(); | |
1502 for (int i = len-1; i >= 0; i--) { | |
1503 if (query_argslot == argslot) return i; | |
1504 BasicType bt = java_lang_Class::as_BasicType(ptypes->obj_at(i)); | |
1505 argslot += type2size[bt]; | |
1506 } | |
1507 // return pseudo-arg deepest in stack: | |
1508 if (query_argslot == argslot) return -1; | |
1509 return -99; // oob slot, or splitting a double-slot arg | |
1510 } | |
1511 | |
1512 methodHandle MethodHandles::dispatch_decoded_method(methodHandle m, | |
1513 KlassHandle receiver_limit, | |
1514 int decode_flags, | |
1515 KlassHandle receiver_klass, | |
1516 TRAPS) { | |
1517 assert((decode_flags & ~_DMF_DIRECT_MASK) == 0, "must be direct method reference"); | |
1518 assert((decode_flags & _dmf_has_receiver) != 0, "must have a receiver or first reference argument"); | |
1519 | |
1520 if (!m->is_static() && | |
1521 (receiver_klass.is_null() || !receiver_klass->is_subtype_of(m->method_holder()))) | |
1522 // given type does not match class of method, or receiver is null! | |
1523 // caller should have checked this, but let's be extra careful... | |
1524 return methodHandle(); | |
1525 | |
1526 if (receiver_limit.not_null() && | |
1527 (receiver_klass.not_null() && !receiver_klass->is_subtype_of(receiver_limit()))) | |
1528 // given type is not limited to the receiver type | |
1529 // note that a null receiver can match any reference value, for a static method | |
1530 return methodHandle(); | |
1531 | |
1532 if (!(decode_flags & MethodHandles::_dmf_does_dispatch)) { | |
1533 // pre-dispatched or static method (null receiver is OK for static) | |
1534 return m; | |
1535 | |
1536 } else if (receiver_klass.is_null()) { | |
1537 // null receiver value; cannot dispatch | |
1538 return methodHandle(); | |
1539 | |
1540 } else if (!(decode_flags & MethodHandles::_dmf_from_interface)) { | |
1541 // perform virtual dispatch | |
1542 int vtable_index = m->vtable_index(); | |
1543 guarantee(vtable_index >= 0, "valid vtable index"); | |
1544 | |
1545 // receiver_klass might be an arrayKlassOop but all vtables start at | |
1546 // the same place. The cast is to avoid virtual call and assertion. | |
1547 // See also LinkResolver::runtime_resolve_virtual_method. | |
1548 instanceKlass* inst = (instanceKlass*)Klass::cast(receiver_klass()); | |
1549 DEBUG_ONLY(inst->verify_vtable_index(vtable_index)); | |
1550 methodOop m_oop = inst->method_at_vtable(vtable_index); | |
1551 return methodHandle(THREAD, m_oop); | |
1552 | |
1553 } else { | |
1554 // perform interface dispatch | |
1555 int itable_index = klassItable::compute_itable_index(m()); | |
1556 guarantee(itable_index >= 0, "valid itable index"); | |
1557 instanceKlass* inst = instanceKlass::cast(receiver_klass()); | |
1558 methodOop m_oop = inst->method_at_itable(m->method_holder(), itable_index, THREAD); | |
1559 return methodHandle(THREAD, m_oop); | |
1560 } | |
1561 } | |
1562 | |
1563 void MethodHandles::verify_DirectMethodHandle(Handle mh, methodHandle m, TRAPS) { | |
1564 // Verify type. | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1565 Handle mtype(THREAD, java_lang_invoke_MethodHandle::type(mh())); |
710 | 1566 verify_method_type(m, mtype, false, KlassHandle(), CHECK); |
1567 | |
1568 // Verify vmslots. | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1569 if (java_lang_invoke_MethodHandle::vmslots(mh()) != m->size_of_parameters()) { |
710 | 1570 THROW_MSG(vmSymbols::java_lang_InternalError(), "bad vmslots in DMH"); |
1571 } | |
1572 } | |
1573 | |
1574 void MethodHandles::init_DirectMethodHandle(Handle mh, methodHandle m, bool do_dispatch, TRAPS) { | |
1575 // Check arguments. | |
1576 if (mh.is_null() || m.is_null() || | |
1577 (!do_dispatch && m->is_abstract())) { | |
1578 THROW(vmSymbols::java_lang_InternalError()); | |
1579 } | |
1580 | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1581 java_lang_invoke_MethodHandle::init_vmslots(mh()); |
710 | 1582 |
1583 if (VerifyMethodHandles) { | |
1584 // The privileged code which invokes this routine should not make | |
1585 // a mistake about types, but it's better to verify. | |
1586 verify_DirectMethodHandle(mh, m, CHECK); | |
1587 } | |
1588 | |
1589 // Finally, after safety checks are done, link to the target method. | |
1590 // We will follow the same path as the latter part of | |
1591 // InterpreterRuntime::resolve_invoke(), which first finds the method | |
1592 // and then decides how to populate the constant pool cache entry | |
1593 // that links the interpreter calls to the method. We need the same | |
1594 // bits, and will use the same calling sequence code. | |
1595 | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1596 int vmindex = methodOopDesc::garbage_vtable_index; |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1597 Handle vmtarget; |
710 | 1598 |
1599 instanceKlass::cast(m->method_holder())->link_class(CHECK); | |
1600 | |
1601 MethodHandleEntry* me = NULL; | |
1602 if (do_dispatch && Klass::cast(m->method_holder())->is_interface()) { | |
1603 // We are simulating an invokeinterface instruction. | |
1604 // (We might also be simulating an invokevirtual on a miranda method, | |
1605 // but it is safe to treat it as an invokeinterface.) | |
1606 assert(!m->can_be_statically_bound(), "no final methods on interfaces"); | |
1607 vmindex = klassItable::compute_itable_index(m()); | |
1608 assert(vmindex >= 0, "(>=0) == do_dispatch"); | |
1609 // Set up same bits as ConstantPoolCacheEntry::set_interface_call(). | |
1610 vmtarget = m->method_holder(); // the interface | |
1611 me = MethodHandles::entry(MethodHandles::_invokeinterface_mh); | |
1612 } else if (!do_dispatch || m->can_be_statically_bound()) { | |
1613 // We are simulating an invokestatic or invokespecial instruction. | |
1614 // Set up the method pointer, just like ConstantPoolCacheEntry::set_method(). | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1615 vmtarget = m; |
710 | 1616 // this does not help dispatch, but it will make it possible to parse this MH: |
1617 vmindex = methodOopDesc::nonvirtual_vtable_index; | |
1618 assert(vmindex < 0, "(>=0) == do_dispatch"); | |
1619 if (!m->is_static()) { | |
1620 me = MethodHandles::entry(MethodHandles::_invokespecial_mh); | |
1621 } else { | |
1622 me = MethodHandles::entry(MethodHandles::_invokestatic_mh); | |
1623 // Part of the semantics of a static call is an initialization barrier. | |
1624 // For a DMH, it is done now, when the handle is created. | |
1625 Klass* k = Klass::cast(m->method_holder()); | |
1626 if (k->should_be_initialized()) { | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1627 k->initialize(CHECK); // possible safepoint |
710 | 1628 } |
1629 } | |
1630 } else { | |
1631 // We are simulating an invokevirtual instruction. | |
1632 // Set up the vtable index, just like ConstantPoolCacheEntry::set_method(). | |
1633 // The key logic is LinkResolver::runtime_resolve_virtual_method. | |
1634 vmindex = m->vtable_index(); | |
1635 vmtarget = m->method_holder(); | |
1636 me = MethodHandles::entry(MethodHandles::_invokevirtual_mh); | |
1637 } | |
1638 | |
1639 if (me == NULL) { THROW(vmSymbols::java_lang_InternalError()); } | |
1640 | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1641 java_lang_invoke_DirectMethodHandle::set_vmtarget(mh(), vmtarget()); |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1642 java_lang_invoke_DirectMethodHandle::set_vmindex( mh(), vmindex); |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1643 DEBUG_ONLY(KlassHandle rlimit; int flags); |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1644 assert(MethodHandles::decode_method(mh(), rlimit, flags) == m, |
710 | 1645 "properly stored for later decoding"); |
1646 DEBUG_ONLY(bool actual_do_dispatch = ((flags & _dmf_does_dispatch) != 0)); | |
1647 assert(!(actual_do_dispatch && !do_dispatch), | |
1648 "do not perform dispatch if !do_dispatch specified"); | |
1649 assert(actual_do_dispatch == (vmindex >= 0), "proper later decoding of do_dispatch"); | |
1650 assert(decode_MethodHandle_stack_pushes(mh()) == 0, "DMH does not move stack"); | |
1651 | |
1652 // Done! | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1653 java_lang_invoke_MethodHandle::set_vmentry(mh(), me); |
710 | 1654 } |
1655 | |
1656 void MethodHandles::verify_BoundMethodHandle_with_receiver(Handle mh, | |
1657 methodHandle m, | |
1658 TRAPS) { | |
1659 // Verify type. | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1660 KlassHandle bound_recv_type; |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1661 { |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1662 oop receiver = java_lang_invoke_BoundMethodHandle::argument(mh()); |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1663 if (receiver != NULL) |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1664 bound_recv_type = KlassHandle(THREAD, receiver->klass()); |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1665 } |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1666 Handle mtype(THREAD, java_lang_invoke_MethodHandle::type(mh())); |
710 | 1667 verify_method_type(m, mtype, true, bound_recv_type, CHECK); |
1668 | |
1669 int receiver_pos = m->size_of_parameters() - 1; | |
1670 | |
1671 // Verify MH.vmargslot, which should point at the bound receiver. | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1672 verify_vmargslot(mh, -1, java_lang_invoke_BoundMethodHandle::vmargslot(mh()), CHECK); |
710 | 1673 //verify_vmslots(mh, CHECK); |
1674 | |
1675 // Verify vmslots. | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1676 if (java_lang_invoke_MethodHandle::vmslots(mh()) != receiver_pos) { |
710 | 1677 THROW_MSG(vmSymbols::java_lang_InternalError(), "bad vmslots in BMH (receiver)"); |
1678 } | |
1679 } | |
1680 | |
1681 // Initialize a BMH with a receiver bound directly to a methodOop. | |
1682 void MethodHandles::init_BoundMethodHandle_with_receiver(Handle mh, | |
1683 methodHandle original_m, | |
1684 KlassHandle receiver_limit, | |
1685 int decode_flags, | |
1686 TRAPS) { | |
1687 // Check arguments. | |
1688 if (mh.is_null() || original_m.is_null()) { | |
1689 THROW(vmSymbols::java_lang_InternalError()); | |
1690 } | |
1691 | |
1692 KlassHandle receiver_klass; | |
1693 { | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1694 oop receiver_oop = java_lang_invoke_BoundMethodHandle::argument(mh()); |
710 | 1695 if (receiver_oop != NULL) |
1696 receiver_klass = KlassHandle(THREAD, receiver_oop->klass()); | |
1697 } | |
1698 methodHandle m = dispatch_decoded_method(original_m, | |
1699 receiver_limit, decode_flags, | |
1700 receiver_klass, | |
1701 CHECK); | |
1702 if (m.is_null()) { THROW(vmSymbols::java_lang_InternalError()); } | |
1703 if (m->is_abstract()) { THROW(vmSymbols::java_lang_AbstractMethodError()); } | |
1704 | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1705 java_lang_invoke_MethodHandle::init_vmslots(mh()); |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
1706 int vmargslot = m->size_of_parameters() - 1; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
1707 assert(java_lang_invoke_BoundMethodHandle::vmargslot(mh()) == vmargslot, ""); |
710 | 1708 |
1709 if (VerifyMethodHandles) { | |
1710 verify_BoundMethodHandle_with_receiver(mh, m, CHECK); | |
1711 } | |
1712 | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1713 java_lang_invoke_BoundMethodHandle::set_vmtarget(mh(), m()); |
710 | 1714 |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1715 DEBUG_ONLY(KlassHandle junk1; int junk2); |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1716 assert(MethodHandles::decode_method(mh(), junk1, junk2) == m, "properly stored for later decoding"); |
710 | 1717 assert(decode_MethodHandle_stack_pushes(mh()) == 1, "BMH pushes one stack slot"); |
1718 | |
1719 // Done! | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1720 java_lang_invoke_MethodHandle::set_vmentry(mh(), MethodHandles::entry(MethodHandles::_bound_ref_direct_mh)); |
710 | 1721 } |
1722 | |
1723 void MethodHandles::verify_BoundMethodHandle(Handle mh, Handle target, int argnum, | |
1724 bool direct_to_method, TRAPS) { | |
3442
f7d55ea6ee56
7045514: SPARC assembly code for JSR 292 ricochet frames
never
parents:
3417
diff
changeset
|
1725 ResourceMark rm; |
710 | 1726 Handle ptype_handle(THREAD, |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1727 java_lang_invoke_MethodType::ptype(java_lang_invoke_MethodHandle::type(target()), argnum)); |
710 | 1728 KlassHandle ptype_klass; |
1729 BasicType ptype = java_lang_Class::as_BasicType(ptype_handle(), &ptype_klass); | |
1730 int slots_pushed = type2size[ptype]; | |
1731 | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1732 oop argument = java_lang_invoke_BoundMethodHandle::argument(mh()); |
710 | 1733 |
1734 const char* err = NULL; | |
1735 | |
1736 switch (ptype) { | |
1737 case T_OBJECT: | |
1738 if (argument != NULL) | |
1739 // we must implicitly convert from the arg type to the outgoing ptype | |
1740 err = check_argument_type_change(T_OBJECT, argument->klass(), ptype, ptype_klass(), argnum); | |
1741 break; | |
1742 | |
1743 case T_ARRAY: case T_VOID: | |
1744 assert(false, "array, void do not appear here"); | |
1745 default: | |
1746 if (ptype != T_INT && !is_subword_type(ptype)) { | |
1747 err = "unexpected parameter type"; | |
1748 break; | |
1749 } | |
1750 // check subrange of Integer.value, if necessary | |
1142 | 1751 if (argument == NULL || argument->klass() != SystemDictionary::Integer_klass()) { |
710 | 1752 err = "bound integer argument must be of type java.lang.Integer"; |
1753 break; | |
1754 } | |
1755 if (ptype != T_INT) { | |
1756 int value_offset = java_lang_boxing_object::value_offset_in_bytes(T_INT); | |
1757 jint value = argument->int_field(value_offset); | |
1849
5beba6174298
6987555: JSR 292 unboxing to a boolean value fails on big-endian SPARC
twisti
parents:
1748
diff
changeset
|
1758 int vminfo = adapter_unbox_subword_vminfo(ptype); |
710 | 1759 jint subword = truncate_subword_from_vminfo(value, vminfo); |
1760 if (value != subword) { | |
1761 err = "bound subword value does not fit into the subword type"; | |
1762 break; | |
1763 } | |
1764 } | |
1765 break; | |
1766 case T_FLOAT: | |
1767 case T_DOUBLE: | |
1768 case T_LONG: | |
1769 { | |
1770 // we must implicitly convert from the unboxed arg type to the outgoing ptype | |
1771 BasicType argbox = java_lang_boxing_object::basic_type(argument); | |
1772 if (argbox != ptype) { | |
1773 err = check_argument_type_change(T_OBJECT, (argument == NULL | |
1142 | 1774 ? SystemDictionary::Object_klass() |
710 | 1775 : argument->klass()), |
1776 ptype, ptype_klass(), argnum); | |
1777 assert(err != NULL, "this must be an error"); | |
1778 } | |
1779 break; | |
1780 } | |
1781 } | |
1782 | |
1783 if (err == NULL) { | |
1784 DEBUG_ONLY(int this_pushes = decode_MethodHandle_stack_pushes(mh())); | |
1785 if (direct_to_method) { | |
1786 assert(this_pushes == slots_pushed, "BMH pushes one or two stack slots"); | |
1787 } else { | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1788 int target_pushes = decode_MethodHandle_stack_pushes(target()); |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1789 assert(this_pushes == slots_pushed + target_pushes, "BMH stack motion must be correct"); |
710 | 1790 } |
1791 } | |
1792 | |
1793 if (err == NULL) { | |
1794 // Verify the rest of the method type. | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1795 err = check_method_type_insertion(java_lang_invoke_MethodHandle::type(mh()), |
710 | 1796 argnum, ptype_handle(), |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1797 java_lang_invoke_MethodHandle::type(target())); |
710 | 1798 } |
1799 | |
1800 if (err != NULL) { | |
1801 THROW_MSG(vmSymbols::java_lang_InternalError(), err); | |
1802 } | |
1803 } | |
1804 | |
1805 void MethodHandles::init_BoundMethodHandle(Handle mh, Handle target, int argnum, TRAPS) { | |
1806 // Check arguments. | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1807 if (mh.is_null() || target.is_null() || !java_lang_invoke_MethodHandle::is_instance(target())) { |
710 | 1808 THROW(vmSymbols::java_lang_InternalError()); |
1809 } | |
1810 | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1811 java_lang_invoke_MethodHandle::init_vmslots(mh()); |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
1812 int argslot = java_lang_invoke_BoundMethodHandle::vmargslot(mh()); |
710 | 1813 |
1814 if (VerifyMethodHandles) { | |
1815 int insert_after = argnum - 1; | |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
1816 verify_vmargslot(mh, insert_after, argslot, CHECK); |
710 | 1817 verify_vmslots(mh, CHECK); |
1818 } | |
1819 | |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
1820 // Get bound type and required slots. |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1821 BasicType ptype; |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1822 { |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1823 oop ptype_oop = java_lang_invoke_MethodType::ptype(java_lang_invoke_MethodHandle::type(target()), argnum); |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1824 ptype = java_lang_Class::as_BasicType(ptype_oop); |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1825 } |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
1826 int slots_pushed = type2size[ptype]; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
1827 |
710 | 1828 // If (a) the target is a direct non-dispatched method handle, |
1829 // or (b) the target is a dispatched direct method handle and we | |
1830 // are binding the receiver, cut out the middle-man. | |
1831 // Do this by decoding the DMH and using its methodOop directly as vmtarget. | |
1832 bool direct_to_method = false; | |
1833 if (OptimizeMethodHandles && | |
1834 target->klass() == SystemDictionary::DirectMethodHandle_klass() && | |
3412
88559690c95a
7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents:
3389
diff
changeset
|
1835 (argnum != 0 || java_lang_invoke_BoundMethodHandle::argument(mh()) != NULL) && |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1836 (argnum == 0 || java_lang_invoke_DirectMethodHandle::vmindex(target()) < 0)) { |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1837 KlassHandle receiver_limit; int decode_flags = 0; |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1838 methodHandle m = decode_method(target(), receiver_limit, decode_flags); |
710 | 1839 if (m.is_null()) { THROW_MSG(vmSymbols::java_lang_InternalError(), "DMH failed to decode"); } |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
1840 DEBUG_ONLY(int m_vmslots = m->size_of_parameters() - slots_pushed); // pos. of 1st arg. |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1841 assert(java_lang_invoke_BoundMethodHandle::vmslots(mh()) == m_vmslots, "type w/ m sig"); |
710 | 1842 if (argnum == 0 && (decode_flags & _dmf_has_receiver) != 0) { |
1843 init_BoundMethodHandle_with_receiver(mh, m, | |
1844 receiver_limit, decode_flags, | |
1845 CHECK); | |
1846 return; | |
1847 } | |
1848 | |
1849 // Even if it is not a bound receiver, we still might be able | |
1850 // to bind another argument and still invoke the methodOop directly. | |
1851 if (!(decode_flags & _dmf_does_dispatch)) { | |
1852 direct_to_method = true; | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1853 java_lang_invoke_BoundMethodHandle::set_vmtarget(mh(), m()); |
710 | 1854 } |
1855 } | |
1856 if (!direct_to_method) | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1857 java_lang_invoke_BoundMethodHandle::set_vmtarget(mh(), target()); |
710 | 1858 |
1859 if (VerifyMethodHandles) { | |
1860 verify_BoundMethodHandle(mh, target, argnum, direct_to_method, CHECK); | |
1861 } | |
1862 | |
1863 // Next question: Is this a ref, int, or long bound value? | |
1864 MethodHandleEntry* me = NULL; | |
1865 if (ptype == T_OBJECT) { | |
1866 if (direct_to_method) me = MethodHandles::entry(_bound_ref_direct_mh); | |
1867 else me = MethodHandles::entry(_bound_ref_mh); | |
1868 } else if (slots_pushed == 2) { | |
1869 if (direct_to_method) me = MethodHandles::entry(_bound_long_direct_mh); | |
1870 else me = MethodHandles::entry(_bound_long_mh); | |
1871 } else if (slots_pushed == 1) { | |
1872 if (direct_to_method) me = MethodHandles::entry(_bound_int_direct_mh); | |
1873 else me = MethodHandles::entry(_bound_int_mh); | |
1874 } else { | |
1875 assert(false, ""); | |
1876 } | |
1877 | |
1878 // Done! | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1879 java_lang_invoke_MethodHandle::set_vmentry(mh(), me); |
710 | 1880 } |
1881 | |
1882 static void throw_InternalError_for_bad_conversion(int conversion, const char* err, TRAPS) { | |
1883 char msg[200]; | |
1884 jio_snprintf(msg, sizeof(msg), "bad adapter (conversion=0x%08x): %s", conversion, err); | |
1885 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), msg); | |
1886 } | |
1887 | |
1888 void MethodHandles::verify_AdapterMethodHandle(Handle mh, int argnum, TRAPS) { | |
3442
f7d55ea6ee56
7045514: SPARC assembly code for JSR 292 ricochet frames
never
parents:
3417
diff
changeset
|
1889 ResourceMark rm; |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1890 jint conversion = java_lang_invoke_AdapterMethodHandle::conversion(mh()); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1891 int argslot = java_lang_invoke_AdapterMethodHandle::vmargslot(mh()); |
710 | 1892 |
1893 verify_vmargslot(mh, argnum, argslot, CHECK); | |
1894 verify_vmslots(mh, CHECK); | |
1895 | |
1896 jint conv_op = adapter_conversion_op(conversion); | |
1897 if (!conv_op_valid(conv_op)) { | |
1898 throw_InternalError_for_bad_conversion(conversion, "unknown conversion op", THREAD); | |
1899 return; | |
1900 } | |
1901 EntryKind ek = adapter_entry_kind(conv_op); | |
1902 | |
1903 int stack_move = adapter_conversion_stack_move(conversion); | |
1904 BasicType src = adapter_conversion_src_type(conversion); | |
1905 BasicType dest = adapter_conversion_dest_type(conversion); | |
1906 int vminfo = adapter_conversion_vminfo(conversion); // should be zero | |
1907 | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1908 Handle argument(THREAD, java_lang_invoke_AdapterMethodHandle::argument(mh())); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1909 Handle target(THREAD, java_lang_invoke_AdapterMethodHandle::vmtarget(mh())); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1910 Handle src_mtype(THREAD, java_lang_invoke_MethodHandle::type(mh())); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1911 Handle dst_mtype(THREAD, java_lang_invoke_MethodHandle::type(target())); |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
1912 Handle arg_mtype; |
710 | 1913 |
1914 const char* err = NULL; | |
1915 | |
1916 if (err == NULL) { | |
1917 // Check that the correct argument is supplied, but only if it is required. | |
1918 switch (ek) { | |
1919 case _adapter_check_cast: // target type of cast | |
1920 case _adapter_ref_to_prim: // wrapper type from which to unbox | |
1921 case _adapter_spread_args: // array type to spread from | |
1922 if (!java_lang_Class::is_instance(argument()) | |
1923 || java_lang_Class::is_primitive(argument())) | |
1924 { err = "adapter requires argument of type java.lang.Class"; break; } | |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
1925 if (ek == _adapter_spread_args) { |
710 | 1926 // Make sure it is a suitable collection type. (Array, for now.) |
1927 Klass* ak = Klass::cast(java_lang_Class::as_klassOop(argument())); | |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
1928 if (!ak->oop_is_array()) |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
1929 { err = "spread adapter requires argument representing an array class"; break; } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
1930 BasicType et = arrayKlass::cast(ak->as_klassOop())->element_type(); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
1931 if (et != dest && stack_move <= 0) |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
1932 { err = "spread adapter requires array class argument of correct type"; break; } |
710 | 1933 } |
1934 break; | |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
1935 case _adapter_prim_to_ref: // boxer MH to use |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
1936 case _adapter_collect_args: // method handle which collects the args |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
1937 case _adapter_fold_args: // method handle which collects the args |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
1938 if (!UseRicochetFrames) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
1939 { err = "box/collect/fold operators are not supported"; break; } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
1940 } |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1941 if (!java_lang_invoke_MethodHandle::is_instance(argument())) |
710 | 1942 { err = "MethodHandle adapter argument required"; break; } |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
1943 arg_mtype = Handle(THREAD, java_lang_invoke_MethodHandle::type(argument())); |
710 | 1944 break; |
1945 default: | |
1946 if (argument.not_null()) | |
1947 { err = "adapter has spurious argument"; break; } | |
1948 break; | |
1949 } | |
1950 } | |
1951 | |
1952 if (err == NULL) { | |
1953 // Check that the src/dest types are supplied if needed. | |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
1954 // Also check relevant parameter or return types. |
710 | 1955 switch (ek) { |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1956 case _adapter_check_cast: |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1957 if (src != T_OBJECT || dest != T_OBJECT) { |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1958 err = "adapter requires object src/dest conversion subfields"; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1959 } |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1960 break; |
710 | 1961 case _adapter_prim_to_prim: |
1962 if (!is_java_primitive(src) || !is_java_primitive(dest) || src == dest) { | |
1963 err = "adapter requires primitive src/dest conversion subfields"; break; | |
1964 } | |
1965 if ( (src == T_FLOAT || src == T_DOUBLE) && !(dest == T_FLOAT || dest == T_DOUBLE) || | |
1966 !(src == T_FLOAT || src == T_DOUBLE) && (dest == T_FLOAT || dest == T_DOUBLE)) { | |
1967 err = "adapter cannot convert beween floating and fixed-point"; break; | |
1968 } | |
1969 break; | |
1970 case _adapter_ref_to_prim: | |
1971 if (src != T_OBJECT || !is_java_primitive(dest) | |
1972 || argument() != Klass::cast(SystemDictionary::box_klass(dest))->java_mirror()) { | |
1973 err = "adapter requires primitive dest conversion subfield"; break; | |
1974 } | |
1975 break; | |
1976 case _adapter_prim_to_ref: | |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
1977 if (!is_java_primitive(src) || dest != T_OBJECT) { |
710 | 1978 err = "adapter requires primitive src conversion subfield"; break; |
1979 } | |
1980 break; | |
1981 case _adapter_swap_args: | |
1982 { | |
3449
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
1983 if (!src || !dest) { |
710 | 1984 err = "adapter requires src/dest conversion subfields for swap"; break; |
1985 } | |
3449
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
1986 int src_size = type2size[src]; |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
1987 if (src_size != type2size[dest]) { |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
1988 err = "adapter requires equal sizes for src/dest"; break; |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
1989 } |
710 | 1990 int src_slot = argslot; |
1991 int dest_slot = vminfo; | |
1992 int src_arg = argnum; | |
3449
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
1993 int dest_arg = argument_slot_to_argnum(src_mtype(), dest_slot); |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
1994 verify_vmargslot(mh, dest_arg, dest_slot, CHECK); |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
1995 if (!(dest_slot >= src_slot + src_size) && |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
1996 !(src_slot >= dest_slot + src_size)) { |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
1997 err = "source, destination slots must be distinct"; break; |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
1998 } else if (!(src_slot > dest_slot)) { |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
1999 err = "source of swap must be deeper in stack"; break; |
710 | 2000 } |
3449
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2001 err = check_argument_type_change(java_lang_invoke_MethodType::ptype(src_mtype(), dest_arg), |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2002 java_lang_invoke_MethodType::ptype(dst_mtype(), src_arg), |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2003 dest_arg); |
710 | 2004 if (err == NULL) |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2005 err = check_argument_type_change(java_lang_invoke_MethodType::ptype(src_mtype(), src_arg), |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2006 java_lang_invoke_MethodType::ptype(dst_mtype(), dest_arg), |
710 | 2007 src_arg); |
3449
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2008 break; |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2009 } |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2010 case _adapter_rot_args: |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2011 { |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2012 if (!src || !dest) { |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2013 err = "adapter requires src/dest conversion subfields for rotate"; break; |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2014 } |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2015 int src_slot = argslot; |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2016 int limit_raw = vminfo; |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2017 bool rot_down = (src_slot < limit_raw); |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2018 int limit_bias = (rot_down ? MethodHandles::OP_ROT_ARGS_DOWN_LIMIT_BIAS : 0); |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2019 int limit_slot = limit_raw - limit_bias; |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2020 int src_arg = argnum; |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2021 int limit_arg = argument_slot_to_argnum(src_mtype(), limit_slot); |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2022 verify_vmargslot(mh, limit_arg, limit_slot, CHECK); |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2023 if (src_slot == limit_slot) { |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2024 err = "source, destination slots must be distinct"; break; |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2025 } |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2026 if (!rot_down) { // rotate slots up == shift arguments left |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2027 // limit_slot is an inclusive lower limit |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2028 assert((src_slot > limit_slot) && (src_arg < limit_arg), ""); |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2029 // rotate up: [limit_slot..src_slot-ss] --> [limit_slot+ss..src_slot] |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2030 // that is: [src_arg+1..limit_arg] --> [src_arg..limit_arg-1] |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2031 for (int i = src_arg+1; i <= limit_arg && err == NULL; i++) { |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2032 err = check_argument_type_change(java_lang_invoke_MethodType::ptype(src_mtype(), i), |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2033 java_lang_invoke_MethodType::ptype(dst_mtype(), i-1), |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2034 i); |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2035 } |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2036 } else { // rotate slots down == shfit arguments right |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2037 // limit_slot is an exclusive upper limit |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2038 assert((src_slot < limit_slot - limit_bias) && (src_arg > limit_arg + limit_bias), ""); |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2039 // rotate down: [src_slot+ss..limit_slot) --> [src_slot..limit_slot-ss) |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2040 // that is: (limit_arg..src_arg-1] --> (dst_arg+1..src_arg] |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2041 for (int i = limit_arg+1; i <= src_arg-1 && err == NULL; i++) { |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2042 err = check_argument_type_change(java_lang_invoke_MethodType::ptype(src_mtype(), i), |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2043 java_lang_invoke_MethodType::ptype(dst_mtype(), i+1), |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2044 i); |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2045 } |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2046 } |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2047 if (err == NULL) { |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2048 int dest_arg = (rot_down ? limit_arg+1 : limit_arg); |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2049 err = check_argument_type_change(java_lang_invoke_MethodType::ptype(src_mtype(), src_arg), |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2050 java_lang_invoke_MethodType::ptype(dst_mtype(), dest_arg), |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2051 src_arg); |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2052 } |
710 | 2053 } |
2054 break; | |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2055 case _adapter_spread_args: |
710 | 2056 case _adapter_collect_args: |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2057 case _adapter_fold_args: |
710 | 2058 { |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2059 bool is_spread = (ek == _adapter_spread_args); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2060 bool is_fold = (ek == _adapter_fold_args); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2061 BasicType coll_type = is_spread ? src : dest; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2062 BasicType elem_type = is_spread ? dest : src; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2063 // coll_type is type of args in collected form (or T_VOID if none) |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2064 // elem_type is common type of args in spread form (or T_VOID if missing or heterogeneous) |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2065 if (coll_type == 0 || elem_type == 0) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2066 err = "adapter requires src/dest subfields for spread or collect"; break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2067 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2068 if (is_spread && coll_type != T_OBJECT) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2069 err = "spread adapter requires object type for argument bundle"; break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2070 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2071 Handle spread_mtype = (is_spread ? dst_mtype : src_mtype); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2072 int spread_slot = argslot; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2073 int spread_arg = argnum; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2074 int slots_pushed = stack_move / stack_move_unit(); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2075 int coll_slot_count = type2size[coll_type]; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2076 int spread_slot_count = (is_spread ? slots_pushed : -slots_pushed) + coll_slot_count; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2077 if (is_fold) spread_slot_count = argument_slot_count(arg_mtype()); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2078 if (!is_spread) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2079 int init_slots = argument_slot_count(src_mtype()); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2080 int coll_slots = argument_slot_count(arg_mtype()); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2081 if (spread_slot_count > init_slots || |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2082 spread_slot_count != coll_slots) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2083 err = "collect adapter has inconsistent arg counts"; break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2084 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2085 int next_slots = argument_slot_count(dst_mtype()); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2086 int unchanged_slots_in = (init_slots - spread_slot_count); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2087 int unchanged_slots_out = (next_slots - coll_slot_count - (is_fold ? spread_slot_count : 0)); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2088 if (unchanged_slots_in != unchanged_slots_out) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2089 err = "collect adapter continuation has inconsistent arg counts"; break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2090 } |
710 | 2091 } |
2092 } | |
2093 break; | |
2094 default: | |
2095 if (src != 0 || dest != 0) { | |
2096 err = "adapter has spurious src/dest conversion subfields"; break; | |
2097 } | |
2098 break; | |
2099 } | |
2100 } | |
2101 | |
2102 if (err == NULL) { | |
2103 // Check the stack_move subfield. | |
2104 // It must always report the net change in stack size, positive or negative. | |
2105 int slots_pushed = stack_move / stack_move_unit(); | |
2106 switch (ek) { | |
2107 case _adapter_prim_to_prim: | |
2108 case _adapter_ref_to_prim: | |
2109 case _adapter_prim_to_ref: | |
2110 if (slots_pushed != type2size[dest] - type2size[src]) { | |
2111 err = "wrong stack motion for primitive conversion"; | |
2112 } | |
2113 break; | |
2114 case _adapter_dup_args: | |
2115 if (slots_pushed <= 0) { | |
2116 err = "adapter requires conversion subfield slots_pushed > 0"; | |
2117 } | |
2118 break; | |
2119 case _adapter_drop_args: | |
2120 if (slots_pushed >= 0) { | |
2121 err = "adapter requires conversion subfield slots_pushed < 0"; | |
2122 } | |
2123 break; | |
2124 case _adapter_collect_args: | |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2125 case _adapter_fold_args: |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2126 if (slots_pushed > 2) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2127 err = "adapter requires conversion subfield slots_pushed <= 2"; |
710 | 2128 } |
2129 break; | |
2130 case _adapter_spread_args: | |
2131 if (slots_pushed < -1) { | |
2132 err = "adapter requires conversion subfield slots_pushed >= -1"; | |
2133 } | |
2134 break; | |
2135 default: | |
2136 if (stack_move != 0) { | |
2137 err = "adapter has spurious stack_move conversion subfield"; | |
2138 } | |
2139 break; | |
2140 } | |
2141 if (err == NULL && stack_move != slots_pushed * stack_move_unit()) { | |
2142 err = "stack_move conversion subfield must be multiple of stack_move_unit"; | |
2143 } | |
2144 } | |
2145 | |
2146 if (err == NULL) { | |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2147 // Make sure this adapter's stack pushing is accurately recorded. |
710 | 2148 int slots_pushed = stack_move / stack_move_unit(); |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2149 int this_vmslots = java_lang_invoke_MethodHandle::vmslots(mh()); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2150 int target_vmslots = java_lang_invoke_MethodHandle::vmslots(target()); |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2151 int target_pushes = decode_MethodHandle_stack_pushes(target()); |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
2152 if (slots_pushed != (target_vmslots - this_vmslots)) { |
710 | 2153 err = "stack_move inconsistent with previous and current MethodType vmslots"; |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2154 } else { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2155 int this_pushes = decode_MethodHandle_stack_pushes(mh()); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2156 if (slots_pushed + target_pushes != this_pushes) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2157 if (this_pushes == 0) |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2158 err = "adapter push count not initialized"; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2159 else |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2160 err = "adapter push count is wrong"; |
710 | 2161 } |
2162 } | |
2163 | |
2164 // While we're at it, check that the stack motion decoder works: | |
2165 DEBUG_ONLY(int this_pushes = decode_MethodHandle_stack_pushes(mh())); | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
2166 assert(this_pushes == slots_pushed + target_pushes, "AMH stack motion must be correct"); |
710 | 2167 } |
2168 | |
2169 if (err == NULL && vminfo != 0) { | |
2170 switch (ek) { | |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2171 case _adapter_swap_args: |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2172 case _adapter_rot_args: |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2173 case _adapter_prim_to_ref: |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2174 case _adapter_collect_args: |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2175 case _adapter_fold_args: |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2176 break; // OK |
710 | 2177 default: |
2178 err = "vminfo subfield is reserved to the JVM"; | |
2179 } | |
2180 } | |
2181 | |
2182 // Do additional ad hoc checks. | |
2183 if (err == NULL) { | |
2184 switch (ek) { | |
2185 case _adapter_retype_only: | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
2186 err = check_method_type_passthrough(src_mtype(), dst_mtype(), false); |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
2187 break; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
2188 |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
2189 case _adapter_retype_raw: |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
2190 err = check_method_type_passthrough(src_mtype(), dst_mtype(), true); |
710 | 2191 break; |
2192 | |
2193 case _adapter_check_cast: | |
2194 { | |
2195 // The actual value being checked must be a reference: | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2196 err = check_argument_type_change(java_lang_invoke_MethodType::ptype(src_mtype(), argnum), |
710 | 2197 object_java_mirror(), argnum); |
2198 if (err != NULL) break; | |
2199 | |
2200 // The output of the cast must fit with the destination argument: | |
2201 Handle cast_class = argument; | |
2202 err = check_method_type_conversion(src_mtype(), | |
2203 argnum, cast_class(), | |
2204 dst_mtype()); | |
2205 } | |
2206 break; | |
2207 | |
2208 // %%% TO DO: continue in remaining cases to verify src/dst_mtype if VerifyMethodHandles | |
2209 } | |
2210 } | |
2211 | |
2212 if (err != NULL) { | |
2213 throw_InternalError_for_bad_conversion(conversion, err, THREAD); | |
2214 return; | |
2215 } | |
2216 | |
2217 } | |
2218 | |
2219 void MethodHandles::init_AdapterMethodHandle(Handle mh, Handle target, int argnum, TRAPS) { | |
3371
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2220 Handle argument = java_lang_invoke_AdapterMethodHandle::argument(mh()); |
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2221 int argslot = java_lang_invoke_AdapterMethodHandle::vmargslot(mh()); |
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2222 jint conversion = java_lang_invoke_AdapterMethodHandle::conversion(mh()); |
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2223 jint conv_op = adapter_conversion_op(conversion); |
710 | 2224 |
2225 // adjust the adapter code to the internal EntryKind enumeration: | |
2226 EntryKind ek_orig = adapter_entry_kind(conv_op); | |
2227 EntryKind ek_opt = ek_orig; // may be optimized | |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2228 EntryKind ek_try; // temp |
710 | 2229 |
2230 // Finalize the vmtarget field (Java initialized it to null). | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2231 if (!java_lang_invoke_MethodHandle::is_instance(target())) { |
710 | 2232 throw_InternalError_for_bad_conversion(conversion, "bad target", THREAD); |
2233 return; | |
2234 } | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2235 java_lang_invoke_AdapterMethodHandle::set_vmtarget(mh(), target()); |
710 | 2236 |
2237 int stack_move = adapter_conversion_stack_move(conversion); | |
2238 BasicType src = adapter_conversion_src_type(conversion); | |
2239 BasicType dest = adapter_conversion_dest_type(conversion); | |
2240 int vminfo = adapter_conversion_vminfo(conversion); // should be zero | |
2241 | |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2242 int slots_pushed = stack_move / stack_move_unit(); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2243 |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2244 if (VerifyMethodHandles) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2245 verify_AdapterMethodHandle(mh, argnum, CHECK); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2246 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2247 |
710 | 2248 const char* err = NULL; |
2249 | |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2250 if (!conv_op_supported(conv_op)) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2251 err = "adapter not yet implemented in the JVM"; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2252 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2253 |
710 | 2254 // Now it's time to finish the case analysis and pick a MethodHandleEntry. |
2255 switch (ek_orig) { | |
2256 case _adapter_retype_only: | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
2257 case _adapter_retype_raw: |
710 | 2258 case _adapter_check_cast: |
2259 case _adapter_dup_args: | |
2260 case _adapter_drop_args: | |
2261 // these work fine via general case code | |
2262 break; | |
2263 | |
2264 case _adapter_prim_to_prim: | |
2265 { | |
2266 // Non-subword cases are {int,float,long,double} -> {int,float,long,double}. | |
2267 // And, the {float,double} -> {int,long} cases must be handled by Java. | |
2268 switch (type2size[src] *4+ type2size[dest]) { | |
2269 case 1 *4+ 1: | |
2270 assert(src == T_INT || is_subword_type(src), "source is not float"); | |
2271 // Subword-related cases are int -> {boolean,byte,char,short}. | |
2272 ek_opt = _adapter_opt_i2i; | |
1849
5beba6174298
6987555: JSR 292 unboxing to a boolean value fails on big-endian SPARC
twisti
parents:
1748
diff
changeset
|
2273 vminfo = adapter_prim_to_prim_subword_vminfo(dest); |
710 | 2274 break; |
2275 case 2 *4+ 1: | |
2276 if (src == T_LONG && (dest == T_INT || is_subword_type(dest))) { | |
2277 ek_opt = _adapter_opt_l2i; | |
1849
5beba6174298
6987555: JSR 292 unboxing to a boolean value fails on big-endian SPARC
twisti
parents:
1748
diff
changeset
|
2278 vminfo = adapter_prim_to_prim_subword_vminfo(dest); |
710 | 2279 } else if (src == T_DOUBLE && dest == T_FLOAT) { |
2280 ek_opt = _adapter_opt_d2f; | |
2281 } else { | |
3371
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2282 goto throw_not_impl; // runs user code, hence could block |
710 | 2283 } |
2284 break; | |
2285 case 1 *4+ 2: | |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2286 if ((src == T_INT || is_subword_type(src)) && dest == T_LONG) { |
710 | 2287 ek_opt = _adapter_opt_i2l; |
2288 } else if (src == T_FLOAT && dest == T_DOUBLE) { | |
2289 ek_opt = _adapter_opt_f2d; | |
2290 } else { | |
3371
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2291 goto throw_not_impl; // runs user code, hence could block |
710 | 2292 } |
2293 break; | |
2294 default: | |
3371
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2295 goto throw_not_impl; // runs user code, hence could block |
710 | 2296 break; |
2297 } | |
2298 } | |
2299 break; | |
2300 | |
2301 case _adapter_ref_to_prim: | |
2302 { | |
2303 switch (type2size[dest]) { | |
2304 case 1: | |
2305 ek_opt = _adapter_opt_unboxi; | |
1849
5beba6174298
6987555: JSR 292 unboxing to a boolean value fails on big-endian SPARC
twisti
parents:
1748
diff
changeset
|
2306 vminfo = adapter_unbox_subword_vminfo(dest); |
710 | 2307 break; |
2308 case 2: | |
2309 ek_opt = _adapter_opt_unboxl; | |
2310 break; | |
2311 default: | |
3371
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2312 goto throw_not_impl; |
710 | 2313 break; |
2314 } | |
2315 } | |
2316 break; | |
2317 | |
2318 case _adapter_prim_to_ref: | |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2319 { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2320 assert(UseRicochetFrames, "else don't come here"); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2321 // vminfo will be the location to insert the return value |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2322 vminfo = argslot; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2323 ek_opt = _adapter_opt_collect_ref; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2324 ensure_vmlayout_field(target, CHECK); |
3371
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2325 // for MethodHandleWalk: |
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2326 if (java_lang_invoke_AdapterMethodHandle::is_instance(argument())) |
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2327 ensure_vmlayout_field(argument, CHECK); |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2328 if (!OptimizeMethodHandles) break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2329 switch (type2size[src]) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2330 case 1: |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2331 ek_try = EntryKind(_adapter_opt_filter_S0_ref + argslot); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2332 if (ek_try < _adapter_opt_collect_LAST && |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2333 ek_adapter_opt_collect_slot(ek_try) == argslot) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2334 assert(ek_adapter_opt_collect_count(ek_try) == 1 && |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2335 ek_adapter_opt_collect_type(ek_try) == T_OBJECT, ""); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2336 ek_opt = ek_try; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2337 break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2338 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2339 // else downgrade to variable slot: |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2340 ek_opt = _adapter_opt_collect_1_ref; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2341 break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2342 case 2: |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2343 ek_try = EntryKind(_adapter_opt_collect_2_S0_ref + argslot); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2344 if (ek_try < _adapter_opt_collect_LAST && |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2345 ek_adapter_opt_collect_slot(ek_try) == argslot) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2346 assert(ek_adapter_opt_collect_count(ek_try) == 2 && |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2347 ek_adapter_opt_collect_type(ek_try) == T_OBJECT, ""); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2348 ek_opt = ek_try; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2349 break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2350 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2351 // else downgrade to variable slot: |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2352 ek_opt = _adapter_opt_collect_2_ref; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2353 break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2354 default: |
3371
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2355 goto throw_not_impl; |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2356 break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2357 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2358 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2359 break; |
710 | 2360 |
2361 case _adapter_swap_args: | |
2362 case _adapter_rot_args: | |
2363 { | |
2364 int swap_slots = type2size[src]; | |
2365 int src_slot = argslot; | |
2366 int dest_slot = vminfo; | |
2367 int rotate = (ek_orig == _adapter_swap_args) ? 0 : (src_slot > dest_slot) ? 1 : -1; | |
2368 switch (swap_slots) { | |
2369 case 1: | |
2370 ek_opt = (!rotate ? _adapter_opt_swap_1 : | |
2371 rotate > 0 ? _adapter_opt_rot_1_up : _adapter_opt_rot_1_down); | |
2372 break; | |
2373 case 2: | |
2374 ek_opt = (!rotate ? _adapter_opt_swap_2 : | |
2375 rotate > 0 ? _adapter_opt_rot_2_up : _adapter_opt_rot_2_down); | |
2376 break; | |
2377 default: | |
3371
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2378 goto throw_not_impl; |
710 | 2379 break; |
2380 } | |
2381 } | |
2382 break; | |
2383 | |
2384 case _adapter_spread_args: | |
2385 { | |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2386 #ifdef TARGET_ARCH_NYI_6939861 |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2387 // ports before 6939861 supported only three kinds of spread ops |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2388 if (!UseRicochetFrames) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2389 int array_size = slots_pushed + 1; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2390 assert(array_size >= 0, ""); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2391 vminfo = array_size; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2392 switch (array_size) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2393 case 0: ek_opt = _adapter_opt_spread_0; break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2394 case 1: ek_opt = _adapter_opt_spread_1; break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2395 default: ek_opt = _adapter_opt_spread_more; break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2396 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2397 break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2398 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2399 #endif //TARGET_ARCH_NYI_6939861 |
710 | 2400 // vminfo will be the required length of the array |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2401 int array_size = (slots_pushed + 1) / (type2size[dest] == 2 ? 2 : 1); |
710 | 2402 vminfo = array_size; |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2403 // general case |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2404 switch (dest) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2405 case T_BOOLEAN : // fall through to T_BYTE: |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2406 case T_BYTE : ek_opt = _adapter_opt_spread_byte; break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2407 case T_CHAR : ek_opt = _adapter_opt_spread_char; break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2408 case T_SHORT : ek_opt = _adapter_opt_spread_short; break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2409 case T_INT : ek_opt = _adapter_opt_spread_int; break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2410 case T_LONG : ek_opt = _adapter_opt_spread_long; break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2411 case T_FLOAT : ek_opt = _adapter_opt_spread_float; break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2412 case T_DOUBLE : ek_opt = _adapter_opt_spread_double; break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2413 case T_OBJECT : ek_opt = _adapter_opt_spread_ref; break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2414 case T_VOID : if (array_size != 0) goto throw_not_impl; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2415 ek_opt = _adapter_opt_spread_ref; break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2416 default : goto throw_not_impl; |
710 | 2417 } |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2418 assert(array_size == 0 || // it doesn't matter what the spreader is |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2419 (ek_adapter_opt_spread_count(ek_opt) == -1 && |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2420 (ek_adapter_opt_spread_type(ek_opt) == dest || |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2421 (ek_adapter_opt_spread_type(ek_opt) == T_BYTE && dest == T_BOOLEAN))), |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2422 err_msg("dest=%d ek_opt=%d", dest, ek_opt)); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2423 |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2424 if (array_size <= 0) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2425 // since the general case does not handle length 0, this case is required: |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2426 ek_opt = _adapter_opt_spread_0; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2427 break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2428 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2429 if (dest == T_OBJECT) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2430 ek_try = EntryKind(_adapter_opt_spread_1_ref - 1 + array_size); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2431 if (ek_try < _adapter_opt_spread_LAST && |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2432 ek_adapter_opt_spread_count(ek_try) == array_size) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2433 assert(ek_adapter_opt_spread_type(ek_try) == dest, ""); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2434 ek_opt = ek_try; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2435 break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2436 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2437 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2438 break; |
710 | 2439 } |
2440 break; | |
2441 | |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2442 case _adapter_collect_args: |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2443 { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2444 assert(UseRicochetFrames, "else don't come here"); |
3371
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2445 int elem_slots = argument_slot_count(java_lang_invoke_MethodHandle::type(argument())); |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2446 // vminfo will be the location to insert the return value |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2447 vminfo = argslot; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2448 ensure_vmlayout_field(target, CHECK); |
3371
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2449 ensure_vmlayout_field(argument, CHECK); |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2450 |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2451 // general case: |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2452 switch (dest) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2453 default : if (!is_subword_type(dest)) goto throw_not_impl; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2454 // else fall through: |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2455 case T_INT : ek_opt = _adapter_opt_collect_int; break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2456 case T_LONG : ek_opt = _adapter_opt_collect_long; break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2457 case T_FLOAT : ek_opt = _adapter_opt_collect_float; break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2458 case T_DOUBLE : ek_opt = _adapter_opt_collect_double; break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2459 case T_OBJECT : ek_opt = _adapter_opt_collect_ref; break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2460 case T_VOID : ek_opt = _adapter_opt_collect_void; break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2461 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2462 assert(ek_adapter_opt_collect_slot(ek_opt) == -1 && |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2463 ek_adapter_opt_collect_count(ek_opt) == -1 && |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2464 (ek_adapter_opt_collect_type(ek_opt) == dest || |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2465 ek_adapter_opt_collect_type(ek_opt) == T_INT && is_subword_type(dest)), |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2466 ""); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2467 |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2468 if (dest == T_OBJECT && elem_slots == 1 && OptimizeMethodHandles) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2469 // filter operation on a ref |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2470 ek_try = EntryKind(_adapter_opt_filter_S0_ref + argslot); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2471 if (ek_try < _adapter_opt_collect_LAST && |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2472 ek_adapter_opt_collect_slot(ek_try) == argslot) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2473 assert(ek_adapter_opt_collect_count(ek_try) == elem_slots && |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2474 ek_adapter_opt_collect_type(ek_try) == dest, ""); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2475 ek_opt = ek_try; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2476 break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2477 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2478 ek_opt = _adapter_opt_collect_1_ref; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2479 break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2480 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2481 |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2482 if (dest == T_OBJECT && elem_slots == 2 && OptimizeMethodHandles) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2483 // filter of two arguments |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2484 ek_try = EntryKind(_adapter_opt_collect_2_S0_ref + argslot); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2485 if (ek_try < _adapter_opt_collect_LAST && |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2486 ek_adapter_opt_collect_slot(ek_try) == argslot) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2487 assert(ek_adapter_opt_collect_count(ek_try) == elem_slots && |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2488 ek_adapter_opt_collect_type(ek_try) == dest, ""); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2489 ek_opt = ek_try; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2490 break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2491 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2492 ek_opt = _adapter_opt_collect_2_ref; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2493 break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2494 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2495 |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2496 if (dest == T_OBJECT && OptimizeMethodHandles) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2497 // try to use a fixed length adapter |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2498 ek_try = EntryKind(_adapter_opt_collect_0_ref + elem_slots); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2499 if (ek_try < _adapter_opt_collect_LAST && |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2500 ek_adapter_opt_collect_count(ek_try) == elem_slots) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2501 assert(ek_adapter_opt_collect_slot(ek_try) == -1 && |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2502 ek_adapter_opt_collect_type(ek_try) == dest, ""); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2503 ek_opt = ek_try; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2504 break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2505 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2506 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2507 |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2508 break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2509 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2510 |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2511 case _adapter_fold_args: |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2512 { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2513 assert(UseRicochetFrames, "else don't come here"); |
3371
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2514 int elem_slots = argument_slot_count(java_lang_invoke_MethodHandle::type(argument())); |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2515 // vminfo will be the location to insert the return value |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2516 vminfo = argslot + elem_slots; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2517 ensure_vmlayout_field(target, CHECK); |
3371
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2518 ensure_vmlayout_field(argument, CHECK); |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2519 |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2520 switch (dest) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2521 default : if (!is_subword_type(dest)) goto throw_not_impl; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2522 // else fall through: |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2523 case T_INT : ek_opt = _adapter_opt_fold_int; break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2524 case T_LONG : ek_opt = _adapter_opt_fold_long; break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2525 case T_FLOAT : ek_opt = _adapter_opt_fold_float; break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2526 case T_DOUBLE : ek_opt = _adapter_opt_fold_double; break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2527 case T_OBJECT : ek_opt = _adapter_opt_fold_ref; break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2528 case T_VOID : ek_opt = _adapter_opt_fold_void; break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2529 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2530 assert(ek_adapter_opt_collect_slot(ek_opt) == -1 && |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2531 ek_adapter_opt_collect_count(ek_opt) == -1 && |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2532 (ek_adapter_opt_collect_type(ek_opt) == dest || |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2533 ek_adapter_opt_collect_type(ek_opt) == T_INT && is_subword_type(dest)), |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2534 ""); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2535 |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2536 if (dest == T_OBJECT && elem_slots == 0 && OptimizeMethodHandles) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2537 // if there are no args, just pretend it's a collect |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2538 ek_opt = _adapter_opt_collect_0_ref; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2539 break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2540 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2541 |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2542 if (dest == T_OBJECT && OptimizeMethodHandles) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2543 // try to use a fixed length adapter |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2544 ek_try = EntryKind(_adapter_opt_fold_1_ref - 1 + elem_slots); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2545 if (ek_try < _adapter_opt_fold_LAST && |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2546 ek_adapter_opt_collect_count(ek_try) == elem_slots) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2547 assert(ek_adapter_opt_collect_slot(ek_try) == -1 && |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2548 ek_adapter_opt_collect_type(ek_try) == dest, ""); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2549 ek_opt = ek_try; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2550 break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2551 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2552 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2553 |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2554 break; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2555 } |
710 | 2556 |
2557 default: | |
2558 // should have failed much earlier; must be a missing case here | |
2559 assert(false, "incomplete switch"); | |
2560 // and fall through: | |
2561 | |
2562 throw_not_impl: | |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2563 if (err == NULL) |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2564 err = "unknown adapter type"; |
710 | 2565 break; |
2566 } | |
2567 | |
3371
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2568 if (err == NULL && (vminfo & CONV_VMINFO_MASK) != vminfo) { |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2569 // should not happen, since vminfo is used to encode arg/slot indexes < 255 |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2570 err = "vminfo overflow"; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2571 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2572 |
3371
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2573 if (err == NULL && !have_entry(ek_opt)) { |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2574 err = "adapter stub for this kind of method handle is missing"; |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2575 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2576 |
3371
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2577 if (err == NULL && ek_opt == ek_orig) { |
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2578 switch (ek_opt) { |
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2579 case _adapter_prim_to_prim: |
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2580 case _adapter_ref_to_prim: |
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2581 case _adapter_prim_to_ref: |
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2582 case _adapter_swap_args: |
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2583 case _adapter_rot_args: |
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2584 case _adapter_collect_args: |
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2585 case _adapter_fold_args: |
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2586 case _adapter_spread_args: |
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2587 // should be handled completely by optimized cases; see above |
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2588 err = "init_AdapterMethodHandle should not issue this"; |
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2589 break; |
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2590 } |
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2591 } |
fabcf26ee72f
6998541: JSR 292 implement missing return-type conversion for OP_RETYPE_RAW
twisti
parents:
3363
diff
changeset
|
2592 |
710 | 2593 if (err != NULL) { |
3442
f7d55ea6ee56
7045514: SPARC assembly code for JSR 292 ricochet frames
never
parents:
3417
diff
changeset
|
2594 throw_InternalError_for_bad_conversion(conversion, err_msg("%s: conv_op %d ek_opt %d", err, conv_op, ek_opt), THREAD); |
710 | 2595 return; |
2596 } | |
2597 | |
2598 // Rebuild the conversion value; maybe parts of it were changed. | |
2599 jint new_conversion = adapter_conversion(conv_op, src, dest, stack_move, vminfo); | |
2600 | |
2601 // Finalize the conversion field. (Note that it is final to Java code.) | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2602 java_lang_invoke_AdapterMethodHandle::set_conversion(mh(), new_conversion); |
710 | 2603 |
2604 // Done! | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2605 java_lang_invoke_MethodHandle::set_vmentry(mh(), entry(ek_opt)); |
710 | 2606 |
2607 // There should be enough memory barriers on exit from native methods | |
2608 // to ensure that the MH is fully initialized to all threads before | |
2609 // Java code can publish it in global data structures. | |
2610 } | |
2611 | |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2612 void MethodHandles::ensure_vmlayout_field(Handle target, TRAPS) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2613 Handle mtype(THREAD, java_lang_invoke_MethodHandle::type(target())); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2614 Handle mtform(THREAD, java_lang_invoke_MethodType::form(mtype())); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2615 if (mtform.is_null()) { THROW(vmSymbols::java_lang_InternalError()); } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2616 if (java_lang_invoke_MethodTypeForm::vmlayout_offset_in_bytes() > 0) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2617 if (java_lang_invoke_MethodTypeForm::vmlayout(mtform()) == NULL) { |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2618 // fill it in |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2619 Handle erased_mtype(THREAD, java_lang_invoke_MethodTypeForm::erasedType(mtform())); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2620 TempNewSymbol erased_signature |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2621 = java_lang_invoke_MethodType::as_signature(erased_mtype(), /*intern:*/true, CHECK); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2622 methodOop cookie |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2623 = SystemDictionary::find_method_handle_invoke(vmSymbols::invokeExact_name(), |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2624 erased_signature, |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2625 SystemDictionaryHandles::Object_klass(), |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2626 THREAD); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2627 java_lang_invoke_MethodTypeForm::init_vmlayout(mtform(), cookie); |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2628 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2629 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2630 } |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2631 |
3388
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2632 #ifdef ASSERT |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2633 |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2634 extern "C" |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2635 void print_method_handle(oop mh); |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2636 |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2637 static void stress_method_handle_walk_impl(Handle mh, TRAPS) { |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2638 if (StressMethodHandleWalk) { |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2639 // Exercise the MethodHandleWalk code in various ways and validate |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2640 // the resulting method oop. Some of these produce output so they |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2641 // are guarded under Verbose. |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2642 ResourceMark rm; |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2643 HandleMark hm; |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2644 if (Verbose) { |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2645 print_method_handle(mh()); |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2646 } |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2647 TempNewSymbol name = SymbolTable::new_symbol("invoke", CHECK); |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2648 Handle mt = java_lang_invoke_MethodHandle::type(mh()); |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2649 TempNewSymbol signature = java_lang_invoke_MethodType::as_signature(mt(), true, CHECK); |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2650 MethodHandleCompiler mhc(mh, name, signature, 10000, false, CHECK); |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2651 methodHandle m = mhc.compile(CHECK); |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2652 if (Verbose) { |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2653 m->print_codes(); |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2654 } |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2655 InterpreterOopMap mask; |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2656 OopMapCache::compute_one_oop_map(m, m->code_size() - 1, &mask); |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2657 } |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2658 } |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2659 |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2660 static void stress_method_handle_walk(Handle mh, TRAPS) { |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2661 stress_method_handle_walk_impl(mh, THREAD); |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2662 if (HAS_PENDING_EXCEPTION) { |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2663 oop ex = PENDING_EXCEPTION; |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2664 CLEAR_PENDING_EXCEPTION; |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2665 tty->print("StressMethodHandleWalk: "); |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2666 java_lang_Throwable::print(ex, tty); |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2667 tty->cr(); |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2668 } |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2669 } |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2670 #else |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2671 |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2672 static void stress_method_handle_walk(Handle mh, TRAPS) {} |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2673 |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2674 #endif |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2675 |
710 | 2676 // |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2677 // Here are the native methods on sun.invoke.MethodHandleImpl. |
710 | 2678 // They are the private interface between this JVM and the HotSpot-specific |
2679 // Java code that implements JSR 292 method handles. | |
2680 // | |
2681 // Note: We use a JVM_ENTRY macro to define each of these, for this is the way | |
2682 // that intrinsic (non-JNI) native methods are defined in HotSpot. | |
2683 // | |
2684 | |
2685 // direct method handles for invokestatic or invokespecial | |
2686 // void init(DirectMethodHandle self, MemberName ref, boolean doDispatch, Class<?> caller); | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2687 JVM_ENTRY(void, MHN_init_DMH(JNIEnv *env, jobject igcls, jobject mh_jh, |
710 | 2688 jobject target_jh, jboolean do_dispatch, jobject caller_jh)) { |
2689 ResourceMark rm; // for error messages | |
2690 | |
2691 // This is the guy we are initializing: | |
3412
88559690c95a
7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents:
3389
diff
changeset
|
2692 if (mh_jh == NULL) { THROW_MSG(vmSymbols::java_lang_InternalError(), "self is null"); } |
710 | 2693 Handle mh(THREAD, JNIHandles::resolve_non_null(mh_jh)); |
2694 | |
2695 // Early returns out of this method leave the DMH in an unfinished state. | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2696 assert(java_lang_invoke_MethodHandle::vmentry(mh()) == NULL, "must be safely null"); |
710 | 2697 |
2698 // which method are we really talking about? | |
3412
88559690c95a
7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents:
3389
diff
changeset
|
2699 if (target_jh == NULL) { THROW_MSG(vmSymbols::java_lang_InternalError(), "target is null"); } |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
2700 Handle target(THREAD, JNIHandles::resolve_non_null(target_jh)); |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
2701 if (java_lang_invoke_MemberName::is_instance(target()) && |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
2702 java_lang_invoke_MemberName::vmindex(target()) == VM_INDEX_UNINITIALIZED) { |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
2703 MethodHandles::resolve_MemberName(target, CHECK); |
710 | 2704 } |
2705 | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
2706 KlassHandle receiver_limit; int decode_flags = 0; |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
2707 methodHandle m = MethodHandles::decode_method(target(), receiver_limit, decode_flags); |
710 | 2708 if (m.is_null()) { THROW_MSG(vmSymbols::java_lang_InternalError(), "no such method"); } |
2709 | |
2710 // The trusted Java code that calls this method should already have performed | |
2711 // access checks on behalf of the given caller. But, we can verify this. | |
2712 if (VerifyMethodHandles && caller_jh != NULL) { | |
2713 KlassHandle caller(THREAD, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(caller_jh))); | |
2714 // If this were a bytecode, the first access check would be against | |
2715 // the "reference class" mentioned in the CONSTANT_Methodref. | |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2716 // We don't know at this point which class that was, and if we |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2717 // check against m.method_holder we might get the wrong answer. |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2718 // So we just make sure to handle this check when the resolution |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2719 // happens, when we call resolve_MemberName. |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2720 // |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2721 // (A public class can inherit public members from private supers, |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2722 // and it would be wrong to check access against the private super |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2723 // if the original symbolic reference was against the public class.) |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2724 // |
710 | 2725 // If there were a bytecode, the next step would be to lookup the method |
2726 // in the reference class, then then check the method's access bits. | |
2727 // Emulate LinkResolver::check_method_accessability. | |
2728 klassOop resolved_klass = m->method_holder(); | |
2729 if (!Reflection::verify_field_access(caller->as_klassOop(), | |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2730 resolved_klass, resolved_klass, |
710 | 2731 m->access_flags(), |
2732 true)) { | |
2733 // %%% following cutout belongs in Reflection::verify_field_access? | |
2734 bool same_pm = Reflection::is_same_package_member(caller->as_klassOop(), | |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2735 resolved_klass, THREAD); |
710 | 2736 if (!same_pm) { |
2737 THROW_MSG(vmSymbols::java_lang_InternalError(), m->name_and_sig_as_C_string()); | |
2738 } | |
2739 } | |
2740 } | |
2741 | |
2742 MethodHandles::init_DirectMethodHandle(mh, m, (do_dispatch != JNI_FALSE), CHECK); | |
3388
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2743 stress_method_handle_walk(mh, CHECK); |
710 | 2744 } |
2745 JVM_END | |
2746 | |
2747 // bound method handles | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2748 JVM_ENTRY(void, MHN_init_BMH(JNIEnv *env, jobject igcls, jobject mh_jh, |
710 | 2749 jobject target_jh, int argnum)) { |
2750 ResourceMark rm; // for error messages | |
2751 | |
2752 // This is the guy we are initializing: | |
3412
88559690c95a
7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents:
3389
diff
changeset
|
2753 if (mh_jh == NULL) { THROW_MSG(vmSymbols::java_lang_InternalError(), "self is null"); } |
710 | 2754 Handle mh(THREAD, JNIHandles::resolve_non_null(mh_jh)); |
2755 | |
2756 // Early returns out of this method leave the BMH in an unfinished state. | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2757 assert(java_lang_invoke_MethodHandle::vmentry(mh()) == NULL, "must be safely null"); |
710 | 2758 |
3412
88559690c95a
7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents:
3389
diff
changeset
|
2759 if (target_jh == NULL) { THROW_MSG(vmSymbols::java_lang_InternalError(), "target is null"); } |
710 | 2760 Handle target(THREAD, JNIHandles::resolve_non_null(target_jh)); |
2761 | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2762 if (!java_lang_invoke_MethodHandle::is_instance(target())) { |
710 | 2763 // Target object is a reflective method. (%%% Do we need this alternate path?) |
2764 Untested("init_BMH of non-MH"); | |
2765 if (argnum != 0) { THROW(vmSymbols::java_lang_InternalError()); } | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
2766 KlassHandle receiver_limit; int decode_flags = 0; |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
2767 methodHandle m = MethodHandles::decode_method(target(), receiver_limit, decode_flags); |
710 | 2768 MethodHandles::init_BoundMethodHandle_with_receiver(mh, m, |
2769 receiver_limit, | |
2770 decode_flags, | |
2771 CHECK); | |
3388
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2772 } else { |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2773 // Build a BMH on top of a DMH or another BMH: |
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2774 MethodHandles::init_BoundMethodHandle(mh, target, argnum, CHECK); |
710 | 2775 } |
3388
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2776 stress_method_handle_walk(mh, CHECK); |
710 | 2777 } |
2778 JVM_END | |
2779 | |
2780 // adapter method handles | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2781 JVM_ENTRY(void, MHN_init_AMH(JNIEnv *env, jobject igcls, jobject mh_jh, |
710 | 2782 jobject target_jh, int argnum)) { |
2783 // This is the guy we are initializing: | |
3412
88559690c95a
7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents:
3389
diff
changeset
|
2784 if (mh_jh == NULL) { THROW_MSG(vmSymbols::java_lang_InternalError(), "self is null"); } |
88559690c95a
7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents:
3389
diff
changeset
|
2785 if (target_jh == NULL) { THROW_MSG(vmSymbols::java_lang_InternalError(), "target is null"); } |
710 | 2786 Handle mh(THREAD, JNIHandles::resolve_non_null(mh_jh)); |
2787 Handle target(THREAD, JNIHandles::resolve_non_null(target_jh)); | |
2788 | |
2789 // Early returns out of this method leave the AMH in an unfinished state. | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2790 assert(java_lang_invoke_MethodHandle::vmentry(mh()) == NULL, "must be safely null"); |
710 | 2791 |
2792 MethodHandles::init_AdapterMethodHandle(mh, target, argnum, CHECK); | |
3388
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3371
diff
changeset
|
2793 stress_method_handle_walk(mh, CHECK); |
710 | 2794 } |
2795 JVM_END | |
2796 | |
2797 // method type forms | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2798 JVM_ENTRY(void, MHN_init_MT(JNIEnv *env, jobject igcls, jobject erased_jh)) { |
710 | 2799 if (erased_jh == NULL) return; |
2800 if (TraceMethodHandles) { | |
2801 tty->print("creating MethodType form "); | |
2802 if (WizardMode || Verbose) { // Warning: this calls Java code on the MH! | |
2803 // call Object.toString() | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
2804 Symbol* name = vmSymbols::toString_name(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
2805 Symbol* sig = vmSymbols::void_string_signature(); |
710 | 2806 JavaCallArguments args(Handle(THREAD, JNIHandles::resolve_non_null(erased_jh))); |
2807 JavaValue result(T_OBJECT); | |
1142 | 2808 JavaCalls::call_virtual(&result, SystemDictionary::Object_klass(), name, sig, |
710 | 2809 &args, CHECK); |
2810 Handle str(THREAD, (oop)result.get_jobject()); | |
2811 java_lang_String::print(str, tty); | |
2812 } | |
2813 tty->cr(); | |
2814 } | |
2815 } | |
2816 JVM_END | |
2817 | |
2818 // debugging and reflection | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2819 JVM_ENTRY(jobject, MHN_getTarget(JNIEnv *env, jobject igcls, jobject mh_jh, jint format)) { |
710 | 2820 Handle mh(THREAD, JNIHandles::resolve(mh_jh)); |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2821 if (!java_lang_invoke_MethodHandle::is_instance(mh())) { |
710 | 2822 THROW_NULL(vmSymbols::java_lang_IllegalArgumentException()); |
2823 } | |
2824 oop target = MethodHandles::encode_target(mh, format, CHECK_NULL); | |
2825 return JNIHandles::make_local(THREAD, target); | |
2826 } | |
2827 JVM_END | |
2828 | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2829 JVM_ENTRY(jint, MHN_getConstant(JNIEnv *env, jobject igcls, jint which)) { |
710 | 2830 switch (which) { |
2831 case MethodHandles::GC_JVM_PUSH_LIMIT: | |
2832 guarantee(MethodHandlePushLimit >= 2 && MethodHandlePushLimit <= 0xFF, | |
2833 "MethodHandlePushLimit parameter must be in valid range"); | |
2834 return MethodHandlePushLimit; | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
2835 case MethodHandles::GC_JVM_STACK_MOVE_UNIT: |
710 | 2836 // return number of words per slot, signed according to stack direction |
2837 return MethodHandles::stack_move_unit(); | |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2838 case MethodHandles::GC_CONV_OP_IMPLEMENTED_MASK: |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2839 return MethodHandles::adapter_conversion_ops_supported_mask(); |
3449
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2840 case MethodHandles::GC_OP_ROT_ARGS_DOWN_LIMIT_BIAS: |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2841 return MethodHandles::OP_ROT_ARGS_DOWN_LIMIT_BIAS; |
710 | 2842 } |
2843 return 0; | |
2844 } | |
2845 JVM_END | |
2846 | |
2847 #ifndef PRODUCT | |
2848 #define EACH_NAMED_CON(template) \ | |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2849 /* hold back this one until JDK stabilizes */ \ |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2850 /* template(MethodHandles,GC_JVM_PUSH_LIMIT) */ \ |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2851 /* hold back this one until JDK stabilizes */ \ |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2852 /* template(MethodHandles,GC_JVM_STACK_MOVE_UNIT) */ \ |
3449
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2853 /* hold back this one until JDK stabilizes */ \ |
a9b8b43b115f
7052219: JSR 292: Crash in ~BufferBlob::MethodHandles adapters
never
parents:
3442
diff
changeset
|
2854 /* template(MethodHandles,GC_OP_ROT_ARGS_DOWN_LIMIT_BIAS) */ \ |
710 | 2855 template(MethodHandles,ETF_HANDLE_OR_METHOD_NAME) \ |
2856 template(MethodHandles,ETF_DIRECT_HANDLE) \ | |
2857 template(MethodHandles,ETF_METHOD_NAME) \ | |
2858 template(MethodHandles,ETF_REFLECT_METHOD) \ | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2859 template(java_lang_invoke_MemberName,MN_IS_METHOD) \ |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2860 template(java_lang_invoke_MemberName,MN_IS_CONSTRUCTOR) \ |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2861 template(java_lang_invoke_MemberName,MN_IS_FIELD) \ |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2862 template(java_lang_invoke_MemberName,MN_IS_TYPE) \ |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2863 template(java_lang_invoke_MemberName,MN_SEARCH_SUPERCLASSES) \ |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2864 template(java_lang_invoke_MemberName,MN_SEARCH_INTERFACES) \ |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2865 template(java_lang_invoke_MemberName,VM_INDEX_UNINITIALIZED) \ |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2866 template(java_lang_invoke_AdapterMethodHandle,OP_RETYPE_ONLY) \ |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2867 template(java_lang_invoke_AdapterMethodHandle,OP_RETYPE_RAW) \ |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2868 template(java_lang_invoke_AdapterMethodHandle,OP_CHECK_CAST) \ |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2869 template(java_lang_invoke_AdapterMethodHandle,OP_PRIM_TO_PRIM) \ |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2870 template(java_lang_invoke_AdapterMethodHandle,OP_REF_TO_PRIM) \ |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2871 template(java_lang_invoke_AdapterMethodHandle,OP_PRIM_TO_REF) \ |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2872 template(java_lang_invoke_AdapterMethodHandle,OP_SWAP_ARGS) \ |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2873 template(java_lang_invoke_AdapterMethodHandle,OP_ROT_ARGS) \ |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2874 template(java_lang_invoke_AdapterMethodHandle,OP_DUP_ARGS) \ |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2875 template(java_lang_invoke_AdapterMethodHandle,OP_DROP_ARGS) \ |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2876 template(java_lang_invoke_AdapterMethodHandle,OP_COLLECT_ARGS) \ |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2877 template(java_lang_invoke_AdapterMethodHandle,OP_SPREAD_ARGS) \ |
3363
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2878 /* hold back this one until JDK stabilizes */ \ |
167b70ff3abc
6939861: JVM should handle more conversion operations
never
parents:
3274
diff
changeset
|
2879 /*template(java_lang_invoke_AdapterMethodHandle,CONV_OP_LIMIT)*/ \ |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2880 template(java_lang_invoke_AdapterMethodHandle,CONV_OP_MASK) \ |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2881 template(java_lang_invoke_AdapterMethodHandle,CONV_VMINFO_MASK) \ |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2882 template(java_lang_invoke_AdapterMethodHandle,CONV_VMINFO_SHIFT) \ |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2883 template(java_lang_invoke_AdapterMethodHandle,CONV_OP_SHIFT) \ |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2884 template(java_lang_invoke_AdapterMethodHandle,CONV_DEST_TYPE_SHIFT) \ |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2885 template(java_lang_invoke_AdapterMethodHandle,CONV_SRC_TYPE_SHIFT) \ |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2886 template(java_lang_invoke_AdapterMethodHandle,CONV_STACK_MOVE_SHIFT) \ |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2887 template(java_lang_invoke_AdapterMethodHandle,CONV_STACK_MOVE_MASK) \ |
710 | 2888 /*end*/ |
2889 | |
2890 #define ONE_PLUS(scope,value) 1+ | |
2891 static const int con_value_count = EACH_NAMED_CON(ONE_PLUS) 0; | |
2892 #define VALUE_COMMA(scope,value) scope::value, | |
2893 static const int con_values[con_value_count+1] = { EACH_NAMED_CON(VALUE_COMMA) 0 }; | |
2894 #define STRING_NULL(scope,value) #value "\0" | |
2895 static const char con_names[] = { EACH_NAMED_CON(STRING_NULL) }; | |
2896 | |
2897 #undef ONE_PLUS | |
2898 #undef VALUE_COMMA | |
2899 #undef STRING_NULL | |
2900 #undef EACH_NAMED_CON | |
2901 #endif | |
2902 | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2903 JVM_ENTRY(jint, MHN_getNamedCon(JNIEnv *env, jobject igcls, jint which, jobjectArray box_jh)) { |
710 | 2904 #ifndef PRODUCT |
2905 if (which >= 0 && which < con_value_count) { | |
2906 int con = con_values[which]; | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
2907 objArrayHandle box(THREAD, (objArrayOop) JNIHandles::resolve(box_jh)); |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
2908 if (box.not_null() && box->klass() == Universe::objectArrayKlassObj() && box->length() > 0) { |
710 | 2909 const char* str = &con_names[0]; |
2910 for (int i = 0; i < which; i++) | |
2911 str += strlen(str) + 1; // skip name and null | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
2912 oop name = java_lang_String::create_oop_from_str(str, CHECK_0); // possible safepoint |
710 | 2913 box->obj_at_put(0, name); |
2914 } | |
2915 return con; | |
2916 } | |
2917 #endif | |
2918 return 0; | |
2919 } | |
2920 JVM_END | |
2921 | |
2922 // void init(MemberName self, AccessibleObject ref) | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2923 JVM_ENTRY(void, MHN_init_Mem(JNIEnv *env, jobject igcls, jobject mname_jh, jobject target_jh)) { |
3412
88559690c95a
7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents:
3389
diff
changeset
|
2924 if (mname_jh == NULL) { THROW_MSG(vmSymbols::java_lang_InternalError(), "mname is null"); } |
88559690c95a
7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents:
3389
diff
changeset
|
2925 if (target_jh == NULL) { THROW_MSG(vmSymbols::java_lang_InternalError(), "target is null"); } |
710 | 2926 Handle mname(THREAD, JNIHandles::resolve_non_null(mname_jh)); |
2927 oop target_oop = JNIHandles::resolve_non_null(target_jh); | |
2928 MethodHandles::init_MemberName(mname(), target_oop); | |
2929 } | |
2930 JVM_END | |
2931 | |
2932 // void expand(MemberName self) | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2933 JVM_ENTRY(void, MHN_expand_Mem(JNIEnv *env, jobject igcls, jobject mname_jh)) { |
3412
88559690c95a
7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents:
3389
diff
changeset
|
2934 if (mname_jh == NULL) { THROW_MSG(vmSymbols::java_lang_InternalError(), "mname is null"); } |
710 | 2935 Handle mname(THREAD, JNIHandles::resolve_non_null(mname_jh)); |
2936 MethodHandles::expand_MemberName(mname, 0, CHECK); | |
2937 } | |
2938 JVM_END | |
2939 | |
2940 // void resolve(MemberName self, Class<?> caller) | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2941 JVM_ENTRY(void, MHN_resolve_Mem(JNIEnv *env, jobject igcls, jobject mname_jh, jclass caller_jh)) { |
3412
88559690c95a
7047961: JSR 292 MethodHandleWalk swap args doesn't handle T_LONG and T_DOUBLE properly
never
parents:
3389
diff
changeset
|
2942 if (mname_jh == NULL) { THROW_MSG(vmSymbols::java_lang_InternalError(), "mname is null"); } |
710 | 2943 Handle mname(THREAD, JNIHandles::resolve_non_null(mname_jh)); |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2944 |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2945 // The trusted Java code that calls this method should already have performed |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2946 // access checks on behalf of the given caller. But, we can verify this. |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2947 if (VerifyMethodHandles && caller_jh != NULL) { |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2948 klassOop reference_klass = java_lang_Class::as_klassOop(java_lang_invoke_MemberName::clazz(mname())); |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2949 if (reference_klass != NULL) { |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2950 // Emulate LinkResolver::check_klass_accessability. |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2951 klassOop caller = java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(caller_jh)); |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2952 if (!Reflection::verify_class_access(caller, |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2953 reference_klass, |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2954 true)) { |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2955 THROW_MSG(vmSymbols::java_lang_InternalError(), Klass::cast(reference_klass)->external_name()); |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2956 } |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2957 } |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2958 } |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2959 |
710 | 2960 MethodHandles::resolve_MemberName(mname, CHECK); |
2961 } | |
2962 JVM_END | |
2963 | |
2964 // static native int getMembers(Class<?> defc, String matchName, String matchSig, | |
2965 // int matchFlags, Class<?> caller, int skip, MemberName[] results); | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2966 JVM_ENTRY(jint, MHN_getMembers(JNIEnv *env, jobject igcls, |
710 | 2967 jclass clazz_jh, jstring name_jh, jstring sig_jh, |
2968 int mflags, jclass caller_jh, jint skip, jobjectArray results_jh)) { | |
2969 if (clazz_jh == NULL || results_jh == NULL) return -1; | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
2970 KlassHandle k(THREAD, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz_jh))); |
710 | 2971 |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
2972 objArrayHandle results(THREAD, (objArrayOop) JNIHandles::resolve(results_jh)); |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
2973 if (results.is_null() || !results->is_objArray()) return -1; |
710 | 2974 |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
2975 TempNewSymbol name = NULL; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
2976 TempNewSymbol sig = NULL; |
710 | 2977 if (name_jh != NULL) { |
2978 name = java_lang_String::as_symbol_or_null(JNIHandles::resolve_non_null(name_jh)); | |
2979 if (name == NULL) return 0; // a match is not possible | |
2980 } | |
2981 if (sig_jh != NULL) { | |
2982 sig = java_lang_String::as_symbol_or_null(JNIHandles::resolve_non_null(sig_jh)); | |
2983 if (sig == NULL) return 0; // a match is not possible | |
2984 } | |
2985 | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
2986 KlassHandle caller; |
710 | 2987 if (caller_jh != NULL) { |
2988 oop caller_oop = JNIHandles::resolve_non_null(caller_jh); | |
2989 if (!java_lang_Class::is_instance(caller_oop)) return -1; | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
2990 caller = KlassHandle(THREAD, java_lang_Class::as_klassOop(caller_oop)); |
710 | 2991 } |
2992 | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
2993 if (name != NULL && sig != NULL && results.not_null()) { |
710 | 2994 // try a direct resolve |
2995 // %%% TO DO | |
2996 } | |
2997 | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
2998 int res = MethodHandles::find_MemberNames(k(), name, sig, mflags, |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
2999 caller(), skip, results()); |
710 | 3000 // TO DO: expand at least some of the MemberNames, to avoid massive callbacks |
3001 return res; | |
3002 } | |
3003 JVM_END | |
3004 | |
3417
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3005 methodOop MethodHandles::resolve_raise_exception_method(TRAPS) { |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3006 if (_raise_exception_method != NULL) { |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3007 // no need to do it twice |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3008 return raise_exception_method(); |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3009 } |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3010 // LinkResolver::resolve_invokedynamic can reach this point |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3011 // because an invokedynamic has failed very early (7049415) |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3012 KlassHandle MHN_klass = SystemDictionaryHandles::MethodHandleNatives_klass(); |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3013 if (MHN_klass.not_null()) { |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3014 TempNewSymbol raiseException_name = SymbolTable::new_symbol("raiseException", CHECK_NULL); |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3015 TempNewSymbol raiseException_sig = SymbolTable::new_symbol("(ILjava/lang/Object;Ljava/lang/Object;)V", CHECK_NULL); |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3016 methodOop raiseException_method = instanceKlass::cast(MHN_klass->as_klassOop()) |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3017 ->find_method(raiseException_name, raiseException_sig); |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3018 if (raiseException_method != NULL && raiseException_method->is_static()) { |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3019 return raiseException_method; |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3020 } |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3021 } |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3022 // not found; let the caller deal with it |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3023 return NULL; |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3024 } |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3025 void MethodHandles::raise_exception(int code, oop actual, oop required, TRAPS) { |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3026 methodOop raiseException_method = resolve_raise_exception_method(CHECK); |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3027 if (raiseException_method != NULL && |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3028 instanceKlass::cast(raiseException_method->method_holder())->is_not_initialized()) { |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3029 instanceKlass::cast(raiseException_method->method_holder())->initialize(CHECK); |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3030 // it had better be resolved by now, or maybe JSR 292 failed to load |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3031 raiseException_method = raise_exception_method(); |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3032 } |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3033 if (raiseException_method == NULL) { |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3034 THROW_MSG(vmSymbols::java_lang_InternalError(), "no raiseException method"); |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3035 } |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3036 JavaCallArguments args; |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3037 args.push_int(code); |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3038 args.push_oop(actual); |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3039 args.push_oop(required); |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3040 JavaValue result(T_VOID); |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3041 JavaCalls::call(&result, raiseException_method, &args, CHECK); |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3042 } |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3043 |
3387
2848194272f4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
3371
diff
changeset
|
3044 JVM_ENTRY(jobject, MH_invoke_UOE(JNIEnv *env, jobject igmh, jobjectArray igargs)) { |
2848194272f4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
3371
diff
changeset
|
3045 TempNewSymbol UOE_name = SymbolTable::new_symbol("java/lang/UnsupportedOperationException", CHECK_NULL); |
2848194272f4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
3371
diff
changeset
|
3046 THROW_MSG_NULL(UOE_name, "MethodHandle.invoke cannot be invoked reflectively"); |
2848194272f4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
3371
diff
changeset
|
3047 return NULL; |
2848194272f4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
3371
diff
changeset
|
3048 } |
2848194272f4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
3371
diff
changeset
|
3049 JVM_END |
2848194272f4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
3371
diff
changeset
|
3050 |
2848194272f4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
3371
diff
changeset
|
3051 JVM_ENTRY(jobject, MH_invokeExact_UOE(JNIEnv *env, jobject igmh, jobjectArray igargs)) { |
2848194272f4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
3371
diff
changeset
|
3052 TempNewSymbol UOE_name = SymbolTable::new_symbol("java/lang/UnsupportedOperationException", CHECK_NULL); |
2848194272f4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
3371
diff
changeset
|
3053 THROW_MSG_NULL(UOE_name, "MethodHandle.invokeExact cannot be invoked reflectively"); |
2848194272f4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
3371
diff
changeset
|
3054 return NULL; |
2848194272f4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
3371
diff
changeset
|
3055 } |
2848194272f4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
3371
diff
changeset
|
3056 JVM_END |
2848194272f4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
3371
diff
changeset
|
3057 |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
3058 |
710 | 3059 /// JVM_RegisterMethodHandleMethods |
3060 | |
3061 #define LANG "Ljava/lang/" | |
2460 | 3062 #define JLINV "Ljava/lang/invoke/" |
710 | 3063 |
3064 #define OBJ LANG"Object;" | |
3065 #define CLS LANG"Class;" | |
3066 #define STRG LANG"String;" | |
2460 | 3067 #define MT JLINV"MethodType;" |
3068 #define MH JLINV"MethodHandle;" | |
3069 #define MEM JLINV"MemberName;" | |
3070 #define AMH JLINV"AdapterMethodHandle;" | |
3071 #define BMH JLINV"BoundMethodHandle;" | |
3072 #define DMH JLINV"DirectMethodHandle;" | |
710 | 3073 |
3074 #define CC (char*) /*cast a literal from (const char*)*/ | |
3075 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f) | |
3076 | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
3077 // These are the native methods on sun.invoke.MethodHandleNatives. |
710 | 3078 static JNINativeMethod methods[] = { |
3079 // void init(MemberName self, AccessibleObject ref) | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
3080 {CC"init", CC"("AMH""MH"I)V", FN_PTR(MHN_init_AMH)}, |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
3081 {CC"init", CC"("BMH""OBJ"I)V", FN_PTR(MHN_init_BMH)}, |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
3082 {CC"init", CC"("DMH""OBJ"Z"CLS")V", FN_PTR(MHN_init_DMH)}, |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
3083 {CC"init", CC"("MT")V", FN_PTR(MHN_init_MT)}, |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
3084 {CC"init", CC"("MEM""OBJ")V", FN_PTR(MHN_init_Mem)}, |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
3085 {CC"expand", CC"("MEM")V", FN_PTR(MHN_expand_Mem)}, |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
3086 {CC"resolve", CC"("MEM""CLS")V", FN_PTR(MHN_resolve_Mem)}, |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
3087 {CC"getTarget", CC"("MH"I)"OBJ, FN_PTR(MHN_getTarget)}, |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
3088 {CC"getConstant", CC"(I)I", FN_PTR(MHN_getConstant)}, |
710 | 3089 // static native int getNamedCon(int which, Object[] name) |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
3090 {CC"getNamedCon", CC"(I["OBJ")I", FN_PTR(MHN_getNamedCon)}, |
710 | 3091 // static native int getMembers(Class<?> defc, String matchName, String matchSig, |
3092 // int matchFlags, Class<?> caller, int skip, MemberName[] results); | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
3093 {CC"getMembers", CC"("CLS""STRG""STRG"I"CLS"I["MEM")I", FN_PTR(MHN_getMembers)} |
710 | 3094 }; |
3095 | |
3387
2848194272f4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
3371
diff
changeset
|
3096 static JNINativeMethod invoke_methods[] = { |
2848194272f4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
3371
diff
changeset
|
3097 // void init(MemberName self, AccessibleObject ref) |
2848194272f4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
3371
diff
changeset
|
3098 {CC"invoke", CC"(["OBJ")"OBJ, FN_PTR(MH_invoke_UOE)}, |
2848194272f4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
3371
diff
changeset
|
3099 {CC"invokeExact", CC"(["OBJ")"OBJ, FN_PTR(MH_invokeExact_UOE)} |
2848194272f4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
3371
diff
changeset
|
3100 }; |
2848194272f4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
3371
diff
changeset
|
3101 |
710 | 3102 // This one function is exported, used by NativeLookup. |
3103 | |
3104 JVM_ENTRY(void, JVM_RegisterMethodHandleMethods(JNIEnv *env, jclass MHN_class)) { | |
3105 assert(MethodHandles::spot_check_entry_names(), "entry enum is OK"); | |
3106 | |
2416
38fea01eb669
6817525: turn on method handle functionality by default for JSR 292
twisti
parents:
2357
diff
changeset
|
3107 if (!EnableInvokeDynamic) { |
38fea01eb669
6817525: turn on method handle functionality by default for JSR 292
twisti
parents:
2357
diff
changeset
|
3108 warning("JSR 292 is disabled in this JVM. Use -XX:+UnlockDiagnosticVMOptions -XX:+EnableInvokeDynamic to enable."); |
710 | 3109 return; // bind nothing |
3110 } | |
3111 | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
3112 bool enable_MH = true; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
3113 |
2460 | 3114 { |
710 | 3115 ThreadToNativeFromVM ttnfv(thread); |
3116 | |
3117 int status = env->RegisterNatives(MHN_class, methods, sizeof(methods)/sizeof(JNINativeMethod)); | |
3387
2848194272f4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
3371
diff
changeset
|
3118 if (!env->ExceptionOccurred()) { |
2848194272f4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
3371
diff
changeset
|
3119 const char* L_MH_name = (JLINV "MethodHandle"); |
2848194272f4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
3371
diff
changeset
|
3120 const char* MH_name = L_MH_name+1; |
2848194272f4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
3371
diff
changeset
|
3121 jclass MH_class = env->FindClass(MH_name); |
2848194272f4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
3371
diff
changeset
|
3122 status = env->RegisterNatives(MH_class, invoke_methods, sizeof(invoke_methods)/sizeof(JNINativeMethod)); |
2848194272f4
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one
jrose
parents:
3371
diff
changeset
|
3123 } |
710 | 3124 if (env->ExceptionOccurred()) { |
2460 | 3125 MethodHandles::set_enabled(false); |
3126 warning("JSR 292 method handle code is mismatched to this JVM. Disabling support."); | |
3127 enable_MH = false; | |
710 | 3128 env->ExceptionClear(); |
3129 } | |
3130 } | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
3131 |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
3132 if (enable_MH) { |
3417
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3133 methodOop raiseException_method = MethodHandles::resolve_raise_exception_method(CHECK); |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3134 if (raiseException_method != NULL) { |
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3135 MethodHandles::set_raise_exception_method(raiseException_method); |
2460 | 3136 } else { |
3417
ba550512d3b2
7049415: Failure of resolution of sym.reference to the c.s.s. should be wrapped in BootstrapMethodError
jrose
parents:
3412
diff
changeset
|
3137 warning("JSR 292 method handle code is mismatched to this JVM. Disabling support."); |
2116
d810e9a3fc33
7010180: JSR 292 InvokeDynamicPrintArgs fails with: assert(_adapter == NULL) failed: init'd to NULL
twisti
parents:
2088
diff
changeset
|
3138 enable_MH = false; |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
3139 } |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
3140 } |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
3141 |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
3142 if (enable_MH) { |
2116
d810e9a3fc33
7010180: JSR 292 InvokeDynamicPrintArgs fails with: assert(_adapter == NULL) failed: init'd to NULL
twisti
parents:
2088
diff
changeset
|
3143 MethodHandles::generate_adapters(); |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
3144 MethodHandles::set_enabled(true); |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
3145 } |
710 | 3146 } |
3147 JVM_END |