Mercurial > hg > truffle
comparison src/share/vm/graal/graalCodeInstaller.cpp @ 9338:0266549ff6e0
added support from compiled stubs to be installed as RuntimeStubs and to be able to directly call C/C++ runtime functions (GRAAL-81)
replaced NewArraySlowStubCall with NewArrayRuntimeCall using this support
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Fri, 26 Apr 2013 18:36:41 +0200 |
parents | 123991e4fbd8 |
children | 44e05c9afb54 |
comparison
equal
deleted
inserted
replaced
9337:e1200d5141fa | 9338:0266549ff6e0 |
---|---|
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 const int MapWordBits = 64; | 69 const int MapWordBits = 64; |
70 | 70 |
71 static bool is_bit_set(oop bit_map, int i) { | 71 static bool is_bit_set(oop bitset, int i) { |
72 jint extra_idx = i / MapWordBits; | 72 jint words_idx = i / MapWordBits; |
73 arrayOop extra = (arrayOop) GraalBitMap::words(bit_map); | 73 arrayOop words = (arrayOop) BitSet::words(bitset); |
74 assert(extra_idx >= 0 && extra_idx < extra->length(), "unexpected index"); | 74 assert(words_idx >= 0 && words_idx < words->length(), "unexpected index"); |
75 jlong word = ((jlong*) extra->base(T_LONG))[extra_idx]; | 75 jlong word = ((jlong*) words->base(T_LONG))[words_idx]; |
76 return (word & (1LL << (i % MapWordBits))) != 0; | 76 return (word & (1LL << (i % MapWordBits))) != 0; |
77 } | 77 } |
78 | 78 |
79 static int bitmap_size(oop bit_map) { | 79 static int bitset_size(oop bitset) { |
80 arrayOop arr = (arrayOop) GraalBitMap::words(bit_map); | 80 arrayOop arr = (arrayOop) BitSet::words(bitset); |
81 return arr->length() * MapWordBits; | 81 return arr->length() * MapWordBits; |
82 } | 82 } |
83 | |
84 #ifdef _LP64 | |
85 #define SLOTS_PER_WORD 2 | |
86 #else | |
87 #define SLOTS_PER_WORD 1 | |
88 #endif // _LP64 | |
83 | 89 |
84 // creates a HotSpot oop map out of the byte arrays provided by DebugInfo | 90 // creates a HotSpot oop map out of the byte arrays provided by DebugInfo |
85 static OopMap* create_oop_map(jint total_frame_size, jint parameter_count, oop debug_info) { | 91 static OopMap* create_oop_map(jint total_frame_size, jint parameter_count, oop debug_info) { |
86 OopMap* map = new OopMap(total_frame_size, parameter_count); | 92 OopMap* map = new OopMap(total_frame_size, parameter_count); |
87 oop register_map = (oop) DebugInfo::registerRefMap(debug_info); | 93 oop register_map = (oop) DebugInfo::registerRefMap(debug_info); |
88 oop frame_map = (oop) DebugInfo::frameRefMap(debug_info); | 94 oop frame_map = (oop) DebugInfo::frameRefMap(debug_info); |
95 oop callee_save_info = (oop) DebugInfo::calleeSaveInfo(debug_info); | |
89 | 96 |
90 if (register_map != NULL) { | 97 if (register_map != NULL) { |
91 for (jint i = 0; i < RegisterImpl::number_of_registers; i++) { | 98 for (jint i = 0; i < RegisterImpl::number_of_registers; i++) { |
92 bool is_oop = is_bit_set(register_map, i); | 99 bool is_oop = is_bit_set(register_map, i); |
93 VMReg reg = get_hotspot_reg(i); | 100 VMReg hotspot_reg = get_hotspot_reg(i); |
94 if (is_oop) { | 101 if (is_oop) { |
95 map->set_oop(reg); | 102 map->set_oop(hotspot_reg); |
96 } else { | 103 } else { |
97 map->set_value(reg); | 104 map->set_value(hotspot_reg); |
98 } | 105 } |
99 } | 106 } |
100 } | 107 } |
101 | 108 |
102 for (jint i = 0; i < bitmap_size(frame_map); i++) { | 109 for (jint i = 0; i < bitset_size(frame_map); i++) { |
103 bool is_oop = is_bit_set(frame_map, i); | 110 bool is_oop = is_bit_set(frame_map, i); |
104 // HotSpot stack slots are 4 bytes | 111 // HotSpot stack slots are 4 bytes |
105 VMReg reg = VMRegImpl::stack2reg(i * 2); | 112 VMReg reg = VMRegImpl::stack2reg(i * SLOTS_PER_WORD); |
106 if (is_oop) { | 113 if (is_oop) { |
107 map->set_oop(reg); | 114 map->set_oop(reg); |
108 } else { | 115 } else { |
109 map->set_value(reg); | 116 map->set_value(reg); |
117 } | |
118 } | |
119 | |
120 if (callee_save_info != NULL) { | |
121 objArrayOop registers = (objArrayOop) RegisterSaveLayout::registers(callee_save_info); | |
122 arrayOop slots = (arrayOop) RegisterSaveLayout::slots(callee_save_info); | |
123 for (jint i = 0; i < slots->length(); i++) { | |
124 oop graal_reg = registers->obj_at(i); | |
125 jint graal_reg_number = code_Register::number(graal_reg); | |
126 VMReg hotspot_reg = get_hotspot_reg(graal_reg_number); | |
127 // HotSpot stack slots are 4 bytes | |
128 jint graal_slot = ((jint*) slots->base(T_INT))[i]; | |
129 jint hotspot_slot = graal_slot * SLOTS_PER_WORD; | |
130 VMReg hotspot_slot_as_reg = VMRegImpl::stack2reg(hotspot_slot); | |
131 map->set_callee_saved(hotspot_slot_as_reg, hotspot_reg); | |
132 #ifdef _LP64 | |
133 // (copied from generate_oop_map() in c1_Runtime1_x86.cpp) | |
134 VMReg hotspot_slot_hi_as_reg = VMRegImpl::stack2reg(hotspot_slot + 1); | |
135 map->set_callee_saved(hotspot_slot_hi_as_reg, hotspot_reg->next()); | |
136 #endif | |
110 } | 137 } |
111 } | 138 } |
112 | 139 |
113 return map; | 140 return map; |
114 } | 141 } |
328 | 355 |
329 return result; | 356 return result; |
330 } | 357 } |
331 | 358 |
332 // constructor used to create a method | 359 // constructor used to create a method |
333 CodeInstaller::CodeInstaller(Handle& comp_result, methodHandle method, GraalEnv::CodeInstallResult& result, nmethod*& nm, Handle installed_code, Handle triggered_deoptimizations) { | 360 CodeInstaller::CodeInstaller(Handle& comp_result, methodHandle method, GraalEnv::CodeInstallResult& result, CodeBlob*& cb, Handle installed_code, Handle triggered_deoptimizations) { |
334 GraalCompiler::initialize_buffer_blob(); | 361 GraalCompiler::initialize_buffer_blob(); |
335 CodeBuffer buffer(JavaThread::current()->get_buffer_blob()); | 362 CodeBuffer buffer(JavaThread::current()->get_buffer_blob()); |
336 jobject comp_result_obj = JNIHandles::make_local(comp_result()); | 363 jobject comp_result_obj = JNIHandles::make_local(comp_result()); |
337 jint entry_bci = HotSpotCompilationResult::entryBCI(comp_result); | 364 jint entry_bci = HotSpotCompilationResult::entryBCI(comp_result); |
338 initialize_assumptions(JNIHandles::resolve(comp_result_obj)); | 365 initialize_assumptions(JNIHandles::resolve(comp_result_obj)); |
345 } | 372 } |
346 | 373 |
347 int stack_slots = _total_frame_size / HeapWordSize; // conversion to words | 374 int stack_slots = _total_frame_size / HeapWordSize; // conversion to words |
348 GrowableArray<jlong>* leaf_graph_ids = get_leaf_graph_ids(comp_result); | 375 GrowableArray<jlong>* leaf_graph_ids = get_leaf_graph_ids(comp_result); |
349 | 376 |
350 result = GraalEnv::register_method(method, nm, entry_bci, &_offsets, _custom_stack_area_offset, &buffer, stack_slots, _debug_recorder->_oopmaps, &_exception_handler_table, | 377 if (_stubName != NULL) { |
351 GraalCompiler::instance(), _debug_recorder, _dependencies, NULL, -1, false, leaf_graph_ids, installed_code, triggered_deoptimizations); | 378 char* name = strdup(java_lang_String::as_utf8_string(_stubName)); |
379 cb = RuntimeStub::new_runtime_stub(name, | |
380 &buffer, | |
381 CodeOffsets::frame_never_safe, | |
382 stack_slots, | |
383 _debug_recorder->_oopmaps, | |
384 false); | |
385 result = GraalEnv::ok; | |
386 } else { | |
387 nmethod* nm = NULL; | |
388 result = GraalEnv::register_method(method, nm, entry_bci, &_offsets, _custom_stack_area_offset, &buffer, stack_slots, _debug_recorder->_oopmaps, &_exception_handler_table, | |
389 GraalCompiler::instance(), _debug_recorder, _dependencies, NULL, -1, false, leaf_graph_ids, installed_code, triggered_deoptimizations); | |
390 cb = nm; | |
391 } | |
352 } | 392 } |
353 | 393 |
354 void CodeInstaller::initialize_fields(oop comp_result, methodHandle method) { | 394 void CodeInstaller::initialize_fields(oop comp_result, methodHandle method) { |
355 _comp_result = HotSpotCompilationResult::comp(comp_result); | 395 _comp_result = HotSpotCompilationResult::comp(comp_result); |
356 if (!method.is_null()) { | 396 if (!method.is_null()) { |
357 _parameter_count = method->size_of_parameters(); | 397 _parameter_count = method->size_of_parameters(); |
358 TRACE_graal_1("installing code for %s", method->name_and_sig_as_C_string()); | 398 TRACE_graal_1("installing code for %s", method->name_and_sig_as_C_string()); |
359 } | 399 } |
360 _name = HotSpotCompilationResult::name(comp_result); | 400 _stubName = HotSpotCompilationResult::stubName(comp_result); |
361 _sites = (arrayOop) HotSpotCompilationResult::sites(comp_result); | 401 _sites = (arrayOop) HotSpotCompilationResult::sites(comp_result); |
362 _exception_handlers = (arrayOop) HotSpotCompilationResult::exceptionHandlers(comp_result); | 402 _exception_handlers = (arrayOop) HotSpotCompilationResult::exceptionHandlers(comp_result); |
363 | 403 |
364 _code = (arrayOop) CompilationResult::targetCode(_comp_result); | 404 _code = (arrayOop) CompilationResult::targetCode(_comp_result); |
365 _code_size = CompilationResult::targetCodeSize(_comp_result); | 405 _code_size = CompilationResult::targetCodeSize(_comp_result); |
638 } | 678 } |
639 | 679 |
640 if (target->is_a(SystemDictionary::HotSpotInstalledCode_klass())) { | 680 if (target->is_a(SystemDictionary::HotSpotInstalledCode_klass())) { |
641 assert(inst->is_jump(), "jump expected"); | 681 assert(inst->is_jump(), "jump expected"); |
642 | 682 |
643 nmethod* nm = (nmethod*) HotSpotInstalledCode::nmethod(target); | 683 CodeBlob* cb = (CodeBlob*) (address) HotSpotInstalledCode::codeBlob(target); |
644 nativeJump_at((address)inst)->set_jump_destination(nm->verified_entry_point()); | 684 assert(cb != NULL, "npe"); |
685 if (cb->is_nmethod()) { | |
686 nmethod* nm = (nmethod*) cb; | |
687 nativeJump_at((address)inst)->set_jump_destination(nm->verified_entry_point()); | |
688 } else { | |
689 nativeJump_at((address)inst)->set_jump_destination(cb->code_begin()); | |
690 } | |
645 _instructions->relocate((address)inst, runtime_call_Relocation::spec(), Assembler::call32_operand); | 691 _instructions->relocate((address)inst, runtime_call_Relocation::spec(), Assembler::call32_operand); |
646 | 692 |
647 return; | 693 return; |
648 } | 694 } |
649 | 695 |