author | phh |
Sat, 30 Nov 2019 14:33:05 -0800 | |
changeset 59330 | 5b96c12f909d |
parent 54669 | ad45b3802d4e |
permissions | -rw-r--r-- |
33160 | 1 |
/* |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50104
diff
changeset
|
2 |
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
33160 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
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" |
|
49480
d7df2dd501ce
8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents:
48487
diff
changeset
|
29 |
#include "runtime/handles.inline.hpp" |
33160 | 30 |
#include "runtime/sharedRuntime.hpp" |
31 |
#include "vmreg_aarch64.inline.hpp" |
|
32 |
||
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50104
diff
changeset
|
33 |
jint CodeInstaller::pd_next_offset(NativeInstruction* inst, jint pc_offset, JVMCIObject method, JVMCI_TRAPS) { |
36060 | 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; |
|
50104 | 38 |
} else if (NativeInstruction::is_adrp_at((address)inst)) { |
39 |
// adrp; add; blr |
|
40 |
return pc_offset + 3 * NativeInstruction::instruction_size; |
|
36060 | 41 |
} else { |
42 |
JVMCI_ERROR_0("unsupported type of instruction for call site"); |
|
43 |
} |
|
33160 | 44 |
} |
45 |
||
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50104
diff
changeset
|
46 |
void CodeInstaller::pd_patch_OopConstant(int pc_offset, JVMCIObject constant, JVMCI_TRAPS) { |
36060 | 47 |
address pc = _instructions->start() + pc_offset; |
42605 | 48 |
#ifdef ASSERT |
49 |
{ |
|
50 |
NativeInstruction *insn = nativeInstruction_at(pc); |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50104
diff
changeset
|
51 |
if (jvmci_env()->get_HotSpotObjectConstantImpl_compressed(constant)) { |
42605 | 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 |
} |
|
61 |
#endif // ASSERT |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50104
diff
changeset
|
62 |
Handle obj = jvmci_env()->asConstant(constant, JVMCI_CHECK); |
36060 | 63 |
jobject value = JNIHandles::make_local(obj()); |
42605 | 64 |
MacroAssembler::patch_oop(pc, (address)obj()); |
65 |
int oop_index = _oop_recorder->find_index(value); |
|
66 |
RelocationHolder rspec = oop_Relocation::spec(oop_index); |
|
67 |
_instructions->relocate(pc, rspec); |
|
33160 | 68 |
} |
69 |
||
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50104
diff
changeset
|
70 |
void CodeInstaller::pd_patch_MetaspaceConstant(int pc_offset, JVMCIObject constant, JVMCI_TRAPS) { |
36060 | 71 |
address pc = _instructions->start() + pc_offset; |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50104
diff
changeset
|
72 |
if (jvmci_env()->get_HotSpotMetaspaceConstantImpl_compressed(constant)) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50104
diff
changeset
|
73 |
narrowKlass narrowOop = record_narrow_metadata_reference(_instructions, pc, constant, JVMCI_CHECK); |
42605 | 74 |
MacroAssembler::patch_narrow_klass(pc, narrowOop); |
36060 | 75 |
TRACE_jvmci_3("relocating (narrow metaspace constant) at " PTR_FORMAT "/0x%x", p2i(pc), narrowOop); |
76 |
} else { |
|
77 |
NativeMovConstReg* move = nativeMovConstReg_at(pc); |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50104
diff
changeset
|
78 |
void* reference = record_metadata_reference(_instructions, pc, constant, JVMCI_CHECK); |
36060 | 79 |
move->set_data((intptr_t) reference); |
80 |
TRACE_jvmci_3("relocating (metaspace constant) at " PTR_FORMAT "/" PTR_FORMAT, p2i(pc), p2i(reference)); |
|
81 |
} |
|
33160 | 82 |
} |
83 |
||
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50104
diff
changeset
|
84 |
void CodeInstaller::pd_patch_DataSectionReference(int pc_offset, int data_offset, JVMCI_TRAPS) { |
36060 | 85 |
address pc = _instructions->start() + pc_offset; |
86 |
NativeInstruction* inst = nativeInstruction_at(pc); |
|
50104 | 87 |
if (inst->is_adr_aligned() || inst->is_ldr_literal() |
88 |
|| (NativeInstruction::maybe_cpool_ref(pc))) { |
|
36060 | 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 |
} |
|
33160 | 95 |
} |
96 |
||
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50104
diff
changeset
|
97 |
void CodeInstaller::pd_relocate_ForeignCall(NativeInstruction* inst, jlong foreign_call_destination, JVMCI_TRAPS) { |
36060 | 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()); |
|
50104 | 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); |
|
36060 | 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)); |
|
33160 | 119 |
} |
120 |
||
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50104
diff
changeset
|
121 |
void CodeInstaller::pd_relocate_JavaMethod(CodeBuffer &cbuf, JVMCIObject hotspot_method, jint pc_offset, JVMCI_TRAPS) { |
36060 | 122 |
#ifdef ASSERT |
123 |
Method* method = NULL; |
|
124 |
// we need to check, this might also be an unresolved method |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50104
diff
changeset
|
125 |
if (JVMCIENV->isa_HotSpotResolvedJavaMethodImpl(hotspot_method)) { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50104
diff
changeset
|
126 |
method = JVMCIENV->asMethod(hotspot_method); |
36060 | 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"); |
|
135 |
NativeCall* call = nativeCall_at(_instructions->start() + pc_offset); |
|
136 |
_instructions->relocate(call->instruction_address(), virtual_call_Relocation::spec(_invoke_mark_pc)); |
|
48487 | 137 |
call->trampoline_jump(cbuf, SharedRuntime::get_resolve_virtual_call_stub()); |
36060 | 138 |
break; |
139 |
} |
|
140 |
case INVOKESTATIC: { |
|
141 |
assert(method == NULL || method->is_static(), "cannot call non-static method with invokestatic"); |
|
142 |
NativeCall* call = nativeCall_at(_instructions->start() + pc_offset); |
|
143 |
_instructions->relocate(call->instruction_address(), relocInfo::static_call_type); |
|
48487 | 144 |
call->trampoline_jump(cbuf, SharedRuntime::get_resolve_static_call_stub()); |
36060 | 145 |
break; |
146 |
} |
|
147 |
case INVOKESPECIAL: { |
|
148 |
assert(method == NULL || !method->is_static(), "cannot call static method with invokespecial"); |
|
149 |
NativeCall* call = nativeCall_at(_instructions->start() + pc_offset); |
|
150 |
_instructions->relocate(call->instruction_address(), relocInfo::opt_virtual_call_type); |
|
48487 | 151 |
call->trampoline_jump(cbuf, SharedRuntime::get_resolve_opt_virtual_call_stub()); |
36060 | 152 |
break; |
153 |
} |
|
154 |
default: |
|
155 |
JVMCI_ERROR("invalid _next_call_type value"); |
|
156 |
break; |
|
157 |
} |
|
33160 | 158 |
} |
159 |
||
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50104
diff
changeset
|
160 |
void CodeInstaller::pd_relocate_poll(address pc, jint mark, JVMCI_TRAPS) { |
36060 | 161 |
switch (mark) { |
162 |
case POLL_NEAR: |
|
163 |
JVMCI_ERROR("unimplemented"); |
|
164 |
break; |
|
165 |
case POLL_FAR: |
|
166 |
_instructions->relocate(pc, relocInfo::poll_type); |
|
167 |
break; |
|
168 |
case POLL_RETURN_NEAR: |
|
169 |
JVMCI_ERROR("unimplemented"); |
|
170 |
break; |
|
171 |
case POLL_RETURN_FAR: |
|
172 |
_instructions->relocate(pc, relocInfo::poll_return_type); |
|
173 |
break; |
|
174 |
default: |
|
175 |
JVMCI_ERROR("invalid mark value"); |
|
176 |
break; |
|
177 |
} |
|
33160 | 178 |
} |
179 |
||
180 |
// convert JVMCI register indices (as used in oop maps) to HotSpot registers |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
50104
diff
changeset
|
181 |
VMReg CodeInstaller::get_hotspot_reg(jint jvmci_reg, JVMCI_TRAPS) { |
36060 | 182 |
if (jvmci_reg < RegisterImpl::number_of_registers) { |
183 |
return as_Register(jvmci_reg)->as_VMReg(); |
|
184 |
} else { |
|
42605 | 185 |
jint floatRegisterNumber = jvmci_reg - RegisterImpl::number_of_registers_for_jvmci; |
186 |
if (floatRegisterNumber >= 0 && floatRegisterNumber < FloatRegisterImpl::number_of_registers) { |
|
36060 | 187 |
return as_FloatRegister(floatRegisterNumber)->as_VMReg(); |
188 |
} |
|
189 |
JVMCI_ERROR_NULL("invalid register number: %d", jvmci_reg); |
|
190 |
} |
|
33160 | 191 |
} |
192 |
||
193 |
bool CodeInstaller::is_general_purpose_reg(VMReg hotspotRegister) { |
|
36060 | 194 |
return !hotspotRegister->is_FloatRegister(); |
33160 | 195 |
} |