Mercurial > hg > graal-jvmci-8
comparison src/share/vm/graal/graalCodeInstaller.cpp @ 10684:6ff467cdb105
Code installer changes for SPARC.
author | twisti |
---|---|
date | Tue, 09 Jul 2013 14:39:34 -0700 |
parents | 0ba44a5a8420 |
children | ec8ee1c2ad7a |
comparison
equal
deleted
inserted
replaced
10683:ae4c79ee71d1 | 10684:6ff467cdb105 |
---|---|
169 Location::Type locationType = Location::normal; | 169 Location::Type locationType = Location::normal; |
170 if (type == T_OBJECT || type == T_ARRAY) locationType = Location::oop; | 170 if (type == T_OBJECT || type == T_ARRAY) locationType = Location::oop; |
171 | 171 |
172 if (value->is_a(RegisterValue::klass())) { | 172 if (value->is_a(RegisterValue::klass())) { |
173 jint number = code_Register::number(RegisterValue::reg(value)); | 173 jint number = code_Register::number(RegisterValue::reg(value)); |
174 if (number < 16) { | 174 if (number < RegisterImpl::number_of_registers) { |
175 if (type == T_INT || type == T_FLOAT || type == T_SHORT || type == T_CHAR || type == T_BOOLEAN || type == T_BYTE || type == T_ADDRESS) { | 175 if (type == T_INT || type == T_FLOAT || type == T_SHORT || type == T_CHAR || type == T_BOOLEAN || type == T_BYTE || type == T_ADDRESS) { |
176 locationType = Location::int_in_long; | 176 locationType = Location::int_in_long; |
177 } else if (type == T_LONG) { | 177 } else if (type == T_LONG) { |
178 locationType = Location::lng; | 178 locationType = Location::lng; |
179 } else { | 179 } else { |
364 GraalCompiler::initialize_buffer_blob(); | 364 GraalCompiler::initialize_buffer_blob(); |
365 CodeBuffer buffer(JavaThread::current()->get_buffer_blob()); | 365 CodeBuffer buffer(JavaThread::current()->get_buffer_blob()); |
366 jobject compiled_code_obj = JNIHandles::make_local(compiled_code()); | 366 jobject compiled_code_obj = JNIHandles::make_local(compiled_code()); |
367 initialize_assumptions(JNIHandles::resolve(compiled_code_obj)); | 367 initialize_assumptions(JNIHandles::resolve(compiled_code_obj)); |
368 | 368 |
369 // Get instructions and constants CodeSections early because we need it. | |
370 _instructions = buffer.insts(); | |
371 _constants = buffer.consts(); | |
372 | |
369 { | 373 { |
370 No_Safepoint_Verifier no_safepoint; | 374 No_Safepoint_Verifier no_safepoint; |
371 initialize_fields(JNIHandles::resolve(compiled_code_obj)); | 375 initialize_fields(JNIHandles::resolve(compiled_code_obj)); |
372 if (!initialize_buffer(buffer)) { | 376 if (!initialize_buffer(buffer)) { |
373 result = GraalEnv::code_too_large; | 377 result = GraalEnv::code_too_large; |
395 jint entry_bci = HotSpotCompiledNmethod::entryBCI(compiled_code); | 399 jint entry_bci = HotSpotCompiledNmethod::entryBCI(compiled_code); |
396 result = GraalEnv::register_method(method, nm, entry_bci, &_offsets, _custom_stack_area_offset, &buffer, stack_slots, _debug_recorder->_oopmaps, &_exception_handler_table, | 400 result = GraalEnv::register_method(method, nm, entry_bci, &_offsets, _custom_stack_area_offset, &buffer, stack_slots, _debug_recorder->_oopmaps, &_exception_handler_table, |
397 GraalCompiler::instance(), _debug_recorder, _dependencies, NULL, -1, false, leaf_graph_ids, installed_code, triggered_deoptimizations); | 401 GraalCompiler::instance(), _debug_recorder, _dependencies, NULL, -1, false, leaf_graph_ids, installed_code, triggered_deoptimizations); |
398 cb = nm; | 402 cb = nm; |
399 } | 403 } |
404 | |
405 if (cb != NULL) { | |
406 // Make sure the pre-calculated constants section size was correct. | |
407 guarantee((cb->code_begin() - cb->content_begin()) == _constants_size, err_msg("%d != %d", cb->code_begin() - cb->content_begin(), _constants_size)); | |
408 } | |
400 } | 409 } |
401 | 410 |
402 void CodeInstaller::initialize_fields(oop compiled_code) { | 411 void CodeInstaller::initialize_fields(oop compiled_code) { |
403 oop comp_result = HotSpotCompiledCode::comp(compiled_code); | 412 oop comp_result = HotSpotCompiledCode::comp(compiled_code); |
404 if (compiled_code->is_a(HotSpotCompiledNmethod::klass())) { | 413 if (compiled_code->is_a(HotSpotCompiledNmethod::klass())) { |
415 _exception_handlers = (arrayOop) HotSpotCompiledCode::exceptionHandlers(compiled_code); | 424 _exception_handlers = (arrayOop) HotSpotCompiledCode::exceptionHandlers(compiled_code); |
416 | 425 |
417 _code = (arrayOop) CompilationResult::targetCode(comp_result); | 426 _code = (arrayOop) CompilationResult::targetCode(comp_result); |
418 _code_size = CompilationResult::targetCodeSize(comp_result); | 427 _code_size = CompilationResult::targetCodeSize(comp_result); |
419 // The frame size we get from the target method does not include the return address, so add one word for it here. | 428 // The frame size we get from the target method does not include the return address, so add one word for it here. |
420 _total_frame_size = CompilationResult::frameSize(comp_result) + HeapWordSize; | 429 _total_frame_size = CompilationResult::frameSize(comp_result) + HeapWordSize; // FIXME this is an x86-ism |
421 _custom_stack_area_offset = CompilationResult::customStackAreaOffset(comp_result); | 430 _custom_stack_area_offset = CompilationResult::customStackAreaOffset(comp_result); |
422 | 431 |
423 // (very) conservative estimate: each site needs a constant section entry | 432 // Pre-calculate the constants section size. This is required for PC-relative addressing. |
424 _constants_size = _sites->length() * (BytesPerLong*2); | 433 _constants_size = calculate_constants_size(); |
434 | |
425 #ifndef PRODUCT | 435 #ifndef PRODUCT |
426 _comments = (arrayOop) HotSpotCompiledCode::comments(compiled_code); | 436 _comments = (arrayOop) HotSpotCompiledCode::comments(compiled_code); |
427 #endif | 437 #endif |
428 | 438 |
429 _next_call_type = MARK_INVOKE_INVALID; | 439 _next_call_type = MARK_INVOKE_INVALID; |
440 _debug_recorder = new DebugInformationRecorder(_oop_recorder); | 450 _debug_recorder = new DebugInformationRecorder(_oop_recorder); |
441 _debug_recorder->set_oopmaps(new OopMapSet()); | 451 _debug_recorder->set_oopmaps(new OopMapSet()); |
442 | 452 |
443 buffer.initialize_oop_recorder(_oop_recorder); | 453 buffer.initialize_oop_recorder(_oop_recorder); |
444 | 454 |
445 _instructions = buffer.insts(); | |
446 _constants = buffer.consts(); | |
447 | |
448 // copy the code into the newly created CodeBuffer | 455 // copy the code into the newly created CodeBuffer |
449 address end_pc = _instructions->start() + _code_size; | 456 address end_pc = _instructions->start() + _code_size; |
450 if (!_instructions->allocates2(end_pc)) { | 457 if (!_instructions->allocates2(end_pc)) { |
451 return false; | 458 return false; |
452 } | 459 } |
453 memcpy(_instructions->start(), _code->base(T_BYTE), _code_size); | 460 memcpy(_instructions->start(), _code->base(T_BYTE), _code_size); |
454 _instructions->set_end(end_pc); | 461 _instructions->set_end(end_pc); |
455 | 462 |
456 for (int i = 0; i < _sites->length(); i++) { | 463 for (int i = 0; i < _sites->length(); i++) { |
457 oop site=((objArrayOop) (_sites))->obj_at(i); | 464 oop site = ((objArrayOop) (_sites))->obj_at(i); |
458 jint pc_offset = CompilationResult_Site::pcOffset(site); | 465 jint pc_offset = CompilationResult_Site::pcOffset(site); |
459 | 466 |
460 if (site->is_a(CompilationResult_Call::klass())) { | 467 if (site->is_a(CompilationResult_Call::klass())) { |
461 TRACE_graal_4("call at %i", pc_offset); | 468 TRACE_graal_4("call at %i", pc_offset); |
462 site_Call(buffer, pc_offset, site); | 469 site_Call(buffer, pc_offset, site); |
483 } | 490 } |
484 | 491 |
485 #ifndef PRODUCT | 492 #ifndef PRODUCT |
486 if (_comments != NULL) { | 493 if (_comments != NULL) { |
487 for (int i = 0; i < _comments->length(); i++) { | 494 for (int i = 0; i < _comments->length(); i++) { |
488 oop comment=((objArrayOop) (_comments))->obj_at(i); | 495 oop comment = ((objArrayOop) (_comments))->obj_at(i); |
489 assert(comment->is_a(HotSpotCompiledCode_Comment::klass()), "cce"); | 496 assert(comment->is_a(HotSpotCompiledCode_Comment::klass()), "cce"); |
490 jint offset = HotSpotCompiledCode_Comment::pcOffset(comment); | 497 jint offset = HotSpotCompiledCode_Comment::pcOffset(comment); |
491 char* text = java_lang_String::as_utf8_string(HotSpotCompiledCode_Comment::text(comment)); | 498 char* text = java_lang_String::as_utf8_string(HotSpotCompiledCode_Comment::text(comment)); |
492 buffer.block_comment(offset, text); | 499 buffer.block_comment(offset, text); |
493 } | 500 } |
494 } | 501 } |
495 #endif | 502 #endif |
496 return true; | 503 return true; |
504 } | |
505 | |
506 /** | |
507 * Calculate the constants section size by iterating over all DataPatches. | |
508 * Knowing the size of the constants section before patching instructions | |
509 * is necessary for PC-relative addressing. | |
510 */ | |
511 int CodeInstaller::calculate_constants_size() { | |
512 int size = 0; | |
513 | |
514 for (int i = 0; i < _sites->length(); i++) { | |
515 oop site = ((objArrayOop) (_sites))->obj_at(i); | |
516 jint pc_offset = CompilationResult_Site::pcOffset(site); | |
517 | |
518 if (site->is_a(CompilationResult_DataPatch::klass())) { | |
519 oop constant = CompilationResult_DataPatch::constant(site); | |
520 int alignment = CompilationResult_DataPatch::alignment(site); | |
521 bool inlined = CompilationResult_DataPatch::inlined(site) == JNI_TRUE; | |
522 | |
523 if (!inlined) { | |
524 if (alignment > 0) { | |
525 guarantee(alignment <= _constants->alignment(), "Alignment inside constants section is restricted by alignment of section begin"); | |
526 size = align_size_up(size, alignment); | |
527 } | |
528 size = size + sizeof(int64_t); | |
529 } | |
530 } | |
531 } | |
532 return size == 0 ? 0 : align_size_up(size, _constants->alignment()); | |
497 } | 533 } |
498 | 534 |
499 void CodeInstaller::assumption_MethodContents(Handle assumption) { | 535 void CodeInstaller::assumption_MethodContents(Handle assumption) { |
500 Handle method_handle = Assumptions_MethodContents::method(assumption()); | 536 Handle method_handle = Assumptions_MethodContents::method(assumption()); |
501 methodHandle method = getMethodFromHotSpotMethod(method_handle()); | 537 methodHandle method = getMethodFromHotSpotMethod(method_handle()); |
730 } | 766 } |
731 } | 767 } |
732 | 768 |
733 void CodeInstaller::site_DataPatch(CodeBuffer& buffer, jint pc_offset, oop site) { | 769 void CodeInstaller::site_DataPatch(CodeBuffer& buffer, jint pc_offset, oop site) { |
734 oop constant = CompilationResult_DataPatch::constant(site); | 770 oop constant = CompilationResult_DataPatch::constant(site); |
735 int alignment = CompilationResult_DataPatch::alignment(site); | |
736 bool inlined = CompilationResult_DataPatch::inlined(site) == JNI_TRUE; | |
737 oop kind = Constant::kind(constant); | 771 oop kind = Constant::kind(constant); |
738 | |
739 address instruction = _instructions->start() + pc_offset; | |
740 char typeChar = Kind::typeChar(kind); | 772 char typeChar = Kind::typeChar(kind); |
741 switch (typeChar) { | 773 switch (typeChar) { |
742 case 'f': | 774 case 'f': |
743 case 'j': | 775 case 'j': |
744 case 'd': | 776 case 'd': |
745 record_metadata_in_constant(constant, _oop_recorder); | 777 record_metadata_in_constant(constant, _oop_recorder); |
746 break; | 778 break; |
747 } | 779 } |
748 CodeInstaller::pd_site_DataPatch(constant, kind, inlined, instruction, alignment, typeChar); | 780 CodeInstaller::pd_site_DataPatch(pc_offset, site); |
749 } | 781 } |
750 | 782 |
751 void CodeInstaller::site_Mark(CodeBuffer& buffer, jint pc_offset, oop site) { | 783 void CodeInstaller::site_Mark(CodeBuffer& buffer, jint pc_offset, oop site) { |
752 oop id_obj = CompilationResult_Mark::id(site); | 784 oop id_obj = CompilationResult_Mark::id(site); |
753 arrayOop references = (arrayOop) CompilationResult_Mark::references(site); | 785 arrayOop references = (arrayOop) CompilationResult_Mark::references(site); |