33 34 // Release the CompiledICHolder* associated with this call site is there is one. 35 void CompiledIC::cleanup_call_site(virtual_call_Relocation* call_site) { 36 // This call site might have become stale so inspect it carefully. 37 NativeCall* call = nativeCall_at(call_site->addr()); 38 if (is_icholder_entry(call->destination())) { 39 NativeMovConstReg* value = nativeMovConstReg_at(call_site->cached_value()); 40 InlineCacheBuffer::queue_for_release((CompiledICHolder*)value->data()); 41 } 42 } 43 44 bool CompiledIC::is_icholder_call_site(virtual_call_Relocation* call_site) { 45 // This call site might have become stale so inspect it carefully. 46 NativeCall* call = nativeCall_at(call_site->addr()); 47 return is_icholder_entry(call->destination()); 48 } 49 50 // ---------------------------------------------------------------------------- 51 52 #define __ _masm. 53 address CompiledStaticCall::emit_to_interp_stub(CodeBuffer &cbuf) { 54 // Stub is fixed up when the corresponding call is converted from 55 // calling compiled code to calling interpreted code. 56 // movq rbx, 0 57 // jmp -5 # to self 58 59 address mark = cbuf.insts_mark(); // Get mark within main instrs section. 60 61 // Note that the code buffer's insts_mark is always relative to insts. 62 // That's why we must use the macroassembler to generate a stub. 63 MacroAssembler _masm(&cbuf); 64 65 address base = __ start_a_stub(to_interp_stub_size()); 66 if (base == NULL) { 67 return NULL; // CodeBuffer::expand failed. 68 } 69 // Static stub relocation stores the instruction address of the call. 70 __ relocate(static_stub_Relocation::spec(mark), Assembler::imm_operand); 71 // Static stub relocation also tags the Method* in the code-stream. 72 __ mov_metadata(rbx, (Metadata*) NULL); // Method is zapped till fixup time. 73 // This is recognized as unresolved by relocs/nativeinst/ic code. 74 __ jump(RuntimeAddress(__ pc())); 75 76 // Update current stubs pointer and restore insts_end. 77 __ end_a_stub(); 78 return base; 79 } 80 #undef __ 81 82 int CompiledStaticCall::to_interp_stub_size() { 83 return NOT_LP64(10) // movl; jmp 84 LP64_ONLY(15); // movq (1+1+8); jmp (1+4) 85 } 86 87 // Relocation entries for call stub, compiled java to interpreter. 88 int CompiledStaticCall::reloc_to_interp_stub() { 89 return 4; // 3 in emit_to_interp_stub + 1 in emit_call 90 } 91 92 void CompiledStaticCall::set_to_interpreted(methodHandle callee, address entry) { 93 address stub = find_stub(); 94 guarantee(stub != NULL, "stub not found"); 95 96 if (TraceICs) { 97 ResourceMark rm; 98 tty->print_cr("CompiledStaticCall@" INTPTR_FORMAT ": set_to_interpreted %s", 99 p2i(instruction_address()), 100 callee->name_and_sig_as_C_string()); 101 } 102 103 // Creation also verifies the object. 104 NativeMovConstReg* method_holder = nativeMovConstReg_at(stub); 105 NativeJump* jump = nativeJump_at(method_holder->next_instruction_address()); 106 107 assert(method_holder->data() == 0 || method_holder->data() == (intptr_t)callee(), 108 "a) MT-unsafe modification of inline cache"); 109 assert(jump->jump_destination() == (address)-1 || jump->jump_destination() == entry, 110 "b) MT-unsafe modification of inline cache"); 111 112 // Update stub. 113 method_holder->set_data((intptr_t)callee()); 114 jump->set_jump_destination(entry); 115 116 // Update jump to call. 117 set_destination_mt_safe(stub); 118 } 119 120 void CompiledStaticCall::set_stub_to_clean(static_stub_Relocation* static_stub) { 121 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "mt unsafe call"); 122 // Reset stub. 123 address stub = static_stub->addr(); 124 assert(stub != NULL, "stub not found"); 125 // Creation also verifies the object. 126 NativeMovConstReg* method_holder = nativeMovConstReg_at(stub); 127 NativeJump* jump = nativeJump_at(method_holder->next_instruction_address()); 128 method_holder->set_data(0); 129 jump->set_jump_destination((address)-1); 130 } 131 132 //----------------------------------------------------------------------------- 133 // Non-product mode code 134 #ifndef PRODUCT 135 136 void CompiledStaticCall::verify() { 137 // Verify call. 138 NativeCall::verify(); 139 if (os::is_MP()) { 140 verify_alignment(); 141 } 142 143 // Verify stub. 144 address stub = find_stub(); 145 assert(stub != NULL, "no stub found for static call"); 146 // Creation also verifies the object. 147 NativeMovConstReg* method_holder = nativeMovConstReg_at(stub); 148 NativeJump* jump = nativeJump_at(method_holder->next_instruction_address()); 149 150 // Verify state. 151 assert(is_clean() || is_call_to_compiled() || is_call_to_interpreted(), "sanity check"); 152 } 153 154 #endif // !PRODUCT | 33 34 // Release the CompiledICHolder* associated with this call site is there is one. 35 void CompiledIC::cleanup_call_site(virtual_call_Relocation* call_site) { 36 // This call site might have become stale so inspect it carefully. 37 NativeCall* call = nativeCall_at(call_site->addr()); 38 if (is_icholder_entry(call->destination())) { 39 NativeMovConstReg* value = nativeMovConstReg_at(call_site->cached_value()); 40 InlineCacheBuffer::queue_for_release((CompiledICHolder*)value->data()); 41 } 42 } 43 44 bool CompiledIC::is_icholder_call_site(virtual_call_Relocation* call_site) { 45 // This call site might have become stale so inspect it carefully. 46 NativeCall* call = nativeCall_at(call_site->addr()); 47 return is_icholder_entry(call->destination()); 48 } 49 50 // ---------------------------------------------------------------------------- 51 52 #define __ _masm. 53 address CompiledStaticCall::emit_to_interp_stub(CodeBuffer &cbuf, address mark) { 54 // Stub is fixed up when the corresponding call is converted from 55 // calling compiled code to calling interpreted code. 56 // movq rbx, 0 57 // jmp -5 # to self 58 59 if (mark == NULL) { 60 mark = cbuf.insts_mark(); // Get mark within main instrs section. 61 } 62 63 // Note that the code buffer's insts_mark is always relative to insts. 64 // That's why we must use the macroassembler to generate a stub. 65 MacroAssembler _masm(&cbuf); 66 67 address base = __ start_a_stub(to_interp_stub_size()); 68 if (base == NULL) { 69 return NULL; // CodeBuffer::expand failed. 70 } 71 // Static stub relocation stores the instruction address of the call. 72 __ relocate(static_stub_Relocation::spec(mark), Assembler::imm_operand); 73 // Static stub relocation also tags the Method* in the code-stream. 74 __ mov_metadata(rbx, (Metadata*) NULL); // Method is zapped till fixup time. 75 // This is recognized as unresolved by relocs/nativeinst/ic code. 76 __ jump(RuntimeAddress(__ pc())); 77 78 assert(__ pc() - base <= to_interp_stub_size(), "wrong stub size"); 79 80 // Update current stubs pointer and restore insts_end. 81 __ end_a_stub(); 82 return base; 83 } 84 #undef __ 85 86 int CompiledStaticCall::to_interp_stub_size() { 87 return NOT_LP64(10) // movl; jmp 88 LP64_ONLY(15); // movq (1+1+8); jmp (1+4) 89 } 90 91 // Relocation entries for call stub, compiled java to interpreter. 92 int CompiledStaticCall::reloc_to_interp_stub() { 93 return 4; // 3 in emit_to_interp_stub + 1 in emit_call 94 } 95 96 void CompiledStaticCall::set_to_interpreted(methodHandle callee, address entry) { 97 address stub = find_stub(); 98 guarantee(stub != NULL, "stub not found"); 99 100 if (TraceICs) { 101 ResourceMark rm; 102 tty->print_cr("CompiledStaticCall@" INTPTR_FORMAT ": set_to_interpreted %s", 103 p2i(instruction_address()), 104 callee->name_and_sig_as_C_string()); 105 } 106 107 // Creation also verifies the object. 108 NativeMovConstReg* method_holder = nativeMovConstReg_at(stub); 109 NativeJump* jump = nativeJump_at(method_holder->next_instruction_address()); 110 111 #ifdef ASSERT 112 // read the value once 113 intptr_t data = method_holder->data(); 114 address destination = jump->jump_destination(); 115 assert(data == 0 || data == (intptr_t)callee(), 116 "a) MT-unsafe modification of inline cache"); 117 assert(destination == (address)-1 || destination == entry, 118 "b) MT-unsafe modification of inline cache"); 119 #endif 120 121 // Update stub. 122 method_holder->set_data((intptr_t)callee()); 123 jump->set_jump_destination(entry); 124 125 // Update jump to call. 126 set_destination_mt_safe(stub); 127 } 128 129 void CompiledStaticCall::set_stub_to_clean(static_stub_Relocation* static_stub) { 130 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "mt unsafe call"); 131 // Reset stub. 132 address stub = static_stub->addr(); 133 assert(stub != NULL, "stub not found"); 134 // Creation also verifies the object. 135 NativeMovConstReg* method_holder = nativeMovConstReg_at(stub); 136 method_holder->set_data(0); 137 NativeJump* jump = nativeJump_at(method_holder->next_instruction_address()); 138 jump->set_jump_destination((address)-1); 139 } 140 141 142 //----------------------------------------------------------------------------- 143 // Non-product mode code 144 #ifndef PRODUCT 145 146 void CompiledStaticCall::verify() { 147 // Verify call. 148 NativeCall::verify(); 149 if (os::is_MP()) { 150 verify_alignment(); 151 } 152 153 // Verify stub. 154 address stub = find_stub(); 155 assert(stub != NULL, "no stub found for static call"); 156 // Creation also verifies the object. 157 NativeMovConstReg* method_holder = nativeMovConstReg_at(stub); 158 NativeJump* jump = nativeJump_at(method_holder->next_instruction_address()); 159 160 // Verify state. 161 assert(is_clean() || is_call_to_compiled() || is_call_to_interpreted(), "sanity check"); 162 } 163 #endif // !PRODUCT |