hotspot/src/share/vm/jvmci/jvmciCodeInstaller.cpp
changeset 33632 038347770a9e
parent 33198 b37ad9fbf681
child 34153 cbcfa2a6fe0b
equal deleted inserted replaced
33631:3eee32561662 33632:038347770a9e
   140     }
   140     }
   141   }
   141   }
   142   return map;
   142   return map;
   143 }
   143 }
   144 
   144 
   145 static void record_metadata_reference(oop obj, jlong prim, jboolean compressed, OopRecorder* oop_recorder) {
   145 Metadata* CodeInstaller::record_metadata_reference(Handle& constant) {
       
   146   oop obj = HotSpotMetaspaceConstantImpl::metaspaceObject(constant);
   146   if (obj->is_a(HotSpotResolvedObjectTypeImpl::klass())) {
   147   if (obj->is_a(HotSpotResolvedObjectTypeImpl::klass())) {
   147     Klass* klass = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(obj));
   148     Klass* klass = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(obj));
   148     if (compressed) {
   149     assert(!HotSpotMetaspaceConstantImpl::compressed(constant), "unexpected compressed klass pointer %s @ " INTPTR_FORMAT, klass->name()->as_C_string(), p2i(klass));
   149       assert(Klass::decode_klass((narrowKlass) prim) == klass, "%s @ " INTPTR_FORMAT " != " PTR64_FORMAT, klass->name()->as_C_string(), p2i(klass), prim);
   150     int index = _oop_recorder->find_index(klass);
   150     } else {
   151     TRACE_jvmci_3("metadata[%d of %d] = %s", index, _oop_recorder->metadata_count(), klass->name()->as_C_string());
   151       assert((Klass*) prim == klass, "%s @ " INTPTR_FORMAT " != " PTR64_FORMAT, klass->name()->as_C_string(), p2i(klass), prim);
   152     return klass;
   152     }
       
   153     int index = oop_recorder->find_index(klass);
       
   154     TRACE_jvmci_3("metadata[%d of %d] = %s", index, oop_recorder->metadata_count(), klass->name()->as_C_string());
       
   155   } else if (obj->is_a(HotSpotResolvedJavaMethodImpl::klass())) {
   153   } else if (obj->is_a(HotSpotResolvedJavaMethodImpl::klass())) {
   156     Method* method = (Method*) (address) HotSpotResolvedJavaMethodImpl::metaspaceMethod(obj);
   154     Method* method = (Method*) (address) HotSpotResolvedJavaMethodImpl::metaspaceMethod(obj);
   157     assert(!compressed, "unexpected compressed method pointer %s @ " INTPTR_FORMAT " = " PTR64_FORMAT, method->name()->as_C_string(), p2i(method), prim);
   155     assert(!HotSpotMetaspaceConstantImpl::compressed(constant), "unexpected compressed method pointer %s @ " INTPTR_FORMAT, method->name()->as_C_string(), p2i(method));
   158     int index = oop_recorder->find_index(method);
   156     int index = _oop_recorder->find_index(method);
   159     TRACE_jvmci_3("metadata[%d of %d] = %s", index, oop_recorder->metadata_count(), method->name()->as_C_string());
   157     TRACE_jvmci_3("metadata[%d of %d] = %s", index, _oop_recorder->metadata_count(), method->name()->as_C_string());
       
   158     return method;
   160   } else {
   159   } else {
   161     assert(java_lang_String::is_instance(obj),
   160     fatal("unexpected metadata reference for constant of type %s", obj->klass()->name()->as_C_string());
   162         "unexpected metadata reference (%s) for constant " JLONG_FORMAT " (" PTR64_FORMAT ")", obj->klass()->name()->as_C_string(), prim, prim);
   161     return NULL;
   163   }
   162   }
   164 }
   163 }
   165 
   164 
   166 // Records any Metadata values embedded in a Constant (e.g., the value returned by HotSpotResolvedObjectTypeImpl.klass()).
   165 #ifdef _LP64
   167 static void record_metadata_in_constant(oop constant, OopRecorder* oop_recorder) {
   166 narrowKlass CodeInstaller::record_narrow_metadata_reference(Handle& constant) {
   168   if (constant->is_a(HotSpotMetaspaceConstantImpl::klass())) {
   167   oop obj = HotSpotMetaspaceConstantImpl::metaspaceObject(constant);
   169     oop obj = HotSpotMetaspaceConstantImpl::metaspaceObject(constant);
   168   assert(HotSpotMetaspaceConstantImpl::compressed(constant), "unexpected uncompressed pointer");
   170     jlong prim = HotSpotMetaspaceConstantImpl::primitive(constant);
   169   assert(obj->is_a(HotSpotResolvedObjectTypeImpl::klass()), "unexpected compressed pointer of type %s", obj->klass()->name()->as_C_string());
   171     assert(obj != NULL, "must have an object");
   170 
   172     assert(prim != 0, "must have a primitive value");
   171   Klass* klass = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(obj));
   173 
   172   int index = _oop_recorder->find_index(klass);
   174     record_metadata_reference(obj, prim, false, oop_recorder);
   173   TRACE_jvmci_3("narrowKlass[%d of %d] = %s", index, _oop_recorder->metadata_count(), klass->name()->as_C_string());
   175   }
   174   return Klass::encode_klass(klass);
   176 }
   175 }
   177 
   176 #endif
   178 static void record_metadata_in_patch(Handle& constant, OopRecorder* oop_recorder) {
       
   179   record_metadata_reference(HotSpotMetaspaceConstantImpl::metaspaceObject(constant), HotSpotMetaspaceConstantImpl::primitive(constant), HotSpotMetaspaceConstantImpl::compressed(constant), oop_recorder);
       
   180 }
       
   181 
   177 
   182 Location::Type CodeInstaller::get_oop_type(oop value) {
   178 Location::Type CodeInstaller::get_oop_type(oop value) {
   183   oop lirKind = Value::lirKind(value);
   179   oop lirKind = Value::lirKind(value);
   184   oop platformKind = LIRKind::platformKind(lirKind);
   180   oop platformKind = LIRKind::platformKind(lirKind);
   185   assert(LIRKind::referenceMask(lirKind) == 1, "unexpected referenceMask");
   181   assert(LIRKind::referenceMask(lirKind) == 1, "unexpected referenceMask");
   251     if (type == T_DOUBLE || type == T_LONG) {
   247     if (type == T_DOUBLE || type == T_LONG) {
   252       second = value;
   248       second = value;
   253     }
   249     }
   254     return value;
   250     return value;
   255   } else if (value->is_a(JavaConstant::klass())) {
   251   } else if (value->is_a(JavaConstant::klass())) {
   256     record_metadata_in_constant(value, _oop_recorder);
       
   257     if (value->is_a(PrimitiveConstant::klass())) {
   252     if (value->is_a(PrimitiveConstant::klass())) {
   258       if (value->is_a(RawConstant::klass())) {
   253       if (value->is_a(RawConstant::klass())) {
   259         jlong prim = PrimitiveConstant::primitive(value);
   254         jlong prim = PrimitiveConstant::primitive(value);
   260         return new ConstantLongValue(prim);
   255         return new ConstantLongValue(prim);
   261       } else {
   256       } else {
   377           fatal("unexpected Assumption subclass");
   372           fatal("unexpected Assumption subclass");
   378         }
   373         }
   379       }
   374       }
   380     }
   375     }
   381   }
   376   }
   382   objArrayHandle methods = HotSpotCompiledCode::methods(compiled_code);
   377   if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
   383   if (!methods.is_null()) {
   378     objArrayHandle methods = HotSpotCompiledCode::methods(compiled_code);
   384     int length = methods->length();
   379     if (!methods.is_null()) {
   385     for (int i = 0; i < length; ++i) {
   380       int length = methods->length();
   386       Handle method_handle = methods->obj_at(i);
   381       for (int i = 0; i < length; ++i) {
   387       methodHandle method = getMethodFromHotSpotMethod(method_handle());
   382         Handle method_handle = methods->obj_at(i);
   388 
   383         methodHandle method = getMethodFromHotSpotMethod(method_handle());
   389       _dependencies->assert_evol_method(method());
   384         _dependencies->assert_evol_method(method());
       
   385       }
   390     }
   386     }
   391   }
   387   }
   392 }
   388 }
   393 
   389 
   394 RelocBuffer::~RelocBuffer() {
   390 RelocBuffer::~RelocBuffer() {
   541   oop arch = TargetDescription::arch(target);
   537   oop arch = TargetDescription::arch(target);
   542   _word_kind_handle = JNIHandles::make_local(Architecture::wordKind(arch));
   538   _word_kind_handle = JNIHandles::make_local(Architecture::wordKind(arch));
   543 }
   539 }
   544 
   540 
   545 int CodeInstaller::estimate_stubs_size() {
   541 int CodeInstaller::estimate_stubs_size() {
   546   // Return size for all stubs.
   542   // Estimate the number of static call stubs that might be emitted.
   547   int static_call_stubs = 0;
   543   int static_call_stubs = 0;
   548   objArrayOop sites = this->sites();
   544   objArrayOop sites = this->sites();
   549   for (int i = 0; i < sites->length(); i++) {
   545   for (int i = 0; i < sites->length(); i++) {
   550     oop site = sites->obj_at(i);
   546     oop site = sites->obj_at(i);
   551     if (site->is_a(CompilationResult_Mark::klass())) {
   547     if (site->is_a(CompilationResult_Mark::klass())) {
   562   return static_call_stubs * CompiledStaticCall::to_interp_stub_size();
   558   return static_call_stubs * CompiledStaticCall::to_interp_stub_size();
   563 }
   559 }
   564 
   560 
   565 // perform data and call relocation on the CodeBuffer
   561 // perform data and call relocation on the CodeBuffer
   566 JVMCIEnv::CodeInstallResult CodeInstaller::initialize_buffer(CodeBuffer& buffer) {
   562 JVMCIEnv::CodeInstallResult CodeInstaller::initialize_buffer(CodeBuffer& buffer) {
       
   563   HandleMark hm;
   567   objArrayHandle sites = this->sites();
   564   objArrayHandle sites = this->sites();
   568   int locs_buffer_size = sites->length() * (relocInfo::length_limit + sizeof(relocInfo));
   565   int locs_buffer_size = sites->length() * (relocInfo::length_limit + sizeof(relocInfo));
   569 
   566 
   570   // Allocate enough space in the stub section for the static call
   567   // Allocate enough space in the stub section for the static call
   571   // stubs.  Stubs have extra relocs but they are managed by the stub
   568   // stubs.  Stubs have extra relocs but they are managed by the stub
   604   for (int i = 0; i < data_section_patches()->length(); i++) {
   601   for (int i = 0; i < data_section_patches()->length(); i++) {
   605     Handle patch = data_section_patches()->obj_at(i);
   602     Handle patch = data_section_patches()->obj_at(i);
   606     Handle reference = CompilationResult_DataPatch::reference(patch);
   603     Handle reference = CompilationResult_DataPatch::reference(patch);
   607     assert(reference->is_a(CompilationResult_ConstantReference::klass()), "patch in data section must be a ConstantReference");
   604     assert(reference->is_a(CompilationResult_ConstantReference::klass()), "patch in data section must be a ConstantReference");
   608     Handle constant = CompilationResult_ConstantReference::constant(reference);
   605     Handle constant = CompilationResult_ConstantReference::constant(reference);
       
   606     address dest = _constants->start() + CompilationResult_Site::pcOffset(patch);
   609     if (constant->is_a(HotSpotMetaspaceConstantImpl::klass())) {
   607     if (constant->is_a(HotSpotMetaspaceConstantImpl::klass())) {
   610       record_metadata_in_patch(constant, _oop_recorder);
   608       if (HotSpotMetaspaceConstantImpl::compressed(constant)) {
       
   609 #ifdef _LP64
       
   610         *((narrowKlass*) dest) = record_narrow_metadata_reference(constant);
       
   611 #else
       
   612         fatal("unexpected compressed Klass* in 32-bit mode");
       
   613 #endif
       
   614       } else {
       
   615         *((Metadata**) dest) = record_metadata_reference(constant);
       
   616       }
   611     } else if (constant->is_a(HotSpotObjectConstantImpl::klass())) {
   617     } else if (constant->is_a(HotSpotObjectConstantImpl::klass())) {
   612       Handle obj = HotSpotObjectConstantImpl::object(constant);
   618       Handle obj = HotSpotObjectConstantImpl::object(constant);
   613       jobject value = JNIHandles::make_local(obj());
   619       jobject value = JNIHandles::make_local(obj());
   614       int oop_index = _oop_recorder->find_index(value);
   620       int oop_index = _oop_recorder->find_index(value);
   615 
   621 
   616       address dest = _constants->start() + CompilationResult_Site::pcOffset(patch);
       
   617       if (HotSpotObjectConstantImpl::compressed(constant)) {
   622       if (HotSpotObjectConstantImpl::compressed(constant)) {
   618 #ifdef _LP64
   623 #ifdef _LP64
   619         _constants->relocate(dest, oop_Relocation::spec(oop_index), relocInfo::narrow_oop_in_const);
   624         _constants->relocate(dest, oop_Relocation::spec(oop_index), relocInfo::narrow_oop_in_const);
   620 #else
   625 #else
   621         fatal("unexpected compressed oop in 32-bit mode");
   626         fatal("unexpected compressed oop in 32-bit mode");
   958   if (reference->is_a(CompilationResult_ConstantReference::klass())) {
   963   if (reference->is_a(CompilationResult_ConstantReference::klass())) {
   959     Handle constant = CompilationResult_ConstantReference::constant(reference);
   964     Handle constant = CompilationResult_ConstantReference::constant(reference);
   960     if (constant->is_a(HotSpotObjectConstantImpl::klass())) {
   965     if (constant->is_a(HotSpotObjectConstantImpl::klass())) {
   961       pd_patch_OopConstant(pc_offset, constant);
   966       pd_patch_OopConstant(pc_offset, constant);
   962     } else if (constant->is_a(HotSpotMetaspaceConstantImpl::klass())) {
   967     } else if (constant->is_a(HotSpotMetaspaceConstantImpl::klass())) {
   963       record_metadata_in_patch(constant, _oop_recorder);
   968       pd_patch_MetaspaceConstant(pc_offset, constant);
   964     } else if (constant->is_a(HotSpotSentinelConstant::klass())) {
   969     } else if (constant->is_a(HotSpotSentinelConstant::klass())) {
   965       fatal("sentinel constant unsupported");
   970       fatal("sentinel constant unsupported");
   966     } else {
   971     } else {
   967       fatal("unknown constant type in data patch");
   972       fatal("unknown constant type in data patch");
   968     }
   973     }
  1012       case POLL_FAR:
  1017       case POLL_FAR:
  1013       case POLL_RETURN_NEAR:
  1018       case POLL_RETURN_NEAR:
  1014       case POLL_RETURN_FAR:
  1019       case POLL_RETURN_FAR:
  1015         pd_relocate_poll(pc, id);
  1020         pd_relocate_poll(pc, id);
  1016         break;
  1021         break;
       
  1022       case CARD_TABLE_SHIFT:
  1017       case CARD_TABLE_ADDRESS:
  1023       case CARD_TABLE_ADDRESS:
  1018       case HEAP_TOP_ADDRESS:
  1024       case HEAP_TOP_ADDRESS:
  1019       case HEAP_END_ADDRESS:
  1025       case HEAP_END_ADDRESS:
  1020       case NARROW_KLASS_BASE_ADDRESS:
  1026       case NARROW_KLASS_BASE_ADDRESS:
  1021       case CRC_TABLE_ADDRESS:
  1027       case CRC_TABLE_ADDRESS: