Mercurial > hg > graal-compiler
comparison src/share/vm/graal/graalCodeInstaller.cpp @ 2890:c23d45daff9b
Renamed cpp/hpp file directory.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Wed, 08 Jun 2011 13:40:25 +0200 |
parents | src/share/vm/c1x/graalCodeInstaller.cpp@2fb867285938 |
children | 75a99b4f1c98 |
comparison
equal
deleted
inserted
replaced
2889:2fb867285938 | 2890:c23d45daff9b |
---|---|
1 /* | |
2 * Copyright (c) 2011, 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 "precompiled.hpp" | |
25 #include "c1x/c1x_Compiler.hpp" | |
26 #include "c1x/c1x_CodeInstaller.hpp" | |
27 #include "c1x/c1x_JavaAccess.hpp" | |
28 #include "c1x/c1x_VmIds.hpp" | |
29 #include "c1/c1_Runtime1.hpp" | |
30 #include "classfile/vmSymbols.hpp" | |
31 #include "vmreg_x86.inline.hpp" | |
32 | |
33 | |
34 // TODO this should be handled in a more robust way - not hard coded... | |
35 Register CPU_REGS[] = { rax, rcx, rdx, rbx, rsp, rbp, rsi, rdi, r8, r9, r10, r11, r12, r13, r14, r15 }; | |
36 bool OOP_ALLOWED[] = {true, true, true, true, false, false, true, true, true, true, false, true, true, true, true, true}; | |
37 const static int NUM_CPU_REGS = sizeof(CPU_REGS) / sizeof(Register); | |
38 XMMRegister XMM_REGS[] = { xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, xmm8, xmm9, xmm10, xmm11, xmm12, xmm13, xmm14, xmm15 }; | |
39 const static int NUM_XMM_REGS = sizeof(XMM_REGS) / sizeof(XMMRegister); | |
40 const static int NUM_REGS = NUM_CPU_REGS + NUM_XMM_REGS; | |
41 const static jlong NO_REF_MAP = 0x8000000000000000L; | |
42 | |
43 // convert c1x register indices (as used in oop maps) to hotspot registers | |
44 VMReg get_hotspot_reg(jint c1x_reg) { | |
45 | |
46 assert(c1x_reg >= 0 && c1x_reg < NUM_REGS, "invalid register number"); | |
47 if (c1x_reg < NUM_CPU_REGS) { | |
48 return CPU_REGS[c1x_reg]->as_VMReg(); | |
49 } else { | |
50 return XMM_REGS[c1x_reg - NUM_CPU_REGS]->as_VMReg(); | |
51 } | |
52 } | |
53 | |
54 static bool is_bit_set(oop bit_map, int i) { | |
55 const int MapWordBits = 64; | |
56 if (i < MapWordBits) { | |
57 jlong low = CiBitMap::low(bit_map); | |
58 return (low & (1LL << i)) != 0; | |
59 } else { | |
60 jint extra_idx = (i - MapWordBits) / MapWordBits; | |
61 arrayOop extra = (arrayOop) CiBitMap::extra(bit_map); | |
62 assert(extra_idx >= 0 && extra_idx < extra->length(), "unexpected index"); | |
63 jlong word = ((jlong*) extra->base(T_LONG))[extra_idx]; | |
64 return (word & (1LL << (i % MapWordBits))) != 0; | |
65 } | |
66 } | |
67 | |
68 // creates a hotspot oop map out of the byte arrays provided by CiDebugInfo | |
69 static OopMap* create_oop_map(jint frame_size, jint parameter_count, oop debug_info) { | |
70 OopMap* map = new OopMap(frame_size, parameter_count); | |
71 oop register_map = (oop) CiDebugInfo::registerRefMap(debug_info); | |
72 oop frame_map = (oop) CiDebugInfo::frameRefMap(debug_info); | |
73 | |
74 if (register_map != NULL) { | |
75 assert(CiBitMap::size(register_map) == (unsigned) NUM_CPU_REGS, "unexpected register_map length"); | |
76 for (jint i = 0; i < NUM_CPU_REGS; i++) { | |
77 bool is_oop = is_bit_set(register_map, i); | |
78 VMReg reg = get_hotspot_reg(i); | |
79 if (is_oop) { | |
80 assert(OOP_ALLOWED[i], "this register may never be an oop, register map misaligned?"); | |
81 map->set_oop(reg); | |
82 } else { | |
83 map->set_value(reg); | |
84 } | |
85 } | |
86 } | |
87 | |
88 if (frame_size > 0) { | |
89 assert(CiBitMap::size(frame_map) == frame_size / HeapWordSize, "unexpected frame_map length"); | |
90 | |
91 for (jint i = 0; i < frame_size / HeapWordSize; i++) { | |
92 bool is_oop = is_bit_set(frame_map, i); | |
93 // hotspot stack slots are 4 bytes | |
94 VMReg reg = VMRegImpl::stack2reg(i * 2); | |
95 if (is_oop) { | |
96 map->set_oop(reg); | |
97 } else { | |
98 map->set_value(reg); | |
99 } | |
100 } | |
101 } else { | |
102 assert(frame_map == NULL || CiBitMap::size(frame_map) == 0, "cannot have frame_map for frames with size 0"); | |
103 } | |
104 | |
105 return map; | |
106 } | |
107 | |
108 // TODO: finish this - c1x doesn't provide any scope values at the moment | |
109 static ScopeValue* get_hotspot_value(oop value, int frame_size) { | |
110 if (value == CiValue::IllegalValue()) { | |
111 return new LocationValue(Location::new_stk_loc(Location::invalid, 0)); | |
112 } | |
113 | |
114 BasicType type = C1XCompiler::kindToBasicType(CiKind::typeChar(CiValue::kind(value))); | |
115 Location::Type locationType = Location::normal; | |
116 if (type == T_OBJECT || type == T_ARRAY) locationType = Location::oop; | |
117 if (value->is_a(CiRegisterValue::klass())) { | |
118 jint number = CiRegister::number(CiRegisterValue::reg(value)); | |
119 if (number < 16) { | |
120 return new LocationValue(Location::new_reg_loc(locationType, as_Register(number)->as_VMReg())); | |
121 } else { | |
122 return new LocationValue(Location::new_reg_loc(locationType, as_XMMRegister(number - 16)->as_VMReg())); | |
123 } | |
124 } else if (value->is_a(CiStackSlot::klass())) { | |
125 jint index = CiStackSlot::index(value); | |
126 if (index >= 0) { | |
127 return new LocationValue(Location::new_stk_loc(locationType, index * HeapWordSize)); | |
128 } else { | |
129 int frame_size_bytes = frame_size + 2 * HeapWordSize; | |
130 return new LocationValue(Location::new_stk_loc(locationType, -(index * HeapWordSize) + frame_size_bytes)); | |
131 } | |
132 } else if (value->is_a(CiConstant::klass())){ | |
133 oop obj = CiConstant::object(value); | |
134 jlong prim = CiConstant::primitive(value); | |
135 if (type == T_INT || type == T_FLOAT || type == T_SHORT || type == T_CHAR || type == T_BOOLEAN || type == T_BYTE) { | |
136 return new ConstantIntValue(*(jint*)&prim); | |
137 } else if (type == T_LONG || type == T_DOUBLE) { | |
138 return new ConstantLongValue(prim); | |
139 } else if (type == T_OBJECT) { | |
140 oop obj = CiConstant::object(value); | |
141 if (obj == NULL) { | |
142 return new ConstantOopWriteValue(NULL); | |
143 } else { | |
144 return new ConstantOopWriteValue(JNIHandles::make_global(obj)); | |
145 } | |
146 } else if (type == T_ADDRESS) { | |
147 return new ConstantLongValue(prim); | |
148 } | |
149 tty->print("%i", type); | |
150 } else { | |
151 value->klass()->print(); | |
152 value->print(); | |
153 } | |
154 ShouldNotReachHere(); | |
155 return NULL; | |
156 } | |
157 | |
158 // constructor used to create a method | |
159 CodeInstaller::CodeInstaller(Handle target_method) { | |
160 ciMethod *ciMethodObject = NULL; | |
161 { | |
162 No_Safepoint_Verifier no_safepoint; | |
163 _env = CURRENT_ENV; | |
164 | |
165 initialize_fields(target_method); | |
166 assert(_hotspot_method != NULL && _name == NULL, "installMethod needs NON-NULL method and NULL name"); | |
167 assert(_hotspot_method->is_a(HotSpotMethodResolved::klass()), "installMethod needs a HotSpotMethodResolved"); | |
168 | |
169 methodOop method = VmIds::get<methodOop>(HotSpotMethodResolved::vmId(_hotspot_method)); | |
170 ciMethodObject = (ciMethod *) _env->get_object(method); | |
171 _parameter_count = method->size_of_parameters(); | |
172 } | |
173 | |
174 // (very) conservative estimate: each site needs a relocation | |
175 //CodeBuffer buffer("temp c1x method", _total_size, _sites->length() * relocInfo::length_limit); | |
176 CodeBuffer buffer(CompilerThread::current()->get_buffer_blob()); | |
177 initialize_buffer(buffer); | |
178 process_exception_handlers(); | |
179 | |
180 int stack_slots = (_frame_size / HeapWordSize) + 2; // conversion to words, need to add two slots for ret address and frame pointer | |
181 ThreadToNativeFromVM t((JavaThread*) Thread::current()); | |
182 _env->register_method(ciMethodObject, -1, &_offsets, _custom_stack_area_offset, &buffer, stack_slots, _debug_recorder->_oopmaps, &_exception_handler_table, | |
183 &_implicit_exception_table, C1XCompiler::instance(), _env->comp_level(), false, false); | |
184 | |
185 } | |
186 | |
187 // constructor used to create a stub | |
188 CodeInstaller::CodeInstaller(Handle target_method, jlong& id) { | |
189 No_Safepoint_Verifier no_safepoint; | |
190 _env = CURRENT_ENV; | |
191 | |
192 initialize_fields(target_method); | |
193 assert(_hotspot_method == NULL && _name != NULL, "installMethod needs NON-NULL name and NULL method"); | |
194 | |
195 // (very) conservative estimate: each site needs a relocation | |
196 CodeBuffer buffer(CompilerThread::current()->get_buffer_blob()); | |
197 initialize_buffer(buffer); | |
198 | |
199 const char* cname = java_lang_String::as_utf8_string(_name); | |
200 BufferBlob* blob = BufferBlob::create(strdup(cname), &buffer); // this is leaking strings... but only a limited number of stubs will be created | |
201 IF_TRACE_C1X_3 Disassembler::decode((CodeBlob*) blob); | |
202 id = VmIds::addStub(blob->code_begin()); | |
203 } | |
204 | |
205 void CodeInstaller::initialize_fields(Handle target_method) { | |
206 _citarget_method = HotSpotTargetMethod::targetMethod(target_method); | |
207 _hotspot_method = HotSpotTargetMethod::method(target_method); | |
208 _name = HotSpotTargetMethod::name(target_method); | |
209 _sites = (arrayOop) HotSpotTargetMethod::sites(target_method); | |
210 oop assumptions = CiTargetMethod::assumptions(_citarget_method); | |
211 if (assumptions != NULL) { | |
212 _assumptions = (arrayOop) CiAssumptions::list(assumptions); | |
213 } else { | |
214 _assumptions = NULL; | |
215 } | |
216 _exception_handlers = (arrayOop) HotSpotTargetMethod::exceptionHandlers(target_method); | |
217 | |
218 _code = (arrayOop) CiTargetMethod::targetCode(_citarget_method); | |
219 _code_size = CiTargetMethod::targetCodeSize(_citarget_method); | |
220 _frame_size = CiTargetMethod::frameSize(_citarget_method); | |
221 _custom_stack_area_offset = CiTargetMethod::customStackAreaOffset(_citarget_method); | |
222 | |
223 | |
224 // (very) conservative estimate: each site needs a constant section entry | |
225 _constants_size = _sites->length() * (BytesPerLong*2); | |
226 _total_size = align_size_up(_code_size, HeapWordSize) + _constants_size; | |
227 | |
228 _next_call_type = MARK_INVOKE_INVALID; | |
229 } | |
230 | |
231 // perform data and call relocation on the CodeBuffer | |
232 void CodeInstaller::initialize_buffer(CodeBuffer& buffer) { | |
233 int locs_buffer_size = _sites->length() * (relocInfo::length_limit + sizeof(relocInfo)); | |
234 char* locs_buffer = NEW_RESOURCE_ARRAY(char, locs_buffer_size); | |
235 buffer.insts()->initialize_shared_locs((relocInfo*)locs_buffer, locs_buffer_size / sizeof(relocInfo)); | |
236 buffer.initialize_stubs_size(256); | |
237 buffer.initialize_consts_size(_constants_size); | |
238 | |
239 _oop_recorder = new OopRecorder(_env->arena()); | |
240 _env->set_oop_recorder(_oop_recorder); | |
241 _debug_recorder = new DebugInformationRecorder(_env->oop_recorder()); | |
242 _debug_recorder->set_oopmaps(new OopMapSet()); | |
243 _dependencies = new Dependencies(_env); | |
244 | |
245 _env->set_oop_recorder(_oop_recorder); | |
246 _env->set_debug_info(_debug_recorder); | |
247 _env->set_dependencies(_dependencies); | |
248 buffer.initialize_oop_recorder(_oop_recorder); | |
249 | |
250 _instructions = buffer.insts(); | |
251 _constants = buffer.consts(); | |
252 | |
253 // copy the code into the newly created CodeBuffer | |
254 memcpy(_instructions->start(), _code->base(T_BYTE), _code_size); | |
255 _instructions->set_end(_instructions->start() + _code_size); | |
256 | |
257 oop* sites = (oop*) _sites->base(T_OBJECT); | |
258 for (int i = 0; i < _sites->length(); i++) { | |
259 oop site = sites[i]; | |
260 jint pc_offset = CiTargetMethod_Site::pcOffset(site); | |
261 | |
262 if (site->is_a(CiTargetMethod_Safepoint::klass())) { | |
263 TRACE_C1X_4("safepoint at %i", pc_offset); | |
264 site_Safepoint(buffer, pc_offset, site); | |
265 } else if (site->is_a(CiTargetMethod_Call::klass())) { | |
266 TRACE_C1X_4("call at %i", pc_offset); | |
267 site_Call(buffer, pc_offset, site); | |
268 } else if (site->is_a(CiTargetMethod_DataPatch::klass())) { | |
269 TRACE_C1X_4("datapatch at %i", pc_offset); | |
270 site_DataPatch(buffer, pc_offset, site); | |
271 } else if (site->is_a(CiTargetMethod_Mark::klass())) { | |
272 TRACE_C1X_4("mark at %i", pc_offset); | |
273 site_Mark(buffer, pc_offset, site); | |
274 } else { | |
275 fatal("unexpected Site subclass"); | |
276 } | |
277 } | |
278 | |
279 | |
280 if (_assumptions != NULL) { | |
281 oop* assumptions = (oop*) _assumptions->base(T_OBJECT); | |
282 for (int i = 0; i < _assumptions->length(); ++i) { | |
283 oop assumption = assumptions[i]; | |
284 if (assumption != NULL) { | |
285 if (assumption->is_a(CiAssumptions_ConcreteSubtype::klass())) { | |
286 assumption_ConcreteSubtype(assumption); | |
287 } else if (assumption->is_a(CiAssumptions_ConcreteMethod::klass())) { | |
288 assumption_ConcreteMethod(assumption); | |
289 } else { | |
290 fatal("unexpected Assumption subclass"); | |
291 } | |
292 } | |
293 } | |
294 } | |
295 } | |
296 | |
297 void CodeInstaller::assumption_ConcreteSubtype(oop assumption) { | |
298 oop context_oop = CiAssumptions_ConcreteSubtype::context(assumption); | |
299 oop type_oop = CiAssumptions_ConcreteSubtype::subtype(assumption); | |
300 | |
301 ciKlass* context = (ciKlass*) CURRENT_ENV->get_object(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(context_oop))); | |
302 ciKlass* type = (ciKlass*) CURRENT_ENV->get_object(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(type_oop))); | |
303 | |
304 _dependencies->assert_leaf_type(type); | |
305 if (context != type) { | |
306 assert(context->is_abstract(), ""); | |
307 ThreadToNativeFromVM trans(JavaThread::current()); | |
308 _dependencies->assert_abstract_with_unique_concrete_subtype(context, type); | |
309 } | |
310 } | |
311 | |
312 void CodeInstaller::assumption_ConcreteMethod(oop assumption) { | |
313 oop context_oop = CiAssumptions_ConcreteMethod::context(assumption); | |
314 oop method_oop = CiAssumptions_ConcreteMethod::method(assumption); | |
315 jlong context_oop_id = HotSpotMethodResolved::vmId(context_oop); | |
316 jlong method_oop_id = HotSpotMethodResolved::vmId(method_oop); | |
317 methodOop method = VmIds::get<methodOop>(method_oop_id); | |
318 methodOop context = VmIds::get<methodOop>(context_oop_id); | |
319 | |
320 ciMethod* m = (ciMethod*) CURRENT_ENV->get_object(method); | |
321 ciMethod* c = (ciMethod*) CURRENT_ENV->get_object(context); | |
322 ciKlass* context_klass = c->holder(); | |
323 { | |
324 ThreadToNativeFromVM trans(JavaThread::current()); | |
325 _dependencies->assert_unique_concrete_method(context_klass, m); | |
326 } | |
327 } | |
328 | |
329 void CodeInstaller::process_exception_handlers() { | |
330 // allocate some arrays for use by the collection code. | |
331 const int num_handlers = 5; | |
332 GrowableArray<intptr_t>* bcis = new GrowableArray<intptr_t> (num_handlers); | |
333 GrowableArray<intptr_t>* scope_depths = new GrowableArray<intptr_t> (num_handlers); | |
334 GrowableArray<intptr_t>* pcos = new GrowableArray<intptr_t> (num_handlers); | |
335 | |
336 if (_exception_handlers != NULL) { | |
337 oop* exception_handlers = (oop*) _exception_handlers->base(T_OBJECT); | |
338 for (int i = 0; i < _exception_handlers->length(); i++) { | |
339 jint pc_offset = CiTargetMethod_Site::pcOffset(exception_handlers[i]); | |
340 int start = i; | |
341 while ((i + 1) < _exception_handlers->length() && CiTargetMethod_Site::pcOffset(exception_handlers[i + 1]) == pc_offset) | |
342 i++; | |
343 | |
344 // empty the arrays | |
345 bcis->trunc_to(0); | |
346 scope_depths->trunc_to(0); | |
347 pcos->trunc_to(0); | |
348 | |
349 for (int j = start; j <= i; j++) { | |
350 oop exc = exception_handlers[j]; | |
351 jint handler_offset = CiTargetMethod_ExceptionHandler::handlerPos(exc); | |
352 jint handler_bci = CiTargetMethod_ExceptionHandler::handlerBci(exc); | |
353 jint bci = CiTargetMethod_ExceptionHandler::bci(exc); | |
354 jint scope_level = CiTargetMethod_ExceptionHandler::scopeLevel(exc); | |
355 Handle handler_type = CiTargetMethod_ExceptionHandler::exceptionType(exc); | |
356 | |
357 assert(handler_offset != -1, "must have been generated"); | |
358 | |
359 int e = bcis->find(handler_bci); | |
360 if (e >= 0 && scope_depths->at(e) == scope_level) { | |
361 // two different handlers are declared to dispatch to the same | |
362 // catch bci. During parsing we created edges for each | |
363 // handler but we really only need one. The exception handler | |
364 // table will also get unhappy if we try to declare both since | |
365 // it's nonsensical. Just skip this handler. | |
366 continue; | |
367 } | |
368 | |
369 bcis->append(handler_bci); | |
370 if (handler_bci == -1) { | |
371 // insert a wildcard handler at scope depth 0 so that the | |
372 // exception lookup logic with find it. | |
373 scope_depths->append(0); | |
374 } else { | |
375 scope_depths->append(scope_level); | |
376 } | |
377 pcos->append(handler_offset); | |
378 | |
379 // stop processing once we hit a catch any | |
380 // if (handler->is_catch_all()) { | |
381 // assert(i == handlers->length() - 1, "catch all must be last handler"); | |
382 // } | |
383 | |
384 } | |
385 _exception_handler_table.add_subtable(pc_offset, bcis, scope_depths, pcos); | |
386 } | |
387 } | |
388 | |
389 } | |
390 | |
391 void CodeInstaller::record_scope(jint pc_offset, oop code_pos) { | |
392 oop caller_pos = CiCodePos::caller(code_pos); | |
393 if (caller_pos != NULL) { | |
394 record_scope(pc_offset, caller_pos); | |
395 } | |
396 oop frame = NULL; | |
397 if (code_pos->klass()->klass_part()->name() == vmSymbols::com_sun_cri_ci_CiFrame()) { | |
398 frame = code_pos; | |
399 } | |
400 | |
401 oop hotspot_method = CiCodePos::method(code_pos); | |
402 assert(hotspot_method != NULL && hotspot_method->is_a(HotSpotMethodResolved::klass()), "unexpected hotspot method"); | |
403 methodOop method = VmIds::get<methodOop>(HotSpotMethodResolved::vmId(hotspot_method)); | |
404 ciMethod *cimethod = (ciMethod *) _env->get_object(method); | |
405 jint bci = CiCodePos::bci(code_pos); | |
406 bool reexecute; | |
407 if (bci == -1) { | |
408 reexecute = false; | |
409 } else { | |
410 Bytecodes::Code code = Bytecodes::java_code_at(method, method->bcp_from(bci)); | |
411 reexecute = Interpreter::bytecode_should_reexecute(code); | |
412 } | |
413 | |
414 if (TraceC1X >= 2) { | |
415 tty->print_cr("Recording scope pc_offset=%d bci=%d frame=%d", pc_offset, bci, frame); | |
416 } | |
417 | |
418 if (frame != NULL) { | |
419 jint local_count = CiFrame::numLocals(frame); | |
420 jint expression_count = CiFrame::numStack(frame); | |
421 jint monitor_count = CiFrame::numLocks(frame); | |
422 arrayOop values = (arrayOop) CiFrame::values(frame); | |
423 | |
424 assert(local_count + expression_count + monitor_count == values->length(), "unexpected values length"); | |
425 | |
426 GrowableArray<ScopeValue*>* locals = new GrowableArray<ScopeValue*> (); | |
427 GrowableArray<ScopeValue*>* expressions = new GrowableArray<ScopeValue*> (); | |
428 GrowableArray<MonitorValue*>* monitors = new GrowableArray<MonitorValue*> (); | |
429 | |
430 if (TraceC1X >= 2) { | |
431 tty->print_cr("Scope at bci %d with %d values", bci, values->length()); | |
432 tty->print_cr("%d locals %d expressions, %d monitors", local_count, expression_count, monitor_count); | |
433 } | |
434 | |
435 for (jint i = 0; i < values->length(); i++) { | |
436 ScopeValue* value = get_hotspot_value(((oop*) values->base(T_OBJECT))[i], _frame_size); | |
437 | |
438 if (i < local_count) { | |
439 locals->append(value); | |
440 } else if (i < local_count + expression_count) { | |
441 expressions->append(value); | |
442 } else { | |
443 assert(value->is_location(), "invalid monitor location"); | |
444 LocationValue* loc = (LocationValue*)value; | |
445 int monitor_offset = loc->location().stack_offset(); | |
446 LocationValue* obj = new LocationValue(Location::new_stk_loc(Location::oop, monitor_offset + BasicObjectLock::obj_offset_in_bytes())); | |
447 monitors->append(new MonitorValue(obj, Location::new_stk_loc(Location::normal, monitor_offset + BasicObjectLock::lock_offset_in_bytes()))); | |
448 } | |
449 } | |
450 DebugToken* locals_token = _debug_recorder->create_scope_values(locals); | |
451 DebugToken* expressions_token = _debug_recorder->create_scope_values(expressions); | |
452 DebugToken* monitors_token = _debug_recorder->create_monitor_values(monitors); | |
453 | |
454 _debug_recorder->describe_scope(pc_offset, cimethod, bci, reexecute, false, false, locals_token, expressions_token, monitors_token); | |
455 } else { | |
456 _debug_recorder->describe_scope(pc_offset, cimethod, bci, reexecute, false, false, NULL, NULL, NULL); | |
457 } | |
458 } | |
459 | |
460 void CodeInstaller::site_Safepoint(CodeBuffer& buffer, jint pc_offset, oop site) { | |
461 oop debug_info = CiTargetMethod_Safepoint::debugInfo(site); | |
462 assert(debug_info != NULL, "debug info expected"); | |
463 | |
464 // address instruction = _instructions->start() + pc_offset; | |
465 // jint next_pc_offset = Assembler::locate_next_instruction(instruction) - _instructions->start(); | |
466 _debug_recorder->add_safepoint(pc_offset, create_oop_map(_frame_size, _parameter_count, debug_info)); | |
467 | |
468 oop code_pos = CiDebugInfo::codePos(debug_info); | |
469 record_scope(pc_offset, code_pos); | |
470 | |
471 _debug_recorder->end_safepoint(pc_offset); | |
472 } | |
473 | |
474 void CodeInstaller::site_Call(CodeBuffer& buffer, jint pc_offset, oop site) { | |
475 oop runtime_call = CiTargetMethod_Call::runtimeCall(site); | |
476 oop hotspot_method = CiTargetMethod_Call::method(site); | |
477 oop symbol = CiTargetMethod_Call::symbol(site); | |
478 oop global_stub = CiTargetMethod_Call::globalStubID(site); | |
479 | |
480 oop debug_info = CiTargetMethod_Call::debugInfo(site); | |
481 | |
482 assert((runtime_call ? 1 : 0) + (hotspot_method ? 1 : 0) + (symbol ? 1 : 0) + (global_stub ? 1 : 0) == 1, "Call site needs exactly one type"); | |
483 | |
484 assert(NativeCall::instruction_size == (int)NativeJump::instruction_size, "unexpected size)"); | |
485 jint next_pc_offset = pc_offset + NativeCall::instruction_size; | |
486 | |
487 if (debug_info != NULL) { | |
488 _debug_recorder->add_safepoint(next_pc_offset, create_oop_map(_frame_size, _parameter_count, debug_info)); | |
489 oop code_pos = CiDebugInfo::codePos(debug_info); | |
490 record_scope(next_pc_offset, code_pos); | |
491 } | |
492 | |
493 if (runtime_call != NULL) { | |
494 NativeCall* call = nativeCall_at(_instructions->start() + pc_offset); | |
495 if (runtime_call == CiRuntimeCall::Debug()) { | |
496 TRACE_C1X_3("CiRuntimeCall::Debug()"); | |
497 } else if (runtime_call == CiRuntimeCall::UnwindException()) { | |
498 call->set_destination(Runtime1::entry_for(Runtime1::c1x_unwind_exception_call_id)); | |
499 _instructions->relocate(call->instruction_address(), runtime_call_Relocation::spec(), Assembler::call32_operand); | |
500 TRACE_C1X_3("CiRuntimeCall::UnwindException()"); | |
501 } else if (runtime_call == CiRuntimeCall::HandleException()) { | |
502 call->set_destination(Runtime1::entry_for(Runtime1::c1x_handle_exception_id)); | |
503 _instructions->relocate(call->instruction_address(), runtime_call_Relocation::spec(), Assembler::call32_operand); | |
504 TRACE_C1X_3("CiRuntimeCall::HandleException()"); | |
505 } else if (runtime_call == CiRuntimeCall::JavaTimeMillis()) { | |
506 call->set_destination((address)os::javaTimeMillis); | |
507 _instructions->relocate(call->instruction_address(), runtime_call_Relocation::spec(), Assembler::call32_operand); | |
508 TRACE_C1X_3("CiRuntimeCall::JavaTimeMillis()"); | |
509 } else if (runtime_call == CiRuntimeCall::JavaTimeNanos()) { | |
510 call->set_destination((address)os::javaTimeNanos); | |
511 _instructions->relocate(call->instruction_address(), runtime_call_Relocation::spec(), Assembler::call32_operand); | |
512 TRACE_C1X_3("CiRuntimeCall::JavaTimeNanos()"); | |
513 } else if (runtime_call == CiRuntimeCall::ArithmeticFrem()) { | |
514 call->set_destination(Runtime1::entry_for(Runtime1::c1x_arithmetic_frem_id)); | |
515 _instructions->relocate(call->instruction_address(), runtime_call_Relocation::spec(), Assembler::call32_operand); | |
516 TRACE_C1X_3("CiRuntimeCall::ArithmeticFrem()"); | |
517 } else if (runtime_call == CiRuntimeCall::ArithmeticDrem()) { | |
518 call->set_destination(Runtime1::entry_for(Runtime1::c1x_arithmetic_drem_id)); | |
519 _instructions->relocate(call->instruction_address(), runtime_call_Relocation::spec(), Assembler::call32_operand); | |
520 TRACE_C1X_3("CiRuntimeCall::ArithmeticDrem()"); | |
521 } else if (runtime_call == CiRuntimeCall::RegisterFinalizer()) { | |
522 call->set_destination(Runtime1::entry_for(Runtime1::register_finalizer_id)); | |
523 _instructions->relocate(call->instruction_address(), runtime_call_Relocation::spec(), Assembler::call32_operand); | |
524 } else if (runtime_call == CiRuntimeCall::Deoptimize()) { | |
525 call->set_destination(SharedRuntime::deopt_blob()->uncommon_trap()); | |
526 _instructions->relocate(call->instruction_address(), runtime_call_Relocation::spec(), Assembler::call32_operand); | |
527 } else { | |
528 runtime_call->print(); | |
529 fatal("runtime_call not implemented"); | |
530 } | |
531 } else if (global_stub != NULL) { | |
532 NativeInstruction* inst = nativeInstruction_at(_instructions->start() + pc_offset); | |
533 assert(java_lang_boxing_object::is_instance(global_stub, T_LONG), "global_stub needs to be of type Long"); | |
534 | |
535 if (inst->is_call()) { | |
536 nativeCall_at((address)inst)->set_destination(VmIds::getStub(global_stub)); | |
537 } else { | |
538 nativeJump_at((address)inst)->set_jump_destination(VmIds::getStub(global_stub)); | |
539 } | |
540 _instructions->relocate((address)inst, runtime_call_Relocation::spec(), Assembler::call32_operand); | |
541 TRACE_C1X_3("relocating (stub) at %016x", inst); | |
542 } else if (symbol != NULL) { | |
543 fatal("symbol"); | |
544 } else { // method != NULL | |
545 NativeCall* call = nativeCall_at(_instructions->start() + pc_offset); | |
546 assert(hotspot_method != NULL, "unexpected RiMethod"); | |
547 assert(debug_info != NULL, "debug info expected"); | |
548 | |
549 methodOop method = NULL; | |
550 if (hotspot_method->is_a(HotSpotMethodResolved::klass())) method = VmIds::get<methodOop>(HotSpotMethodResolved::vmId(hotspot_method)); | |
551 | |
552 assert(debug_info != NULL, "debug info expected"); | |
553 | |
554 TRACE_C1X_3("method call"); | |
555 switch (_next_call_type) { | |
556 case MARK_INVOKEVIRTUAL: | |
557 case MARK_INVOKEINTERFACE: { | |
558 assert(method == NULL || !method->is_static(), "cannot call static method with invokeinterface"); | |
559 | |
560 call->set_destination(SharedRuntime::get_resolve_virtual_call_stub()); | |
561 _instructions->relocate(call->instruction_address(), virtual_call_Relocation::spec(_invoke_mark_pc), Assembler::call32_operand); | |
562 break; | |
563 } | |
564 case MARK_INVOKESTATIC: { | |
565 assert(method == NULL || method->is_static(), "cannot call non-static method with invokestatic"); | |
566 call->set_destination(SharedRuntime::get_resolve_static_call_stub()); | |
567 _instructions->relocate(call->instruction_address(), relocInfo::static_call_type, Assembler::call32_operand); | |
568 break; | |
569 } | |
570 case MARK_INVOKESPECIAL: { | |
571 assert(method == NULL || !method->is_static(), "cannot call static method with invokespecial"); | |
572 | |
573 call->set_destination(SharedRuntime::get_resolve_opt_virtual_call_stub()); | |
574 _instructions->relocate(call->instruction_address(), relocInfo::opt_virtual_call_type, Assembler::call32_operand); | |
575 break; | |
576 } | |
577 case MARK_INVOKE_INVALID: | |
578 default: | |
579 fatal("invalid _next_call_type value"); | |
580 break; | |
581 } | |
582 } | |
583 _next_call_type = MARK_INVOKE_INVALID; | |
584 if (debug_info != NULL) { | |
585 _debug_recorder->end_safepoint(next_pc_offset); | |
586 } | |
587 } | |
588 | |
589 void CodeInstaller::site_DataPatch(CodeBuffer& buffer, jint pc_offset, oop site) { | |
590 oop constant = CiTargetMethod_DataPatch::constant(site); | |
591 oop kind = CiConstant::kind(constant); | |
592 | |
593 address instruction = _instructions->start() + pc_offset; | |
594 | |
595 char typeChar = CiKind::typeChar(kind); | |
596 switch (typeChar) { | |
597 case 'z': | |
598 case 'b': | |
599 case 's': | |
600 case 'c': | |
601 case 'i': | |
602 fatal("int-sized values not expected in DataPatch") | |
603 ; | |
604 break; | |
605 case 'f': | |
606 case 'l': | |
607 case 'd': { | |
608 address operand = Assembler::locate_operand(instruction, Assembler::disp32_operand); | |
609 address next_instruction = Assembler::locate_next_instruction(instruction); | |
610 // we don't care if this is a long/double/etc., the primitive field contains the right bits | |
611 int size = _constants->size(); | |
612 if (typeChar == 'd' || typeChar == 'l') { | |
613 size = _constants->align_at_start(size); | |
614 } | |
615 address dest = _constants->start() + size; | |
616 _constants->set_end(dest + BytesPerLong); | |
617 *(jlong*) dest = CiConstant::primitive(constant); | |
618 | |
619 long disp = dest - next_instruction; | |
620 assert(disp == (jint) disp, "disp doesn't fit in 32 bits"); | |
621 *((jint*) operand) = (jint) disp; | |
622 | |
623 _instructions->relocate(instruction, section_word_Relocation::spec((address) dest, CodeBuffer::SECT_CONSTS), Assembler::disp32_operand); | |
624 TRACE_C1X_3("relocating (%c) at %016x/%016x with destination at %016x (%d)", typeChar, instruction, operand, dest, size); | |
625 break; | |
626 } | |
627 case 'a': { | |
628 address operand = Assembler::locate_operand(instruction, Assembler::imm_operand); | |
629 Handle obj = CiConstant::object(constant); | |
630 | |
631 if (obj->is_a(HotSpotTypeResolved::klass())) { | |
632 assert(!obj.is_null(), ""); | |
633 *((jobject*) operand) = JNIHandles::make_local(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(obj))); | |
634 _instructions->relocate(instruction, oop_Relocation::spec_for_immediate(), Assembler::imm_operand); | |
635 TRACE_C1X_3("relocating (HotSpotType) at %016x/%016x", instruction, operand); | |
636 } else { | |
637 jobject value; | |
638 if (obj() == HotSpotProxy::DUMMY_CONSTANT_OBJ()) { | |
639 value = (jobject) Universe::non_oop_word(); | |
640 } else { | |
641 value = JNIHandles::make_local(obj()); | |
642 } | |
643 *((jobject*) operand) = value; | |
644 _instructions->relocate(instruction, oop_Relocation::spec_for_immediate(), Assembler::imm_operand); | |
645 TRACE_C1X_3("relocating (oop constant) at %016x/%016x", instruction, operand); | |
646 } | |
647 break; | |
648 } | |
649 default: | |
650 fatal("unexpected CiKind in DataPatch"); | |
651 break; | |
652 } | |
653 } | |
654 | |
655 void CodeInstaller::site_Mark(CodeBuffer& buffer, jint pc_offset, oop site) { | |
656 oop id_obj = CiTargetMethod_Mark::id(site); | |
657 arrayOop references = (arrayOop) CiTargetMethod_Mark::references(site); | |
658 | |
659 if (id_obj != NULL) { | |
660 assert(java_lang_boxing_object::is_instance(id_obj, T_INT), "Integer id expected"); | |
661 jint id = id_obj->int_field(java_lang_boxing_object::value_offset_in_bytes(T_INT)); | |
662 | |
663 address instruction = _instructions->start() + pc_offset; | |
664 | |
665 switch (id) { | |
666 case MARK_UNVERIFIED_ENTRY: | |
667 _offsets.set_value(CodeOffsets::Entry, pc_offset); | |
668 break; | |
669 case MARK_VERIFIED_ENTRY: | |
670 _offsets.set_value(CodeOffsets::Verified_Entry, pc_offset); | |
671 break; | |
672 case MARK_OSR_ENTRY: | |
673 _offsets.set_value(CodeOffsets::OSR_Entry, pc_offset); | |
674 break; | |
675 case MARK_UNWIND_ENTRY: | |
676 _offsets.set_value(CodeOffsets::UnwindHandler, pc_offset); | |
677 break; | |
678 case MARK_EXCEPTION_HANDLER_ENTRY: | |
679 _offsets.set_value(CodeOffsets::Exceptions, pc_offset); | |
680 break; | |
681 case MARK_DEOPT_HANDLER_ENTRY: | |
682 _offsets.set_value(CodeOffsets::Deopt, pc_offset); | |
683 break; | |
684 case MARK_STATIC_CALL_STUB: { | |
685 assert(references->length() == 1, "static call stub needs one reference"); | |
686 oop ref = ((oop*) references->base(T_OBJECT))[0]; | |
687 address call_pc = _instructions->start() + CiTargetMethod_Site::pcOffset(ref); | |
688 _instructions->relocate(instruction, static_stub_Relocation::spec(call_pc)); | |
689 _instructions->relocate(instruction, oop_Relocation::spec_for_immediate(), Assembler::imm_operand); | |
690 break; | |
691 } | |
692 case MARK_INVOKE_INVALID: | |
693 case MARK_INVOKEINTERFACE: | |
694 case MARK_INVOKESTATIC: | |
695 case MARK_INVOKESPECIAL: | |
696 case MARK_INVOKEVIRTUAL: | |
697 _next_call_type = (MarkId) id; | |
698 _invoke_mark_pc = instruction; | |
699 break; | |
700 case MARK_IMPLICIT_NULL: | |
701 _implicit_exception_table.append(pc_offset, pc_offset); | |
702 break; | |
703 case MARK_KLASS_PATCHING: | |
704 case MARK_ACCESS_FIELD_PATCHING: { | |
705 unsigned char* byte_count = (unsigned char*) (instruction - 1); | |
706 unsigned char* byte_skip = (unsigned char*) (instruction - 2); | |
707 unsigned char* being_initialized_entry_offset = (unsigned char*) (instruction - 3); | |
708 | |
709 assert(*byte_skip == 5, "unexpected byte_skip"); | |
710 | |
711 assert(references->length() == 2, "MARK_KLASS_PATCHING/MARK_ACCESS_FIELD_PATCHING needs 2 references"); | |
712 oop ref1 = ((oop*) references->base(T_OBJECT))[0]; | |
713 oop ref2 = ((oop*) references->base(T_OBJECT))[1]; | |
714 int i_byte_count = CiTargetMethod_Site::pcOffset(ref2) - CiTargetMethod_Site::pcOffset(ref1); | |
715 assert(i_byte_count == (unsigned char)i_byte_count, "invalid offset"); | |
716 *byte_count = i_byte_count; | |
717 *being_initialized_entry_offset = *byte_count + *byte_skip; | |
718 | |
719 // we need to correct the offset of a field access - it's created with MAX_INT to ensure the correct size, and hotspot expects 0 | |
720 if (id == MARK_ACCESS_FIELD_PATCHING) { | |
721 NativeMovRegMem* inst = nativeMovRegMem_at(_instructions->start() + CiTargetMethod_Site::pcOffset(ref1)); | |
722 assert(inst->offset() == max_jint, "unexpected offset value"); | |
723 inst->set_offset(0); | |
724 } | |
725 break; | |
726 } | |
727 case MARK_DUMMY_OOP_RELOCATION: { | |
728 _instructions->relocate(instruction, oop_Relocation::spec_for_immediate(), Assembler::imm_operand); | |
729 | |
730 RelocIterator iter(_instructions, (address) instruction, (address) (instruction + 1)); | |
731 relocInfo::change_reloc_info_for_address(&iter, (address) instruction, relocInfo::oop_type, relocInfo::none); | |
732 break; | |
733 } | |
734 default: | |
735 ShouldNotReachHere(); | |
736 break; | |
737 } | |
738 } | |
739 } | |
740 |