comparison src/cpu/x86/vm/graalCodeInstaller_x86.hpp @ 10411:67fa9b3e10ed

renamed codeInstaller_<cpu>.hpp to graalCodeInstaller_<cpu>.hpp
author Doug Simon <doug.simon@oracle.com>
date Wed, 19 Jun 2013 15:46:28 +0200
parents src/cpu/x86/vm/codeInstaller_x86.hpp@60648c97cdd0
children d71c56c67921
comparison
equal deleted inserted replaced
10410:9062da84cd75 10411:67fa9b3e10ed
1 /*
2 * Copyright (c) 2013, 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 #ifndef CPU_SPARC_VM_CODEINSTALLER_X86_HPP
24 #define CPU_SPARC_VM_CODEINSTALLER_X86_HPP
25
26 #include "compiler/disassembler.hpp"
27 #include "runtime/javaCalls.hpp"
28 #include "graal/graalEnv.hpp"
29 #include "graal/graalCompiler.hpp"
30 #include "graal/graalCodeInstaller.hpp"
31 #include "graal/graalJavaAccess.hpp"
32 #include "graal/graalCompilerToVM.hpp"
33 #include "graal/graalRuntime.hpp"
34 #include "asm/register.hpp"
35 #include "classfile/vmSymbols.hpp"
36 #include "code/vmreg.hpp"
37
38 inline jint CodeInstaller::pd_next_offset(NativeInstruction* inst, jint pc_offset, oop method) {
39 if (inst->is_call() || inst->is_jump()) {
40 assert(NativeCall::instruction_size == (int)NativeJump::instruction_size, "unexpected size");
41 return (pc_offset + NativeCall::instruction_size);
42 } else if (inst->is_mov_literal64()) {
43 // mov+call instruction pair
44 jint offset = pc_offset + NativeMovConstReg::instruction_size;
45 u_char* call = (u_char*) (_instructions->start() + offset);
46 assert((call[0] == 0x40 || call[0] == 0x41) && call[1] == 0xFF, "expected call with rex/rexb prefix byte");
47 offset += 3; /* prefix byte + opcode byte + modrm byte */
48 return (offset);
49 } else if (inst->is_call_reg()) {
50 // the inlined vtable stub contains a "call register" instruction
51 assert(method != NULL, "only valid for virtual calls");
52 return (pc_offset + ((NativeCallReg *) inst)->next_instruction_offset());
53 } else {
54 fatal("unsupported type of instruction for call site");
55 return 0;
56 }
57 }
58
59 inline void CodeInstaller::pd_site_DataPatch(oop constant, oop kind, bool inlined,
60 address instruction, int alignment, char typeChar) {
61 switch (typeChar) {
62 case 'z':
63 case 'b':
64 case 's':
65 case 'c':
66 case 'i':
67 fatal("int-sized values not expected in DataPatch");
68 break;
69 case 'f':
70 case 'j':
71 case 'd': {
72 if (inlined) {
73 address operand = Assembler::locate_operand(instruction, Assembler::imm_operand);
74 *((jlong*) operand) = Constant::primitive(constant);
75 } else {
76 address operand = Assembler::locate_operand(instruction, Assembler::disp32_operand);
77 address next_instruction = Assembler::locate_next_instruction(instruction);
78 int size = _constants->size();
79 if (alignment > 0) {
80 guarantee(alignment <= _constants->alignment(), "Alignment inside constants section is restricted by alignment of section begin");
81 size = align_size_up(size, alignment);
82 }
83 // we don't care if this is a long/double/etc., the primitive field contains the right bits
84 address dest = _constants->start() + size;
85 _constants->set_end(dest + BytesPerLong);
86 *(jlong*) dest = Constant::primitive(constant);
87
88 long disp = dest - next_instruction;
89 assert(disp == (jint) disp, "disp doesn't fit in 32 bits");
90 *((jint*) operand) = (jint) disp;
91
92 _instructions->relocate(instruction, section_word_Relocation::spec((address) dest, CodeBuffer::SECT_CONSTS), Assembler::disp32_operand);
93 TRACE_graal_3("relocating (%c) at %p/%p with destination at %p (%d)", typeChar, instruction, operand, dest, size);
94 }
95 break;
96 }
97 case 'a': {
98 address operand = Assembler::locate_operand(instruction, Assembler::imm_operand);
99 Handle obj = Constant::object(constant);
100
101 jobject value = JNIHandles::make_local(obj());
102 *((jobject*) operand) = value;
103 _instructions->relocate(instruction, oop_Relocation::spec_for_immediate(), Assembler::imm_operand);
104 TRACE_graal_3("relocating (oop constant) at %p/%p", instruction, operand);
105 break;
106 }
107 default:
108 fatal(err_msg("unexpected Kind (%d) in DataPatch", typeChar));
109 break;
110 }
111 }
112
113 inline void CodeInstaller::pd_relocate_CodeBlob(CodeBlob* cb, NativeInstruction* inst) {
114 if (cb->is_nmethod()) {
115 nmethod* nm = (nmethod*) cb;
116 nativeJump_at((address)inst)->set_jump_destination(nm->verified_entry_point());
117 } else {
118 nativeJump_at((address)inst)->set_jump_destination(cb->code_begin());
119 }
120 _instructions->relocate((address)inst, runtime_call_Relocation::spec(), Assembler::call32_operand);
121 }
122
123 inline void CodeInstaller::pd_relocate_ForeignCall(NativeInstruction* inst, jlong foreign_call_destination) {
124 if (inst->is_call()) {
125 // NOTE: for call without a mov, the offset must fit a 32-bit immediate
126 // see also CompilerToVM.getMaxCallTargetOffset()
127 NativeCall* call = nativeCall_at((address) (inst));
128 call->set_destination((address) foreign_call_destination);
129 _instructions->relocate(call->instruction_address(), runtime_call_Relocation::spec(), Assembler::call32_operand);
130 } else if (inst->is_mov_literal64()) {
131 NativeMovConstReg* mov = nativeMovConstReg_at((address) (inst));
132 mov->set_data((intptr_t) foreign_call_destination);
133 _instructions->relocate(mov->instruction_address(), runtime_call_Relocation::spec(), Assembler::imm_operand);
134 } else {
135 NativeJump* jump = nativeJump_at((address) (inst));
136 jump->set_jump_destination((address) foreign_call_destination);
137 _instructions->relocate((address)inst, runtime_call_Relocation::spec(), Assembler::call32_operand);
138 }
139 TRACE_graal_3("relocating (foreign call) at %p", inst);
140 }
141
142 inline void CodeInstaller::pd_relocate_JavaMethod(oop hotspot_method, jint pc_offset) {
143 #ifdef ASSERT
144 Method* method = NULL;
145 // we need to check, this might also be an unresolved method
146 if (hotspot_method->is_a(HotSpotResolvedJavaMethod::klass())) {
147 method = getMethodFromHotSpotMethod(hotspot_method);
148 }
149 #endif
150 switch (_next_call_type) {
151 case MARK_INLINE_INVOKE:
152 break;
153 case MARK_INVOKEVIRTUAL:
154 case MARK_INVOKEINTERFACE: {
155 assert(method == NULL || !method->is_static(), "cannot call static method with invokeinterface");
156
157 NativeCall* call = nativeCall_at(_instructions->start() + pc_offset);
158 call->set_destination(SharedRuntime::get_resolve_virtual_call_stub());
159 _instructions->relocate(call->instruction_address(),
160 virtual_call_Relocation::spec(_invoke_mark_pc),
161 Assembler::call32_operand);
162 break;
163 }
164 case MARK_INVOKESTATIC: {
165 assert(method == NULL || method->is_static(), "cannot call non-static method with invokestatic");
166
167 NativeCall* call = nativeCall_at(_instructions->start() + pc_offset);
168 call->set_destination(SharedRuntime::get_resolve_static_call_stub());
169 _instructions->relocate(call->instruction_address(),
170 relocInfo::static_call_type, Assembler::call32_operand);
171 break;
172 }
173 case MARK_INVOKESPECIAL: {
174 assert(method == NULL || !method->is_static(), "cannot call static method with invokespecial");
175 NativeCall* call = nativeCall_at(_instructions->start() + pc_offset);
176 call->set_destination(SharedRuntime::get_resolve_opt_virtual_call_stub());
177 _instructions->relocate(call->instruction_address(),
178 relocInfo::opt_virtual_call_type, Assembler::call32_operand);
179 break;
180 }
181 default:
182 fatal("invalid _next_call_type value");
183 break;
184 }
185 }
186
187 inline int32_t* CodeInstaller::pd_locate_operand(address instruction) {
188 return (int32_t*) Assembler::locate_operand(instruction, Assembler::disp32_operand);
189 }
190
191 #endif // CPU_SPARC_VM_CODEINSTALLER_X86_HPP
192