Mercurial > hg > graal-compiler
comparison src/share/vm/graal/graalCodeInstaller.cpp @ 14561:e14198669e5c
Make data patch system use vm specific NarrowOop kind.
author | Roland Schatz <roland.schatz@oracle.com> |
---|---|
date | Mon, 17 Mar 2014 11:53:51 +0100 |
parents | cd22c8dbda4f |
children | 45812e05cdb3 |
comparison
equal
deleted
inserted
replaced
14560:570910f5412b | 14561:e14198669e5c |
---|---|
155 } | 155 } |
156 | 156 |
157 return map; | 157 return map; |
158 } | 158 } |
159 | 159 |
160 static void record_metadata_reference(oop obj, jlong prim, bool compressed, OopRecorder* oop_recorder) { | |
161 if (obj->is_a(HotSpotResolvedObjectType::klass())) { | |
162 Klass* klass = java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaClass(obj)); | |
163 if (compressed) { | |
164 assert(Klass::decode_klass((narrowKlass) prim) == klass, err_msg("%s @ %p != %p", klass->name()->as_C_string(), klass, prim)); | |
165 } else { | |
166 assert((Klass*) prim == klass, err_msg("%s @ %p != %p", klass->name()->as_C_string(), klass, prim)); | |
167 } | |
168 int index = oop_recorder->find_index(klass); | |
169 TRACE_graal_3("metadata[%d of %d] = %s", index, oop_recorder->metadata_count(), klass->name()->as_C_string()); | |
170 } else if (obj->is_a(HotSpotResolvedJavaMethod::klass())) { | |
171 Method* method = (Method*) (address) HotSpotResolvedJavaMethod::metaspaceMethod(obj); | |
172 assert(!compressed, err_msg("unexpected compressed method pointer %s @ %p = %p", method->name()->as_C_string(), method, prim)); | |
173 int index = oop_recorder->find_index(method); | |
174 TRACE_graal_3("metadata[%d of %d] = %s", index, oop_recorder->metadata_count(), method->name()->as_C_string()); | |
175 } else { | |
176 assert(java_lang_String::is_instance(obj), | |
177 err_msg("unexpected metadata reference (%s) for constant %ld (%p)", obj->klass()->name()->as_C_string(), prim, prim)); | |
178 } | |
179 } | |
180 | |
160 // Records any Metadata values embedded in a Constant (e.g., the value returned by HotSpotResolvedObjectType.klass()). | 181 // Records any Metadata values embedded in a Constant (e.g., the value returned by HotSpotResolvedObjectType.klass()). |
161 static void record_metadata_in_constant(oop constant, OopRecorder* oop_recorder) { | 182 static void record_metadata_in_constant(oop constant, OopRecorder* oop_recorder) { |
162 char kind = Kind::typeChar(Constant::kind(constant)); | 183 char kind = Kind::typeChar(Constant::kind(constant)); |
163 char wordKind = 'j'; | 184 char wordKind = 'j'; |
164 if (kind == wordKind) { | 185 if (kind == wordKind) { |
165 oop obj = Constant::object(constant); | 186 oop obj = Constant::object(constant); |
166 jlong prim = Constant::primitive(constant); | 187 jlong prim = Constant::primitive(constant); |
167 if (obj != NULL) { | 188 if (obj != NULL) { |
168 if (obj->is_a(HotSpotResolvedObjectType::klass())) { | 189 record_metadata_reference(obj, prim, false, oop_recorder); |
169 Klass* klass = java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaClass(obj)); | 190 } |
170 assert((Klass*) prim == klass, err_msg("%s @ %p != %p", klass->name()->as_C_string(), klass, prim)); | 191 } |
171 int index = oop_recorder->find_index(klass); | 192 } |
172 TRACE_graal_3("metadata[%d of %d] = %s", index, oop_recorder->metadata_count(), klass->name()->as_C_string()); | 193 |
173 } else if (obj->is_a(HotSpotResolvedJavaMethod::klass())) { | 194 static void record_metadata_in_patch(oop data, OopRecorder* oop_recorder) { |
174 Method* method = (Method*) (address) HotSpotResolvedJavaMethod::metaspaceMethod(obj); | 195 record_metadata_reference(MetaspaceData::annotation(data), MetaspaceData::value(data), MetaspaceData::compressed(data), oop_recorder); |
175 int index = oop_recorder->find_index(method); | |
176 TRACE_graal_3("metadata[%d of %d] = %s", index, oop_recorder->metadata_count(), method->name()->as_C_string()); | |
177 } else { | |
178 assert(java_lang_String::is_instance(obj), | |
179 err_msg("unexpected annotation type (%s) for constant %ld (%p) of kind %c", obj->klass()->name()->as_C_string(), prim, prim, kind)); | |
180 } | |
181 } | |
182 } | |
183 } | 196 } |
184 | 197 |
185 ScopeValue* CodeInstaller::get_scope_value(oop value, int total_frame_size, GrowableArray<ScopeValue*>* objects, ScopeValue* &second, OopRecorder* oop_recorder) { | 198 ScopeValue* CodeInstaller::get_scope_value(oop value, int total_frame_size, GrowableArray<ScopeValue*>* objects, ScopeValue* &second, OopRecorder* oop_recorder) { |
186 second = NULL; | 199 second = NULL; |
187 if (value == Value::ILLEGAL()) { | 200 if (value == Value::ILLEGAL()) { |
443 _total_frame_size = CompilationResult::frameSize(comp_result) + HeapWordSize; // FIXME this is an x86-ism | 456 _total_frame_size = CompilationResult::frameSize(comp_result) + HeapWordSize; // FIXME this is an x86-ism |
444 _custom_stack_area_offset = CompilationResult::customStackAreaOffset(comp_result); | 457 _custom_stack_area_offset = CompilationResult::customStackAreaOffset(comp_result); |
445 | 458 |
446 // Pre-calculate the constants section size. This is required for PC-relative addressing. | 459 // Pre-calculate the constants section size. This is required for PC-relative addressing. |
447 _dataSection = HotSpotCompiledCode::dataSection(compiled_code); | 460 _dataSection = HotSpotCompiledCode::dataSection(compiled_code); |
448 guarantee(HotSpotCompiledCode_DataSection::sectionAlignment(_dataSection) <= _constants->alignment(), "Alignment inside constants section is restricted by alignment of section begin"); | 461 guarantee(DataSection::sectionAlignment(_dataSection) <= _constants->alignment(), "Alignment inside constants section is restricted by alignment of section begin"); |
449 arrayOop data = (arrayOop) HotSpotCompiledCode_DataSection::data(_dataSection); | 462 arrayOop data = (arrayOop) DataSection::data(_dataSection); |
450 _constants_size = data->length(); | 463 _constants_size = data->length(); |
451 if (_constants_size > 0) { | 464 if (_constants_size > 0) { |
452 _constants_size = align_size_up(_constants_size, _constants->alignment()); | 465 _constants_size = align_size_up(_constants_size, _constants->alignment()); |
453 } | 466 } |
454 | 467 |
480 memcpy(_instructions->start(), _code->base(T_BYTE), _code_size); | 493 memcpy(_instructions->start(), _code->base(T_BYTE), _code_size); |
481 _instructions->set_end(end_pc); | 494 _instructions->set_end(end_pc); |
482 | 495 |
483 // copy the constant data into the newly created CodeBuffer | 496 // copy the constant data into the newly created CodeBuffer |
484 address end_data = _constants->start() + _constants_size; | 497 address end_data = _constants->start() + _constants_size; |
485 arrayOop data = (arrayOop) HotSpotCompiledCode_DataSection::data(_dataSection); | 498 arrayOop data = (arrayOop) DataSection::data(_dataSection); |
486 memcpy(_constants->start(), data->base(T_BYTE), data->length()); | 499 memcpy(_constants->start(), data->base(T_BYTE), data->length()); |
487 _constants->set_end(end_data); | 500 _constants->set_end(end_data); |
488 | 501 |
489 objArrayOop patches = (objArrayOop) HotSpotCompiledCode_DataSection::patches(_dataSection); | 502 objArrayOop patches = (objArrayOop) DataSection::patches(_dataSection); |
490 for (int i = 0; i < patches->length(); i++) { | 503 for (int i = 0; i < patches->length(); i++) { |
491 oop patch = patches->obj_at(i); | 504 oop patch = patches->obj_at(i); |
492 oop constant = HotSpotCompiledCode_HotSpotData::constant(patch); | 505 oop data = CompilationResult_DataPatch::data(patch); |
493 oop kind = Constant::kind(constant); | 506 if (data->is_a(MetaspaceData::klass())) { |
494 char typeChar = Kind::typeChar(kind); | 507 record_metadata_in_patch(data, _oop_recorder); |
495 switch (typeChar) { | 508 } else if (data->is_a(OopData::klass())) { |
496 case 'f': | 509 Handle obj = OopData::object(data); |
497 case 'j': | 510 jobject value = JNIHandles::make_local(obj()); |
498 case 'd': | 511 int oop_index = _oop_recorder->find_index(value); |
499 record_metadata_in_constant(constant, _oop_recorder); | 512 |
500 break; | 513 address dest = _constants->start() + CompilationResult_Site::pcOffset(patch); |
501 case 'a': | 514 assert(!OopData::compressed(data), err_msg("unexpected compressed oop in data section")); |
502 Handle obj = Constant::object(constant); | 515 _constants->relocate(dest, oop_Relocation::spec(oop_index)); |
503 jobject value = JNIHandles::make_local(obj()); | |
504 int oop_index = _oop_recorder->find_index(value); | |
505 | |
506 address dest = _constants->start() + HotSpotCompiledCode_HotSpotData::offset(patch); | |
507 _constants->relocate(dest, oop_Relocation::spec(oop_index)); | |
508 break; | |
509 } | 516 } |
510 } | 517 } |
511 | 518 |
512 for (int i = 0; i < _sites->length(); i++) { | 519 for (int i = 0; i < _sites->length(); i++) { |
513 oop site = ((objArrayOop) (_sites))->obj_at(i); | 520 oop site = ((objArrayOop) (_sites))->obj_at(i); |
775 _debug_recorder->end_safepoint(next_pc_offset); | 782 _debug_recorder->end_safepoint(next_pc_offset); |
776 } | 783 } |
777 } | 784 } |
778 | 785 |
779 void CodeInstaller::site_DataPatch(CodeBuffer& buffer, jint pc_offset, oop site) { | 786 void CodeInstaller::site_DataPatch(CodeBuffer& buffer, jint pc_offset, oop site) { |
780 oop inlineData = CompilationResult_DataPatch::inlineData(site); | 787 oop data = CompilationResult_DataPatch::data(site); |
781 if (inlineData != NULL) { | 788 if (data->is_a(MetaspaceData::klass())) { |
782 oop kind = Constant::kind(inlineData); | 789 record_metadata_in_patch(data, _oop_recorder); |
783 char typeChar = Kind::typeChar(kind); | 790 } else if (data->is_a(OopData::klass())) { |
784 switch (typeChar) { | 791 pd_patch_OopData(pc_offset, data); |
785 case 'f': | 792 } else if (data->is_a(DataSectionReference::klass())) { |
786 case 'j': | 793 pd_patch_DataSectionReference(pc_offset, data); |
787 case 'd': | 794 } else { |
788 record_metadata_in_constant(inlineData, _oop_recorder); | 795 fatal("unknown data patch type"); |
789 break; | 796 } |
790 } | |
791 } | |
792 CodeInstaller::pd_site_DataPatch(pc_offset, site); | |
793 } | 797 } |
794 | 798 |
795 void CodeInstaller::site_Mark(CodeBuffer& buffer, jint pc_offset, oop site) { | 799 void CodeInstaller::site_Mark(CodeBuffer& buffer, jint pc_offset, oop site) { |
796 oop id_obj = CompilationResult_Mark::id(site); | 800 oop id_obj = CompilationResult_Mark::id(site); |
797 | 801 |