Mercurial > hg > graal-jvmci-8
comparison src/share/vm/graal/graalCodeInstaller.cpp @ 6674:fd71ca8c5f88
VM infrstructure for OnStackReplacement
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Wed, 07 Nov 2012 13:18:04 +0100 |
parents | d5f7e737827f |
children | e522a00b91aa |
comparison
equal
deleted
inserted
replaced
6673:a52320a6bbda | 6674:fd71ca8c5f88 |
---|---|
245 void CodeInstaller::initialize_assumptions(oop target_method) { | 245 void CodeInstaller::initialize_assumptions(oop target_method) { |
246 _oop_recorder = new OopRecorder(_env->arena()); | 246 _oop_recorder = new OopRecorder(_env->arena()); |
247 _env->set_oop_recorder(_oop_recorder); | 247 _env->set_oop_recorder(_oop_recorder); |
248 _env->set_dependencies(_dependencies); | 248 _env->set_dependencies(_dependencies); |
249 _dependencies = new Dependencies(_env); | 249 _dependencies = new Dependencies(_env); |
250 Handle assumptions_handle = InstalledCode::assumptions(HotSpotCompilationResult::comp(target_method)); | 250 Handle assumptions_handle = CompilationResult::assumptions(HotSpotCompilationResult::comp(target_method)); |
251 if (!assumptions_handle.is_null()) { | 251 if (!assumptions_handle.is_null()) { |
252 objArrayHandle assumptions(Thread::current(), (objArrayOop)Assumptions::list(assumptions_handle())); | 252 objArrayHandle assumptions(Thread::current(), (objArrayOop)Assumptions::list(assumptions_handle())); |
253 int length = assumptions->length(); | 253 int length = assumptions->length(); |
254 for (int i = 0; i < length; ++i) { | 254 for (int i = 0; i < length; ++i) { |
255 Handle assumption = assumptions->obj_at(i); | 255 Handle assumption = assumptions->obj_at(i); |
273 CodeInstaller::CodeInstaller(Handle& comp_result, nmethod*& nm, bool install_code) { | 273 CodeInstaller::CodeInstaller(Handle& comp_result, nmethod*& nm, bool install_code) { |
274 _env = CURRENT_ENV; | 274 _env = CURRENT_ENV; |
275 GraalCompiler::initialize_buffer_blob(); | 275 GraalCompiler::initialize_buffer_blob(); |
276 CodeBuffer buffer(JavaThread::current()->get_buffer_blob()); | 276 CodeBuffer buffer(JavaThread::current()->get_buffer_blob()); |
277 jobject comp_result_obj = JNIHandles::make_local(comp_result()); | 277 jobject comp_result_obj = JNIHandles::make_local(comp_result()); |
278 jint entry_bci = HotSpotCompilationResult::entryBCI(comp_result); | |
278 initialize_assumptions(JNIHandles::resolve(comp_result_obj)); | 279 initialize_assumptions(JNIHandles::resolve(comp_result_obj)); |
279 | 280 |
280 { | 281 { |
281 No_Safepoint_Verifier no_safepoint; | 282 No_Safepoint_Verifier no_safepoint; |
282 initialize_fields(JNIHandles::resolve(comp_result_obj)); | 283 initialize_fields(JNIHandles::resolve(comp_result_obj)); |
285 } | 286 } |
286 | 287 |
287 int stack_slots = _total_frame_size / HeapWordSize; // conversion to words | 288 int stack_slots = _total_frame_size / HeapWordSize; // conversion to words |
288 methodHandle method = getMethodFromHotSpotMethod(HotSpotCompilationResult::method(JNIHandles::resolve(comp_result_obj))); | 289 methodHandle method = getMethodFromHotSpotMethod(HotSpotCompilationResult::method(JNIHandles::resolve(comp_result_obj))); |
289 | 290 |
290 nm = GraalEnv::register_method(method, -1, &_offsets, _custom_stack_area_offset, &buffer, stack_slots, _debug_recorder->_oopmaps, &_exception_handler_table, | 291 nm = GraalEnv::register_method(method, entry_bci, &_offsets, _custom_stack_area_offset, &buffer, stack_slots, _debug_recorder->_oopmaps, &_exception_handler_table, |
291 &_implicit_exception_table, GraalCompiler::instance(), _debug_recorder, _dependencies, NULL, -1, true, false, install_code); | 292 &_implicit_exception_table, GraalCompiler::instance(), _debug_recorder, _dependencies, NULL, -1, true, false, install_code); |
292 | 293 |
293 method->clear_queued_for_compilation(); | 294 method->clear_queued_for_compilation(); |
294 } | 295 } |
295 | 296 |
324 } | 325 } |
325 _name = HotSpotCompilationResult::name(comp_result); | 326 _name = HotSpotCompilationResult::name(comp_result); |
326 _sites = (arrayOop) HotSpotCompilationResult::sites(comp_result); | 327 _sites = (arrayOop) HotSpotCompilationResult::sites(comp_result); |
327 _exception_handlers = (arrayOop) HotSpotCompilationResult::exceptionHandlers(comp_result); | 328 _exception_handlers = (arrayOop) HotSpotCompilationResult::exceptionHandlers(comp_result); |
328 | 329 |
329 _code = (arrayOop) InstalledCode::targetCode(_comp_result); | 330 _code = (arrayOop) CompilationResult::targetCode(_comp_result); |
330 _code_size = InstalledCode::targetCodeSize(_comp_result); | 331 _code_size = CompilationResult::targetCodeSize(_comp_result); |
331 // The frame size we get from the target method does not include the return address, so add one word for it here. | 332 // The frame size we get from the target method does not include the return address, so add one word for it here. |
332 _total_frame_size = InstalledCode::frameSize(_comp_result) + HeapWordSize; | 333 _total_frame_size = CompilationResult::frameSize(_comp_result) + HeapWordSize; |
333 _custom_stack_area_offset = InstalledCode::customStackAreaOffset(_comp_result); | 334 _custom_stack_area_offset = CompilationResult::customStackAreaOffset(_comp_result); |
334 | 335 |
335 // (very) conservative estimate: each site needs a constant section entry | 336 // (very) conservative estimate: each site needs a constant section entry |
336 _constants_size = _sites->length() * (BytesPerLong*2); | 337 _constants_size = _sites->length() * (BytesPerLong*2); |
337 _total_size = align_size_up(_code_size, HeapWordSize) + _constants_size; | 338 _total_size = align_size_up(_code_size, HeapWordSize) + _constants_size; |
338 | 339 |
361 _instructions->set_end(_instructions->start() + _code_size); | 362 _instructions->set_end(_instructions->start() + _code_size); |
362 | 363 |
363 oop* sites = (oop*) _sites->base(T_OBJECT); | 364 oop* sites = (oop*) _sites->base(T_OBJECT); |
364 for (int i = 0; i < _sites->length(); i++) { | 365 for (int i = 0; i < _sites->length(); i++) { |
365 oop site = sites[i]; | 366 oop site = sites[i]; |
366 jint pc_offset = InstalledCode_Site::pcOffset(site); | 367 jint pc_offset = CompilationResult_Site::pcOffset(site); |
367 | 368 |
368 if (site->is_a(InstalledCode_Call::klass())) { | 369 if (site->is_a(CompilationResult_Call::klass())) { |
369 TRACE_graal_4("call at %i", pc_offset); | 370 TRACE_graal_4("call at %i", pc_offset); |
370 site_Call(buffer, pc_offset, site); | 371 site_Call(buffer, pc_offset, site); |
371 } else if (site->is_a(InstalledCode_Safepoint::klass())) { | 372 } else if (site->is_a(CompilationResult_Safepoint::klass())) { |
372 TRACE_graal_4("safepoint at %i", pc_offset); | 373 TRACE_graal_4("safepoint at %i", pc_offset); |
373 site_Safepoint(buffer, pc_offset, site); | 374 site_Safepoint(buffer, pc_offset, site); |
374 } else if (site->is_a(InstalledCode_DataPatch::klass())) { | 375 } else if (site->is_a(CompilationResult_DataPatch::klass())) { |
375 TRACE_graal_4("datapatch at %i", pc_offset); | 376 TRACE_graal_4("datapatch at %i", pc_offset); |
376 site_DataPatch(buffer, pc_offset, site); | 377 site_DataPatch(buffer, pc_offset, site); |
377 } else if (site->is_a(InstalledCode_Mark::klass())) { | 378 } else if (site->is_a(CompilationResult_Mark::klass())) { |
378 TRACE_graal_4("mark at %i", pc_offset); | 379 TRACE_graal_4("mark at %i", pc_offset); |
379 site_Mark(buffer, pc_offset, site); | 380 site_Mark(buffer, pc_offset, site); |
380 } else { | 381 } else { |
381 fatal("unexpected Site subclass"); | 382 fatal("unexpected Site subclass"); |
382 } | 383 } |
424 | 425 |
425 if (_exception_handlers != NULL) { | 426 if (_exception_handlers != NULL) { |
426 oop* exception_handlers = (oop*) _exception_handlers->base(T_OBJECT); | 427 oop* exception_handlers = (oop*) _exception_handlers->base(T_OBJECT); |
427 for (int i = 0; i < _exception_handlers->length(); i++) { | 428 for (int i = 0; i < _exception_handlers->length(); i++) { |
428 oop exc = exception_handlers[i]; | 429 oop exc = exception_handlers[i]; |
429 jint pc_offset = InstalledCode_Site::pcOffset(exc); | 430 jint pc_offset = CompilationResult_Site::pcOffset(exc); |
430 jint handler_offset = InstalledCode_ExceptionHandler::handlerPos(exc); | 431 jint handler_offset = CompilationResult_ExceptionHandler::handlerPos(exc); |
431 | 432 |
432 // Subtable header | 433 // Subtable header |
433 _exception_handler_table.add_entry(HandlerTableEntry(1, pc_offset, 0)); | 434 _exception_handler_table.add_entry(HandlerTableEntry(1, pc_offset, 0)); |
434 | 435 |
435 // Subtable entry | 436 // Subtable entry |
515 | 516 |
516 _debug_recorder->describe_scope(pc_offset, method, NULL, bci, reexecute, throw_exception, false, false, locals_token, expressions_token, monitors_token); | 517 _debug_recorder->describe_scope(pc_offset, method, NULL, bci, reexecute, throw_exception, false, false, locals_token, expressions_token, monitors_token); |
517 } | 518 } |
518 | 519 |
519 void CodeInstaller::site_Safepoint(CodeBuffer& buffer, jint pc_offset, oop site) { | 520 void CodeInstaller::site_Safepoint(CodeBuffer& buffer, jint pc_offset, oop site) { |
520 oop debug_info = InstalledCode_Safepoint::debugInfo(site); | 521 oop debug_info = CompilationResult_Safepoint::debugInfo(site); |
521 assert(debug_info != NULL, "debug info expected"); | 522 assert(debug_info != NULL, "debug info expected"); |
522 | 523 |
523 // address instruction = _instructions->start() + pc_offset; | 524 // address instruction = _instructions->start() + pc_offset; |
524 // jint next_pc_offset = Assembler::locate_next_instruction(instruction) - _instructions->start(); | 525 // jint next_pc_offset = Assembler::locate_next_instruction(instruction) - _instructions->start(); |
525 _debug_recorder->add_safepoint(pc_offset, -1, create_oop_map(_total_frame_size, _parameter_count, debug_info)); | 526 _debug_recorder->add_safepoint(pc_offset, -1, create_oop_map(_total_frame_size, _parameter_count, debug_info)); |
529 | 530 |
530 _debug_recorder->end_safepoint(pc_offset); | 531 _debug_recorder->end_safepoint(pc_offset); |
531 } | 532 } |
532 | 533 |
533 void CodeInstaller::site_Call(CodeBuffer& buffer, jint pc_offset, oop site) { | 534 void CodeInstaller::site_Call(CodeBuffer& buffer, jint pc_offset, oop site) { |
534 oop target = InstalledCode_Call::target(site); | 535 oop target = CompilationResult_Call::target(site); |
535 instanceKlass* target_klass = instanceKlass::cast(target->klass()); | 536 instanceKlass* target_klass = instanceKlass::cast(target->klass()); |
536 | 537 |
537 oop hotspot_method = NULL; // JavaMethod | 538 oop hotspot_method = NULL; // JavaMethod |
538 oop global_stub = NULL; | 539 oop global_stub = NULL; |
539 | 540 |
541 global_stub = target; | 542 global_stub = target; |
542 } else { | 543 } else { |
543 hotspot_method = target; | 544 hotspot_method = target; |
544 } | 545 } |
545 | 546 |
546 oop debug_info = InstalledCode_Call::debugInfo(site); | 547 oop debug_info = CompilationResult_Call::debugInfo(site); |
547 | 548 |
548 assert((hotspot_method ? 1 : 0) + (global_stub ? 1 : 0) == 1, "Call site needs exactly one type"); | 549 assert((hotspot_method ? 1 : 0) + (global_stub ? 1 : 0) == 1, "Call site needs exactly one type"); |
549 | 550 |
550 NativeInstruction* inst = nativeInstruction_at(_instructions->start() + pc_offset); | 551 NativeInstruction* inst = nativeInstruction_at(_instructions->start() + pc_offset); |
551 jint next_pc_offset = 0x0; | 552 jint next_pc_offset = 0x0; |
657 _debug_recorder->end_safepoint(next_pc_offset); | 658 _debug_recorder->end_safepoint(next_pc_offset); |
658 } | 659 } |
659 } | 660 } |
660 | 661 |
661 void CodeInstaller::site_DataPatch(CodeBuffer& buffer, jint pc_offset, oop site) { | 662 void CodeInstaller::site_DataPatch(CodeBuffer& buffer, jint pc_offset, oop site) { |
662 oop constant = InstalledCode_DataPatch::constant(site); | 663 oop constant = CompilationResult_DataPatch::constant(site); |
663 int alignment = InstalledCode_DataPatch::alignment(site); | 664 int alignment = CompilationResult_DataPatch::alignment(site); |
664 oop kind = Constant::kind(constant); | 665 oop kind = Constant::kind(constant); |
665 | 666 |
666 address instruction = _instructions->start() + pc_offset; | 667 address instruction = _instructions->start() + pc_offset; |
667 | 668 |
668 char typeChar = Kind::typeChar(kind); | 669 char typeChar = Kind::typeChar(kind); |
721 break; | 722 break; |
722 } | 723 } |
723 } | 724 } |
724 | 725 |
725 void CodeInstaller::site_Mark(CodeBuffer& buffer, jint pc_offset, oop site) { | 726 void CodeInstaller::site_Mark(CodeBuffer& buffer, jint pc_offset, oop site) { |
726 oop id_obj = InstalledCode_Mark::id(site); | 727 oop id_obj = CompilationResult_Mark::id(site); |
727 arrayOop references = (arrayOop) InstalledCode_Mark::references(site); | 728 arrayOop references = (arrayOop) CompilationResult_Mark::references(site); |
728 | 729 |
729 if (id_obj != NULL) { | 730 if (id_obj != NULL) { |
730 assert(java_lang_boxing_object::is_instance(id_obj, T_INT), "Integer id expected"); | 731 assert(java_lang_boxing_object::is_instance(id_obj, T_INT), "Integer id expected"); |
731 jint id = id_obj->int_field(java_lang_boxing_object::value_offset_in_bytes(T_INT)); | 732 jint id = id_obj->int_field(java_lang_boxing_object::value_offset_in_bytes(T_INT)); |
732 | 733 |
749 _offsets.set_value(CodeOffsets::Deopt, pc_offset); | 750 _offsets.set_value(CodeOffsets::Deopt, pc_offset); |
750 break; | 751 break; |
751 case MARK_STATIC_CALL_STUB: { | 752 case MARK_STATIC_CALL_STUB: { |
752 assert(references->length() == 1, "static call stub needs one reference"); | 753 assert(references->length() == 1, "static call stub needs one reference"); |
753 oop ref = ((oop*) references->base(T_OBJECT))[0]; | 754 oop ref = ((oop*) references->base(T_OBJECT))[0]; |
754 address call_pc = _instructions->start() + InstalledCode_Site::pcOffset(ref); | 755 address call_pc = _instructions->start() + CompilationResult_Site::pcOffset(ref); |
755 _instructions->relocate(instruction, static_stub_Relocation::spec(call_pc)); | 756 _instructions->relocate(instruction, static_stub_Relocation::spec(call_pc)); |
756 _instructions->relocate(instruction, oop_Relocation::spec_for_immediate(), Assembler::imm_operand); | 757 _instructions->relocate(instruction, oop_Relocation::spec_for_immediate(), Assembler::imm_operand); |
757 break; | 758 break; |
758 } | 759 } |
759 case MARK_INVOKEVIRTUAL: | 760 case MARK_INVOKEVIRTUAL: |
803 assert(*byte_skip == 5, "unexpected byte_skip"); | 804 assert(*byte_skip == 5, "unexpected byte_skip"); |
804 | 805 |
805 assert(references->length() == 2, "MARK_KLASS_PATCHING/MARK_ACCESS_FIELD_PATCHING needs 2 references"); | 806 assert(references->length() == 2, "MARK_KLASS_PATCHING/MARK_ACCESS_FIELD_PATCHING needs 2 references"); |
806 oop ref1 = ((oop*) references->base(T_OBJECT))[0]; | 807 oop ref1 = ((oop*) references->base(T_OBJECT))[0]; |
807 oop ref2 = ((oop*) references->base(T_OBJECT))[1]; | 808 oop ref2 = ((oop*) references->base(T_OBJECT))[1]; |
808 int i_byte_count = InstalledCode_Site::pcOffset(ref2) - InstalledCode_Site::pcOffset(ref1); | 809 int i_byte_count = CompilationResult_Site::pcOffset(ref2) - CompilationResult_Site::pcOffset(ref1); |
809 assert(i_byte_count == (unsigned char)i_byte_count, "invalid offset"); | 810 assert(i_byte_count == (unsigned char)i_byte_count, "invalid offset"); |
810 *byte_count = i_byte_count; | 811 *byte_count = i_byte_count; |
811 *being_initialized_entry_offset = *byte_count + *byte_skip; | 812 *being_initialized_entry_offset = *byte_count + *byte_skip; |
812 | 813 |
813 // 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 | 814 // 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 |
814 if (id == MARK_ACCESS_FIELD_PATCHING) { | 815 if (id == MARK_ACCESS_FIELD_PATCHING) { |
815 NativeMovRegMem* inst = nativeMovRegMem_at(_instructions->start() + InstalledCode_Site::pcOffset(ref1)); | 816 NativeMovRegMem* inst = nativeMovRegMem_at(_instructions->start() + CompilationResult_Site::pcOffset(ref1)); |
816 assert(inst->offset() == max_jint, "unexpected offset value"); | 817 assert(inst->offset() == max_jint, "unexpected offset value"); |
817 inst->set_offset(0); | 818 inst->set_offset(0); |
818 } | 819 } |
819 break; | 820 break; |
820 } | 821 } |