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