< prev index next >

src/hotspot/share/runtime/deoptimization.cpp

Print this page

  57 #include "prims/methodHandles.hpp"
  58 #include "runtime/atomic.hpp"
  59 #include "runtime/biasedLocking.hpp"
  60 #include "runtime/deoptimization.hpp"
  61 #include "runtime/escapeBarrier.hpp"
  62 #include "runtime/fieldDescriptor.hpp"
  63 #include "runtime/fieldDescriptor.inline.hpp"
  64 #include "runtime/frame.inline.hpp"
  65 #include "runtime/handles.inline.hpp"
  66 #include "runtime/interfaceSupport.inline.hpp"
  67 #include "runtime/jniHandles.inline.hpp"
  68 #include "runtime/keepStackGCProcessed.hpp"
  69 #include "runtime/objectMonitor.inline.hpp"
  70 #include "runtime/osThread.hpp"
  71 #include "runtime/safepointVerifiers.hpp"
  72 #include "runtime/sharedRuntime.hpp"
  73 #include "runtime/signature.hpp"
  74 #include "runtime/stackFrameStream.inline.hpp"
  75 #include "runtime/stackWatermarkSet.hpp"
  76 #include "runtime/stubRoutines.hpp"

  77 #include "runtime/thread.hpp"
  78 #include "runtime/threadSMR.hpp"
  79 #include "runtime/threadWXSetters.inline.hpp"
  80 #include "runtime/vframe.hpp"
  81 #include "runtime/vframeArray.hpp"
  82 #include "runtime/vframe_hp.hpp"
  83 #include "runtime/vmOperations.hpp"
  84 #include "utilities/events.hpp"
  85 #include "utilities/macros.hpp"
  86 #include "utilities/preserveException.hpp"
  87 #include "utilities/xmlstream.hpp"
  88 #if INCLUDE_JFR
  89 #include "jfr/jfrEvents.hpp"
  90 #include "jfr/metadata/jfrSerializer.hpp"
  91 #endif
  92 
  93 bool DeoptimizationMarker::_is_active = false;
  94 
  95 Deoptimization::UnrollBlock::UnrollBlock(int  size_of_deoptimized_frame,
  96                                          int  caller_adjustment,

1484                                     JavaThread* deoptee_thread, frame& fr, int exec_mode, bool realloc_failures) {
1485   bool relocked_objects = false;
1486   for (int i = 0; i < monitors->length(); i++) {
1487     MonitorInfo* mon_info = monitors->at(i);
1488     if (mon_info->eliminated()) {
1489       assert(!mon_info->owner_is_scalar_replaced() || realloc_failures, "reallocation was missed");
1490       relocked_objects = true;
1491       if (!mon_info->owner_is_scalar_replaced()) {
1492         Handle obj(thread, mon_info->owner());
1493         markWord mark = obj->mark();
1494         if (UseBiasedLocking && mark.has_bias_pattern()) {
1495           // New allocated objects may have the mark set to anonymously biased.
1496           // Also the deoptimized method may called methods with synchronization
1497           // where the thread-local object is bias locked to the current thread.
1498           assert(mark.is_biased_anonymously() ||
1499                  mark.biased_locker() == deoptee_thread, "should be locked to current thread");
1500           // Reset mark word to unbiased prototype.
1501           markWord unbiased_prototype = markWord::prototype().set_age(mark.age());
1502           obj->set_mark(unbiased_prototype);
1503         } else if (exec_mode == Unpack_none) {
1504           if (mark.has_locker() && fr.sp() > (intptr_t*)mark.locker()) {
1505             // With exec_mode == Unpack_none obj may be thread local and locked in
1506             // a callee frame. In this case the bias was revoked before in revoke_for_object_deoptimization().
1507             // Make the lock in the callee a recursive lock and restore the displaced header.
1508             markWord dmw = mark.displaced_mark_helper();
1509             mark.locker()->set_displaced_header(markWord::encode((BasicLock*) NULL));
1510             obj->set_mark(dmw);
1511           }
1512           if (mark.has_monitor()) {
1513             // defer relocking if the deoptee thread is currently waiting for obj
1514             ObjectMonitor* waiting_monitor = deoptee_thread->current_waiting_monitor();
1515             if (waiting_monitor != NULL && waiting_monitor->object() == obj()) {
1516               assert(fr.is_deoptimized_frame(), "frame must be scheduled for deoptimization");
1517               mon_info->lock()->set_displaced_header(markWord::unused_mark());
1518               JvmtiDeferredUpdates::inc_relock_count_after_wait(deoptee_thread);
1519               continue;
1520             }
1521           }
1522         }
1523         BasicLock* lock = mon_info->lock();
1524         ObjectSynchronizer::enter(obj, lock, deoptee_thread);
1525         assert(mon_info->owner()->is_locked(), "object must be locked now");










1526       }
1527     }
1528   }
1529   return relocked_objects;
1530 }
1531 #endif // COMPILER2_OR_JVMCI
1532 
1533 vframeArray* Deoptimization::create_vframeArray(JavaThread* thread, frame fr, RegisterMap *reg_map, GrowableArray<compiledVFrame*>* chunk, bool realloc_failures) {
1534   Events::log_deopt_message(thread, "DEOPT PACKING pc=" INTPTR_FORMAT " sp=" INTPTR_FORMAT, p2i(fr.pc()), p2i(fr.sp()));
1535 
1536 #ifndef PRODUCT
1537   if (PrintDeoptimizationDetails) {
1538     ResourceMark rm;
1539     stringStream st;
1540     st.print("DEOPT PACKING thread " INTPTR_FORMAT " ", p2i(thread));
1541     fr.print_on(&st);
1542     st.print_cr("     Virtual frames (innermost first):");
1543     for (int index = 0; index < chunk->length(); index++) {
1544       compiledVFrame* vf = chunk->at(index);
1545       st.print("       %2d - ", index);

  57 #include "prims/methodHandles.hpp"
  58 #include "runtime/atomic.hpp"
  59 #include "runtime/biasedLocking.hpp"
  60 #include "runtime/deoptimization.hpp"
  61 #include "runtime/escapeBarrier.hpp"
  62 #include "runtime/fieldDescriptor.hpp"
  63 #include "runtime/fieldDescriptor.inline.hpp"
  64 #include "runtime/frame.inline.hpp"
  65 #include "runtime/handles.inline.hpp"
  66 #include "runtime/interfaceSupport.inline.hpp"
  67 #include "runtime/jniHandles.inline.hpp"
  68 #include "runtime/keepStackGCProcessed.hpp"
  69 #include "runtime/objectMonitor.inline.hpp"
  70 #include "runtime/osThread.hpp"
  71 #include "runtime/safepointVerifiers.hpp"
  72 #include "runtime/sharedRuntime.hpp"
  73 #include "runtime/signature.hpp"
  74 #include "runtime/stackFrameStream.inline.hpp"
  75 #include "runtime/stackWatermarkSet.hpp"
  76 #include "runtime/stubRoutines.hpp"
  77 #include "runtime/synchronizer.hpp"
  78 #include "runtime/thread.hpp"
  79 #include "runtime/threadSMR.hpp"
  80 #include "runtime/threadWXSetters.inline.hpp"
  81 #include "runtime/vframe.hpp"
  82 #include "runtime/vframeArray.hpp"
  83 #include "runtime/vframe_hp.hpp"
  84 #include "runtime/vmOperations.hpp"
  85 #include "utilities/events.hpp"
  86 #include "utilities/macros.hpp"
  87 #include "utilities/preserveException.hpp"
  88 #include "utilities/xmlstream.hpp"
  89 #if INCLUDE_JFR
  90 #include "jfr/jfrEvents.hpp"
  91 #include "jfr/metadata/jfrSerializer.hpp"
  92 #endif
  93 
  94 bool DeoptimizationMarker::_is_active = false;
  95 
  96 Deoptimization::UnrollBlock::UnrollBlock(int  size_of_deoptimized_frame,
  97                                          int  caller_adjustment,

1485                                     JavaThread* deoptee_thread, frame& fr, int exec_mode, bool realloc_failures) {
1486   bool relocked_objects = false;
1487   for (int i = 0; i < monitors->length(); i++) {
1488     MonitorInfo* mon_info = monitors->at(i);
1489     if (mon_info->eliminated()) {
1490       assert(!mon_info->owner_is_scalar_replaced() || realloc_failures, "reallocation was missed");
1491       relocked_objects = true;
1492       if (!mon_info->owner_is_scalar_replaced()) {
1493         Handle obj(thread, mon_info->owner());
1494         markWord mark = obj->mark();
1495         if (UseBiasedLocking && mark.has_bias_pattern()) {
1496           // New allocated objects may have the mark set to anonymously biased.
1497           // Also the deoptimized method may called methods with synchronization
1498           // where the thread-local object is bias locked to the current thread.
1499           assert(mark.is_biased_anonymously() ||
1500                  mark.biased_locker() == deoptee_thread, "should be locked to current thread");
1501           // Reset mark word to unbiased prototype.
1502           markWord unbiased_prototype = markWord::prototype().set_age(mark.age());
1503           obj->set_mark(unbiased_prototype);
1504         } else if (exec_mode == Unpack_none) {
1505           if (LockingMode == LM_LEGACY && mark.has_locker() && fr.sp() > (intptr_t*)mark.locker()) {
1506             // With exec_mode == Unpack_none obj may be thread local and locked in
1507             // a callee frame. In this case the bias was revoked before in revoke_for_object_deoptimization().
1508             // Make the lock in the callee a recursive lock and restore the displaced header.
1509             markWord dmw = mark.displaced_mark_helper();
1510             mark.locker()->set_displaced_header(markWord::encode((BasicLock*) NULL));
1511             obj->set_mark(dmw);
1512           }
1513           if (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               mon_info->lock()->set_displaced_header(markWord::unused_mark());
1519               JvmtiDeferredUpdates::inc_relock_count_after_wait(deoptee_thread);
1520               continue;
1521             }
1522           }
1523         }
1524         if (LockingMode == LM_LIGHTWEIGHT && exec_mode == Unpack_none) {
1525           // We have lost information about the correct state of the lock stack.
1526           // Inflate the locks instead. Enter then inflate to avoid races with
1527           // deflation.
1528           ObjectSynchronizer::enter_for(obj, nullptr, deoptee_thread);
1529           assert(mon_info->owner()->is_locked(), "object must be locked now");
1530           ObjectMonitor* mon = ObjectSynchronizer::inflate_for(deoptee_thread, obj(), ObjectSynchronizer::inflate_cause_vm_internal);
1531           assert(mon->owner() == deoptee_thread, "must be");
1532         } else {
1533           BasicLock* lock = mon_info->lock();
1534           ObjectSynchronizer::enter_for(obj, lock, deoptee_thread);
1535           assert(mon_info->owner()->is_locked(), "object must be locked now");
1536         }
1537       }
1538     }
1539   }
1540   return relocked_objects;
1541 }
1542 #endif // COMPILER2_OR_JVMCI
1543 
1544 vframeArray* Deoptimization::create_vframeArray(JavaThread* thread, frame fr, RegisterMap *reg_map, GrowableArray<compiledVFrame*>* chunk, bool realloc_failures) {
1545   Events::log_deopt_message(thread, "DEOPT PACKING pc=" INTPTR_FORMAT " sp=" INTPTR_FORMAT, p2i(fr.pc()), p2i(fr.sp()));
1546 
1547 #ifndef PRODUCT
1548   if (PrintDeoptimizationDetails) {
1549     ResourceMark rm;
1550     stringStream st;
1551     st.print("DEOPT PACKING thread " INTPTR_FORMAT " ", p2i(thread));
1552     fr.print_on(&st);
1553     st.print_cr("     Virtual frames (innermost first):");
1554     for (int index = 0; index < chunk->length(); index++) {
1555       compiledVFrame* vf = chunk->at(index);
1556       st.print("       %2d - ", index);
< prev index next >