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