18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 #include "jvmci/jvmciCodeInstaller.hpp"
25 #include "jvmci/jvmciRuntime.hpp"
26 #include "jvmci/jvmciCompilerToVM.hpp"
27 #include "jvmci/jvmciJavaClasses.hpp"
28 #include "oops/oop.inline.hpp"
29 #include "runtime/handles.inline.hpp"
30 #include "runtime/sharedRuntime.hpp"
31 #include "vmreg_aarch64.inline.hpp"
32
33 jint CodeInstaller::pd_next_offset(NativeInstruction* inst, jint pc_offset, Handle method, TRAPS) {
34 if (inst->is_call() || inst->is_jump() || inst->is_blr()) {
35 return pc_offset + NativeCall::instruction_size;
36 } else if (inst->is_general_jump()) {
37 return pc_offset + NativeGeneralJump::instruction_size;
38 } else {
39 JVMCI_ERROR_0("unsupported type of instruction for call site");
40 }
41 }
42
43 void CodeInstaller::pd_patch_OopConstant(int pc_offset, Handle constant, TRAPS) {
44 address pc = _instructions->start() + pc_offset;
45 #ifdef ASSERT
46 {
47 NativeInstruction *insn = nativeInstruction_at(pc);
48 if (HotSpotObjectConstantImpl::compressed(constant)) {
49 // Mov narrow constant: movz n << 16, movk
50 assert(Instruction_aarch64::extract(insn->encoding(), 31, 21) == 0b11010010101 &&
51 nativeInstruction_at(pc+4)->is_movk(), "wrong insn in patch");
52 } else {
53 // Move wide constant: movz n, movk, movk.
54 assert(nativeInstruction_at(pc+4)->is_movk()
55 && nativeInstruction_at(pc+8)->is_movk(), "wrong insn in patch");
56 }
57 }
64 _instructions->relocate(pc, rspec);
65 }
66
67 void CodeInstaller::pd_patch_MetaspaceConstant(int pc_offset, Handle constant, TRAPS) {
68 address pc = _instructions->start() + pc_offset;
69 if (HotSpotMetaspaceConstantImpl::compressed(constant)) {
70 narrowKlass narrowOop = record_narrow_metadata_reference(_instructions, pc, constant, CHECK);
71 MacroAssembler::patch_narrow_klass(pc, narrowOop);
72 TRACE_jvmci_3("relocating (narrow metaspace constant) at " PTR_FORMAT "/0x%x", p2i(pc), narrowOop);
73 } else {
74 NativeMovConstReg* move = nativeMovConstReg_at(pc);
75 void* reference = record_metadata_reference(_instructions, pc, constant, CHECK);
76 move->set_data((intptr_t) reference);
77 TRACE_jvmci_3("relocating (metaspace constant) at " PTR_FORMAT "/" PTR_FORMAT, p2i(pc), p2i(reference));
78 }
79 }
80
81 void CodeInstaller::pd_patch_DataSectionReference(int pc_offset, int data_offset, TRAPS) {
82 address pc = _instructions->start() + pc_offset;
83 NativeInstruction* inst = nativeInstruction_at(pc);
84 if (inst->is_adr_aligned() || inst->is_ldr_literal()) {
85 address dest = _constants->start() + data_offset;
86 _instructions->relocate(pc, section_word_Relocation::spec((address) dest, CodeBuffer::SECT_CONSTS));
87 TRACE_jvmci_3("relocating at " PTR_FORMAT " (+%d) with destination at %d", p2i(pc), pc_offset, data_offset);
88 } else {
89 JVMCI_ERROR("unknown load or move instruction at " PTR_FORMAT, p2i(pc));
90 }
91 }
92
93 void CodeInstaller::pd_relocate_ForeignCall(NativeInstruction* inst, jlong foreign_call_destination, TRAPS) {
94 address pc = (address) inst;
95 if (inst->is_call()) {
96 NativeCall* call = nativeCall_at(pc);
97 call->set_destination((address) foreign_call_destination);
98 _instructions->relocate(call->instruction_address(), runtime_call_Relocation::spec());
99 } else if (inst->is_jump()) {
100 NativeJump* jump = nativeJump_at(pc);
101 jump->set_jump_destination((address) foreign_call_destination);
102 _instructions->relocate(jump->instruction_address(), runtime_call_Relocation::spec());
103 } else if (inst->is_general_jump()) {
104 NativeGeneralJump* jump = nativeGeneralJump_at(pc);
105 jump->set_jump_destination((address) foreign_call_destination);
106 _instructions->relocate(jump->instruction_address(), runtime_call_Relocation::spec());
107 } else {
108 JVMCI_ERROR("unknown call or jump instruction at " PTR_FORMAT, p2i(pc));
109 }
110 TRACE_jvmci_3("relocating (foreign call) at " PTR_FORMAT, p2i(inst));
111 }
112
113 void CodeInstaller::pd_relocate_JavaMethod(CodeBuffer &cbuf, Handle hotspot_method, jint pc_offset, TRAPS) {
114 #ifdef ASSERT
115 Method* method = NULL;
116 // we need to check, this might also be an unresolved method
117 if (hotspot_method->is_a(HotSpotResolvedJavaMethodImpl::klass())) {
118 method = getMethodFromHotSpotMethod(hotspot_method());
119 }
120 #endif
121 switch (_next_call_type) {
122 case INLINE_INVOKE:
123 break;
124 case INVOKEVIRTUAL:
125 case INVOKEINTERFACE: {
126 assert(method == NULL || !method->is_static(), "cannot call static method with invokeinterface");
|
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 #include "jvmci/jvmciCodeInstaller.hpp"
25 #include "jvmci/jvmciRuntime.hpp"
26 #include "jvmci/jvmciCompilerToVM.hpp"
27 #include "jvmci/jvmciJavaClasses.hpp"
28 #include "oops/oop.inline.hpp"
29 #include "runtime/handles.inline.hpp"
30 #include "runtime/sharedRuntime.hpp"
31 #include "vmreg_aarch64.inline.hpp"
32
33 jint CodeInstaller::pd_next_offset(NativeInstruction* inst, jint pc_offset, Handle method, TRAPS) {
34 if (inst->is_call() || inst->is_jump() || inst->is_blr()) {
35 return pc_offset + NativeCall::instruction_size;
36 } else if (inst->is_general_jump()) {
37 return pc_offset + NativeGeneralJump::instruction_size;
38 } else if (NativeInstruction::is_adrp_at((address)inst)) {
39 // adrp; add; blr
40 return pc_offset + 3 * NativeInstruction::instruction_size;
41 } else {
42 JVMCI_ERROR_0("unsupported type of instruction for call site");
43 }
44 }
45
46 void CodeInstaller::pd_patch_OopConstant(int pc_offset, Handle constant, TRAPS) {
47 address pc = _instructions->start() + pc_offset;
48 #ifdef ASSERT
49 {
50 NativeInstruction *insn = nativeInstruction_at(pc);
51 if (HotSpotObjectConstantImpl::compressed(constant)) {
52 // Mov narrow constant: movz n << 16, movk
53 assert(Instruction_aarch64::extract(insn->encoding(), 31, 21) == 0b11010010101 &&
54 nativeInstruction_at(pc+4)->is_movk(), "wrong insn in patch");
55 } else {
56 // Move wide constant: movz n, movk, movk.
57 assert(nativeInstruction_at(pc+4)->is_movk()
58 && nativeInstruction_at(pc+8)->is_movk(), "wrong insn in patch");
59 }
60 }
67 _instructions->relocate(pc, rspec);
68 }
69
70 void CodeInstaller::pd_patch_MetaspaceConstant(int pc_offset, Handle constant, TRAPS) {
71 address pc = _instructions->start() + pc_offset;
72 if (HotSpotMetaspaceConstantImpl::compressed(constant)) {
73 narrowKlass narrowOop = record_narrow_metadata_reference(_instructions, pc, constant, CHECK);
74 MacroAssembler::patch_narrow_klass(pc, narrowOop);
75 TRACE_jvmci_3("relocating (narrow metaspace constant) at " PTR_FORMAT "/0x%x", p2i(pc), narrowOop);
76 } else {
77 NativeMovConstReg* move = nativeMovConstReg_at(pc);
78 void* reference = record_metadata_reference(_instructions, pc, constant, CHECK);
79 move->set_data((intptr_t) reference);
80 TRACE_jvmci_3("relocating (metaspace constant) at " PTR_FORMAT "/" PTR_FORMAT, p2i(pc), p2i(reference));
81 }
82 }
83
84 void CodeInstaller::pd_patch_DataSectionReference(int pc_offset, int data_offset, TRAPS) {
85 address pc = _instructions->start() + pc_offset;
86 NativeInstruction* inst = nativeInstruction_at(pc);
87 if (inst->is_adr_aligned() || inst->is_ldr_literal()
88 || (NativeInstruction::maybe_cpool_ref(pc))) {
89 address dest = _constants->start() + data_offset;
90 _instructions->relocate(pc, section_word_Relocation::spec((address) dest, CodeBuffer::SECT_CONSTS));
91 TRACE_jvmci_3("relocating at " PTR_FORMAT " (+%d) with destination at %d", p2i(pc), pc_offset, data_offset);
92 } else {
93 JVMCI_ERROR("unknown load or move instruction at " PTR_FORMAT, p2i(pc));
94 }
95 }
96
97 void CodeInstaller::pd_relocate_ForeignCall(NativeInstruction* inst, jlong foreign_call_destination, TRAPS) {
98 address pc = (address) inst;
99 if (inst->is_call()) {
100 NativeCall* call = nativeCall_at(pc);
101 call->set_destination((address) foreign_call_destination);
102 _instructions->relocate(call->instruction_address(), runtime_call_Relocation::spec());
103 } else if (inst->is_jump()) {
104 NativeJump* jump = nativeJump_at(pc);
105 jump->set_jump_destination((address) foreign_call_destination);
106 _instructions->relocate(jump->instruction_address(), runtime_call_Relocation::spec());
107 } else if (inst->is_general_jump()) {
108 NativeGeneralJump* jump = nativeGeneralJump_at(pc);
109 jump->set_jump_destination((address) foreign_call_destination);
110 _instructions->relocate(jump->instruction_address(), runtime_call_Relocation::spec());
111 } else if (NativeInstruction::is_adrp_at((address)inst)) {
112 // adrp; add; blr
113 MacroAssembler::pd_patch_instruction_size((address)inst,
114 (address)foreign_call_destination);
115 } else {
116 JVMCI_ERROR("unknown call or jump instruction at " PTR_FORMAT, p2i(pc));
117 }
118 TRACE_jvmci_3("relocating (foreign call) at " PTR_FORMAT, p2i(inst));
119 }
120
121 void CodeInstaller::pd_relocate_JavaMethod(CodeBuffer &cbuf, Handle hotspot_method, jint pc_offset, TRAPS) {
122 #ifdef ASSERT
123 Method* method = NULL;
124 // we need to check, this might also be an unresolved method
125 if (hotspot_method->is_a(HotSpotResolvedJavaMethodImpl::klass())) {
126 method = getMethodFromHotSpotMethod(hotspot_method());
127 }
128 #endif
129 switch (_next_call_type) {
130 case INLINE_INVOKE:
131 break;
132 case INVOKEVIRTUAL:
133 case INVOKEINTERFACE: {
134 assert(method == NULL || !method->is_static(), "cannot call static method with invokeinterface");
|