Mercurial > hg > truffle
comparison src/share/vm/c1x/c1x_CodeInstaller.cpp @ 1428:695451afc619
refactoring classes into separate files
author | Lukas Stadler <lukas.stadler@oracle.com> |
---|---|
date | Thu, 19 Aug 2010 14:34:52 -0700 |
parents | |
children | abc670a709dc |
comparison
equal
deleted
inserted
replaced
1427:149b1d2316de | 1428:695451afc619 |
---|---|
1 /* | |
2 * Copyright 2000-2010 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 | |
26 # include "incls/_precompiled.incl" | |
27 # include "incls/_c1x_CodeInstaller.cpp.incl" | |
28 | |
29 | |
30 #define C1X_REGISTER_COUNT 32 | |
31 | |
32 VMReg get_hotspot_reg(jint c1x_reg) { | |
33 Register cpu_registers[] = { rax, rcx, rdx, rbx, rsp, rbp, rsi, rdi, r8, r9, r10, r11, r12, r13, r14, r15 }; | |
34 XMMRegister xmm_registers[] = { xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15 }; | |
35 | |
36 if (c1x_reg < 16) { | |
37 return cpu_registers[c1x_reg]->as_VMReg(); | |
38 } else { | |
39 assert(c1x_reg < C1X_REGISTER_COUNT, "invalid register number"); | |
40 return xmm_registers[c1x_reg - 16]->as_VMReg(); | |
41 } | |
42 | |
43 } | |
44 | |
45 static OopMap* create_oop_map(jint frame_size, jint parameter_count, oop debug_info) { | |
46 OopMap* map = new OopMap(frame_size, parameter_count); | |
47 arrayOop register_map = (arrayOop)CiDebugInfo::registerRefMap(debug_info); | |
48 arrayOop frame_map = (arrayOop)CiDebugInfo::frameRefMap(debug_info); | |
49 | |
50 for (jint i=0; i<C1X_REGISTER_COUNT; i++) { | |
51 unsigned char byte = ((unsigned char*)register_map->base(T_BYTE))[i / 8]; | |
52 bool is_oop = (byte & (1 << (i % 8))) != 0; | |
53 VMReg reg = get_hotspot_reg(i); | |
54 if (is_oop) { | |
55 map->set_oop(reg); | |
56 } else { | |
57 map->set_value(reg); | |
58 } | |
59 } | |
60 | |
61 for (jint i=0; i<frame_size; i++) { | |
62 unsigned char byte = ((unsigned char*)frame_map->base(T_BYTE))[i / 8]; | |
63 bool is_oop = (byte & (1 << (i % 8))) != 0; | |
64 VMReg reg = VMRegImpl::stack2reg(i); | |
65 if (is_oop) { | |
66 map->set_oop(reg); | |
67 } else { | |
68 map->set_value(reg); | |
69 } | |
70 } | |
71 | |
72 // TODO parameters? | |
73 return map; | |
74 } | |
75 | |
76 static ScopeValue* get_hotspot_value(oop value) { | |
77 fatal("not implemented"); | |
78 if (value->is_a(CiRegisterValue::klass())) { | |
79 tty->print("register value"); | |
80 value->print(); | |
81 } else if (value->is_a(CiStackSlot::klass())) { | |
82 tty->print("stack value"); | |
83 value->print(); | |
84 } else { | |
85 ShouldNotReachHere(); | |
86 } | |
87 } | |
88 | |
89 | |
90 // constructor used to create a method | |
91 CodeInstaller::CodeInstaller(oop target_method) { | |
92 VM_ENTRY_MARK; | |
93 _env = CURRENT_ENV; | |
94 | |
95 initialize_fields(target_method); | |
96 assert(_hotspot_method != NULL && _name == NULL, "installMethod needs NON-NULL method and NULL name"); | |
97 | |
98 | |
99 // TODO: This is a hack.. Produce correct entries. | |
100 _offsets.set_value(CodeOffsets::Exceptions, 0); | |
101 _offsets.set_value(CodeOffsets::Deopt, 0); | |
102 | |
103 methodOop method = VmIds::get<methodOop>(HotSpotMethod::vmId(_hotspot_method)); | |
104 ciMethod *ciMethodObject = (ciMethod *)_env->get_object(method); | |
105 _parameter_count = method->size_of_parameters(); | |
106 | |
107 // (very) conservative estimate: each site needs a relocation | |
108 CodeBuffer buffer("temp c1x method", _total_size, _sites->length() * relocInfo::length_limit); | |
109 initialize_buffer(buffer); | |
110 ExceptionHandlerTable handler_table; | |
111 ImplicitExceptionTable inc_table; | |
112 { | |
113 ThreadToNativeFromVM t((JavaThread*)THREAD); | |
114 _env->register_method(ciMethodObject, -1, &_offsets, 0, &buffer, _frame_size, _debug_recorder->_oopmaps, &handler_table, &inc_table, NULL, _env->comp_level(), false, false); | |
115 } | |
116 } | |
117 | |
118 // constructor used to create a stub | |
119 CodeInstaller::CodeInstaller(oop target_method, jlong& id) { | |
120 VM_ENTRY_MARK; | |
121 _env = CURRENT_ENV; | |
122 | |
123 initialize_fields(target_method); | |
124 assert(_hotspot_method == NULL && _name != NULL, "installMethod needs NON-NULL name and NULL method"); | |
125 | |
126 // (very) conservative estimate: each site needs a relocation | |
127 CodeBuffer buffer("temp c1x stub", _total_size, _sites->length() * relocInfo::length_limit); | |
128 initialize_buffer(buffer); | |
129 | |
130 const char* cname = java_lang_String::as_utf8_string(_name); | |
131 BufferBlob* blob = BufferBlob::create(strdup(cname), &buffer); // this is leaking strings... but only a limited number of stubs will be created | |
132 Disassembler::decode((CodeBlob*)blob); | |
133 id = VmIds::addStub(blob->instructions_begin()); | |
134 } | |
135 | |
136 void CodeInstaller::initialize_fields(oop target_method) { | |
137 _citarget_method = HotSpotTargetMethod::targetMethod(target_method); | |
138 _hotspot_method = HotSpotTargetMethod::method(target_method); | |
139 _name = HotSpotTargetMethod::name(target_method); | |
140 _sites = (arrayOop)HotSpotTargetMethod::sites(target_method); | |
141 | |
142 _code = (arrayOop)CiTargetMethod::targetCode(_citarget_method); | |
143 _code_size = CiTargetMethod::targetCodeSize(_citarget_method); | |
144 _frame_size = CiTargetMethod::frameSize(_citarget_method); | |
145 | |
146 // (very) conservative estimate: each site needs a constant section entry | |
147 _constants_size = _sites->length() * BytesPerLong; | |
148 _total_size = align_size_up(_code_size, HeapWordSize) + _constants_size; | |
149 | |
150 _next_call_type = MARK_INVOKE_INVALID; | |
151 } | |
152 | |
153 void CodeInstaller::site_Safepoint(CodeBuffer& buffer, jint pc_offset, oop site) { | |
154 | |
155 } | |
156 | |
157 void CodeInstaller::record_frame(jint pc_offset, oop code_pos, oop frame) { | |
158 oop caller_pos = CiCodePos::caller(code_pos); | |
159 if (caller_pos != NULL) { | |
160 oop caller_frame = CiDebugInfo_Frame::caller(frame); | |
161 record_frame(pc_offset, caller_pos, caller_frame); | |
162 } else { | |
163 assert(frame == NULL || CiDebugInfo_Frame::caller(frame) == NULL, "unexpected layout - different nesting of Frame and CiCodePos"); | |
164 } | |
165 | |
166 assert(frame == NULL || code_pos == CiDebugInfo_Frame::codePos(frame), "unexpected CiCodePos layout"); | |
167 | |
168 oop hotspot_method = CiCodePos::method(code_pos); | |
169 methodOop method = VmIds::get<methodOop>(HotSpotMethod::vmId(hotspot_method)); | |
170 ciMethod *cimethod = (ciMethod *)_env->get_object(method); | |
171 jint bci = CiCodePos::bci(code_pos); | |
172 | |
173 if (frame != NULL) { | |
174 jint local_count = CiDebugInfo_Frame::numLocals(frame); | |
175 jint expression_count = CiDebugInfo_Frame::numStack(frame); | |
176 jint monitor_count = CiDebugInfo_Frame::numLocks(frame); | |
177 arrayOop values = (arrayOop)CiDebugInfo_Frame::values(frame); | |
178 | |
179 assert(local_count + expression_count + monitor_count == values->length(), "unexpected values length"); | |
180 assert(monitor_count == 0, "monitors not supported"); | |
181 | |
182 GrowableArray<ScopeValue*>* locals = new GrowableArray<ScopeValue*>(); | |
183 GrowableArray<ScopeValue*>* expressions = new GrowableArray<ScopeValue*>(); | |
184 GrowableArray<MonitorValue*>* monitors = new GrowableArray<MonitorValue*>(); | |
185 | |
186 for (jint i=0; i<values->length(); i++) { | |
187 ScopeValue* value = get_hotspot_value(((oop*)values->base(T_OBJECT))[i]); | |
188 | |
189 if (i < local_count) { | |
190 locals->append(value); | |
191 } else if (i < local_count + expression_count) { | |
192 expressions->append(value); | |
193 } else { | |
194 ShouldNotReachHere(); | |
195 // monitors->append(value); | |
196 } | |
197 } | |
198 DebugToken* locals_token = _debug_recorder->create_scope_values(locals); | |
199 DebugToken* expressions_token = _debug_recorder->create_scope_values(expressions); | |
200 DebugToken* monitors_token = _debug_recorder->create_monitor_values(monitors); | |
201 | |
202 _debug_recorder->describe_scope(pc_offset, cimethod, bci, false, false, false, locals_token, expressions_token, monitors_token); | |
203 } else { | |
204 _debug_recorder->describe_scope(pc_offset, cimethod, bci, false, false, false, NULL, NULL, NULL); | |
205 } | |
206 } | |
207 | |
208 void CodeInstaller::site_Call(CodeBuffer& buffer, jint pc_offset, oop site) { | |
209 oop runtime_call = CiTargetMethod_Call::runtimeCall(site); | |
210 oop hotspot_method = CiTargetMethod_Call::method(site); | |
211 oop symbol = CiTargetMethod_Call::symbol(site); | |
212 oop global_stub = CiTargetMethod_Call::globalStubID(site); | |
213 | |
214 oop debug_info = CiTargetMethod_Call::debugInfo(site); | |
215 arrayOop stack_map = (arrayOop)CiTargetMethod_Call::stackMap(site); | |
216 arrayOop register_map = (arrayOop)CiTargetMethod_Call::registerMap(site); | |
217 | |
218 assert((runtime_call ? 1 : 0) + (hotspot_method ? 1 : 0) + (symbol ? 1 : 0) + (global_stub ? 1 : 0) == 1, "Call site needs exactly one type"); | |
219 | |
220 address instruction = _instructions->start() + pc_offset; | |
221 address operand = Assembler::locate_operand(instruction, Assembler::call32_operand); | |
222 address next_instruction = Assembler::locate_next_instruction(instruction); | |
223 | |
224 if (runtime_call != NULL) { | |
225 if (runtime_call == CiRuntimeCall::Debug()) { | |
226 tty->print_cr("CiRuntimeCall::Debug()"); | |
227 } else { | |
228 runtime_call->print(); | |
229 } | |
230 tty->print_cr("runtime_call"); | |
231 } else if (global_stub != NULL) { | |
232 assert(java_lang_boxing_object::is_instance(global_stub, T_LONG), "global_stub needs to be of type Long"); | |
233 | |
234 jlong stub_id = global_stub->long_field(java_lang_boxing_object::value_offset_in_bytes(T_LONG)); | |
235 address dest = VmIds::getStub(stub_id); | |
236 long disp = dest - next_instruction; | |
237 assert(disp == (jint) disp, "disp doesn't fit in 32 bits"); | |
238 *((jint*)operand) = (jint)disp; | |
239 | |
240 _instructions->relocate(instruction, runtime_call_Relocation::spec(), Assembler::call32_operand); | |
241 tty->print_cr("relocating (stub) %016x/%016x", instruction, operand); | |
242 } else if (symbol != NULL) { | |
243 tty->print_cr("symbol"); | |
244 } else { // method != NULL | |
245 assert(hotspot_method->is_a(SystemDictionary::HotSpotMethod_klass()), "unexpected RiMethod subclass"); | |
246 methodOop method = VmIds::get<methodOop>(HotSpotMethod::vmId(hotspot_method)); | |
247 | |
248 jint next_pc_offset = next_instruction - _instructions->start(); | |
249 | |
250 assert(debug_info != NULL, "debug info expected"); | |
251 _debug_recorder->add_safepoint(next_pc_offset, create_oop_map(_frame_size, _parameter_count, debug_info)); | |
252 oop code_pos = CiDebugInfo::codePos(debug_info); | |
253 oop frame = CiDebugInfo::frame(debug_info); | |
254 record_frame(next_pc_offset, code_pos, frame); | |
255 | |
256 switch(_next_call_type) { | |
257 case MARK_INVOKEVIRTUAL: | |
258 case MARK_INVOKEINTERFACE: { | |
259 assert(!method->is_static(), "cannot call static method with invokeinterface"); | |
260 | |
261 address dest = SharedRuntime::get_resolve_virtual_call_stub(); | |
262 long disp = dest - next_instruction; | |
263 assert(disp == (jint) disp, "disp doesn't fit in 32 bits"); | |
264 *((jint*)operand) = (jint)disp; | |
265 | |
266 _instructions->relocate(instruction, virtual_call_Relocation::spec(_invoke_mark_pc), Assembler::call32_operand); | |
267 break; | |
268 } | |
269 case MARK_INVOKESTATIC: { | |
270 assert(method->is_static(), "cannot call non-static method with invokestatic"); | |
271 | |
272 address dest = SharedRuntime::get_resolve_static_call_stub(); | |
273 long disp = dest - next_instruction; | |
274 assert(disp == (jint) disp, "disp doesn't fit in 32 bits"); | |
275 *((jint*)operand) = (jint)disp; | |
276 | |
277 _instructions->relocate(instruction, relocInfo::static_call_type, Assembler::call32_operand); | |
278 break; | |
279 } | |
280 case MARK_INVOKESPECIAL: { | |
281 assert(!method->is_static(), "cannot call static method with invokespecial"); | |
282 | |
283 address dest = SharedRuntime::get_resolve_opt_virtual_call_stub(); | |
284 long disp = dest - next_instruction; | |
285 assert(disp == (jint) disp, "disp doesn't fit in 32 bits"); | |
286 *((jint*)operand) = (jint)disp; | |
287 | |
288 _instructions->relocate(instruction, relocInfo::opt_virtual_call_type, Assembler::call32_operand); | |
289 break; | |
290 } | |
291 case MARK_INVOKE_INVALID: | |
292 default: | |
293 ShouldNotReachHere(); | |
294 break; | |
295 } | |
296 _next_call_type = MARK_INVOKE_INVALID; | |
297 _debug_recorder->end_safepoint(pc_offset); | |
298 } | |
299 } | |
300 | |
301 void CodeInstaller::site_DataPatch(CodeBuffer& buffer, jint pc_offset, oop site) { | |
302 oop constant = CiTargetMethod_DataPatch::constant(site); | |
303 oop kind = CiConstant::kind(constant); | |
304 | |
305 address instruction = _instructions->start() + pc_offset; | |
306 | |
307 switch(CiKind::typeChar(kind)) { | |
308 case 'z': | |
309 case 'b': | |
310 case 's': | |
311 case 'c': | |
312 case 'i': | |
313 fatal("int-sized values not expected in DataPatch"); | |
314 break; | |
315 case 'f': | |
316 case 'l': | |
317 case 'd': { | |
318 address operand = Assembler::locate_operand(instruction, Assembler::disp32_operand); | |
319 address next_instruction = Assembler::locate_next_instruction(instruction); | |
320 // we don't care if this is a long/double/etc., the primitive field contains the right bits | |
321 address dest = _constants->end(); | |
322 *(jlong*)dest = CiConstant::primitive(constant); | |
323 _constants->set_end(dest + BytesPerLong); | |
324 | |
325 long disp = dest - next_instruction; | |
326 assert(disp == (jint) disp, "disp doesn't fit in 32 bits"); | |
327 *((jint*)operand) = (jint)disp; | |
328 | |
329 _instructions->relocate(instruction, section_word_Relocation::spec((address)dest, CodeBuffer::SECT_CONSTS), Assembler::disp32_operand); | |
330 tty->print_cr("relocating (Float/Long/Double) at %016x/%016x", instruction, operand); | |
331 break; | |
332 } | |
333 case 'a': { | |
334 address operand = Assembler::locate_operand(instruction, Assembler::imm_operand); | |
335 oop obj = CiConstant::object(constant); | |
336 | |
337 if (obj->is_a(HotSpotTypeResolved::klass())) { | |
338 *((jobject*)operand) = JNIHandles::make_local(VmIds::get<klassOop>(HotSpotTypeResolved::vmId(obj))); | |
339 _instructions->relocate(instruction, oop_Relocation::spec_for_immediate(), Assembler::imm_operand); | |
340 tty->print_cr("relocating (HotSpotType) at %016x/%016x", instruction, operand); | |
341 } else { | |
342 assert(java_lang_boxing_object::is_instance(obj, T_LONG), "unexpected DataPatch object type"); | |
343 jlong id = obj->long_field(java_lang_boxing_object::value_offset_in_bytes(T_LONG)); | |
344 | |
345 assert((id & VmIds::TYPE_MASK) == VmIds::CONSTANT, "unexpected DataPatch type"); | |
346 | |
347 address operand = Assembler::locate_operand(instruction, Assembler::imm_operand); | |
348 | |
349 if (id == VmIds::DUMMY_CONSTANT) { | |
350 *((jobject*)operand) = (jobject)Universe::non_oop_word(); | |
351 } else { | |
352 *((jobject*)operand) = JNIHandles::make_local(VmIds::get<oop>(id)); | |
353 } | |
354 _instructions->relocate(instruction, oop_Relocation::spec_for_immediate(), Assembler::imm_operand); | |
355 tty->print_cr("relocating (oop constant) at %016x/%016x", instruction, operand); | |
356 } | |
357 break; | |
358 } | |
359 default: | |
360 fatal("unexpected CiKind in DataPatch"); | |
361 break; | |
362 } | |
363 } | |
364 | |
365 void CodeInstaller::site_ExceptionHandler(CodeBuffer& buffer, jint pc_offset, oop site) { | |
366 | |
367 } | |
368 | |
369 void CodeInstaller::site_Mark(CodeBuffer& buffer, jint pc_offset, oop site) { | |
370 oop id_obj = CiTargetMethod_Mark::id(site); | |
371 arrayOop references = (arrayOop)CiTargetMethod_Mark::references(site); | |
372 | |
373 if (id_obj != NULL) { | |
374 assert(java_lang_boxing_object::is_instance(id_obj, T_INT), "Integer id expected"); | |
375 jint id = id_obj->int_field(java_lang_boxing_object::value_offset_in_bytes(T_INT)); | |
376 | |
377 address instruction = _instructions->start() + pc_offset; | |
378 | |
379 switch (id) { | |
380 case MARK_UNVERIFIED_ENTRY: | |
381 _offsets.set_value(CodeOffsets::Entry, pc_offset); | |
382 break; | |
383 case MARK_VERIFIED_ENTRY: | |
384 _offsets.set_value(CodeOffsets::Verified_Entry, pc_offset); | |
385 break; | |
386 case MARK_OSR_ENTRY: | |
387 _offsets.set_value(CodeOffsets::OSR_Entry, pc_offset); | |
388 break; | |
389 case MARK_STATIC_CALL_STUB: { | |
390 assert(references->length() == 1, "static call stub needs one reference"); | |
391 oop ref = ((oop*)references->base(T_OBJECT))[0]; | |
392 address call_pc = _instructions->start() + CiTargetMethod_Site::pcOffset(ref); | |
393 _instructions->relocate(instruction, static_stub_Relocation::spec(call_pc)); | |
394 break; | |
395 } | |
396 case MARK_INVOKE_INVALID: | |
397 case MARK_INVOKEINTERFACE: | |
398 case MARK_INVOKESTATIC: | |
399 case MARK_INVOKESPECIAL: | |
400 case MARK_INVOKEVIRTUAL: | |
401 _next_call_type = (MarkId)id; | |
402 _invoke_mark_pc = instruction; | |
403 break; | |
404 case MARK_IMPLICIT_NULL_EXCEPTION_TARGET: | |
405 break; | |
406 default: | |
407 ShouldNotReachHere(); | |
408 break; | |
409 } | |
410 } | |
411 } | |
412 | |
413 // perform data and call relocation on the CodeBuffer | |
414 void CodeInstaller::initialize_buffer(CodeBuffer& buffer) { | |
415 _oop_recorder = new OopRecorder(_env->arena()); | |
416 _env->set_oop_recorder(_oop_recorder); | |
417 _debug_recorder = new DebugInformationRecorder(_env->oop_recorder()); | |
418 _debug_recorder->set_oopmaps(new OopMapSet()); | |
419 _dependencies = new Dependencies(_env); | |
420 | |
421 _env->set_oop_recorder(_oop_recorder); | |
422 _env->set_debug_info(_debug_recorder); | |
423 _env->set_dependencies(_dependencies); | |
424 buffer.initialize_oop_recorder(_oop_recorder); | |
425 | |
426 buffer.initialize_consts_size(_constants_size); | |
427 _instructions = buffer.insts(); | |
428 _constants = buffer.consts(); | |
429 | |
430 // copy the code into the newly created CodeBuffer | |
431 memcpy(_instructions->start(), _code->base(T_BYTE), _code_size); | |
432 _instructions->set_end(_instructions->start() + _code_size); | |
433 | |
434 oop* sites = (oop*)_sites->base(T_OBJECT); | |
435 for (int i=0; i<_sites->length(); i++) { | |
436 oop site = sites[i]; | |
437 jint pc_offset = CiTargetMethod_Site::pcOffset(site); | |
438 | |
439 if (site->is_a(CiTargetMethod_Safepoint::klass())) { | |
440 tty->print_cr("safepoint at %i", pc_offset); | |
441 site_Safepoint(buffer, pc_offset, site); | |
442 } else if (site->is_a(CiTargetMethod_Call::klass())) { | |
443 tty->print_cr("call at %i", pc_offset); | |
444 site_Call(buffer, pc_offset, site); | |
445 } else if (site->is_a(CiTargetMethod_DataPatch::klass())) { | |
446 tty->print_cr("datapatch at %i", pc_offset); | |
447 site_DataPatch(buffer, pc_offset, site); | |
448 } else if (site->is_a(CiTargetMethod_ExceptionHandler::klass())) { | |
449 tty->print_cr("exception handler at %i", pc_offset); | |
450 site_ExceptionHandler(buffer, pc_offset, site); | |
451 } else if (site->is_a(CiTargetMethod_Mark::klass())) { | |
452 tty->print_cr("mark at %i", pc_offset); | |
453 site_Mark(buffer, pc_offset, site); | |
454 } else { | |
455 ShouldNotReachHere(); | |
456 } | |
457 } | |
458 | |
459 /* | |
460 if (_relocation_count > 0) { | |
461 jint* relocation_offsets = (jint*)((arrayOop)JNIHandles::resolve(_relocation_offsets))->base(T_INT); | |
462 oop* relocation_objects = (oop*)((arrayOop)JNIHandles::resolve(_relocation_data))->base(T_OBJECT); | |
463 | |
464 for (int i = 0; i < _relocation_count; i++) { | |
465 address inst = (address)instructions->start() + relocation_offsets[i]; | |
466 u_char inst_byte = *inst; | |
467 oop obj = relocation_objects[i]; | |
468 assert(obj != NULL, "NULL oop needn't be patched"); | |
469 | |
470 if (obj->is_a(SystemDictionary::HotSpotProxy_klass())) { | |
471 jlong id = com_sun_hotspot_c1x_HotSpotProxy::get_id(obj); | |
472 switch (id & VmIds::TYPE_MASK) { | |
473 case VmIds::CONSTANT: { | |
474 address operand = Assembler::locate_operand(inst, Assembler::imm_operand); | |
475 | |
476 *((jobject*)operand) = JNIHandles::make_local(VmIds::get<oop>(id)); | |
477 instructions->relocate(inst, oop_Relocation::spec_for_immediate(), Assembler::imm_operand); | |
478 tty->print_cr("relocating (HotSpotType) %02x at %016x/%016x", inst_byte, inst, operand); | |
479 break; | |
480 } | |
481 case VmIds::STUB: { | |
482 address operand = Assembler::locate_operand(inst, Assembler::call32_operand); | |
483 | |
484 long dest = (long)VmIds::getStub(id); | |
485 long disp = dest - (long)(operand + 4); | |
486 assert(disp == (int) disp, "disp doesn't fit in 32 bits"); | |
487 *((int*)operand) = (int)disp; | |
488 | |
489 instructions->relocate(inst, runtime_call_Relocation::spec(), Assembler::call32_operand); | |
490 tty->print_cr("relocating (Long) %02x at %016x/%016x", inst_byte, inst, operand); | |
491 break; | |
492 } | |
493 } | |
494 } else if (java_lang_boxing_object::is_instance(obj)) { | |
495 address operand = Assembler::locate_operand(inst, Assembler::disp32_operand); | |
496 long dest = (long)constants->end(); | |
497 if (java_lang_boxing_object::is_instance(obj, T_LONG)) { | |
498 // tty->print("relocate: %l\n", obj->long_field(java_lang_boxing_object::value_offset_in_bytes(T_LONG))); | |
499 *(jlong*)constants->end() = obj->long_field(java_lang_boxing_object::value_offset_in_bytes(T_LONG)); | |
500 } else if (java_lang_boxing_object::is_instance(obj, T_DOUBLE)) { | |
501 // tty->print("relocate: %f\n", obj->double_field(java_lang_boxing_object::value_offset_in_bytes(T_DOUBLE))); | |
502 *(jdouble*)constants->end() = obj->double_field(java_lang_boxing_object::value_offset_in_bytes(T_DOUBLE)); | |
503 } else if (java_lang_boxing_object::is_instance(obj, T_FLOAT)) { | |
504 // tty->print("relocate: %f\n", obj->double_field(java_lang_boxing_object::value_offset_in_bytes(T_DOUBLE))); | |
505 *(jfloat*)constants->end() = obj->float_field(java_lang_boxing_object::value_offset_in_bytes(T_FLOAT)); | |
506 } | |
507 constants->set_end(constants->end() + 8); | |
508 | |
509 long disp = dest - (long)(operand + 4); | |
510 assert(disp == (int) disp, "disp doesn't fit in 32 bits"); | |
511 *((int*)operand) = (int)disp; | |
512 | |
513 instructions->relocate(inst, section_word_Relocation::spec((address)dest, CodeBuffer::SECT_CONSTS), Assembler::disp32_operand); | |
514 tty->print_cr("relocating (Long/Double) %02x at %016x/%016x", inst_byte, inst, operand); | |
515 } else if (obj->is_a(_types.HotSpotTypeResolved)) { | |
516 address operand = Assembler::locate_operand(inst, Assembler::imm_operand); | |
517 | |
518 *((jobject*)operand) = JNIHandles::make_local(VmIds::get<klassOop>(obj->obj_field(_types.HotSpotTypeResolved_klassOop))); | |
519 instructions->relocate(inst, oop_Relocation::spec_for_immediate(), Assembler::imm_operand); | |
520 tty->print_cr("relocating (HotSpotType) %02x at %016x/%016x", inst_byte, inst, operand); | |
521 } else { | |
522 tty->print_cr("unknown relocation type"); | |
523 obj->print(); | |
524 } | |
525 } | |
526 }*/ | |
527 } | |
528 |