Mercurial > hg > truffle
annotate src/cpu/x86/vm/methodHandles_x86.cpp @ 1932:e6500c6c5e24
Removed launch configuration.
author | Thomas Wuerthinger <wuerthinger@ssw.jku.at> |
---|---|
date | Tue, 21 Dec 2010 17:09:37 +0100 |
parents | beba40b26a79 |
children | f95d63e2154a |
rev | line source |
---|---|
710 | 1 /* |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1507
diff
changeset
|
2 * Copyright (c) 1997, 2010, 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:
1507
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1507
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:
1507
diff
changeset
|
21 * questions. |
710 | 22 * |
23 */ | |
24 | |
25 #include "incls/_precompiled.incl" | |
26 #include "incls/_methodHandles_x86.cpp.incl" | |
27 | |
28 #define __ _masm-> | |
29 | |
1793
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
30 #ifdef PRODUCT |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
31 #define BLOCK_COMMENT(str) /* nothing */ |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
32 #else |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
33 #define BLOCK_COMMENT(str) __ block_comment(str) |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
34 #endif |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
35 |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
36 #define BIND(label) bind(label); BLOCK_COMMENT(#label ":") |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
37 |
710 | 38 address MethodHandleEntry::start_compiled_entry(MacroAssembler* _masm, |
39 address interpreted_entry) { | |
40 // Just before the actual machine code entry point, allocate space | |
41 // for a MethodHandleEntry::Data record, so that we can manage everything | |
42 // from one base pointer. | |
43 __ align(wordSize); | |
44 address target = __ pc() + sizeof(Data); | |
45 while (__ pc() < target) { | |
46 __ nop(); | |
47 __ align(wordSize); | |
48 } | |
49 | |
50 MethodHandleEntry* me = (MethodHandleEntry*) __ pc(); | |
51 me->set_end_address(__ pc()); // set a temporary end_address | |
52 me->set_from_interpreted_entry(interpreted_entry); | |
53 me->set_type_checking_entry(NULL); | |
54 | |
55 return (address) me; | |
56 } | |
57 | |
58 MethodHandleEntry* MethodHandleEntry::finish_compiled_entry(MacroAssembler* _masm, | |
59 address start_addr) { | |
60 MethodHandleEntry* me = (MethodHandleEntry*) start_addr; | |
61 assert(me->end_address() == start_addr, "valid ME"); | |
62 | |
63 // Fill in the real end_address: | |
64 __ align(wordSize); | |
65 me->set_end_address(__ pc()); | |
66 | |
67 return me; | |
68 } | |
69 | |
70 #ifdef ASSERT | |
1304 | 71 static void verify_argslot(MacroAssembler* _masm, Register argslot_reg, |
710 | 72 const char* error_message) { |
73 // Verify that argslot lies within (rsp, rbp]. | |
74 Label L_ok, L_bad; | |
1793
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
75 BLOCK_COMMENT("{ verify_argslot"); |
1304 | 76 __ cmpptr(argslot_reg, rbp); |
1135
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1133
diff
changeset
|
77 __ jccb(Assembler::above, L_bad); |
1304 | 78 __ cmpptr(rsp, argslot_reg); |
1135
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1133
diff
changeset
|
79 __ jccb(Assembler::below, L_ok); |
710 | 80 __ bind(L_bad); |
81 __ stop(error_message); | |
82 __ bind(L_ok); | |
1793
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
83 BLOCK_COMMENT("} verify_argslot"); |
710 | 84 } |
85 #endif | |
86 | |
87 | |
88 // Code generation | |
89 address MethodHandles::generate_method_handle_interpreter_entry(MacroAssembler* _masm) { | |
90 // rbx: methodOop | |
91 // rcx: receiver method handle (must load from sp[MethodTypeForm.vmslots]) | |
92 // rsi/r13: sender SP (must preserve; see prepare_to_jump_from_interpreted) | |
1793
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
93 // rdx, rdi: garbage temp, blown away |
710 | 94 |
95 Register rbx_method = rbx; | |
96 Register rcx_recv = rcx; | |
97 Register rax_mtype = rax; | |
98 Register rdx_temp = rdx; | |
1793
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
99 Register rdi_temp = rdi; |
710 | 100 |
101 // emit WrongMethodType path first, to enable jccb back-branch from main path | |
102 Label wrong_method_type; | |
103 __ bind(wrong_method_type); | |
1793
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
104 Label invoke_generic_slow_path; |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
105 assert(methodOopDesc::intrinsic_id_size_in_bytes() == sizeof(u1), "");; |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
106 __ cmpb(Address(rbx_method, methodOopDesc::intrinsic_id_offset_in_bytes()), (int) vmIntrinsics::_invokeExact); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
107 __ jcc(Assembler::notEqual, invoke_generic_slow_path); |
710 | 108 __ push(rax_mtype); // required mtype |
109 __ push(rcx_recv); // bad mh (1st stacked argument) | |
110 __ jump(ExternalAddress(Interpreter::throw_WrongMethodType_entry())); | |
111 | |
112 // here's where control starts out: | |
113 __ align(CodeEntryAlignment); | |
114 address entry_point = __ pc(); | |
115 | |
116 // fetch the MethodType from the method handle into rax (the 'check' register) | |
117 { | |
118 Register tem = rbx_method; | |
119 for (jint* pchase = methodOopDesc::method_type_offsets_chain(); (*pchase) != -1; pchase++) { | |
120 __ movptr(rax_mtype, Address(tem, *pchase)); | |
121 tem = rax_mtype; // in case there is another indirection | |
122 } | |
123 } | |
124 | |
125 // given the MethodType, find out where the MH argument is buried | |
1846 | 126 __ load_heap_oop(rdx_temp, Address(rax_mtype, __ delayed_value(java_dyn_MethodType::form_offset_in_bytes, rdi_temp))); |
1793
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
127 Register rdx_vmslots = rdx_temp; |
1846 | 128 __ movl(rdx_vmslots, Address(rdx_temp, __ delayed_value(java_dyn_MethodTypeForm::vmslots_offset_in_bytes, rdi_temp))); |
1793
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
129 __ movptr(rcx_recv, __ argument_address(rdx_vmslots)); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
130 |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
131 trace_method_handle(_masm, "invokeExact"); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
132 |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
133 __ check_method_handle_type(rax_mtype, rcx_recv, rdi_temp, wrong_method_type); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
134 __ jump_to_method_handle_entry(rcx_recv, rdi_temp); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
135 |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
136 // for invokeGeneric (only), apply argument and result conversions on the fly |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
137 __ bind(invoke_generic_slow_path); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
138 #ifdef ASSERT |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
139 { Label L; |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
140 __ cmpb(Address(rbx_method, methodOopDesc::intrinsic_id_offset_in_bytes()), (int) vmIntrinsics::_invokeGeneric); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
141 __ jcc(Assembler::equal, L); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
142 __ stop("bad methodOop::intrinsic_id"); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
143 __ bind(L); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
144 } |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
145 #endif //ASSERT |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
146 Register rbx_temp = rbx_method; // don't need it now |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
147 |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
148 // make room on the stack for another pointer: |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
149 Register rcx_argslot = rcx_recv; |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
150 __ lea(rcx_argslot, __ argument_address(rdx_vmslots, 1)); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
151 insert_arg_slots(_masm, 2 * stack_move_unit(), _INSERT_REF_MASK, |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
152 rcx_argslot, rbx_temp, rdx_temp); |
710 | 153 |
1793
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
154 // load up an adapter from the calling type (Java weaves this) |
1846 | 155 __ load_heap_oop(rdx_temp, Address(rax_mtype, __ delayed_value(java_dyn_MethodType::form_offset_in_bytes, rdi_temp))); |
1793
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
156 Register rdx_adapter = rdx_temp; |
1846 | 157 // __ load_heap_oop(rdx_adapter, Address(rdx_temp, java_dyn_MethodTypeForm::genericInvoker_offset_in_bytes())); |
1793
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
158 // deal with old JDK versions: |
1846 | 159 __ lea(rdi_temp, Address(rdx_temp, __ delayed_value(java_dyn_MethodTypeForm::genericInvoker_offset_in_bytes, rdi_temp))); |
1793
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
160 __ cmpptr(rdi_temp, rdx_temp); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
161 Label sorry_no_invoke_generic; |
1846 | 162 __ jcc(Assembler::below, sorry_no_invoke_generic); |
1793
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
163 |
1846 | 164 __ load_heap_oop(rdx_adapter, Address(rdi_temp, 0)); |
1793
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
165 __ testptr(rdx_adapter, rdx_adapter); |
1846 | 166 __ jcc(Assembler::zero, sorry_no_invoke_generic); |
1793
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
167 __ movptr(Address(rcx_argslot, 1 * Interpreter::stackElementSize), rdx_adapter); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
168 // As a trusted first argument, pass the type being called, so the adapter knows |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
169 // the actual types of the arguments and return values. |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
170 // (Generic invokers are shared among form-families of method-type.) |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
171 __ movptr(Address(rcx_argslot, 0 * Interpreter::stackElementSize), rax_mtype); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
172 // FIXME: assert that rdx_adapter is of the right method-type. |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
173 __ mov(rcx, rdx_adapter); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
174 trace_method_handle(_masm, "invokeGeneric"); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
175 __ jump_to_method_handle_entry(rcx, rdi_temp); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
176 |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
177 __ bind(sorry_no_invoke_generic); // no invokeGeneric implementation available! |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
178 __ movptr(rcx_recv, Address(rcx_argslot, -1 * Interpreter::stackElementSize)); // recover original MH |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
179 __ push(rax_mtype); // required mtype |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
180 __ push(rcx_recv); // bad mh (1st stacked argument) |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
181 __ jump(ExternalAddress(Interpreter::throw_WrongMethodType_entry())); |
710 | 182 |
183 return entry_point; | |
184 } | |
185 | |
186 // Helper to insert argument slots into the stack. | |
187 // arg_slots must be a multiple of stack_move_unit() and <= 0 | |
188 void MethodHandles::insert_arg_slots(MacroAssembler* _masm, | |
189 RegisterOrConstant arg_slots, | |
190 int arg_mask, | |
191 Register rax_argslot, | |
1503 | 192 Register rbx_temp, Register rdx_temp, Register temp3_reg) { |
193 assert(temp3_reg == noreg, "temp3 not required"); | |
710 | 194 assert_different_registers(rax_argslot, rbx_temp, rdx_temp, |
195 (!arg_slots.is_register() ? rsp : arg_slots.as_register())); | |
196 | |
197 #ifdef ASSERT | |
198 verify_argslot(_masm, rax_argslot, "insertion point must fall within current frame"); | |
199 if (arg_slots.is_register()) { | |
200 Label L_ok, L_bad; | |
201 __ cmpptr(arg_slots.as_register(), (int32_t) NULL_WORD); | |
1135
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1133
diff
changeset
|
202 __ jccb(Assembler::greater, L_bad); |
710 | 203 __ testl(arg_slots.as_register(), -stack_move_unit() - 1); |
1135
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1133
diff
changeset
|
204 __ jccb(Assembler::zero, L_ok); |
710 | 205 __ bind(L_bad); |
206 __ stop("assert arg_slots <= 0 and clear low bits"); | |
207 __ bind(L_ok); | |
208 } else { | |
209 assert(arg_slots.as_constant() <= 0, ""); | |
210 assert(arg_slots.as_constant() % -stack_move_unit() == 0, ""); | |
211 } | |
212 #endif //ASSERT | |
213 | |
214 #ifdef _LP64 | |
215 if (arg_slots.is_register()) { | |
216 // clean high bits of stack motion register (was loaded as an int) | |
217 __ movslq(arg_slots.as_register(), arg_slots.as_register()); | |
218 } | |
219 #endif | |
220 | |
221 // Make space on the stack for the inserted argument(s). | |
222 // Then pull down everything shallower than rax_argslot. | |
223 // The stacked return address gets pulled down with everything else. | |
224 // That is, copy [rsp, argslot) downward by -size words. In pseudo-code: | |
225 // rsp -= size; | |
226 // for (rdx = rsp + size; rdx < argslot; rdx++) | |
227 // rdx[-size] = rdx[0] | |
228 // argslot -= size; | |
1793
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
229 BLOCK_COMMENT("insert_arg_slots {"); |
710 | 230 __ mov(rdx_temp, rsp); // source pointer for copy |
231 __ lea(rsp, Address(rsp, arg_slots, Address::times_ptr)); | |
232 { | |
233 Label loop; | |
1793
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
234 __ BIND(loop); |
710 | 235 // pull one word down each time through the loop |
236 __ movptr(rbx_temp, Address(rdx_temp, 0)); | |
237 __ movptr(Address(rdx_temp, arg_slots, Address::times_ptr), rbx_temp); | |
238 __ addptr(rdx_temp, wordSize); | |
239 __ cmpptr(rdx_temp, rax_argslot); | |
1135
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1133
diff
changeset
|
240 __ jccb(Assembler::less, loop); |
710 | 241 } |
242 | |
243 // Now move the argslot down, to point to the opened-up space. | |
244 __ lea(rax_argslot, Address(rax_argslot, arg_slots, Address::times_ptr)); | |
1793
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
245 BLOCK_COMMENT("} insert_arg_slots"); |
710 | 246 } |
247 | |
248 // Helper to remove argument slots from the stack. | |
249 // arg_slots must be a multiple of stack_move_unit() and >= 0 | |
250 void MethodHandles::remove_arg_slots(MacroAssembler* _masm, | |
251 RegisterOrConstant arg_slots, | |
252 Register rax_argslot, | |
1503 | 253 Register rbx_temp, Register rdx_temp, Register temp3_reg) { |
254 assert(temp3_reg == noreg, "temp3 not required"); | |
710 | 255 assert_different_registers(rax_argslot, rbx_temp, rdx_temp, |
256 (!arg_slots.is_register() ? rsp : arg_slots.as_register())); | |
257 | |
258 #ifdef ASSERT | |
1304 | 259 // Verify that [argslot..argslot+size) lies within (rsp, rbp). |
260 __ lea(rbx_temp, Address(rax_argslot, arg_slots, Address::times_ptr)); | |
261 verify_argslot(_masm, rbx_temp, "deleted argument(s) must fall within current frame"); | |
710 | 262 if (arg_slots.is_register()) { |
263 Label L_ok, L_bad; | |
264 __ cmpptr(arg_slots.as_register(), (int32_t) NULL_WORD); | |
1135
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1133
diff
changeset
|
265 __ jccb(Assembler::less, L_bad); |
710 | 266 __ testl(arg_slots.as_register(), -stack_move_unit() - 1); |
1135
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1133
diff
changeset
|
267 __ jccb(Assembler::zero, L_ok); |
710 | 268 __ bind(L_bad); |
269 __ stop("assert arg_slots >= 0 and clear low bits"); | |
270 __ bind(L_ok); | |
271 } else { | |
272 assert(arg_slots.as_constant() >= 0, ""); | |
273 assert(arg_slots.as_constant() % -stack_move_unit() == 0, ""); | |
274 } | |
275 #endif //ASSERT | |
276 | |
277 #ifdef _LP64 | |
278 if (false) { // not needed, since register is positive | |
279 // clean high bits of stack motion register (was loaded as an int) | |
280 if (arg_slots.is_register()) | |
281 __ movslq(arg_slots.as_register(), arg_slots.as_register()); | |
282 } | |
283 #endif | |
284 | |
1793
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
285 BLOCK_COMMENT("remove_arg_slots {"); |
710 | 286 // Pull up everything shallower than rax_argslot. |
287 // Then remove the excess space on the stack. | |
288 // The stacked return address gets pulled up with everything else. | |
289 // That is, copy [rsp, argslot) upward by size words. In pseudo-code: | |
290 // for (rdx = argslot-1; rdx >= rsp; --rdx) | |
291 // rdx[size] = rdx[0] | |
292 // argslot += size; | |
293 // rsp += size; | |
294 __ lea(rdx_temp, Address(rax_argslot, -wordSize)); // source pointer for copy | |
295 { | |
296 Label loop; | |
1793
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
297 __ BIND(loop); |
710 | 298 // pull one word up each time through the loop |
299 __ movptr(rbx_temp, Address(rdx_temp, 0)); | |
300 __ movptr(Address(rdx_temp, arg_slots, Address::times_ptr), rbx_temp); | |
301 __ addptr(rdx_temp, -wordSize); | |
302 __ cmpptr(rdx_temp, rsp); | |
1135
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1133
diff
changeset
|
303 __ jccb(Assembler::greaterEqual, loop); |
710 | 304 } |
305 | |
306 // Now move the argslot up, to point to the just-copied block. | |
307 __ lea(rsp, Address(rsp, arg_slots, Address::times_ptr)); | |
308 // And adjust the argslot address to point at the deletion point. | |
309 __ lea(rax_argslot, Address(rax_argslot, arg_slots, Address::times_ptr)); | |
1793
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
310 BLOCK_COMMENT("} remove_arg_slots"); |
710 | 311 } |
312 | |
313 #ifndef PRODUCT | |
1133
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1108
diff
changeset
|
314 extern "C" void print_method_handle(oop mh); |
710 | 315 void trace_method_handle_stub(const char* adaptername, |
1133
aa62b9388fce
6894206: JVM needs a way to traverse method handle structures
twisti
parents:
1108
diff
changeset
|
316 oop mh, |
1793
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
317 intptr_t* saved_regs, |
710 | 318 intptr_t* entry_sp, |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
319 intptr_t* saved_sp, |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
320 intptr_t* saved_bp) { |
710 | 321 // called as a leaf from native code: do not block the JVM! |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
322 intptr_t* last_sp = (intptr_t*) saved_bp[frame::interpreter_frame_last_sp_offset]; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
323 intptr_t* base_sp = (intptr_t*) saved_bp[frame::interpreter_frame_monitor_block_top_offset]; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
324 printf("MH %s mh="INTPTR_FORMAT" sp=("INTPTR_FORMAT"+"INTX_FORMAT") stack_size="INTX_FORMAT" bp="INTPTR_FORMAT"\n", |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
325 adaptername, (intptr_t)mh, (intptr_t)entry_sp, (intptr_t)(saved_sp - entry_sp), (intptr_t)(base_sp - last_sp), (intptr_t)saved_bp); |
1793
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
326 if (last_sp != saved_sp && last_sp != NULL) |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
327 printf("*** last_sp="INTPTR_FORMAT"\n", (intptr_t)last_sp); |
1793
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
328 if (Verbose) { |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
329 printf(" reg dump: "); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
330 int saved_regs_count = (entry_sp-1) - saved_regs; |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
331 // 32 bit: rdi rsi rbp rsp; rbx rdx rcx (*) rax |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
332 int i; |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
333 for (i = 0; i <= saved_regs_count; i++) { |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
334 if (i > 0 && i % 4 == 0 && i != saved_regs_count) |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
335 printf("\n + dump: "); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
336 printf(" %d: "INTPTR_FORMAT, i, saved_regs[i]); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
337 } |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
338 printf("\n"); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
339 int stack_dump_count = 16; |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
340 if (stack_dump_count < (int)(saved_bp + 2 - saved_sp)) |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
341 stack_dump_count = (int)(saved_bp + 2 - saved_sp); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
342 if (stack_dump_count > 64) stack_dump_count = 48; |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
343 for (i = 0; i < stack_dump_count; i += 4) { |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
344 printf(" dump at SP[%d] "INTPTR_FORMAT": "INTPTR_FORMAT" "INTPTR_FORMAT" "INTPTR_FORMAT" "INTPTR_FORMAT"\n", |
1818
c93c652551b5
6986944: JSR 292 assert(caller_nm->is_method_handle_return(caller_frame.pc())) failed: must be MH call site
twisti
parents:
1793
diff
changeset
|
345 i, (intptr_t) &entry_sp[i+0], entry_sp[i+0], entry_sp[i+1], entry_sp[i+2], entry_sp[i+3]); |
1793
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
346 } |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
347 print_method_handle(mh); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
348 } |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
349 } |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
350 void MethodHandles::trace_method_handle(MacroAssembler* _masm, const char* adaptername) { |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
351 if (!TraceMethodHandles) return; |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
352 BLOCK_COMMENT("trace_method_handle {"); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
353 __ push(rax); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
354 __ lea(rax, Address(rsp, wordSize*6)); // entry_sp |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
355 __ pusha(); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
356 // arguments: |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
357 __ push(rbp); // interpreter frame pointer |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
358 __ push(rsi); // saved_sp |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
359 __ push(rax); // entry_sp |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
360 __ push(rcx); // mh |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
361 __ push(rcx); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
362 __ movptr(Address(rsp, 0), (intptr_t) adaptername); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
363 __ call_VM_leaf(CAST_FROM_FN_PTR(address, trace_method_handle_stub), 5); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
364 __ popa(); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
365 __ pop(rax); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
366 BLOCK_COMMENT("} trace_method_handle"); |
710 | 367 } |
368 #endif //PRODUCT | |
369 | |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1506
diff
changeset
|
370 // which conversion op types are implemented here? |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1506
diff
changeset
|
371 int MethodHandles::adapter_conversion_ops_supported_mask() { |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1506
diff
changeset
|
372 return ((1<<sun_dyn_AdapterMethodHandle::OP_RETYPE_ONLY) |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1506
diff
changeset
|
373 |(1<<sun_dyn_AdapterMethodHandle::OP_RETYPE_RAW) |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1506
diff
changeset
|
374 |(1<<sun_dyn_AdapterMethodHandle::OP_CHECK_CAST) |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1506
diff
changeset
|
375 |(1<<sun_dyn_AdapterMethodHandle::OP_PRIM_TO_PRIM) |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1506
diff
changeset
|
376 |(1<<sun_dyn_AdapterMethodHandle::OP_REF_TO_PRIM) |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1506
diff
changeset
|
377 |(1<<sun_dyn_AdapterMethodHandle::OP_SWAP_ARGS) |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1506
diff
changeset
|
378 |(1<<sun_dyn_AdapterMethodHandle::OP_ROT_ARGS) |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1506
diff
changeset
|
379 |(1<<sun_dyn_AdapterMethodHandle::OP_DUP_ARGS) |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1506
diff
changeset
|
380 |(1<<sun_dyn_AdapterMethodHandle::OP_DROP_ARGS) |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1506
diff
changeset
|
381 //|(1<<sun_dyn_AdapterMethodHandle::OP_SPREAD_ARGS) //BUG! |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1506
diff
changeset
|
382 ); |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1506
diff
changeset
|
383 // FIXME: MethodHandlesTest gets a crash if we enable OP_SPREAD_ARGS. |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1506
diff
changeset
|
384 } |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1506
diff
changeset
|
385 |
710 | 386 // Generate an "entry" field for a method handle. |
387 // This determines how the method handle will respond to calls. | |
388 void MethodHandles::generate_method_handle_stub(MacroAssembler* _masm, MethodHandles::EntryKind ek) { | |
389 // Here is the register state during an interpreted call, | |
390 // as set up by generate_method_handle_interpreter_entry(): | |
391 // - rbx: garbage temp (was MethodHandle.invoke methodOop, unused) | |
392 // - rcx: receiver method handle | |
393 // - rax: method handle type (only used by the check_mtype entry point) | |
394 // - rsi/r13: sender SP (must preserve; see prepare_to_jump_from_interpreted) | |
395 // - rdx: garbage temp, can blow away | |
396 | |
397 Register rcx_recv = rcx; | |
398 Register rax_argslot = rax; | |
399 Register rbx_temp = rbx; | |
400 Register rdx_temp = rdx; | |
401 | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
402 // This guy is set up by prepare_to_jump_from_interpreted (from interpreted calls) |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
403 // and gen_c2i_adapter (from compiled calls): |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
404 Register saved_last_sp = LP64_ONLY(r13) NOT_LP64(rsi); |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
405 |
710 | 406 guarantee(java_dyn_MethodHandle::vmentry_offset_in_bytes() != 0, "must have offsets"); |
407 | |
408 // some handy addresses | |
409 Address rbx_method_fie( rbx, methodOopDesc::from_interpreted_offset() ); | |
410 | |
411 Address rcx_mh_vmtarget( rcx_recv, java_dyn_MethodHandle::vmtarget_offset_in_bytes() ); | |
412 Address rcx_dmh_vmindex( rcx_recv, sun_dyn_DirectMethodHandle::vmindex_offset_in_bytes() ); | |
413 | |
414 Address rcx_bmh_vmargslot( rcx_recv, sun_dyn_BoundMethodHandle::vmargslot_offset_in_bytes() ); | |
415 Address rcx_bmh_argument( rcx_recv, sun_dyn_BoundMethodHandle::argument_offset_in_bytes() ); | |
416 | |
417 Address rcx_amh_vmargslot( rcx_recv, sun_dyn_AdapterMethodHandle::vmargslot_offset_in_bytes() ); | |
418 Address rcx_amh_argument( rcx_recv, sun_dyn_AdapterMethodHandle::argument_offset_in_bytes() ); | |
419 Address rcx_amh_conversion( rcx_recv, sun_dyn_AdapterMethodHandle::conversion_offset_in_bytes() ); | |
420 Address vmarg; // __ argument_address(vmargslot) | |
421 | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
422 const int java_mirror_offset = klassOopDesc::klass_part_offset_in_bytes() + Klass::java_mirror_offset_in_bytes(); |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
423 |
710 | 424 if (have_entry(ek)) { |
425 __ nop(); // empty stubs make SG sick | |
426 return; | |
427 } | |
428 | |
429 address interp_entry = __ pc(); | |
430 | |
1793
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
431 trace_method_handle(_masm, entry_name(ek)); |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
432 |
d257356e35f0
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
1552
diff
changeset
|
433 BLOCK_COMMENT(entry_name(ek)); |
710 | 434 |
435 switch ((int) ek) { | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
436 case _raise_exception: |
710 | 437 { |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
438 // Not a real MH entry, but rather shared code for raising an exception. |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
439 // Extra local arguments are pushed on stack, as required type at TOS+8, |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
440 // failing object (or NULL) at TOS+4, failing bytecode type at TOS. |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
441 // Beyond those local arguments are the PC, of course. |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
442 Register rdx_code = rdx_temp; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
443 Register rcx_fail = rcx_recv; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
444 Register rax_want = rax_argslot; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
445 Register rdi_pc = rdi; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
446 __ pop(rdx_code); // TOS+0 |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
447 __ pop(rcx_fail); // TOS+4 |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
448 __ pop(rax_want); // TOS+8 |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
449 __ pop(rdi_pc); // caller PC |
710 | 450 |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
451 __ mov(rsp, rsi); // cut the stack back to where the caller started |
710 | 452 |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
453 // Repush the arguments as if coming from the interpreter. |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
454 __ push(rdx_code); |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
455 __ push(rcx_fail); |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
456 __ push(rax_want); |
710 | 457 |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
458 Register rbx_method = rbx_temp; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
459 Label no_method; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
460 // FIXME: fill in _raise_exception_method with a suitable sun.dyn method |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
461 __ movptr(rbx_method, ExternalAddress((address) &_raise_exception_method)); |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
462 __ testptr(rbx_method, rbx_method); |
1135
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1133
diff
changeset
|
463 __ jccb(Assembler::zero, no_method); |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
464 int jobject_oop_offset = 0; |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
465 __ movptr(rbx_method, Address(rbx_method, jobject_oop_offset)); // dereference the jobject |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
466 __ testptr(rbx_method, rbx_method); |
1135
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1133
diff
changeset
|
467 __ jccb(Assembler::zero, no_method); |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
468 __ verify_oop(rbx_method); |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
469 __ push(rdi_pc); // and restore caller PC |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
470 __ jmp(rbx_method_fie); |
710 | 471 |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
472 // If we get here, the Java runtime did not do its job of creating the exception. |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
473 // Do something that is at least causes a valid throw from the interpreter. |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
474 __ bind(no_method); |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
475 __ pop(rax_want); |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
476 __ pop(rcx_fail); |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
477 __ push(rax_want); |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
478 __ push(rcx_fail); |
710 | 479 __ jump(ExternalAddress(Interpreter::throw_WrongMethodType_entry())); |
480 } | |
481 break; | |
482 | |
483 case _invokestatic_mh: | |
484 case _invokespecial_mh: | |
485 { | |
486 Register rbx_method = rbx_temp; | |
1846 | 487 __ load_heap_oop(rbx_method, rcx_mh_vmtarget); // target is a methodOop |
710 | 488 __ verify_oop(rbx_method); |
489 // same as TemplateTable::invokestatic or invokespecial, | |
490 // minus the CP setup and profiling: | |
491 if (ek == _invokespecial_mh) { | |
492 // Must load & check the first argument before entering the target method. | |
493 __ load_method_handle_vmslots(rax_argslot, rcx_recv, rdx_temp); | |
494 __ movptr(rcx_recv, __ argument_address(rax_argslot, -1)); | |
495 __ null_check(rcx_recv); | |
496 __ verify_oop(rcx_recv); | |
497 } | |
498 __ jmp(rbx_method_fie); | |
499 } | |
500 break; | |
501 | |
502 case _invokevirtual_mh: | |
503 { | |
504 // same as TemplateTable::invokevirtual, | |
505 // minus the CP setup and profiling: | |
506 | |
507 // pick out the vtable index and receiver offset from the MH, | |
508 // and then we can discard it: | |
509 __ load_method_handle_vmslots(rax_argslot, rcx_recv, rdx_temp); | |
510 Register rbx_index = rbx_temp; | |
511 __ movl(rbx_index, rcx_dmh_vmindex); | |
512 // Note: The verifier allows us to ignore rcx_mh_vmtarget. | |
513 __ movptr(rcx_recv, __ argument_address(rax_argslot, -1)); | |
514 __ null_check(rcx_recv, oopDesc::klass_offset_in_bytes()); | |
515 | |
516 // get receiver klass | |
517 Register rax_klass = rax_argslot; | |
518 __ load_klass(rax_klass, rcx_recv); | |
519 __ verify_oop(rax_klass); | |
520 | |
521 // get target methodOop & entry point | |
522 const int base = instanceKlass::vtable_start_offset() * wordSize; | |
523 assert(vtableEntry::size() * wordSize == wordSize, "adjust the scaling in the code below"); | |
524 Address vtable_entry_addr(rax_klass, | |
525 rbx_index, Address::times_ptr, | |
526 base + vtableEntry::method_offset_in_bytes()); | |
527 Register rbx_method = rbx_temp; | |
1108 | 528 __ movptr(rbx_method, vtable_entry_addr); |
710 | 529 |
530 __ verify_oop(rbx_method); | |
531 __ jmp(rbx_method_fie); | |
532 } | |
533 break; | |
534 | |
535 case _invokeinterface_mh: | |
536 { | |
537 // same as TemplateTable::invokeinterface, | |
538 // minus the CP setup and profiling: | |
539 | |
540 // pick out the interface and itable index from the MH. | |
541 __ load_method_handle_vmslots(rax_argslot, rcx_recv, rdx_temp); | |
542 Register rdx_intf = rdx_temp; | |
543 Register rbx_index = rbx_temp; | |
1846 | 544 __ load_heap_oop(rdx_intf, rcx_mh_vmtarget); |
545 __ movl(rbx_index, rcx_dmh_vmindex); | |
710 | 546 __ movptr(rcx_recv, __ argument_address(rax_argslot, -1)); |
547 __ null_check(rcx_recv, oopDesc::klass_offset_in_bytes()); | |
548 | |
549 // get receiver klass | |
550 Register rax_klass = rax_argslot; | |
551 __ load_klass(rax_klass, rcx_recv); | |
552 __ verify_oop(rax_klass); | |
553 | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
554 Register rdi_temp = rdi; |
710 | 555 Register rbx_method = rbx_index; |
556 | |
557 // get interface klass | |
558 Label no_such_interface; | |
559 __ verify_oop(rdx_intf); | |
560 __ lookup_interface_method(rax_klass, rdx_intf, | |
561 // note: next two args must be the same: | |
562 rbx_index, rbx_method, | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
563 rdi_temp, |
710 | 564 no_such_interface); |
565 | |
566 __ verify_oop(rbx_method); | |
567 __ jmp(rbx_method_fie); | |
568 __ hlt(); | |
569 | |
570 __ bind(no_such_interface); | |
571 // Throw an exception. | |
572 // For historical reasons, it will be IncompatibleClassChangeError. | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
573 __ pushptr(Address(rdx_intf, java_mirror_offset)); // required interface |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
574 __ push(rcx_recv); // bad receiver |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
575 __ push((int)Bytecodes::_invokeinterface); // who is complaining? |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
576 __ jump(ExternalAddress(from_interpreted_entry(_raise_exception))); |
710 | 577 } |
578 break; | |
579 | |
580 case _bound_ref_mh: | |
581 case _bound_int_mh: | |
582 case _bound_long_mh: | |
583 case _bound_ref_direct_mh: | |
584 case _bound_int_direct_mh: | |
585 case _bound_long_direct_mh: | |
586 { | |
587 bool direct_to_method = (ek >= _bound_ref_direct_mh); | |
1304 | 588 BasicType arg_type = T_ILLEGAL; |
589 int arg_mask = _INSERT_NO_MASK; | |
590 int arg_slots = -1; | |
591 get_ek_bound_mh_info(ek, arg_type, arg_mask, arg_slots); | |
710 | 592 |
593 // make room for the new argument: | |
594 __ movl(rax_argslot, rcx_bmh_vmargslot); | |
595 __ lea(rax_argslot, __ argument_address(rax_argslot)); | |
596 insert_arg_slots(_masm, arg_slots * stack_move_unit(), arg_mask, | |
597 rax_argslot, rbx_temp, rdx_temp); | |
598 | |
599 // store bound argument into the new stack slot: | |
1846 | 600 __ load_heap_oop(rbx_temp, rcx_bmh_argument); |
710 | 601 Address prim_value_addr(rbx_temp, java_lang_boxing_object::value_offset_in_bytes(arg_type)); |
602 if (arg_type == T_OBJECT) { | |
603 __ movptr(Address(rax_argslot, 0), rbx_temp); | |
604 } else { | |
1135
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1133
diff
changeset
|
605 __ load_sized_value(rdx_temp, prim_value_addr, |
710 | 606 type2aelembytes(arg_type), is_signed_subword_type(arg_type)); |
1135
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1133
diff
changeset
|
607 __ movptr(Address(rax_argslot, 0), rdx_temp); |
710 | 608 #ifndef _LP64 |
609 if (arg_slots == 2) { | |
1135
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1133
diff
changeset
|
610 __ movl(rdx_temp, prim_value_addr.plus_disp(wordSize)); |
1506 | 611 __ movl(Address(rax_argslot, Interpreter::stackElementSize), rdx_temp); |
710 | 612 } |
613 #endif //_LP64 | |
614 } | |
615 | |
616 if (direct_to_method) { | |
617 Register rbx_method = rbx_temp; | |
1846 | 618 __ load_heap_oop(rbx_method, rcx_mh_vmtarget); |
710 | 619 __ verify_oop(rbx_method); |
620 __ jmp(rbx_method_fie); | |
621 } else { | |
1846 | 622 __ load_heap_oop(rcx_recv, rcx_mh_vmtarget); |
710 | 623 __ verify_oop(rcx_recv); |
624 __ jump_to_method_handle_entry(rcx_recv, rdx_temp); | |
625 } | |
626 } | |
627 break; | |
628 | |
629 case _adapter_retype_only: | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
630 case _adapter_retype_raw: |
710 | 631 // immediately jump to the next MH layer: |
1846 | 632 __ load_heap_oop(rcx_recv, rcx_mh_vmtarget); |
710 | 633 __ verify_oop(rcx_recv); |
634 __ jump_to_method_handle_entry(rcx_recv, rdx_temp); | |
635 // This is OK when all parameter types widen. | |
636 // It is also OK when a return type narrows. | |
637 break; | |
638 | |
639 case _adapter_check_cast: | |
640 { | |
641 // temps: | |
642 Register rbx_klass = rbx_temp; // interesting AMH data | |
643 | |
644 // check a reference argument before jumping to the next layer of MH: | |
645 __ movl(rax_argslot, rcx_amh_vmargslot); | |
646 vmarg = __ argument_address(rax_argslot); | |
647 | |
648 // What class are we casting to? | |
1846 | 649 __ load_heap_oop(rbx_klass, rcx_amh_argument); // this is a Class object! |
650 __ load_heap_oop(rbx_klass, Address(rbx_klass, java_lang_Class::klass_offset_in_bytes())); | |
710 | 651 |
652 Label done; | |
653 __ movptr(rdx_temp, vmarg); | |
1277 | 654 __ testptr(rdx_temp, rdx_temp); |
1846 | 655 __ jcc(Assembler::zero, done); // no cast if null |
710 | 656 __ load_klass(rdx_temp, rdx_temp); |
657 | |
658 // live at this point: | |
659 // - rbx_klass: klass required by the target method | |
660 // - rdx_temp: argument klass to test | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
661 // - rcx_recv: adapter method handle |
710 | 662 __ check_klass_subtype(rdx_temp, rbx_klass, rax_argslot, done); |
663 | |
664 // If we get here, the type check failed! | |
665 // Call the wrong_method_type stub, passing the failing argument type in rax. | |
666 Register rax_mtype = rax_argslot; | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
667 __ movl(rax_argslot, rcx_amh_vmargslot); // reload argslot field |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
668 __ movptr(rdx_temp, vmarg); |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
669 |
1846 | 670 __ load_heap_oop(rbx_klass, rcx_amh_argument); // required class |
671 __ push(rbx_klass); | |
672 __ push(rdx_temp); // bad object | |
673 __ push((int)Bytecodes::_checkcast); // who is complaining? | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
674 __ jump(ExternalAddress(from_interpreted_entry(_raise_exception))); |
710 | 675 |
676 __ bind(done); | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
677 // get the new MH: |
1846 | 678 __ load_heap_oop(rcx_recv, rcx_mh_vmtarget); |
710 | 679 __ jump_to_method_handle_entry(rcx_recv, rdx_temp); |
680 } | |
681 break; | |
682 | |
683 case _adapter_prim_to_prim: | |
684 case _adapter_ref_to_prim: | |
685 // handled completely by optimized cases | |
686 __ stop("init_AdapterMethodHandle should not issue this"); | |
687 break; | |
688 | |
689 case _adapter_opt_i2i: // optimized subcase of adapt_prim_to_prim | |
690 //case _adapter_opt_f2i: // optimized subcase of adapt_prim_to_prim | |
691 case _adapter_opt_l2i: // optimized subcase of adapt_prim_to_prim | |
692 case _adapter_opt_unboxi: // optimized subcase of adapt_ref_to_prim | |
693 { | |
694 // perform an in-place conversion to int or an int subword | |
695 __ movl(rax_argslot, rcx_amh_vmargslot); | |
696 vmarg = __ argument_address(rax_argslot); | |
697 | |
698 switch (ek) { | |
699 case _adapter_opt_i2i: | |
700 __ movl(rdx_temp, vmarg); | |
701 break; | |
702 case _adapter_opt_l2i: | |
703 { | |
704 // just delete the extra slot; on a little-endian machine we keep the first | |
705 __ lea(rax_argslot, __ argument_address(rax_argslot, 1)); | |
706 remove_arg_slots(_masm, -stack_move_unit(), | |
707 rax_argslot, rbx_temp, rdx_temp); | |
1506 | 708 vmarg = Address(rax_argslot, -Interpreter::stackElementSize); |
710 | 709 __ movl(rdx_temp, vmarg); |
710 } | |
711 break; | |
712 case _adapter_opt_unboxi: | |
713 { | |
714 // Load the value up from the heap. | |
715 __ movptr(rdx_temp, vmarg); | |
716 int value_offset = java_lang_boxing_object::value_offset_in_bytes(T_INT); | |
717 #ifdef ASSERT | |
718 for (int bt = T_BOOLEAN; bt < T_INT; bt++) { | |
719 if (is_subword_type(BasicType(bt))) | |
720 assert(value_offset == java_lang_boxing_object::value_offset_in_bytes(BasicType(bt)), ""); | |
721 } | |
722 #endif | |
723 __ null_check(rdx_temp, value_offset); | |
724 __ movl(rdx_temp, Address(rdx_temp, value_offset)); | |
725 // We load this as a word. Because we are little-endian, | |
726 // the low bits will be correct, but the high bits may need cleaning. | |
727 // The vminfo will guide us to clean those bits. | |
728 } | |
729 break; | |
730 default: | |
1304 | 731 ShouldNotReachHere(); |
710 | 732 } |
733 | |
1304 | 734 // Do the requested conversion and store the value. |
710 | 735 Register rbx_vminfo = rbx_temp; |
736 __ movl(rbx_vminfo, rcx_amh_conversion); | |
737 assert(CONV_VMINFO_SHIFT == 0, "preshifted"); | |
738 | |
739 // get the new MH: | |
1846 | 740 __ load_heap_oop(rcx_recv, rcx_mh_vmtarget); |
710 | 741 // (now we are done with the old MH) |
742 | |
743 // original 32-bit vmdata word must be of this form: | |
1135
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1133
diff
changeset
|
744 // | MBZ:6 | signBitCount:8 | srcDstTypes:8 | conversionOp:8 | |
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1133
diff
changeset
|
745 __ xchgptr(rcx, rbx_vminfo); // free rcx for shifts |
710 | 746 __ shll(rdx_temp /*, rcx*/); |
747 Label zero_extend, done; | |
748 __ testl(rcx, CONV_VMINFO_SIGN_FLAG); | |
1135
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1133
diff
changeset
|
749 __ jccb(Assembler::zero, zero_extend); |
710 | 750 |
751 // this path is taken for int->byte, int->short | |
752 __ sarl(rdx_temp /*, rcx*/); | |
1135
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1133
diff
changeset
|
753 __ jmpb(done); |
710 | 754 |
755 __ bind(zero_extend); | |
756 // this is taken for int->char | |
757 __ shrl(rdx_temp /*, rcx*/); | |
758 | |
759 __ bind(done); | |
1304 | 760 __ movl(vmarg, rdx_temp); // Store the value. |
1135
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1133
diff
changeset
|
761 __ xchgptr(rcx, rbx_vminfo); // restore rcx_recv |
710 | 762 |
763 __ jump_to_method_handle_entry(rcx_recv, rdx_temp); | |
764 } | |
765 break; | |
766 | |
767 case _adapter_opt_i2l: // optimized subcase of adapt_prim_to_prim | |
768 case _adapter_opt_unboxl: // optimized subcase of adapt_ref_to_prim | |
769 { | |
770 // perform an in-place int-to-long or ref-to-long conversion | |
771 __ movl(rax_argslot, rcx_amh_vmargslot); | |
772 | |
773 // on a little-endian machine we keep the first slot and add another after | |
774 __ lea(rax_argslot, __ argument_address(rax_argslot, 1)); | |
775 insert_arg_slots(_masm, stack_move_unit(), _INSERT_INT_MASK, | |
776 rax_argslot, rbx_temp, rdx_temp); | |
1506 | 777 Address vmarg1(rax_argslot, -Interpreter::stackElementSize); |
778 Address vmarg2 = vmarg1.plus_disp(Interpreter::stackElementSize); | |
710 | 779 |
780 switch (ek) { | |
781 case _adapter_opt_i2l: | |
782 { | |
1293
51db1e4b379d
6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents:
1277
diff
changeset
|
783 #ifdef _LP64 |
51db1e4b379d
6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents:
1277
diff
changeset
|
784 __ movslq(rdx_temp, vmarg1); // Load sign-extended |
51db1e4b379d
6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents:
1277
diff
changeset
|
785 __ movq(vmarg1, rdx_temp); // Store into first slot |
51db1e4b379d
6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents:
1277
diff
changeset
|
786 #else |
710 | 787 __ movl(rdx_temp, vmarg1); |
1293
51db1e4b379d
6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents:
1277
diff
changeset
|
788 __ sarl(rdx_temp, BitsPerInt - 1); // __ extend_sign() |
710 | 789 __ movl(vmarg2, rdx_temp); // store second word |
1293
51db1e4b379d
6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents:
1277
diff
changeset
|
790 #endif |
710 | 791 } |
792 break; | |
793 case _adapter_opt_unboxl: | |
794 { | |
795 // Load the value up from the heap. | |
796 __ movptr(rdx_temp, vmarg1); | |
797 int value_offset = java_lang_boxing_object::value_offset_in_bytes(T_LONG); | |
798 assert(value_offset == java_lang_boxing_object::value_offset_in_bytes(T_DOUBLE), ""); | |
799 __ null_check(rdx_temp, value_offset); | |
1293
51db1e4b379d
6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents:
1277
diff
changeset
|
800 #ifdef _LP64 |
51db1e4b379d
6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents:
1277
diff
changeset
|
801 __ movq(rbx_temp, Address(rdx_temp, value_offset)); |
51db1e4b379d
6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents:
1277
diff
changeset
|
802 __ movq(vmarg1, rbx_temp); |
51db1e4b379d
6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents:
1277
diff
changeset
|
803 #else |
710 | 804 __ movl(rbx_temp, Address(rdx_temp, value_offset + 0*BytesPerInt)); |
805 __ movl(rdx_temp, Address(rdx_temp, value_offset + 1*BytesPerInt)); | |
806 __ movl(vmarg1, rbx_temp); | |
807 __ movl(vmarg2, rdx_temp); | |
1293
51db1e4b379d
6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents:
1277
diff
changeset
|
808 #endif |
710 | 809 } |
810 break; | |
811 default: | |
1304 | 812 ShouldNotReachHere(); |
710 | 813 } |
814 | |
1846 | 815 __ load_heap_oop(rcx_recv, rcx_mh_vmtarget); |
710 | 816 __ jump_to_method_handle_entry(rcx_recv, rdx_temp); |
817 } | |
818 break; | |
819 | |
820 case _adapter_opt_f2d: // optimized subcase of adapt_prim_to_prim | |
821 case _adapter_opt_d2f: // optimized subcase of adapt_prim_to_prim | |
822 { | |
823 // perform an in-place floating primitive conversion | |
824 __ movl(rax_argslot, rcx_amh_vmargslot); | |
825 __ lea(rax_argslot, __ argument_address(rax_argslot, 1)); | |
826 if (ek == _adapter_opt_f2d) { | |
827 insert_arg_slots(_masm, stack_move_unit(), _INSERT_INT_MASK, | |
828 rax_argslot, rbx_temp, rdx_temp); | |
829 } | |
1506 | 830 Address vmarg(rax_argslot, -Interpreter::stackElementSize); |
710 | 831 |
832 #ifdef _LP64 | |
833 if (ek == _adapter_opt_f2d) { | |
834 __ movflt(xmm0, vmarg); | |
835 __ cvtss2sd(xmm0, xmm0); | |
836 __ movdbl(vmarg, xmm0); | |
837 } else { | |
838 __ movdbl(xmm0, vmarg); | |
839 __ cvtsd2ss(xmm0, xmm0); | |
840 __ movflt(vmarg, xmm0); | |
841 } | |
842 #else //_LP64 | |
843 if (ek == _adapter_opt_f2d) { | |
844 __ fld_s(vmarg); // load float to ST0 | |
845 __ fstp_s(vmarg); // store single | |
1304 | 846 } else { |
710 | 847 __ fld_d(vmarg); // load double to ST0 |
848 __ fstp_s(vmarg); // store single | |
849 } | |
850 #endif //_LP64 | |
851 | |
852 if (ek == _adapter_opt_d2f) { | |
853 remove_arg_slots(_masm, -stack_move_unit(), | |
854 rax_argslot, rbx_temp, rdx_temp); | |
855 } | |
856 | |
1846 | 857 __ load_heap_oop(rcx_recv, rcx_mh_vmtarget); |
710 | 858 __ jump_to_method_handle_entry(rcx_recv, rdx_temp); |
859 } | |
860 break; | |
861 | |
862 case _adapter_prim_to_ref: | |
863 __ unimplemented(entry_name(ek)); // %%% FIXME: NYI | |
864 break; | |
865 | |
866 case _adapter_swap_args: | |
867 case _adapter_rot_args: | |
868 // handled completely by optimized cases | |
869 __ stop("init_AdapterMethodHandle should not issue this"); | |
870 break; | |
871 | |
872 case _adapter_opt_swap_1: | |
873 case _adapter_opt_swap_2: | |
874 case _adapter_opt_rot_1_up: | |
875 case _adapter_opt_rot_1_down: | |
876 case _adapter_opt_rot_2_up: | |
877 case _adapter_opt_rot_2_down: | |
878 { | |
1304 | 879 int swap_bytes = 0, rotate = 0; |
880 get_ek_adapter_opt_swap_rot_info(ek, swap_bytes, rotate); | |
710 | 881 |
882 // 'argslot' is the position of the first argument to swap | |
883 __ movl(rax_argslot, rcx_amh_vmargslot); | |
884 __ lea(rax_argslot, __ argument_address(rax_argslot)); | |
885 | |
886 // 'vminfo' is the second | |
887 Register rbx_destslot = rbx_temp; | |
888 __ movl(rbx_destslot, rcx_amh_conversion); | |
889 assert(CONV_VMINFO_SHIFT == 0, "preshifted"); | |
890 __ andl(rbx_destslot, CONV_VMINFO_MASK); | |
891 __ lea(rbx_destslot, __ argument_address(rbx_destslot)); | |
892 DEBUG_ONLY(verify_argslot(_masm, rbx_destslot, "swap point must fall within current frame")); | |
893 | |
894 if (!rotate) { | |
895 for (int i = 0; i < swap_bytes; i += wordSize) { | |
896 __ movptr(rdx_temp, Address(rax_argslot , i)); | |
897 __ push(rdx_temp); | |
898 __ movptr(rdx_temp, Address(rbx_destslot, i)); | |
899 __ movptr(Address(rax_argslot, i), rdx_temp); | |
900 __ pop(rdx_temp); | |
901 __ movptr(Address(rbx_destslot, i), rdx_temp); | |
902 } | |
903 } else { | |
904 // push the first chunk, which is going to get overwritten | |
905 for (int i = swap_bytes; (i -= wordSize) >= 0; ) { | |
906 __ movptr(rdx_temp, Address(rax_argslot, i)); | |
907 __ push(rdx_temp); | |
908 } | |
909 | |
910 if (rotate > 0) { | |
911 // rotate upward | |
912 __ subptr(rax_argslot, swap_bytes); | |
913 #ifdef ASSERT | |
914 { | |
915 // Verify that argslot > destslot, by at least swap_bytes. | |
916 Label L_ok; | |
917 __ cmpptr(rax_argslot, rbx_destslot); | |
1135
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1133
diff
changeset
|
918 __ jccb(Assembler::aboveEqual, L_ok); |
710 | 919 __ stop("source must be above destination (upward rotation)"); |
920 __ bind(L_ok); | |
921 } | |
922 #endif | |
923 // work argslot down to destslot, copying contiguous data upwards | |
924 // pseudo-code: | |
925 // rax = src_addr - swap_bytes | |
926 // rbx = dest_addr | |
927 // while (rax >= rbx) *(rax + swap_bytes) = *(rax + 0), rax--; | |
928 Label loop; | |
929 __ bind(loop); | |
930 __ movptr(rdx_temp, Address(rax_argslot, 0)); | |
931 __ movptr(Address(rax_argslot, swap_bytes), rdx_temp); | |
932 __ addptr(rax_argslot, -wordSize); | |
933 __ cmpptr(rax_argslot, rbx_destslot); | |
1135
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1133
diff
changeset
|
934 __ jccb(Assembler::aboveEqual, loop); |
710 | 935 } else { |
936 __ addptr(rax_argslot, swap_bytes); | |
937 #ifdef ASSERT | |
938 { | |
939 // Verify that argslot < destslot, by at least swap_bytes. | |
940 Label L_ok; | |
941 __ cmpptr(rax_argslot, rbx_destslot); | |
1135
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1133
diff
changeset
|
942 __ jccb(Assembler::belowEqual, L_ok); |
710 | 943 __ stop("source must be below destination (downward rotation)"); |
944 __ bind(L_ok); | |
945 } | |
946 #endif | |
947 // work argslot up to destslot, copying contiguous data downwards | |
948 // pseudo-code: | |
949 // rax = src_addr + swap_bytes | |
950 // rbx = dest_addr | |
951 // while (rax <= rbx) *(rax - swap_bytes) = *(rax + 0), rax++; | |
952 Label loop; | |
953 __ bind(loop); | |
954 __ movptr(rdx_temp, Address(rax_argslot, 0)); | |
955 __ movptr(Address(rax_argslot, -swap_bytes), rdx_temp); | |
956 __ addptr(rax_argslot, wordSize); | |
957 __ cmpptr(rax_argslot, rbx_destslot); | |
1135
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1133
diff
changeset
|
958 __ jccb(Assembler::belowEqual, loop); |
710 | 959 } |
960 | |
961 // pop the original first chunk into the destination slot, now free | |
962 for (int i = 0; i < swap_bytes; i += wordSize) { | |
963 __ pop(rdx_temp); | |
964 __ movptr(Address(rbx_destslot, i), rdx_temp); | |
965 } | |
966 } | |
967 | |
1846 | 968 __ load_heap_oop(rcx_recv, rcx_mh_vmtarget); |
710 | 969 __ jump_to_method_handle_entry(rcx_recv, rdx_temp); |
970 } | |
971 break; | |
972 | |
973 case _adapter_dup_args: | |
974 { | |
975 // 'argslot' is the position of the first argument to duplicate | |
976 __ movl(rax_argslot, rcx_amh_vmargslot); | |
977 __ lea(rax_argslot, __ argument_address(rax_argslot)); | |
978 | |
979 // 'stack_move' is negative number of words to duplicate | |
980 Register rdx_stack_move = rdx_temp; | |
1293
51db1e4b379d
6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents:
1277
diff
changeset
|
981 __ movl2ptr(rdx_stack_move, rcx_amh_conversion); |
51db1e4b379d
6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents:
1277
diff
changeset
|
982 __ sarptr(rdx_stack_move, CONV_STACK_MOVE_SHIFT); |
710 | 983 |
984 int argslot0_num = 0; | |
985 Address argslot0 = __ argument_address(RegisterOrConstant(argslot0_num)); | |
986 assert(argslot0.base() == rsp, ""); | |
987 int pre_arg_size = argslot0.disp(); | |
988 assert(pre_arg_size % wordSize == 0, ""); | |
989 assert(pre_arg_size > 0, "must include PC"); | |
990 | |
991 // remember the old rsp+1 (argslot[0]) | |
992 Register rbx_oldarg = rbx_temp; | |
993 __ lea(rbx_oldarg, argslot0); | |
994 | |
995 // move rsp down to make room for dups | |
996 __ lea(rsp, Address(rsp, rdx_stack_move, Address::times_ptr)); | |
997 | |
998 // compute the new rsp+1 (argslot[0]) | |
999 Register rdx_newarg = rdx_temp; | |
1000 __ lea(rdx_newarg, argslot0); | |
1001 | |
1002 __ push(rdi); // need a temp | |
1003 // (preceding push must be done after arg addresses are taken!) | |
1004 | |
1005 // pull down the pre_arg_size data (PC) | |
1006 for (int i = -pre_arg_size; i < 0; i += wordSize) { | |
1007 __ movptr(rdi, Address(rbx_oldarg, i)); | |
1008 __ movptr(Address(rdx_newarg, i), rdi); | |
1009 } | |
1010 | |
1011 // copy from rax_argslot[0...] down to new_rsp[1...] | |
1012 // pseudo-code: | |
1013 // rbx = old_rsp+1 | |
1014 // rdx = new_rsp+1 | |
1015 // rax = argslot | |
1016 // while (rdx < rbx) *rdx++ = *rax++ | |
1017 Label loop; | |
1018 __ bind(loop); | |
1019 __ movptr(rdi, Address(rax_argslot, 0)); | |
1020 __ movptr(Address(rdx_newarg, 0), rdi); | |
1021 __ addptr(rax_argslot, wordSize); | |
1022 __ addptr(rdx_newarg, wordSize); | |
1023 __ cmpptr(rdx_newarg, rbx_oldarg); | |
1135
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1133
diff
changeset
|
1024 __ jccb(Assembler::less, loop); |
710 | 1025 |
1026 __ pop(rdi); // restore temp | |
1027 | |
1846 | 1028 __ load_heap_oop(rcx_recv, rcx_mh_vmtarget); |
710 | 1029 __ jump_to_method_handle_entry(rcx_recv, rdx_temp); |
1030 } | |
1031 break; | |
1032 | |
1033 case _adapter_drop_args: | |
1034 { | |
1035 // 'argslot' is the position of the first argument to nuke | |
1036 __ movl(rax_argslot, rcx_amh_vmargslot); | |
1037 __ lea(rax_argslot, __ argument_address(rax_argslot)); | |
1038 | |
1039 __ push(rdi); // need a temp | |
1040 // (must do previous push after argslot address is taken) | |
1041 | |
1042 // 'stack_move' is number of words to drop | |
1043 Register rdi_stack_move = rdi; | |
1293
51db1e4b379d
6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents:
1277
diff
changeset
|
1044 __ movl2ptr(rdi_stack_move, rcx_amh_conversion); |
51db1e4b379d
6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents:
1277
diff
changeset
|
1045 __ sarptr(rdi_stack_move, CONV_STACK_MOVE_SHIFT); |
710 | 1046 remove_arg_slots(_masm, rdi_stack_move, |
1047 rax_argslot, rbx_temp, rdx_temp); | |
1048 | |
1049 __ pop(rdi); // restore temp | |
1050 | |
1846 | 1051 __ load_heap_oop(rcx_recv, rcx_mh_vmtarget); |
710 | 1052 __ jump_to_method_handle_entry(rcx_recv, rdx_temp); |
1053 } | |
1054 break; | |
1055 | |
1056 case _adapter_collect_args: | |
1057 __ unimplemented(entry_name(ek)); // %%% FIXME: NYI | |
1058 break; | |
1059 | |
1060 case _adapter_spread_args: | |
1061 // handled completely by optimized cases | |
1062 __ stop("init_AdapterMethodHandle should not issue this"); | |
1063 break; | |
1064 | |
1065 case _adapter_opt_spread_0: | |
1066 case _adapter_opt_spread_1: | |
1067 case _adapter_opt_spread_more: | |
1068 { | |
1069 // spread an array out into a group of arguments | |
1304 | 1070 int length_constant = get_ek_adapter_opt_spread_info(ek); |
710 | 1071 |
1072 // find the address of the array argument | |
1073 __ movl(rax_argslot, rcx_amh_vmargslot); | |
1074 __ lea(rax_argslot, __ argument_address(rax_argslot)); | |
1075 | |
1076 // grab some temps | |
1077 { __ push(rsi); __ push(rdi); } | |
1078 // (preceding pushes must be done after argslot address is taken!) | |
1079 #define UNPUSH_RSI_RDI \ | |
1080 { __ pop(rdi); __ pop(rsi); } | |
1081 | |
1082 // arx_argslot points both to the array and to the first output arg | |
1083 vmarg = Address(rax_argslot, 0); | |
1084 | |
1085 // Get the array value. | |
1086 Register rsi_array = rsi; | |
1087 Register rdx_array_klass = rdx_temp; | |
1088 BasicType elem_type = T_OBJECT; | |
1089 int length_offset = arrayOopDesc::length_offset_in_bytes(); | |
1090 int elem0_offset = arrayOopDesc::base_offset_in_bytes(elem_type); | |
1091 __ movptr(rsi_array, vmarg); | |
1092 Label skip_array_check; | |
1093 if (length_constant == 0) { | |
1094 __ testptr(rsi_array, rsi_array); | |
1095 __ jcc(Assembler::zero, skip_array_check); | |
1096 } | |
1097 __ null_check(rsi_array, oopDesc::klass_offset_in_bytes()); | |
1098 __ load_klass(rdx_array_klass, rsi_array); | |
1099 | |
1100 // Check the array type. | |
1101 Register rbx_klass = rbx_temp; | |
1846 | 1102 __ load_heap_oop(rbx_klass, rcx_amh_argument); // this is a Class object! |
1103 __ load_heap_oop(rbx_klass, Address(rbx_klass, java_lang_Class::klass_offset_in_bytes())); | |
710 | 1104 |
1105 Label ok_array_klass, bad_array_klass, bad_array_length; | |
1106 __ check_klass_subtype(rdx_array_klass, rbx_klass, rdi, ok_array_klass); | |
1107 // If we get here, the type check failed! | |
1108 __ jmp(bad_array_klass); | |
1109 __ bind(ok_array_klass); | |
1110 | |
1111 // Check length. | |
1112 if (length_constant >= 0) { | |
1113 __ cmpl(Address(rsi_array, length_offset), length_constant); | |
1114 } else { | |
1115 Register rbx_vminfo = rbx_temp; | |
1116 __ movl(rbx_vminfo, rcx_amh_conversion); | |
1117 assert(CONV_VMINFO_SHIFT == 0, "preshifted"); | |
1118 __ andl(rbx_vminfo, CONV_VMINFO_MASK); | |
1119 __ cmpl(rbx_vminfo, Address(rsi_array, length_offset)); | |
1120 } | |
1121 __ jcc(Assembler::notEqual, bad_array_length); | |
1122 | |
1123 Register rdx_argslot_limit = rdx_temp; | |
1124 | |
1125 // Array length checks out. Now insert any required stack slots. | |
1126 if (length_constant == -1) { | |
1127 // Form a pointer to the end of the affected region. | |
1506 | 1128 __ lea(rdx_argslot_limit, Address(rax_argslot, Interpreter::stackElementSize)); |
710 | 1129 // 'stack_move' is negative number of words to insert |
1130 Register rdi_stack_move = rdi; | |
1293
51db1e4b379d
6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents:
1277
diff
changeset
|
1131 __ movl2ptr(rdi_stack_move, rcx_amh_conversion); |
51db1e4b379d
6932536: JSR 292 modified JDK MethodHandlesTest fails on x86_64
twisti
parents:
1277
diff
changeset
|
1132 __ sarptr(rdi_stack_move, CONV_STACK_MOVE_SHIFT); |
710 | 1133 Register rsi_temp = rsi_array; // spill this |
1134 insert_arg_slots(_masm, rdi_stack_move, -1, | |
1135 rax_argslot, rbx_temp, rsi_temp); | |
1136 // reload the array (since rsi was killed) | |
1137 __ movptr(rsi_array, vmarg); | |
1138 } else if (length_constant > 1) { | |
1139 int arg_mask = 0; | |
1140 int new_slots = (length_constant - 1); | |
1141 for (int i = 0; i < new_slots; i++) { | |
1142 arg_mask <<= 1; | |
1143 arg_mask |= _INSERT_REF_MASK; | |
1144 } | |
1145 insert_arg_slots(_masm, new_slots * stack_move_unit(), arg_mask, | |
1146 rax_argslot, rbx_temp, rdx_temp); | |
1147 } else if (length_constant == 1) { | |
1148 // no stack resizing required | |
1149 } else if (length_constant == 0) { | |
1150 remove_arg_slots(_masm, -stack_move_unit(), | |
1151 rax_argslot, rbx_temp, rdx_temp); | |
1152 } | |
1153 | |
1154 // Copy from the array to the new slots. | |
1155 // Note: Stack change code preserves integrity of rax_argslot pointer. | |
1156 // So even after slot insertions, rax_argslot still points to first argument. | |
1157 if (length_constant == -1) { | |
1158 // [rax_argslot, rdx_argslot_limit) is the area we are inserting into. | |
1159 Register rsi_source = rsi_array; | |
1160 __ lea(rsi_source, Address(rsi_array, elem0_offset)); | |
1161 Label loop; | |
1162 __ bind(loop); | |
1163 __ movptr(rbx_temp, Address(rsi_source, 0)); | |
1164 __ movptr(Address(rax_argslot, 0), rbx_temp); | |
1165 __ addptr(rsi_source, type2aelembytes(elem_type)); | |
1506 | 1166 __ addptr(rax_argslot, Interpreter::stackElementSize); |
710 | 1167 __ cmpptr(rax_argslot, rdx_argslot_limit); |
1135
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1133
diff
changeset
|
1168 __ jccb(Assembler::less, loop); |
710 | 1169 } else if (length_constant == 0) { |
1170 __ bind(skip_array_check); | |
1171 // nothing to copy | |
1172 } else { | |
1173 int elem_offset = elem0_offset; | |
1174 int slot_offset = 0; | |
1175 for (int index = 0; index < length_constant; index++) { | |
1176 __ movptr(rbx_temp, Address(rsi_array, elem_offset)); | |
1177 __ movptr(Address(rax_argslot, slot_offset), rbx_temp); | |
1178 elem_offset += type2aelembytes(elem_type); | |
1506 | 1179 slot_offset += Interpreter::stackElementSize; |
710 | 1180 } |
1181 } | |
1182 | |
1183 // Arguments are spread. Move to next method handle. | |
1184 UNPUSH_RSI_RDI; | |
1846 | 1185 __ load_heap_oop(rcx_recv, rcx_mh_vmtarget); |
710 | 1186 __ jump_to_method_handle_entry(rcx_recv, rdx_temp); |
1187 | |
1188 __ bind(bad_array_klass); | |
1189 UNPUSH_RSI_RDI; | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
1190 __ pushptr(Address(rdx_array_klass, java_mirror_offset)); // required type |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
1191 __ pushptr(vmarg); // bad array |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
1192 __ push((int)Bytecodes::_aaload); // who is complaining? |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
1193 __ jump(ExternalAddress(from_interpreted_entry(_raise_exception))); |
710 | 1194 |
1195 __ bind(bad_array_length); | |
1196 UNPUSH_RSI_RDI; | |
1039
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
1197 __ push(rcx_recv); // AMH requiring a certain length |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
1198 __ pushptr(vmarg); // bad array |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
1199 __ push((int)Bytecodes::_arraylength); // who is complaining? |
987e948ebbc8
6815692: method handle code needs some cleanup (post-6655638)
jrose
parents:
845
diff
changeset
|
1200 __ jump(ExternalAddress(from_interpreted_entry(_raise_exception))); |
710 | 1201 |
1202 #undef UNPUSH_RSI_RDI | |
1203 } | |
1204 break; | |
1205 | |
1206 case _adapter_flyby: | |
1207 case _adapter_ricochet: | |
1208 __ unimplemented(entry_name(ek)); // %%% FIXME: NYI | |
1209 break; | |
1210 | |
1211 default: ShouldNotReachHere(); | |
1212 } | |
1213 __ hlt(); | |
1214 | |
1215 address me_cookie = MethodHandleEntry::start_compiled_entry(_masm, interp_entry); | |
1216 __ unimplemented(entry_name(ek)); // %%% FIXME: NYI | |
1217 | |
1218 init_entry(ek, MethodHandleEntry::finish_compiled_entry(_masm, me_cookie)); | |
1219 } |