Print this page
Split |
Close |
Expand all |
Collapse all |
--- old/src/cpu/x86/vm/interp_masm_x86_64.cpp
+++ new/src/cpu/x86/vm/interp_masm_x86_64.cpp
1 1 /*
2 2 * Copyright (c) 2003, 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 "interp_masm_x86_64.hpp"
27 27 #include "interpreter/interpreter.hpp"
28 28 #include "interpreter/interpreterRuntime.hpp"
29 29 #include "oops/arrayOop.hpp"
30 30 #include "oops/markOop.hpp"
31 31 #include "oops/methodDataOop.hpp"
32 32 #include "oops/methodOop.hpp"
33 33 #include "prims/jvmtiExport.hpp"
34 34 #include "prims/jvmtiRedefineClassesTrace.hpp"
35 35 #include "prims/jvmtiThreadState.hpp"
36 36 #include "runtime/basicLock.hpp"
37 37 #include "runtime/biasedLocking.hpp"
38 38 #include "runtime/sharedRuntime.hpp"
39 39 #ifdef TARGET_OS_FAMILY_linux
40 40 # include "thread_linux.inline.hpp"
41 41 #endif
42 42 #ifdef TARGET_OS_FAMILY_solaris
43 43 # include "thread_solaris.inline.hpp"
44 44 #endif
45 45 #ifdef TARGET_OS_FAMILY_windows
46 46 # include "thread_windows.inline.hpp"
47 47 #endif
48 48
49 49
50 50 // Implementation of InterpreterMacroAssembler
51 51
52 52 #ifdef CC_INTERP
53 53 void InterpreterMacroAssembler::get_method(Register reg) {
54 54 movptr(reg, Address(rbp, -((int)sizeof(BytecodeInterpreter) + 2 * wordSize)));
55 55 movptr(reg, Address(reg, byte_offset_of(BytecodeInterpreter, _method)));
56 56 }
57 57 #endif // CC_INTERP
58 58
59 59 #ifndef CC_INTERP
60 60
61 61 void InterpreterMacroAssembler::call_VM_leaf_base(address entry_point,
62 62 int number_of_arguments) {
63 63 // interpreter specific
64 64 //
65 65 // Note: No need to save/restore bcp & locals (r13 & r14) pointer
66 66 // since these are callee saved registers and no blocking/
67 67 // GC can happen in leaf calls.
68 68 // Further Note: DO NOT save/restore bcp/locals. If a caller has
69 69 // already saved them so that it can use esi/edi as temporaries
70 70 // then a save/restore here will DESTROY the copy the caller
71 71 // saved! There used to be a save_bcp() that only happened in
72 72 // the ASSERT path (no restore_bcp). Which caused bizarre failures
73 73 // when jvm built with ASSERTs.
74 74 #ifdef ASSERT
75 75 {
76 76 Label L;
77 77 cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
78 78 jcc(Assembler::equal, L);
79 79 stop("InterpreterMacroAssembler::call_VM_leaf_base:"
80 80 " last_sp != NULL");
81 81 bind(L);
82 82 }
83 83 #endif
84 84 // super call
85 85 MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments);
86 86 // interpreter specific
87 87 // Used to ASSERT that r13/r14 were equal to frame's bcp/locals
88 88 // but since they may not have been saved (and we don't want to
89 89 // save thme here (see note above) the assert is invalid.
90 90 }
91 91
92 92 void InterpreterMacroAssembler::call_VM_base(Register oop_result,
93 93 Register java_thread,
94 94 Register last_java_sp,
95 95 address entry_point,
96 96 int number_of_arguments,
97 97 bool check_exceptions) {
98 98 // interpreter specific
99 99 //
100 100 // Note: Could avoid restoring locals ptr (callee saved) - however doesn't
101 101 // really make a difference for these runtime calls, since they are
102 102 // slow anyway. Btw., bcp must be saved/restored since it may change
103 103 // due to GC.
104 104 // assert(java_thread == noreg , "not expecting a precomputed java thread");
105 105 save_bcp();
106 106 #ifdef ASSERT
107 107 {
108 108 Label L;
109 109 cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
110 110 jcc(Assembler::equal, L);
111 111 stop("InterpreterMacroAssembler::call_VM_leaf_base:"
112 112 " last_sp != NULL");
113 113 bind(L);
114 114 }
115 115 #endif /* ASSERT */
116 116 // super call
117 117 MacroAssembler::call_VM_base(oop_result, noreg, last_java_sp,
118 118 entry_point, number_of_arguments,
119 119 check_exceptions);
120 120 // interpreter specific
121 121 restore_bcp();
122 122 restore_locals();
123 123 }
124 124
125 125
126 126 void InterpreterMacroAssembler::check_and_handle_popframe(Register java_thread) {
127 127 if (JvmtiExport::can_pop_frame()) {
128 128 Label L;
129 129 // Initiate popframe handling only if it is not already being
130 130 // processed. If the flag has the popframe_processing bit set, it
131 131 // means that this code is called *during* popframe handling - we
132 132 // don't want to reenter.
133 133 // This method is only called just after the call into the vm in
134 134 // call_VM_base, so the arg registers are available.
135 135 movl(c_rarg0, Address(r15_thread, JavaThread::popframe_condition_offset()));
136 136 testl(c_rarg0, JavaThread::popframe_pending_bit);
137 137 jcc(Assembler::zero, L);
138 138 testl(c_rarg0, JavaThread::popframe_processing_bit);
139 139 jcc(Assembler::notZero, L);
140 140 // Call Interpreter::remove_activation_preserving_args_entry() to get the
141 141 // address of the same-named entrypoint in the generated interpreter code.
142 142 call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry));
143 143 jmp(rax);
144 144 bind(L);
145 145 }
146 146 }
147 147
148 148
149 149 void InterpreterMacroAssembler::load_earlyret_value(TosState state) {
150 150 movptr(rcx, Address(r15_thread, JavaThread::jvmti_thread_state_offset()));
151 151 const Address tos_addr(rcx, JvmtiThreadState::earlyret_tos_offset());
152 152 const Address oop_addr(rcx, JvmtiThreadState::earlyret_oop_offset());
153 153 const Address val_addr(rcx, JvmtiThreadState::earlyret_value_offset());
154 154 switch (state) {
155 155 case atos: movptr(rax, oop_addr);
156 156 movptr(oop_addr, (int32_t)NULL_WORD);
157 157 verify_oop(rax, state); break;
158 158 case ltos: movptr(rax, val_addr); break;
159 159 case btos: // fall through
160 160 case ctos: // fall through
161 161 case stos: // fall through
162 162 case itos: movl(rax, val_addr); break;
163 163 case ftos: movflt(xmm0, val_addr); break;
164 164 case dtos: movdbl(xmm0, val_addr); break;
165 165 case vtos: /* nothing to do */ break;
166 166 default : ShouldNotReachHere();
167 167 }
168 168 // Clean up tos value in the thread object
169 169 movl(tos_addr, (int) ilgl);
170 170 movl(val_addr, (int32_t) NULL_WORD);
171 171 }
172 172
173 173
174 174 void InterpreterMacroAssembler::check_and_handle_earlyret(Register java_thread) {
175 175 if (JvmtiExport::can_force_early_return()) {
176 176 Label L;
177 177 movptr(c_rarg0, Address(r15_thread, JavaThread::jvmti_thread_state_offset()));
178 178 testptr(c_rarg0, c_rarg0);
179 179 jcc(Assembler::zero, L); // if (thread->jvmti_thread_state() == NULL) exit;
180 180
181 181 // Initiate earlyret handling only if it is not already being processed.
182 182 // If the flag has the earlyret_processing bit set, it means that this code
183 183 // is called *during* earlyret handling - we don't want to reenter.
184 184 movl(c_rarg0, Address(c_rarg0, JvmtiThreadState::earlyret_state_offset()));
185 185 cmpl(c_rarg0, JvmtiThreadState::earlyret_pending);
186 186 jcc(Assembler::notEqual, L);
187 187
188 188 // Call Interpreter::remove_activation_early_entry() to get the address of the
189 189 // same-named entrypoint in the generated interpreter code.
190 190 movptr(c_rarg0, Address(r15_thread, JavaThread::jvmti_thread_state_offset()));
191 191 movl(c_rarg0, Address(c_rarg0, JvmtiThreadState::earlyret_tos_offset()));
192 192 call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), c_rarg0);
193 193 jmp(rax);
194 194 bind(L);
195 195 }
196 196 }
197 197
198 198
199 199 void InterpreterMacroAssembler::get_unsigned_2_byte_index_at_bcp(
200 200 Register reg,
201 201 int bcp_offset) {
202 202 assert(bcp_offset >= 0, "bcp is still pointing to start of bytecode");
203 203 movl(reg, Address(r13, bcp_offset));
204 204 bswapl(reg);
205 205 shrl(reg, 16);
206 206 }
207 207
208 208
209 209 void InterpreterMacroAssembler::get_cache_index_at_bcp(Register index,
210 210 int bcp_offset,
211 211 size_t index_size) {
212 212 assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
213 213 if (index_size == sizeof(u2)) {
214 214 load_unsigned_short(index, Address(r13, bcp_offset));
215 215 } else if (index_size == sizeof(u4)) {
216 216 assert(EnableInvokeDynamic, "giant index used only for JSR 292");
217 217 movl(index, Address(r13, bcp_offset));
218 218 // Check if the secondary index definition is still ~x, otherwise
219 219 // we have to change the following assembler code to calculate the
220 220 // plain index.
221 221 assert(constantPoolCacheOopDesc::decode_secondary_index(~123) == 123, "else change next line");
222 222 notl(index); // convert to plain index
223 223 } else if (index_size == sizeof(u1)) {
224 224 assert(EnableInvokeDynamic, "tiny index used only for JSR 292");
225 225 load_unsigned_byte(index, Address(r13, bcp_offset));
↓ open down ↓ |
225 lines elided |
↑ open up ↑ |
226 226 } else {
227 227 ShouldNotReachHere();
228 228 }
229 229 }
230 230
231 231
232 232 void InterpreterMacroAssembler::get_cache_and_index_at_bcp(Register cache,
233 233 Register index,
234 234 int bcp_offset,
235 235 size_t index_size) {
236 - assert(cache != index, "must use different registers");
236 + assert_different_registers(cache, index);
237 237 get_cache_index_at_bcp(index, bcp_offset, index_size);
238 238 movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize));
239 239 assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below");
240 240 // convert from field index to ConstantPoolCacheEntry index
241 241 shll(index, 2);
242 242 }
243 243
244 244
245 +void InterpreterMacroAssembler::get_cache_and_index_and_bytecode_at_bcp(Register cache,
246 + Register index,
247 + Register bytecode,
248 + int byte_no,
249 + int bcp_offset,
250 + size_t index_size) {
251 + get_cache_and_index_at_bcp(cache, index, bcp_offset, index_size);
252 + // We use a 32-bit load here since the layout of 64-bit words on
253 + // little-endian machines allow us that.
254 + movl(bytecode, Address(cache, index, Address::times_ptr, constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::indices_offset()));
255 + const int shift_count = (1 + byte_no) * BitsPerByte;
256 + shrl(bytecode, shift_count);
257 + andl(bytecode, 0xFF);
258 +}
259 +
260 +
245 261 void InterpreterMacroAssembler::get_cache_entry_pointer_at_bcp(Register cache,
246 262 Register tmp,
247 263 int bcp_offset,
248 264 size_t index_size) {
249 265 assert(cache != tmp, "must use different register");
250 266 get_cache_index_at_bcp(tmp, bcp_offset, index_size);
251 267 assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below");
252 268 // convert from field index to ConstantPoolCacheEntry index
253 269 // and from word offset to byte offset
254 270 shll(tmp, 2 + LogBytesPerWord);
255 271 movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize));
256 272 // skip past the header
257 273 addptr(cache, in_bytes(constantPoolCacheOopDesc::base_offset()));
258 274 addptr(cache, tmp); // construct pointer to cache entry
259 275 }
260 276
261 277
262 278 // Generate a subtype check: branch to ok_is_subtype if sub_klass is a
263 279 // subtype of super_klass.
264 280 //
265 281 // Args:
266 282 // rax: superklass
267 283 // Rsub_klass: subklass
268 284 //
269 285 // Kills:
270 286 // rcx, rdi
271 287 void InterpreterMacroAssembler::gen_subtype_check(Register Rsub_klass,
272 288 Label& ok_is_subtype) {
273 289 assert(Rsub_klass != rax, "rax holds superklass");
274 290 assert(Rsub_klass != r14, "r14 holds locals");
275 291 assert(Rsub_klass != r13, "r13 holds bcp");
276 292 assert(Rsub_klass != rcx, "rcx holds 2ndary super array length");
277 293 assert(Rsub_klass != rdi, "rdi holds 2ndary super array scan ptr");
278 294
279 295 // Profile the not-null value's klass.
280 296 profile_typecheck(rcx, Rsub_klass, rdi); // blows rcx, reloads rdi
281 297
282 298 // Do the check.
283 299 check_klass_subtype(Rsub_klass, rax, rcx, ok_is_subtype); // blows rcx
284 300
285 301 // Profile the failure of the check.
286 302 profile_typecheck_failed(rcx); // blows rcx
287 303 }
288 304
289 305
290 306
291 307 // Java Expression Stack
292 308
293 309 void InterpreterMacroAssembler::pop_ptr(Register r) {
294 310 pop(r);
295 311 }
296 312
297 313 void InterpreterMacroAssembler::pop_i(Register r) {
298 314 // XXX can't use pop currently, upper half non clean
299 315 movl(r, Address(rsp, 0));
300 316 addptr(rsp, wordSize);
301 317 }
302 318
303 319 void InterpreterMacroAssembler::pop_l(Register r) {
304 320 movq(r, Address(rsp, 0));
305 321 addptr(rsp, 2 * Interpreter::stackElementSize);
306 322 }
307 323
308 324 void InterpreterMacroAssembler::pop_f(XMMRegister r) {
309 325 movflt(r, Address(rsp, 0));
310 326 addptr(rsp, wordSize);
311 327 }
312 328
313 329 void InterpreterMacroAssembler::pop_d(XMMRegister r) {
314 330 movdbl(r, Address(rsp, 0));
315 331 addptr(rsp, 2 * Interpreter::stackElementSize);
316 332 }
317 333
318 334 void InterpreterMacroAssembler::push_ptr(Register r) {
319 335 push(r);
320 336 }
321 337
322 338 void InterpreterMacroAssembler::push_i(Register r) {
323 339 push(r);
324 340 }
325 341
326 342 void InterpreterMacroAssembler::push_l(Register r) {
327 343 subptr(rsp, 2 * wordSize);
328 344 movq(Address(rsp, 0), r);
329 345 }
330 346
331 347 void InterpreterMacroAssembler::push_f(XMMRegister r) {
332 348 subptr(rsp, wordSize);
333 349 movflt(Address(rsp, 0), r);
334 350 }
335 351
336 352 void InterpreterMacroAssembler::push_d(XMMRegister r) {
337 353 subptr(rsp, 2 * wordSize);
338 354 movdbl(Address(rsp, 0), r);
339 355 }
340 356
341 357 void InterpreterMacroAssembler::pop(TosState state) {
342 358 switch (state) {
343 359 case atos: pop_ptr(); break;
344 360 case btos:
345 361 case ctos:
346 362 case stos:
347 363 case itos: pop_i(); break;
348 364 case ltos: pop_l(); break;
349 365 case ftos: pop_f(); break;
350 366 case dtos: pop_d(); break;
351 367 case vtos: /* nothing to do */ break;
352 368 default: ShouldNotReachHere();
353 369 }
354 370 verify_oop(rax, state);
355 371 }
356 372
357 373 void InterpreterMacroAssembler::push(TosState state) {
358 374 verify_oop(rax, state);
359 375 switch (state) {
360 376 case atos: push_ptr(); break;
361 377 case btos:
362 378 case ctos:
363 379 case stos:
364 380 case itos: push_i(); break;
365 381 case ltos: push_l(); break;
366 382 case ftos: push_f(); break;
367 383 case dtos: push_d(); break;
368 384 case vtos: /* nothing to do */ break;
369 385 default : ShouldNotReachHere();
370 386 }
371 387 }
372 388
373 389
374 390 // Helpers for swap and dup
375 391 void InterpreterMacroAssembler::load_ptr(int n, Register val) {
376 392 movptr(val, Address(rsp, Interpreter::expr_offset_in_bytes(n)));
377 393 }
378 394
379 395 void InterpreterMacroAssembler::store_ptr(int n, Register val) {
380 396 movptr(Address(rsp, Interpreter::expr_offset_in_bytes(n)), val);
381 397 }
382 398
383 399
384 400 void InterpreterMacroAssembler::prepare_to_jump_from_interpreted() {
385 401 // set sender sp
386 402 lea(r13, Address(rsp, wordSize));
387 403 // record last_sp
388 404 movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), r13);
389 405 }
390 406
391 407
392 408 // Jump to from_interpreted entry of a call unless single stepping is possible
393 409 // in this thread in which case we must call the i2i entry
394 410 void InterpreterMacroAssembler::jump_from_interpreted(Register method, Register temp) {
395 411 prepare_to_jump_from_interpreted();
396 412
397 413 if (JvmtiExport::can_post_interpreter_events()) {
398 414 Label run_compiled_code;
399 415 // JVMTI events, such as single-stepping, are implemented partly by avoiding running
400 416 // compiled code in threads for which the event is enabled. Check here for
401 417 // interp_only_mode if these events CAN be enabled.
402 418 // interp_only is an int, on little endian it is sufficient to test the byte only
403 419 // Is a cmpl faster?
404 420 cmpb(Address(r15_thread, JavaThread::interp_only_mode_offset()), 0);
405 421 jccb(Assembler::zero, run_compiled_code);
406 422 jmp(Address(method, methodOopDesc::interpreter_entry_offset()));
407 423 bind(run_compiled_code);
408 424 }
409 425
410 426 jmp(Address(method, methodOopDesc::from_interpreted_offset()));
411 427
412 428 }
413 429
414 430
415 431 // The following two routines provide a hook so that an implementation
416 432 // can schedule the dispatch in two parts. amd64 does not do this.
417 433 void InterpreterMacroAssembler::dispatch_prolog(TosState state, int step) {
418 434 // Nothing amd64 specific to be done here
419 435 }
420 436
421 437 void InterpreterMacroAssembler::dispatch_epilog(TosState state, int step) {
422 438 dispatch_next(state, step);
423 439 }
424 440
425 441 void InterpreterMacroAssembler::dispatch_base(TosState state,
426 442 address* table,
427 443 bool verifyoop) {
428 444 verify_FPU(1, state);
429 445 if (VerifyActivationFrameSize) {
430 446 Label L;
431 447 mov(rcx, rbp);
432 448 subptr(rcx, rsp);
433 449 int32_t min_frame_size =
434 450 (frame::link_offset - frame::interpreter_frame_initial_sp_offset) *
435 451 wordSize;
436 452 cmpptr(rcx, (int32_t)min_frame_size);
437 453 jcc(Assembler::greaterEqual, L);
438 454 stop("broken stack frame");
439 455 bind(L);
440 456 }
441 457 if (verifyoop) {
442 458 verify_oop(rax, state);
443 459 }
444 460 lea(rscratch1, ExternalAddress((address)table));
445 461 jmp(Address(rscratch1, rbx, Address::times_8));
446 462 }
447 463
448 464 void InterpreterMacroAssembler::dispatch_only(TosState state) {
449 465 dispatch_base(state, Interpreter::dispatch_table(state));
450 466 }
451 467
452 468 void InterpreterMacroAssembler::dispatch_only_normal(TosState state) {
453 469 dispatch_base(state, Interpreter::normal_table(state));
454 470 }
455 471
456 472 void InterpreterMacroAssembler::dispatch_only_noverify(TosState state) {
457 473 dispatch_base(state, Interpreter::normal_table(state), false);
458 474 }
459 475
460 476
461 477 void InterpreterMacroAssembler::dispatch_next(TosState state, int step) {
462 478 // load next bytecode (load before advancing r13 to prevent AGI)
463 479 load_unsigned_byte(rbx, Address(r13, step));
464 480 // advance r13
465 481 increment(r13, step);
466 482 dispatch_base(state, Interpreter::dispatch_table(state));
467 483 }
468 484
469 485 void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) {
470 486 // load current bytecode
471 487 load_unsigned_byte(rbx, Address(r13, 0));
472 488 dispatch_base(state, table);
473 489 }
474 490
475 491 // remove activation
476 492 //
477 493 // Unlock the receiver if this is a synchronized method.
478 494 // Unlock any Java monitors from syncronized blocks.
479 495 // Remove the activation from the stack.
480 496 //
481 497 // If there are locked Java monitors
482 498 // If throw_monitor_exception
483 499 // throws IllegalMonitorStateException
484 500 // Else if install_monitor_exception
485 501 // installs IllegalMonitorStateException
486 502 // Else
487 503 // no error processing
488 504 void InterpreterMacroAssembler::remove_activation(
489 505 TosState state,
490 506 Register ret_addr,
491 507 bool throw_monitor_exception,
492 508 bool install_monitor_exception,
493 509 bool notify_jvmdi) {
494 510 // Note: Registers rdx xmm0 may be in use for the
495 511 // result check if synchronized method
496 512 Label unlocked, unlock, no_unlock;
497 513
498 514 // get the value of _do_not_unlock_if_synchronized into rdx
499 515 const Address do_not_unlock_if_synchronized(r15_thread,
500 516 in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
501 517 movbool(rdx, do_not_unlock_if_synchronized);
502 518 movbool(do_not_unlock_if_synchronized, false); // reset the flag
503 519
504 520 // get method access flags
505 521 movptr(rbx, Address(rbp, frame::interpreter_frame_method_offset * wordSize));
506 522 movl(rcx, Address(rbx, methodOopDesc::access_flags_offset()));
507 523 testl(rcx, JVM_ACC_SYNCHRONIZED);
508 524 jcc(Assembler::zero, unlocked);
509 525
510 526 // Don't unlock anything if the _do_not_unlock_if_synchronized flag
511 527 // is set.
512 528 testbool(rdx);
513 529 jcc(Assembler::notZero, no_unlock);
514 530
515 531 // unlock monitor
516 532 push(state); // save result
517 533
518 534 // BasicObjectLock will be first in list, since this is a
519 535 // synchronized method. However, need to check that the object has
520 536 // not been unlocked by an explicit monitorexit bytecode.
521 537 const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset *
522 538 wordSize - (int) sizeof(BasicObjectLock));
523 539 // We use c_rarg1 so that if we go slow path it will be the correct
524 540 // register for unlock_object to pass to VM directly
525 541 lea(c_rarg1, monitor); // address of first monitor
526 542
527 543 movptr(rax, Address(c_rarg1, BasicObjectLock::obj_offset_in_bytes()));
528 544 testptr(rax, rax);
529 545 jcc(Assembler::notZero, unlock);
530 546
531 547 pop(state);
532 548 if (throw_monitor_exception) {
533 549 // Entry already unlocked, need to throw exception
534 550 call_VM(noreg, CAST_FROM_FN_PTR(address,
535 551 InterpreterRuntime::throw_illegal_monitor_state_exception));
536 552 should_not_reach_here();
537 553 } else {
538 554 // Monitor already unlocked during a stack unroll. If requested,
539 555 // install an illegal_monitor_state_exception. Continue with
540 556 // stack unrolling.
541 557 if (install_monitor_exception) {
542 558 call_VM(noreg, CAST_FROM_FN_PTR(address,
543 559 InterpreterRuntime::new_illegal_monitor_state_exception));
544 560 }
545 561 jmp(unlocked);
546 562 }
547 563
548 564 bind(unlock);
549 565 unlock_object(c_rarg1);
550 566 pop(state);
551 567
552 568 // Check that for block-structured locking (i.e., that all locked
553 569 // objects has been unlocked)
554 570 bind(unlocked);
555 571
556 572 // rax: Might contain return value
557 573
558 574 // Check that all monitors are unlocked
559 575 {
560 576 Label loop, exception, entry, restart;
561 577 const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
562 578 const Address monitor_block_top(
563 579 rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
564 580 const Address monitor_block_bot(
565 581 rbp, frame::interpreter_frame_initial_sp_offset * wordSize);
566 582
567 583 bind(restart);
568 584 // We use c_rarg1 so that if we go slow path it will be the correct
569 585 // register for unlock_object to pass to VM directly
570 586 movptr(c_rarg1, monitor_block_top); // points to current entry, starting
571 587 // with top-most entry
572 588 lea(rbx, monitor_block_bot); // points to word before bottom of
573 589 // monitor block
574 590 jmp(entry);
575 591
576 592 // Entry already locked, need to throw exception
577 593 bind(exception);
578 594
579 595 if (throw_monitor_exception) {
580 596 // Throw exception
581 597 MacroAssembler::call_VM(noreg,
582 598 CAST_FROM_FN_PTR(address, InterpreterRuntime::
583 599 throw_illegal_monitor_state_exception));
584 600 should_not_reach_here();
585 601 } else {
586 602 // Stack unrolling. Unlock object and install illegal_monitor_exception.
587 603 // Unlock does not block, so don't have to worry about the frame.
588 604 // We don't have to preserve c_rarg1 since we are going to throw an exception.
589 605
590 606 push(state);
591 607 unlock_object(c_rarg1);
592 608 pop(state);
593 609
594 610 if (install_monitor_exception) {
595 611 call_VM(noreg, CAST_FROM_FN_PTR(address,
596 612 InterpreterRuntime::
597 613 new_illegal_monitor_state_exception));
598 614 }
599 615
600 616 jmp(restart);
601 617 }
602 618
603 619 bind(loop);
604 620 // check if current entry is used
605 621 cmpptr(Address(c_rarg1, BasicObjectLock::obj_offset_in_bytes()), (int32_t) NULL);
606 622 jcc(Assembler::notEqual, exception);
607 623
608 624 addptr(c_rarg1, entry_size); // otherwise advance to next entry
609 625 bind(entry);
610 626 cmpptr(c_rarg1, rbx); // check if bottom reached
611 627 jcc(Assembler::notEqual, loop); // if not at bottom then check this entry
612 628 }
613 629
614 630 bind(no_unlock);
615 631
616 632 // jvmti support
617 633 if (notify_jvmdi) {
618 634 notify_method_exit(state, NotifyJVMTI); // preserve TOSCA
619 635 } else {
620 636 notify_method_exit(state, SkipNotifyJVMTI); // preserve TOSCA
621 637 }
622 638
623 639 // remove activation
624 640 // get sender sp
625 641 movptr(rbx,
626 642 Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize));
627 643 leave(); // remove frame anchor
628 644 pop(ret_addr); // get return address
629 645 mov(rsp, rbx); // set sp to sender sp
630 646 }
631 647
632 648 #endif // C_INTERP
633 649
634 650 // Lock object
635 651 //
636 652 // Args:
637 653 // c_rarg1: BasicObjectLock to be used for locking
638 654 //
639 655 // Kills:
640 656 // rax
641 657 // c_rarg0, c_rarg1, c_rarg2, c_rarg3, .. (param regs)
642 658 // rscratch1, rscratch2 (scratch regs)
643 659 void InterpreterMacroAssembler::lock_object(Register lock_reg) {
644 660 assert(lock_reg == c_rarg1, "The argument is only for looks. It must be c_rarg1");
645 661
646 662 if (UseHeavyMonitors) {
647 663 call_VM(noreg,
648 664 CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
649 665 lock_reg);
650 666 } else {
651 667 Label done;
652 668
653 669 const Register swap_reg = rax; // Must use rax for cmpxchg instruction
654 670 const Register obj_reg = c_rarg3; // Will contain the oop
655 671
656 672 const int obj_offset = BasicObjectLock::obj_offset_in_bytes();
657 673 const int lock_offset = BasicObjectLock::lock_offset_in_bytes ();
658 674 const int mark_offset = lock_offset +
659 675 BasicLock::displaced_header_offset_in_bytes();
660 676
661 677 Label slow_case;
662 678
663 679 // Load object pointer into obj_reg %c_rarg3
664 680 movptr(obj_reg, Address(lock_reg, obj_offset));
665 681
666 682 if (UseBiasedLocking) {
667 683 biased_locking_enter(lock_reg, obj_reg, swap_reg, rscratch1, false, done, &slow_case);
668 684 }
669 685
670 686 // Load immediate 1 into swap_reg %rax
671 687 movl(swap_reg, 1);
672 688
673 689 // Load (object->mark() | 1) into swap_reg %rax
674 690 orptr(swap_reg, Address(obj_reg, 0));
675 691
676 692 // Save (object->mark() | 1) into BasicLock's displaced header
677 693 movptr(Address(lock_reg, mark_offset), swap_reg);
678 694
679 695 assert(lock_offset == 0,
680 696 "displached header must be first word in BasicObjectLock");
681 697
682 698 if (os::is_MP()) lock();
683 699 cmpxchgptr(lock_reg, Address(obj_reg, 0));
684 700 if (PrintBiasedLockingStatistics) {
685 701 cond_inc32(Assembler::zero,
686 702 ExternalAddress((address) BiasedLocking::fast_path_entry_count_addr()));
687 703 }
688 704 jcc(Assembler::zero, done);
689 705
690 706 // Test if the oopMark is an obvious stack pointer, i.e.,
691 707 // 1) (mark & 7) == 0, and
692 708 // 2) rsp <= mark < mark + os::pagesize()
693 709 //
694 710 // These 3 tests can be done by evaluating the following
695 711 // expression: ((mark - rsp) & (7 - os::vm_page_size())),
696 712 // assuming both stack pointer and pagesize have their
697 713 // least significant 3 bits clear.
698 714 // NOTE: the oopMark is in swap_reg %rax as the result of cmpxchg
699 715 subptr(swap_reg, rsp);
700 716 andptr(swap_reg, 7 - os::vm_page_size());
701 717
702 718 // Save the test result, for recursive case, the result is zero
703 719 movptr(Address(lock_reg, mark_offset), swap_reg);
704 720
705 721 if (PrintBiasedLockingStatistics) {
706 722 cond_inc32(Assembler::zero,
707 723 ExternalAddress((address) BiasedLocking::fast_path_entry_count_addr()));
708 724 }
709 725 jcc(Assembler::zero, done);
710 726
711 727 bind(slow_case);
712 728
713 729 // Call the runtime routine for slow case
714 730 call_VM(noreg,
715 731 CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
716 732 lock_reg);
717 733
718 734 bind(done);
719 735 }
720 736 }
721 737
722 738
723 739 // Unlocks an object. Used in monitorexit bytecode and
724 740 // remove_activation. Throws an IllegalMonitorException if object is
725 741 // not locked by current thread.
726 742 //
727 743 // Args:
728 744 // c_rarg1: BasicObjectLock for lock
729 745 //
730 746 // Kills:
731 747 // rax
732 748 // c_rarg0, c_rarg1, c_rarg2, c_rarg3, ... (param regs)
733 749 // rscratch1, rscratch2 (scratch regs)
734 750 void InterpreterMacroAssembler::unlock_object(Register lock_reg) {
735 751 assert(lock_reg == c_rarg1, "The argument is only for looks. It must be rarg1");
736 752
737 753 if (UseHeavyMonitors) {
738 754 call_VM(noreg,
739 755 CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit),
740 756 lock_reg);
741 757 } else {
742 758 Label done;
743 759
744 760 const Register swap_reg = rax; // Must use rax for cmpxchg instruction
745 761 const Register header_reg = c_rarg2; // Will contain the old oopMark
746 762 const Register obj_reg = c_rarg3; // Will contain the oop
747 763
748 764 save_bcp(); // Save in case of exception
749 765
750 766 // Convert from BasicObjectLock structure to object and BasicLock
751 767 // structure Store the BasicLock address into %rax
752 768 lea(swap_reg, Address(lock_reg, BasicObjectLock::lock_offset_in_bytes()));
753 769
754 770 // Load oop into obj_reg(%c_rarg3)
755 771 movptr(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()));
756 772
757 773 // Free entry
758 774 movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()), (int32_t)NULL_WORD);
759 775
760 776 if (UseBiasedLocking) {
761 777 biased_locking_exit(obj_reg, header_reg, done);
762 778 }
763 779
764 780 // Load the old header from BasicLock structure
765 781 movptr(header_reg, Address(swap_reg,
766 782 BasicLock::displaced_header_offset_in_bytes()));
767 783
768 784 // Test for recursion
769 785 testptr(header_reg, header_reg);
770 786
771 787 // zero for recursive case
772 788 jcc(Assembler::zero, done);
773 789
774 790 // Atomic swap back the old header
775 791 if (os::is_MP()) lock();
776 792 cmpxchgptr(header_reg, Address(obj_reg, 0));
777 793
778 794 // zero for recursive case
779 795 jcc(Assembler::zero, done);
780 796
781 797 // Call the runtime routine for slow case.
782 798 movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()),
783 799 obj_reg); // restore obj
784 800 call_VM(noreg,
785 801 CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit),
786 802 lock_reg);
787 803
788 804 bind(done);
789 805
790 806 restore_bcp();
791 807 }
792 808 }
793 809
794 810 #ifndef CC_INTERP
795 811
796 812 void InterpreterMacroAssembler::test_method_data_pointer(Register mdp,
797 813 Label& zero_continue) {
798 814 assert(ProfileInterpreter, "must be profiling interpreter");
799 815 movptr(mdp, Address(rbp, frame::interpreter_frame_mdx_offset * wordSize));
800 816 testptr(mdp, mdp);
801 817 jcc(Assembler::zero, zero_continue);
802 818 }
803 819
804 820
805 821 // Set the method data pointer for the current bcp.
806 822 void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() {
807 823 assert(ProfileInterpreter, "must be profiling interpreter");
808 824 Label set_mdp;
809 825 push(rax);
810 826 push(rbx);
811 827
812 828 get_method(rbx);
813 829 // Test MDO to avoid the call if it is NULL.
814 830 movptr(rax, Address(rbx, in_bytes(methodOopDesc::method_data_offset())));
815 831 testptr(rax, rax);
816 832 jcc(Assembler::zero, set_mdp);
817 833 // rbx: method
818 834 // r13: bcp
819 835 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), rbx, r13);
820 836 // rax: mdi
821 837 // mdo is guaranteed to be non-zero here, we checked for it before the call.
822 838 movptr(rbx, Address(rbx, in_bytes(methodOopDesc::method_data_offset())));
823 839 addptr(rbx, in_bytes(methodDataOopDesc::data_offset()));
824 840 addptr(rax, rbx);
825 841 bind(set_mdp);
826 842 movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), rax);
827 843 pop(rbx);
828 844 pop(rax);
829 845 }
830 846
831 847 void InterpreterMacroAssembler::verify_method_data_pointer() {
832 848 assert(ProfileInterpreter, "must be profiling interpreter");
833 849 #ifdef ASSERT
834 850 Label verify_continue;
835 851 push(rax);
836 852 push(rbx);
837 853 push(c_rarg3);
838 854 push(c_rarg2);
839 855 test_method_data_pointer(c_rarg3, verify_continue); // If mdp is zero, continue
840 856 get_method(rbx);
841 857
842 858 // If the mdp is valid, it will point to a DataLayout header which is
843 859 // consistent with the bcp. The converse is highly probable also.
844 860 load_unsigned_short(c_rarg2,
845 861 Address(c_rarg3, in_bytes(DataLayout::bci_offset())));
846 862 addptr(c_rarg2, Address(rbx, methodOopDesc::const_offset()));
847 863 lea(c_rarg2, Address(c_rarg2, constMethodOopDesc::codes_offset()));
848 864 cmpptr(c_rarg2, r13);
849 865 jcc(Assembler::equal, verify_continue);
850 866 // rbx: method
851 867 // r13: bcp
852 868 // c_rarg3: mdp
853 869 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp),
854 870 rbx, r13, c_rarg3);
855 871 bind(verify_continue);
856 872 pop(c_rarg2);
857 873 pop(c_rarg3);
858 874 pop(rbx);
859 875 pop(rax);
860 876 #endif // ASSERT
861 877 }
862 878
863 879
864 880 void InterpreterMacroAssembler::set_mdp_data_at(Register mdp_in,
865 881 int constant,
866 882 Register value) {
867 883 assert(ProfileInterpreter, "must be profiling interpreter");
868 884 Address data(mdp_in, constant);
869 885 movptr(data, value);
870 886 }
871 887
872 888
873 889 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
874 890 int constant,
875 891 bool decrement) {
876 892 // Counter address
877 893 Address data(mdp_in, constant);
878 894
879 895 increment_mdp_data_at(data, decrement);
880 896 }
881 897
882 898 void InterpreterMacroAssembler::increment_mdp_data_at(Address data,
883 899 bool decrement) {
884 900 assert(ProfileInterpreter, "must be profiling interpreter");
885 901 // %%% this does 64bit counters at best it is wasting space
886 902 // at worst it is a rare bug when counters overflow
887 903
888 904 if (decrement) {
889 905 // Decrement the register. Set condition codes.
890 906 addptr(data, (int32_t) -DataLayout::counter_increment);
891 907 // If the decrement causes the counter to overflow, stay negative
892 908 Label L;
893 909 jcc(Assembler::negative, L);
894 910 addptr(data, (int32_t) DataLayout::counter_increment);
895 911 bind(L);
896 912 } else {
897 913 assert(DataLayout::counter_increment == 1,
898 914 "flow-free idiom only works with 1");
899 915 // Increment the register. Set carry flag.
900 916 addptr(data, DataLayout::counter_increment);
901 917 // If the increment causes the counter to overflow, pull back by 1.
902 918 sbbptr(data, (int32_t)0);
903 919 }
904 920 }
905 921
906 922
907 923 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
908 924 Register reg,
909 925 int constant,
910 926 bool decrement) {
911 927 Address data(mdp_in, reg, Address::times_1, constant);
912 928
913 929 increment_mdp_data_at(data, decrement);
914 930 }
915 931
916 932 void InterpreterMacroAssembler::set_mdp_flag_at(Register mdp_in,
917 933 int flag_byte_constant) {
918 934 assert(ProfileInterpreter, "must be profiling interpreter");
919 935 int header_offset = in_bytes(DataLayout::header_offset());
920 936 int header_bits = DataLayout::flag_mask_to_header_mask(flag_byte_constant);
921 937 // Set the flag
922 938 orl(Address(mdp_in, header_offset), header_bits);
923 939 }
924 940
925 941
926 942
927 943 void InterpreterMacroAssembler::test_mdp_data_at(Register mdp_in,
928 944 int offset,
929 945 Register value,
930 946 Register test_value_out,
931 947 Label& not_equal_continue) {
932 948 assert(ProfileInterpreter, "must be profiling interpreter");
933 949 if (test_value_out == noreg) {
934 950 cmpptr(value, Address(mdp_in, offset));
935 951 } else {
936 952 // Put the test value into a register, so caller can use it:
937 953 movptr(test_value_out, Address(mdp_in, offset));
938 954 cmpptr(test_value_out, value);
939 955 }
940 956 jcc(Assembler::notEqual, not_equal_continue);
941 957 }
942 958
943 959
944 960 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
945 961 int offset_of_disp) {
946 962 assert(ProfileInterpreter, "must be profiling interpreter");
947 963 Address disp_address(mdp_in, offset_of_disp);
948 964 addptr(mdp_in, disp_address);
949 965 movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in);
950 966 }
951 967
952 968
953 969 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
954 970 Register reg,
955 971 int offset_of_disp) {
956 972 assert(ProfileInterpreter, "must be profiling interpreter");
957 973 Address disp_address(mdp_in, reg, Address::times_1, offset_of_disp);
958 974 addptr(mdp_in, disp_address);
959 975 movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in);
960 976 }
961 977
962 978
963 979 void InterpreterMacroAssembler::update_mdp_by_constant(Register mdp_in,
964 980 int constant) {
965 981 assert(ProfileInterpreter, "must be profiling interpreter");
966 982 addptr(mdp_in, constant);
967 983 movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in);
968 984 }
969 985
970 986
971 987 void InterpreterMacroAssembler::update_mdp_for_ret(Register return_bci) {
972 988 assert(ProfileInterpreter, "must be profiling interpreter");
973 989 push(return_bci); // save/restore across call_VM
974 990 call_VM(noreg,
975 991 CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret),
976 992 return_bci);
977 993 pop(return_bci);
978 994 }
979 995
980 996
981 997 void InterpreterMacroAssembler::profile_taken_branch(Register mdp,
982 998 Register bumped_count) {
983 999 if (ProfileInterpreter) {
984 1000 Label profile_continue;
985 1001
986 1002 // If no method data exists, go to profile_continue.
987 1003 // Otherwise, assign to mdp
988 1004 test_method_data_pointer(mdp, profile_continue);
989 1005
990 1006 // We are taking a branch. Increment the taken count.
991 1007 // We inline increment_mdp_data_at to return bumped_count in a register
992 1008 //increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset()));
993 1009 Address data(mdp, in_bytes(JumpData::taken_offset()));
994 1010 movptr(bumped_count, data);
995 1011 assert(DataLayout::counter_increment == 1,
996 1012 "flow-free idiom only works with 1");
997 1013 addptr(bumped_count, DataLayout::counter_increment);
998 1014 sbbptr(bumped_count, 0);
999 1015 movptr(data, bumped_count); // Store back out
1000 1016
1001 1017 // The method data pointer needs to be updated to reflect the new target.
1002 1018 update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset()));
1003 1019 bind(profile_continue);
1004 1020 }
1005 1021 }
1006 1022
1007 1023
1008 1024 void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp) {
1009 1025 if (ProfileInterpreter) {
1010 1026 Label profile_continue;
1011 1027
1012 1028 // If no method data exists, go to profile_continue.
1013 1029 test_method_data_pointer(mdp, profile_continue);
1014 1030
1015 1031 // We are taking a branch. Increment the not taken count.
1016 1032 increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset()));
1017 1033
1018 1034 // The method data pointer needs to be updated to correspond to
1019 1035 // the next bytecode
1020 1036 update_mdp_by_constant(mdp, in_bytes(BranchData::branch_data_size()));
1021 1037 bind(profile_continue);
1022 1038 }
1023 1039 }
1024 1040
1025 1041
1026 1042 void InterpreterMacroAssembler::profile_call(Register mdp) {
1027 1043 if (ProfileInterpreter) {
1028 1044 Label profile_continue;
1029 1045
1030 1046 // If no method data exists, go to profile_continue.
1031 1047 test_method_data_pointer(mdp, profile_continue);
1032 1048
1033 1049 // We are making a call. Increment the count.
1034 1050 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1035 1051
1036 1052 // The method data pointer needs to be updated to reflect the new target.
1037 1053 update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size()));
1038 1054 bind(profile_continue);
1039 1055 }
1040 1056 }
1041 1057
1042 1058
1043 1059 void InterpreterMacroAssembler::profile_final_call(Register mdp) {
1044 1060 if (ProfileInterpreter) {
1045 1061 Label profile_continue;
1046 1062
1047 1063 // If no method data exists, go to profile_continue.
1048 1064 test_method_data_pointer(mdp, profile_continue);
1049 1065
1050 1066 // We are making a call. Increment the count.
1051 1067 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1052 1068
1053 1069 // The method data pointer needs to be updated to reflect the new target.
1054 1070 update_mdp_by_constant(mdp,
1055 1071 in_bytes(VirtualCallData::
1056 1072 virtual_call_data_size()));
1057 1073 bind(profile_continue);
1058 1074 }
1059 1075 }
1060 1076
1061 1077
1062 1078 void InterpreterMacroAssembler::profile_virtual_call(Register receiver,
1063 1079 Register mdp,
1064 1080 Register reg2,
1065 1081 bool receiver_can_be_null) {
1066 1082 if (ProfileInterpreter) {
1067 1083 Label profile_continue;
1068 1084
1069 1085 // If no method data exists, go to profile_continue.
1070 1086 test_method_data_pointer(mdp, profile_continue);
1071 1087
1072 1088 Label skip_receiver_profile;
1073 1089 if (receiver_can_be_null) {
1074 1090 Label not_null;
1075 1091 testptr(receiver, receiver);
1076 1092 jccb(Assembler::notZero, not_null);
1077 1093 // We are making a call. Increment the count for null receiver.
1078 1094 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1079 1095 jmp(skip_receiver_profile);
1080 1096 bind(not_null);
1081 1097 }
1082 1098
1083 1099 // Record the receiver type.
1084 1100 record_klass_in_profile(receiver, mdp, reg2, true);
1085 1101 bind(skip_receiver_profile);
1086 1102
1087 1103 // The method data pointer needs to be updated to reflect the new target.
1088 1104 update_mdp_by_constant(mdp,
1089 1105 in_bytes(VirtualCallData::
1090 1106 virtual_call_data_size()));
1091 1107 bind(profile_continue);
1092 1108 }
1093 1109 }
1094 1110
1095 1111 // This routine creates a state machine for updating the multi-row
1096 1112 // type profile at a virtual call site (or other type-sensitive bytecode).
1097 1113 // The machine visits each row (of receiver/count) until the receiver type
1098 1114 // is found, or until it runs out of rows. At the same time, it remembers
1099 1115 // the location of the first empty row. (An empty row records null for its
1100 1116 // receiver, and can be allocated for a newly-observed receiver type.)
1101 1117 // Because there are two degrees of freedom in the state, a simple linear
1102 1118 // search will not work; it must be a decision tree. Hence this helper
1103 1119 // function is recursive, to generate the required tree structured code.
1104 1120 // It's the interpreter, so we are trading off code space for speed.
1105 1121 // See below for example code.
1106 1122 void InterpreterMacroAssembler::record_klass_in_profile_helper(
1107 1123 Register receiver, Register mdp,
1108 1124 Register reg2, int start_row,
1109 1125 Label& done, bool is_virtual_call) {
1110 1126 if (TypeProfileWidth == 0) {
1111 1127 if (is_virtual_call) {
1112 1128 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1113 1129 }
1114 1130 return;
1115 1131 }
1116 1132
1117 1133 int last_row = VirtualCallData::row_limit() - 1;
1118 1134 assert(start_row <= last_row, "must be work left to do");
1119 1135 // Test this row for both the receiver and for null.
1120 1136 // Take any of three different outcomes:
1121 1137 // 1. found receiver => increment count and goto done
1122 1138 // 2. found null => keep looking for case 1, maybe allocate this cell
1123 1139 // 3. found something else => keep looking for cases 1 and 2
1124 1140 // Case 3 is handled by a recursive call.
1125 1141 for (int row = start_row; row <= last_row; row++) {
1126 1142 Label next_test;
1127 1143 bool test_for_null_also = (row == start_row);
1128 1144
1129 1145 // See if the receiver is receiver[n].
1130 1146 int recvr_offset = in_bytes(VirtualCallData::receiver_offset(row));
1131 1147 test_mdp_data_at(mdp, recvr_offset, receiver,
1132 1148 (test_for_null_also ? reg2 : noreg),
1133 1149 next_test);
1134 1150 // (Reg2 now contains the receiver from the CallData.)
1135 1151
1136 1152 // The receiver is receiver[n]. Increment count[n].
1137 1153 int count_offset = in_bytes(VirtualCallData::receiver_count_offset(row));
1138 1154 increment_mdp_data_at(mdp, count_offset);
1139 1155 jmp(done);
1140 1156 bind(next_test);
1141 1157
1142 1158 if (test_for_null_also) {
1143 1159 Label found_null;
1144 1160 // Failed the equality check on receiver[n]... Test for null.
1145 1161 testptr(reg2, reg2);
1146 1162 if (start_row == last_row) {
1147 1163 // The only thing left to do is handle the null case.
1148 1164 if (is_virtual_call) {
1149 1165 jccb(Assembler::zero, found_null);
1150 1166 // Receiver did not match any saved receiver and there is no empty row for it.
1151 1167 // Increment total counter to indicate polymorphic case.
1152 1168 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1153 1169 jmp(done);
1154 1170 bind(found_null);
1155 1171 } else {
1156 1172 jcc(Assembler::notZero, done);
1157 1173 }
1158 1174 break;
1159 1175 }
1160 1176 // Since null is rare, make it be the branch-taken case.
1161 1177 jcc(Assembler::zero, found_null);
1162 1178
1163 1179 // Put all the "Case 3" tests here.
1164 1180 record_klass_in_profile_helper(receiver, mdp, reg2, start_row + 1, done, is_virtual_call);
1165 1181
1166 1182 // Found a null. Keep searching for a matching receiver,
1167 1183 // but remember that this is an empty (unused) slot.
1168 1184 bind(found_null);
1169 1185 }
1170 1186 }
1171 1187
1172 1188 // In the fall-through case, we found no matching receiver, but we
1173 1189 // observed the receiver[start_row] is NULL.
1174 1190
1175 1191 // Fill in the receiver field and increment the count.
1176 1192 int recvr_offset = in_bytes(VirtualCallData::receiver_offset(start_row));
1177 1193 set_mdp_data_at(mdp, recvr_offset, receiver);
1178 1194 int count_offset = in_bytes(VirtualCallData::receiver_count_offset(start_row));
1179 1195 movl(reg2, DataLayout::counter_increment);
1180 1196 set_mdp_data_at(mdp, count_offset, reg2);
1181 1197 if (start_row > 0) {
1182 1198 jmp(done);
1183 1199 }
1184 1200 }
1185 1201
1186 1202 // Example state machine code for three profile rows:
1187 1203 // // main copy of decision tree, rooted at row[1]
1188 1204 // if (row[0].rec == rec) { row[0].incr(); goto done; }
1189 1205 // if (row[0].rec != NULL) {
1190 1206 // // inner copy of decision tree, rooted at row[1]
1191 1207 // if (row[1].rec == rec) { row[1].incr(); goto done; }
1192 1208 // if (row[1].rec != NULL) {
1193 1209 // // degenerate decision tree, rooted at row[2]
1194 1210 // if (row[2].rec == rec) { row[2].incr(); goto done; }
1195 1211 // if (row[2].rec != NULL) { count.incr(); goto done; } // overflow
1196 1212 // row[2].init(rec); goto done;
1197 1213 // } else {
1198 1214 // // remember row[1] is empty
1199 1215 // if (row[2].rec == rec) { row[2].incr(); goto done; }
1200 1216 // row[1].init(rec); goto done;
1201 1217 // }
1202 1218 // } else {
1203 1219 // // remember row[0] is empty
1204 1220 // if (row[1].rec == rec) { row[1].incr(); goto done; }
1205 1221 // if (row[2].rec == rec) { row[2].incr(); goto done; }
1206 1222 // row[0].init(rec); goto done;
1207 1223 // }
1208 1224 // done:
1209 1225
1210 1226 void InterpreterMacroAssembler::record_klass_in_profile(Register receiver,
1211 1227 Register mdp, Register reg2,
1212 1228 bool is_virtual_call) {
1213 1229 assert(ProfileInterpreter, "must be profiling");
1214 1230 Label done;
1215 1231
1216 1232 record_klass_in_profile_helper(receiver, mdp, reg2, 0, done, is_virtual_call);
1217 1233
1218 1234 bind (done);
1219 1235 }
1220 1236
1221 1237 void InterpreterMacroAssembler::profile_ret(Register return_bci,
1222 1238 Register mdp) {
1223 1239 if (ProfileInterpreter) {
1224 1240 Label profile_continue;
1225 1241 uint row;
1226 1242
1227 1243 // If no method data exists, go to profile_continue.
1228 1244 test_method_data_pointer(mdp, profile_continue);
1229 1245
1230 1246 // Update the total ret count.
1231 1247 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
1232 1248
1233 1249 for (row = 0; row < RetData::row_limit(); row++) {
1234 1250 Label next_test;
1235 1251
1236 1252 // See if return_bci is equal to bci[n]:
1237 1253 test_mdp_data_at(mdp,
1238 1254 in_bytes(RetData::bci_offset(row)),
1239 1255 return_bci, noreg,
1240 1256 next_test);
1241 1257
1242 1258 // return_bci is equal to bci[n]. Increment the count.
1243 1259 increment_mdp_data_at(mdp, in_bytes(RetData::bci_count_offset(row)));
1244 1260
1245 1261 // The method data pointer needs to be updated to reflect the new target.
1246 1262 update_mdp_by_offset(mdp,
1247 1263 in_bytes(RetData::bci_displacement_offset(row)));
1248 1264 jmp(profile_continue);
1249 1265 bind(next_test);
1250 1266 }
1251 1267
1252 1268 update_mdp_for_ret(return_bci);
1253 1269
1254 1270 bind(profile_continue);
1255 1271 }
1256 1272 }
1257 1273
1258 1274
1259 1275 void InterpreterMacroAssembler::profile_null_seen(Register mdp) {
1260 1276 if (ProfileInterpreter) {
1261 1277 Label profile_continue;
1262 1278
1263 1279 // If no method data exists, go to profile_continue.
1264 1280 test_method_data_pointer(mdp, profile_continue);
1265 1281
1266 1282 set_mdp_flag_at(mdp, BitData::null_seen_byte_constant());
1267 1283
1268 1284 // The method data pointer needs to be updated.
1269 1285 int mdp_delta = in_bytes(BitData::bit_data_size());
1270 1286 if (TypeProfileCasts) {
1271 1287 mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1272 1288 }
1273 1289 update_mdp_by_constant(mdp, mdp_delta);
1274 1290
1275 1291 bind(profile_continue);
1276 1292 }
1277 1293 }
1278 1294
1279 1295
1280 1296 void InterpreterMacroAssembler::profile_typecheck_failed(Register mdp) {
1281 1297 if (ProfileInterpreter && TypeProfileCasts) {
1282 1298 Label profile_continue;
1283 1299
1284 1300 // If no method data exists, go to profile_continue.
1285 1301 test_method_data_pointer(mdp, profile_continue);
1286 1302
1287 1303 int count_offset = in_bytes(CounterData::count_offset());
1288 1304 // Back up the address, since we have already bumped the mdp.
1289 1305 count_offset -= in_bytes(VirtualCallData::virtual_call_data_size());
1290 1306
1291 1307 // *Decrement* the counter. We expect to see zero or small negatives.
1292 1308 increment_mdp_data_at(mdp, count_offset, true);
1293 1309
1294 1310 bind (profile_continue);
1295 1311 }
1296 1312 }
1297 1313
1298 1314
1299 1315 void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2) {
1300 1316 if (ProfileInterpreter) {
1301 1317 Label profile_continue;
1302 1318
1303 1319 // If no method data exists, go to profile_continue.
1304 1320 test_method_data_pointer(mdp, profile_continue);
1305 1321
1306 1322 // The method data pointer needs to be updated.
1307 1323 int mdp_delta = in_bytes(BitData::bit_data_size());
1308 1324 if (TypeProfileCasts) {
1309 1325 mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1310 1326
1311 1327 // Record the object type.
1312 1328 record_klass_in_profile(klass, mdp, reg2, false);
1313 1329 }
1314 1330 update_mdp_by_constant(mdp, mdp_delta);
1315 1331
1316 1332 bind(profile_continue);
1317 1333 }
1318 1334 }
1319 1335
1320 1336
1321 1337 void InterpreterMacroAssembler::profile_switch_default(Register mdp) {
1322 1338 if (ProfileInterpreter) {
1323 1339 Label profile_continue;
1324 1340
1325 1341 // If no method data exists, go to profile_continue.
1326 1342 test_method_data_pointer(mdp, profile_continue);
1327 1343
1328 1344 // Update the default case count
1329 1345 increment_mdp_data_at(mdp,
1330 1346 in_bytes(MultiBranchData::default_count_offset()));
1331 1347
1332 1348 // The method data pointer needs to be updated.
1333 1349 update_mdp_by_offset(mdp,
1334 1350 in_bytes(MultiBranchData::
1335 1351 default_displacement_offset()));
1336 1352
1337 1353 bind(profile_continue);
1338 1354 }
1339 1355 }
1340 1356
1341 1357
1342 1358 void InterpreterMacroAssembler::profile_switch_case(Register index,
1343 1359 Register mdp,
1344 1360 Register reg2) {
1345 1361 if (ProfileInterpreter) {
1346 1362 Label profile_continue;
1347 1363
1348 1364 // If no method data exists, go to profile_continue.
1349 1365 test_method_data_pointer(mdp, profile_continue);
1350 1366
1351 1367 // Build the base (index * per_case_size_in_bytes()) +
1352 1368 // case_array_offset_in_bytes()
1353 1369 movl(reg2, in_bytes(MultiBranchData::per_case_size()));
1354 1370 imulptr(index, reg2); // XXX l ?
1355 1371 addptr(index, in_bytes(MultiBranchData::case_array_offset())); // XXX l ?
1356 1372
1357 1373 // Update the case count
1358 1374 increment_mdp_data_at(mdp,
1359 1375 index,
1360 1376 in_bytes(MultiBranchData::relative_count_offset()));
1361 1377
1362 1378 // The method data pointer needs to be updated.
1363 1379 update_mdp_by_offset(mdp,
1364 1380 index,
1365 1381 in_bytes(MultiBranchData::
1366 1382 relative_displacement_offset()));
1367 1383
1368 1384 bind(profile_continue);
1369 1385 }
1370 1386 }
1371 1387
1372 1388
1373 1389
1374 1390 void InterpreterMacroAssembler::verify_oop(Register reg, TosState state) {
1375 1391 if (state == atos) {
1376 1392 MacroAssembler::verify_oop(reg);
1377 1393 }
1378 1394 }
1379 1395
1380 1396 void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) {
1381 1397 }
1382 1398 #endif // !CC_INTERP
1383 1399
1384 1400
1385 1401 void InterpreterMacroAssembler::notify_method_entry() {
1386 1402 // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
1387 1403 // track stack depth. If it is possible to enter interp_only_mode we add
1388 1404 // the code to check if the event should be sent.
1389 1405 if (JvmtiExport::can_post_interpreter_events()) {
1390 1406 Label L;
1391 1407 movl(rdx, Address(r15_thread, JavaThread::interp_only_mode_offset()));
1392 1408 testl(rdx, rdx);
1393 1409 jcc(Assembler::zero, L);
1394 1410 call_VM(noreg, CAST_FROM_FN_PTR(address,
1395 1411 InterpreterRuntime::post_method_entry));
1396 1412 bind(L);
1397 1413 }
1398 1414
1399 1415 {
1400 1416 SkipIfEqual skip(this, &DTraceMethodProbes, false);
1401 1417 get_method(c_rarg1);
1402 1418 call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry),
1403 1419 r15_thread, c_rarg1);
1404 1420 }
1405 1421
1406 1422 // RedefineClasses() tracing support for obsolete method entry
1407 1423 if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
1408 1424 get_method(c_rarg1);
1409 1425 call_VM_leaf(
1410 1426 CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry),
1411 1427 r15_thread, c_rarg1);
1412 1428 }
1413 1429 }
1414 1430
1415 1431
1416 1432 void InterpreterMacroAssembler::notify_method_exit(
1417 1433 TosState state, NotifyMethodExitMode mode) {
1418 1434 // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
1419 1435 // track stack depth. If it is possible to enter interp_only_mode we add
1420 1436 // the code to check if the event should be sent.
1421 1437 if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) {
1422 1438 Label L;
1423 1439 // Note: frame::interpreter_frame_result has a dependency on how the
1424 1440 // method result is saved across the call to post_method_exit. If this
1425 1441 // is changed then the interpreter_frame_result implementation will
1426 1442 // need to be updated too.
1427 1443
1428 1444 // For c++ interpreter the result is always stored at a known location in the frame
1429 1445 // template interpreter will leave it on the top of the stack.
1430 1446 NOT_CC_INTERP(push(state);)
1431 1447 movl(rdx, Address(r15_thread, JavaThread::interp_only_mode_offset()));
1432 1448 testl(rdx, rdx);
1433 1449 jcc(Assembler::zero, L);
1434 1450 call_VM(noreg,
1435 1451 CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit));
1436 1452 bind(L);
1437 1453 NOT_CC_INTERP(pop(state));
1438 1454 }
1439 1455
1440 1456 {
1441 1457 SkipIfEqual skip(this, &DTraceMethodProbes, false);
1442 1458 NOT_CC_INTERP(push(state));
1443 1459 get_method(c_rarg1);
1444 1460 call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
1445 1461 r15_thread, c_rarg1);
1446 1462 NOT_CC_INTERP(pop(state));
1447 1463 }
1448 1464 }
1449 1465
1450 1466 // Jump if ((*counter_addr += increment) & mask) satisfies the condition.
1451 1467 void InterpreterMacroAssembler::increment_mask_and_jump(Address counter_addr,
1452 1468 int increment, int mask,
1453 1469 Register scratch, bool preloaded,
1454 1470 Condition cond, Label* where) {
1455 1471 if (!preloaded) {
1456 1472 movl(scratch, counter_addr);
1457 1473 }
1458 1474 incrementl(scratch, increment);
1459 1475 movl(counter_addr, scratch);
1460 1476 andl(scratch, mask);
1461 1477 jcc(cond, *where);
1462 1478 }
↓ open down ↓ |
1208 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX