void C1_MacroAssembler::build_frame(int frame_size_in_bytes, int bang_size_in_bytes) { // Avoid stack bang as first instruction. It may get overwritten by patch_verified_entry. const Register return_pc = R20; mflr(return_pc); // Make sure there is enough stack space for this method's activation. assert(bang_size_in_bytes >= frame_size_in_bytes, "stack bang size incorrect"); generate_stack_overflow_check(bang_size_in_bytes); std(return_pc, _abi(lr), R1_SP); // SP->lr = return_pc push_frame(frame_size_in_bytes, R0); // SP -= frame_size_in_bytes }
void emit_trampoline(struct compilation_unit *cu, void *target_addr, struct jit_trampoline *t) { struct buffer *b = t->objcode; jit_text_lock(); b->buf = jit_text_ptr(); /* Allocate memory on the stack */ emit(b, stwu(1, -16, 1)); /* Save LR on stack */ emit(b, mflr(0)); emit(b, stw(0, 0, 1)); /* Pass pointer to 'struct compilation_unit' as first argument */ emit(b, lis(3, ptr_high(cu))); emit(b, ori(3, 3, ptr_low(cu))); /* Then call 'target_addr' */ emit(b, lis(0, ptr_high(target_addr))); emit(b, ori(0, 0, ptr_low(target_addr))); emit(b, mtctr(0)); emit(b, bctrl()); /* Restore LR from stack */ emit(b, lwz(0, 0, 1)); emit(b, mtlr(0)); /* Free memory on stack */ emit(b, addi(1, 1, 16)); /* Finally jump to the compiled method */ emit(b, mtctr(3)); emit(b, bctr()); jit_text_reserve(buffer_offset(b)); jit_text_unlock(); }
address generate_call_stub(address& return_address) { assert (!TaggedStackInterpreter, "not supported"); StubCodeMark mark(this, "StubRoutines", "call_stub"); address start = __ enter(); const Register call_wrapper = r3; const Register result = r4; const Register result_type = r5; const Register method = r6; const Register entry_point = r7; const Register parameters = r8; const Register parameter_words = r9; const Register thread = r10; #ifdef ASSERT // Make sure we have no pending exceptions { StackFrame frame; Label label; __ load (r0, Address(thread, Thread::pending_exception_offset())); __ compare (r0, 0); __ beq (label); __ prolog (frame); __ should_not_reach_here (__FILE__, __LINE__); __ epilog (frame); __ blr (); __ bind (label); } #endif // ASSERT // Calculate the frame size StackFrame frame; for (int i = 0; i < StackFrame::max_crfs; i++) frame.get_cr_field(); for (int i = 0; i < StackFrame::max_gprs; i++) frame.get_register(); StubRoutines::set_call_stub_base_size(frame.unaligned_size() + 3*wordSize); // the 3 extra words are for call_wrapper, result and result_type const Register parameter_bytes = parameter_words; __ shift_left (parameter_bytes, parameter_words, LogBytesPerWord); const Register frame_size = r11; const Register padding = r12; __ addi (frame_size, parameter_bytes, StubRoutines::call_stub_base_size()); __ calc_padding_for_alignment (padding, frame_size, StackAlignmentInBytes); __ add (frame_size, frame_size, padding); // Save the link register and create the new frame __ mflr (r0); __ store (r0, Address(r1, StackFrame::lr_save_offset * wordSize)); __ neg (r0, frame_size); __ store_update_indexed (r1, r1, r0); #ifdef PPC64 __ mfcr (r0); __ store (r0, Address(r1, StackFrame::cr_save_offset * wordSize)); #endif // PPC64 // Calculate the address of the interpreter's local variables const Register locals = frame_size; __ addi (locals, r1, frame.start_of_locals() - wordSize); __ add (locals, locals, padding); __ add (locals, locals, parameter_bytes); // Store the call wrapper address and the result stuff const int initial_offset = 1; int offset = initial_offset; __ store (call_wrapper, Address(locals, offset++ * wordSize)); __ store (result, Address(locals, offset++ * wordSize)); __ store (result_type, Address(locals, offset++ * wordSize)); // Store the registers #ifdef PPC32 __ mfcr (r0); __ store (r0, Address(locals, offset++ * wordSize)); #endif // PPC32 for (int i = 14; i < 32; i++) { __ store (as_Register(i), Address(locals, offset++ * wordSize)); } const int final_offset = offset; // Store the location of call_wrapper frame::set_call_wrapper_offset((final_offset - initial_offset) * wordSize); #ifdef ASSERT // Check that we wrote all the way to the end of the frame. // The frame may have been resized when we return from the // interpreter, so the start of the frame may have moved // but the end will be where we left it and we rely on this // to find our stuff. { StackFrame frame; Label label; __ load (r3, Address(r1, 0)); __ subi (r3, r3, final_offset * wordSize); __ compare (r3, locals); __ beq (label); __ prolog (frame); __ should_not_reach_here (__FILE__, __LINE__); __ epilog (frame); __ blr (); __ bind (label); } #endif // ASSERT // Pass parameters if any { Label loop, done; __ compare (parameter_bytes, 0); __ ble (done); const Register src = parameters; const Register dst = padding; __ mr (dst, locals); __ shift_right (r0, parameter_bytes, LogBytesPerWord); __ mtctr (r0); __ bind (loop); __ load (r0, Address(src, 0)); __ store (r0, Address(dst, 0)); __ addi (src, src, wordSize); __ subi (dst, dst, wordSize); __ bdnz (loop); __ bind (done); } // Make the call __ mr (Rmethod, method); __ mr (Rlocals, locals); __ mr (Rthread, thread); __ mtctr (entry_point); __ bctrl(); // This is used to identify call_stub stack frames return_address = __ pc(); // Figure out where our stuff is stored __ load (locals, Address(r1, 0)); __ subi (locals, locals, final_offset * wordSize); #ifdef ASSERT // Rlocals should contain the address we just calculated. { StackFrame frame; Label label; __ compare (Rlocals, locals); __ beq (label); __ prolog (frame); __ should_not_reach_here (__FILE__, __LINE__); __ epilog (frame); __ blr (); __ bind (label); } #endif // ASSERT // Is an exception being thrown? Label exit; __ load (r0, Address(Rthread, Thread::pending_exception_offset())); __ compare (r0, 0); __ bne (exit); // Store result depending on type const Register result_addr = r6; Label is_int, is_long, is_object; offset = initial_offset + 1; // skip call_wrapper __ load (result_addr, Address(locals, offset++ * wordSize)); __ load (result_type, Address(locals, offset++ * wordSize)); __ compare (result_type, T_INT); __ beq (is_int); __ compare (result_type, T_LONG); __ beq (is_long); __ compare (result_type, T_OBJECT); __ beq (is_object); __ should_not_reach_here (__FILE__, __LINE__); __ bind (is_int); __ stw (r3, Address(result_addr, 0)); __ b (exit); __ bind (is_long); #ifdef PPC32 __ store (r4, Address(result_addr, wordSize)); #endif __ store (r3, Address(result_addr, 0)); __ b (exit); __ bind (is_object); __ store (r3, Address(result_addr, 0)); //__ b (exit); // Restore the registers __ bind (exit); #ifdef PPC32 __ load (r0, Address(locals, offset++ * wordSize)); __ mtcr (r0); #endif // PPC32 for (int i = 14; i < 32; i++) { __ load (as_Register(i), Address(locals, offset++ * wordSize)); } #ifdef PPC64 __ load (r0, Address(r1, StackFrame::cr_save_offset * wordSize)); __ mtcr (r0); #endif // PPC64 assert (offset == final_offset, "save and restore must match"); // Unwind and return __ load (r1, Address(r1, StackFrame::back_chain_offset * wordSize)); __ load (r0, Address(r1, StackFrame::lr_save_offset * wordSize)); __ mtlr (r0); __ blr (); return start; }
void CppInterpreterGenerator::generate_compute_interpreter_state(bool native) { StackFrame frame; const Address stack_words_addr( Rmethod, methodOopDesc::max_stack_offset()); const Address access_flags_addr( Rmethod, methodOopDesc::access_flags_offset()); Label not_synchronized_1, not_synchronized_2, not_synchronized_3; Label not_static, init_monitor; const int monitor_size = frame::interpreter_frame_monitor_size() * wordSize; // Calculate the access flags conditions const Register access_flags = r3; __ lwz (access_flags, access_flags_addr); __ andi_ (r0, access_flags, JVM_ACC_SYNCHRONIZED); __ compare (CRsync, r0, JVM_ACC_SYNCHRONIZED); __ andi_ (r0, access_flags, JVM_ACC_STATIC); __ compare (CRstatic, r0, JVM_ACC_STATIC); const int basic_frame_size = frame.unaligned_size() + sizeof(BytecodeInterpreter) + slop_factor; // Calculate the frame size const Register stack_size = r3; const Register frame_size = r4; const Register padding = r5; if (native) { __ load (frame_size, basic_frame_size); } else { __ lhz (stack_size, stack_words_addr); __ shift_left (stack_size, stack_size, LogBytesPerWord); __ addi (frame_size, stack_size, basic_frame_size); } __ bne (CRsync, not_synchronized_1); __ addi (frame_size, frame_size, monitor_size); __ bind (not_synchronized_1); __ calc_padding_for_alignment (padding, frame_size, StackAlignmentInBytes); __ add (frame_size, frame_size, padding); // Save the link register and create the new frame __ mflr (r0); __ store (r0, Address(r1, StackFrame::lr_save_offset * wordSize)); __ neg (r0, frame_size); __ store_update_indexed (r1, r1, r0); // Calculate everything's addresses const Register stack_limit = r6; const Register stack = r7; const Register stack_base = Rmonitor; const Register monitor_base = r8; __ addi (stack_limit, r1, frame.start_of_locals() + slop_factor - wordSize); __ add (stack_limit, stack_limit, padding); if (native) __ mr (stack, stack_limit); else __ add (stack, stack_limit, stack_size); __ addi (stack_base, stack, wordSize); __ mr (monitor_base, stack_base); __ bne (CRsync, not_synchronized_2); __ addi (monitor_base, monitor_base, monitor_size); __ bind (not_synchronized_2); __ mr (r0, Rstate); __ mr (Rstate, monitor_base); // Initialise the interpreter state object __ store (Rlocals, STATE(_locals)); __ store (Rmethod, STATE(_method)); __ store (Rstate, STATE(_self_link)); __ store (r0, STATE(_prev_link)); __ store (stack_limit, STATE(_stack_limit)); __ store (stack, STATE(_stack)); __ store (stack_base, STATE(_stack_base)); __ store (monitor_base, STATE(_monitor_base)); __ store (Rthread, STATE(_thread)); #ifdef ASSERT { Label ok; __ load (r3, ThreadLocalStorage::thread_index()); __ call (CAST_FROM_FN_PTR(address, pthread_getspecific)); __ compare (Rthread, r3); __ beq (ok); __ should_not_reach_here (__FILE__, __LINE__); __ bind (ok); } #endif if (!native) { __ load (r3, Address(Rmethod, methodOopDesc::const_offset())); __ addi (r3, r3, in_bytes(constMethodOopDesc::codes_offset())); __ store (r3, STATE(_bcp)); } __ load (r3, Address(Rmethod, methodOopDesc::constants_offset())); __ load (r3, Address(r3, constantPoolOopDesc::cache_offset_in_bytes())); __ store (r3, STATE(_constants)); __ load (r3, BytecodeInterpreter::method_entry); __ stw (r3, STATE(_msg)); __ load (r3, 0); if (native) __ store (r3, STATE(_bcp)); __ store (r3, STATE(_oop_temp)); __ store (r3, STATE(_mdx)); __ store (r3, STATE(_result._to_call._callee)); // Initialise the monitor if synchronized __ bne (CRsync, not_synchronized_3); __ bne (CRstatic, not_static); __ get_mirror_handle (r3); __ b (init_monitor); __ bind (not_static); __ load (r3, Address(Rlocals, 0)); __ bind (init_monitor); __ store (r3, Address(Rmonitor, BasicObjectLock::obj_offset_in_bytes())); __ bind (not_synchronized_3); }