< prev index next >

src/hotspot/share/runtime/deoptimization.cpp

Print this page



  33 #include "code/nmethod.hpp"
  34 #include "code/pcDesc.hpp"
  35 #include "code/scopeDesc.hpp"
  36 #include "compiler/compilationPolicy.hpp"
  37 #include "interpreter/bytecode.hpp"
  38 #include "interpreter/interpreter.hpp"
  39 #include "interpreter/oopMapCache.hpp"
  40 #include "memory/allocation.inline.hpp"
  41 #include "memory/oopFactory.hpp"
  42 #include "memory/resourceArea.hpp"
  43 #include "memory/universe.hpp"
  44 #include "oops/constantPool.hpp"
  45 #include "oops/method.hpp"
  46 #include "oops/objArrayKlass.hpp"
  47 #include "oops/objArrayOop.inline.hpp"
  48 #include "oops/oop.inline.hpp"
  49 #include "oops/fieldStreams.inline.hpp"
  50 #include "oops/typeArrayOop.inline.hpp"
  51 #include "oops/verifyOopClosure.hpp"
  52 #include "prims/jvmtiThreadState.hpp"

  53 #include "runtime/atomic.hpp"
  54 #include "runtime/biasedLocking.hpp"
  55 #include "runtime/deoptimization.hpp"
  56 #include "runtime/fieldDescriptor.hpp"
  57 #include "runtime/fieldDescriptor.inline.hpp"
  58 #include "runtime/frame.inline.hpp"
  59 #include "runtime/handles.inline.hpp"
  60 #include "runtime/interfaceSupport.inline.hpp"
  61 #include "runtime/jniHandles.inline.hpp"
  62 #include "runtime/safepointVerifiers.hpp"
  63 #include "runtime/sharedRuntime.hpp"
  64 #include "runtime/signature.hpp"
  65 #include "runtime/stubRoutines.hpp"
  66 #include "runtime/thread.hpp"
  67 #include "runtime/threadSMR.hpp"
  68 #include "runtime/vframe.hpp"
  69 #include "runtime/vframeArray.hpp"
  70 #include "runtime/vframe_hp.hpp"
  71 #include "utilities/events.hpp"
  72 #include "utilities/macros.hpp"


 984     assert(objects->at(i)->is_object(), "invalid debug information");
 985     ObjectValue* sv = (ObjectValue*) objects->at(i);
 986 
 987     Klass* k = java_lang_Class::as_Klass(sv->klass()->as_ConstantOopReadValue()->value()());
 988     oop obj = NULL;
 989 
 990     if (k->is_instance_klass()) {
 991 #if INCLUDE_JVMCI || INCLUDE_AOT
 992       CompiledMethod* cm = fr->cb()->as_compiled_method_or_null();
 993       if (cm->is_compiled_by_jvmci() && sv->is_auto_box()) {
 994         AutoBoxObjectValue* abv = (AutoBoxObjectValue*) sv;
 995         obj = get_cached_box(abv, fr, reg_map, THREAD);
 996         if (obj != NULL) {
 997           // Set the flag to indicate the box came from a cache, so that we can skip the field reassignment for it.
 998           abv->set_cached(true);
 999         }
1000       }
1001 #endif // INCLUDE_JVMCI || INCLUDE_AOT
1002       InstanceKlass* ik = InstanceKlass::cast(k);
1003       if (obj == NULL) {







1004         obj = ik->allocate_instance(THREAD);

1005       }
1006     } else if (k->is_typeArray_klass()) {
1007       TypeArrayKlass* ak = TypeArrayKlass::cast(k);
1008       assert(sv->field_size() % type2size[ak->element_type()] == 0, "non-integral array length");
1009       int len = sv->field_size() / type2size[ak->element_type()];
1010       obj = ak->allocate(len, THREAD);
1011     } else if (k->is_objArray_klass()) {
1012       ObjArrayKlass* ak = ObjArrayKlass::cast(k);
1013       obj = ak->allocate(sv->field_size(), THREAD);
1014     }
1015 
1016     if (obj == NULL) {
1017       failures = true;
1018     }
1019 
1020     assert(sv->value().is_null(), "redundant reallocation");
1021     assert(obj != NULL || HAS_PENDING_EXCEPTION, "allocation should succeed or we should get an exception");
1022     CLEAR_PENDING_EXCEPTION;
1023     sv->set_value(obj);
1024   }


1264 
1265 // restore fields of all eliminated objects and arrays
1266 void Deoptimization::reassign_fields(frame* fr, RegisterMap* reg_map, GrowableArray<ScopeValue*>* objects, bool realloc_failures, bool skip_internal) {
1267   for (int i = 0; i < objects->length(); i++) {
1268     ObjectValue* sv = (ObjectValue*) objects->at(i);
1269     Klass* k = java_lang_Class::as_Klass(sv->klass()->as_ConstantOopReadValue()->value()());
1270     Handle obj = sv->value();
1271     assert(obj.not_null() || realloc_failures, "reallocation was missed");
1272     if (PrintDeoptimizationDetails) {
1273       tty->print_cr("reassign fields for object of type %s!", k->name()->as_C_string());
1274     }
1275     if (obj.is_null()) {
1276       continue;
1277     }
1278 #if INCLUDE_JVMCI || INCLUDE_AOT
1279     // Don't reassign fields of boxes that came from a cache. Caches may be in CDS.
1280     if (sv->is_auto_box() && ((AutoBoxObjectValue*) sv)->is_cached()) {
1281       continue;
1282     }
1283 #endif // INCLUDE_JVMCI || INCLUDE_AOT





1284     if (k->is_instance_klass()) {
1285       InstanceKlass* ik = InstanceKlass::cast(k);
1286       reassign_fields_by_klass(ik, fr, reg_map, sv, 0, obj(), skip_internal);
1287     } else if (k->is_typeArray_klass()) {
1288       TypeArrayKlass* ak = TypeArrayKlass::cast(k);
1289       reassign_type_array_elements(fr, reg_map, sv, (typeArrayOop) obj(), ak->element_type());
1290     } else if (k->is_objArray_klass()) {
1291       reassign_object_array_elements(fr, reg_map, sv, (objArrayOop) obj());
1292     }
1293   }
1294 }
1295 
1296 
1297 // relock objects for which synchronization was eliminated
1298 void Deoptimization::relock_objects(GrowableArray<MonitorInfo*>* monitors, JavaThread* thread, bool realloc_failures) {
1299   for (int i = 0; i < monitors->length(); i++) {
1300     MonitorInfo* mon_info = monitors->at(i);
1301     if (mon_info->eliminated()) {
1302       assert(!mon_info->owner_is_scalar_replaced() || realloc_failures, "reallocation was missed");
1303       if (!mon_info->owner_is_scalar_replaced()) {



  33 #include "code/nmethod.hpp"
  34 #include "code/pcDesc.hpp"
  35 #include "code/scopeDesc.hpp"
  36 #include "compiler/compilationPolicy.hpp"
  37 #include "interpreter/bytecode.hpp"
  38 #include "interpreter/interpreter.hpp"
  39 #include "interpreter/oopMapCache.hpp"
  40 #include "memory/allocation.inline.hpp"
  41 #include "memory/oopFactory.hpp"
  42 #include "memory/resourceArea.hpp"
  43 #include "memory/universe.hpp"
  44 #include "oops/constantPool.hpp"
  45 #include "oops/method.hpp"
  46 #include "oops/objArrayKlass.hpp"
  47 #include "oops/objArrayOop.inline.hpp"
  48 #include "oops/oop.inline.hpp"
  49 #include "oops/fieldStreams.inline.hpp"
  50 #include "oops/typeArrayOop.inline.hpp"
  51 #include "oops/verifyOopClosure.hpp"
  52 #include "prims/jvmtiThreadState.hpp"
  53 #include "prims/vectorSupport.hpp"
  54 #include "runtime/atomic.hpp"
  55 #include "runtime/biasedLocking.hpp"
  56 #include "runtime/deoptimization.hpp"
  57 #include "runtime/fieldDescriptor.hpp"
  58 #include "runtime/fieldDescriptor.inline.hpp"
  59 #include "runtime/frame.inline.hpp"
  60 #include "runtime/handles.inline.hpp"
  61 #include "runtime/interfaceSupport.inline.hpp"
  62 #include "runtime/jniHandles.inline.hpp"
  63 #include "runtime/safepointVerifiers.hpp"
  64 #include "runtime/sharedRuntime.hpp"
  65 #include "runtime/signature.hpp"
  66 #include "runtime/stubRoutines.hpp"
  67 #include "runtime/thread.hpp"
  68 #include "runtime/threadSMR.hpp"
  69 #include "runtime/vframe.hpp"
  70 #include "runtime/vframeArray.hpp"
  71 #include "runtime/vframe_hp.hpp"
  72 #include "utilities/events.hpp"
  73 #include "utilities/macros.hpp"


 985     assert(objects->at(i)->is_object(), "invalid debug information");
 986     ObjectValue* sv = (ObjectValue*) objects->at(i);
 987 
 988     Klass* k = java_lang_Class::as_Klass(sv->klass()->as_ConstantOopReadValue()->value()());
 989     oop obj = NULL;
 990 
 991     if (k->is_instance_klass()) {
 992 #if INCLUDE_JVMCI || INCLUDE_AOT
 993       CompiledMethod* cm = fr->cb()->as_compiled_method_or_null();
 994       if (cm->is_compiled_by_jvmci() && sv->is_auto_box()) {
 995         AutoBoxObjectValue* abv = (AutoBoxObjectValue*) sv;
 996         obj = get_cached_box(abv, fr, reg_map, THREAD);
 997         if (obj != NULL) {
 998           // Set the flag to indicate the box came from a cache, so that we can skip the field reassignment for it.
 999           abv->set_cached(true);
1000         }
1001       }
1002 #endif // INCLUDE_JVMCI || INCLUDE_AOT
1003       InstanceKlass* ik = InstanceKlass::cast(k);
1004       if (obj == NULL) {
1005 #ifdef COMPILER2
1006         if (EnableVectorSupport && VectorSupport::is_vector(ik)) {
1007           obj = VectorSupport::allocate_vector(ik, fr, reg_map, sv, THREAD);
1008         } else {
1009           obj = ik->allocate_instance(THREAD);
1010         }
1011 #else
1012         obj = ik->allocate_instance(THREAD);
1013 #endif // COMPILER2
1014       }
1015     } else if (k->is_typeArray_klass()) {
1016       TypeArrayKlass* ak = TypeArrayKlass::cast(k);
1017       assert(sv->field_size() % type2size[ak->element_type()] == 0, "non-integral array length");
1018       int len = sv->field_size() / type2size[ak->element_type()];
1019       obj = ak->allocate(len, THREAD);
1020     } else if (k->is_objArray_klass()) {
1021       ObjArrayKlass* ak = ObjArrayKlass::cast(k);
1022       obj = ak->allocate(sv->field_size(), THREAD);
1023     }
1024 
1025     if (obj == NULL) {
1026       failures = true;
1027     }
1028 
1029     assert(sv->value().is_null(), "redundant reallocation");
1030     assert(obj != NULL || HAS_PENDING_EXCEPTION, "allocation should succeed or we should get an exception");
1031     CLEAR_PENDING_EXCEPTION;
1032     sv->set_value(obj);
1033   }


1273 
1274 // restore fields of all eliminated objects and arrays
1275 void Deoptimization::reassign_fields(frame* fr, RegisterMap* reg_map, GrowableArray<ScopeValue*>* objects, bool realloc_failures, bool skip_internal) {
1276   for (int i = 0; i < objects->length(); i++) {
1277     ObjectValue* sv = (ObjectValue*) objects->at(i);
1278     Klass* k = java_lang_Class::as_Klass(sv->klass()->as_ConstantOopReadValue()->value()());
1279     Handle obj = sv->value();
1280     assert(obj.not_null() || realloc_failures, "reallocation was missed");
1281     if (PrintDeoptimizationDetails) {
1282       tty->print_cr("reassign fields for object of type %s!", k->name()->as_C_string());
1283     }
1284     if (obj.is_null()) {
1285       continue;
1286     }
1287 #if INCLUDE_JVMCI || INCLUDE_AOT
1288     // Don't reassign fields of boxes that came from a cache. Caches may be in CDS.
1289     if (sv->is_auto_box() && ((AutoBoxObjectValue*) sv)->is_cached()) {
1290       continue;
1291     }
1292 #endif // INCLUDE_JVMCI || INCLUDE_AOT
1293 #ifdef COMPILER2
1294     if (EnableVectorSupport && VectorSupport::is_vector(k)) {
1295       continue; // skip field reassignment for vectors
1296     }
1297 #endif
1298     if (k->is_instance_klass()) {
1299       InstanceKlass* ik = InstanceKlass::cast(k);
1300       reassign_fields_by_klass(ik, fr, reg_map, sv, 0, obj(), skip_internal);
1301     } else if (k->is_typeArray_klass()) {
1302       TypeArrayKlass* ak = TypeArrayKlass::cast(k);
1303       reassign_type_array_elements(fr, reg_map, sv, (typeArrayOop) obj(), ak->element_type());
1304     } else if (k->is_objArray_klass()) {
1305       reassign_object_array_elements(fr, reg_map, sv, (objArrayOop) obj());
1306     }
1307   }
1308 }
1309 
1310 
1311 // relock objects for which synchronization was eliminated
1312 void Deoptimization::relock_objects(GrowableArray<MonitorInfo*>* monitors, JavaThread* thread, bool realloc_failures) {
1313   for (int i = 0; i < monitors->length(); i++) {
1314     MonitorInfo* mon_info = monitors->at(i);
1315     if (mon_info->eliminated()) {
1316       assert(!mon_info->owner_is_scalar_replaced() || realloc_failures, "reallocation was missed");
1317       if (!mon_info->owner_is_scalar_replaced()) {


< prev index next >