Mercurial > hg > truffle
comparison src/cpu/sparc/vm/jvmciCodeInstaller_sparc.cpp @ 21559:be896a1983c0
recast all Graal native code as JVMCI code (JBS:GRAAL-53)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Thu, 28 May 2015 15:36:48 +0200 |
parents | src/cpu/sparc/vm/graalCodeInstaller_sparc.cpp@ccddbb1409d2 |
children |
comparison
equal
deleted
inserted
replaced
21558:d563baeca9df | 21559:be896a1983c0 |
---|---|
1 /* | |
2 * Copyright (c) 2013, 2015, 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 "jvmci/jvmciCodeInstaller.hpp" | |
25 #include "jvmci/jvmciRuntime.hpp" | |
26 #include "jvmci/jvmciCompilerToVM.hpp" | |
27 #include "jvmci/jvmciJavaAccess.hpp" | |
28 #include "vmreg_sparc.inline.hpp" | |
29 | |
30 jint CodeInstaller::pd_next_offset(NativeInstruction* inst, jint pc_offset, oop method) { | |
31 if (inst->is_call() || inst->is_jump()) { | |
32 return pc_offset + NativeCall::instruction_size; | |
33 } else if (inst->is_call_reg()) { | |
34 return pc_offset + NativeCallReg::instruction_size; | |
35 } else if (inst->is_sethi()) { | |
36 return pc_offset + NativeFarCall::instruction_size; | |
37 } else { | |
38 fatal("unsupported type of instruction for call site"); | |
39 return 0; | |
40 } | |
41 } | |
42 | |
43 void CodeInstaller::pd_patch_OopConstant(int pc_offset, Handle& constant) { | |
44 address pc = _instructions->start() + pc_offset; | |
45 Handle obj = HotSpotObjectConstantImpl::object(constant); | |
46 jobject value = JNIHandles::make_local(obj()); | |
47 if (HotSpotObjectConstantImpl::compressed(constant)) { | |
48 #ifdef _LP64 | |
49 int oop_index = _oop_recorder->find_index(value); | |
50 RelocationHolder rspec = oop_Relocation::spec(oop_index); | |
51 _instructions->relocate(pc, rspec, 1); | |
52 #else | |
53 fatal("compressed oop on 32bit"); | |
54 #endif | |
55 } else { | |
56 NativeMovConstReg* move = nativeMovConstReg_at(pc); | |
57 move->set_data((intptr_t) value); | |
58 | |
59 // We need two relocations: one on the sethi and one on the add. | |
60 int oop_index = _oop_recorder->find_index(value); | |
61 RelocationHolder rspec = oop_Relocation::spec(oop_index); | |
62 _instructions->relocate(pc + NativeMovConstReg::sethi_offset, rspec); | |
63 _instructions->relocate(pc + NativeMovConstReg::add_offset, rspec); | |
64 } | |
65 } | |
66 | |
67 void CodeInstaller::pd_patch_DataSectionReference(int pc_offset, int data_offset) { | |
68 address pc = _instructions->start() + pc_offset; | |
69 address const_start = _constants->start(); | |
70 address dest = _constants->start() + data_offset; | |
71 | |
72 _instructions->relocate(pc + NativeMovConstReg::sethi_offset, internal_word_Relocation::spec((address) dest)); | |
73 _instructions->relocate(pc + NativeMovConstReg::add_offset, internal_word_Relocation::spec((address) dest)); | |
74 TRACE_jvmci_3("relocating at %p with destination at %p (%d)", pc, dest, data_offset); | |
75 } | |
76 | |
77 void CodeInstaller::pd_relocate_CodeBlob(CodeBlob* cb, NativeInstruction* inst) { | |
78 fatal("CodeInstaller::pd_relocate_CodeBlob - sparc unimp"); | |
79 } | |
80 | |
81 void CodeInstaller::pd_relocate_ForeignCall(NativeInstruction* inst, jlong foreign_call_destination) { | |
82 address pc = (address) inst; | |
83 if (inst->is_call()) { | |
84 NativeCall* call = nativeCall_at(pc); | |
85 call->set_destination((address) foreign_call_destination); | |
86 _instructions->relocate(call->instruction_address(), runtime_call_Relocation::spec()); | |
87 } else if (inst->is_sethi()) { | |
88 NativeJump* jump = nativeJump_at(pc); | |
89 jump->set_jump_destination((address) foreign_call_destination); | |
90 _instructions->relocate(jump->instruction_address(), runtime_call_Relocation::spec()); | |
91 } else { | |
92 fatal(err_msg("unknown call or jump instruction at %p", pc)); | |
93 } | |
94 TRACE_jvmci_3("relocating (foreign call) at %p", inst); | |
95 } | |
96 | |
97 void CodeInstaller::pd_relocate_JavaMethod(oop hotspot_method, jint pc_offset) { | |
98 #ifdef ASSERT | |
99 Method* method = NULL; | |
100 // we need to check, this might also be an unresolved method | |
101 if (hotspot_method->is_a(HotSpotResolvedJavaMethodImpl::klass())) { | |
102 method = getMethodFromHotSpotMethod(hotspot_method); | |
103 } | |
104 #endif | |
105 switch (_next_call_type) { | |
106 case INLINE_INVOKE: | |
107 break; | |
108 case INVOKEVIRTUAL: | |
109 case INVOKEINTERFACE: { | |
110 assert(method == NULL || !method->is_static(), "cannot call static method with invokeinterface"); | |
111 NativeCall* call = nativeCall_at(_instructions->start() + pc_offset); | |
112 call->set_destination(SharedRuntime::get_resolve_virtual_call_stub()); | |
113 _instructions->relocate(call->instruction_address(), virtual_call_Relocation::spec(_invoke_mark_pc)); | |
114 break; | |
115 } | |
116 case INVOKESTATIC: { | |
117 assert(method == NULL || method->is_static(), "cannot call non-static method with invokestatic"); | |
118 NativeCall* call = nativeCall_at(_instructions->start() + pc_offset); | |
119 call->set_destination(SharedRuntime::get_resolve_static_call_stub()); | |
120 _instructions->relocate(call->instruction_address(), relocInfo::static_call_type); | |
121 break; | |
122 } | |
123 case INVOKESPECIAL: { | |
124 assert(method == NULL || !method->is_static(), "cannot call static method with invokespecial"); | |
125 NativeCall* call = nativeCall_at(_instructions->start() + pc_offset); | |
126 call->set_destination(SharedRuntime::get_resolve_opt_virtual_call_stub()); | |
127 _instructions->relocate(call->instruction_address(), relocInfo::opt_virtual_call_type); | |
128 break; | |
129 } | |
130 default: | |
131 fatal("invalid _next_call_type value"); | |
132 break; | |
133 } | |
134 } | |
135 | |
136 void CodeInstaller::pd_relocate_poll(address pc, jint mark) { | |
137 switch (mark) { | |
138 case POLL_NEAR: | |
139 fatal("unimplemented"); | |
140 break; | |
141 case POLL_FAR: | |
142 _instructions->relocate(pc, relocInfo::poll_type); | |
143 break; | |
144 case POLL_RETURN_NEAR: | |
145 fatal("unimplemented"); | |
146 break; | |
147 case POLL_RETURN_FAR: | |
148 _instructions->relocate(pc, relocInfo::poll_return_type); | |
149 break; | |
150 default: | |
151 fatal("invalid mark value"); | |
152 break; | |
153 } | |
154 } | |
155 | |
156 // convert JVMCI register indices (as used in oop maps) to HotSpot registers | |
157 VMReg CodeInstaller::get_hotspot_reg(jint jvmci_reg) { | |
158 if (jvmci_reg < RegisterImpl::number_of_registers) { | |
159 return as_Register(jvmci_reg)->as_VMReg(); | |
160 } else { | |
161 jint floatRegisterNumber = jvmci_reg - RegisterImpl::number_of_registers; | |
162 floatRegisterNumber += MAX2(0, floatRegisterNumber-32); // Beginning with f32, only every second register is going to be addressed | |
163 if (floatRegisterNumber < FloatRegisterImpl::number_of_registers) { | |
164 return as_FloatRegister(floatRegisterNumber)->as_VMReg(); | |
165 } | |
166 ShouldNotReachHere(); | |
167 return NULL; | |
168 } | |
169 } | |
170 | |
171 bool CodeInstaller::is_general_purpose_reg(VMReg hotspotRegister) { | |
172 return !hotspotRegister->is_FloatRegister(); | |
173 } |