46 #include "logging/logMessage.hpp"
47 #include "logging/logStream.hpp"
48 #include "memory/allocation.inline.hpp"
49 #include "memory/oopFactory.hpp"
50 #include "memory/resourceArea.hpp"
51 #include "memory/universe.hpp"
52 #include "oops/constantPool.hpp"
53 #include "oops/fieldStreams.inline.hpp"
54 #include "oops/method.hpp"
55 #include "oops/objArrayKlass.hpp"
56 #include "oops/objArrayOop.inline.hpp"
57 #include "oops/oop.inline.hpp"
58 #include "oops/typeArrayOop.inline.hpp"
59 #include "oops/verifyOopClosure.hpp"
60 #include "prims/jvmtiDeferredUpdates.hpp"
61 #include "prims/jvmtiExport.hpp"
62 #include "prims/jvmtiThreadState.hpp"
63 #include "prims/methodHandles.hpp"
64 #include "prims/vectorSupport.hpp"
65 #include "runtime/atomic.hpp"
66 #include "runtime/continuation.hpp"
67 #include "runtime/continuationEntry.inline.hpp"
68 #include "runtime/deoptimization.hpp"
69 #include "runtime/escapeBarrier.hpp"
70 #include "runtime/fieldDescriptor.hpp"
71 #include "runtime/fieldDescriptor.inline.hpp"
72 #include "runtime/frame.inline.hpp"
73 #include "runtime/handles.inline.hpp"
74 #include "runtime/interfaceSupport.inline.hpp"
75 #include "runtime/javaThread.hpp"
76 #include "runtime/jniHandles.inline.hpp"
77 #include "runtime/keepStackGCProcessed.hpp"
78 #include "runtime/objectMonitor.inline.hpp"
79 #include "runtime/osThread.hpp"
80 #include "runtime/safepointVerifiers.hpp"
81 #include "runtime/sharedRuntime.hpp"
82 #include "runtime/signature.hpp"
83 #include "runtime/stackFrameStream.inline.hpp"
84 #include "runtime/stackValue.hpp"
85 #include "runtime/stackWatermarkSet.hpp"
86 #include "runtime/stubRoutines.hpp"
87 #include "runtime/synchronizer.hpp"
88 #include "runtime/threadSMR.hpp"
89 #include "runtime/threadWXSetters.inline.hpp"
90 #include "runtime/vframe.hpp"
91 #include "runtime/vframeArray.hpp"
92 #include "runtime/vframe_hp.hpp"
93 #include "runtime/vmOperations.hpp"
94 #include "utilities/checkedCast.hpp"
95 #include "utilities/events.hpp"
96 #include "utilities/growableArray.hpp"
97 #include "utilities/macros.hpp"
98 #include "utilities/preserveException.hpp"
99 #include "utilities/xmlstream.hpp"
100 #if INCLUDE_JFR
101 #include "jfr/jfrEvents.hpp"
102 #include "jfr/metadata/jfrSerializer.hpp"
103 #endif
104
105 uint64_t DeoptimizationScope::_committed_deopt_gen = 0;
106 uint64_t DeoptimizationScope::_active_deopt_gen = 1;
107 bool DeoptimizationScope::_committing_in_progress = false;
1617 MonitorInfo* mon_info = monitors->at(i);
1618 if (mon_info->eliminated()) {
1619 assert(!mon_info->owner_is_scalar_replaced() || realloc_failures, "reallocation was missed");
1620 relocked_objects = true;
1621 if (!mon_info->owner_is_scalar_replaced()) {
1622 Handle obj(thread, mon_info->owner());
1623 markWord mark = obj->mark();
1624 if (exec_mode == Unpack_none) {
1625 if (LockingMode == LM_LEGACY && mark.has_locker() && fr.sp() > (intptr_t*)mark.locker()) {
1626 // With exec_mode == Unpack_none obj may be thread local and locked in
1627 // a callee frame. Make the lock in the callee a recursive lock and restore the displaced header.
1628 markWord dmw = mark.displaced_mark_helper();
1629 mark.locker()->set_displaced_header(markWord::encode((BasicLock*) nullptr));
1630 obj->set_mark(dmw);
1631 }
1632 if (mark.has_monitor()) {
1633 // defer relocking if the deoptee thread is currently waiting for obj
1634 ObjectMonitor* waiting_monitor = deoptee_thread->current_waiting_monitor();
1635 if (waiting_monitor != nullptr && waiting_monitor->object() == obj()) {
1636 assert(fr.is_deoptimized_frame(), "frame must be scheduled for deoptimization");
1637 mon_info->lock()->set_displaced_header(markWord::unused_mark());
1638 JvmtiDeferredUpdates::inc_relock_count_after_wait(deoptee_thread);
1639 continue;
1640 }
1641 }
1642 }
1643 if (LockingMode == LM_LIGHTWEIGHT) {
1644 // We have lost information about the correct state of the lock stack.
1645 // Inflate the locks instead. Enter then inflate to avoid races with
1646 // deflation.
1647 ObjectSynchronizer::enter_for(obj, nullptr, deoptee_thread);
1648 assert(mon_info->owner()->is_locked(), "object must be locked now");
1649 ObjectMonitor* mon = ObjectSynchronizer::inflate_for(deoptee_thread, obj(), ObjectSynchronizer::inflate_cause_vm_internal);
1650 assert(mon->owner() == deoptee_thread, "must be");
1651 } else {
1652 BasicLock* lock = mon_info->lock();
1653 ObjectSynchronizer::enter_for(obj, lock, deoptee_thread);
1654 assert(mon_info->owner()->is_locked(), "object must be locked now");
1655 }
1656 }
1657 }
1658 }
1659 return relocked_objects;
1660 }
1661 #endif // COMPILER2_OR_JVMCI
1662
1663 vframeArray* Deoptimization::create_vframeArray(JavaThread* thread, frame fr, RegisterMap *reg_map, GrowableArray<compiledVFrame*>* chunk, bool realloc_failures) {
1664 Events::log_deopt_message(thread, "DEOPT PACKING pc=" INTPTR_FORMAT " sp=" INTPTR_FORMAT, p2i(fr.pc()), p2i(fr.sp()));
1665
1666 // Register map for next frame (used for stack crawl). We capture
1667 // the state of the deopt'ing frame's caller. Thus if we need to
1668 // stuff a C2I adapter we can properly fill in the callee-save
1669 // register locations.
1670 frame caller = fr.sender(reg_map);
1671 int frame_size = pointer_delta_as_int(caller.sp(), fr.sp());
1672
|
46 #include "logging/logMessage.hpp"
47 #include "logging/logStream.hpp"
48 #include "memory/allocation.inline.hpp"
49 #include "memory/oopFactory.hpp"
50 #include "memory/resourceArea.hpp"
51 #include "memory/universe.hpp"
52 #include "oops/constantPool.hpp"
53 #include "oops/fieldStreams.inline.hpp"
54 #include "oops/method.hpp"
55 #include "oops/objArrayKlass.hpp"
56 #include "oops/objArrayOop.inline.hpp"
57 #include "oops/oop.inline.hpp"
58 #include "oops/typeArrayOop.inline.hpp"
59 #include "oops/verifyOopClosure.hpp"
60 #include "prims/jvmtiDeferredUpdates.hpp"
61 #include "prims/jvmtiExport.hpp"
62 #include "prims/jvmtiThreadState.hpp"
63 #include "prims/methodHandles.hpp"
64 #include "prims/vectorSupport.hpp"
65 #include "runtime/atomic.hpp"
66 #include "runtime/basicLock.inline.hpp"
67 #include "runtime/continuation.hpp"
68 #include "runtime/continuationEntry.inline.hpp"
69 #include "runtime/deoptimization.hpp"
70 #include "runtime/escapeBarrier.hpp"
71 #include "runtime/fieldDescriptor.hpp"
72 #include "runtime/fieldDescriptor.inline.hpp"
73 #include "runtime/frame.inline.hpp"
74 #include "runtime/handles.inline.hpp"
75 #include "runtime/interfaceSupport.inline.hpp"
76 #include "runtime/javaThread.hpp"
77 #include "runtime/jniHandles.inline.hpp"
78 #include "runtime/keepStackGCProcessed.hpp"
79 #include "runtime/lightweightSynchronizer.hpp"
80 #include "runtime/lockStack.inline.hpp"
81 #include "runtime/objectMonitor.inline.hpp"
82 #include "runtime/osThread.hpp"
83 #include "runtime/safepointVerifiers.hpp"
84 #include "runtime/sharedRuntime.hpp"
85 #include "runtime/signature.hpp"
86 #include "runtime/stackFrameStream.inline.hpp"
87 #include "runtime/stackValue.hpp"
88 #include "runtime/stackWatermarkSet.hpp"
89 #include "runtime/stubRoutines.hpp"
90 #include "runtime/synchronizer.inline.hpp"
91 #include "runtime/threadSMR.hpp"
92 #include "runtime/threadWXSetters.inline.hpp"
93 #include "runtime/vframe.hpp"
94 #include "runtime/vframeArray.hpp"
95 #include "runtime/vframe_hp.hpp"
96 #include "runtime/vmOperations.hpp"
97 #include "utilities/checkedCast.hpp"
98 #include "utilities/events.hpp"
99 #include "utilities/growableArray.hpp"
100 #include "utilities/macros.hpp"
101 #include "utilities/preserveException.hpp"
102 #include "utilities/xmlstream.hpp"
103 #if INCLUDE_JFR
104 #include "jfr/jfrEvents.hpp"
105 #include "jfr/metadata/jfrSerializer.hpp"
106 #endif
107
108 uint64_t DeoptimizationScope::_committed_deopt_gen = 0;
109 uint64_t DeoptimizationScope::_active_deopt_gen = 1;
110 bool DeoptimizationScope::_committing_in_progress = false;
1620 MonitorInfo* mon_info = monitors->at(i);
1621 if (mon_info->eliminated()) {
1622 assert(!mon_info->owner_is_scalar_replaced() || realloc_failures, "reallocation was missed");
1623 relocked_objects = true;
1624 if (!mon_info->owner_is_scalar_replaced()) {
1625 Handle obj(thread, mon_info->owner());
1626 markWord mark = obj->mark();
1627 if (exec_mode == Unpack_none) {
1628 if (LockingMode == LM_LEGACY && mark.has_locker() && fr.sp() > (intptr_t*)mark.locker()) {
1629 // With exec_mode == Unpack_none obj may be thread local and locked in
1630 // a callee frame. Make the lock in the callee a recursive lock and restore the displaced header.
1631 markWord dmw = mark.displaced_mark_helper();
1632 mark.locker()->set_displaced_header(markWord::encode((BasicLock*) nullptr));
1633 obj->set_mark(dmw);
1634 }
1635 if (mark.has_monitor()) {
1636 // defer relocking if the deoptee thread is currently waiting for obj
1637 ObjectMonitor* waiting_monitor = deoptee_thread->current_waiting_monitor();
1638 if (waiting_monitor != nullptr && waiting_monitor->object() == obj()) {
1639 assert(fr.is_deoptimized_frame(), "frame must be scheduled for deoptimization");
1640 if (LockingMode == LM_LEGACY) {
1641 mon_info->lock()->set_displaced_header(markWord::unused_mark());
1642 } else if (UseObjectMonitorTable) {
1643 mon_info->lock()->clear_object_monitor_cache();
1644 }
1645 #ifdef ASSERT
1646 else {
1647 assert(LockingMode == LM_MONITOR || !UseObjectMonitorTable, "must be");
1648 mon_info->lock()->set_bad_metadata_deopt();
1649 }
1650 #endif
1651 JvmtiDeferredUpdates::inc_relock_count_after_wait(deoptee_thread);
1652 continue;
1653 }
1654 }
1655 }
1656 BasicLock* lock = mon_info->lock();
1657 if (LockingMode == LM_LIGHTWEIGHT) {
1658 // We have lost information about the correct state of the lock stack.
1659 // Entering may create an invalid lock stack. Inflate the lock if it
1660 // was fast_locked to restore the valid lock stack.
1661 ObjectSynchronizer::enter_for(obj, lock, deoptee_thread);
1662 if (deoptee_thread->lock_stack().contains(obj())) {
1663 LightweightSynchronizer::inflate_fast_locked_object(obj(), deoptee_thread, thread,
1664 ObjectSynchronizer::InflateCause::inflate_cause_vm_internal);
1665 }
1666 assert(mon_info->owner()->is_locked(), "object must be locked now");
1667 assert(obj->mark().has_monitor(), "must be");
1668 assert(!deoptee_thread->lock_stack().contains(obj()), "must be");
1669 assert(ObjectSynchronizer::read_monitor(thread, obj(), obj->mark())->owner() == deoptee_thread, "must be");
1670 } else {
1671 ObjectSynchronizer::enter_for(obj, lock, deoptee_thread);
1672 assert(mon_info->owner()->is_locked(), "object must be locked now");
1673 }
1674 }
1675 }
1676 }
1677 return relocked_objects;
1678 }
1679 #endif // COMPILER2_OR_JVMCI
1680
1681 vframeArray* Deoptimization::create_vframeArray(JavaThread* thread, frame fr, RegisterMap *reg_map, GrowableArray<compiledVFrame*>* chunk, bool realloc_failures) {
1682 Events::log_deopt_message(thread, "DEOPT PACKING pc=" INTPTR_FORMAT " sp=" INTPTR_FORMAT, p2i(fr.pc()), p2i(fr.sp()));
1683
1684 // Register map for next frame (used for stack crawl). We capture
1685 // the state of the deopt'ing frame's caller. Thus if we need to
1686 // stuff a C2I adapter we can properly fill in the callee-save
1687 // register locations.
1688 frame caller = fr.sender(reg_map);
1689 int frame_size = pointer_delta_as_int(caller.sp(), fr.sp());
1690
|