36 #include "jvm_io.h"
37 #include "logging/log.hpp"
38 #include "memory/resourceArea.hpp"
39 #include "memory/universe.hpp"
40 #include "oops/constantPool.inline.hpp"
41 #include "oops/cpCache.inline.hpp"
42 #include "oops/instanceKlass.inline.hpp"
43 #include "oops/klass.inline.hpp"
44 #include "oops/method.inline.hpp"
45 #include "oops/methodCounters.hpp"
46 #include "oops/objArrayKlass.hpp"
47 #include "oops/objArrayOop.inline.hpp"
48 #include "oops/oop.inline.hpp"
49 #include "oops/resolvedFieldEntry.hpp"
50 #include "oops/resolvedIndyEntry.hpp"
51 #include "oops/resolvedMethodEntry.hpp"
52 #include "oops/typeArrayOop.inline.hpp"
53 #include "prims/jvmtiExport.hpp"
54 #include "prims/jvmtiThreadState.hpp"
55 #include "runtime/atomic.hpp"
56 #include "runtime/frame.inline.hpp"
57 #include "runtime/handles.inline.hpp"
58 #include "runtime/interfaceSupport.inline.hpp"
59 #include "runtime/orderAccess.hpp"
60 #include "runtime/sharedRuntime.hpp"
61 #include "runtime/threadCritical.hpp"
62 #include "utilities/debug.hpp"
63 #include "utilities/exceptions.hpp"
64 #include "utilities/macros.hpp"
65
66 /*
67 * USELABELS - If using GCC, then use labels for the opcode dispatching
68 * rather -then a switch statement. This improves performance because it
69 * gives us the opportunity to have the instructions that calculate the
70 * next opcode to jump to be intermixed with the rest of the instructions
71 * that implement the opcode (see UPDATE_PC_AND_TOS_AND_CONTINUE macro).
72 */
73 #undef USELABELS
74 #ifdef __GNUC__
75 /*
76 ASSERT signifies debugging. It is much easier to step thru bytecodes if we
77 don't use the computed goto approach.
78 */
79 #ifndef ASSERT
80 #define USELABELS
81 #endif
82 #endif
83
607 return;
608 }
609 case method_entry: {
610 THREAD->set_do_not_unlock_if_synchronized(true);
611
612 // Lock method if synchronized.
613 if (METHOD->is_synchronized()) {
614 // oop rcvr = locals[0].j.r;
615 oop rcvr;
616 if (METHOD->is_static()) {
617 rcvr = METHOD->constants()->pool_holder()->java_mirror();
618 } else {
619 rcvr = LOCALS_OBJECT(0);
620 VERIFY_OOP(rcvr);
621 }
622
623 // The initial monitor is ours for the taking.
624 BasicObjectLock* mon = &istate->monitor_base()[-1];
625 mon->set_obj(rcvr);
626
627 // Traditional lightweight locking.
628 markWord displaced = rcvr->mark().set_unlocked();
629 mon->lock()->set_displaced_header(displaced);
630 bool call_vm = (LockingMode == LM_MONITOR);
631 bool inc_monitor_count = true;
632 if (call_vm || rcvr->cas_set_mark(markWord::from_pointer(mon), displaced) != displaced) {
633 // Is it simple recursive case?
634 if (!call_vm && THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) {
635 mon->lock()->set_displaced_header(markWord::from_pointer(nullptr));
636 } else {
637 inc_monitor_count = false;
638 CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception);
639 }
640 }
641 if (inc_monitor_count) {
642 THREAD->inc_held_monitor_count();
643 }
644 }
645 THREAD->set_do_not_unlock_if_synchronized(false);
646
647 // Notify jvmti.
648 // Whenever JVMTI puts a thread in interp_only_mode, method
649 // entry/exit events are sent for that thread to track stack depth.
650 if (JVMTI_ENABLED && THREAD->is_interp_only_mode()) {
651 CALL_VM(InterpreterRuntime::post_method_entry(THREAD),
652 handle_exception);
653 }
654
655 goto run;
656 }
657
658 case popping_frame: {
659 // returned from a java call to pop the frame, restart the call
660 // clear the message so we don't confuse ourselves later
661 assert(THREAD->pop_frame_in_process(), "wrong frame pop state");
662 istate->set_msg(no_request);
663 THREAD->clr_pop_frame_in_process();
706 //
707 if ( Bytecodes::code_at(METHOD, pc) == Bytecodes::_return_register_finalizer) {
708 // this will do the right thing even if an exception is pending.
709 goto handle_return;
710 }
711 UPDATE_PC(Bytecodes::length_at(METHOD, pc));
712 if (THREAD->has_pending_exception()) goto handle_exception;
713 goto run;
714 }
715 case got_monitors: {
716 // continue locking now that we have a monitor to use
717 // we expect to find newly allocated monitor at the "top" of the monitor stack.
718 oop lockee = STACK_OBJECT(-1);
719 VERIFY_OOP(lockee);
720 // derefing's lockee ought to provoke implicit null check
721 // find a free monitor
722 BasicObjectLock* entry = (BasicObjectLock*) istate->stack_base();
723 assert(entry->obj() == nullptr, "Frame manager didn't allocate the monitor");
724 entry->set_obj(lockee);
725
726 // traditional lightweight locking
727 markWord displaced = lockee->mark().set_unlocked();
728 entry->lock()->set_displaced_header(displaced);
729 bool call_vm = (LockingMode == LM_MONITOR);
730 bool inc_monitor_count = true;
731 if (call_vm || lockee->cas_set_mark(markWord::from_pointer(entry), displaced) != displaced) {
732 // Is it simple recursive case?
733 if (!call_vm && THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) {
734 entry->lock()->set_displaced_header(markWord::from_pointer(nullptr));
735 } else {
736 inc_monitor_count = false;
737 CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
738 }
739 }
740 if (inc_monitor_count) {
741 THREAD->inc_held_monitor_count();
742 }
743 UPDATE_PC_AND_TOS(1, -1);
744 goto run;
745 }
746 default: {
747 fatal("Unexpected message from frame manager");
748 }
749 }
750
751 run:
752
753 DO_UPDATE_INSTRUCTION_COUNT(*pc)
754 DEBUGGER_SINGLE_STEP_NOTIFY();
755 #ifdef PREFETCH_OPCCODE
756 opcode = *pc; /* prefetch first opcode */
757 #endif
758
759 #ifndef USELABELS
760 while (1)
761 #endif
762 {
1636 /* monitorenter and monitorexit for locking/unlocking an object */
1637
1638 CASE(_monitorenter): {
1639 oop lockee = STACK_OBJECT(-1);
1640 // derefing's lockee ought to provoke implicit null check
1641 CHECK_NULL(lockee);
1642 // find a free monitor or one already allocated for this object
1643 // if we find a matching object then we need a new monitor
1644 // since this is recursive enter
1645 BasicObjectLock* limit = istate->monitor_base();
1646 BasicObjectLock* most_recent = (BasicObjectLock*) istate->stack_base();
1647 BasicObjectLock* entry = nullptr;
1648 while (most_recent != limit ) {
1649 if (most_recent->obj() == nullptr) entry = most_recent;
1650 else if (most_recent->obj() == lockee) break;
1651 most_recent++;
1652 }
1653 if (entry != nullptr) {
1654 entry->set_obj(lockee);
1655
1656 // traditional lightweight locking
1657 markWord displaced = lockee->mark().set_unlocked();
1658 entry->lock()->set_displaced_header(displaced);
1659 bool call_vm = (LockingMode == LM_MONITOR);
1660 bool inc_monitor_count = true;
1661 if (call_vm || lockee->cas_set_mark(markWord::from_pointer(entry), displaced) != displaced) {
1662 // Is it simple recursive case?
1663 if (!call_vm && THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) {
1664 entry->lock()->set_displaced_header(markWord::from_pointer(nullptr));
1665 } else {
1666 inc_monitor_count = false;
1667 CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
1668 }
1669 }
1670 if (inc_monitor_count) {
1671 THREAD->inc_held_monitor_count();
1672 }
1673 UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1674 } else {
1675 istate->set_msg(more_monitors);
1676 UPDATE_PC_AND_RETURN(0); // Re-execute
1677 }
1678 }
1679
1680 CASE(_monitorexit): {
1681 oop lockee = STACK_OBJECT(-1);
1682 CHECK_NULL(lockee);
1683 // derefing's lockee ought to provoke implicit null check
1684 // find our monitor slot
1685 BasicObjectLock* limit = istate->monitor_base();
1686 BasicObjectLock* most_recent = (BasicObjectLock*) istate->stack_base();
1687 while (most_recent != limit ) {
1688 if ((most_recent)->obj() == lockee) {
1689 BasicLock* lock = most_recent->lock();
1690 markWord header = lock->displaced_header();
1691 most_recent->set_obj(nullptr);
1692
1693 // If it isn't recursive we either must swap old header or call the runtime
1694 bool dec_monitor_count = true;
1695 bool call_vm = (LockingMode == LM_MONITOR);
1696 if (header.to_pointer() != nullptr || call_vm) {
1697 markWord old_header = markWord::encode(lock);
1698 if (call_vm || lockee->cas_set_mark(header, old_header) != old_header) {
1699 // restore object for the slow case
1700 most_recent->set_obj(lockee);
1701 dec_monitor_count = false;
1702 InterpreterRuntime::monitorexit(most_recent);
1703 }
1704 }
1705 if (dec_monitor_count) {
1706 THREAD->dec_held_monitor_count();
1707 }
1708 UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1709 }
1710 most_recent++;
1711 }
1712 // Need to throw illegal monitor state exception
1713 CALL_VM(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD), handle_exception);
1714 ShouldNotReachHere();
1715 }
1716
1717 /* All of the non-quick opcodes. */
1718
1719 /* -Set clobbersCpIndex true if the quickened opcode clobbers the
1720 * constant pool index in the instruction.
1721 */
1722 CASE(_getfield):
1723 CASE(_nofast_getfield):
1724 CASE(_getstatic):
1725 {
1726 u2 index;
1982 // To do this, we need to make sure:
1983 // - klass is initialized
1984 // - klass can be fastpath allocated (e.g. does not have finalizer)
1985 // - TLAB accepts the allocation
1986 ConstantPool* constants = istate->method()->constants();
1987 if (UseTLAB && !constants->tag_at(index).is_unresolved_klass()) {
1988 Klass* entry = constants->resolved_klass_at(index);
1989 InstanceKlass* ik = InstanceKlass::cast(entry);
1990 if (ik->is_initialized() && ik->can_be_fastpath_allocated()) {
1991 size_t obj_size = ik->size_helper();
1992 HeapWord* result = THREAD->tlab().allocate(obj_size);
1993 if (result != nullptr) {
1994 // Initialize object field block.
1995 if (!ZeroTLAB) {
1996 // The TLAB was not pre-zeroed, we need to clear the memory here.
1997 size_t hdr_size = oopDesc::header_size();
1998 Copy::fill_to_words(result + hdr_size, obj_size - hdr_size, 0);
1999 }
2000
2001 // Initialize header, mirrors MemAllocator.
2002 oopDesc::set_mark(result, markWord::prototype());
2003 oopDesc::set_klass_gap(result, 0);
2004 oopDesc::release_set_klass(result, ik);
2005
2006 oop obj = cast_to_oop(result);
2007
2008 // Must prevent reordering of stores for object initialization
2009 // with stores that publish the new object.
2010 OrderAccess::storestore();
2011 SET_STACK_OBJECT(obj, 0);
2012 UPDATE_PC_AND_TOS_AND_CONTINUE(3, 1);
2013 }
2014 }
2015 }
2016 // Slow case allocation
2017 CALL_VM(InterpreterRuntime::_new(THREAD, METHOD->constants(), index),
2018 handle_exception);
2019 // Must prevent reordering of stores for object initialization
2020 // with stores that publish the new object.
2021 OrderAccess::storestore();
2022 SET_STACK_OBJECT(THREAD->vm_result(), 0);
2023 THREAD->set_vm_result(nullptr);
2024 UPDATE_PC_AND_TOS_AND_CONTINUE(3, 1);
2025 }
3108 // Another weird thing to watch for is if the method was locked
3109 // recursively and then not exited properly. This means we must
3110 // examine all the entries in reverse time(and stack) order and
3111 // unlock as we find them. If we find the method monitor before
3112 // we are at the initial entry then we should throw an exception.
3113 // It is not clear the template based interpreter does this
3114 // correctly
3115
3116 BasicObjectLock* base = istate->monitor_base();
3117 BasicObjectLock* end = (BasicObjectLock*) istate->stack_base();
3118 bool method_unlock_needed = METHOD->is_synchronized();
3119 // We know the initial monitor was used for the method don't check that
3120 // slot in the loop
3121 if (method_unlock_needed) base--;
3122
3123 // Check all the monitors to see they are unlocked. Install exception if found to be locked.
3124 while (end < base) {
3125 oop lockee = end->obj();
3126 if (lockee != nullptr) {
3127 BasicLock* lock = end->lock();
3128 markWord header = lock->displaced_header();
3129 end->set_obj(nullptr);
3130
3131 // If it isn't recursive we either must swap old header or call the runtime
3132 bool dec_monitor_count = true;
3133 if (header.to_pointer() != nullptr) {
3134 markWord old_header = markWord::encode(lock);
3135 if (lockee->cas_set_mark(header, old_header) != old_header) {
3136 // restore object for the slow case
3137 end->set_obj(lockee);
3138 dec_monitor_count = false;
3139 InterpreterRuntime::monitorexit(end);
3140 }
3141 }
3142 if (dec_monitor_count) {
3143 THREAD->dec_held_monitor_count();
3144 }
3145
3146 // One error is plenty
3147 if (illegal_state_oop() == nullptr && !suppress_error) {
3148 {
3149 // Prevent any HandleMarkCleaner from freeing our live handles
3150 HandleMark __hm(THREAD);
3151 CALL_VM_NOCHECK(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD));
3152 }
3153 assert(THREAD->has_pending_exception(), "Lost our exception!");
3154 illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
3155 THREAD->clear_pending_exception();
3156 }
3157 }
3158 end++;
3159 }
3160 // Unlock the method if needed
3161 if (method_unlock_needed) {
3162 if (base->obj() == nullptr) {
3163 // The method is already unlocked this is not good.
3171 illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
3172 THREAD->clear_pending_exception();
3173 }
3174 } else {
3175 //
3176 // The initial monitor is always used for the method
3177 // However if that slot is no longer the oop for the method it was unlocked
3178 // and reused by something that wasn't unlocked!
3179 //
3180 // deopt can come in with rcvr dead because c2 knows
3181 // its value is preserved in the monitor. So we can't use locals[0] at all
3182 // and must use first monitor slot.
3183 //
3184 oop rcvr = base->obj();
3185 if (rcvr == nullptr) {
3186 if (!suppress_error) {
3187 VM_JAVA_ERROR_NO_JUMP(vmSymbols::java_lang_NullPointerException(), "");
3188 illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
3189 THREAD->clear_pending_exception();
3190 }
3191 } else if (LockingMode == LM_MONITOR) {
3192 InterpreterRuntime::monitorexit(base);
3193 if (THREAD->has_pending_exception()) {
3194 if (!suppress_error) illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
3195 THREAD->clear_pending_exception();
3196 }
3197 } else {
3198 BasicLock* lock = base->lock();
3199 markWord header = lock->displaced_header();
3200 base->set_obj(nullptr);
3201
3202 // If it isn't recursive we either must swap old header or call the runtime
3203 bool dec_monitor_count = true;
3204 if (header.to_pointer() != nullptr) {
3205 markWord old_header = markWord::encode(lock);
3206 if (rcvr->cas_set_mark(header, old_header) != old_header) {
3207 // restore object for the slow case
3208 base->set_obj(rcvr);
3209 dec_monitor_count = false;
3210 InterpreterRuntime::monitorexit(base);
3211 if (THREAD->has_pending_exception()) {
|
36 #include "jvm_io.h"
37 #include "logging/log.hpp"
38 #include "memory/resourceArea.hpp"
39 #include "memory/universe.hpp"
40 #include "oops/constantPool.inline.hpp"
41 #include "oops/cpCache.inline.hpp"
42 #include "oops/instanceKlass.inline.hpp"
43 #include "oops/klass.inline.hpp"
44 #include "oops/method.inline.hpp"
45 #include "oops/methodCounters.hpp"
46 #include "oops/objArrayKlass.hpp"
47 #include "oops/objArrayOop.inline.hpp"
48 #include "oops/oop.inline.hpp"
49 #include "oops/resolvedFieldEntry.hpp"
50 #include "oops/resolvedIndyEntry.hpp"
51 #include "oops/resolvedMethodEntry.hpp"
52 #include "oops/typeArrayOop.inline.hpp"
53 #include "prims/jvmtiExport.hpp"
54 #include "prims/jvmtiThreadState.hpp"
55 #include "runtime/atomic.hpp"
56 #include "runtime/basicLock.inline.hpp"
57 #include "runtime/frame.inline.hpp"
58 #include "runtime/globals.hpp"
59 #include "runtime/handles.inline.hpp"
60 #include "runtime/interfaceSupport.inline.hpp"
61 #include "runtime/orderAccess.hpp"
62 #include "runtime/sharedRuntime.hpp"
63 #include "runtime/threadCritical.hpp"
64 #include "utilities/debug.hpp"
65 #include "utilities/exceptions.hpp"
66 #include "utilities/globalDefinitions.hpp"
67 #include "utilities/macros.hpp"
68
69 /*
70 * USELABELS - If using GCC, then use labels for the opcode dispatching
71 * rather -then a switch statement. This improves performance because it
72 * gives us the opportunity to have the instructions that calculate the
73 * next opcode to jump to be intermixed with the rest of the instructions
74 * that implement the opcode (see UPDATE_PC_AND_TOS_AND_CONTINUE macro).
75 */
76 #undef USELABELS
77 #ifdef __GNUC__
78 /*
79 ASSERT signifies debugging. It is much easier to step thru bytecodes if we
80 don't use the computed goto approach.
81 */
82 #ifndef ASSERT
83 #define USELABELS
84 #endif
85 #endif
86
610 return;
611 }
612 case method_entry: {
613 THREAD->set_do_not_unlock_if_synchronized(true);
614
615 // Lock method if synchronized.
616 if (METHOD->is_synchronized()) {
617 // oop rcvr = locals[0].j.r;
618 oop rcvr;
619 if (METHOD->is_static()) {
620 rcvr = METHOD->constants()->pool_holder()->java_mirror();
621 } else {
622 rcvr = LOCALS_OBJECT(0);
623 VERIFY_OOP(rcvr);
624 }
625
626 // The initial monitor is ours for the taking.
627 BasicObjectLock* mon = &istate->monitor_base()[-1];
628 mon->set_obj(rcvr);
629
630 bool success = false;
631 if (LockingMode == LM_LEGACY) {
632 // Traditional lightweight locking.
633 markWord displaced = rcvr->mark().set_unlocked();
634 mon->lock()->set_displaced_header(displaced);
635 success = true;
636 if (rcvr->cas_set_mark(markWord::from_pointer(mon), displaced) != displaced) {
637 // Is it simple recursive case?
638 if (THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) {
639 mon->lock()->set_displaced_header(markWord::from_pointer(nullptr));
640 } else {
641 success = false;
642 }
643 }
644 if (success) {
645 THREAD->inc_held_monitor_count();
646 }
647 }
648 if (!success) {
649 CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception);
650 }
651
652 }
653 THREAD->set_do_not_unlock_if_synchronized(false);
654
655 // Notify jvmti.
656 // Whenever JVMTI puts a thread in interp_only_mode, method
657 // entry/exit events are sent for that thread to track stack depth.
658 if (JVMTI_ENABLED && THREAD->is_interp_only_mode()) {
659 CALL_VM(InterpreterRuntime::post_method_entry(THREAD),
660 handle_exception);
661 }
662
663 goto run;
664 }
665
666 case popping_frame: {
667 // returned from a java call to pop the frame, restart the call
668 // clear the message so we don't confuse ourselves later
669 assert(THREAD->pop_frame_in_process(), "wrong frame pop state");
670 istate->set_msg(no_request);
671 THREAD->clr_pop_frame_in_process();
714 //
715 if ( Bytecodes::code_at(METHOD, pc) == Bytecodes::_return_register_finalizer) {
716 // this will do the right thing even if an exception is pending.
717 goto handle_return;
718 }
719 UPDATE_PC(Bytecodes::length_at(METHOD, pc));
720 if (THREAD->has_pending_exception()) goto handle_exception;
721 goto run;
722 }
723 case got_monitors: {
724 // continue locking now that we have a monitor to use
725 // we expect to find newly allocated monitor at the "top" of the monitor stack.
726 oop lockee = STACK_OBJECT(-1);
727 VERIFY_OOP(lockee);
728 // derefing's lockee ought to provoke implicit null check
729 // find a free monitor
730 BasicObjectLock* entry = (BasicObjectLock*) istate->stack_base();
731 assert(entry->obj() == nullptr, "Frame manager didn't allocate the monitor");
732 entry->set_obj(lockee);
733
734 bool success = false;
735 if (LockingMode == LM_LEGACY) {
736 // traditional lightweight locking
737 markWord displaced = lockee->mark().set_unlocked();
738 entry->lock()->set_displaced_header(displaced);
739 success = true;
740 if (lockee->cas_set_mark(markWord::from_pointer(entry), displaced) != displaced) {
741 // Is it simple recursive case?
742 if (THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) {
743 entry->lock()->set_displaced_header(markWord::from_pointer(nullptr));
744 } else {
745 success = false;
746 }
747 }
748 if (success) {
749 THREAD->inc_held_monitor_count();
750 }
751 }
752 if (!success) {
753 CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
754 }
755
756 UPDATE_PC_AND_TOS(1, -1);
757 goto run;
758 }
759 default: {
760 fatal("Unexpected message from frame manager");
761 }
762 }
763
764 run:
765
766 DO_UPDATE_INSTRUCTION_COUNT(*pc)
767 DEBUGGER_SINGLE_STEP_NOTIFY();
768 #ifdef PREFETCH_OPCCODE
769 opcode = *pc; /* prefetch first opcode */
770 #endif
771
772 #ifndef USELABELS
773 while (1)
774 #endif
775 {
1649 /* monitorenter and monitorexit for locking/unlocking an object */
1650
1651 CASE(_monitorenter): {
1652 oop lockee = STACK_OBJECT(-1);
1653 // derefing's lockee ought to provoke implicit null check
1654 CHECK_NULL(lockee);
1655 // find a free monitor or one already allocated for this object
1656 // if we find a matching object then we need a new monitor
1657 // since this is recursive enter
1658 BasicObjectLock* limit = istate->monitor_base();
1659 BasicObjectLock* most_recent = (BasicObjectLock*) istate->stack_base();
1660 BasicObjectLock* entry = nullptr;
1661 while (most_recent != limit ) {
1662 if (most_recent->obj() == nullptr) entry = most_recent;
1663 else if (most_recent->obj() == lockee) break;
1664 most_recent++;
1665 }
1666 if (entry != nullptr) {
1667 entry->set_obj(lockee);
1668
1669 bool success = false;
1670 if (LockingMode == LM_LEGACY) {
1671 // traditional lightweight locking
1672 markWord displaced = lockee->mark().set_unlocked();
1673 entry->lock()->set_displaced_header(displaced);
1674 success = true;
1675 if (lockee->cas_set_mark(markWord::from_pointer(entry), displaced) != displaced) {
1676 // Is it simple recursive case?
1677 if (THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) {
1678 entry->lock()->set_displaced_header(markWord::from_pointer(nullptr));
1679 } else {
1680 success = false;
1681 }
1682 }
1683 if (success) {
1684 THREAD->inc_held_monitor_count();
1685 }
1686 }
1687 if (!success) {
1688 CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
1689 }
1690
1691 UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1692 } else {
1693 istate->set_msg(more_monitors);
1694 UPDATE_PC_AND_RETURN(0); // Re-execute
1695 }
1696 }
1697
1698 CASE(_monitorexit): {
1699 oop lockee = STACK_OBJECT(-1);
1700 CHECK_NULL(lockee);
1701 // derefing's lockee ought to provoke implicit null check
1702 // find our monitor slot
1703 BasicObjectLock* limit = istate->monitor_base();
1704 BasicObjectLock* most_recent = (BasicObjectLock*) istate->stack_base();
1705 while (most_recent != limit ) {
1706 if ((most_recent)->obj() == lockee) {
1707 BasicLock* lock = most_recent->lock();
1708
1709 bool success = false;
1710 if (LockingMode == LM_LEGACY) {
1711 // If it isn't recursive we either must swap old header or call the runtime
1712 most_recent->set_obj(nullptr);
1713 success = true;
1714 markWord header = lock->displaced_header();
1715 if (header.to_pointer() != nullptr) {
1716 markWord old_header = markWord::encode(lock);
1717 if (lockee->cas_set_mark(header, old_header) != old_header) {
1718 // restore object for the slow case
1719 most_recent->set_obj(lockee);
1720 success = false;
1721 }
1722 }
1723 if (success) {
1724 THREAD->dec_held_monitor_count();
1725 }
1726 }
1727 if (!success) {
1728 InterpreterRuntime::monitorexit(most_recent);
1729 }
1730 UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1731 }
1732 most_recent++;
1733 }
1734 // Need to throw illegal monitor state exception
1735 CALL_VM(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD), handle_exception);
1736 ShouldNotReachHere();
1737 }
1738
1739 /* All of the non-quick opcodes. */
1740
1741 /* -Set clobbersCpIndex true if the quickened opcode clobbers the
1742 * constant pool index in the instruction.
1743 */
1744 CASE(_getfield):
1745 CASE(_nofast_getfield):
1746 CASE(_getstatic):
1747 {
1748 u2 index;
2004 // To do this, we need to make sure:
2005 // - klass is initialized
2006 // - klass can be fastpath allocated (e.g. does not have finalizer)
2007 // - TLAB accepts the allocation
2008 ConstantPool* constants = istate->method()->constants();
2009 if (UseTLAB && !constants->tag_at(index).is_unresolved_klass()) {
2010 Klass* entry = constants->resolved_klass_at(index);
2011 InstanceKlass* ik = InstanceKlass::cast(entry);
2012 if (ik->is_initialized() && ik->can_be_fastpath_allocated()) {
2013 size_t obj_size = ik->size_helper();
2014 HeapWord* result = THREAD->tlab().allocate(obj_size);
2015 if (result != nullptr) {
2016 // Initialize object field block.
2017 if (!ZeroTLAB) {
2018 // The TLAB was not pre-zeroed, we need to clear the memory here.
2019 size_t hdr_size = oopDesc::header_size();
2020 Copy::fill_to_words(result + hdr_size, obj_size - hdr_size, 0);
2021 }
2022
2023 // Initialize header, mirrors MemAllocator.
2024 if (UseCompactObjectHeaders) {
2025 oopDesc::release_set_mark(result, ik->prototype_header());
2026 } else {
2027 oopDesc::set_mark(result, markWord::prototype());
2028 oopDesc::set_klass_gap(result, 0);
2029 oopDesc::release_set_klass(result, ik);
2030 }
2031 oop obj = cast_to_oop(result);
2032
2033 // Must prevent reordering of stores for object initialization
2034 // with stores that publish the new object.
2035 OrderAccess::storestore();
2036 SET_STACK_OBJECT(obj, 0);
2037 UPDATE_PC_AND_TOS_AND_CONTINUE(3, 1);
2038 }
2039 }
2040 }
2041 // Slow case allocation
2042 CALL_VM(InterpreterRuntime::_new(THREAD, METHOD->constants(), index),
2043 handle_exception);
2044 // Must prevent reordering of stores for object initialization
2045 // with stores that publish the new object.
2046 OrderAccess::storestore();
2047 SET_STACK_OBJECT(THREAD->vm_result(), 0);
2048 THREAD->set_vm_result(nullptr);
2049 UPDATE_PC_AND_TOS_AND_CONTINUE(3, 1);
2050 }
3133 // Another weird thing to watch for is if the method was locked
3134 // recursively and then not exited properly. This means we must
3135 // examine all the entries in reverse time(and stack) order and
3136 // unlock as we find them. If we find the method monitor before
3137 // we are at the initial entry then we should throw an exception.
3138 // It is not clear the template based interpreter does this
3139 // correctly
3140
3141 BasicObjectLock* base = istate->monitor_base();
3142 BasicObjectLock* end = (BasicObjectLock*) istate->stack_base();
3143 bool method_unlock_needed = METHOD->is_synchronized();
3144 // We know the initial monitor was used for the method don't check that
3145 // slot in the loop
3146 if (method_unlock_needed) base--;
3147
3148 // Check all the monitors to see they are unlocked. Install exception if found to be locked.
3149 while (end < base) {
3150 oop lockee = end->obj();
3151 if (lockee != nullptr) {
3152 BasicLock* lock = end->lock();
3153
3154 bool success = false;
3155 if (LockingMode == LM_LEGACY) {
3156 markWord header = lock->displaced_header();
3157 end->set_obj(nullptr);
3158
3159 // If it isn't recursive we either must swap old header or call the runtime
3160 success = true;
3161 if (header.to_pointer() != nullptr) {
3162 markWord old_header = markWord::encode(lock);
3163 if (lockee->cas_set_mark(header, old_header) != old_header) {
3164 // restore object for the slow case
3165 end->set_obj(lockee);
3166 success = false;
3167 }
3168 }
3169 if (success) {
3170 THREAD->dec_held_monitor_count();
3171 }
3172 }
3173 if (!success) {
3174 InterpreterRuntime::monitorexit(end);
3175 }
3176
3177 // One error is plenty
3178 if (illegal_state_oop() == nullptr && !suppress_error) {
3179 {
3180 // Prevent any HandleMarkCleaner from freeing our live handles
3181 HandleMark __hm(THREAD);
3182 CALL_VM_NOCHECK(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD));
3183 }
3184 assert(THREAD->has_pending_exception(), "Lost our exception!");
3185 illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
3186 THREAD->clear_pending_exception();
3187 }
3188 }
3189 end++;
3190 }
3191 // Unlock the method if needed
3192 if (method_unlock_needed) {
3193 if (base->obj() == nullptr) {
3194 // The method is already unlocked this is not good.
3202 illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
3203 THREAD->clear_pending_exception();
3204 }
3205 } else {
3206 //
3207 // The initial monitor is always used for the method
3208 // However if that slot is no longer the oop for the method it was unlocked
3209 // and reused by something that wasn't unlocked!
3210 //
3211 // deopt can come in with rcvr dead because c2 knows
3212 // its value is preserved in the monitor. So we can't use locals[0] at all
3213 // and must use first monitor slot.
3214 //
3215 oop rcvr = base->obj();
3216 if (rcvr == nullptr) {
3217 if (!suppress_error) {
3218 VM_JAVA_ERROR_NO_JUMP(vmSymbols::java_lang_NullPointerException(), "");
3219 illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
3220 THREAD->clear_pending_exception();
3221 }
3222 } else if (LockingMode != LM_LEGACY) {
3223 InterpreterRuntime::monitorexit(base);
3224 if (THREAD->has_pending_exception()) {
3225 if (!suppress_error) illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
3226 THREAD->clear_pending_exception();
3227 }
3228 } else {
3229 BasicLock* lock = base->lock();
3230 markWord header = lock->displaced_header();
3231 base->set_obj(nullptr);
3232
3233 // If it isn't recursive we either must swap old header or call the runtime
3234 bool dec_monitor_count = true;
3235 if (header.to_pointer() != nullptr) {
3236 markWord old_header = markWord::encode(lock);
3237 if (rcvr->cas_set_mark(header, old_header) != old_header) {
3238 // restore object for the slow case
3239 base->set_obj(rcvr);
3240 dec_monitor_count = false;
3241 InterpreterRuntime::monitorexit(base);
3242 if (THREAD->has_pending_exception()) {
|