155 typeArrayHandle slots = RegisterSaveLayout::slots(callee_save_info); 156 for (jint i = 0; i < slots->length(); i++) { 157 Handle jvmci_reg = registers->obj_at(i); 158 jint jvmci_reg_number = code_Register::number(jvmci_reg); 159 VMReg hotspot_reg = CodeInstaller::get_hotspot_reg(jvmci_reg_number, CHECK_NULL); 160 // HotSpot stack slots are 4 bytes 161 jint jvmci_slot = slots->int_at(i); 162 jint hotspot_slot = jvmci_slot * VMRegImpl::slots_per_word; 163 VMReg hotspot_slot_as_reg = VMRegImpl::stack2reg(hotspot_slot); 164 map->set_callee_saved(hotspot_slot_as_reg, hotspot_reg); 165 #ifdef _LP64 166 // (copied from generate_oop_map() in c1_Runtime1_x86.cpp) 167 VMReg hotspot_slot_hi_as_reg = VMRegImpl::stack2reg(hotspot_slot + 1); 168 map->set_callee_saved(hotspot_slot_hi_as_reg, hotspot_reg->next()); 169 #endif 170 } 171 } 172 return map; 173 } 174 175 void* CodeInstaller::record_metadata_reference(Handle constant, TRAPS) { 176 /* 177 * This method needs to return a raw (untyped) pointer, since the value of a pointer to the base 178 * class is in general not equal to the pointer of the subclass. When patching metaspace pointers, 179 * the compiler expects a direct pointer to the subclass (Klass* or Method*), not a pointer to the 180 * base class (Metadata* or MetaspaceObj*). 181 */ 182 oop obj = HotSpotMetaspaceConstantImpl::metaspaceObject(constant); 183 if (obj->is_a(HotSpotResolvedObjectTypeImpl::klass())) { 184 Klass* klass = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(obj)); 185 assert(!HotSpotMetaspaceConstantImpl::compressed(constant), "unexpected compressed klass pointer %s @ " INTPTR_FORMAT, klass->name()->as_C_string(), p2i(klass)); 186 int index = _oop_recorder->find_index(klass); 187 TRACE_jvmci_3("metadata[%d of %d] = %s", index, _oop_recorder->metadata_count(), klass->name()->as_C_string()); 188 return klass; 189 } else if (obj->is_a(HotSpotResolvedJavaMethodImpl::klass())) { 190 Method* method = (Method*) (address) HotSpotResolvedJavaMethodImpl::metaspaceMethod(obj); 191 assert(!HotSpotMetaspaceConstantImpl::compressed(constant), "unexpected compressed method pointer %s @ " INTPTR_FORMAT, method->name()->as_C_string(), p2i(method)); 192 int index = _oop_recorder->find_index(method); 193 TRACE_jvmci_3("metadata[%d of %d] = %s", index, _oop_recorder->metadata_count(), method->name()->as_C_string()); 194 return method; 195 } else { 196 JVMCI_ERROR_NULL("unexpected metadata reference for constant of type %s", obj->klass()->signature_name()); 197 } 198 } 199 200 #ifdef _LP64 201 narrowKlass CodeInstaller::record_narrow_metadata_reference(Handle constant, TRAPS) { 202 oop obj = HotSpotMetaspaceConstantImpl::metaspaceObject(constant); 203 assert(HotSpotMetaspaceConstantImpl::compressed(constant), "unexpected uncompressed pointer"); 204 205 if (!obj->is_a(HotSpotResolvedObjectTypeImpl::klass())) { 206 JVMCI_ERROR_0("unexpected compressed pointer of type %s", obj->klass()->signature_name()); 207 } 208 209 Klass* klass = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(obj)); 210 int index = _oop_recorder->find_index(klass); 211 TRACE_jvmci_3("narrowKlass[%d of %d] = %s", index, _oop_recorder->metadata_count(), klass->name()->as_C_string()); 212 return Klass::encode_klass(klass); 213 } 214 #endif 215 216 Location::Type CodeInstaller::get_oop_type(Handle value) { 217 Handle valueKind = Value::valueKind(value); 218 Handle platformKind = ValueKind::platformKind(valueKind); 219 220 if (platformKind == word_kind()) { 221 return Location::oop; 222 } else { 223 return Location::narrowoop; 224 } 225 } 226 227 ScopeValue* CodeInstaller::get_scope_value(Handle value, BasicType type, GrowableArray<ScopeValue*>* objects, ScopeValue* &second, TRAPS) { 228 second = NULL; 229 if (value.is_null()) { 230 THROW_NULL(vmSymbols::java_lang_NullPointerException()); 684 for (int i = 0; i < data_section_patches()->length(); i++) { 685 Handle patch = data_section_patches()->obj_at(i); 686 if (patch.is_null()) { 687 THROW_(vmSymbols::java_lang_NullPointerException(), JVMCIEnv::ok); 688 } 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 *((void**) 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; | 155 typeArrayHandle slots = RegisterSaveLayout::slots(callee_save_info); 156 for (jint i = 0; i < slots->length(); i++) { 157 Handle jvmci_reg = registers->obj_at(i); 158 jint jvmci_reg_number = code_Register::number(jvmci_reg); 159 VMReg hotspot_reg = CodeInstaller::get_hotspot_reg(jvmci_reg_number, CHECK_NULL); 160 // HotSpot stack slots are 4 bytes 161 jint jvmci_slot = slots->int_at(i); 162 jint hotspot_slot = jvmci_slot * VMRegImpl::slots_per_word; 163 VMReg hotspot_slot_as_reg = VMRegImpl::stack2reg(hotspot_slot); 164 map->set_callee_saved(hotspot_slot_as_reg, hotspot_reg); 165 #ifdef _LP64 166 // (copied from generate_oop_map() in c1_Runtime1_x86.cpp) 167 VMReg hotspot_slot_hi_as_reg = VMRegImpl::stack2reg(hotspot_slot + 1); 168 map->set_callee_saved(hotspot_slot_hi_as_reg, hotspot_reg->next()); 169 #endif 170 } 171 } 172 return map; 173 } 174 175 void* CodeInstaller::record_metadata_reference(CodeSection* section, address dest, Handle constant, TRAPS) { 176 /* 177 * This method needs to return a raw (untyped) pointer, since the value of a pointer to the base 178 * class is in general not equal to the pointer of the subclass. When patching metaspace pointers, 179 * the compiler expects a direct pointer to the subclass (Klass* or Method*), not a pointer to the 180 * base class (Metadata* or MetaspaceObj*). 181 */ 182 oop obj = HotSpotMetaspaceConstantImpl::metaspaceObject(constant); 183 if (obj->is_a(HotSpotResolvedObjectTypeImpl::klass())) { 184 Klass* klass = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(obj)); 185 assert(!HotSpotMetaspaceConstantImpl::compressed(constant), "unexpected compressed klass pointer %s @ " INTPTR_FORMAT, klass->name()->as_C_string(), p2i(klass)); 186 int index = _oop_recorder->find_index(klass); 187 section->relocate(dest, metadata_Relocation::spec(index)); 188 TRACE_jvmci_3("metadata[%d of %d] = %s", index, _oop_recorder->metadata_count(), klass->name()->as_C_string()); 189 return klass; 190 } else if (obj->is_a(HotSpotResolvedJavaMethodImpl::klass())) { 191 Method* method = (Method*) (address) HotSpotResolvedJavaMethodImpl::metaspaceMethod(obj); 192 assert(!HotSpotMetaspaceConstantImpl::compressed(constant), "unexpected compressed method pointer %s @ " INTPTR_FORMAT, method->name()->as_C_string(), p2i(method)); 193 int index = _oop_recorder->find_index(method); 194 section->relocate(dest, metadata_Relocation::spec(index)); 195 TRACE_jvmci_3("metadata[%d of %d] = %s", index, _oop_recorder->metadata_count(), method->name()->as_C_string()); 196 return method; 197 } else { 198 JVMCI_ERROR_NULL("unexpected metadata reference for constant of type %s", obj->klass()->signature_name()); 199 } 200 } 201 202 #ifdef _LP64 203 narrowKlass CodeInstaller::record_narrow_metadata_reference(CodeSection* section, address dest, Handle constant, TRAPS) { 204 oop obj = HotSpotMetaspaceConstantImpl::metaspaceObject(constant); 205 assert(HotSpotMetaspaceConstantImpl::compressed(constant), "unexpected uncompressed pointer"); 206 207 if (!obj->is_a(HotSpotResolvedObjectTypeImpl::klass())) { 208 JVMCI_ERROR_0("unexpected compressed pointer of type %s", obj->klass()->signature_name()); 209 } 210 211 Klass* klass = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(obj)); 212 int index = _oop_recorder->find_index(klass); 213 section->relocate(dest, metadata_Relocation::spec(index)); 214 TRACE_jvmci_3("narrowKlass[%d of %d] = %s", index, _oop_recorder->metadata_count(), klass->name()->as_C_string()); 215 return Klass::encode_klass(klass); 216 } 217 #endif 218 219 Location::Type CodeInstaller::get_oop_type(Handle value) { 220 Handle valueKind = Value::valueKind(value); 221 Handle platformKind = ValueKind::platformKind(valueKind); 222 223 if (platformKind == word_kind()) { 224 return Location::oop; 225 } else { 226 return Location::narrowoop; 227 } 228 } 229 230 ScopeValue* CodeInstaller::get_scope_value(Handle value, BasicType type, GrowableArray<ScopeValue*>* objects, ScopeValue* &second, TRAPS) { 231 second = NULL; 232 if (value.is_null()) { 233 THROW_NULL(vmSymbols::java_lang_NullPointerException()); 687 for (int i = 0; i < data_section_patches()->length(); i++) { 688 Handle patch = data_section_patches()->obj_at(i); 689 if (patch.is_null()) { 690 THROW_(vmSymbols::java_lang_NullPointerException(), JVMCIEnv::ok); 691 } 692 Handle reference = site_DataPatch::reference(patch); 693 if (reference.is_null()) { 694 THROW_(vmSymbols::java_lang_NullPointerException(), JVMCIEnv::ok); 695 } 696 if (!reference->is_a(site_ConstantReference::klass())) { 697 JVMCI_ERROR_OK("invalid patch in data section: %s", reference->klass()->signature_name()); 698 } 699 Handle constant = site_ConstantReference::constant(reference); 700 if (constant.is_null()) { 701 THROW_(vmSymbols::java_lang_NullPointerException(), JVMCIEnv::ok); 702 } 703 address dest = _constants->start() + site_Site::pcOffset(patch); 704 if (constant->is_a(HotSpotMetaspaceConstantImpl::klass())) { 705 if (HotSpotMetaspaceConstantImpl::compressed(constant)) { 706 #ifdef _LP64 707 *((narrowKlass*) dest) = record_narrow_metadata_reference(_constants, dest, constant, CHECK_OK); 708 #else 709 JVMCI_ERROR_OK("unexpected compressed Klass* in 32-bit mode"); 710 #endif 711 } else { 712 *((void**) dest) = record_metadata_reference(_constants, dest, constant, CHECK_OK); 713 } 714 } else if (constant->is_a(HotSpotObjectConstantImpl::klass())) { 715 Handle obj = HotSpotObjectConstantImpl::object(constant); 716 jobject value = JNIHandles::make_local(obj()); 717 int oop_index = _oop_recorder->find_index(value); 718 719 if (HotSpotObjectConstantImpl::compressed(constant)) { 720 #ifdef _LP64 721 _constants->relocate(dest, oop_Relocation::spec(oop_index), relocInfo::narrow_oop_in_const); 722 #else 723 JVMCI_ERROR_OK("unexpected compressed oop in 32-bit mode"); 724 #endif 725 } else { 726 _constants->relocate(dest, oop_Relocation::spec(oop_index)); 727 } 728 } else { 729 JVMCI_ERROR_OK("invalid constant in data section: %s", constant->klass()->signature_name()); 730 } 731 } 732 jint last_pc_offset = -1; |