Mercurial > hg > truffle
comparison src/cpu/x86/vm/graalCodeInstaller_x86.cpp @ 15123:7ccd2a1df0fa
made SPARC compile again; moved graalCodeInstaller_<arch>.hpp to .cpp files
author | twisti |
---|---|
date | Tue, 15 Apr 2014 12:01:51 -1000 |
parents | src/cpu/x86/vm/graalCodeInstaller_x86.hpp@6bab029d6e3a |
children | 370cb412d027 |
comparison
equal
deleted
inserted
replaced
15122:11a591a99515 | 15123:7ccd2a1df0fa |
---|---|
1 /* | |
2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. | |
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 "compiler/disassembler.hpp" | |
25 #include "runtime/javaCalls.hpp" | |
26 #include "graal/graalEnv.hpp" | |
27 #include "graal/graalCompiler.hpp" | |
28 #include "graal/graalCodeInstaller.hpp" | |
29 #include "graal/graalJavaAccess.hpp" | |
30 #include "graal/graalCompilerToVM.hpp" | |
31 #include "graal/graalRuntime.hpp" | |
32 #include "asm/register.hpp" | |
33 #include "classfile/vmSymbols.hpp" | |
34 #include "code/vmreg.hpp" | |
35 | |
36 jint CodeInstaller::pd_next_offset(NativeInstruction* inst, jint pc_offset, oop method) { | |
37 if (inst->is_call() || inst->is_jump()) { | |
38 assert(NativeCall::instruction_size == (int)NativeJump::instruction_size, "unexpected size"); | |
39 return (pc_offset + NativeCall::instruction_size); | |
40 } else if (inst->is_mov_literal64()) { | |
41 // mov+call instruction pair | |
42 jint offset = pc_offset + NativeMovConstReg::instruction_size; | |
43 u_char* call = (u_char*) (_instructions->start() + offset); | |
44 assert((call[0] == 0x40 || call[0] == 0x41) && call[1] == 0xFF, "expected call with rex/rexb prefix byte"); | |
45 offset += 3; /* prefix byte + opcode byte + modrm byte */ | |
46 return (offset); | |
47 } else if (inst->is_call_reg()) { | |
48 // the inlined vtable stub contains a "call register" instruction | |
49 assert(method != NULL, "only valid for virtual calls"); | |
50 return (pc_offset + ((NativeCallReg *) inst)->next_instruction_offset()); | |
51 } else if (inst->is_cond_jump()) { | |
52 address pc = (address) (inst); | |
53 return pc_offset + (jint) (Assembler::locate_next_instruction(pc) - pc); | |
54 } else { | |
55 fatal("unsupported type of instruction for call site"); | |
56 return 0; | |
57 } | |
58 } | |
59 | |
60 void CodeInstaller::pd_patch_OopData(int pc_offset, oop data) { | |
61 address pc = _instructions->start() + pc_offset; | |
62 Handle obj = OopData::object(data); | |
63 jobject value = JNIHandles::make_local(obj()); | |
64 if (OopData::compressed(data)) { | |
65 address operand = Assembler::locate_operand(pc, Assembler::narrow_oop_operand); | |
66 int oop_index = _oop_recorder->find_index(value); | |
67 _instructions->relocate(pc, oop_Relocation::spec(oop_index), Assembler::narrow_oop_operand); | |
68 TRACE_graal_3("relocating (narrow oop constant) at %p/%p", pc, operand); | |
69 } else { | |
70 address operand = Assembler::locate_operand(pc, Assembler::imm_operand); | |
71 *((jobject*) operand) = value; | |
72 _instructions->relocate(pc, oop_Relocation::spec_for_immediate(), Assembler::imm_operand); | |
73 TRACE_graal_3("relocating (oop constant) at %p/%p", pc, operand); | |
74 } | |
75 } | |
76 | |
77 void CodeInstaller::pd_patch_DataSectionReference(int pc_offset, oop data) { | |
78 address pc = _instructions->start() + pc_offset; | |
79 jint offset = DataSectionReference::offset(data); | |
80 | |
81 address operand = Assembler::locate_operand(pc, Assembler::disp32_operand); | |
82 address next_instruction = Assembler::locate_next_instruction(pc); | |
83 address dest = _constants->start() + offset; | |
84 | |
85 long disp = dest - next_instruction; | |
86 assert(disp == (jint) disp, "disp doesn't fit in 32 bits"); | |
87 *((jint*) operand) = (jint) disp; | |
88 | |
89 _instructions->relocate(pc, section_word_Relocation::spec((address) dest, CodeBuffer::SECT_CONSTS), Assembler::disp32_operand); | |
90 TRACE_graal_3("relocating at %p/%p with destination at %p (%d)", pc, operand, dest, offset); | |
91 } | |
92 | |
93 void CodeInstaller::pd_relocate_CodeBlob(CodeBlob* cb, NativeInstruction* inst) { | |
94 if (cb->is_nmethod()) { | |
95 nmethod* nm = (nmethod*) cb; | |
96 nativeJump_at((address)inst)->set_jump_destination(nm->verified_entry_point()); | |
97 } else { | |
98 nativeJump_at((address)inst)->set_jump_destination(cb->code_begin()); | |
99 } | |
100 _instructions->relocate((address)inst, runtime_call_Relocation::spec(), Assembler::call32_operand); | |
101 } | |
102 | |
103 void CodeInstaller::pd_relocate_ForeignCall(NativeInstruction* inst, jlong foreign_call_destination) { | |
104 address pc = (address) inst; | |
105 if (inst->is_call()) { | |
106 // NOTE: for call without a mov, the offset must fit a 32-bit immediate | |
107 // see also CompilerToVM.getMaxCallTargetOffset() | |
108 NativeCall* call = nativeCall_at(pc); | |
109 call->set_destination((address) foreign_call_destination); | |
110 _instructions->relocate(call->instruction_address(), runtime_call_Relocation::spec(), Assembler::call32_operand); | |
111 } else if (inst->is_mov_literal64()) { | |
112 NativeMovConstReg* mov = nativeMovConstReg_at(pc); | |
113 mov->set_data((intptr_t) foreign_call_destination); | |
114 _instructions->relocate(mov->instruction_address(), runtime_call_Relocation::spec(), Assembler::imm_operand); | |
115 } else if (inst->is_jump()) { | |
116 NativeJump* jump = nativeJump_at(pc); | |
117 jump->set_jump_destination((address) foreign_call_destination); | |
118 _instructions->relocate(jump->instruction_address(), runtime_call_Relocation::spec(), Assembler::call32_operand); | |
119 } else if (inst->is_cond_jump()) { | |
120 address old_dest = nativeGeneralJump_at(pc)->jump_destination(); | |
121 address disp = Assembler::locate_operand(pc, Assembler::call32_operand); | |
122 *(jint*) disp += ((address) foreign_call_destination) - old_dest; | |
123 _instructions->relocate(pc, runtime_call_Relocation::spec(), Assembler::call32_operand); | |
124 } else { | |
125 fatal("unsupported relocation for foreign call"); | |
126 } | |
127 | |
128 TRACE_graal_3("relocating (foreign call) at %p", inst); | |
129 } | |
130 | |
131 void CodeInstaller::pd_relocate_JavaMethod(oop hotspot_method, jint pc_offset) { | |
132 #ifdef ASSERT | |
133 Method* method = NULL; | |
134 // we need to check, this might also be an unresolved method | |
135 if (hotspot_method->is_a(HotSpotResolvedJavaMethod::klass())) { | |
136 method = getMethodFromHotSpotMethod(hotspot_method); | |
137 } | |
138 #endif | |
139 switch (_next_call_type) { | |
140 case INLINE_INVOKE: | |
141 break; | |
142 case INVOKEVIRTUAL: | |
143 case INVOKEINTERFACE: { | |
144 assert(method == NULL || !method->is_static(), "cannot call static method with invokeinterface"); | |
145 | |
146 NativeCall* call = nativeCall_at(_instructions->start() + pc_offset); | |
147 call->set_destination(SharedRuntime::get_resolve_virtual_call_stub()); | |
148 _instructions->relocate(call->instruction_address(), | |
149 virtual_call_Relocation::spec(_invoke_mark_pc), | |
150 Assembler::call32_operand); | |
151 break; | |
152 } | |
153 case INVOKESTATIC: { | |
154 assert(method == NULL || method->is_static(), "cannot call non-static method with invokestatic"); | |
155 | |
156 NativeCall* call = nativeCall_at(_instructions->start() + pc_offset); | |
157 call->set_destination(SharedRuntime::get_resolve_static_call_stub()); | |
158 _instructions->relocate(call->instruction_address(), | |
159 relocInfo::static_call_type, Assembler::call32_operand); | |
160 break; | |
161 } | |
162 case INVOKESPECIAL: { | |
163 assert(method == NULL || !method->is_static(), "cannot call static method with invokespecial"); | |
164 NativeCall* call = nativeCall_at(_instructions->start() + pc_offset); | |
165 call->set_destination(SharedRuntime::get_resolve_opt_virtual_call_stub()); | |
166 _instructions->relocate(call->instruction_address(), | |
167 relocInfo::opt_virtual_call_type, Assembler::call32_operand); | |
168 break; | |
169 } | |
170 default: | |
171 break; | |
172 } | |
173 } | |
174 | |
175 static void relocate_poll_near(address pc) { | |
176 NativeInstruction* ni = nativeInstruction_at(pc); | |
177 int32_t* disp = (int32_t*) Assembler::locate_operand(pc, Assembler::disp32_operand); | |
178 int32_t offset = *disp; // The Java code installed the polling page offset into the disp32 operand | |
179 intptr_t new_disp = (intptr_t) (os::get_polling_page() + offset) - (intptr_t) ni; | |
180 *disp = (int32_t)new_disp; | |
181 } | |
182 | |
183 | |
184 void CodeInstaller::pd_relocate_poll(address pc, jint mark) { | |
185 switch (mark) { | |
186 case POLL_NEAR: { | |
187 relocate_poll_near(pc); | |
188 _instructions->relocate(pc, relocInfo::poll_type, Assembler::disp32_operand); | |
189 break; | |
190 } | |
191 case POLL_FAR: | |
192 // This is a load from a register so there is no relocatable operand. | |
193 // We just have to ensure that the format is not disp32_operand | |
194 // so that poll_Relocation::fix_relocation_after_move does the right | |
195 // thing (i.e. ignores this relocation record) | |
196 _instructions->relocate(pc, relocInfo::poll_type, Assembler::imm_operand); | |
197 break; | |
198 case POLL_RETURN_NEAR: { | |
199 relocate_poll_near(pc); | |
200 _instructions->relocate(pc, relocInfo::poll_return_type, Assembler::disp32_operand); | |
201 break; | |
202 } | |
203 case POLL_RETURN_FAR: | |
204 // see comment above for POLL_FAR | |
205 _instructions->relocate(pc, relocInfo::poll_return_type, Assembler::imm_operand); | |
206 break; | |
207 default: | |
208 fatal("invalid mark value"); | |
209 break; | |
210 } | |
211 } |