Mercurial > hg > graal-jvmci-8
annotate src/share/vm/prims/methodHandles.cpp @ 3274:2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
Reviewed-by: kvn, jrose
author | twisti |
---|---|
date | Mon, 18 Apr 2011 01:33:28 -0700 |
parents | 328926869b15 |
children | 167b70ff3abc |
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" | |
28 #include "memory/allocation.inline.hpp" | |
29 #include "memory/oopFactory.hpp" | |
30 #include "prims/methodHandles.hpp" | |
31 #include "runtime/javaCalls.hpp" | |
32 #include "runtime/reflection.hpp" | |
33 #include "runtime/signature.hpp" | |
34 #include "runtime/stubRoutines.hpp" | |
35 | |
710 | 36 /* |
37 * JSR 292 reference implementation: method handles | |
38 */ | |
39 | |
40 bool MethodHandles::_enabled = false; // set true after successful native linkage | |
41 | |
42 MethodHandleEntry* MethodHandles::_entries[MethodHandles::_EK_LIMIT] = {NULL}; | |
43 const char* MethodHandles::_entry_names[_EK_LIMIT+1] = { | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
44 "raise_exception", |
710 | 45 "invokestatic", // how a MH emulates invokestatic |
46 "invokespecial", // ditto for the other invokes... | |
47 "invokevirtual", | |
48 "invokeinterface", | |
49 "bound_ref", // these are for BMH... | |
50 "bound_int", | |
51 "bound_long", | |
52 "bound_ref_direct", // (direct versions have a direct methodOop) | |
53 "bound_int_direct", | |
54 "bound_long_direct", | |
55 | |
56 // starting at _adapter_mh_first: | |
57 "adapter_retype_only", // these are for AMH... | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
58 "adapter_retype_raw", |
710 | 59 "adapter_check_cast", |
60 "adapter_prim_to_prim", | |
61 "adapter_ref_to_prim", | |
62 "adapter_prim_to_ref", | |
63 "adapter_swap_args", | |
64 "adapter_rot_args", | |
65 "adapter_dup_args", | |
66 "adapter_drop_args", | |
67 "adapter_collect_args", | |
68 "adapter_spread_args", | |
69 "adapter_flyby", | |
70 "adapter_ricochet", | |
71 | |
72 // optimized adapter types: | |
73 "adapter_swap_args/1", | |
74 "adapter_swap_args/2", | |
75 "adapter_rot_args/1,up", | |
76 "adapter_rot_args/1,down", | |
77 "adapter_rot_args/2,up", | |
78 "adapter_rot_args/2,down", | |
79 "adapter_prim_to_prim/i2i", | |
80 "adapter_prim_to_prim/l2i", | |
81 "adapter_prim_to_prim/d2f", | |
82 "adapter_prim_to_prim/i2l", | |
83 "adapter_prim_to_prim/f2d", | |
84 "adapter_ref_to_prim/unboxi", | |
85 "adapter_ref_to_prim/unboxl", | |
86 "adapter_spread_args/0", | |
87 "adapter_spread_args/1", | |
88 "adapter_spread_args/more", | |
89 | |
90 NULL | |
91 }; | |
92 | |
1299
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
93 // Adapters. |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
94 MethodHandlesAdapterBlob* MethodHandles::_adapter_code = NULL; |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
95 int MethodHandles::_adapter_code_size = StubRoutines::method_handles_adapters_code_size; |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
96 |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
97 jobject MethodHandles::_raise_exception_method; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
98 |
710 | 99 #ifdef ASSERT |
100 bool MethodHandles::spot_check_entry_names() { | |
101 assert(!strcmp(entry_name(_invokestatic_mh), "invokestatic"), ""); | |
102 assert(!strcmp(entry_name(_bound_ref_mh), "bound_ref"), ""); | |
103 assert(!strcmp(entry_name(_adapter_retype_only), "adapter_retype_only"), ""); | |
104 assert(!strcmp(entry_name(_adapter_ricochet), "adapter_ricochet"), ""); | |
105 assert(!strcmp(entry_name(_adapter_opt_unboxi), "adapter_ref_to_prim/unboxi"), ""); | |
106 return true; | |
107 } | |
108 #endif | |
109 | |
1299
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
110 |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
111 //------------------------------------------------------------------------------ |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
112 // MethodHandles::generate_adapters |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
113 // |
2116
d810e9a3fc33
7010180: JSR 292 InvokeDynamicPrintArgs fails with: assert(_adapter == NULL) failed: init'd to NULL
twisti
parents:
2088
diff
changeset
|
114 void MethodHandles::generate_adapters() { |
2416
38fea01eb669
6817525: turn on method handle functionality by default for JSR 292
twisti
parents:
2357
diff
changeset
|
115 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
|
116 |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
117 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
|
118 |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
119 ResourceMark rm; |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
120 TraceTime timer("MethodHandles adapters generation", TraceStartupTime); |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
121 _adapter_code = MethodHandlesAdapterBlob::create(_adapter_code_size); |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
122 if (_adapter_code == NULL) |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
123 vm_exit_out_of_memory(_adapter_code_size, "CodeCache: no room for MethodHandles adapters"); |
1748 | 124 CodeBuffer code(_adapter_code); |
1299
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
125 MethodHandlesAdapterGenerator g(&code); |
2116
d810e9a3fc33
7010180: JSR 292 InvokeDynamicPrintArgs fails with: assert(_adapter == NULL) failed: init'd to NULL
twisti
parents:
2088
diff
changeset
|
126 g.generate(); |
1299
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
127 } |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
128 |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
129 |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
130 //------------------------------------------------------------------------------ |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
131 // MethodHandlesAdapterGenerator::generate |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
132 // |
2116
d810e9a3fc33
7010180: JSR 292 InvokeDynamicPrintArgs fails with: assert(_adapter == NULL) failed: init'd to NULL
twisti
parents:
2088
diff
changeset
|
133 void MethodHandlesAdapterGenerator::generate() { |
1299
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
134 // Generate generic method handle adapters. |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
135 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
|
136 ek < MethodHandles::_EK_LIMIT; |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
137 ek = MethodHandles::EntryKind(1 + (int)ek)) { |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
138 StubCodeMark mark(this, "MethodHandle", MethodHandles::entry_name(ek)); |
2116
d810e9a3fc33
7010180: JSR 292 InvokeDynamicPrintArgs fails with: assert(_adapter == NULL) failed: init'd to NULL
twisti
parents:
2088
diff
changeset
|
139 MethodHandles::generate_method_handle_stub(_masm, ek); |
1299
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
140 } |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
141 } |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
142 |
9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
twisti
parents:
1142
diff
changeset
|
143 |
710 | 144 void MethodHandles::set_enabled(bool z) { |
145 if (_enabled != z) { | |
2416
38fea01eb669
6817525: turn on method handle functionality by default for JSR 292
twisti
parents:
2357
diff
changeset
|
146 guarantee(z && EnableInvokeDynamic, "can only enable once, and only if -XX:+EnableInvokeDynamic"); |
710 | 147 _enabled = z; |
148 } | |
149 } | |
150 | |
151 // Note: A method which does not have a TRAPS argument cannot block in the GC | |
152 // or throw exceptions. Such methods are used in this file to do something quick | |
153 // and local, like parse a data structure. For speed, such methods work on plain | |
154 // oops, not handles. Trapping methods uniformly operate on handles. | |
155 | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
156 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
|
157 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
|
158 if (vmtarget == NULL) return methodHandle(); |
710 | 159 assert(methodOopDesc::nonvirtual_vtable_index < 0, "encoding"); |
160 if (vmindex < 0) { | |
161 // this DMH performs no dispatch; it is directly bound to a methodOop | |
162 // A MemberName may either be directly bound to a methodOop, | |
163 // or it may use the klass/index form; both forms mean the same thing. | |
164 methodOop m = decode_methodOop(methodOop(vmtarget), decode_flags_result); | |
165 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
|
166 && java_lang_invoke_MethodType::is_instance(mtype)) { |
710 | 167 // 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
|
168 objArrayOop ptypes = java_lang_invoke_MethodType::ptypes(mtype); |
710 | 169 oop ptype0 = (ptypes == NULL || ptypes->length() < 1) ? oop(NULL) : ptypes->obj_at(0); |
170 if (java_lang_Class::is_instance(ptype0)) | |
171 receiver_limit_result = java_lang_Class::as_klassOop(ptype0); | |
172 } | |
173 if (vmindex == methodOopDesc::nonvirtual_vtable_index) { | |
174 // this DMH can be an "invokespecial" version | |
175 decode_flags_result &= ~_dmf_does_dispatch; | |
176 } else { | |
177 assert(vmindex == methodOopDesc::invalid_vtable_index, "random vmindex?"); | |
178 } | |
179 return m; | |
180 } else { | |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
181 assert(vmtarget->is_klass(), "must be class or interface"); |
710 | 182 decode_flags_result |= MethodHandles::_dmf_does_dispatch; |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
183 decode_flags_result |= MethodHandles::_dmf_has_receiver; |
710 | 184 receiver_limit_result = (klassOop)vmtarget; |
185 Klass* tk = Klass::cast((klassOop)vmtarget); | |
186 if (tk->is_interface()) { | |
187 // an itable linkage is <interface, itable index> | |
188 decode_flags_result |= MethodHandles::_dmf_from_interface; | |
189 return klassItable::method_for_itable_index((klassOop)vmtarget, vmindex); | |
190 } else { | |
191 if (!tk->oop_is_instance()) | |
1142 | 192 tk = instanceKlass::cast(SystemDictionary::Object_klass()); |
710 | 193 return ((instanceKlass*)tk)->method_at_vtable(vmindex); |
194 } | |
195 } | |
196 } | |
197 | |
198 // MemberName and DirectMethodHandle have the same linkage to the JVM internals. | |
199 // (MemberName is the non-operational name used for queries and setup.) | |
200 | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
201 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
|
202 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
|
203 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
|
204 oop mtype = java_lang_invoke_DirectMethodHandle::type(mh); |
710 | 205 return decode_vmtarget(vmtarget, vmindex, mtype, receiver_limit_result, decode_flags_result); |
206 } | |
207 | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
208 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
|
209 assert(java_lang_invoke_BoundMethodHandle::is_instance(mh), ""); |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
210 assert(mh->klass() != SystemDictionary::AdapterMethodHandle_klass(), ""); |
710 | 211 for (oop bmh = mh;;) { |
212 // 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
|
213 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
|
214 if (target == NULL) return methodHandle(); |
710 | 215 decode_flags_result |= MethodHandles::_dmf_binds_argument; |
216 klassOop tk = target->klass(); | |
217 if (tk == SystemDictionary::BoundMethodHandle_klass()) { | |
218 bmh = target; | |
219 continue; | |
220 } else { | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
221 if (java_lang_invoke_MethodHandle::is_subclass(tk)) { |
710 | 222 //assert(tk == SystemDictionary::DirectMethodHandle_klass(), "end of BMH chain must be DMH"); |
223 return decode_MethodHandle(target, receiver_limit_result, decode_flags_result); | |
224 } else { | |
225 // Optimized case: binding a receiver to a non-dispatched DMH | |
226 // short-circuits directly to the methodOop. | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
227 // (It might be another argument besides a receiver also.) |
710 | 228 assert(target->is_method(), "must be a simple method"); |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
229 decode_flags_result |= MethodHandles::_dmf_binds_method; |
710 | 230 methodOop m = (methodOop) target; |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
231 if (!m->is_static()) |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
232 decode_flags_result |= MethodHandles::_dmf_has_receiver; |
710 | 233 return m; |
234 } | |
235 } | |
236 } | |
237 } | |
238 | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
239 methodHandle MethodHandles::decode_AdapterMethodHandle(oop mh, KlassHandle& receiver_limit_result, int& decode_flags_result) { |
710 | 240 assert(mh->klass() == SystemDictionary::AdapterMethodHandle_klass(), ""); |
241 for (oop amh = mh;;) { | |
242 // 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
|
243 int conv_op = adapter_conversion_op(java_lang_invoke_AdapterMethodHandle::conversion(amh)); |
710 | 244 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
|
245 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
|
246 if (target == NULL) return methodHandle(); |
710 | 247 klassOop tk = target->klass(); |
248 if (tk == SystemDictionary::AdapterMethodHandle_klass()) { | |
249 amh = target; | |
250 continue; | |
251 } else { | |
252 // must be a BMH (which will bind some more arguments) or a DMH (for the final call) | |
253 return MethodHandles::decode_MethodHandle(target, receiver_limit_result, decode_flags_result); | |
254 } | |
255 } | |
256 } | |
257 | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
258 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
|
259 if (mh == NULL) return methodHandle(); |
710 | 260 klassOop mhk = mh->klass(); |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
261 assert(java_lang_invoke_MethodHandle::is_subclass(mhk), "must be a MethodHandle"); |
710 | 262 if (mhk == SystemDictionary::DirectMethodHandle_klass()) { |
263 return decode_DirectMethodHandle(mh, receiver_limit_result, decode_flags_result); | |
264 } else if (mhk == SystemDictionary::BoundMethodHandle_klass()) { | |
265 return decode_BoundMethodHandle(mh, receiver_limit_result, decode_flags_result); | |
266 } else if (mhk == SystemDictionary::AdapterMethodHandle_klass()) { | |
267 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
|
268 } 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
|
269 // could be a JavaMethodHandle (but not an adapter MH) |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
270 return decode_BoundMethodHandle(mh, receiver_limit_result, decode_flags_result); |
710 | 271 } else { |
272 assert(false, "cannot parse this MH"); | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
273 return methodHandle(); // random MH? |
710 | 274 } |
275 } | |
276 | |
277 methodOop MethodHandles::decode_methodOop(methodOop m, int& decode_flags_result) { | |
278 assert(m->is_method(), ""); | |
279 if (m->is_static()) { | |
280 // 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
|
281 Symbol* sig = m->signature(); |
710 | 282 BasicType recv_bt = char2type(sig->byte_at(1)); |
283 // Note: recv_bt might be T_ILLEGAL if byte_at(2) is ')' | |
284 assert(sig->byte_at(0) == '(', "must be method sig"); | |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
285 // if (recv_bt == T_OBJECT || recv_bt == T_ARRAY) |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
286 // decode_flags_result |= _dmf_has_receiver; |
710 | 287 } else { |
288 // non-static method | |
289 decode_flags_result |= _dmf_has_receiver; | |
290 if (!m->can_be_statically_bound() && !m->is_initializer()) { | |
291 decode_flags_result |= _dmf_does_dispatch; | |
292 if (Klass::cast(m->method_holder())->is_interface()) | |
293 decode_flags_result |= _dmf_from_interface; | |
294 } | |
295 } | |
296 return m; | |
297 } | |
298 | |
299 | |
300 // A trusted party is handing us a cookie to determine a method. | |
301 // 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
|
302 methodHandle MethodHandles::decode_method(oop x, KlassHandle& receiver_limit_result, int& decode_flags_result) { |
710 | 303 decode_flags_result = 0; |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
304 receiver_limit_result = KlassHandle(); |
710 | 305 klassOop xk = x->klass(); |
306 if (xk == Universe::methodKlassObj()) { | |
307 return decode_methodOop((methodOop) x, decode_flags_result); | |
308 } else if (xk == SystemDictionary::MemberName_klass()) { | |
309 // Note: This only works if the MemberName has already been resolved. | |
310 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
|
311 } else if (java_lang_invoke_MethodHandle::is_subclass(xk)) { |
710 | 312 return decode_MethodHandle(x, receiver_limit_result, decode_flags_result); |
1142 | 313 } else if (xk == SystemDictionary::reflect_Method_klass()) { |
710 | 314 oop clazz = java_lang_reflect_Method::clazz(x); |
315 int slot = java_lang_reflect_Method::slot(x); | |
316 klassOop k = java_lang_Class::as_klassOop(clazz); | |
317 if (k != NULL && Klass::cast(k)->oop_is_instance()) | |
318 return decode_methodOop(instanceKlass::cast(k)->method_with_idnum(slot), | |
319 decode_flags_result); | |
1142 | 320 } else if (xk == SystemDictionary::reflect_Constructor_klass()) { |
710 | 321 oop clazz = java_lang_reflect_Constructor::clazz(x); |
322 int slot = java_lang_reflect_Constructor::slot(x); | |
323 klassOop k = java_lang_Class::as_klassOop(clazz); | |
324 if (k != NULL && Klass::cast(k)->oop_is_instance()) | |
325 return decode_methodOop(instanceKlass::cast(k)->method_with_idnum(slot), | |
326 decode_flags_result); | |
327 } else { | |
328 // unrecognized object | |
329 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
|
330 assert(!java_lang_invoke_MemberName::is_instance(x), "already checked"); |
710 | 331 } |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
332 return methodHandle(); |
710 | 333 } |
334 | |
335 | |
336 int MethodHandles::decode_MethodHandle_stack_pushes(oop mh) { | |
337 if (mh->klass() == SystemDictionary::DirectMethodHandle_klass()) | |
338 return 0; // no push/pop | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
339 int this_vmslots = java_lang_invoke_MethodHandle::vmslots(mh); |
710 | 340 int last_vmslots = 0; |
341 oop last_mh = mh; | |
342 for (;;) { | |
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(last_mh); |
710 | 344 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
|
345 last_vmslots = java_lang_invoke_MethodHandle::vmslots(target); |
710 | 346 break; |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
347 } else if (!java_lang_invoke_MethodHandle::is_instance(target)) { |
710 | 348 // might be klass or method |
349 assert(target->is_method(), "must get here with a direct ref to method"); | |
350 last_vmslots = methodOop(target)->size_of_parameters(); | |
351 break; | |
352 } | |
353 last_mh = target; | |
354 } | |
355 // If I am called with fewer VM slots than my ultimate callee, | |
356 // it must be that I push the additionally needed slots. | |
357 // Likewise if am called with more VM slots, I will pop them. | |
358 return (last_vmslots - this_vmslots); | |
359 } | |
360 | |
361 | |
362 // MemberName support | |
363 | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
364 // import java_lang_invoke_MemberName.* |
710 | 365 enum { |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
366 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
|
367 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
|
368 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
|
369 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
|
370 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
|
371 SEARCH_INTERFACES = java_lang_invoke_MemberName::MN_SEARCH_INTERFACES, |
710 | 372 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
|
373 VM_INDEX_UNINITIALIZED = java_lang_invoke_MemberName::VM_INDEX_UNINITIALIZED |
710 | 374 }; |
375 | |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
376 Handle MethodHandles::new_MemberName(TRAPS) { |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
377 Handle empty; |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
378 instanceKlassHandle k(THREAD, SystemDictionary::MemberName_klass()); |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
379 if (!k->is_initialized()) k->initialize(CHECK_(empty)); |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
380 return Handle(THREAD, k->allocate_instance(THREAD)); |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
381 } |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
382 |
710 | 383 void MethodHandles::init_MemberName(oop mname_oop, oop target_oop) { |
1142 | 384 if (target_oop->klass() == SystemDictionary::reflect_Field_klass()) { |
710 | 385 oop clazz = java_lang_reflect_Field::clazz(target_oop); // fd.field_holder() |
386 int slot = java_lang_reflect_Field::slot(target_oop); // fd.index() | |
387 int mods = java_lang_reflect_Field::modifiers(target_oop); | |
388 klassOop k = java_lang_Class::as_klassOop(clazz); | |
389 int offset = instanceKlass::cast(k)->offset_from_fields(slot); | |
390 init_MemberName(mname_oop, k, accessFlags_from(mods), offset); | |
391 } else { | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
392 KlassHandle receiver_limit; int decode_flags = 0; |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
393 methodHandle m = MethodHandles::decode_method(target_oop, receiver_limit, decode_flags); |
710 | 394 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
|
395 init_MemberName(mname_oop, m(), do_dispatch); |
710 | 396 } |
397 } | |
398 | |
399 void MethodHandles::init_MemberName(oop mname_oop, methodOop m, bool do_dispatch) { | |
400 int flags = ((m->is_initializer() ? IS_CONSTRUCTOR : IS_METHOD) | |
401 | (jushort)( m->access_flags().as_short() & JVM_RECOGNIZED_METHOD_MODIFIERS )); | |
402 oop vmtarget = m; | |
403 int vmindex = methodOopDesc::invalid_vtable_index; // implies no info yet | |
404 if (!do_dispatch || (flags & IS_CONSTRUCTOR) || m->can_be_statically_bound()) | |
405 vmindex = methodOopDesc::nonvirtual_vtable_index; // implies never any dispatch | |
406 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
|
407 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
|
408 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
|
409 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
|
410 java_lang_invoke_MemberName::set_clazz(mname_oop, Klass::cast(m->method_holder())->java_mirror()); |
710 | 411 } |
412 | |
413 void MethodHandles::init_MemberName(oop mname_oop, klassOop field_holder, AccessFlags mods, int offset) { | |
414 int flags = (IS_FIELD | (jushort)( mods.as_short() & JVM_RECOGNIZED_FIELD_MODIFIERS )); | |
415 oop vmtarget = field_holder; | |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
416 int vmindex = offset; // determines the field uniquely when combined with static bit |
710 | 417 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
|
418 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
|
419 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
|
420 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
|
421 java_lang_invoke_MemberName::set_clazz(mname_oop, Klass::cast(field_holder)->java_mirror()); |
710 | 422 } |
423 | |
424 | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
425 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
|
426 methodHandle empty; |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
427 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
|
428 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
|
429 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
|
430 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
|
431 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
|
432 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
|
433 oop clazz = java_lang_invoke_MemberName::clazz(mname); |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
434 if (clazz != NULL && java_lang_Class::is_instance(clazz)) { |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
435 klassOop klass = java_lang_Class::as_klassOop(clazz); |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
436 if (klass != NULL) receiver_limit_result = klass; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
437 } |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
438 return m; |
710 | 439 } |
440 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
441 // 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
|
442 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
|
443 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
|
444 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
|
445 } 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
|
446 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
|
447 } 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
|
448 if (polymorphic) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
449 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
|
450 } else { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
451 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
|
452 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
453 } else { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
454 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
|
455 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
456 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
457 |
710 | 458 // An unresolved member name is a mere symbolic reference. |
459 // Resolving it plants a vmtarget/vmindex in it, | |
460 // which refers dirctly to JVM internals. | |
461 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
|
462 assert(java_lang_invoke_MemberName::is_instance(mname()), ""); |
710 | 463 #ifdef ASSERT |
464 // If this assert throws, renegotiate the sentinel value used by the Java code, | |
465 // so that it is distinct from any valid vtable index value, and any special | |
466 // values defined in methodOopDesc::VtableIndexFlag. | |
467 // The point of the slop is to give the Java code and the JVM some room | |
468 // to independently specify sentinel values. | |
469 const int sentinel_slop = 10; | |
470 const int sentinel_limit = methodOopDesc::highest_unused_vtable_index_value - sentinel_slop; | |
471 assert(VM_INDEX_UNINITIALIZED < sentinel_limit, "Java sentinel != JVM sentinels"); | |
472 #endif | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
473 if (java_lang_invoke_MemberName::vmindex(mname()) != VM_INDEX_UNINITIALIZED) |
710 | 474 return; // already resolved |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
475 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
|
476 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
|
477 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
|
478 int flags = java_lang_invoke_MemberName::flags(mname()); |
710 | 479 |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
480 if (defc_oop.is_null() || name_str.is_null() || type_str.is_null()) { |
710 | 481 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "nothing to resolve"); |
482 } | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
483 |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
484 instanceKlassHandle defc; |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
485 { |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
486 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
|
487 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
|
488 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
|
489 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
|
490 defc_klassOop = SystemDictionary::Object_klass(); |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
491 } |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
492 defc = instanceKlassHandle(THREAD, defc_klassOop); |
710 | 493 } |
494 if (defc.is_null()) { | |
495 THROW_MSG(vmSymbols::java_lang_InternalError(), "primitive class"); | |
496 } | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
497 defc->link_class(CHECK); // possible safepoint |
710 | 498 |
499 // 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
|
500 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
|
501 if (name == NULL) return; // no such name |
710 | 502 |
1508
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
503 Handle polymorphic_method_type; |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
504 bool polymorphic_signature = false; |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
505 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
|
506 (defc() == SystemDictionary::MethodHandle_klass() && |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
507 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
|
508 polymorphic_signature = true; |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
509 } |
1508
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
510 |
710 | 511 // 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
|
512 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
|
513 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
|
514 polymorphic_method_type = type_str; // preserve exactly |
710 | 515 } |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
516 if (type == NULL) return; // no such signature exists in the VM |
710 | 517 |
518 // Time to do the lookup. | |
519 switch (flags & ALL_KINDS) { | |
520 case IS_METHOD: | |
521 { | |
522 CallInfo result; | |
523 { | |
524 EXCEPTION_MARK; | |
525 if ((flags & JVM_ACC_STATIC) != 0) { | |
526 LinkResolver::resolve_static_call(result, | |
527 defc, name, type, KlassHandle(), false, false, THREAD); | |
528 } else if (defc->is_interface()) { | |
529 LinkResolver::resolve_interface_call(result, Handle(), defc, | |
530 defc, name, type, KlassHandle(), false, false, THREAD); | |
531 } else { | |
532 LinkResolver::resolve_virtual_call(result, Handle(), defc, | |
533 defc, name, type, KlassHandle(), false, false, THREAD); | |
534 } | |
535 if (HAS_PENDING_EXCEPTION) { | |
536 CLEAR_PENDING_EXCEPTION; | |
1508
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
537 break; // go to second chance |
710 | 538 } |
539 } | |
540 methodHandle m = result.resolved_method(); | |
541 oop vmtarget = NULL; | |
542 int vmindex = methodOopDesc::nonvirtual_vtable_index; | |
543 if (defc->is_interface()) { | |
544 vmindex = klassItable::compute_itable_index(m()); | |
545 assert(vmindex >= 0, ""); | |
546 } else if (result.has_vtable_index()) { | |
547 vmindex = result.vtable_index(); | |
548 assert(vmindex >= 0, ""); | |
549 } | |
550 assert(vmindex != VM_INDEX_UNINITIALIZED, ""); | |
551 if (vmindex < 0) { | |
552 assert(result.is_statically_bound(), ""); | |
553 vmtarget = m(); | |
554 } else { | |
555 vmtarget = result.resolved_klass()->as_klassOop(); | |
556 } | |
557 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
|
558 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
|
559 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
|
560 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
|
561 DEBUG_ONLY(KlassHandle junk1; int junk2); |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
562 assert(decode_MemberName(mname(), junk1, junk2) == result.resolved_method(), |
710 | 563 "properly stored for later decoding"); |
564 return; | |
565 } | |
566 case IS_CONSTRUCTOR: | |
567 { | |
568 CallInfo result; | |
569 { | |
570 EXCEPTION_MARK; | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
571 if (name == vmSymbols::object_initializer_name()) { |
710 | 572 LinkResolver::resolve_special_call(result, |
573 defc, name, type, KlassHandle(), false, THREAD); | |
574 } else { | |
575 break; // will throw after end of switch | |
576 } | |
577 if (HAS_PENDING_EXCEPTION) { | |
578 CLEAR_PENDING_EXCEPTION; | |
579 return; | |
580 } | |
581 } | |
582 assert(result.is_statically_bound(), ""); | |
583 methodHandle m = result.resolved_method(); | |
584 oop vmtarget = m(); | |
585 int vmindex = methodOopDesc::nonvirtual_vtable_index; | |
586 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
|
587 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
|
588 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
|
589 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
|
590 DEBUG_ONLY(KlassHandle junk1; int junk2); |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
591 assert(decode_MemberName(mname(), junk1, junk2) == result.resolved_method(), |
710 | 592 "properly stored for later decoding"); |
593 return; | |
594 } | |
595 case IS_FIELD: | |
596 { | |
597 // This is taken from LinkResolver::resolve_field, sans access checks. | |
598 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
|
599 KlassHandle sel_klass(THREAD, instanceKlass::cast(defc())->find_field(name, type, &fd)); |
710 | 600 // check if field exists; i.e., if a klass containing the field def has been selected |
601 if (sel_klass.is_null()) return; | |
602 oop vmtarget = sel_klass->as_klassOop(); | |
603 int vmindex = fd.offset(); | |
604 int mods = (fd.access_flags().as_short() & JVM_RECOGNIZED_FIELD_MODIFIERS); | |
605 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
|
606 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
|
607 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
|
608 java_lang_invoke_MemberName::set_modifiers(mname(), mods); |
710 | 609 return; |
610 } | |
1508
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
611 default: |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
612 THROW_MSG(vmSymbols::java_lang_InternalError(), "unrecognized MemberName format"); |
710 | 613 } |
1508
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
614 |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
615 // Second chance. |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
616 if (polymorphic_method_type.not_null()) { |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
617 // 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
|
618 Handle cur_class_loader; |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
619 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
|
620 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
|
621 oop type_mirror; |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
622 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
|
623 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
|
624 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
|
625 if (example_type == NULL) continue; |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
626 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
|
627 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
|
628 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
|
629 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
|
630 type, |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
631 KlassHandle(THREAD, example_type), |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
632 THREAD); |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
633 if (HAS_PENDING_EXCEPTION) { |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
634 CLEAR_PENDING_EXCEPTION; |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
635 m = NULL; |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
636 // 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
|
637 } |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
638 if (m != NULL) { |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
639 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
|
640 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
|
641 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
|
642 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
|
643 return; |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
644 } |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
645 } |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
646 } |
710 | 647 } |
648 | |
649 // Conversely, a member name which is only initialized from JVM internals | |
650 // may have null defc, name, and type fields. | |
651 // Resolving it plants a vmtarget/vmindex in it, | |
652 // which refers directly to JVM internals. | |
653 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
|
654 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
|
655 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
|
656 int vmindex = java_lang_invoke_MemberName::vmindex(mname()); |
710 | 657 if (vmtarget == NULL || vmindex == VM_INDEX_UNINITIALIZED) { |
658 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "nothing to expand"); | |
659 } | |
660 | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
661 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
|
662 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
|
663 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
|
664 int flags = java_lang_invoke_MemberName::flags(mname()); |
710 | 665 |
666 if (suppress != 0) { | |
667 if (suppress & _suppress_defc) have_defc = true; | |
668 if (suppress & _suppress_name) have_name = true; | |
669 if (suppress & _suppress_type) have_type = true; | |
670 } | |
671 | |
672 if (have_defc && have_name && have_type) return; // nothing needed | |
673 | |
674 switch (flags & ALL_KINDS) { | |
675 case IS_METHOD: | |
676 case IS_CONSTRUCTOR: | |
677 { | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
678 KlassHandle receiver_limit; int decode_flags = 0; |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
679 methodHandle m = decode_vmtarget(vmtarget, vmindex, NULL, receiver_limit, decode_flags); |
710 | 680 if (m.is_null()) break; |
681 if (!have_defc) { | |
682 klassOop defc = m->method_holder(); | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
683 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
|
684 && 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
|
685 defc = receiver_limit(); |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
686 java_lang_invoke_MemberName::set_clazz(mname(), Klass::cast(defc)->java_mirror()); |
710 | 687 } |
688 if (!have_name) { | |
689 //not java_lang_String::create_from_symbol; let's intern member names | |
690 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
|
691 java_lang_invoke_MemberName::set_name(mname(), name()); |
710 | 692 } |
693 if (!have_type) { | |
694 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
|
695 java_lang_invoke_MemberName::set_type(mname(), type()); |
710 | 696 } |
697 return; | |
698 } | |
699 case IS_FIELD: | |
700 { | |
701 // This is taken from LinkResolver::resolve_field, sans access checks. | |
702 if (!vmtarget->is_klass()) break; | |
703 if (!Klass::cast((klassOop) vmtarget)->oop_is_instance()) break; | |
704 instanceKlassHandle defc(THREAD, (klassOop) vmtarget); | |
705 bool is_static = ((flags & JVM_ACC_STATIC) != 0); | |
706 fieldDescriptor fd; // find_field initializes fd if found | |
707 if (!defc->find_field_from_offset(vmindex, is_static, &fd)) | |
708 break; // cannot expand | |
709 if (!have_defc) { | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
710 java_lang_invoke_MemberName::set_clazz(mname(), defc->java_mirror()); |
710 | 711 } |
712 if (!have_name) { | |
713 //not java_lang_String::create_from_symbol; let's intern member names | |
714 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
|
715 java_lang_invoke_MemberName::set_name(mname(), name()); |
710 | 716 } |
717 if (!have_type) { | |
718 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
|
719 java_lang_invoke_MemberName::set_type(mname(), type()); |
710 | 720 } |
721 return; | |
722 } | |
723 } | |
724 THROW_MSG(vmSymbols::java_lang_InternalError(), "unrecognized MemberName format"); | |
725 } | |
726 | |
727 int MethodHandles::find_MemberNames(klassOop k, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
728 Symbol* name, Symbol* sig, |
710 | 729 int mflags, klassOop caller, |
730 int skip, objArrayOop results) { | |
731 DEBUG_ONLY(No_Safepoint_Verifier nsv); | |
732 // this code contains no safepoints! | |
733 | |
734 // %%% take caller into account! | |
735 | |
736 if (k == NULL || !Klass::cast(k)->oop_is_instance()) return -1; | |
737 | |
738 int rfill = 0, rlimit = results->length(), rskip = skip; | |
739 // overflow measurement: | |
740 int overflow = 0, overflow_limit = MAX2(1000, rlimit); | |
741 | |
742 int match_flags = mflags; | |
743 bool search_superc = ((match_flags & SEARCH_SUPERCLASSES) != 0); | |
744 bool search_intfc = ((match_flags & SEARCH_INTERFACES) != 0); | |
745 bool local_only = !(search_superc | search_intfc); | |
746 bool classes_only = false; | |
747 | |
748 if (name != NULL) { | |
749 if (name->utf8_length() == 0) return 0; // a match is not possible | |
750 } | |
751 if (sig != NULL) { | |
752 if (sig->utf8_length() == 0) return 0; // a match is not possible | |
753 if (sig->byte_at(0) == '(') | |
754 match_flags &= ~(IS_FIELD | IS_TYPE); | |
755 else | |
756 match_flags &= ~(IS_CONSTRUCTOR | IS_METHOD); | |
757 } | |
758 | |
759 if ((match_flags & IS_TYPE) != 0) { | |
760 // NYI, and Core Reflection works quite well for this query | |
761 } | |
762 | |
763 if ((match_flags & IS_FIELD) != 0) { | |
764 for (FieldStream st(k, local_only, !search_intfc); !st.eos(); st.next()) { | |
765 if (name != NULL && st.name() != name) | |
766 continue; | |
767 if (sig != NULL && st.signature() != sig) | |
768 continue; | |
769 // passed the filters | |
770 if (rskip > 0) { | |
771 --rskip; | |
772 } else if (rfill < rlimit) { | |
773 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
|
774 if (!java_lang_invoke_MemberName::is_instance(result)) |
710 | 775 return -99; // caller bug! |
776 MethodHandles::init_MemberName(result, st.klass()->as_klassOop(), st.access_flags(), st.offset()); | |
777 } else if (++overflow >= overflow_limit) { | |
778 match_flags = 0; break; // got tired of looking at overflow | |
779 } | |
780 } | |
781 } | |
782 | |
783 if ((match_flags & (IS_METHOD | IS_CONSTRUCTOR)) != 0) { | |
784 // watch out for these guys: | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
785 Symbol* init_name = vmSymbols::object_initializer_name(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
786 Symbol* clinit_name = vmSymbols::class_initializer_name(); |
710 | 787 if (name == clinit_name) clinit_name = NULL; // hack for exposing <clinit> |
788 bool negate_name_test = false; | |
789 // fix name so that it captures the intention of IS_CONSTRUCTOR | |
790 if (!(match_flags & IS_METHOD)) { | |
791 // constructors only | |
792 if (name == NULL) { | |
793 name = init_name; | |
794 } else if (name != init_name) { | |
795 return 0; // no constructors of this method name | |
796 } | |
797 } else if (!(match_flags & IS_CONSTRUCTOR)) { | |
798 // methods only | |
799 if (name == NULL) { | |
800 name = init_name; | |
801 negate_name_test = true; // if we see the name, we *omit* the entry | |
802 } else if (name == init_name) { | |
803 return 0; // no methods of this constructor name | |
804 } | |
805 } else { | |
806 // caller will accept either sort; no need to adjust name | |
807 } | |
808 for (MethodStream st(k, local_only, !search_intfc); !st.eos(); st.next()) { | |
809 methodOop m = st.method(); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
810 Symbol* m_name = m->name(); |
710 | 811 if (m_name == clinit_name) |
812 continue; | |
813 if (name != NULL && ((m_name != name) ^ negate_name_test)) | |
814 continue; | |
815 if (sig != NULL && m->signature() != sig) | |
816 continue; | |
817 // passed the filters | |
818 if (rskip > 0) { | |
819 --rskip; | |
820 } else if (rfill < rlimit) { | |
821 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
|
822 if (!java_lang_invoke_MemberName::is_instance(result)) |
710 | 823 return -99; // caller bug! |
824 MethodHandles::init_MemberName(result, m, true); | |
825 } else if (++overflow >= overflow_limit) { | |
826 match_flags = 0; break; // got tired of looking at overflow | |
827 } | |
828 } | |
829 } | |
830 | |
831 // return number of elements we at leasted wanted to initialize | |
832 return rfill + overflow; | |
833 } | |
834 | |
835 | |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
836 // 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
|
837 // Throw IAE if not |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
838 instanceKlassHandle MethodHandles::resolve_instance_klass(oop java_mirror_oop, TRAPS) { |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
839 instanceKlassHandle empty; |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
840 klassOop caller = NULL; |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
841 if (java_lang_Class::is_instance(java_mirror_oop)) { |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
842 caller = java_lang_Class::as_klassOop(java_mirror_oop); |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
843 } |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
844 if (caller == NULL || !Klass::cast(caller)->oop_is_instance()) { |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
845 THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), "not a class", empty); |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
846 } |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
847 return instanceKlassHandle(THREAD, caller); |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
848 } |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
849 |
710 | 850 |
851 | |
852 // Decode the vmtarget field of a method handle. | |
853 // Sanitize out methodOops, klassOops, and any other non-Java data. | |
854 // This is for debugging and reflection. | |
855 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
|
856 assert(java_lang_invoke_MethodHandle::is_instance(mh()), "must be a MH"); |
710 | 857 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
|
858 oop target = java_lang_invoke_MethodHandle::vmtarget(mh()); |
710 | 859 if (target == NULL) { |
860 return NULL; // unformed MH | |
861 } | |
862 klassOop tklass = target->klass(); | |
1142 | 863 if (Klass::cast(tklass)->is_subclass_of(SystemDictionary::Object_klass())) { |
710 | 864 return target; // target is another MH (or something else?) |
865 } | |
866 } | |
867 if (format == ETF_DIRECT_HANDLE) { | |
868 oop target = mh(); | |
869 for (;;) { | |
870 if (target->klass() == SystemDictionary::DirectMethodHandle_klass()) { | |
871 return target; | |
872 } | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
873 if (!java_lang_invoke_MethodHandle::is_instance(target)){ |
710 | 874 return NULL; // unformed MH |
875 } | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
876 target = java_lang_invoke_MethodHandle::vmtarget(target); |
710 | 877 } |
878 } | |
879 // cases of metadata in MH.vmtarget: | |
880 // - AMH can have methodOop for static invoke with bound receiver | |
881 // - DMH can have methodOop for static invoke (on variable receiver) | |
882 // - 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
|
883 KlassHandle receiver_limit; int decode_flags = 0; |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
884 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
|
885 if (m.is_null()) return NULL; |
710 | 886 switch (format) { |
887 case ETF_REFLECT_METHOD: | |
888 // same as jni_ToReflectedMethod: | |
889 if (m->is_initializer()) { | |
890 return Reflection::new_constructor(m, THREAD); | |
891 } else { | |
892 return Reflection::new_method(m, UseNewReflection, false, THREAD); | |
893 } | |
894 | |
895 case ETF_HANDLE_OR_METHOD_NAME: // method, not handle | |
896 case ETF_METHOD_NAME: | |
897 { | |
898 if (SystemDictionary::MemberName_klass() == NULL) break; | |
899 instanceKlassHandle mname_klass(THREAD, SystemDictionary::MemberName_klass()); | |
900 mname_klass->initialize(CHECK_NULL); | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
901 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
|
902 java_lang_invoke_MemberName::set_vmindex(mname(), VM_INDEX_UNINITIALIZED); |
710 | 903 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
|
904 init_MemberName(mname(), m(), do_dispatch); |
710 | 905 expand_MemberName(mname, 0, CHECK_NULL); |
906 return mname(); | |
907 } | |
908 } | |
909 | |
910 // Unknown format code. | |
911 char msg[50]; | |
912 jio_snprintf(msg, sizeof(msg), "unknown getTarget format=%d", format); | |
913 THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), msg); | |
914 } | |
915 | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
916 static const char* always_null_names[] = { |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
917 "java/lang/Void", |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
918 "java/lang/Null", |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
919 //"java/lang/Nothing", |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
920 "sun/dyn/empty/Empty", |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
921 "sun/invoke/empty/Empty", |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
922 NULL |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
923 }; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
924 |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
925 static bool is_always_null_type(klassOop klass) { |
2478
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
926 if (klass == NULL) return false; // safety |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
927 if (!Klass::cast(klass)->oop_is_instance()) return false; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
928 instanceKlass* ik = instanceKlass::cast(klass); |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
929 // Must be on the boot class path: |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
930 if (ik->class_loader() != NULL) return false; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
931 // Check the name. |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
932 Symbol* name = ik->name(); |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
933 for (int i = 0; ; i++) { |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
934 const char* test_name = always_null_names[i]; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
935 if (test_name == NULL) break; |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
936 if (name->equals(test_name)) |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
937 return true; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
938 } |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
939 return false; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
940 } |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
941 |
710 | 942 bool MethodHandles::class_cast_needed(klassOop src, klassOop dst) { |
2478
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
943 if (dst == NULL) return true; |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
944 if (src == NULL) return (dst != SystemDictionary::Object_klass()); |
1142 | 945 if (src == dst || dst == SystemDictionary::Object_klass()) |
710 | 946 return false; // quickest checks |
947 Klass* srck = Klass::cast(src); | |
948 Klass* dstk = Klass::cast(dst); | |
949 if (dstk->is_interface()) { | |
950 // interface receivers can safely be viewed as untyped, | |
951 // because interface calls always include a dynamic check | |
1142 | 952 //dstk = Klass::cast(SystemDictionary::Object_klass()); |
710 | 953 return false; |
954 } | |
955 if (srck->is_interface()) { | |
956 // interface arguments must be viewed as untyped | |
1142 | 957 //srck = Klass::cast(SystemDictionary::Object_klass()); |
710 | 958 return true; |
959 } | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
960 if (is_always_null_type(src)) { |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
961 // some source types are known to be never instantiated; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
962 // they represent references which are always null |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
963 // such null references never fail to convert safely |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
964 return false; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
965 } |
710 | 966 return !srck->is_subclass_of(dstk->as_klassOop()); |
967 } | |
968 | |
969 static oop object_java_mirror() { | |
1142 | 970 return Klass::cast(SystemDictionary::Object_klass())->java_mirror(); |
710 | 971 } |
972 | |
973 bool MethodHandles::same_basic_type_for_arguments(BasicType src, | |
974 BasicType dst, | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
975 bool raw, |
710 | 976 bool for_return) { |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
977 if (for_return) { |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
978 // return values can always be forgotten: |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
979 if (dst == T_VOID) return true; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
980 if (src == T_VOID) return raw && (dst == T_INT); |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
981 // 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
|
982 // 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
|
983 } |
710 | 984 assert(src != T_VOID && dst != T_VOID, "should not be here"); |
985 if (src == dst) return true; | |
986 if (type2size[src] != type2size[dst]) return false; | |
1912
8213b0f5c92d
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
1849
diff
changeset
|
987 if (src == T_OBJECT || dst == T_OBJECT) return false; |
8213b0f5c92d
6981777: implement JSR 292 EG adjustments from summer 2010
jrose
parents:
1849
diff
changeset
|
988 if (raw) return true; // bitwise reinterpretation; caller guarantees safety |
710 | 989 // allow reinterpretation casts for integral widening |
990 if (is_subword_type(src)) { // subwords can fit in int or other subwords | |
991 if (dst == T_INT) // any subword fits in an int | |
992 return true; | |
993 if (src == T_BOOLEAN) // boolean fits in any subword | |
994 return is_subword_type(dst); | |
995 if (src == T_BYTE && dst == T_SHORT) | |
996 return true; // remaining case: byte fits in short | |
997 } | |
998 // allow float/fixed reinterpretation casts | |
999 if (src == T_FLOAT) return dst == T_INT; | |
1000 if (src == T_INT) return dst == T_FLOAT; | |
1001 if (src == T_DOUBLE) return dst == T_LONG; | |
1002 if (src == T_LONG) return dst == T_DOUBLE; | |
1003 return false; | |
1004 } | |
1005 | |
1006 const char* MethodHandles::check_method_receiver(methodOop m, | |
1007 klassOop passed_recv_type) { | |
1008 assert(!m->is_static(), "caller resp."); | |
1009 if (passed_recv_type == NULL) | |
1010 return "receiver type is primitive"; | |
1011 if (class_cast_needed(passed_recv_type, m->method_holder())) { | |
1012 Klass* formal = Klass::cast(m->method_holder()); | |
1013 return SharedRuntime::generate_class_cast_message("receiver type", | |
1014 formal->external_name()); | |
1015 } | |
1016 return NULL; // checks passed | |
1017 } | |
1018 | |
1019 // Verify that m's signature can be called type-safely by a method handle | |
1020 // of the given method type 'mtype'. | |
1021 // It takes a TRAPS argument because it must perform symbol lookups. | |
1022 void MethodHandles::verify_method_signature(methodHandle m, | |
1023 Handle mtype, | |
1024 int first_ptype_pos, | |
1025 KlassHandle insert_ptype, | |
1026 TRAPS) { | |
2478
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1027 Handle mhi_type; |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1028 if (m->is_method_handle_invoke()) { |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1029 // use this more exact typing instead of the symbolic signature: |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1030 mhi_type = Handle(THREAD, m->method_handle_type()); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1031 } |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1032 objArrayHandle ptypes(THREAD, java_lang_invoke_MethodType::ptypes(mtype())); |
710 | 1033 int pnum = first_ptype_pos; |
1034 int pmax = ptypes->length(); | |
2478
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1035 int anum = 0; // method argument |
710 | 1036 const char* err = NULL; |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
1037 ResourceMark rm(THREAD); |
710 | 1038 for (SignatureStream ss(m->signature()); !ss.is_done(); ss.next()) { |
1039 oop ptype_oop = NULL; | |
1040 if (ss.at_return_type()) { | |
1041 if (pnum != pmax) | |
1042 { err = "too many arguments"; break; } | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1043 ptype_oop = java_lang_invoke_MethodType::rtype(mtype()); |
710 | 1044 } else { |
1045 if (pnum >= pmax) | |
1046 { err = "not enough arguments"; break; } | |
1047 if (pnum >= 0) | |
1048 ptype_oop = ptypes->obj_at(pnum); | |
1049 else if (insert_ptype.is_null()) | |
1050 ptype_oop = NULL; | |
1051 else | |
1052 ptype_oop = insert_ptype->java_mirror(); | |
1053 pnum += 1; | |
2478
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1054 anum += 1; |
710 | 1055 } |
2478
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1056 KlassHandle pklass; |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1057 BasicType ptype = T_OBJECT; |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1058 bool have_ptype = false; |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1059 // 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
|
1060 pklass = SystemDictionaryHandles::Object_klass(); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1061 if (ptype_oop != NULL) { |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1062 have_ptype = true; |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1063 klassOop pklass_oop = NULL; |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1064 ptype = java_lang_Class::as_BasicType(ptype_oop, &pklass_oop); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1065 pklass = KlassHandle(THREAD, pklass_oop); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1066 } |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1067 ptype_oop = NULL; //done with this |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1068 KlassHandle aklass; |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1069 BasicType atype = ss.type(); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1070 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
|
1071 if (atype == T_OBJECT) { |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1072 if (!have_ptype) { |
710 | 1073 // null matches any reference |
1074 continue; | |
1075 } | |
2478
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1076 if (mhi_type.is_null()) { |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1077 // 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
|
1078 TempNewSymbol name = ss.as_symbol_or_null(); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1079 if (name != NULL) { |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1080 instanceKlass* mk = instanceKlass::cast(m->method_holder()); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1081 Handle loader(THREAD, mk->class_loader()); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1082 Handle domain(THREAD, mk->protection_domain()); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1083 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
|
1084 if (aklass_oop != NULL) |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1085 aklass = KlassHandle(THREAD, aklass_oop); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1086 } |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1087 } else { |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1088 // 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
|
1089 oop atype_oop; |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1090 if (ss.at_return_type()) |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1091 atype_oop = java_lang_invoke_MethodType::rtype(mhi_type()); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1092 else |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1093 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
|
1094 klassOop aklass_oop = NULL; |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1095 atype = java_lang_Class::as_BasicType(atype_oop, &aklass_oop); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1096 aklass = KlassHandle(THREAD, aklass_oop); |
1508
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1507
diff
changeset
|
1097 } |
710 | 1098 } |
1099 if (!ss.at_return_type()) { | |
2478
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1100 err = check_argument_type_change(ptype, pklass(), atype, aklass(), anum); |
710 | 1101 } else { |
2478
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1102 err = check_return_type_change(atype, aklass(), ptype, pklass()); // note reversal! |
710 | 1103 } |
1104 if (err != NULL) break; | |
1105 } | |
1106 | |
1107 if (err != NULL) { | |
2478
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1108 #ifndef PRODUCT |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1109 if (PrintMiscellaneous && (Verbose || WizardMode)) { |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1110 tty->print("*** verify_method_signature failed: "); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1111 java_lang_invoke_MethodType::print_signature(mtype(), tty); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1112 tty->cr(); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1113 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
|
1114 tty->print(" Failing method: "); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1115 m->print(); |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1116 } |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1117 #endif //PRODUCT |
710 | 1118 THROW_MSG(vmSymbols::java_lang_InternalError(), err); |
1119 } | |
1120 } | |
1121 | |
1122 // Main routine for verifying the MethodHandle.type of a proposed | |
1123 // direct or bound-direct method handle. | |
1124 void MethodHandles::verify_method_type(methodHandle m, | |
1125 Handle mtype, | |
1126 bool has_bound_recv, | |
1127 KlassHandle bound_recv_type, | |
1128 TRAPS) { | |
1129 bool m_needs_receiver = !m->is_static(); | |
1130 | |
1131 const char* err = NULL; | |
1132 | |
1133 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
|
1134 if (has_bound_recv) { |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1135 first_ptype_pos -= 1; // ptypes do not include the bound argument; start earlier in them |
710 | 1136 if (m_needs_receiver && bound_recv_type.is_null()) |
1137 { err = "bound receiver is not an object"; goto die; } | |
1138 } | |
1139 | |
1140 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
|
1141 objArrayOop ptypes = java_lang_invoke_MethodType::ptypes(mtype()); |
710 | 1142 if (ptypes->length() < first_ptype_pos) |
1143 { err = "receiver argument is missing"; goto die; } | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1144 if (has_bound_recv) |
710 | 1145 err = check_method_receiver(m(), bound_recv_type->as_klassOop()); |
1146 else | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1147 err = check_method_receiver(m(), java_lang_Class::as_klassOop(ptypes->obj_at(first_ptype_pos-1))); |
710 | 1148 if (err != NULL) goto die; |
1149 } | |
1150 | |
1151 // Check the other arguments for mistypes. | |
1152 verify_method_signature(m, mtype, first_ptype_pos, bound_recv_type, CHECK); | |
1153 return; | |
1154 | |
1155 die: | |
1156 THROW_MSG(vmSymbols::java_lang_InternalError(), err); | |
1157 } | |
1158 | |
1159 void MethodHandles::verify_vmslots(Handle mh, TRAPS) { | |
1160 // Verify vmslots. | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1161 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
|
1162 if (java_lang_invoke_MethodHandle::vmslots(mh()) != check_slots) { |
710 | 1163 THROW_MSG(vmSymbols::java_lang_InternalError(), "bad vmslots in BMH"); |
1164 } | |
1165 } | |
1166 | |
1167 void MethodHandles::verify_vmargslot(Handle mh, int argnum, int argslot, TRAPS) { | |
1168 // 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
|
1169 int check_slot = argument_slot(java_lang_invoke_MethodHandle::type(mh()), argnum); |
710 | 1170 if (argslot != check_slot || argslot < 0) { |
1171 const char* fmt = "for argnum of %d, vmargslot is %d, should be %d"; | |
1172 size_t msglen = strlen(fmt) + 3*11 + 1; | |
1173 char* msg = NEW_RESOURCE_ARRAY(char, msglen); | |
1174 jio_snprintf(msg, msglen, fmt, argnum, argslot, check_slot); | |
1175 THROW_MSG(vmSymbols::java_lang_InternalError(), msg); | |
1176 } | |
1177 } | |
1178 | |
1179 // Verify the correspondence between two method types. | |
1180 // Apart from the advertised changes, caller method type X must | |
1181 // be able to invoke the callee method Y type with no violations | |
1182 // of type integrity. | |
1183 // Return NULL if all is well, else a short error message. | |
1184 const char* MethodHandles::check_method_type_change(oop src_mtype, int src_beg, int src_end, | |
1185 int insert_argnum, oop insert_type, | |
1186 int change_argnum, oop change_type, | |
1187 int delete_argnum, | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1188 oop dst_mtype, int dst_beg, int dst_end, |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1189 bool raw) { |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1190 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
|
1191 objArrayOop dst_ptypes = java_lang_invoke_MethodType::ptypes(dst_mtype); |
710 | 1192 |
1193 int src_max = src_ptypes->length(); | |
1194 int dst_max = dst_ptypes->length(); | |
1195 | |
1196 if (src_end == -1) src_end = src_max; | |
1197 if (dst_end == -1) dst_end = dst_max; | |
1198 | |
1199 assert(0 <= src_beg && src_beg <= src_end && src_end <= src_max, "oob"); | |
1200 assert(0 <= dst_beg && dst_beg <= dst_end && dst_end <= dst_max, "oob"); | |
1201 | |
1202 // pending actions; set to -1 when done: | |
1203 int ins_idx = insert_argnum, chg_idx = change_argnum, del_idx = delete_argnum; | |
1204 | |
1205 const char* err = NULL; | |
1206 | |
1207 // Walk along each array of parameter types, including a virtual | |
1208 // NULL end marker at the end of each. | |
1209 for (int src_idx = src_beg, dst_idx = dst_beg; | |
1210 (src_idx <= src_end && dst_idx <= dst_end); | |
1211 src_idx++, dst_idx++) { | |
1212 oop src_type = (src_idx == src_end) ? oop(NULL) : src_ptypes->obj_at(src_idx); | |
1213 oop dst_type = (dst_idx == dst_end) ? oop(NULL) : dst_ptypes->obj_at(dst_idx); | |
1214 bool fix_null_src_type = false; | |
1215 | |
1216 // Perform requested edits. | |
1217 if (ins_idx == src_idx) { | |
1218 // note that the inserted guy is never affected by a change or deletion | |
1219 ins_idx = -1; | |
1220 src_type = insert_type; | |
1221 fix_null_src_type = true; | |
1222 --src_idx; // back up to process src type on next loop | |
1223 src_idx = src_end; | |
1224 } else { | |
1225 // note that the changed guy can be immediately deleted | |
1226 if (chg_idx == src_idx) { | |
1227 chg_idx = -1; | |
1228 assert(src_idx < src_end, "oob"); | |
1229 src_type = change_type; | |
1230 fix_null_src_type = true; | |
1231 } | |
1232 if (del_idx == src_idx) { | |
1233 del_idx = -1; | |
1234 assert(src_idx < src_end, "oob"); | |
1235 --dst_idx; | |
1236 continue; // rerun loop after skipping this position | |
1237 } | |
1238 } | |
1239 | |
1240 if (src_type == NULL && fix_null_src_type) | |
1241 // explicit null in this case matches any dest reference | |
1242 src_type = (java_lang_Class::is_primitive(dst_type) ? object_java_mirror() : dst_type); | |
1243 | |
1244 // Compare the two argument types. | |
1245 if (src_type != dst_type) { | |
1246 if (src_type == NULL) return "not enough arguments"; | |
1247 if (dst_type == NULL) return "too many arguments"; | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1248 err = check_argument_type_change(src_type, dst_type, dst_idx, raw); |
710 | 1249 if (err != NULL) return err; |
1250 } | |
1251 } | |
1252 | |
1253 // Now compare return types also. | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1254 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
|
1255 oop dst_rtype = java_lang_invoke_MethodType::rtype(dst_mtype); |
710 | 1256 if (src_rtype != dst_rtype) { |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1257 err = check_return_type_change(dst_rtype, src_rtype, raw); // note reversal! |
710 | 1258 if (err != NULL) return err; |
1259 } | |
1260 | |
1261 assert(err == NULL, ""); | |
1262 return NULL; // all is well | |
1263 } | |
1264 | |
1265 | |
1266 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
|
1267 klassOop src_klass, |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1268 BasicType dst_type, |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1269 klassOop dst_klass, |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1270 int argnum, |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1271 bool raw) { |
710 | 1272 const char* err = NULL; |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1273 bool for_return = (argnum < 0); |
710 | 1274 |
1275 // just in case: | |
1276 if (src_type == T_ARRAY) src_type = T_OBJECT; | |
1277 if (dst_type == T_ARRAY) dst_type = T_OBJECT; | |
1278 | |
1279 // 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
|
1280 if (!same_basic_type_for_arguments(src_type, dst_type, raw, for_return)) { |
710 | 1281 if (src_type == T_OBJECT) { |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1282 if (raw && dst_type == T_INT && is_always_null_type(src_klass)) |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1283 return NULL; // OK to convert a null pointer to a garbage int |
710 | 1284 err = ((argnum >= 0) |
1285 ? "type mismatch: passing a %s for method argument #%d, which expects primitive %s" | |
1286 : "type mismatch: returning a %s, but caller expects primitive %s"); | |
1287 } else if (dst_type == T_OBJECT) { | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1288 err = ((argnum >= 0) |
710 | 1289 ? "type mismatch: passing a primitive %s for method argument #%d, which expects %s" |
1290 : "type mismatch: returning a primitive %s, but caller expects %s"); | |
1291 } else { | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1292 err = ((argnum >= 0) |
710 | 1293 ? "type mismatch: passing a %s for method argument #%d, which expects %s" |
1294 : "type mismatch: returning a %s, but caller expects %s"); | |
1295 } | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1296 } 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
|
1297 class_cast_needed(src_klass, dst_klass)) { |
710 | 1298 if (!class_cast_needed(dst_klass, src_klass)) { |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1299 if (raw) |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1300 return NULL; // reverse cast is OK; the MH target is trusted to enforce it |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1301 err = ((argnum >= 0) |
710 | 1302 ? "cast required: passing a %s for method argument #%d, which expects %s" |
1303 : "cast required: returning a %s, but caller expects %s"); | |
1304 } else { | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1305 err = ((argnum >= 0) |
710 | 1306 ? "reference mismatch: passing a %s for method argument #%d, which expects %s" |
1307 : "reference mismatch: returning a %s, but caller expects %s"); | |
1308 } | |
1309 } else { | |
1310 // passed the obstacle course | |
1311 return NULL; | |
1312 } | |
1313 | |
1314 // format, format, format | |
1315 const char* src_name = type2name(src_type); | |
1316 const char* dst_name = type2name(dst_type); | |
1317 if (src_name == NULL) src_name = "unknown type"; | |
1318 if (dst_name == NULL) dst_name = "unknown type"; | |
2478
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1319 if (src_type == T_OBJECT) |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1320 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
|
1321 if (dst_type == T_OBJECT) |
328926869b15
6987991: JSR 292 phpreboot test/testtracefun2.phpr segfaults
jrose
parents:
2460
diff
changeset
|
1322 dst_name = (dst_klass != NULL) ? Klass::cast(dst_klass)->external_name() : "an unresolved class"; |
710 | 1323 |
1324 size_t msglen = strlen(err) + strlen(src_name) + strlen(dst_name) + (argnum < 10 ? 1 : 11); | |
1325 char* msg = NEW_RESOURCE_ARRAY(char, msglen + 1); | |
1326 if (argnum >= 0) { | |
1327 assert(strstr(err, "%d") != NULL, ""); | |
1328 jio_snprintf(msg, msglen, err, src_name, argnum, dst_name); | |
1329 } else { | |
1330 assert(strstr(err, "%d") == NULL, ""); | |
1331 jio_snprintf(msg, msglen, err, src_name, dst_name); | |
1332 } | |
1333 return msg; | |
1334 } | |
1335 | |
1336 // Compute the depth within the stack of the given argument, i.e., | |
1337 // the combined size of arguments to the right of the given argument. | |
1338 // For the last argument (ptypes.length-1) this will be zero. | |
1339 // For the first argument (0) this will be the size of all | |
1340 // arguments but that one. For the special number -1, this | |
1341 // will be the size of all arguments, including the first. | |
1342 // If the argument is neither -1 nor a valid argument index, | |
1343 // then return a negative number. Otherwise, the result | |
1344 // is in the range [0..vmslots] inclusive. | |
1345 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
|
1346 objArrayOop ptypes = java_lang_invoke_MethodType::ptypes(method_type); |
710 | 1347 int argslot = 0; |
1348 int len = ptypes->length(); | |
1349 if (arg < -1 || arg >= len) return -99; | |
1350 for (int i = len-1; i > arg; i--) { | |
1351 BasicType bt = java_lang_Class::as_BasicType(ptypes->obj_at(i)); | |
1352 argslot += type2size[bt]; | |
1353 } | |
1354 assert(argument_slot_to_argnum(method_type, argslot) == arg, "inverse works"); | |
1355 return argslot; | |
1356 } | |
1357 | |
1358 // Given a slot number, return the argument number. | |
1359 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
|
1360 objArrayOop ptypes = java_lang_invoke_MethodType::ptypes(method_type); |
710 | 1361 int argslot = 0; |
1362 int len = ptypes->length(); | |
1363 for (int i = len-1; i >= 0; i--) { | |
1364 if (query_argslot == argslot) return i; | |
1365 BasicType bt = java_lang_Class::as_BasicType(ptypes->obj_at(i)); | |
1366 argslot += type2size[bt]; | |
1367 } | |
1368 // return pseudo-arg deepest in stack: | |
1369 if (query_argslot == argslot) return -1; | |
1370 return -99; // oob slot, or splitting a double-slot arg | |
1371 } | |
1372 | |
1373 methodHandle MethodHandles::dispatch_decoded_method(methodHandle m, | |
1374 KlassHandle receiver_limit, | |
1375 int decode_flags, | |
1376 KlassHandle receiver_klass, | |
1377 TRAPS) { | |
1378 assert((decode_flags & ~_DMF_DIRECT_MASK) == 0, "must be direct method reference"); | |
1379 assert((decode_flags & _dmf_has_receiver) != 0, "must have a receiver or first reference argument"); | |
1380 | |
1381 if (!m->is_static() && | |
1382 (receiver_klass.is_null() || !receiver_klass->is_subtype_of(m->method_holder()))) | |
1383 // given type does not match class of method, or receiver is null! | |
1384 // caller should have checked this, but let's be extra careful... | |
1385 return methodHandle(); | |
1386 | |
1387 if (receiver_limit.not_null() && | |
1388 (receiver_klass.not_null() && !receiver_klass->is_subtype_of(receiver_limit()))) | |
1389 // given type is not limited to the receiver type | |
1390 // note that a null receiver can match any reference value, for a static method | |
1391 return methodHandle(); | |
1392 | |
1393 if (!(decode_flags & MethodHandles::_dmf_does_dispatch)) { | |
1394 // pre-dispatched or static method (null receiver is OK for static) | |
1395 return m; | |
1396 | |
1397 } else if (receiver_klass.is_null()) { | |
1398 // null receiver value; cannot dispatch | |
1399 return methodHandle(); | |
1400 | |
1401 } else if (!(decode_flags & MethodHandles::_dmf_from_interface)) { | |
1402 // perform virtual dispatch | |
1403 int vtable_index = m->vtable_index(); | |
1404 guarantee(vtable_index >= 0, "valid vtable index"); | |
1405 | |
1406 // receiver_klass might be an arrayKlassOop but all vtables start at | |
1407 // the same place. The cast is to avoid virtual call and assertion. | |
1408 // See also LinkResolver::runtime_resolve_virtual_method. | |
1409 instanceKlass* inst = (instanceKlass*)Klass::cast(receiver_klass()); | |
1410 DEBUG_ONLY(inst->verify_vtable_index(vtable_index)); | |
1411 methodOop m_oop = inst->method_at_vtable(vtable_index); | |
1412 return methodHandle(THREAD, m_oop); | |
1413 | |
1414 } else { | |
1415 // perform interface dispatch | |
1416 int itable_index = klassItable::compute_itable_index(m()); | |
1417 guarantee(itable_index >= 0, "valid itable index"); | |
1418 instanceKlass* inst = instanceKlass::cast(receiver_klass()); | |
1419 methodOop m_oop = inst->method_at_itable(m->method_holder(), itable_index, THREAD); | |
1420 return methodHandle(THREAD, m_oop); | |
1421 } | |
1422 } | |
1423 | |
1424 void MethodHandles::verify_DirectMethodHandle(Handle mh, methodHandle m, TRAPS) { | |
1425 // Verify type. | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1426 Handle mtype(THREAD, java_lang_invoke_MethodHandle::type(mh())); |
710 | 1427 verify_method_type(m, mtype, false, KlassHandle(), CHECK); |
1428 | |
1429 // Verify vmslots. | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1430 if (java_lang_invoke_MethodHandle::vmslots(mh()) != m->size_of_parameters()) { |
710 | 1431 THROW_MSG(vmSymbols::java_lang_InternalError(), "bad vmslots in DMH"); |
1432 } | |
1433 } | |
1434 | |
1435 void MethodHandles::init_DirectMethodHandle(Handle mh, methodHandle m, bool do_dispatch, TRAPS) { | |
1436 // Check arguments. | |
1437 if (mh.is_null() || m.is_null() || | |
1438 (!do_dispatch && m->is_abstract())) { | |
1439 THROW(vmSymbols::java_lang_InternalError()); | |
1440 } | |
1441 | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1442 java_lang_invoke_MethodHandle::init_vmslots(mh()); |
710 | 1443 |
1444 if (VerifyMethodHandles) { | |
1445 // The privileged code which invokes this routine should not make | |
1446 // a mistake about types, but it's better to verify. | |
1447 verify_DirectMethodHandle(mh, m, CHECK); | |
1448 } | |
1449 | |
1450 // Finally, after safety checks are done, link to the target method. | |
1451 // We will follow the same path as the latter part of | |
1452 // InterpreterRuntime::resolve_invoke(), which first finds the method | |
1453 // and then decides how to populate the constant pool cache entry | |
1454 // that links the interpreter calls to the method. We need the same | |
1455 // bits, and will use the same calling sequence code. | |
1456 | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1457 int vmindex = methodOopDesc::garbage_vtable_index; |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1458 Handle vmtarget; |
710 | 1459 |
1460 instanceKlass::cast(m->method_holder())->link_class(CHECK); | |
1461 | |
1462 MethodHandleEntry* me = NULL; | |
1463 if (do_dispatch && Klass::cast(m->method_holder())->is_interface()) { | |
1464 // We are simulating an invokeinterface instruction. | |
1465 // (We might also be simulating an invokevirtual on a miranda method, | |
1466 // but it is safe to treat it as an invokeinterface.) | |
1467 assert(!m->can_be_statically_bound(), "no final methods on interfaces"); | |
1468 vmindex = klassItable::compute_itable_index(m()); | |
1469 assert(vmindex >= 0, "(>=0) == do_dispatch"); | |
1470 // Set up same bits as ConstantPoolCacheEntry::set_interface_call(). | |
1471 vmtarget = m->method_holder(); // the interface | |
1472 me = MethodHandles::entry(MethodHandles::_invokeinterface_mh); | |
1473 } else if (!do_dispatch || m->can_be_statically_bound()) { | |
1474 // We are simulating an invokestatic or invokespecial instruction. | |
1475 // 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
|
1476 vmtarget = m; |
710 | 1477 // this does not help dispatch, but it will make it possible to parse this MH: |
1478 vmindex = methodOopDesc::nonvirtual_vtable_index; | |
1479 assert(vmindex < 0, "(>=0) == do_dispatch"); | |
1480 if (!m->is_static()) { | |
1481 me = MethodHandles::entry(MethodHandles::_invokespecial_mh); | |
1482 } else { | |
1483 me = MethodHandles::entry(MethodHandles::_invokestatic_mh); | |
1484 // Part of the semantics of a static call is an initialization barrier. | |
1485 // For a DMH, it is done now, when the handle is created. | |
1486 Klass* k = Klass::cast(m->method_holder()); | |
1487 if (k->should_be_initialized()) { | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1488 k->initialize(CHECK); // possible safepoint |
710 | 1489 } |
1490 } | |
1491 } else { | |
1492 // We are simulating an invokevirtual instruction. | |
1493 // Set up the vtable index, just like ConstantPoolCacheEntry::set_method(). | |
1494 // The key logic is LinkResolver::runtime_resolve_virtual_method. | |
1495 vmindex = m->vtable_index(); | |
1496 vmtarget = m->method_holder(); | |
1497 me = MethodHandles::entry(MethodHandles::_invokevirtual_mh); | |
1498 } | |
1499 | |
1500 if (me == NULL) { THROW(vmSymbols::java_lang_InternalError()); } | |
1501 | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1502 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
|
1503 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
|
1504 DEBUG_ONLY(KlassHandle rlimit; int flags); |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1505 assert(MethodHandles::decode_method(mh(), rlimit, flags) == m, |
710 | 1506 "properly stored for later decoding"); |
1507 DEBUG_ONLY(bool actual_do_dispatch = ((flags & _dmf_does_dispatch) != 0)); | |
1508 assert(!(actual_do_dispatch && !do_dispatch), | |
1509 "do not perform dispatch if !do_dispatch specified"); | |
1510 assert(actual_do_dispatch == (vmindex >= 0), "proper later decoding of do_dispatch"); | |
1511 assert(decode_MethodHandle_stack_pushes(mh()) == 0, "DMH does not move stack"); | |
1512 | |
1513 // Done! | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1514 java_lang_invoke_MethodHandle::set_vmentry(mh(), me); |
710 | 1515 } |
1516 | |
1517 void MethodHandles::verify_BoundMethodHandle_with_receiver(Handle mh, | |
1518 methodHandle m, | |
1519 TRAPS) { | |
1520 // Verify type. | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1521 KlassHandle bound_recv_type; |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1522 { |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1523 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
|
1524 if (receiver != NULL) |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1525 bound_recv_type = KlassHandle(THREAD, receiver->klass()); |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1526 } |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1527 Handle mtype(THREAD, java_lang_invoke_MethodHandle::type(mh())); |
710 | 1528 verify_method_type(m, mtype, true, bound_recv_type, CHECK); |
1529 | |
1530 int receiver_pos = m->size_of_parameters() - 1; | |
1531 | |
1532 // 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
|
1533 verify_vmargslot(mh, -1, java_lang_invoke_BoundMethodHandle::vmargslot(mh()), CHECK); |
710 | 1534 //verify_vmslots(mh, CHECK); |
1535 | |
1536 // Verify vmslots. | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1537 if (java_lang_invoke_MethodHandle::vmslots(mh()) != receiver_pos) { |
710 | 1538 THROW_MSG(vmSymbols::java_lang_InternalError(), "bad vmslots in BMH (receiver)"); |
1539 } | |
1540 } | |
1541 | |
1542 // Initialize a BMH with a receiver bound directly to a methodOop. | |
1543 void MethodHandles::init_BoundMethodHandle_with_receiver(Handle mh, | |
1544 methodHandle original_m, | |
1545 KlassHandle receiver_limit, | |
1546 int decode_flags, | |
1547 TRAPS) { | |
1548 // Check arguments. | |
1549 if (mh.is_null() || original_m.is_null()) { | |
1550 THROW(vmSymbols::java_lang_InternalError()); | |
1551 } | |
1552 | |
1553 KlassHandle receiver_klass; | |
1554 { | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1555 oop receiver_oop = java_lang_invoke_BoundMethodHandle::argument(mh()); |
710 | 1556 if (receiver_oop != NULL) |
1557 receiver_klass = KlassHandle(THREAD, receiver_oop->klass()); | |
1558 } | |
1559 methodHandle m = dispatch_decoded_method(original_m, | |
1560 receiver_limit, decode_flags, | |
1561 receiver_klass, | |
1562 CHECK); | |
1563 if (m.is_null()) { THROW(vmSymbols::java_lang_InternalError()); } | |
1564 if (m->is_abstract()) { THROW(vmSymbols::java_lang_AbstractMethodError()); } | |
1565 | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1566 java_lang_invoke_MethodHandle::init_vmslots(mh()); |
710 | 1567 |
1568 if (VerifyMethodHandles) { | |
1569 verify_BoundMethodHandle_with_receiver(mh, m, CHECK); | |
1570 } | |
1571 | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1572 java_lang_invoke_BoundMethodHandle::set_vmtarget(mh(), m()); |
710 | 1573 |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1574 DEBUG_ONLY(KlassHandle junk1; int junk2); |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1575 assert(MethodHandles::decode_method(mh(), junk1, junk2) == m, "properly stored for later decoding"); |
710 | 1576 assert(decode_MethodHandle_stack_pushes(mh()) == 1, "BMH pushes one stack slot"); |
1577 | |
1578 // Done! | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1579 java_lang_invoke_MethodHandle::set_vmentry(mh(), MethodHandles::entry(MethodHandles::_bound_ref_direct_mh)); |
710 | 1580 } |
1581 | |
1582 void MethodHandles::verify_BoundMethodHandle(Handle mh, Handle target, int argnum, | |
1583 bool direct_to_method, TRAPS) { | |
1584 Handle ptype_handle(THREAD, | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1585 java_lang_invoke_MethodType::ptype(java_lang_invoke_MethodHandle::type(target()), argnum)); |
710 | 1586 KlassHandle ptype_klass; |
1587 BasicType ptype = java_lang_Class::as_BasicType(ptype_handle(), &ptype_klass); | |
1588 int slots_pushed = type2size[ptype]; | |
1589 | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1590 oop argument = java_lang_invoke_BoundMethodHandle::argument(mh()); |
710 | 1591 |
1592 const char* err = NULL; | |
1593 | |
1594 switch (ptype) { | |
1595 case T_OBJECT: | |
1596 if (argument != NULL) | |
1597 // we must implicitly convert from the arg type to the outgoing ptype | |
1598 err = check_argument_type_change(T_OBJECT, argument->klass(), ptype, ptype_klass(), argnum); | |
1599 break; | |
1600 | |
1601 case T_ARRAY: case T_VOID: | |
1602 assert(false, "array, void do not appear here"); | |
1603 default: | |
1604 if (ptype != T_INT && !is_subword_type(ptype)) { | |
1605 err = "unexpected parameter type"; | |
1606 break; | |
1607 } | |
1608 // check subrange of Integer.value, if necessary | |
1142 | 1609 if (argument == NULL || argument->klass() != SystemDictionary::Integer_klass()) { |
710 | 1610 err = "bound integer argument must be of type java.lang.Integer"; |
1611 break; | |
1612 } | |
1613 if (ptype != T_INT) { | |
1614 int value_offset = java_lang_boxing_object::value_offset_in_bytes(T_INT); | |
1615 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
|
1616 int vminfo = adapter_unbox_subword_vminfo(ptype); |
710 | 1617 jint subword = truncate_subword_from_vminfo(value, vminfo); |
1618 if (value != subword) { | |
1619 err = "bound subword value does not fit into the subword type"; | |
1620 break; | |
1621 } | |
1622 } | |
1623 break; | |
1624 case T_FLOAT: | |
1625 case T_DOUBLE: | |
1626 case T_LONG: | |
1627 { | |
1628 // we must implicitly convert from the unboxed arg type to the outgoing ptype | |
1629 BasicType argbox = java_lang_boxing_object::basic_type(argument); | |
1630 if (argbox != ptype) { | |
1631 err = check_argument_type_change(T_OBJECT, (argument == NULL | |
1142 | 1632 ? SystemDictionary::Object_klass() |
710 | 1633 : argument->klass()), |
1634 ptype, ptype_klass(), argnum); | |
1635 assert(err != NULL, "this must be an error"); | |
1636 } | |
1637 break; | |
1638 } | |
1639 } | |
1640 | |
1641 if (err == NULL) { | |
1642 DEBUG_ONLY(int this_pushes = decode_MethodHandle_stack_pushes(mh())); | |
1643 if (direct_to_method) { | |
1644 assert(this_pushes == slots_pushed, "BMH pushes one or two stack slots"); | |
1645 assert(slots_pushed <= MethodHandlePushLimit, ""); | |
1646 } else { | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1647 int target_pushes = decode_MethodHandle_stack_pushes(target()); |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1648 assert(this_pushes == slots_pushed + target_pushes, "BMH stack motion must be correct"); |
710 | 1649 // do not blow the stack; use a Java-based adapter if this limit is exceeded |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
1650 // FIXME |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
1651 // if (slots_pushed + target_pushes > MethodHandlePushLimit) |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
1652 // err = "too many bound parameters"; |
710 | 1653 } |
1654 } | |
1655 | |
1656 if (err == NULL) { | |
1657 // 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
|
1658 err = check_method_type_insertion(java_lang_invoke_MethodHandle::type(mh()), |
710 | 1659 argnum, ptype_handle(), |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1660 java_lang_invoke_MethodHandle::type(target())); |
710 | 1661 } |
1662 | |
1663 if (err != NULL) { | |
1664 THROW_MSG(vmSymbols::java_lang_InternalError(), err); | |
1665 } | |
1666 } | |
1667 | |
1668 void MethodHandles::init_BoundMethodHandle(Handle mh, Handle target, int argnum, TRAPS) { | |
1669 // Check arguments. | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1670 if (mh.is_null() || target.is_null() || !java_lang_invoke_MethodHandle::is_instance(target())) { |
710 | 1671 THROW(vmSymbols::java_lang_InternalError()); |
1672 } | |
1673 | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1674 java_lang_invoke_MethodHandle::init_vmslots(mh()); |
710 | 1675 |
1676 if (VerifyMethodHandles) { | |
1677 int insert_after = argnum - 1; | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1678 verify_vmargslot(mh, insert_after, java_lang_invoke_BoundMethodHandle::vmargslot(mh()), CHECK); |
710 | 1679 verify_vmslots(mh, CHECK); |
1680 } | |
1681 | |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
1682 // Get bound type and required slots. |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1683 BasicType ptype; |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1684 { |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1685 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
|
1686 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
|
1687 } |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
1688 int slots_pushed = type2size[ptype]; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
1689 |
710 | 1690 // If (a) the target is a direct non-dispatched method handle, |
1691 // or (b) the target is a dispatched direct method handle and we | |
1692 // are binding the receiver, cut out the middle-man. | |
1693 // Do this by decoding the DMH and using its methodOop directly as vmtarget. | |
1694 bool direct_to_method = false; | |
1695 if (OptimizeMethodHandles && | |
1696 target->klass() == SystemDictionary::DirectMethodHandle_klass() && | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1697 (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
|
1698 KlassHandle receiver_limit; int decode_flags = 0; |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
1699 methodHandle m = decode_method(target(), receiver_limit, decode_flags); |
710 | 1700 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
|
1701 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
|
1702 assert(java_lang_invoke_BoundMethodHandle::vmslots(mh()) == m_vmslots, "type w/ m sig"); |
710 | 1703 if (argnum == 0 && (decode_flags & _dmf_has_receiver) != 0) { |
1704 init_BoundMethodHandle_with_receiver(mh, m, | |
1705 receiver_limit, decode_flags, | |
1706 CHECK); | |
1707 return; | |
1708 } | |
1709 | |
1710 // Even if it is not a bound receiver, we still might be able | |
1711 // to bind another argument and still invoke the methodOop directly. | |
1712 if (!(decode_flags & _dmf_does_dispatch)) { | |
1713 direct_to_method = true; | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1714 java_lang_invoke_BoundMethodHandle::set_vmtarget(mh(), m()); |
710 | 1715 } |
1716 } | |
1717 if (!direct_to_method) | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1718 java_lang_invoke_BoundMethodHandle::set_vmtarget(mh(), target()); |
710 | 1719 |
1720 if (VerifyMethodHandles) { | |
1721 verify_BoundMethodHandle(mh, target, argnum, direct_to_method, CHECK); | |
1722 } | |
1723 | |
1724 // Next question: Is this a ref, int, or long bound value? | |
1725 MethodHandleEntry* me = NULL; | |
1726 if (ptype == T_OBJECT) { | |
1727 if (direct_to_method) me = MethodHandles::entry(_bound_ref_direct_mh); | |
1728 else me = MethodHandles::entry(_bound_ref_mh); | |
1729 } else if (slots_pushed == 2) { | |
1730 if (direct_to_method) me = MethodHandles::entry(_bound_long_direct_mh); | |
1731 else me = MethodHandles::entry(_bound_long_mh); | |
1732 } else if (slots_pushed == 1) { | |
1733 if (direct_to_method) me = MethodHandles::entry(_bound_int_direct_mh); | |
1734 else me = MethodHandles::entry(_bound_int_mh); | |
1735 } else { | |
1736 assert(false, ""); | |
1737 } | |
1738 | |
1739 // Done! | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1740 java_lang_invoke_MethodHandle::set_vmentry(mh(), me); |
710 | 1741 } |
1742 | |
1743 static void throw_InternalError_for_bad_conversion(int conversion, const char* err, TRAPS) { | |
1744 char msg[200]; | |
1745 jio_snprintf(msg, sizeof(msg), "bad adapter (conversion=0x%08x): %s", conversion, err); | |
1746 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), msg); | |
1747 } | |
1748 | |
1749 void MethodHandles::verify_AdapterMethodHandle(Handle mh, int argnum, TRAPS) { | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1750 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
|
1751 int argslot = java_lang_invoke_AdapterMethodHandle::vmargslot(mh()); |
710 | 1752 |
1753 verify_vmargslot(mh, argnum, argslot, CHECK); | |
1754 verify_vmslots(mh, CHECK); | |
1755 | |
1756 jint conv_op = adapter_conversion_op(conversion); | |
1757 if (!conv_op_valid(conv_op)) { | |
1758 throw_InternalError_for_bad_conversion(conversion, "unknown conversion op", THREAD); | |
1759 return; | |
1760 } | |
1761 EntryKind ek = adapter_entry_kind(conv_op); | |
1762 | |
1763 int stack_move = adapter_conversion_stack_move(conversion); | |
1764 BasicType src = adapter_conversion_src_type(conversion); | |
1765 BasicType dest = adapter_conversion_dest_type(conversion); | |
1766 int vminfo = adapter_conversion_vminfo(conversion); // should be zero | |
1767 | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1768 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
|
1769 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
|
1770 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
|
1771 Handle dst_mtype(THREAD, java_lang_invoke_MethodHandle::type(target())); |
710 | 1772 |
1773 const char* err = NULL; | |
1774 | |
1775 if (err == NULL) { | |
1776 // Check that the correct argument is supplied, but only if it is required. | |
1777 switch (ek) { | |
1778 case _adapter_check_cast: // target type of cast | |
1779 case _adapter_ref_to_prim: // wrapper type from which to unbox | |
1780 case _adapter_prim_to_ref: // wrapper type to box into | |
1781 case _adapter_collect_args: // array type to collect into | |
1782 case _adapter_spread_args: // array type to spread from | |
1783 if (!java_lang_Class::is_instance(argument()) | |
1784 || java_lang_Class::is_primitive(argument())) | |
1785 { err = "adapter requires argument of type java.lang.Class"; break; } | |
1786 if (ek == _adapter_collect_args || | |
1787 ek == _adapter_spread_args) { | |
1788 // Make sure it is a suitable collection type. (Array, for now.) | |
1789 Klass* ak = Klass::cast(java_lang_Class::as_klassOop(argument())); | |
1790 if (!ak->oop_is_objArray()) { | |
1791 { err = "adapter requires argument of type java.lang.Class<Object[]>"; break; } | |
1792 } | |
1793 } | |
1794 break; | |
1795 case _adapter_flyby: | |
1796 case _adapter_ricochet: | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1797 if (!java_lang_invoke_MethodHandle::is_instance(argument())) |
710 | 1798 { err = "MethodHandle adapter argument required"; break; } |
1799 break; | |
1800 default: | |
1801 if (argument.not_null()) | |
1802 { err = "adapter has spurious argument"; break; } | |
1803 break; | |
1804 } | |
1805 } | |
1806 | |
1807 if (err == NULL) { | |
1808 // Check that the src/dest types are supplied if needed. | |
1809 switch (ek) { | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1810 case _adapter_check_cast: |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1811 if (src != T_OBJECT || dest != T_OBJECT) { |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1812 err = "adapter requires object src/dest conversion subfields"; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1813 } |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1814 break; |
710 | 1815 case _adapter_prim_to_prim: |
1816 if (!is_java_primitive(src) || !is_java_primitive(dest) || src == dest) { | |
1817 err = "adapter requires primitive src/dest conversion subfields"; break; | |
1818 } | |
1819 if ( (src == T_FLOAT || src == T_DOUBLE) && !(dest == T_FLOAT || dest == T_DOUBLE) || | |
1820 !(src == T_FLOAT || src == T_DOUBLE) && (dest == T_FLOAT || dest == T_DOUBLE)) { | |
1821 err = "adapter cannot convert beween floating and fixed-point"; break; | |
1822 } | |
1823 break; | |
1824 case _adapter_ref_to_prim: | |
1825 if (src != T_OBJECT || !is_java_primitive(dest) | |
1826 || argument() != Klass::cast(SystemDictionary::box_klass(dest))->java_mirror()) { | |
1827 err = "adapter requires primitive dest conversion subfield"; break; | |
1828 } | |
1829 break; | |
1830 case _adapter_prim_to_ref: | |
1831 if (!is_java_primitive(src) || dest != T_OBJECT | |
1832 || argument() != Klass::cast(SystemDictionary::box_klass(src))->java_mirror()) { | |
1833 err = "adapter requires primitive src conversion subfield"; break; | |
1834 } | |
1835 break; | |
1836 case _adapter_swap_args: | |
1837 case _adapter_rot_args: | |
1838 { | |
1839 if (!src || src != dest) { | |
1840 err = "adapter requires src/dest conversion subfields for swap"; break; | |
1841 } | |
1842 int swap_size = type2size[src]; | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1843 oop src_mtype = java_lang_invoke_AdapterMethodHandle::type(mh()); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1844 oop dest_mtype = java_lang_invoke_AdapterMethodHandle::type(target()); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1845 int slot_limit = java_lang_invoke_AdapterMethodHandle::vmslots(target()); |
710 | 1846 int src_slot = argslot; |
1847 int dest_slot = vminfo; | |
1848 bool rotate_up = (src_slot > dest_slot); // upward rotation | |
1849 int src_arg = argnum; | |
1850 int dest_arg = argument_slot_to_argnum(dest_mtype, dest_slot); | |
1851 verify_vmargslot(mh, dest_arg, dest_slot, CHECK); | |
1852 if (!(dest_slot >= src_slot + swap_size) && | |
1853 !(src_slot >= dest_slot + swap_size)) { | |
1854 err = "source, destination slots must be distinct"; | |
1855 } else if (ek == _adapter_swap_args && !(src_slot > dest_slot)) { | |
1856 err = "source of swap must be deeper in stack"; | |
1857 } else if (ek == _adapter_swap_args) { | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1858 err = check_argument_type_change(java_lang_invoke_MethodType::ptype(src_mtype, dest_arg), |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1859 java_lang_invoke_MethodType::ptype(dest_mtype, src_arg), |
710 | 1860 dest_arg); |
1861 } else if (ek == _adapter_rot_args) { | |
1862 if (rotate_up) { | |
1863 assert((src_slot > dest_slot) && (src_arg < dest_arg), ""); | |
1864 // rotate up: [dest_slot..src_slot-ss] --> [dest_slot+ss..src_slot] | |
1865 // that is: [src_arg+1..dest_arg] --> [src_arg..dest_arg-1] | |
1866 for (int i = src_arg+1; i <= dest_arg && err == NULL; i++) { | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1867 err = check_argument_type_change(java_lang_invoke_MethodType::ptype(src_mtype, i), |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1868 java_lang_invoke_MethodType::ptype(dest_mtype, i-1), |
710 | 1869 i); |
1870 } | |
1871 } else { // rotate down | |
1872 assert((src_slot < dest_slot) && (src_arg > dest_arg), ""); | |
1873 // rotate down: [src_slot+ss..dest_slot] --> [src_slot..dest_slot-ss] | |
1874 // that is: [dest_arg..src_arg-1] --> [dst_arg+1..src_arg] | |
1875 for (int i = dest_arg; i <= src_arg-1 && err == NULL; i++) { | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1876 err = check_argument_type_change(java_lang_invoke_MethodType::ptype(src_mtype, i), |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1877 java_lang_invoke_MethodType::ptype(dest_mtype, i+1), |
710 | 1878 i); |
1879 } | |
1880 } | |
1881 } | |
1882 if (err == NULL) | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1883 err = check_argument_type_change(java_lang_invoke_MethodType::ptype(src_mtype, src_arg), |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
1884 java_lang_invoke_MethodType::ptype(dest_mtype, dest_arg), |
710 | 1885 src_arg); |
1886 } | |
1887 break; | |
1888 case _adapter_collect_args: | |
1889 case _adapter_spread_args: | |
1890 { | |
1891 BasicType coll_type = (ek == _adapter_collect_args) ? dest : src; | |
1892 BasicType elem_type = (ek == _adapter_collect_args) ? src : dest; | |
1893 if (coll_type != T_OBJECT || elem_type != T_OBJECT) { | |
1894 err = "adapter requires src/dest subfields"; break; | |
1895 // later: | |
1896 // - consider making coll be a primitive array | |
1897 // - consider making coll be a heterogeneous collection | |
1898 } | |
1899 } | |
1900 break; | |
1901 default: | |
1902 if (src != 0 || dest != 0) { | |
1903 err = "adapter has spurious src/dest conversion subfields"; break; | |
1904 } | |
1905 break; | |
1906 } | |
1907 } | |
1908 | |
1909 if (err == NULL) { | |
1910 // Check the stack_move subfield. | |
1911 // It must always report the net change in stack size, positive or negative. | |
1912 int slots_pushed = stack_move / stack_move_unit(); | |
1913 switch (ek) { | |
1914 case _adapter_prim_to_prim: | |
1915 case _adapter_ref_to_prim: | |
1916 case _adapter_prim_to_ref: | |
1917 if (slots_pushed != type2size[dest] - type2size[src]) { | |
1918 err = "wrong stack motion for primitive conversion"; | |
1919 } | |
1920 break; | |
1921 case _adapter_dup_args: | |
1922 if (slots_pushed <= 0) { | |
1923 err = "adapter requires conversion subfield slots_pushed > 0"; | |
1924 } | |
1925 break; | |
1926 case _adapter_drop_args: | |
1927 if (slots_pushed >= 0) { | |
1928 err = "adapter requires conversion subfield slots_pushed < 0"; | |
1929 } | |
1930 break; | |
1931 case _adapter_collect_args: | |
1932 if (slots_pushed > 1) { | |
1933 err = "adapter requires conversion subfield slots_pushed <= 1"; | |
1934 } | |
1935 break; | |
1936 case _adapter_spread_args: | |
1937 if (slots_pushed < -1) { | |
1938 err = "adapter requires conversion subfield slots_pushed >= -1"; | |
1939 } | |
1940 break; | |
1941 default: | |
1942 if (stack_move != 0) { | |
1943 err = "adapter has spurious stack_move conversion subfield"; | |
1944 } | |
1945 break; | |
1946 } | |
1947 if (err == NULL && stack_move != slots_pushed * stack_move_unit()) { | |
1948 err = "stack_move conversion subfield must be multiple of stack_move_unit"; | |
1949 } | |
1950 } | |
1951 | |
1952 if (err == NULL) { | |
1953 // Make sure this adapter does not push too deeply. | |
1954 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
|
1955 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
|
1956 int target_vmslots = java_lang_invoke_MethodHandle::vmslots(target()); |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1957 if (slots_pushed != (target_vmslots - this_vmslots)) { |
710 | 1958 err = "stack_move inconsistent with previous and current MethodType vmslots"; |
1959 } else if (slots_pushed > 0) { | |
1960 // verify stack_move against MethodHandlePushLimit | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1961 int target_pushes = decode_MethodHandle_stack_pushes(target()); |
710 | 1962 // do not blow the stack; use a Java-based adapter if this limit is exceeded |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1963 if (slots_pushed + target_pushes > MethodHandlePushLimit) { |
710 | 1964 err = "adapter pushes too many parameters"; |
1965 } | |
1966 } | |
1967 | |
1968 // While we're at it, check that the stack motion decoder works: | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1969 DEBUG_ONLY(int target_pushes = decode_MethodHandle_stack_pushes(target())); |
710 | 1970 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
|
1971 assert(this_pushes == slots_pushed + target_pushes, "AMH stack motion must be correct"); |
710 | 1972 } |
1973 | |
1974 if (err == NULL && vminfo != 0) { | |
1975 switch (ek) { | |
1976 case _adapter_swap_args: | |
1977 case _adapter_rot_args: | |
1978 break; // OK | |
1979 default: | |
1980 err = "vminfo subfield is reserved to the JVM"; | |
1981 } | |
1982 } | |
1983 | |
1984 // Do additional ad hoc checks. | |
1985 if (err == NULL) { | |
1986 switch (ek) { | |
1987 case _adapter_retype_only: | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1988 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
|
1989 break; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1990 |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1991 case _adapter_retype_raw: |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1992 err = check_method_type_passthrough(src_mtype(), dst_mtype(), true); |
710 | 1993 break; |
1994 | |
1995 case _adapter_check_cast: | |
1996 { | |
1997 // 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
|
1998 err = check_argument_type_change(java_lang_invoke_MethodType::ptype(src_mtype(), argnum), |
710 | 1999 object_java_mirror(), argnum); |
2000 if (err != NULL) break; | |
2001 | |
2002 // The output of the cast must fit with the destination argument: | |
2003 Handle cast_class = argument; | |
2004 err = check_method_type_conversion(src_mtype(), | |
2005 argnum, cast_class(), | |
2006 dst_mtype()); | |
2007 } | |
2008 break; | |
2009 | |
2010 // %%% TO DO: continue in remaining cases to verify src/dst_mtype if VerifyMethodHandles | |
2011 } | |
2012 } | |
2013 | |
2014 if (err != NULL) { | |
2015 throw_InternalError_for_bad_conversion(conversion, err, THREAD); | |
2016 return; | |
2017 } | |
2018 | |
2019 } | |
2020 | |
2021 void MethodHandles::init_AdapterMethodHandle(Handle mh, Handle target, int argnum, TRAPS) { | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2022 int argslot = java_lang_invoke_AdapterMethodHandle::vmargslot(mh()); |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2023 jint conversion = java_lang_invoke_AdapterMethodHandle::conversion(mh()); |
710 | 2024 jint conv_op = adapter_conversion_op(conversion); |
2025 | |
2026 // adjust the adapter code to the internal EntryKind enumeration: | |
2027 EntryKind ek_orig = adapter_entry_kind(conv_op); | |
2028 EntryKind ek_opt = ek_orig; // may be optimized | |
2029 | |
2030 // 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
|
2031 if (!java_lang_invoke_MethodHandle::is_instance(target())) { |
710 | 2032 throw_InternalError_for_bad_conversion(conversion, "bad target", THREAD); |
2033 return; | |
2034 } | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2035 java_lang_invoke_AdapterMethodHandle::set_vmtarget(mh(), target()); |
710 | 2036 |
2037 if (VerifyMethodHandles) { | |
2038 verify_AdapterMethodHandle(mh, argnum, CHECK); | |
2039 } | |
2040 | |
2041 int stack_move = adapter_conversion_stack_move(conversion); | |
2042 BasicType src = adapter_conversion_src_type(conversion); | |
2043 BasicType dest = adapter_conversion_dest_type(conversion); | |
2044 int vminfo = adapter_conversion_vminfo(conversion); // should be zero | |
2045 | |
2046 const char* err = NULL; | |
2047 | |
2048 // Now it's time to finish the case analysis and pick a MethodHandleEntry. | |
2049 switch (ek_orig) { | |
2050 case _adapter_retype_only: | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
2051 case _adapter_retype_raw: |
710 | 2052 case _adapter_check_cast: |
2053 case _adapter_dup_args: | |
2054 case _adapter_drop_args: | |
2055 // these work fine via general case code | |
2056 break; | |
2057 | |
2058 case _adapter_prim_to_prim: | |
2059 { | |
2060 // Non-subword cases are {int,float,long,double} -> {int,float,long,double}. | |
2061 // And, the {float,double} -> {int,long} cases must be handled by Java. | |
2062 switch (type2size[src] *4+ type2size[dest]) { | |
2063 case 1 *4+ 1: | |
2064 assert(src == T_INT || is_subword_type(src), "source is not float"); | |
2065 // Subword-related cases are int -> {boolean,byte,char,short}. | |
2066 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
|
2067 vminfo = adapter_prim_to_prim_subword_vminfo(dest); |
710 | 2068 break; |
2069 case 2 *4+ 1: | |
2070 if (src == T_LONG && (dest == T_INT || is_subword_type(dest))) { | |
2071 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
|
2072 vminfo = adapter_prim_to_prim_subword_vminfo(dest); |
710 | 2073 } else if (src == T_DOUBLE && dest == T_FLOAT) { |
2074 ek_opt = _adapter_opt_d2f; | |
2075 } else { | |
2076 assert(false, ""); | |
2077 } | |
2078 break; | |
2079 case 1 *4+ 2: | |
2080 if (src == T_INT && dest == T_LONG) { | |
2081 ek_opt = _adapter_opt_i2l; | |
2082 } else if (src == T_FLOAT && dest == T_DOUBLE) { | |
2083 ek_opt = _adapter_opt_f2d; | |
2084 } else { | |
2085 assert(false, ""); | |
2086 } | |
2087 break; | |
2088 default: | |
2089 assert(false, ""); | |
2090 break; | |
2091 } | |
2092 } | |
2093 break; | |
2094 | |
2095 case _adapter_ref_to_prim: | |
2096 { | |
2097 switch (type2size[dest]) { | |
2098 case 1: | |
2099 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
|
2100 vminfo = adapter_unbox_subword_vminfo(dest); |
710 | 2101 break; |
2102 case 2: | |
2103 ek_opt = _adapter_opt_unboxl; | |
2104 break; | |
2105 default: | |
2106 assert(false, ""); | |
2107 break; | |
2108 } | |
2109 } | |
2110 break; | |
2111 | |
2112 case _adapter_prim_to_ref: | |
2113 goto throw_not_impl; // allocates, hence could block | |
2114 | |
2115 case _adapter_swap_args: | |
2116 case _adapter_rot_args: | |
2117 { | |
2118 int swap_slots = type2size[src]; | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2119 int slot_limit = java_lang_invoke_AdapterMethodHandle::vmslots(mh()); |
710 | 2120 int src_slot = argslot; |
2121 int dest_slot = vminfo; | |
2122 int rotate = (ek_orig == _adapter_swap_args) ? 0 : (src_slot > dest_slot) ? 1 : -1; | |
2123 switch (swap_slots) { | |
2124 case 1: | |
2125 ek_opt = (!rotate ? _adapter_opt_swap_1 : | |
2126 rotate > 0 ? _adapter_opt_rot_1_up : _adapter_opt_rot_1_down); | |
2127 break; | |
2128 case 2: | |
2129 ek_opt = (!rotate ? _adapter_opt_swap_2 : | |
2130 rotate > 0 ? _adapter_opt_rot_2_up : _adapter_opt_rot_2_down); | |
2131 break; | |
2132 default: | |
2133 assert(false, ""); | |
2134 break; | |
2135 } | |
2136 } | |
2137 break; | |
2138 | |
2139 case _adapter_collect_args: | |
2140 goto throw_not_impl; // allocates, hence could block | |
2141 | |
2142 case _adapter_spread_args: | |
2143 { | |
2144 // vminfo will be the required length of the array | |
2145 int slots_pushed = stack_move / stack_move_unit(); | |
2146 int array_size = slots_pushed + 1; | |
2147 assert(array_size >= 0, ""); | |
2148 vminfo = array_size; | |
2149 switch (array_size) { | |
2150 case 0: ek_opt = _adapter_opt_spread_0; break; | |
2151 case 1: ek_opt = _adapter_opt_spread_1; break; | |
2152 default: ek_opt = _adapter_opt_spread_more; break; | |
2153 } | |
2154 if ((vminfo & CONV_VMINFO_MASK) != vminfo) | |
2155 goto throw_not_impl; // overflow | |
2156 } | |
2157 break; | |
2158 | |
2159 case _adapter_flyby: | |
2160 case _adapter_ricochet: | |
2161 goto throw_not_impl; // runs Java code, hence could block | |
2162 | |
2163 default: | |
2164 // should have failed much earlier; must be a missing case here | |
2165 assert(false, "incomplete switch"); | |
2166 // and fall through: | |
2167 | |
2168 throw_not_impl: | |
2169 // FIXME: these adapters are NYI | |
2170 err = "adapter not yet implemented in the JVM"; | |
2171 break; | |
2172 } | |
2173 | |
2174 if (err != NULL) { | |
2175 throw_InternalError_for_bad_conversion(conversion, err, THREAD); | |
2176 return; | |
2177 } | |
2178 | |
2179 // Rebuild the conversion value; maybe parts of it were changed. | |
2180 jint new_conversion = adapter_conversion(conv_op, src, dest, stack_move, vminfo); | |
2181 | |
2182 // 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
|
2183 java_lang_invoke_AdapterMethodHandle::set_conversion(mh(), new_conversion); |
710 | 2184 |
2185 // Done! | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2186 java_lang_invoke_MethodHandle::set_vmentry(mh(), entry(ek_opt)); |
710 | 2187 |
2188 // There should be enough memory barriers on exit from native methods | |
2189 // to ensure that the MH is fully initialized to all threads before | |
2190 // Java code can publish it in global data structures. | |
2191 } | |
2192 | |
2193 // | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2194 // Here are the native methods on sun.invoke.MethodHandleImpl. |
710 | 2195 // They are the private interface between this JVM and the HotSpot-specific |
2196 // Java code that implements JSR 292 method handles. | |
2197 // | |
2198 // Note: We use a JVM_ENTRY macro to define each of these, for this is the way | |
2199 // that intrinsic (non-JNI) native methods are defined in HotSpot. | |
2200 // | |
2201 | |
2202 // direct method handles for invokestatic or invokespecial | |
2203 // 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
|
2204 JVM_ENTRY(void, MHN_init_DMH(JNIEnv *env, jobject igcls, jobject mh_jh, |
710 | 2205 jobject target_jh, jboolean do_dispatch, jobject caller_jh)) { |
2206 ResourceMark rm; // for error messages | |
2207 | |
2208 // This is the guy we are initializing: | |
2209 if (mh_jh == NULL) { THROW(vmSymbols::java_lang_InternalError()); } | |
2210 Handle mh(THREAD, JNIHandles::resolve_non_null(mh_jh)); | |
2211 | |
2212 // 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
|
2213 assert(java_lang_invoke_MethodHandle::vmentry(mh()) == NULL, "must be safely null"); |
710 | 2214 |
2215 // which method are we really talking about? | |
2216 if (target_jh == NULL) { THROW(vmSymbols::java_lang_InternalError()); } | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
2217 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
|
2218 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
|
2219 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
|
2220 MethodHandles::resolve_MemberName(target, CHECK); |
710 | 2221 } |
2222 | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
2223 KlassHandle receiver_limit; int decode_flags = 0; |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
2224 methodHandle m = MethodHandles::decode_method(target(), receiver_limit, decode_flags); |
710 | 2225 if (m.is_null()) { THROW_MSG(vmSymbols::java_lang_InternalError(), "no such method"); } |
2226 | |
2227 // The trusted Java code that calls this method should already have performed | |
2228 // access checks on behalf of the given caller. But, we can verify this. | |
2229 if (VerifyMethodHandles && caller_jh != NULL) { | |
2230 KlassHandle caller(THREAD, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(caller_jh))); | |
2231 // If this were a bytecode, the first access check would be against | |
2232 // the "reference class" mentioned in the CONSTANT_Methodref. | |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2233 // 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
|
2234 // 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
|
2235 // 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
|
2236 // happens, when we call resolve_MemberName. |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2237 // |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2238 // (A public class can inherit public members from private supers, |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2239 // 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
|
2240 // if the original symbolic reference was against the public class.) |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2241 // |
710 | 2242 // If there were a bytecode, the next step would be to lookup the method |
2243 // in the reference class, then then check the method's access bits. | |
2244 // Emulate LinkResolver::check_method_accessability. | |
2245 klassOop resolved_klass = m->method_holder(); | |
2246 if (!Reflection::verify_field_access(caller->as_klassOop(), | |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2247 resolved_klass, resolved_klass, |
710 | 2248 m->access_flags(), |
2249 true)) { | |
2250 // %%% following cutout belongs in Reflection::verify_field_access? | |
2251 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
|
2252 resolved_klass, THREAD); |
710 | 2253 if (!same_pm) { |
2254 THROW_MSG(vmSymbols::java_lang_InternalError(), m->name_and_sig_as_C_string()); | |
2255 } | |
2256 } | |
2257 } | |
2258 | |
2259 MethodHandles::init_DirectMethodHandle(mh, m, (do_dispatch != JNI_FALSE), CHECK); | |
2260 } | |
2261 JVM_END | |
2262 | |
2263 // bound method handles | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2264 JVM_ENTRY(void, MHN_init_BMH(JNIEnv *env, jobject igcls, jobject mh_jh, |
710 | 2265 jobject target_jh, int argnum)) { |
2266 ResourceMark rm; // for error messages | |
2267 | |
2268 // This is the guy we are initializing: | |
2269 if (mh_jh == NULL) { THROW(vmSymbols::java_lang_InternalError()); } | |
2270 Handle mh(THREAD, JNIHandles::resolve_non_null(mh_jh)); | |
2271 | |
2272 // 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
|
2273 assert(java_lang_invoke_MethodHandle::vmentry(mh()) == NULL, "must be safely null"); |
710 | 2274 |
2275 if (target_jh == NULL) { THROW(vmSymbols::java_lang_InternalError()); } | |
2276 Handle target(THREAD, JNIHandles::resolve_non_null(target_jh)); | |
2277 | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2278 if (!java_lang_invoke_MethodHandle::is_instance(target())) { |
710 | 2279 // Target object is a reflective method. (%%% Do we need this alternate path?) |
2280 Untested("init_BMH of non-MH"); | |
2281 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
|
2282 KlassHandle receiver_limit; int decode_flags = 0; |
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
2283 methodHandle m = MethodHandles::decode_method(target(), receiver_limit, decode_flags); |
710 | 2284 MethodHandles::init_BoundMethodHandle_with_receiver(mh, m, |
2285 receiver_limit, | |
2286 decode_flags, | |
2287 CHECK); | |
2288 return; | |
2289 } | |
2290 | |
2291 // Build a BMH on top of a DMH or another BMH: | |
2292 MethodHandles::init_BoundMethodHandle(mh, target, argnum, CHECK); | |
2293 } | |
2294 JVM_END | |
2295 | |
2296 // adapter method handles | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2297 JVM_ENTRY(void, MHN_init_AMH(JNIEnv *env, jobject igcls, jobject mh_jh, |
710 | 2298 jobject target_jh, int argnum)) { |
2299 // This is the guy we are initializing: | |
2300 if (mh_jh == NULL || target_jh == NULL) { | |
2301 THROW(vmSymbols::java_lang_InternalError()); | |
2302 } | |
2303 Handle mh(THREAD, JNIHandles::resolve_non_null(mh_jh)); | |
2304 Handle target(THREAD, JNIHandles::resolve_non_null(target_jh)); | |
2305 | |
2306 // 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
|
2307 assert(java_lang_invoke_MethodHandle::vmentry(mh()) == NULL, "must be safely null"); |
710 | 2308 |
2309 MethodHandles::init_AdapterMethodHandle(mh, target, argnum, CHECK); | |
2310 } | |
2311 JVM_END | |
2312 | |
2313 // method type forms | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2314 JVM_ENTRY(void, MHN_init_MT(JNIEnv *env, jobject igcls, jobject erased_jh)) { |
710 | 2315 if (erased_jh == NULL) return; |
2316 if (TraceMethodHandles) { | |
2317 tty->print("creating MethodType form "); | |
2318 if (WizardMode || Verbose) { // Warning: this calls Java code on the MH! | |
2319 // call Object.toString() | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
2320 Symbol* name = vmSymbols::toString_name(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
2321 Symbol* sig = vmSymbols::void_string_signature(); |
710 | 2322 JavaCallArguments args(Handle(THREAD, JNIHandles::resolve_non_null(erased_jh))); |
2323 JavaValue result(T_OBJECT); | |
1142 | 2324 JavaCalls::call_virtual(&result, SystemDictionary::Object_klass(), name, sig, |
710 | 2325 &args, CHECK); |
2326 Handle str(THREAD, (oop)result.get_jobject()); | |
2327 java_lang_String::print(str, tty); | |
2328 } | |
2329 tty->cr(); | |
2330 } | |
2331 } | |
2332 JVM_END | |
2333 | |
2334 // debugging and reflection | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2335 JVM_ENTRY(jobject, MHN_getTarget(JNIEnv *env, jobject igcls, jobject mh_jh, jint format)) { |
710 | 2336 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
|
2337 if (!java_lang_invoke_MethodHandle::is_instance(mh())) { |
710 | 2338 THROW_NULL(vmSymbols::java_lang_IllegalArgumentException()); |
2339 } | |
2340 oop target = MethodHandles::encode_target(mh, format, CHECK_NULL); | |
2341 return JNIHandles::make_local(THREAD, target); | |
2342 } | |
2343 JVM_END | |
2344 | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2345 JVM_ENTRY(jint, MHN_getConstant(JNIEnv *env, jobject igcls, jint which)) { |
710 | 2346 switch (which) { |
2347 case MethodHandles::GC_JVM_PUSH_LIMIT: | |
2348 guarantee(MethodHandlePushLimit >= 2 && MethodHandlePushLimit <= 0xFF, | |
2349 "MethodHandlePushLimit parameter must be in valid range"); | |
2350 return MethodHandlePushLimit; | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
2351 case MethodHandles::GC_JVM_STACK_MOVE_UNIT: |
710 | 2352 // return number of words per slot, signed according to stack direction |
2353 return MethodHandles::stack_move_unit(); | |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2354 case MethodHandles::GC_CONV_OP_IMPLEMENTED_MASK: |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2355 return MethodHandles::adapter_conversion_ops_supported_mask(); |
710 | 2356 } |
2357 return 0; | |
2358 } | |
2359 JVM_END | |
2360 | |
2361 #ifndef PRODUCT | |
2362 #define EACH_NAMED_CON(template) \ | |
2363 template(MethodHandles,GC_JVM_PUSH_LIMIT) \ | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
2364 template(MethodHandles,GC_JVM_STACK_MOVE_UNIT) \ |
710 | 2365 template(MethodHandles,ETF_HANDLE_OR_METHOD_NAME) \ |
2366 template(MethodHandles,ETF_DIRECT_HANDLE) \ | |
2367 template(MethodHandles,ETF_METHOD_NAME) \ | |
2368 template(MethodHandles,ETF_REFLECT_METHOD) \ | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2369 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
|
2370 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
|
2371 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
|
2372 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
|
2373 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
|
2374 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
|
2375 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
|
2376 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
|
2377 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
|
2378 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
|
2379 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
|
2380 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
|
2381 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
|
2382 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
|
2383 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
|
2384 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
|
2385 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
|
2386 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
|
2387 template(java_lang_invoke_AdapterMethodHandle,OP_SPREAD_ARGS) \ |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2388 template(java_lang_invoke_AdapterMethodHandle,OP_FLYBY) \ |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2389 template(java_lang_invoke_AdapterMethodHandle,OP_RICOCHET) \ |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2390 template(java_lang_invoke_AdapterMethodHandle,CONV_OP_LIMIT) \ |
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2391 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
|
2392 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
|
2393 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
|
2394 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
|
2395 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
|
2396 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
|
2397 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
|
2398 template(java_lang_invoke_AdapterMethodHandle,CONV_STACK_MOVE_MASK) \ |
710 | 2399 /*end*/ |
2400 | |
2401 #define ONE_PLUS(scope,value) 1+ | |
2402 static const int con_value_count = EACH_NAMED_CON(ONE_PLUS) 0; | |
2403 #define VALUE_COMMA(scope,value) scope::value, | |
2404 static const int con_values[con_value_count+1] = { EACH_NAMED_CON(VALUE_COMMA) 0 }; | |
2405 #define STRING_NULL(scope,value) #value "\0" | |
2406 static const char con_names[] = { EACH_NAMED_CON(STRING_NULL) }; | |
2407 | |
2408 #undef ONE_PLUS | |
2409 #undef VALUE_COMMA | |
2410 #undef STRING_NULL | |
2411 #undef EACH_NAMED_CON | |
2412 #endif | |
2413 | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2414 JVM_ENTRY(jint, MHN_getNamedCon(JNIEnv *env, jobject igcls, jint which, jobjectArray box_jh)) { |
710 | 2415 #ifndef PRODUCT |
2416 if (which >= 0 && which < con_value_count) { | |
2417 int con = con_values[which]; | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
2418 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
|
2419 if (box.not_null() && box->klass() == Universe::objectArrayKlassObj() && box->length() > 0) { |
710 | 2420 const char* str = &con_names[0]; |
2421 for (int i = 0; i < which; i++) | |
2422 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
|
2423 oop name = java_lang_String::create_oop_from_str(str, CHECK_0); // possible safepoint |
710 | 2424 box->obj_at_put(0, name); |
2425 } | |
2426 return con; | |
2427 } | |
2428 #endif | |
2429 return 0; | |
2430 } | |
2431 JVM_END | |
2432 | |
2433 // 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
|
2434 JVM_ENTRY(void, MHN_init_Mem(JNIEnv *env, jobject igcls, jobject mname_jh, jobject target_jh)) { |
710 | 2435 if (mname_jh == NULL || target_jh == NULL) { THROW(vmSymbols::java_lang_InternalError()); } |
2436 Handle mname(THREAD, JNIHandles::resolve_non_null(mname_jh)); | |
2437 oop target_oop = JNIHandles::resolve_non_null(target_jh); | |
2438 MethodHandles::init_MemberName(mname(), target_oop); | |
2439 } | |
2440 JVM_END | |
2441 | |
2442 // void expand(MemberName self) | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2443 JVM_ENTRY(void, MHN_expand_Mem(JNIEnv *env, jobject igcls, jobject mname_jh)) { |
710 | 2444 if (mname_jh == NULL) { THROW(vmSymbols::java_lang_InternalError()); } |
2445 Handle mname(THREAD, JNIHandles::resolve_non_null(mname_jh)); | |
2446 MethodHandles::expand_MemberName(mname, 0, CHECK); | |
2447 } | |
2448 JVM_END | |
2449 | |
2450 // 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
|
2451 JVM_ENTRY(void, MHN_resolve_Mem(JNIEnv *env, jobject igcls, jobject mname_jh, jclass caller_jh)) { |
710 | 2452 if (mname_jh == NULL) { THROW(vmSymbols::java_lang_InternalError()); } |
2453 Handle mname(THREAD, JNIHandles::resolve_non_null(mname_jh)); | |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2454 |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2455 // 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
|
2456 // 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
|
2457 if (VerifyMethodHandles && caller_jh != NULL) { |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2458 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
|
2459 if (reference_klass != NULL) { |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2460 // Emulate LinkResolver::check_klass_accessability. |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2461 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
|
2462 if (!Reflection::verify_class_access(caller, |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2463 reference_klass, |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2464 true)) { |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2465 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
|
2466 } |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2467 } |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2468 } |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1299
diff
changeset
|
2469 |
710 | 2470 MethodHandles::resolve_MemberName(mname, CHECK); |
2471 } | |
2472 JVM_END | |
2473 | |
2474 // static native int getMembers(Class<?> defc, String matchName, String matchSig, | |
2475 // 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
|
2476 JVM_ENTRY(jint, MHN_getMembers(JNIEnv *env, jobject igcls, |
710 | 2477 jclass clazz_jh, jstring name_jh, jstring sig_jh, |
2478 int mflags, jclass caller_jh, jint skip, jobjectArray results_jh)) { | |
2479 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
|
2480 KlassHandle k(THREAD, java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz_jh))); |
710 | 2481 |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
2482 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
|
2483 if (results.is_null() || !results->is_objArray()) return -1; |
710 | 2484 |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
2485 TempNewSymbol name = NULL; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
2486 TempNewSymbol sig = NULL; |
710 | 2487 if (name_jh != NULL) { |
2488 name = java_lang_String::as_symbol_or_null(JNIHandles::resolve_non_null(name_jh)); | |
2489 if (name == NULL) return 0; // a match is not possible | |
2490 } | |
2491 if (sig_jh != NULL) { | |
2492 sig = java_lang_String::as_symbol_or_null(JNIHandles::resolve_non_null(sig_jh)); | |
2493 if (sig == NULL) return 0; // a match is not possible | |
2494 } | |
2495 | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
2496 KlassHandle caller; |
710 | 2497 if (caller_jh != NULL) { |
2498 oop caller_oop = JNIHandles::resolve_non_null(caller_jh); | |
2499 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
|
2500 caller = KlassHandle(THREAD, java_lang_Class::as_klassOop(caller_oop)); |
710 | 2501 } |
2502 | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
2503 if (name != NULL && sig != NULL && results.not_null()) { |
710 | 2504 // try a direct resolve |
2505 // %%% TO DO | |
2506 } | |
2507 | |
3274
2a23b1b5a0a8
7018355: JSR 292: VM crash in DefNewGeneration::copy_to_survivor_space
twisti
parents:
2478
diff
changeset
|
2508 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
|
2509 caller(), skip, results()); |
710 | 2510 // TO DO: expand at least some of the MemberNames, to avoid massive callbacks |
2511 return res; | |
2512 } | |
2513 JVM_END | |
2514 | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2515 |
710 | 2516 /// JVM_RegisterMethodHandleMethods |
2517 | |
2518 #define LANG "Ljava/lang/" | |
2460 | 2519 #define JLINV "Ljava/lang/invoke/" |
710 | 2520 |
2521 #define OBJ LANG"Object;" | |
2522 #define CLS LANG"Class;" | |
2523 #define STRG LANG"String;" | |
2460 | 2524 #define MT JLINV"MethodType;" |
2525 #define MH JLINV"MethodHandle;" | |
2526 #define MEM JLINV"MemberName;" | |
2527 #define AMH JLINV"AdapterMethodHandle;" | |
2528 #define BMH JLINV"BoundMethodHandle;" | |
2529 #define DMH JLINV"DirectMethodHandle;" | |
710 | 2530 |
2531 #define CC (char*) /*cast a literal from (const char*)*/ | |
2532 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f) | |
2533 | |
2357
8033953d67ff
7012648: move JSR 292 to package java.lang.invoke and adjust names
jrose
parents:
2356
diff
changeset
|
2534 // These are the native methods on sun.invoke.MethodHandleNatives. |
710 | 2535 static JNINativeMethod methods[] = { |
2536 // 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
|
2537 {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
|
2538 {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
|
2539 {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
|
2540 {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
|
2541 {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
|
2542 {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
|
2543 {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
|
2544 {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
|
2545 {CC"getConstant", CC"(I)I", FN_PTR(MHN_getConstant)}, |
710 | 2546 // 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
|
2547 {CC"getNamedCon", CC"(I["OBJ")I", FN_PTR(MHN_getNamedCon)}, |
710 | 2548 // static native int getMembers(Class<?> defc, String matchName, String matchSig, |
2549 // 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
|
2550 {CC"getMembers", CC"("CLS""STRG""STRG"I"CLS"I["MEM")I", FN_PTR(MHN_getMembers)} |
710 | 2551 }; |
2552 | |
2553 // This one function is exported, used by NativeLookup. | |
2554 | |
2555 JVM_ENTRY(void, JVM_RegisterMethodHandleMethods(JNIEnv *env, jclass MHN_class)) { | |
2556 assert(MethodHandles::spot_check_entry_names(), "entry enum is OK"); | |
2557 | |
2416
38fea01eb669
6817525: turn on method handle functionality by default for JSR 292
twisti
parents:
2357
diff
changeset
|
2558 if (!EnableInvokeDynamic) { |
38fea01eb669
6817525: turn on method handle functionality by default for JSR 292
twisti
parents:
2357
diff
changeset
|
2559 warning("JSR 292 is disabled in this JVM. Use -XX:+UnlockDiagnosticVMOptions -XX:+EnableInvokeDynamic to enable."); |
710 | 2560 return; // bind nothing |
2561 } | |
2562 | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
2563 bool enable_MH = true; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
2564 |
2460 | 2565 { |
710 | 2566 ThreadToNativeFromVM ttnfv(thread); |
2567 | |
2568 int status = env->RegisterNatives(MHN_class, methods, sizeof(methods)/sizeof(JNINativeMethod)); | |
2569 if (env->ExceptionOccurred()) { | |
2460 | 2570 MethodHandles::set_enabled(false); |
2571 warning("JSR 292 method handle code is mismatched to this JVM. Disabling support."); | |
2572 enable_MH = false; | |
710 | 2573 env->ExceptionClear(); |
2574 } | |
2575 } | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
2576 |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
2577 if (enable_MH) { |
2356
72dee110246f
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
2177
diff
changeset
|
2578 KlassHandle MHN_klass = SystemDictionaryHandles::MethodHandleNatives_klass(); |
2460 | 2579 if (MHN_klass.not_null()) { |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
2580 TempNewSymbol raiseException_name = SymbolTable::new_symbol("raiseException", CHECK); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
2581 TempNewSymbol raiseException_sig = SymbolTable::new_symbol("(ILjava/lang/Object;Ljava/lang/Object;)V", CHECK); |
2460 | 2582 methodOop raiseException_method = instanceKlass::cast(MHN_klass->as_klassOop()) |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2116
diff
changeset
|
2583 ->find_method(raiseException_name, raiseException_sig); |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
2584 if (raiseException_method != NULL && raiseException_method->is_static()) { |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
2585 MethodHandles::set_raise_exception_method(raiseException_method); |
2460 | 2586 } else { |
2587 warning("JSR 292 method handle code is mismatched to this JVM. Disabling support."); | |
2588 enable_MH = false; | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
2589 } |
2460 | 2590 } else { |
2116
d810e9a3fc33
7010180: JSR 292 InvokeDynamicPrintArgs fails with: assert(_adapter == NULL) failed: init'd to NULL
twisti
parents:
2088
diff
changeset
|
2591 enable_MH = false; |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
2592 } |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
2593 } |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
2594 |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
2595 if (enable_MH) { |
2116
d810e9a3fc33
7010180: JSR 292 InvokeDynamicPrintArgs fails with: assert(_adapter == NULL) failed: init'd to NULL
twisti
parents:
2088
diff
changeset
|
2596 MethodHandles::generate_adapters(); |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
2597 MethodHandles::set_enabled(true); |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
2598 } |
710 | 2599 } |
2600 JVM_END |