< prev index next >

src/hotspot/share/runtime/deoptimization.cpp

Print this page

1493       reassign_type_array_elements(fr, reg_map, sv, (typeArrayOop) obj(), ak->element_type());
1494     } else if (k->is_objArray_klass()) {
1495       reassign_object_array_elements(fr, reg_map, sv, (objArrayOop) obj());
1496     }
1497   }
1498 }
1499 
1500 
1501 // relock objects for which synchronization was eliminated
1502 bool Deoptimization::relock_objects(JavaThread* thread, GrowableArray<MonitorInfo*>* monitors,
1503                                     JavaThread* deoptee_thread, frame& fr, int exec_mode, bool realloc_failures) {
1504   bool relocked_objects = false;
1505   for (int i = 0; i < monitors->length(); i++) {
1506     MonitorInfo* mon_info = monitors->at(i);
1507     if (mon_info->eliminated()) {
1508       assert(!mon_info->owner_is_scalar_replaced() || realloc_failures, "reallocation was missed");
1509       relocked_objects = true;
1510       if (!mon_info->owner_is_scalar_replaced()) {
1511         Handle obj(thread, mon_info->owner());
1512         markWord mark = obj->mark();
1513         if (exec_mode == Unpack_none) {
1514           if (mark.has_locker() && fr.sp() > (intptr_t*)mark.locker()) {
1515             // With exec_mode == Unpack_none obj may be thread local and locked in
1516             // a callee frame. Make the lock in the callee a recursive lock and restore the displaced header.
1517             markWord dmw = mark.displaced_mark_helper();
1518             mark.locker()->set_displaced_header(markWord::encode((BasicLock*) NULL));
1519             obj->set_mark(dmw);
1520           }
1521           if (mark.has_monitor()) {
1522             // defer relocking if the deoptee thread is currently waiting for obj
1523             ObjectMonitor* waiting_monitor = deoptee_thread->current_waiting_monitor();
1524             if (waiting_monitor != NULL && waiting_monitor->object() == obj()) {
1525               assert(fr.is_deoptimized_frame(), "frame must be scheduled for deoptimization");
1526               mon_info->lock()->set_displaced_header(markWord::unused_mark());
1527               JvmtiDeferredUpdates::inc_relock_count_after_wait(deoptee_thread);
1528               continue;
1529             }
1530           }
1531         }
1532         BasicLock* lock = mon_info->lock();
1533         ObjectSynchronizer::enter(obj, lock, deoptee_thread);
1534         assert(mon_info->owner()->is_locked(), "object must be locked now");
1535       }
1536     }
1537   }
1538   return relocked_objects;
1539 }
1540 #endif // COMPILER2_OR_JVMCI
1541 
1542 vframeArray* Deoptimization::create_vframeArray(JavaThread* thread, frame fr, RegisterMap *reg_map, GrowableArray<compiledVFrame*>* chunk, bool realloc_failures) {
1543   Events::log_deopt_message(thread, "DEOPT PACKING pc=" INTPTR_FORMAT " sp=" INTPTR_FORMAT, p2i(fr.pc()), p2i(fr.sp()));
1544 
1545   // Register map for next frame (used for stack crawl).  We capture
1546   // the state of the deopt'ing frame's caller.  Thus if we need to
1547   // stuff a C2I adapter we can properly fill in the callee-save
1548   // register locations.
1549   frame caller = fr.sender(reg_map);
1550   int frame_size = caller.sp() - fr.sp();
1551 
1552   frame sender = caller;
1553 

1588 
1589   return array;
1590 }
1591 
1592 #if COMPILER2_OR_JVMCI
1593 void Deoptimization::pop_frames_failed_reallocs(JavaThread* thread, vframeArray* array) {
1594   // Reallocation of some scalar replaced objects failed. Record
1595   // that we need to pop all the interpreter frames for the
1596   // deoptimized compiled frame.
1597   assert(thread->frames_to_pop_failed_realloc() == 0, "missed frames to pop?");
1598   thread->set_frames_to_pop_failed_realloc(array->frames());
1599   // Unlock all monitors here otherwise the interpreter will see a
1600   // mix of locked and unlocked monitors (because of failed
1601   // reallocations of synchronized objects) and be confused.
1602   for (int i = 0; i < array->frames(); i++) {
1603     MonitorChunk* monitors = array->element(i)->monitors();
1604     if (monitors != NULL) {
1605       for (int j = 0; j < monitors->number_of_monitors(); j++) {
1606         BasicObjectLock* src = monitors->at(j);
1607         if (src->obj() != NULL) {
1608           ObjectSynchronizer::exit(src->obj(), src->lock(), thread);
1609         }
1610       }
1611       array->element(i)->free_monitors(thread);
1612 #ifdef ASSERT
1613       array->element(i)->set_removed_monitors();
1614 #endif
1615     }
1616   }
1617 }
1618 #endif
1619 
1620 void Deoptimization::deoptimize_single_frame(JavaThread* thread, frame fr, Deoptimization::DeoptReason reason) {
1621   assert(fr.can_be_deoptimized(), "checking frame type");
1622 
1623   gather_statistics(reason, Action_none, Bytecodes::_illegal);
1624 
1625   if (LogCompilation && xtty != NULL) {
1626     CompiledMethod* cm = fr.cb()->as_compiled_method_or_null();
1627     assert(cm != NULL, "only compiled methods can deopt");
1628 

1493       reassign_type_array_elements(fr, reg_map, sv, (typeArrayOop) obj(), ak->element_type());
1494     } else if (k->is_objArray_klass()) {
1495       reassign_object_array_elements(fr, reg_map, sv, (objArrayOop) obj());
1496     }
1497   }
1498 }
1499 
1500 
1501 // relock objects for which synchronization was eliminated
1502 bool Deoptimization::relock_objects(JavaThread* thread, GrowableArray<MonitorInfo*>* monitors,
1503                                     JavaThread* deoptee_thread, frame& fr, int exec_mode, bool realloc_failures) {
1504   bool relocked_objects = false;
1505   for (int i = 0; i < monitors->length(); i++) {
1506     MonitorInfo* mon_info = monitors->at(i);
1507     if (mon_info->eliminated()) {
1508       assert(!mon_info->owner_is_scalar_replaced() || realloc_failures, "reallocation was missed");
1509       relocked_objects = true;
1510       if (!mon_info->owner_is_scalar_replaced()) {
1511         Handle obj(thread, mon_info->owner());
1512         markWord mark = obj->mark();
1513         if (exec_mode == Unpack_none && mark.has_monitor()) {
1514           // defer relocking if the deoptee thread is currently waiting for obj
1515           ObjectMonitor* waiting_monitor = deoptee_thread->current_waiting_monitor();
1516           if (waiting_monitor != NULL && waiting_monitor->object() == obj()) {
1517             assert(fr.is_deoptimized_frame(), "frame must be scheduled for deoptimization");
1518             JvmtiDeferredUpdates::inc_relock_count_after_wait(deoptee_thread);
1519             continue;










1520           }
1521         }
1522         ObjectSynchronizer::enter(obj, deoptee_thread);

1523         assert(mon_info->owner()->is_locked(), "object must be locked now");
1524       }
1525     }
1526   }
1527   return relocked_objects;
1528 }
1529 #endif // COMPILER2_OR_JVMCI
1530 
1531 vframeArray* Deoptimization::create_vframeArray(JavaThread* thread, frame fr, RegisterMap *reg_map, GrowableArray<compiledVFrame*>* chunk, bool realloc_failures) {
1532   Events::log_deopt_message(thread, "DEOPT PACKING pc=" INTPTR_FORMAT " sp=" INTPTR_FORMAT, p2i(fr.pc()), p2i(fr.sp()));
1533 
1534   // Register map for next frame (used for stack crawl).  We capture
1535   // the state of the deopt'ing frame's caller.  Thus if we need to
1536   // stuff a C2I adapter we can properly fill in the callee-save
1537   // register locations.
1538   frame caller = fr.sender(reg_map);
1539   int frame_size = caller.sp() - fr.sp();
1540 
1541   frame sender = caller;
1542 

1577 
1578   return array;
1579 }
1580 
1581 #if COMPILER2_OR_JVMCI
1582 void Deoptimization::pop_frames_failed_reallocs(JavaThread* thread, vframeArray* array) {
1583   // Reallocation of some scalar replaced objects failed. Record
1584   // that we need to pop all the interpreter frames for the
1585   // deoptimized compiled frame.
1586   assert(thread->frames_to_pop_failed_realloc() == 0, "missed frames to pop?");
1587   thread->set_frames_to_pop_failed_realloc(array->frames());
1588   // Unlock all monitors here otherwise the interpreter will see a
1589   // mix of locked and unlocked monitors (because of failed
1590   // reallocations of synchronized objects) and be confused.
1591   for (int i = 0; i < array->frames(); i++) {
1592     MonitorChunk* monitors = array->element(i)->monitors();
1593     if (monitors != NULL) {
1594       for (int j = 0; j < monitors->number_of_monitors(); j++) {
1595         BasicObjectLock* src = monitors->at(j);
1596         if (src->obj() != NULL) {
1597           ObjectSynchronizer::exit(src->obj(), thread);
1598         }
1599       }
1600       array->element(i)->free_monitors(thread);
1601 #ifdef ASSERT
1602       array->element(i)->set_removed_monitors();
1603 #endif
1604     }
1605   }
1606 }
1607 #endif
1608 
1609 void Deoptimization::deoptimize_single_frame(JavaThread* thread, frame fr, Deoptimization::DeoptReason reason) {
1610   assert(fr.can_be_deoptimized(), "checking frame type");
1611 
1612   gather_statistics(reason, Action_none, Bytecodes::_illegal);
1613 
1614   if (LogCompilation && xtty != NULL) {
1615     CompiledMethod* cm = fr.cb()->as_compiled_method_or_null();
1616     assert(cm != NULL, "only compiled methods can deopt");
1617 
< prev index next >