19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 *
25 */
26
27 #include "precompiled.hpp"
28 #include "asm/assembler.hpp"
29 #include "asm/assembler.inline.hpp"
30 #include "code/compiledIC.hpp"
31 #include "compiler/disassembler.hpp"
32 #include "gc/shared/barrierSet.hpp"
33 #include "gc/shared/barrierSetAssembler.hpp"
34 #include "gc/shared/cardTable.hpp"
35 #include "gc/shared/cardTableBarrierSet.hpp"
36 #include "gc/shared/collectedHeap.hpp"
37 #include "interpreter/bytecodeHistogram.hpp"
38 #include "interpreter/interpreter.hpp"
39 #include "memory/resourceArea.hpp"
40 #include "memory/universe.hpp"
41 #include "oops/accessDecorators.hpp"
42 #include "oops/compressedKlass.inline.hpp"
43 #include "oops/compressedOops.inline.hpp"
44 #include "oops/klass.inline.hpp"
45 #include "oops/oop.hpp"
46 #include "runtime/interfaceSupport.inline.hpp"
47 #include "runtime/javaThread.hpp"
48 #include "runtime/jniHandles.inline.hpp"
49 #include "runtime/sharedRuntime.hpp"
50 #include "runtime/stubRoutines.hpp"
51 #include "utilities/globalDefinitions.hpp"
52 #include "utilities/powerOfTwo.hpp"
53 #ifdef COMPILER2
54 #include "opto/compile.hpp"
55 #include "opto/node.hpp"
56 #include "opto/output.hpp"
57 #endif
58
209 }
210
211 void MacroAssembler::push_cont_fastpath(Register java_thread) {
212 if (!Continuations::enabled()) return;
213 Label done;
214 ld(t0, Address(java_thread, JavaThread::cont_fastpath_offset()));
215 bleu(sp, t0, done);
216 sd(sp, Address(java_thread, JavaThread::cont_fastpath_offset()));
217 bind(done);
218 }
219
220 void MacroAssembler::pop_cont_fastpath(Register java_thread) {
221 if (!Continuations::enabled()) return;
222 Label done;
223 ld(t0, Address(java_thread, JavaThread::cont_fastpath_offset()));
224 bltu(sp, t0, done);
225 sd(zr, Address(java_thread, JavaThread::cont_fastpath_offset()));
226 bind(done);
227 }
228
229 int MacroAssembler::align(int modulus, int extra_offset) {
230 CompressibleRegion cr(this);
231 intptr_t before = offset();
232 while ((offset() + extra_offset) % modulus != 0) { nop(); }
233 return (int)(offset() - before);
234 }
235
236 void MacroAssembler::call_VM_helper(Register oop_result, address entry_point, int number_of_arguments, bool check_exceptions) {
237 call_VM_base(oop_result, noreg, noreg, entry_point, number_of_arguments, check_exceptions);
238 }
239
240 // Implementation of call_VM versions
241
242 void MacroAssembler::call_VM(Register oop_result,
243 address entry_point,
244 bool check_exceptions) {
245 call_VM_helper(oop_result, entry_point, 0, check_exceptions);
246 }
247
248 void MacroAssembler::call_VM(Register oop_result,
390 L.add_patch_at(code(), locator());
391 IncompressibleRegion ir(this); // the label address will be patched back.
392 set_last_Java_frame(last_java_sp, last_java_fp, pc() /* Patched later */, tmp);
393 }
394 }
395
396 void MacroAssembler::reset_last_Java_frame(bool clear_fp) {
397 // we must set sp to zero to clear frame
398 sd(zr, Address(xthread, JavaThread::last_Java_sp_offset()));
399
400 // must clear fp, so that compiled frames are not confused; it is
401 // possible that we need it only for debugging
402 if (clear_fp) {
403 sd(zr, Address(xthread, JavaThread::last_Java_fp_offset()));
404 }
405
406 // Always clear the pc because it could have been set by make_walkable()
407 sd(zr, Address(xthread, JavaThread::last_Java_pc_offset()));
408 }
409
410 void MacroAssembler::call_VM_base(Register oop_result,
411 Register java_thread,
412 Register last_java_sp,
413 address entry_point,
414 int number_of_arguments,
415 bool check_exceptions) {
416 // determine java_thread register
417 if (!java_thread->is_valid()) {
418 java_thread = xthread;
419 }
420 // determine last_java_sp register
421 if (!last_java_sp->is_valid()) {
422 last_java_sp = esp;
423 }
424
425 // debugging support
426 assert(number_of_arguments >= 0 , "cannot have negative number of arguments");
427 assert(java_thread == xthread, "unexpected register");
428
429 assert(java_thread != oop_result , "cannot use the same register for java_thread & oop_result");
430 assert(java_thread != last_java_sp, "cannot use the same register for java_thread & last_java_sp");
431
432 // push java thread (becomes first argument of C function)
433 mv(c_rarg0, java_thread);
434
435 // set last Java frame before call
436 assert(last_java_sp != fp, "can't use fp");
437
438 Label l;
439 set_last_Java_frame(last_java_sp, fp, l, t0);
440
441 // do the call, remove parameters
442 MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments, &l);
443
444 // reset last Java frame
445 // Only interpreter should have to clear fp
446 reset_last_Java_frame(true);
447
448 // C++ interp handles this in the interpreter
449 check_and_handle_popframe(java_thread);
450 check_and_handle_earlyret(java_thread);
451
452 if (check_exceptions) {
453 // check for pending exceptions (java_thread is set upon return)
454 ld(t0, Address(java_thread, in_bytes(Thread::pending_exception_offset())));
455 Label ok;
456 beqz(t0, ok);
457 RuntimeAddress target(StubRoutines::forward_exception_entry());
458 relocate(target.rspec(), [&] {
459 int32_t offset;
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 *
25 */
26
27 #include "precompiled.hpp"
28 #include "asm/assembler.hpp"
29 #include "asm/assembler.inline.hpp"
30 #include "code/compiledIC.hpp"
31 #include "compiler/disassembler.hpp"
32 #include "gc/shared/barrierSet.hpp"
33 #include "gc/shared/barrierSetAssembler.hpp"
34 #include "gc/shared/cardTable.hpp"
35 #include "gc/shared/cardTableBarrierSet.hpp"
36 #include "gc/shared/collectedHeap.hpp"
37 #include "interpreter/bytecodeHistogram.hpp"
38 #include "interpreter/interpreter.hpp"
39 #include "interpreter/interpreterRuntime.hpp"
40 #include "memory/resourceArea.hpp"
41 #include "memory/universe.hpp"
42 #include "oops/accessDecorators.hpp"
43 #include "oops/compressedKlass.inline.hpp"
44 #include "oops/compressedOops.inline.hpp"
45 #include "oops/klass.inline.hpp"
46 #include "oops/oop.hpp"
47 #include "runtime/interfaceSupport.inline.hpp"
48 #include "runtime/javaThread.hpp"
49 #include "runtime/jniHandles.inline.hpp"
50 #include "runtime/sharedRuntime.hpp"
51 #include "runtime/stubRoutines.hpp"
52 #include "utilities/globalDefinitions.hpp"
53 #include "utilities/powerOfTwo.hpp"
54 #ifdef COMPILER2
55 #include "opto/compile.hpp"
56 #include "opto/node.hpp"
57 #include "opto/output.hpp"
58 #endif
59
210 }
211
212 void MacroAssembler::push_cont_fastpath(Register java_thread) {
213 if (!Continuations::enabled()) return;
214 Label done;
215 ld(t0, Address(java_thread, JavaThread::cont_fastpath_offset()));
216 bleu(sp, t0, done);
217 sd(sp, Address(java_thread, JavaThread::cont_fastpath_offset()));
218 bind(done);
219 }
220
221 void MacroAssembler::pop_cont_fastpath(Register java_thread) {
222 if (!Continuations::enabled()) return;
223 Label done;
224 ld(t0, Address(java_thread, JavaThread::cont_fastpath_offset()));
225 bltu(sp, t0, done);
226 sd(zr, Address(java_thread, JavaThread::cont_fastpath_offset()));
227 bind(done);
228 }
229
230 void MacroAssembler::inc_held_monitor_count(Register tmp) {
231 Address dst = Address(xthread, JavaThread::held_monitor_count_offset());
232 ld(tmp, dst);
233 addi(tmp, tmp, 1);
234 sd(tmp, dst);
235 #ifdef ASSERT
236 Label ok;
237 test_bit(tmp, tmp, 63);
238 beqz(tmp, ok);
239 STOP("assert(held monitor count overflow)");
240 should_not_reach_here();
241 bind(ok);
242 #endif
243 }
244
245 void MacroAssembler::dec_held_monitor_count(Register tmp) {
246 Address dst = Address(xthread, JavaThread::held_monitor_count_offset());
247 ld(tmp, dst);
248 addi(tmp, tmp, -1);
249 sd(tmp, dst);
250 #ifdef ASSERT
251 Label ok;
252 test_bit(tmp, tmp, 63);
253 beqz(tmp, ok);
254 STOP("assert(held monitor count underflow)");
255 should_not_reach_here();
256 bind(ok);
257 #endif
258 }
259
260 int MacroAssembler::align(int modulus, int extra_offset) {
261 CompressibleRegion cr(this);
262 intptr_t before = offset();
263 while ((offset() + extra_offset) % modulus != 0) { nop(); }
264 return (int)(offset() - before);
265 }
266
267 void MacroAssembler::call_VM_helper(Register oop_result, address entry_point, int number_of_arguments, bool check_exceptions) {
268 call_VM_base(oop_result, noreg, noreg, entry_point, number_of_arguments, check_exceptions);
269 }
270
271 // Implementation of call_VM versions
272
273 void MacroAssembler::call_VM(Register oop_result,
274 address entry_point,
275 bool check_exceptions) {
276 call_VM_helper(oop_result, entry_point, 0, check_exceptions);
277 }
278
279 void MacroAssembler::call_VM(Register oop_result,
421 L.add_patch_at(code(), locator());
422 IncompressibleRegion ir(this); // the label address will be patched back.
423 set_last_Java_frame(last_java_sp, last_java_fp, pc() /* Patched later */, tmp);
424 }
425 }
426
427 void MacroAssembler::reset_last_Java_frame(bool clear_fp) {
428 // we must set sp to zero to clear frame
429 sd(zr, Address(xthread, JavaThread::last_Java_sp_offset()));
430
431 // must clear fp, so that compiled frames are not confused; it is
432 // possible that we need it only for debugging
433 if (clear_fp) {
434 sd(zr, Address(xthread, JavaThread::last_Java_fp_offset()));
435 }
436
437 // Always clear the pc because it could have been set by make_walkable()
438 sd(zr, Address(xthread, JavaThread::last_Java_pc_offset()));
439 }
440
441 static bool is_preemptable(address entry_point) {
442 return entry_point == CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter);
443 }
444
445 void MacroAssembler::call_VM_base(Register oop_result,
446 Register java_thread,
447 Register last_java_sp,
448 address entry_point,
449 int number_of_arguments,
450 bool check_exceptions) {
451 // determine java_thread register
452 if (!java_thread->is_valid()) {
453 java_thread = xthread;
454 }
455 // determine last_java_sp register
456 if (!last_java_sp->is_valid()) {
457 last_java_sp = esp;
458 }
459
460 // debugging support
461 assert(number_of_arguments >= 0 , "cannot have negative number of arguments");
462 assert(java_thread == xthread, "unexpected register");
463
464 assert(java_thread != oop_result , "cannot use the same register for java_thread & oop_result");
465 assert(java_thread != last_java_sp, "cannot use the same register for java_thread & last_java_sp");
466
467 // push java thread (becomes first argument of C function)
468 mv(c_rarg0, java_thread);
469
470 // set last Java frame before call
471 assert(last_java_sp != fp, "can't use fp");
472
473 Label l;
474 if (is_preemptable(entry_point)) {
475 // skip setting last_pc since we already set it to desired value.
476 set_last_Java_frame(last_java_sp, fp, noreg);
477 } else {
478 set_last_Java_frame(last_java_sp, fp, l, t0);
479 }
480
481 // do the call, remove parameters
482 MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments, &l);
483
484 // reset last Java frame
485 // Only interpreter should have to clear fp
486 reset_last_Java_frame(true);
487
488 // C++ interp handles this in the interpreter
489 check_and_handle_popframe(java_thread);
490 check_and_handle_earlyret(java_thread);
491
492 if (check_exceptions) {
493 // check for pending exceptions (java_thread is set upon return)
494 ld(t0, Address(java_thread, in_bytes(Thread::pending_exception_offset())));
495 Label ok;
496 beqz(t0, ok);
497 RuntimeAddress target(StubRoutines::forward_exception_entry());
498 relocate(target.rspec(), [&] {
499 int32_t offset;
|