Mercurial > hg > graal-jvmci-8
comparison src/share/vm/graal/graalCodeInstaller.cpp @ 18176:c2270ad35f57
Better construction of data section and data patches.
author | Roland Schatz <roland.schatz@oracle.com> |
---|---|
date | Mon, 27 Oct 2014 14:07:49 +0100 |
parents | 26d381457145 |
children | 89f97291c3a5 |
comparison
equal
deleted
inserted
replaced
18175:cf09e921458f | 18176:c2270ad35f57 |
---|---|
197 | 197 |
198 record_metadata_reference(obj, prim, false, oop_recorder); | 198 record_metadata_reference(obj, prim, false, oop_recorder); |
199 } | 199 } |
200 } | 200 } |
201 | 201 |
202 static void record_metadata_in_patch(oop data, OopRecorder* oop_recorder) { | 202 static void record_metadata_in_patch(Handle& constant, OopRecorder* oop_recorder) { |
203 record_metadata_reference(MetaspaceData::annotation(data), MetaspaceData::value(data), MetaspaceData::compressed(data) != 0, oop_recorder); | 203 record_metadata_reference(HotSpotMetaspaceConstant::metaspaceObject(constant), HotSpotMetaspaceConstant::primitive(constant), HotSpotMetaspaceConstant::compressed(constant), oop_recorder); |
204 } | 204 } |
205 | 205 |
206 ScopeValue* CodeInstaller::get_scope_value(oop value, int total_frame_size, GrowableArray<ScopeValue*>* objects, ScopeValue* &second, OopRecorder* oop_recorder) { | 206 ScopeValue* CodeInstaller::get_scope_value(oop value, int total_frame_size, GrowableArray<ScopeValue*>* objects, ScopeValue* &second, OopRecorder* oop_recorder) { |
207 second = NULL; | 207 second = NULL; |
208 if (value == Value::ILLEGAL()) { | 208 if (value == Value::ILLEGAL()) { |
496 _total_frame_size = CompilationResult::totalFrameSize(comp_result); | 496 _total_frame_size = CompilationResult::totalFrameSize(comp_result); |
497 _custom_stack_area_offset = CompilationResult::customStackAreaOffset(comp_result); | 497 _custom_stack_area_offset = CompilationResult::customStackAreaOffset(comp_result); |
498 | 498 |
499 // Pre-calculate the constants section size. This is required for PC-relative addressing. | 499 // Pre-calculate the constants section size. This is required for PC-relative addressing. |
500 _data_section_handle = JNIHandles::make_local(HotSpotCompiledCode::dataSection(compiled_code)); | 500 _data_section_handle = JNIHandles::make_local(HotSpotCompiledCode::dataSection(compiled_code)); |
501 guarantee(DataSection::sectionAlignment(data_section()) <= _constants->alignment(), "Alignment inside constants section is restricted by alignment of section begin"); | 501 guarantee(HotSpotCompiledCode::dataSectionAlignment(compiled_code) <= _constants->alignment(), "Alignment inside constants section is restricted by alignment of section begin"); |
502 typeArrayHandle data = DataSection::data(data_section()); | 502 _constants_size = data_section()->length(); |
503 _constants_size = data->length(); | |
504 if (_constants_size > 0) { | 503 if (_constants_size > 0) { |
505 _constants_size = align_size_up(_constants_size, _constants->alignment()); | 504 _constants_size = align_size_up(_constants_size, _constants->alignment()); |
506 } | 505 } |
506 | |
507 _data_section_patches_handle = JNIHandles::make_local(HotSpotCompiledCode::dataSectionPatches(compiled_code)); | |
507 | 508 |
508 #ifndef PRODUCT | 509 #ifndef PRODUCT |
509 _comments_handle = JNIHandles::make_local(HotSpotCompiledCode::comments(compiled_code)); | 510 _comments_handle = JNIHandles::make_local(HotSpotCompiledCode::comments(compiled_code)); |
510 #endif | 511 #endif |
511 | 512 |
554 // copy the code into the newly created CodeBuffer | 555 // copy the code into the newly created CodeBuffer |
555 address end_pc = _instructions->start() + _code_size; | 556 address end_pc = _instructions->start() + _code_size; |
556 if (!_instructions->allocates2(end_pc)) { | 557 if (!_instructions->allocates2(end_pc)) { |
557 return false; | 558 return false; |
558 } | 559 } |
559 memcpy(_instructions->start(), code()->base(T_BYTE), _code_size); | 560 memcpy(_instructions->start(), code()->base(T_BYTE), code()->length()); |
560 _instructions->set_end(end_pc); | 561 _instructions->set_end(end_pc); |
561 | 562 |
562 // copy the constant data into the newly created CodeBuffer | 563 // copy the constant data into the newly created CodeBuffer |
563 address end_data = _constants->start() + _constants_size; | 564 address end_data = _constants->start() + _constants_size; |
564 typeArrayHandle data(DataSection::data(data_section())); | 565 memcpy(_constants->start(), data_section()->base(T_BYTE), _constants_size); |
565 memcpy(_constants->start(), data->base(T_BYTE), data->length()); | |
566 _constants->set_end(end_data); | 566 _constants->set_end(end_data); |
567 | 567 |
568 | 568 |
569 objArrayHandle patches = DataSection::patches(data_section()); | 569 for (int i = 0; i < data_section_patches()->length(); i++) { |
570 for (int i = 0; i < patches->length(); i++) { | 570 Handle patch = data_section_patches()->obj_at(i); |
571 Handle patch = patches->obj_at(i); | 571 Handle reference = CompilationResult_DataPatch::reference(patch); |
572 Handle data = CompilationResult_DataPatch::data(patch); | 572 assert(reference->is_a(CompilationResult_ConstantReference::klass()), err_msg("patch in data section must be a ConstantReference")); |
573 if (data->is_a(MetaspaceData::klass())) { | 573 Handle constant = CompilationResult_ConstantReference::constant(reference); |
574 record_metadata_in_patch(data(), _oop_recorder); | 574 if (constant->is_a(HotSpotMetaspaceConstant::klass())) { |
575 } else if (data->is_a(OopData::klass())) { | 575 record_metadata_in_patch(constant, _oop_recorder); |
576 Handle obj = OopData::object(data); | 576 } else if (constant->is_a(HotSpotObjectConstant::klass())) { |
577 Handle obj = HotSpotObjectConstant::object(constant); | |
577 jobject value = JNIHandles::make_local(obj()); | 578 jobject value = JNIHandles::make_local(obj()); |
578 int oop_index = _oop_recorder->find_index(value); | 579 int oop_index = _oop_recorder->find_index(value); |
579 | 580 |
580 address dest = _constants->start() + CompilationResult_Site::pcOffset(patch); | 581 address dest = _constants->start() + CompilationResult_Site::pcOffset(patch); |
581 assert(!OopData::compressed(data), err_msg("unexpected compressed oop in data section")); | 582 if (HotSpotObjectConstant::compressed(constant)) { |
582 _constants->relocate(dest, oop_Relocation::spec(oop_index)); | 583 fatal("unexpected compressed oop in data section"); |
584 } else { | |
585 _constants->relocate(dest, oop_Relocation::spec(oop_index)); | |
586 } | |
583 } else { | 587 } else { |
584 ShouldNotReachHere(); | 588 ShouldNotReachHere(); |
585 } | 589 } |
586 } | 590 } |
587 jint last_pc_offset = -1; | 591 jint last_pc_offset = -1; |
896 _debug_recorder->end_safepoint(next_pc_offset); | 900 _debug_recorder->end_safepoint(next_pc_offset); |
897 } | 901 } |
898 } | 902 } |
899 | 903 |
900 void CodeInstaller::site_DataPatch(CodeBuffer& buffer, jint pc_offset, oop site) { | 904 void CodeInstaller::site_DataPatch(CodeBuffer& buffer, jint pc_offset, oop site) { |
901 oop data = CompilationResult_DataPatch::data(site); | 905 oop reference = CompilationResult_DataPatch::reference(site); |
902 if (data->is_a(MetaspaceData::klass())) { | 906 if (reference->is_a(CompilationResult_ConstantReference::klass())) { |
903 record_metadata_in_patch(data, _oop_recorder); | 907 Handle constant = CompilationResult_ConstantReference::constant(reference); |
904 } else if (data->is_a(OopData::klass())) { | 908 if (constant->is_a(HotSpotObjectConstant::klass())) { |
905 pd_patch_OopData(pc_offset, data); | 909 pd_patch_OopConstant(pc_offset, constant); |
906 } else if (data->is_a(DataSectionReference::klass())) { | 910 } else if (constant->is_a(HotSpotMetaspaceConstant::klass())) { |
907 pd_patch_DataSectionReference(pc_offset, data); | 911 record_metadata_in_patch(constant, _oop_recorder); |
912 } else { | |
913 fatal("unknown constant type in data patch"); | |
914 } | |
915 } else if (reference->is_a(CompilationResult_DataSectionReference::klass())) { | |
916 int data_offset = CompilationResult_DataSectionReference::offset(reference); | |
917 assert(0 <= data_offset && data_offset < _constants_size, err_msg("data offset 0x%X points outside data section (size 0x%X)", data_offset, _constants_size)); | |
918 pd_patch_DataSectionReference(pc_offset, data_offset); | |
908 } else { | 919 } else { |
909 fatal("unknown data patch type"); | 920 fatal("unknown data patch type"); |
910 } | 921 } |
911 } | 922 } |
912 | 923 |