< prev index next >

src/share/vm/jvmci/jvmciCodeInstaller.cpp

Print this page




 160     typeArrayHandle slots = RegisterSaveLayout::slots(callee_save_info);
 161     for (jint i = 0; i < slots->length(); i++) {
 162       Handle jvmci_reg = registers->obj_at(i);
 163       jint jvmci_reg_number = code_Register::number(jvmci_reg);
 164       VMReg hotspot_reg = CodeInstaller::get_hotspot_reg(jvmci_reg_number, CHECK_NULL);
 165       // HotSpot stack slots are 4 bytes
 166       jint jvmci_slot = slots->int_at(i);
 167       jint hotspot_slot = jvmci_slot * VMRegImpl::slots_per_word;
 168       VMReg hotspot_slot_as_reg = VMRegImpl::stack2reg(hotspot_slot);
 169       map->set_callee_saved(hotspot_slot_as_reg, hotspot_reg);
 170 #ifdef _LP64
 171       // (copied from generate_oop_map() in c1_Runtime1_x86.cpp)
 172       VMReg hotspot_slot_hi_as_reg = VMRegImpl::stack2reg(hotspot_slot + 1);
 173       map->set_callee_saved(hotspot_slot_hi_as_reg, hotspot_reg->next());
 174 #endif
 175     }
 176   }
 177   return map;
 178 }
 179 
 180 Metadata* CodeInstaller::record_metadata_reference(Handle constant, TRAPS) {






 181   oop obj = HotSpotMetaspaceConstantImpl::metaspaceObject(constant);
 182   if (obj->is_a(HotSpotResolvedObjectTypeImpl::klass())) {
 183     Klass* klass = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(obj));
 184     assert(!HotSpotMetaspaceConstantImpl::compressed(constant), "unexpected compressed klass pointer %s @ " INTPTR_FORMAT, klass->name()->as_C_string(), p2i(klass));
 185     int index = _oop_recorder->find_index(klass);
 186     TRACE_jvmci_3("metadata[%d of %d] = %s", index, _oop_recorder->metadata_count(), klass->name()->as_C_string());
 187     return klass;
 188   } else if (obj->is_a(HotSpotResolvedJavaMethodImpl::klass())) {
 189     Method* method = (Method*) (address) HotSpotResolvedJavaMethodImpl::metaspaceMethod(obj);
 190     assert(!HotSpotMetaspaceConstantImpl::compressed(constant), "unexpected compressed method pointer %s @ " INTPTR_FORMAT, method->name()->as_C_string(), p2i(method));
 191     int index = _oop_recorder->find_index(method);
 192     TRACE_jvmci_3("metadata[%d of %d] = %s", index, _oop_recorder->metadata_count(), method->name()->as_C_string());
 193     return method;





 194   } else {
 195     JVMCI_ERROR_NULL("unexpected metadata reference for constant of type %s", obj->klass()->signature_name());
 196   }
 197 }
 198 
 199 #ifdef _LP64
 200 narrowKlass CodeInstaller::record_narrow_metadata_reference(Handle constant, TRAPS) {
 201   oop obj = HotSpotMetaspaceConstantImpl::metaspaceObject(constant);
 202   assert(HotSpotMetaspaceConstantImpl::compressed(constant), "unexpected uncompressed pointer");
 203 
 204   if (!obj->is_a(HotSpotResolvedObjectTypeImpl::klass())) {
 205     JVMCI_ERROR_0("unexpected compressed pointer of type %s", obj->klass()->signature_name());
 206   }
 207 
 208   Klass* klass = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(obj));
 209   int index = _oop_recorder->find_index(klass);
 210   TRACE_jvmci_3("narrowKlass[%d of %d] = %s", index, _oop_recorder->metadata_count(), klass->name()->as_C_string());
 211   return Klass::encode_klass(klass);
 212 }
 213 #endif


 689     Handle reference = site_DataPatch::reference(patch);
 690     if (reference.is_null()) {
 691       THROW_(vmSymbols::java_lang_NullPointerException(), JVMCIEnv::ok);
 692     }
 693     if (!reference->is_a(site_ConstantReference::klass())) {
 694       JVMCI_ERROR_OK("invalid patch in data section: %s", reference->klass()->signature_name());
 695     }
 696     Handle constant = site_ConstantReference::constant(reference);
 697     if (constant.is_null()) {
 698       THROW_(vmSymbols::java_lang_NullPointerException(), JVMCIEnv::ok);
 699     }
 700     address dest = _constants->start() + site_Site::pcOffset(patch);
 701     if (constant->is_a(HotSpotMetaspaceConstantImpl::klass())) {
 702       if (HotSpotMetaspaceConstantImpl::compressed(constant)) {
 703 #ifdef _LP64
 704         *((narrowKlass*) dest) = record_narrow_metadata_reference(constant, CHECK_OK);
 705 #else
 706         JVMCI_ERROR_OK("unexpected compressed Klass* in 32-bit mode");
 707 #endif
 708       } else {
 709         *((Metadata**) dest) = record_metadata_reference(constant, CHECK_OK);
 710       }
 711     } else if (constant->is_a(HotSpotObjectConstantImpl::klass())) {
 712       Handle obj = HotSpotObjectConstantImpl::object(constant);
 713       jobject value = JNIHandles::make_local(obj());
 714       int oop_index = _oop_recorder->find_index(value);
 715 
 716       if (HotSpotObjectConstantImpl::compressed(constant)) {
 717 #ifdef _LP64
 718         _constants->relocate(dest, oop_Relocation::spec(oop_index), relocInfo::narrow_oop_in_const);
 719 #else
 720         JVMCI_ERROR_OK("unexpected compressed oop in 32-bit mode");
 721 #endif
 722       } else {
 723         _constants->relocate(dest, oop_Relocation::spec(oop_index));
 724       }
 725     } else {
 726       JVMCI_ERROR_OK("invalid constant in data section: %s", constant->klass()->signature_name());
 727     }
 728   }
 729   jint last_pc_offset = -1;




 160     typeArrayHandle slots = RegisterSaveLayout::slots(callee_save_info);
 161     for (jint i = 0; i < slots->length(); i++) {
 162       Handle jvmci_reg = registers->obj_at(i);
 163       jint jvmci_reg_number = code_Register::number(jvmci_reg);
 164       VMReg hotspot_reg = CodeInstaller::get_hotspot_reg(jvmci_reg_number, CHECK_NULL);
 165       // HotSpot stack slots are 4 bytes
 166       jint jvmci_slot = slots->int_at(i);
 167       jint hotspot_slot = jvmci_slot * VMRegImpl::slots_per_word;
 168       VMReg hotspot_slot_as_reg = VMRegImpl::stack2reg(hotspot_slot);
 169       map->set_callee_saved(hotspot_slot_as_reg, hotspot_reg);
 170 #ifdef _LP64
 171       // (copied from generate_oop_map() in c1_Runtime1_x86.cpp)
 172       VMReg hotspot_slot_hi_as_reg = VMRegImpl::stack2reg(hotspot_slot + 1);
 173       map->set_callee_saved(hotspot_slot_hi_as_reg, hotspot_reg->next());
 174 #endif
 175     }
 176   }
 177   return map;
 178 }
 179 
 180 void* CodeInstaller::record_metadata_reference(Handle constant, TRAPS) {
 181   /*
 182    * This method needs to return a raw (untyped) pointer, since the value of a pointer to the base
 183    * class is in general not equal to the pointer of the subclass. When patching metaspace pointers,
 184    * the compiler expects a direct pointer to the subclass (Klass*, Method* or Symbol*), not a
 185    * pointer to the base class (Metadata* or MetaspaceObj*).
 186    */
 187   oop obj = HotSpotMetaspaceConstantImpl::metaspaceObject(constant);
 188   if (obj->is_a(HotSpotResolvedObjectTypeImpl::klass())) {
 189     Klass* klass = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(obj));
 190     assert(!HotSpotMetaspaceConstantImpl::compressed(constant), "unexpected compressed klass pointer %s @ " INTPTR_FORMAT, klass->name()->as_C_string(), p2i(klass));
 191     int index = _oop_recorder->find_index(klass);
 192     TRACE_jvmci_3("metadata[%d of %d] = %s", index, _oop_recorder->metadata_count(), klass->name()->as_C_string());
 193     return klass;
 194   } else if (obj->is_a(HotSpotResolvedJavaMethodImpl::klass())) {
 195     Method* method = (Method*) (address) HotSpotResolvedJavaMethodImpl::metaspaceMethod(obj);
 196     assert(!HotSpotMetaspaceConstantImpl::compressed(constant), "unexpected compressed method pointer %s @ " INTPTR_FORMAT, method->name()->as_C_string(), p2i(method));
 197     int index = _oop_recorder->find_index(method);
 198     TRACE_jvmci_3("metadata[%d of %d] = %s", index, _oop_recorder->metadata_count(), method->name()->as_C_string());
 199     return method;
 200   } else if (obj->is_a(HotSpotSymbol::klass())) {
 201     Symbol* symbol = (Symbol*) (address) HotSpotSymbol::pointer(obj);
 202     assert(!HotSpotMetaspaceConstantImpl::compressed(constant), "unexpected compressed symbol pointer %s @ " INTPTR_FORMAT, symbol->as_C_string(), p2i(symbol));
 203     TRACE_jvmci_3("symbol = %s", symbol->as_C_string());
 204     return symbol;
 205   } else {
 206     JVMCI_ERROR_NULL("unexpected metadata reference for constant of type %s", obj->klass()->signature_name());
 207   }
 208 }
 209 
 210 #ifdef _LP64
 211 narrowKlass CodeInstaller::record_narrow_metadata_reference(Handle constant, TRAPS) {
 212   oop obj = HotSpotMetaspaceConstantImpl::metaspaceObject(constant);
 213   assert(HotSpotMetaspaceConstantImpl::compressed(constant), "unexpected uncompressed pointer");
 214 
 215   if (!obj->is_a(HotSpotResolvedObjectTypeImpl::klass())) {
 216     JVMCI_ERROR_0("unexpected compressed pointer of type %s", obj->klass()->signature_name());
 217   }
 218 
 219   Klass* klass = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(obj));
 220   int index = _oop_recorder->find_index(klass);
 221   TRACE_jvmci_3("narrowKlass[%d of %d] = %s", index, _oop_recorder->metadata_count(), klass->name()->as_C_string());
 222   return Klass::encode_klass(klass);
 223 }
 224 #endif


 700     Handle reference = site_DataPatch::reference(patch);
 701     if (reference.is_null()) {
 702       THROW_(vmSymbols::java_lang_NullPointerException(), JVMCIEnv::ok);
 703     }
 704     if (!reference->is_a(site_ConstantReference::klass())) {
 705       JVMCI_ERROR_OK("invalid patch in data section: %s", reference->klass()->signature_name());
 706     }
 707     Handle constant = site_ConstantReference::constant(reference);
 708     if (constant.is_null()) {
 709       THROW_(vmSymbols::java_lang_NullPointerException(), JVMCIEnv::ok);
 710     }
 711     address dest = _constants->start() + site_Site::pcOffset(patch);
 712     if (constant->is_a(HotSpotMetaspaceConstantImpl::klass())) {
 713       if (HotSpotMetaspaceConstantImpl::compressed(constant)) {
 714 #ifdef _LP64
 715         *((narrowKlass*) dest) = record_narrow_metadata_reference(constant, CHECK_OK);
 716 #else
 717         JVMCI_ERROR_OK("unexpected compressed Klass* in 32-bit mode");
 718 #endif
 719       } else {
 720         *((void**) dest) = record_metadata_reference(constant, CHECK_OK);
 721       }
 722     } else if (constant->is_a(HotSpotObjectConstantImpl::klass())) {
 723       Handle obj = HotSpotObjectConstantImpl::object(constant);
 724       jobject value = JNIHandles::make_local(obj());
 725       int oop_index = _oop_recorder->find_index(value);
 726 
 727       if (HotSpotObjectConstantImpl::compressed(constant)) {
 728 #ifdef _LP64
 729         _constants->relocate(dest, oop_Relocation::spec(oop_index), relocInfo::narrow_oop_in_const);
 730 #else
 731         JVMCI_ERROR_OK("unexpected compressed oop in 32-bit mode");
 732 #endif
 733       } else {
 734         _constants->relocate(dest, oop_Relocation::spec(oop_index));
 735       }
 736     } else {
 737       JVMCI_ERROR_OK("invalid constant in data section: %s", constant->klass()->signature_name());
 738     }
 739   }
 740   jint last_pc_offset = -1;


< prev index next >