Mercurial > hg > graal-compiler
comparison src/share/vm/c1x/c1x_CodeInstaller.cpp @ 1429:abc670a709dc
* -XX:TraceC1X=0...5 controls the native c1x tracing
* -Dc1x.debug=true turns on the logging proxies and lots of log output on the java side
* provide more information about types to the compiler (type hierarchy, etc)
* provide exception handler tables to the compiler
* add exception handlers to the nmethod
* correct implementation of ExceptionObject
* exception handling/unwinding entry points
* modified versions of handle/unwind exception stubs using standard calling conventions
* exception throwing
* implicit null pointer exception, implicit div by 0 exception
* arraystore/classcast/arrayindex exceptions
* checkcast implementation
* newarray, anewarray, multinewarray implementation
* correct new instance initialization
* access to java class mirrors (for ldc)
* unresolved methods
* class resolving - class patching (asssembly prototype copying)
author | Lukas Stadler <lukas.stadler@oracle.com> |
---|---|
date | Tue, 31 Aug 2010 22:13:30 -0700 |
parents | 695451afc619 |
children | b61a43cd1255 |
comparison
equal
deleted
inserted
replaced
1428:695451afc619 | 1429:abc670a709dc |
---|---|
24 | 24 |
25 | 25 |
26 # include "incls/_precompiled.incl" | 26 # include "incls/_precompiled.incl" |
27 # include "incls/_c1x_CodeInstaller.cpp.incl" | 27 # include "incls/_c1x_CodeInstaller.cpp.incl" |
28 | 28 |
29 | |
30 #define C1X_REGISTER_COUNT 32 | 29 #define C1X_REGISTER_COUNT 32 |
31 | 30 |
32 VMReg get_hotspot_reg(jint c1x_reg) { | 31 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 }; | 32 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 }; | 33 XMMRegister xmm_registers[] = { xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15 }; |
74 } | 73 } |
75 | 74 |
76 static ScopeValue* get_hotspot_value(oop value) { | 75 static ScopeValue* get_hotspot_value(oop value) { |
77 fatal("not implemented"); | 76 fatal("not implemented"); |
78 if (value->is_a(CiRegisterValue::klass())) { | 77 if (value->is_a(CiRegisterValue::klass())) { |
79 tty->print("register value"); | 78 TRACE_C1X_4("register value"); |
80 value->print(); | 79 IF_TRACE_C1X_4 value->print(); |
81 } else if (value->is_a(CiStackSlot::klass())) { | 80 } else if (value->is_a(CiStackSlot::klass())) { |
82 tty->print("stack value"); | 81 TRACE_C1X_4("stack value"); |
83 value->print(); | 82 IF_TRACE_C1X_4 value->print(); |
84 } else { | 83 } else { |
85 ShouldNotReachHere(); | 84 ShouldNotReachHere(); |
86 } | 85 } |
87 } | 86 } |
88 | 87 |
92 VM_ENTRY_MARK; | 91 VM_ENTRY_MARK; |
93 _env = CURRENT_ENV; | 92 _env = CURRENT_ENV; |
94 | 93 |
95 initialize_fields(target_method); | 94 initialize_fields(target_method); |
96 assert(_hotspot_method != NULL && _name == NULL, "installMethod needs NON-NULL method and NULL name"); | 95 assert(_hotspot_method != NULL && _name == NULL, "installMethod needs NON-NULL method and NULL name"); |
97 | 96 assert(_hotspot_method->is_a(HotSpotMethodResolved::klass()), "installMethod needs a HotSpotMethodResolved"); |
98 | 97 |
99 // TODO: This is a hack.. Produce correct entries. | 98 // TODO: This is a hack.. Produce correct entries. |
100 _offsets.set_value(CodeOffsets::Exceptions, 0); | 99 _offsets.set_value(CodeOffsets::Exceptions, 0); |
101 _offsets.set_value(CodeOffsets::Deopt, 0); | 100 _offsets.set_value(CodeOffsets::Deopt, 0); |
102 | 101 |
103 methodOop method = VmIds::get<methodOop>(HotSpotMethod::vmId(_hotspot_method)); | 102 methodOop method = VmIds::get<methodOop>(HotSpotMethodResolved::vmId(_hotspot_method)); |
104 ciMethod *ciMethodObject = (ciMethod *)_env->get_object(method); | 103 ciMethod *ciMethodObject = (ciMethod *)_env->get_object(method); |
105 _parameter_count = method->size_of_parameters(); | 104 _parameter_count = method->size_of_parameters(); |
106 | 105 |
107 // (very) conservative estimate: each site needs a relocation | 106 // (very) conservative estimate: each site needs a relocation |
108 CodeBuffer buffer("temp c1x method", _total_size, _sites->length() * relocInfo::length_limit); | 107 CodeBuffer buffer("temp c1x method", _total_size, _sites->length() * relocInfo::length_limit); |
109 initialize_buffer(buffer); | 108 initialize_buffer(buffer); |
110 ExceptionHandlerTable handler_table; | 109 process_exception_handlers(); |
111 ImplicitExceptionTable inc_table; | |
112 { | 110 { |
113 ThreadToNativeFromVM t((JavaThread*)THREAD); | 111 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); | 112 _env->register_method(ciMethodObject, |
113 -1, | |
114 &_offsets, | |
115 0, | |
116 &buffer, | |
117 (_frame_size / HeapWordSize) + 2, // conversion to words, need to add two slots for ret address and frame pointer | |
118 _debug_recorder->_oopmaps, | |
119 &_exception_handler_table, | |
120 &_implicit_exception_table, | |
121 C1XCompiler::instance(), | |
122 _env->comp_level(), | |
123 false, | |
124 false); | |
115 } | 125 } |
116 } | 126 } |
117 | 127 |
118 // constructor used to create a stub | 128 // constructor used to create a stub |
119 CodeInstaller::CodeInstaller(oop target_method, jlong& id) { | 129 CodeInstaller::CodeInstaller(oop target_method, jlong& id) { |
127 CodeBuffer buffer("temp c1x stub", _total_size, _sites->length() * relocInfo::length_limit); | 137 CodeBuffer buffer("temp c1x stub", _total_size, _sites->length() * relocInfo::length_limit); |
128 initialize_buffer(buffer); | 138 initialize_buffer(buffer); |
129 | 139 |
130 const char* cname = java_lang_String::as_utf8_string(_name); | 140 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 | 141 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); | 142 IF_TRACE_C1X_3 Disassembler::decode((CodeBlob*)blob); |
133 id = VmIds::addStub(blob->instructions_begin()); | 143 id = VmIds::addStub(blob->instructions_begin()); |
134 } | 144 } |
135 | 145 |
136 void CodeInstaller::initialize_fields(oop target_method) { | 146 void CodeInstaller::initialize_fields(oop target_method) { |
137 _citarget_method = HotSpotTargetMethod::targetMethod(target_method); | 147 _citarget_method = HotSpotTargetMethod::targetMethod(target_method); |
138 _hotspot_method = HotSpotTargetMethod::method(target_method); | 148 _hotspot_method = HotSpotTargetMethod::method(target_method); |
139 _name = HotSpotTargetMethod::name(target_method); | 149 _name = HotSpotTargetMethod::name(target_method); |
140 _sites = (arrayOop)HotSpotTargetMethod::sites(target_method); | 150 _sites = (arrayOop)HotSpotTargetMethod::sites(target_method); |
151 _exception_handlers = (arrayOop)HotSpotTargetMethod::exceptionHandlers(target_method); | |
141 | 152 |
142 _code = (arrayOop)CiTargetMethod::targetCode(_citarget_method); | 153 _code = (arrayOop)CiTargetMethod::targetCode(_citarget_method); |
143 _code_size = CiTargetMethod::targetCodeSize(_citarget_method); | 154 _code_size = CiTargetMethod::targetCodeSize(_citarget_method); |
144 _frame_size = CiTargetMethod::frameSize(_citarget_method); | 155 _frame_size = CiTargetMethod::frameSize(_citarget_method); |
145 | 156 |
148 _total_size = align_size_up(_code_size, HeapWordSize) + _constants_size; | 159 _total_size = align_size_up(_code_size, HeapWordSize) + _constants_size; |
149 | 160 |
150 _next_call_type = MARK_INVOKE_INVALID; | 161 _next_call_type = MARK_INVOKE_INVALID; |
151 } | 162 } |
152 | 163 |
153 void CodeInstaller::site_Safepoint(CodeBuffer& buffer, jint pc_offset, oop site) { | 164 // perform data and call relocation on the CodeBuffer |
165 void CodeInstaller::initialize_buffer(CodeBuffer& buffer) { | |
166 _oop_recorder = new OopRecorder(_env->arena()); | |
167 _env->set_oop_recorder(_oop_recorder); | |
168 _debug_recorder = new DebugInformationRecorder(_env->oop_recorder()); | |
169 _debug_recorder->set_oopmaps(new OopMapSet()); | |
170 _dependencies = new Dependencies(_env); | |
171 | |
172 _env->set_oop_recorder(_oop_recorder); | |
173 _env->set_debug_info(_debug_recorder); | |
174 _env->set_dependencies(_dependencies); | |
175 buffer.initialize_oop_recorder(_oop_recorder); | |
176 | |
177 buffer.initialize_consts_size(_constants_size); | |
178 _instructions = buffer.insts(); | |
179 _constants = buffer.consts(); | |
180 | |
181 // copy the code into the newly created CodeBuffer | |
182 memcpy(_instructions->start(), _code->base(T_BYTE), _code_size); | |
183 _instructions->set_end(_instructions->start() + _code_size); | |
184 | |
185 oop* sites = (oop*)_sites->base(T_OBJECT); | |
186 for (int i=0; i<_sites->length(); i++) { | |
187 oop site = sites[i]; | |
188 jint pc_offset = CiTargetMethod_Site::pcOffset(site); | |
189 | |
190 if (site->is_a(CiTargetMethod_Safepoint::klass())) { | |
191 TRACE_C1X_4("safepoint at %i", pc_offset); | |
192 site_Safepoint(buffer, pc_offset, site); | |
193 } else if (site->is_a(CiTargetMethod_Call::klass())) { | |
194 TRACE_C1X_4("call at %i", pc_offset); | |
195 site_Call(buffer, pc_offset, site); | |
196 } else if (site->is_a(CiTargetMethod_DataPatch::klass())) { | |
197 TRACE_C1X_4("datapatch at %i", pc_offset); | |
198 site_DataPatch(buffer, pc_offset, site); | |
199 } else if (site->is_a(CiTargetMethod_Mark::klass())) { | |
200 TRACE_C1X_4("mark at %i", pc_offset); | |
201 site_Mark(buffer, pc_offset, site); | |
202 } else { | |
203 fatal("unexpected Site subclass"); | |
204 } | |
205 } | |
206 } | |
207 | |
208 void CodeInstaller::process_exception_handlers() { | |
209 // allocate some arrays for use by the collection code. | |
210 const int num_handlers = 5; | |
211 GrowableArray<intptr_t>* bcis = new GrowableArray<intptr_t>(num_handlers); | |
212 GrowableArray<intptr_t>* scope_depths = new GrowableArray<intptr_t>(num_handlers); | |
213 GrowableArray<intptr_t>* pcos = new GrowableArray<intptr_t>(num_handlers); | |
214 | |
215 if (_exception_handlers != NULL) { | |
216 oop* exception_handlers = (oop*)_exception_handlers->base(T_OBJECT); | |
217 for (int i=0; i<_exception_handlers->length(); i++) { | |
218 jint pc_offset = CiTargetMethod_Site::pcOffset(exception_handlers[i]); | |
219 int start = i; | |
220 while ((i + 1)<_exception_handlers->length() && CiTargetMethod_Site::pcOffset(exception_handlers[i + 1]) == pc_offset) | |
221 i ++; | |
222 | |
223 // empty the arrays | |
224 bcis->trunc_to(0); | |
225 scope_depths->trunc_to(0); | |
226 pcos->trunc_to(0); | |
227 | |
228 for (int j = start; j <= i; j++) { | |
229 oop exc = exception_handlers[j]; | |
230 jint handler_offset = CiTargetMethod_ExceptionHandler::handlerPos(exc); | |
231 jint handler_bci = CiTargetMethod_ExceptionHandler::handlerBci(exc); | |
232 jint bci = CiTargetMethod_ExceptionHandler::bci(exc); | |
233 jint scope_level = CiTargetMethod_ExceptionHandler::scopeLevel(exc); | |
234 Handle handler_type = CiTargetMethod_ExceptionHandler::exceptionType(exc); | |
235 | |
236 assert(handler_offset != -1, "must have been generated"); | |
237 | |
238 int e = bcis->find(handler_bci); | |
239 if (e >= 0 && scope_depths->at(e) == scope_level) { | |
240 // two different handlers are declared to dispatch to the same | |
241 // catch bci. During parsing we created edges for each | |
242 // handler but we really only need one. The exception handler | |
243 // table will also get unhappy if we try to declare both since | |
244 // it's nonsensical. Just skip this handler. | |
245 continue; | |
246 } | |
247 | |
248 bcis->append(handler_bci); | |
249 if (handler_bci == -1) { | |
250 // insert a wildcard handler at scope depth 0 so that the | |
251 // exception lookup logic with find it. | |
252 scope_depths->append(0); | |
253 } else { | |
254 scope_depths->append(scope_level); | |
255 } | |
256 pcos->append(handler_offset); | |
257 | |
258 // stop processing once we hit a catch any | |
259 // if (handler->is_catch_all()) { | |
260 // assert(i == handlers->length() - 1, "catch all must be last handler"); | |
261 // } | |
262 | |
263 } | |
264 _exception_handler_table.add_subtable(pc_offset, bcis, scope_depths, pcos); | |
265 } | |
266 } | |
267 | |
154 | 268 |
155 } | 269 } |
156 | 270 |
157 void CodeInstaller::record_frame(jint pc_offset, oop code_pos, oop frame) { | 271 void CodeInstaller::record_frame(jint pc_offset, oop code_pos, oop frame) { |
158 oop caller_pos = CiCodePos::caller(code_pos); | 272 oop caller_pos = CiCodePos::caller(code_pos); |
159 if (caller_pos != NULL) { | 273 if (caller_pos != NULL) { |
160 oop caller_frame = CiDebugInfo_Frame::caller(frame); | 274 oop caller_frame = CiDebugInfo_Frame::caller(frame); |
161 record_frame(pc_offset, caller_pos, caller_frame); | 275 record_frame(pc_offset, caller_pos, caller_frame); |
162 } else { | 276 } else { |
163 assert(frame == NULL || CiDebugInfo_Frame::caller(frame) == NULL, "unexpected layout - different nesting of Frame and CiCodePos"); | 277 assert(frame == NULL || CiDebugInfo_Frame::caller(frame) == NULL, "unexpected layout - mismatching nesting of Frame and CiCodePos"); |
164 } | 278 } |
165 | 279 |
166 assert(frame == NULL || code_pos == CiDebugInfo_Frame::codePos(frame), "unexpected CiCodePos layout"); | 280 assert(frame == NULL || code_pos == CiDebugInfo_Frame::codePos(frame), "unexpected CiCodePos layout"); |
167 | 281 |
168 oop hotspot_method = CiCodePos::method(code_pos); | 282 oop hotspot_method = CiCodePos::method(code_pos); |
169 methodOop method = VmIds::get<methodOop>(HotSpotMethod::vmId(hotspot_method)); | 283 assert(hotspot_method != NULL && hotspot_method->is_a(HotSpotMethodResolved::klass()), "unexpected hotspot method"); |
284 methodOop method = VmIds::get<methodOop>(HotSpotMethodResolved::vmId(hotspot_method)); | |
170 ciMethod *cimethod = (ciMethod *)_env->get_object(method); | 285 ciMethod *cimethod = (ciMethod *)_env->get_object(method); |
171 jint bci = CiCodePos::bci(code_pos); | 286 jint bci = CiCodePos::bci(code_pos); |
172 | 287 |
173 if (frame != NULL) { | 288 if (frame != NULL) { |
174 jint local_count = CiDebugInfo_Frame::numLocals(frame); | 289 jint local_count = CiDebugInfo_Frame::numLocals(frame); |
203 } else { | 318 } else { |
204 _debug_recorder->describe_scope(pc_offset, cimethod, bci, false, false, false, NULL, NULL, NULL); | 319 _debug_recorder->describe_scope(pc_offset, cimethod, bci, false, false, false, NULL, NULL, NULL); |
205 } | 320 } |
206 } | 321 } |
207 | 322 |
323 | |
324 void CodeInstaller::site_Safepoint(CodeBuffer& buffer, jint pc_offset, oop site) { | |
325 oop debug_info = CiTargetMethod_Safepoint::debugInfo(site); | |
326 assert(debug_info != NULL, "debug info expected"); | |
327 | |
328 // address instruction = _instructions->start() + pc_offset; | |
329 // jint next_pc_offset = Assembler::locate_next_instruction(instruction) - _instructions->start(); | |
330 _debug_recorder->add_safepoint(pc_offset, create_oop_map(_frame_size, _parameter_count, debug_info)); | |
331 | |
332 oop code_pos = CiDebugInfo::codePos(debug_info); | |
333 oop frame = CiDebugInfo::frame(debug_info); | |
334 record_frame(pc_offset, code_pos, frame); | |
335 | |
336 _debug_recorder->end_safepoint(pc_offset); | |
337 } | |
338 | |
208 void CodeInstaller::site_Call(CodeBuffer& buffer, jint pc_offset, oop site) { | 339 void CodeInstaller::site_Call(CodeBuffer& buffer, jint pc_offset, oop site) { |
209 oop runtime_call = CiTargetMethod_Call::runtimeCall(site); | 340 oop runtime_call = CiTargetMethod_Call::runtimeCall(site); |
210 oop hotspot_method = CiTargetMethod_Call::method(site); | 341 oop hotspot_method = CiTargetMethod_Call::method(site); |
211 oop symbol = CiTargetMethod_Call::symbol(site); | 342 oop symbol = CiTargetMethod_Call::symbol(site); |
212 oop global_stub = CiTargetMethod_Call::globalStubID(site); | 343 oop global_stub = CiTargetMethod_Call::globalStubID(site); |
215 arrayOop stack_map = (arrayOop)CiTargetMethod_Call::stackMap(site); | 346 arrayOop stack_map = (arrayOop)CiTargetMethod_Call::stackMap(site); |
216 arrayOop register_map = (arrayOop)CiTargetMethod_Call::registerMap(site); | 347 arrayOop register_map = (arrayOop)CiTargetMethod_Call::registerMap(site); |
217 | 348 |
218 assert((runtime_call ? 1 : 0) + (hotspot_method ? 1 : 0) + (symbol ? 1 : 0) + (global_stub ? 1 : 0) == 1, "Call site needs exactly one type"); | 349 assert((runtime_call ? 1 : 0) + (hotspot_method ? 1 : 0) + (symbol ? 1 : 0) + (global_stub ? 1 : 0) == 1, "Call site needs exactly one type"); |
219 | 350 |
220 address instruction = _instructions->start() + pc_offset; | 351 NativeCall* call = nativeCall_at(_instructions->start() + pc_offset); |
221 address operand = Assembler::locate_operand(instruction, Assembler::call32_operand); | 352 jint next_pc_offset = pc_offset + NativeCall::instruction_size; |
222 address next_instruction = Assembler::locate_next_instruction(instruction); | 353 |
223 | 354 if (debug_info != NULL) { |
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)); | 355 _debug_recorder->add_safepoint(next_pc_offset, create_oop_map(_frame_size, _parameter_count, debug_info)); |
252 oop code_pos = CiDebugInfo::codePos(debug_info); | 356 oop code_pos = CiDebugInfo::codePos(debug_info); |
253 oop frame = CiDebugInfo::frame(debug_info); | 357 oop frame = CiDebugInfo::frame(debug_info); |
254 record_frame(next_pc_offset, code_pos, frame); | 358 record_frame(next_pc_offset, code_pos, frame); |
255 | 359 } |
360 | |
361 if (runtime_call != NULL) { | |
362 if (runtime_call == CiRuntimeCall::Debug()) { | |
363 TRACE_C1X_3("CiRuntimeCall::Debug()"); | |
364 } else if (runtime_call == CiRuntimeCall::UnwindException()) { | |
365 call->set_destination(Runtime1::entry_for(Runtime1::c1x_unwind_exception_call_id)); | |
366 _instructions->relocate(call->instruction_address(), runtime_call_Relocation::spec(), Assembler::call32_operand); | |
367 TRACE_C1X_3("CiRuntimeCall::UnwindException()"); | |
368 } else if (runtime_call == CiRuntimeCall::HandleException()) { | |
369 call->set_destination(Runtime1::entry_for(Runtime1::c1x_handle_exception_id)); | |
370 _instructions->relocate(call->instruction_address(), runtime_call_Relocation::spec(), Assembler::call32_operand); | |
371 TRACE_C1X_3("CiRuntimeCall::HandleException()"); | |
372 } else { | |
373 TRACE_C1X_1("runtime_call not implemented: "); | |
374 IF_TRACE_C1X_1 runtime_call->print(); | |
375 } | |
376 } else if (global_stub != NULL) { | |
377 assert(java_lang_boxing_object::is_instance(global_stub, T_LONG), "global_stub needs to be of type Long"); | |
378 | |
379 call->set_destination(VmIds::getStub(global_stub)); | |
380 _instructions->relocate(call->instruction_address(), runtime_call_Relocation::spec(), Assembler::call32_operand); | |
381 TRACE_C1X_3("relocating (stub) at %016x", call->instruction_address()); | |
382 } else if (symbol != NULL) { | |
383 fatal("symbol"); | |
384 } else { // method != NULL | |
385 assert(hotspot_method != NULL, "unexpected RiMethod"); | |
386 assert(debug_info != NULL, "debug info expected"); | |
387 | |
388 methodOop method = NULL; | |
389 if (hotspot_method->is_a(HotSpotMethodResolved::klass())) | |
390 method = VmIds::get<methodOop>(HotSpotMethodResolved::vmId(hotspot_method)); | |
391 | |
392 assert(debug_info != NULL, "debug info expected"); | |
393 | |
394 TRACE_C1X_3("method call"); | |
256 switch(_next_call_type) { | 395 switch(_next_call_type) { |
257 case MARK_INVOKEVIRTUAL: | 396 case MARK_INVOKEVIRTUAL: |
258 case MARK_INVOKEINTERFACE: { | 397 case MARK_INVOKEINTERFACE: { |
259 assert(!method->is_static(), "cannot call static method with invokeinterface"); | 398 assert(method == NULL || !method->is_static(), "cannot call static method with invokeinterface"); |
260 | 399 |
261 address dest = SharedRuntime::get_resolve_virtual_call_stub(); | 400 call->set_destination(SharedRuntime::get_resolve_virtual_call_stub()); |
262 long disp = dest - next_instruction; | 401 _instructions->relocate(call->instruction_address(), virtual_call_Relocation::spec(_invoke_mark_pc), Assembler::call32_operand); |
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; | 402 break; |
268 } | 403 } |
269 case MARK_INVOKESTATIC: { | 404 case MARK_INVOKESTATIC: { |
270 assert(method->is_static(), "cannot call non-static method with invokestatic"); | 405 assert(method == NULL || method->is_static(), "cannot call non-static method with invokestatic"); |
271 | 406 |
272 address dest = SharedRuntime::get_resolve_static_call_stub(); | 407 call->set_destination(SharedRuntime::get_resolve_static_call_stub()); |
273 long disp = dest - next_instruction; | 408 _instructions->relocate(call->instruction_address(), relocInfo::static_call_type, Assembler::call32_operand); |
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; | 409 break; |
279 } | 410 } |
280 case MARK_INVOKESPECIAL: { | 411 case MARK_INVOKESPECIAL: { |
281 assert(!method->is_static(), "cannot call static method with invokespecial"); | 412 assert(method == NULL || !method->is_static(), "cannot call static method with invokespecial"); |
282 | 413 |
283 address dest = SharedRuntime::get_resolve_opt_virtual_call_stub(); | 414 call->set_destination(SharedRuntime::get_resolve_opt_virtual_call_stub()); |
284 long disp = dest - next_instruction; | 415 _instructions->relocate(call->instruction_address(), relocInfo::opt_virtual_call_type, Assembler::call32_operand); |
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; | 416 break; |
290 } | 417 } |
291 case MARK_INVOKE_INVALID: | 418 case MARK_INVOKE_INVALID: |
292 default: | 419 default: |
293 ShouldNotReachHere(); | 420 ShouldNotReachHere(); |
294 break; | 421 break; |
295 } | 422 } |
296 _next_call_type = MARK_INVOKE_INVALID; | 423 } |
297 _debug_recorder->end_safepoint(pc_offset); | 424 _next_call_type = MARK_INVOKE_INVALID; |
425 if (debug_info != NULL) { | |
426 _debug_recorder->end_safepoint(next_pc_offset); | |
298 } | 427 } |
299 } | 428 } |
300 | 429 |
301 void CodeInstaller::site_DataPatch(CodeBuffer& buffer, jint pc_offset, oop site) { | 430 void CodeInstaller::site_DataPatch(CodeBuffer& buffer, jint pc_offset, oop site) { |
302 oop constant = CiTargetMethod_DataPatch::constant(site); | 431 oop constant = CiTargetMethod_DataPatch::constant(site); |
325 long disp = dest - next_instruction; | 454 long disp = dest - next_instruction; |
326 assert(disp == (jint) disp, "disp doesn't fit in 32 bits"); | 455 assert(disp == (jint) disp, "disp doesn't fit in 32 bits"); |
327 *((jint*)operand) = (jint)disp; | 456 *((jint*)operand) = (jint)disp; |
328 | 457 |
329 _instructions->relocate(instruction, section_word_Relocation::spec((address)dest, CodeBuffer::SECT_CONSTS), Assembler::disp32_operand); | 458 _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); | 459 TRACE_C1X_3("relocating (Float/Long/Double) at %016x/%016x", instruction, operand); |
331 break; | 460 break; |
332 } | 461 } |
333 case 'a': { | 462 case 'a': { |
334 address operand = Assembler::locate_operand(instruction, Assembler::imm_operand); | 463 address operand = Assembler::locate_operand(instruction, Assembler::imm_operand); |
335 oop obj = CiConstant::object(constant); | 464 oop obj = CiConstant::object(constant); |
336 | 465 |
337 if (obj->is_a(HotSpotTypeResolved::klass())) { | 466 if (obj->is_a(HotSpotTypeResolved::klass())) { |
338 *((jobject*)operand) = JNIHandles::make_local(VmIds::get<klassOop>(HotSpotTypeResolved::vmId(obj))); | 467 *((jobject*)operand) = JNIHandles::make_local(VmIds::get<klassOop>(HotSpotTypeResolved::vmId(obj))); |
339 _instructions->relocate(instruction, oop_Relocation::spec_for_immediate(), Assembler::imm_operand); | 468 _instructions->relocate(instruction, oop_Relocation::spec_for_immediate(), Assembler::imm_operand); |
340 tty->print_cr("relocating (HotSpotType) at %016x/%016x", instruction, operand); | 469 TRACE_C1X_3("relocating (HotSpotType) at %016x/%016x", instruction, operand); |
341 } else { | 470 } else { |
342 assert(java_lang_boxing_object::is_instance(obj, T_LONG), "unexpected DataPatch object type"); | 471 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)); | 472 jlong id = obj->long_field(java_lang_boxing_object::value_offset_in_bytes(T_LONG)); |
344 | 473 |
345 assert((id & VmIds::TYPE_MASK) == VmIds::CONSTANT, "unexpected DataPatch type"); | 474 assert((id & VmIds::TYPE_MASK) == VmIds::CONSTANT, "unexpected DataPatch type"); |
350 *((jobject*)operand) = (jobject)Universe::non_oop_word(); | 479 *((jobject*)operand) = (jobject)Universe::non_oop_word(); |
351 } else { | 480 } else { |
352 *((jobject*)operand) = JNIHandles::make_local(VmIds::get<oop>(id)); | 481 *((jobject*)operand) = JNIHandles::make_local(VmIds::get<oop>(id)); |
353 } | 482 } |
354 _instructions->relocate(instruction, oop_Relocation::spec_for_immediate(), Assembler::imm_operand); | 483 _instructions->relocate(instruction, oop_Relocation::spec_for_immediate(), Assembler::imm_operand); |
355 tty->print_cr("relocating (oop constant) at %016x/%016x", instruction, operand); | 484 TRACE_C1X_3("relocating (oop constant) at %016x/%016x", instruction, operand); |
356 } | 485 } |
357 break; | 486 break; |
358 } | 487 } |
359 default: | 488 default: |
360 fatal("unexpected CiKind in DataPatch"); | 489 fatal("unexpected CiKind in DataPatch"); |
361 break; | 490 break; |
362 } | 491 } |
363 } | 492 } |
364 | 493 |
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) { | 494 void CodeInstaller::site_Mark(CodeBuffer& buffer, jint pc_offset, oop site) { |
370 oop id_obj = CiTargetMethod_Mark::id(site); | 495 oop id_obj = CiTargetMethod_Mark::id(site); |
371 arrayOop references = (arrayOop)CiTargetMethod_Mark::references(site); | 496 arrayOop references = (arrayOop)CiTargetMethod_Mark::references(site); |
372 | 497 |
373 if (id_obj != NULL) { | 498 if (id_obj != NULL) { |
383 case MARK_VERIFIED_ENTRY: | 508 case MARK_VERIFIED_ENTRY: |
384 _offsets.set_value(CodeOffsets::Verified_Entry, pc_offset); | 509 _offsets.set_value(CodeOffsets::Verified_Entry, pc_offset); |
385 break; | 510 break; |
386 case MARK_OSR_ENTRY: | 511 case MARK_OSR_ENTRY: |
387 _offsets.set_value(CodeOffsets::OSR_Entry, pc_offset); | 512 _offsets.set_value(CodeOffsets::OSR_Entry, pc_offset); |
513 break; | |
514 case MARK_UNWIND_ENTRY: | |
515 _offsets.set_value(CodeOffsets::UnwindHandler, pc_offset); | |
516 break; | |
517 case MARK_EXCEPTION_HANDLER_ENTRY: | |
518 _offsets.set_value(CodeOffsets::Exceptions, pc_offset); | |
388 break; | 519 break; |
389 case MARK_STATIC_CALL_STUB: { | 520 case MARK_STATIC_CALL_STUB: { |
390 assert(references->length() == 1, "static call stub needs one reference"); | 521 assert(references->length() == 1, "static call stub needs one reference"); |
391 oop ref = ((oop*)references->base(T_OBJECT))[0]; | 522 oop ref = ((oop*)references->base(T_OBJECT))[0]; |
392 address call_pc = _instructions->start() + CiTargetMethod_Site::pcOffset(ref); | 523 address call_pc = _instructions->start() + CiTargetMethod_Site::pcOffset(ref); |
399 case MARK_INVOKESPECIAL: | 530 case MARK_INVOKESPECIAL: |
400 case MARK_INVOKEVIRTUAL: | 531 case MARK_INVOKEVIRTUAL: |
401 _next_call_type = (MarkId)id; | 532 _next_call_type = (MarkId)id; |
402 _invoke_mark_pc = instruction; | 533 _invoke_mark_pc = instruction; |
403 break; | 534 break; |
404 case MARK_IMPLICIT_NULL_EXCEPTION_TARGET: | 535 case MARK_IMPLICIT_NULL: |
405 break; | 536 _implicit_exception_table.append(pc_offset, pc_offset); |
537 break; | |
538 case MARK_KLASS_PATCHING: { | |
539 unsigned char* byte_count = (unsigned char*) (instruction - 1); | |
540 unsigned char* byte_skip = (unsigned char*) (instruction - 2); | |
541 unsigned char* being_initialized_entry_offset = (unsigned char*) (instruction - 3); | |
542 | |
543 assert(*byte_skip == 5, "unexpected byte_skip"); | |
544 | |
545 assert(references->length() == 2, "MARK_KLASS_PATCHING needs 2 references"); | |
546 oop ref1 = ((oop*)references->base(T_OBJECT))[0]; | |
547 oop ref2 = ((oop*)references->base(T_OBJECT))[1]; | |
548 int i_byte_count = CiTargetMethod_Site::pcOffset(ref2) - CiTargetMethod_Site::pcOffset(ref1); | |
549 assert(i_byte_count == (unsigned char)i_byte_count, "invalid offset"); | |
550 *byte_count = i_byte_count; | |
551 *being_initialized_entry_offset = *byte_count + *byte_skip; | |
552 | |
553 break; | |
554 } | |
555 case MARK_DUMMY_OOP_RELOCATION: { | |
556 _instructions->relocate(instruction, oop_Relocation::spec_for_immediate(), Assembler::imm_operand); | |
557 | |
558 RelocIterator iter(_instructions, (address)instruction, (address)(instruction + 1)); | |
559 relocInfo::change_reloc_info_for_address(&iter, (address) instruction, relocInfo::oop_type, relocInfo::none); | |
560 break; | |
561 } | |
406 default: | 562 default: |
407 ShouldNotReachHere(); | 563 ShouldNotReachHere(); |
408 break; | 564 break; |
409 } | 565 } |
410 } | 566 } |
411 } | 567 } |
412 | 568 |
413 // perform data and call relocation on the CodeBuffer | 569 |
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 | 570 |
459 /* | 571 /* |
460 if (_relocation_count > 0) { | 572 if (_relocation_count > 0) { |
461 jint* relocation_offsets = (jint*)((arrayOop)JNIHandles::resolve(_relocation_offsets))->base(T_INT); | 573 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); | 574 oop* relocation_objects = (oop*)((arrayOop)JNIHandles::resolve(_relocation_data))->base(T_OBJECT); |
522 tty->print_cr("unknown relocation type"); | 634 tty->print_cr("unknown relocation type"); |
523 obj->print(); | 635 obj->print(); |
524 } | 636 } |
525 } | 637 } |
526 }*/ | 638 }*/ |
527 } | 639 |
528 |