68 address pc = _instructions->start() + pc_offset; 69 Handle obj = HotSpotObjectConstantImpl::object(constant); 70 jobject value = JNIHandles::make_local(obj()); 71 if (HotSpotObjectConstantImpl::compressed(constant)) { 72 #ifdef _LP64 73 address operand = Assembler::locate_operand(pc, Assembler::narrow_oop_operand); 74 int oop_index = _oop_recorder->find_index(value); 75 _instructions->relocate(pc, oop_Relocation::spec(oop_index), Assembler::narrow_oop_operand); 76 TRACE_jvmci_3("relocating (narrow oop constant) at " PTR_FORMAT "/" PTR_FORMAT, p2i(pc), p2i(operand)); 77 #else 78 fatal("compressed oop on 32bit"); 79 #endif 80 } else { 81 address operand = Assembler::locate_operand(pc, Assembler::imm_operand); 82 *((jobject*) operand) = value; 83 _instructions->relocate(pc, oop_Relocation::spec_for_immediate(), Assembler::imm_operand); 84 TRACE_jvmci_3("relocating (oop constant) at " PTR_FORMAT "/" PTR_FORMAT, p2i(pc), p2i(operand)); 85 } 86 } 87 88 void CodeInstaller::pd_patch_DataSectionReference(int pc_offset, int data_offset) { 89 address pc = _instructions->start() + pc_offset; 90 91 address operand = Assembler::locate_operand(pc, Assembler::disp32_operand); 92 address next_instruction = Assembler::locate_next_instruction(pc); 93 address dest = _constants->start() + data_offset; 94 95 long disp = dest - next_instruction; 96 assert(disp == (jint) disp, "disp doesn't fit in 32 bits"); 97 *((jint*) operand) = (jint) disp; 98 99 _instructions->relocate(pc, section_word_Relocation::spec((address) dest, CodeBuffer::SECT_CONSTS), Assembler::disp32_operand); 100 TRACE_jvmci_3("relocating at " PTR_FORMAT "/" PTR_FORMAT " with destination at " PTR_FORMAT " (%d)", p2i(pc), p2i(operand), p2i(dest), data_offset); 101 } 102 103 void CodeInstaller::pd_relocate_CodeBlob(CodeBlob* cb, NativeInstruction* inst) { 104 if (cb->is_nmethod()) { 105 nmethod* nm = (nmethod*) cb; 106 nativeJump_at((address)inst)->set_jump_destination(nm->verified_entry_point()); 107 } else { 108 nativeJump_at((address)inst)->set_jump_destination(cb->code_begin()); 109 } 110 _instructions->relocate((address)inst, runtime_call_Relocation::spec(), Assembler::call32_operand); 111 } 112 113 void CodeInstaller::pd_relocate_ForeignCall(NativeInstruction* inst, jlong foreign_call_destination) { 114 address pc = (address) inst; 115 if (inst->is_call()) { 116 // NOTE: for call without a mov, the offset must fit a 32-bit immediate 117 // see also CompilerToVM.getMaxCallTargetOffset() 118 NativeCall* call = nativeCall_at(pc); 119 call->set_destination((address) foreign_call_destination); 120 _instructions->relocate(call->instruction_address(), runtime_call_Relocation::spec(), Assembler::call32_operand); 121 } else if (inst->is_mov_literal64()) { 122 NativeMovConstReg* mov = nativeMovConstReg_at(pc); 123 mov->set_data((intptr_t) foreign_call_destination); 124 _instructions->relocate(mov->instruction_address(), runtime_call_Relocation::spec(), Assembler::imm_operand); 125 } else if (inst->is_jump()) { 126 NativeJump* jump = nativeJump_at(pc); 127 jump->set_jump_destination((address) foreign_call_destination); 128 _instructions->relocate(jump->instruction_address(), runtime_call_Relocation::spec(), Assembler::call32_operand); 129 } else if (inst->is_cond_jump()) { 130 address old_dest = nativeGeneralJump_at(pc)->jump_destination(); 131 address disp = Assembler::locate_operand(pc, Assembler::call32_operand); 132 *(jint*) disp += ((address) foreign_call_destination) - old_dest; | 68 address pc = _instructions->start() + pc_offset; 69 Handle obj = HotSpotObjectConstantImpl::object(constant); 70 jobject value = JNIHandles::make_local(obj()); 71 if (HotSpotObjectConstantImpl::compressed(constant)) { 72 #ifdef _LP64 73 address operand = Assembler::locate_operand(pc, Assembler::narrow_oop_operand); 74 int oop_index = _oop_recorder->find_index(value); 75 _instructions->relocate(pc, oop_Relocation::spec(oop_index), Assembler::narrow_oop_operand); 76 TRACE_jvmci_3("relocating (narrow oop constant) at " PTR_FORMAT "/" PTR_FORMAT, p2i(pc), p2i(operand)); 77 #else 78 fatal("compressed oop on 32bit"); 79 #endif 80 } else { 81 address operand = Assembler::locate_operand(pc, Assembler::imm_operand); 82 *((jobject*) operand) = value; 83 _instructions->relocate(pc, oop_Relocation::spec_for_immediate(), Assembler::imm_operand); 84 TRACE_jvmci_3("relocating (oop constant) at " PTR_FORMAT "/" PTR_FORMAT, p2i(pc), p2i(operand)); 85 } 86 } 87 88 void CodeInstaller::pd_patch_MetaspaceConstant(int pc_offset, Handle& constant) { 89 address pc = _instructions->start() + pc_offset; 90 if (HotSpotMetaspaceConstantImpl::compressed(constant)) { 91 #ifdef _LP64 92 address operand = Assembler::locate_operand(pc, Assembler::narrow_oop_operand); 93 *((narrowKlass*) operand) = record_narrow_metadata_reference(constant); 94 TRACE_jvmci_3("relocating (narrow metaspace constant) at " PTR_FORMAT "/" PTR_FORMAT, p2i(pc), p2i(operand)); 95 #else 96 fatal("compressed Klass* on 32bit"); 97 #endif 98 } else { 99 address operand = Assembler::locate_operand(pc, Assembler::imm_operand); 100 *((Metadata**) operand) = record_metadata_reference(constant); 101 TRACE_jvmci_3("relocating (metaspace constant) at " PTR_FORMAT "/" PTR_FORMAT, p2i(pc), p2i(operand)); 102 } 103 } 104 105 void CodeInstaller::pd_patch_DataSectionReference(int pc_offset, int data_offset) { 106 address pc = _instructions->start() + pc_offset; 107 108 address operand = Assembler::locate_operand(pc, Assembler::disp32_operand); 109 address next_instruction = Assembler::locate_next_instruction(pc); 110 address dest = _constants->start() + data_offset; 111 112 long disp = dest - next_instruction; 113 assert(disp == (jint) disp, "disp doesn't fit in 32 bits"); 114 *((jint*) operand) = (jint) disp; 115 116 _instructions->relocate(pc, section_word_Relocation::spec((address) dest, CodeBuffer::SECT_CONSTS), Assembler::disp32_operand); 117 TRACE_jvmci_3("relocating at " PTR_FORMAT "/" PTR_FORMAT " with destination at " PTR_FORMAT " (%d)", p2i(pc), p2i(operand), p2i(dest), data_offset); 118 } 119 120 void CodeInstaller::pd_relocate_ForeignCall(NativeInstruction* inst, jlong foreign_call_destination) { 121 address pc = (address) inst; 122 if (inst->is_call()) { 123 // NOTE: for call without a mov, the offset must fit a 32-bit immediate 124 // see also CompilerToVM.getMaxCallTargetOffset() 125 NativeCall* call = nativeCall_at(pc); 126 call->set_destination((address) foreign_call_destination); 127 _instructions->relocate(call->instruction_address(), runtime_call_Relocation::spec(), Assembler::call32_operand); 128 } else if (inst->is_mov_literal64()) { 129 NativeMovConstReg* mov = nativeMovConstReg_at(pc); 130 mov->set_data((intptr_t) foreign_call_destination); 131 _instructions->relocate(mov->instruction_address(), runtime_call_Relocation::spec(), Assembler::imm_operand); 132 } else if (inst->is_jump()) { 133 NativeJump* jump = nativeJump_at(pc); 134 jump->set_jump_destination((address) foreign_call_destination); 135 _instructions->relocate(jump->instruction_address(), runtime_call_Relocation::spec(), Assembler::call32_operand); 136 } else if (inst->is_cond_jump()) { 137 address old_dest = nativeGeneralJump_at(pc)->jump_destination(); 138 address disp = Assembler::locate_operand(pc, Assembler::call32_operand); 139 *(jint*) disp += ((address) foreign_call_destination) - old_dest; |