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