< prev index next >

src/hotspot/share/runtime/deoptimization.cpp

Print this page




1247 // relock objects for which synchronization was eliminated
1248 void Deoptimization::relock_objects(GrowableArray<MonitorInfo*>* monitors, JavaThread* thread, bool realloc_failures) {
1249   for (int i = 0; i < monitors->length(); i++) {
1250     MonitorInfo* mon_info = monitors->at(i);
1251     if (mon_info->eliminated()) {
1252       assert(!mon_info->owner_is_scalar_replaced() || realloc_failures, "reallocation was missed");
1253       if (!mon_info->owner_is_scalar_replaced()) {
1254         Handle obj(thread, mon_info->owner());
1255         markWord mark = obj->mark();
1256         if (UseBiasedLocking && mark.has_bias_pattern()) {
1257           // New allocated objects may have the mark set to anonymously biased.
1258           // Also the deoptimized method may called methods with synchronization
1259           // where the thread-local object is bias locked to the current thread.
1260           assert(mark.is_biased_anonymously() ||
1261                  mark.biased_locker() == thread, "should be locked to current thread");
1262           // Reset mark word to unbiased prototype.
1263           markWord unbiased_prototype = markWord::prototype().set_age(mark.age());
1264           obj->set_mark(unbiased_prototype);
1265         }
1266         BasicLock* lock = mon_info->lock();
1267         ObjectSynchronizer::slow_enter(obj, lock, thread);
1268         assert(mon_info->owner()->is_locked(), "object must be locked now");
1269       }
1270     }
1271   }
1272 }
1273 
1274 
1275 #ifndef PRODUCT
1276 // print information about reallocated objects
1277 void Deoptimization::print_objects(GrowableArray<ScopeValue*>* objects, bool realloc_failures) {
1278   fieldDescriptor fd;
1279 
1280   for (int i = 0; i < objects->length(); i++) {
1281     ObjectValue* sv = (ObjectValue*) objects->at(i);
1282     Klass* k = java_lang_Class::as_Klass(sv->klass()->as_ConstantOopReadValue()->value()());
1283     Handle obj = sv->value();
1284 
1285     tty->print("     object <" INTPTR_FORMAT "> of type ", p2i(sv->value()()));
1286     k->print_value();
1287     assert(obj.not_null() || realloc_failures, "reallocation was missed");


1357 
1358   return array;
1359 }
1360 
1361 #if COMPILER2_OR_JVMCI
1362 void Deoptimization::pop_frames_failed_reallocs(JavaThread* thread, vframeArray* array) {
1363   // Reallocation of some scalar replaced objects failed. Record
1364   // that we need to pop all the interpreter frames for the
1365   // deoptimized compiled frame.
1366   assert(thread->frames_to_pop_failed_realloc() == 0, "missed frames to pop?");
1367   thread->set_frames_to_pop_failed_realloc(array->frames());
1368   // Unlock all monitors here otherwise the interpreter will see a
1369   // mix of locked and unlocked monitors (because of failed
1370   // reallocations of synchronized objects) and be confused.
1371   for (int i = 0; i < array->frames(); i++) {
1372     MonitorChunk* monitors = array->element(i)->monitors();
1373     if (monitors != NULL) {
1374       for (int j = 0; j < monitors->number_of_monitors(); j++) {
1375         BasicObjectLock* src = monitors->at(j);
1376         if (src->obj() != NULL) {
1377           ObjectSynchronizer::fast_exit(src->obj(), src->lock(), thread);
1378         }
1379       }
1380       array->element(i)->free_monitors(thread);
1381 #ifdef ASSERT
1382       array->element(i)->set_removed_monitors();
1383 #endif
1384     }
1385   }
1386 }
1387 #endif
1388 
1389 static void collect_monitors(compiledVFrame* cvf, GrowableArray<Handle>* objects_to_revoke) {
1390   GrowableArray<MonitorInfo*>* monitors = cvf->monitors();
1391   Thread* thread = Thread::current();
1392   for (int i = 0; i < monitors->length(); i++) {
1393     MonitorInfo* mon_info = monitors->at(i);
1394     if (!mon_info->eliminated() && mon_info->owner() != NULL) {
1395       objects_to_revoke->append(Handle(thread, mon_info->owner()));
1396     }
1397   }




1247 // relock objects for which synchronization was eliminated
1248 void Deoptimization::relock_objects(GrowableArray<MonitorInfo*>* monitors, JavaThread* thread, bool realloc_failures) {
1249   for (int i = 0; i < monitors->length(); i++) {
1250     MonitorInfo* mon_info = monitors->at(i);
1251     if (mon_info->eliminated()) {
1252       assert(!mon_info->owner_is_scalar_replaced() || realloc_failures, "reallocation was missed");
1253       if (!mon_info->owner_is_scalar_replaced()) {
1254         Handle obj(thread, mon_info->owner());
1255         markWord mark = obj->mark();
1256         if (UseBiasedLocking && mark.has_bias_pattern()) {
1257           // New allocated objects may have the mark set to anonymously biased.
1258           // Also the deoptimized method may called methods with synchronization
1259           // where the thread-local object is bias locked to the current thread.
1260           assert(mark.is_biased_anonymously() ||
1261                  mark.biased_locker() == thread, "should be locked to current thread");
1262           // Reset mark word to unbiased prototype.
1263           markWord unbiased_prototype = markWord::prototype().set_age(mark.age());
1264           obj->set_mark(unbiased_prototype);
1265         }
1266         BasicLock* lock = mon_info->lock();
1267         ObjectSynchronizer::enter(obj, lock, thread);
1268         assert(mon_info->owner()->is_locked(), "object must be locked now");
1269       }
1270     }
1271   }
1272 }
1273 
1274 
1275 #ifndef PRODUCT
1276 // print information about reallocated objects
1277 void Deoptimization::print_objects(GrowableArray<ScopeValue*>* objects, bool realloc_failures) {
1278   fieldDescriptor fd;
1279 
1280   for (int i = 0; i < objects->length(); i++) {
1281     ObjectValue* sv = (ObjectValue*) objects->at(i);
1282     Klass* k = java_lang_Class::as_Klass(sv->klass()->as_ConstantOopReadValue()->value()());
1283     Handle obj = sv->value();
1284 
1285     tty->print("     object <" INTPTR_FORMAT "> of type ", p2i(sv->value()()));
1286     k->print_value();
1287     assert(obj.not_null() || realloc_failures, "reallocation was missed");


1357 
1358   return array;
1359 }
1360 
1361 #if COMPILER2_OR_JVMCI
1362 void Deoptimization::pop_frames_failed_reallocs(JavaThread* thread, vframeArray* array) {
1363   // Reallocation of some scalar replaced objects failed. Record
1364   // that we need to pop all the interpreter frames for the
1365   // deoptimized compiled frame.
1366   assert(thread->frames_to_pop_failed_realloc() == 0, "missed frames to pop?");
1367   thread->set_frames_to_pop_failed_realloc(array->frames());
1368   // Unlock all monitors here otherwise the interpreter will see a
1369   // mix of locked and unlocked monitors (because of failed
1370   // reallocations of synchronized objects) and be confused.
1371   for (int i = 0; i < array->frames(); i++) {
1372     MonitorChunk* monitors = array->element(i)->monitors();
1373     if (monitors != NULL) {
1374       for (int j = 0; j < monitors->number_of_monitors(); j++) {
1375         BasicObjectLock* src = monitors->at(j);
1376         if (src->obj() != NULL) {
1377           ObjectSynchronizer::exit(src->obj(), src->lock(), thread);
1378         }
1379       }
1380       array->element(i)->free_monitors(thread);
1381 #ifdef ASSERT
1382       array->element(i)->set_removed_monitors();
1383 #endif
1384     }
1385   }
1386 }
1387 #endif
1388 
1389 static void collect_monitors(compiledVFrame* cvf, GrowableArray<Handle>* objects_to_revoke) {
1390   GrowableArray<MonitorInfo*>* monitors = cvf->monitors();
1391   Thread* thread = Thread::current();
1392   for (int i = 0; i < monitors->length(); i++) {
1393     MonitorInfo* mon_info = monitors->at(i);
1394     if (!mon_info->eliminated() && mon_info->owner() != NULL) {
1395       objects_to_revoke->append(Handle(thread, mon_info->owner()));
1396     }
1397   }


< prev index next >