Mercurial > hg > graal-compiler
comparison src/share/vm/graal/graalCodeInstaller.cpp @ 13576:4e679d50ba9a
Move data section building code to Java.
author | Roland Schatz <roland.schatz@oracle.com> |
---|---|
date | Thu, 09 Jan 2014 13:09:44 +0100 |
parents | 03bb0ee05409 |
children | b1838411e896 |
comparison
equal
deleted
inserted
replaced
13575:55a8ca3f49f7 | 13576:4e679d50ba9a |
---|---|
433 // The frame size we get from the target method does not include the return address, so add one word for it here. | 433 // The frame size we get from the target method does not include the return address, so add one word for it here. |
434 _total_frame_size = CompilationResult::frameSize(comp_result) + HeapWordSize; // FIXME this is an x86-ism | 434 _total_frame_size = CompilationResult::frameSize(comp_result) + HeapWordSize; // FIXME this is an x86-ism |
435 _custom_stack_area_offset = CompilationResult::customStackAreaOffset(comp_result); | 435 _custom_stack_area_offset = CompilationResult::customStackAreaOffset(comp_result); |
436 | 436 |
437 // Pre-calculate the constants section size. This is required for PC-relative addressing. | 437 // Pre-calculate the constants section size. This is required for PC-relative addressing. |
438 _constants_size = calculate_constants_size(); | 438 _dataSection = HotSpotCompiledCode::dataSection(compiled_code); |
439 guarantee(HotSpotCompiledCode_DataSection::sectionAlignment(_dataSection) <= _constants->alignment(), "Alignment inside constants section is restricted by alignment of section begin"); | |
440 arrayOop data = (arrayOop) HotSpotCompiledCode_DataSection::data(_dataSection); | |
441 _constants_size = data->length(); | |
442 if (_constants_size > 0) { | |
443 _constants_size = align_size_up(_constants_size, _constants->alignment()); | |
444 } | |
439 | 445 |
440 #ifndef PRODUCT | 446 #ifndef PRODUCT |
441 _comments = (arrayOop) HotSpotCompiledCode::comments(compiled_code); | 447 _comments = (arrayOop) HotSpotCompiledCode::comments(compiled_code); |
442 #endif | 448 #endif |
443 | 449 |
462 if (!_instructions->allocates2(end_pc)) { | 468 if (!_instructions->allocates2(end_pc)) { |
463 return false; | 469 return false; |
464 } | 470 } |
465 memcpy(_instructions->start(), _code->base(T_BYTE), _code_size); | 471 memcpy(_instructions->start(), _code->base(T_BYTE), _code_size); |
466 _instructions->set_end(end_pc); | 472 _instructions->set_end(end_pc); |
473 | |
474 // copy the constant data into the newly created CodeBuffer | |
475 address end_data = _constants->start() + _constants_size; | |
476 arrayOop data = (arrayOop) HotSpotCompiledCode_DataSection::data(_dataSection); | |
477 memcpy(_constants->start(), data->base(T_BYTE), data->length()); | |
478 _constants->set_end(end_data); | |
479 | |
480 objArrayOop patches = (objArrayOop) HotSpotCompiledCode_DataSection::patches(_dataSection); | |
481 for (int i = 0; i < patches->length(); i++) { | |
482 oop patch = patches->obj_at(i); | |
483 oop constant = HotSpotCompiledCode_HotSpotData::constant(patch); | |
484 oop kind = Constant::kind(constant); | |
485 char typeChar = Kind::typeChar(kind); | |
486 switch (typeChar) { | |
487 case 'f': | |
488 case 'j': | |
489 case 'd': | |
490 record_metadata_in_constant(constant, _oop_recorder); | |
491 break; | |
492 case 'a': | |
493 Handle obj = Constant::object(constant); | |
494 jobject value = JNIHandles::make_local(obj()); | |
495 int oop_index = _oop_recorder->find_index(value); | |
496 | |
497 address dest = _constants->start() + HotSpotCompiledCode_HotSpotData::offset(patch); | |
498 _constants->relocate(dest, oop_Relocation::spec(oop_index)); | |
499 break; | |
500 } | |
501 } | |
467 | 502 |
468 for (int i = 0; i < _sites->length(); i++) { | 503 for (int i = 0; i < _sites->length(); i++) { |
469 oop site = ((objArrayOop) (_sites))->obj_at(i); | 504 oop site = ((objArrayOop) (_sites))->obj_at(i); |
470 jint pc_offset = CompilationResult_Site::pcOffset(site); | 505 jint pc_offset = CompilationResult_Site::pcOffset(site); |
471 | 506 |
506 } | 541 } |
507 #endif | 542 #endif |
508 return true; | 543 return true; |
509 } | 544 } |
510 | 545 |
511 /** | |
512 * Calculate the constants section size by iterating over all DataPatches. | |
513 * Knowing the size of the constants section before patching instructions | |
514 * is necessary for PC-relative addressing. | |
515 */ | |
516 int CodeInstaller::calculate_constants_size() { | |
517 int size = 0; | |
518 | |
519 for (int i = 0; i < _sites->length(); i++) { | |
520 oop site = ((objArrayOop) (_sites))->obj_at(i); | |
521 jint pc_offset = CompilationResult_Site::pcOffset(site); | |
522 | |
523 if (site->is_a(CompilationResult_DataPatch::klass())) { | |
524 int alignment = CompilationResult_DataPatch::alignment(site); | |
525 bool inlined = CompilationResult_DataPatch::inlined(site) == JNI_TRUE; | |
526 | |
527 if (!inlined) { | |
528 if (alignment > 0) { | |
529 guarantee(alignment <= _constants->alignment(), "Alignment inside constants section is restricted by alignment of section begin"); | |
530 size = align_size_up(size, alignment); | |
531 } | |
532 if (CompilationResult_DataPatch::constant(site) != NULL) { | |
533 size = size + sizeof(int64_t); | |
534 } else { | |
535 arrayOop rawConstant = arrayOop(CompilationResult_DataPatch::rawConstant(site)); | |
536 size = size + rawConstant->length(); | |
537 } | |
538 } | |
539 } | |
540 } | |
541 return size == 0 ? 0 : align_size_up(size, _constants->alignment()); | |
542 } | |
543 | |
544 void CodeInstaller::assumption_MethodContents(Handle assumption) { | 546 void CodeInstaller::assumption_MethodContents(Handle assumption) { |
545 Handle method_handle = Assumptions_MethodContents::method(assumption()); | 547 Handle method_handle = Assumptions_MethodContents::method(assumption()); |
546 methodHandle method = getMethodFromHotSpotMethod(method_handle()); | 548 methodHandle method = getMethodFromHotSpotMethod(method_handle()); |
547 _dependencies->assert_evol_method(method()); | 549 _dependencies->assert_evol_method(method()); |
548 } | 550 } |
764 _debug_recorder->end_safepoint(next_pc_offset); | 766 _debug_recorder->end_safepoint(next_pc_offset); |
765 } | 767 } |
766 } | 768 } |
767 | 769 |
768 void CodeInstaller::site_DataPatch(CodeBuffer& buffer, jint pc_offset, oop site) { | 770 void CodeInstaller::site_DataPatch(CodeBuffer& buffer, jint pc_offset, oop site) { |
769 oop constant = CompilationResult_DataPatch::constant(site); | 771 oop inlineData = CompilationResult_DataPatch::inlineData(site); |
770 if (constant != NULL) { | 772 if (inlineData != NULL) { |
771 oop kind = Constant::kind(constant); | 773 oop kind = Constant::kind(inlineData); |
772 char typeChar = Kind::typeChar(kind); | 774 char typeChar = Kind::typeChar(kind); |
773 switch (typeChar) { | 775 switch (typeChar) { |
774 case 'f': | 776 case 'f': |
775 case 'j': | 777 case 'j': |
776 case 'd': | 778 case 'd': |
777 record_metadata_in_constant(constant, _oop_recorder); | 779 record_metadata_in_constant(inlineData, _oop_recorder); |
778 break; | 780 break; |
779 } | 781 } |
780 } | 782 } |
781 CodeInstaller::pd_site_DataPatch(pc_offset, site); | 783 CodeInstaller::pd_site_DataPatch(pc_offset, site); |
782 } | 784 } |