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