< prev index next >

src/share/vm/runtime/deoptimization.cpp

Print this page




 792   Threads::deoptimized_wrt_marked_nmethods();
 793   return 0;
 794 }
 795 
 796 Deoptimization::DeoptAction Deoptimization::_unloaded_action
 797   = Deoptimization::Action_reinterpret;
 798 
 799 #if defined(COMPILER2) || INCLUDE_JVMCI
 800 bool Deoptimization::realloc_objects(JavaThread* thread, frame* fr, GrowableArray<ScopeValue*>* objects, TRAPS) {
 801   Handle pending_exception(THREAD, thread->pending_exception());
 802   const char* exception_file = thread->exception_file();
 803   int exception_line = thread->exception_line();
 804   thread->clear_pending_exception();
 805 
 806   bool failures = false;
 807 
 808   for (int i = 0; i < objects->length(); i++) {
 809     assert(objects->at(i)->is_object(), "invalid debug information");
 810     ObjectValue* sv = (ObjectValue*) objects->at(i);
 811 
 812     KlassHandle k(java_lang_Class::as_Klass(sv->klass()->as_ConstantOopReadValue()->value()()));
 813     oop obj = NULL;
 814 
 815     if (k->is_instance_klass()) {
 816       InstanceKlass* ik = InstanceKlass::cast(k());
 817       obj = ik->allocate_instance(THREAD);
 818     } else if (k->is_typeArray_klass()) {
 819       TypeArrayKlass* ak = TypeArrayKlass::cast(k());
 820       assert(sv->field_size() % type2size[ak->element_type()] == 0, "non-integral array length");
 821       int len = sv->field_size() / type2size[ak->element_type()];
 822       obj = ak->allocate(len, THREAD);
 823     } else if (k->is_objArray_klass()) {
 824       ObjArrayKlass* ak = ObjArrayKlass::cast(k());
 825       obj = ak->allocate(sv->field_size(), THREAD);
 826     }
 827 
 828     if (obj == NULL) {
 829       failures = true;
 830     }
 831 
 832     assert(sv->value().is_null(), "redundant reallocation");
 833     assert(obj != NULL || HAS_PENDING_EXCEPTION, "allocation should succeed or we should get an exception");
 834     CLEAR_PENDING_EXCEPTION;
 835     sv->set_value(obj);
 836   }
 837 
 838   if (failures) {
 839     THROW_OOP_(Universe::out_of_memory_error_realloc_objects(), failures);
 840   } else if (pending_exception.not_null()) {
 841     thread->set_pending_exception(pending_exception(), exception_file, exception_line);
 842   }
 843 
 844   return failures;


1061         break;
1062 
1063       case T_BOOLEAN:
1064         assert(value->type() == T_INT, "Agreement.");
1065         val = value->get_int();
1066         obj->bool_field_put(offset, (jboolean)*((jint*)&val));
1067         break;
1068 
1069       default:
1070         ShouldNotReachHere();
1071     }
1072     svIndex++;
1073   }
1074   return svIndex;
1075 }
1076 
1077 // restore fields of all eliminated objects and arrays
1078 void Deoptimization::reassign_fields(frame* fr, RegisterMap* reg_map, GrowableArray<ScopeValue*>* objects, bool realloc_failures, bool skip_internal) {
1079   for (int i = 0; i < objects->length(); i++) {
1080     ObjectValue* sv = (ObjectValue*) objects->at(i);
1081     KlassHandle k(java_lang_Class::as_Klass(sv->klass()->as_ConstantOopReadValue()->value()()));
1082     Handle obj = sv->value();
1083     assert(obj.not_null() || realloc_failures, "reallocation was missed");
1084     if (PrintDeoptimizationDetails) {
1085       tty->print_cr("reassign fields for object of type %s!", k->name()->as_C_string());
1086     }
1087     if (obj.is_null()) {
1088       continue;
1089     }
1090 
1091     if (k->is_instance_klass()) {
1092       InstanceKlass* ik = InstanceKlass::cast(k());
1093       reassign_fields_by_klass(ik, fr, reg_map, sv, 0, obj(), skip_internal);
1094     } else if (k->is_typeArray_klass()) {
1095       TypeArrayKlass* ak = TypeArrayKlass::cast(k());
1096       reassign_type_array_elements(fr, reg_map, sv, (typeArrayOop) obj(), ak->element_type());
1097     } else if (k->is_objArray_klass()) {
1098       reassign_object_array_elements(fr, reg_map, sv, (objArrayOop) obj());
1099     }
1100   }
1101 }
1102 
1103 
1104 // relock objects for which synchronization was eliminated
1105 void Deoptimization::relock_objects(GrowableArray<MonitorInfo*>* monitors, JavaThread* thread, bool realloc_failures) {
1106   for (int i = 0; i < monitors->length(); i++) {
1107     MonitorInfo* mon_info = monitors->at(i);
1108     if (mon_info->eliminated()) {
1109       assert(!mon_info->owner_is_scalar_replaced() || realloc_failures, "reallocation was missed");
1110       if (!mon_info->owner_is_scalar_replaced()) {
1111         Handle obj(thread, mon_info->owner());
1112         markOop mark = obj->mark();
1113         if (UseBiasedLocking && mark->has_bias_pattern()) {
1114           // New allocated objects may have the mark set to anonymously biased.
1115           // Also the deoptimized method may called methods with synchronization


1119           // Reset mark word to unbiased prototype.
1120           markOop unbiased_prototype = markOopDesc::prototype()->set_age(mark->age());
1121           obj->set_mark(unbiased_prototype);
1122         }
1123         BasicLock* lock = mon_info->lock();
1124         ObjectSynchronizer::slow_enter(obj, lock, thread);
1125         assert(mon_info->owner()->is_locked(), "object must be locked now");
1126       }
1127     }
1128   }
1129 }
1130 
1131 
1132 #ifndef PRODUCT
1133 // print information about reallocated objects
1134 void Deoptimization::print_objects(GrowableArray<ScopeValue*>* objects, bool realloc_failures) {
1135   fieldDescriptor fd;
1136 
1137   for (int i = 0; i < objects->length(); i++) {
1138     ObjectValue* sv = (ObjectValue*) objects->at(i);
1139     KlassHandle k(java_lang_Class::as_Klass(sv->klass()->as_ConstantOopReadValue()->value()()));
1140     Handle obj = sv->value();
1141 
1142     tty->print("     object <" INTPTR_FORMAT "> of type ", p2i(sv->value()()));
1143     k->print_value();
1144     assert(obj.not_null() || realloc_failures, "reallocation was missed");
1145     if (obj.is_null()) {
1146       tty->print(" allocation failed");
1147     } else {
1148       tty->print(" allocated (%d bytes)", obj->size() * HeapWordSize);
1149     }
1150     tty->cr();
1151 
1152     if (Verbose && !obj.is_null()) {
1153       k->oop_print_on(obj(), tty);
1154     }
1155   }
1156 }
1157 #endif
1158 #endif // COMPILER2 || INCLUDE_JVMCI
1159 




 792   Threads::deoptimized_wrt_marked_nmethods();
 793   return 0;
 794 }
 795 
 796 Deoptimization::DeoptAction Deoptimization::_unloaded_action
 797   = Deoptimization::Action_reinterpret;
 798 
 799 #if defined(COMPILER2) || INCLUDE_JVMCI
 800 bool Deoptimization::realloc_objects(JavaThread* thread, frame* fr, GrowableArray<ScopeValue*>* objects, TRAPS) {
 801   Handle pending_exception(THREAD, thread->pending_exception());
 802   const char* exception_file = thread->exception_file();
 803   int exception_line = thread->exception_line();
 804   thread->clear_pending_exception();
 805 
 806   bool failures = false;
 807 
 808   for (int i = 0; i < objects->length(); i++) {
 809     assert(objects->at(i)->is_object(), "invalid debug information");
 810     ObjectValue* sv = (ObjectValue*) objects->at(i);
 811 
 812     Klass* k = java_lang_Class::as_Klass(sv->klass()->as_ConstantOopReadValue()->value()());
 813     oop obj = NULL;
 814 
 815     if (k->is_instance_klass()) {
 816       InstanceKlass* ik = InstanceKlass::cast(k);
 817       obj = ik->allocate_instance(THREAD);
 818     } else if (k->is_typeArray_klass()) {
 819       TypeArrayKlass* ak = TypeArrayKlass::cast(k);
 820       assert(sv->field_size() % type2size[ak->element_type()] == 0, "non-integral array length");
 821       int len = sv->field_size() / type2size[ak->element_type()];
 822       obj = ak->allocate(len, THREAD);
 823     } else if (k->is_objArray_klass()) {
 824       ObjArrayKlass* ak = ObjArrayKlass::cast(k);
 825       obj = ak->allocate(sv->field_size(), THREAD);
 826     }
 827 
 828     if (obj == NULL) {
 829       failures = true;
 830     }
 831 
 832     assert(sv->value().is_null(), "redundant reallocation");
 833     assert(obj != NULL || HAS_PENDING_EXCEPTION, "allocation should succeed or we should get an exception");
 834     CLEAR_PENDING_EXCEPTION;
 835     sv->set_value(obj);
 836   }
 837 
 838   if (failures) {
 839     THROW_OOP_(Universe::out_of_memory_error_realloc_objects(), failures);
 840   } else if (pending_exception.not_null()) {
 841     thread->set_pending_exception(pending_exception(), exception_file, exception_line);
 842   }
 843 
 844   return failures;


1061         break;
1062 
1063       case T_BOOLEAN:
1064         assert(value->type() == T_INT, "Agreement.");
1065         val = value->get_int();
1066         obj->bool_field_put(offset, (jboolean)*((jint*)&val));
1067         break;
1068 
1069       default:
1070         ShouldNotReachHere();
1071     }
1072     svIndex++;
1073   }
1074   return svIndex;
1075 }
1076 
1077 // restore fields of all eliminated objects and arrays
1078 void Deoptimization::reassign_fields(frame* fr, RegisterMap* reg_map, GrowableArray<ScopeValue*>* objects, bool realloc_failures, bool skip_internal) {
1079   for (int i = 0; i < objects->length(); i++) {
1080     ObjectValue* sv = (ObjectValue*) objects->at(i);
1081     Klass* k = java_lang_Class::as_Klass(sv->klass()->as_ConstantOopReadValue()->value()());
1082     Handle obj = sv->value();
1083     assert(obj.not_null() || realloc_failures, "reallocation was missed");
1084     if (PrintDeoptimizationDetails) {
1085       tty->print_cr("reassign fields for object of type %s!", k->name()->as_C_string());
1086     }
1087     if (obj.is_null()) {
1088       continue;
1089     }
1090 
1091     if (k->is_instance_klass()) {
1092       InstanceKlass* ik = InstanceKlass::cast(k);
1093       reassign_fields_by_klass(ik, fr, reg_map, sv, 0, obj(), skip_internal);
1094     } else if (k->is_typeArray_klass()) {
1095       TypeArrayKlass* ak = TypeArrayKlass::cast(k);
1096       reassign_type_array_elements(fr, reg_map, sv, (typeArrayOop) obj(), ak->element_type());
1097     } else if (k->is_objArray_klass()) {
1098       reassign_object_array_elements(fr, reg_map, sv, (objArrayOop) obj());
1099     }
1100   }
1101 }
1102 
1103 
1104 // relock objects for which synchronization was eliminated
1105 void Deoptimization::relock_objects(GrowableArray<MonitorInfo*>* monitors, JavaThread* thread, bool realloc_failures) {
1106   for (int i = 0; i < monitors->length(); i++) {
1107     MonitorInfo* mon_info = monitors->at(i);
1108     if (mon_info->eliminated()) {
1109       assert(!mon_info->owner_is_scalar_replaced() || realloc_failures, "reallocation was missed");
1110       if (!mon_info->owner_is_scalar_replaced()) {
1111         Handle obj(thread, mon_info->owner());
1112         markOop mark = obj->mark();
1113         if (UseBiasedLocking && mark->has_bias_pattern()) {
1114           // New allocated objects may have the mark set to anonymously biased.
1115           // Also the deoptimized method may called methods with synchronization


1119           // Reset mark word to unbiased prototype.
1120           markOop unbiased_prototype = markOopDesc::prototype()->set_age(mark->age());
1121           obj->set_mark(unbiased_prototype);
1122         }
1123         BasicLock* lock = mon_info->lock();
1124         ObjectSynchronizer::slow_enter(obj, lock, thread);
1125         assert(mon_info->owner()->is_locked(), "object must be locked now");
1126       }
1127     }
1128   }
1129 }
1130 
1131 
1132 #ifndef PRODUCT
1133 // print information about reallocated objects
1134 void Deoptimization::print_objects(GrowableArray<ScopeValue*>* objects, bool realloc_failures) {
1135   fieldDescriptor fd;
1136 
1137   for (int i = 0; i < objects->length(); i++) {
1138     ObjectValue* sv = (ObjectValue*) objects->at(i);
1139     Klass* k = java_lang_Class::as_Klass(sv->klass()->as_ConstantOopReadValue()->value()());
1140     Handle obj = sv->value();
1141 
1142     tty->print("     object <" INTPTR_FORMAT "> of type ", p2i(sv->value()()));
1143     k->print_value();
1144     assert(obj.not_null() || realloc_failures, "reallocation was missed");
1145     if (obj.is_null()) {
1146       tty->print(" allocation failed");
1147     } else {
1148       tty->print(" allocated (%d bytes)", obj->size() * HeapWordSize);
1149     }
1150     tty->cr();
1151 
1152     if (Verbose && !obj.is_null()) {
1153       k->oop_print_on(obj(), tty);
1154     }
1155   }
1156 }
1157 #endif
1158 #endif // COMPILER2 || INCLUDE_JVMCI
1159 


< prev index next >