< prev index next >

src/hotspot/share/interpreter/zero/bytecodeInterpreter.cpp

Print this page

 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 fast 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: {

 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 fast 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

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 fast 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):

3146       while (end < base) {
3147         oop lockee = end->obj();
3148         if (lockee != nullptr) {
3149           BasicLock* lock = end->lock();
3150 
3151           bool success = false;
3152           if (LockingMode == LM_LEGACY) {
3153             markWord header = lock->displaced_header();
3154             end->set_obj(nullptr);
3155 
3156             // If it isn't recursive we either must swap old header or call the runtime
3157             success = true;
3158             if (header.to_pointer() != nullptr) {
3159               markWord old_header = markWord::encode(lock);
3160               if (lockee->cas_set_mark(header, old_header) != old_header) {
3161                 // restore object for the slow case
3162                 end->set_obj(lockee);
3163                 success = false;
3164               }
3165             }
3166             if (success) {
3167               THREAD->dec_held_monitor_count();
3168             }
3169           }
3170           if (!success) {
3171             InterpreterRuntime::monitorexit(end);
3172           }
3173 
3174           // One error is plenty
3175           if (illegal_state_oop() == nullptr && !suppress_error) {
3176             {
3177               // Prevent any HandleMarkCleaner from freeing our live handles
3178               HandleMark __hm(THREAD);
3179               CALL_VM_NOCHECK(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD));
3180             }
3181             assert(THREAD->has_pending_exception(), "Lost our exception!");
3182             illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
3183             THREAD->clear_pending_exception();
3184           }
3185         }
3186         end++;
3187       }
3188       // Unlock the method if needed

3225           } else {
3226             BasicLock* lock = base->lock();
3227             markWord header = lock->displaced_header();
3228             base->set_obj(nullptr);
3229 
3230             // If it isn't recursive we either must swap old header or call the runtime
3231             bool dec_monitor_count = true;
3232             if (header.to_pointer() != nullptr) {
3233               markWord old_header = markWord::encode(lock);
3234               if (rcvr->cas_set_mark(header, old_header) != old_header) {
3235                 // restore object for the slow case
3236                 base->set_obj(rcvr);
3237                 dec_monitor_count = false;
3238                 InterpreterRuntime::monitorexit(base);
3239                 if (THREAD->has_pending_exception()) {
3240                   if (!suppress_error) illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
3241                   THREAD->clear_pending_exception();
3242                 }
3243               }
3244             }
3245             if (dec_monitor_count) {
3246               THREAD->dec_held_monitor_count();
3247             }
3248           }
3249         }
3250       }
3251     }
3252     // Clear the do_not_unlock flag now.
3253     THREAD->set_do_not_unlock_if_synchronized(false);
3254 
3255     //
3256     // Notify jvmti/jvmdi
3257     //
3258     // NOTE: we do not notify a method_exit if we have a pending exception,
3259     // including an exception we generate for unlocking checks.  In the former
3260     // case, JVMDI has already been notified by our call for the exception handler
3261     // and in both cases as far as JVMDI is concerned we have already returned.
3262     // If we notify it again JVMDI will be all confused about how many frames
3263     // are still on the stack (4340444).
3264     //
3265     // NOTE Further! It turns out the JVMTI spec in fact expects to see
3266     // method_exit events whenever we leave an activation unless it was done
3267     // for popframe. This is nothing like jvmdi. However we are passing the

 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 fast 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         }
 645         if (!success) {
 646             CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception);
 647         }
 648 
 649       }
 650       THREAD->set_do_not_unlock_if_synchronized(false);
 651 
 652       // Notify jvmti.
 653       // Whenever JVMTI puts a thread in interp_only_mode, method
 654       // entry/exit events are sent for that thread to track stack depth.
 655       if (JVMTI_ENABLED && THREAD->is_interp_only_mode()) {
 656         CALL_VM(InterpreterRuntime::post_method_entry(THREAD),
 657                 handle_exception);
 658       }
 659 
 660       goto run;
 661     }
 662 
 663     case popping_frame: {

 725       // derefing's lockee ought to provoke implicit null check
 726       // find a free monitor
 727       BasicObjectLock* entry = (BasicObjectLock*) istate->stack_base();
 728       assert(entry->obj() == nullptr, "Frame manager didn't allocate the monitor");
 729       entry->set_obj(lockee);
 730 
 731       bool success = false;
 732       if (LockingMode == LM_LEGACY) {
 733         // Traditional fast locking.
 734         markWord displaced = lockee->mark().set_unlocked();
 735         entry->lock()->set_displaced_header(displaced);
 736         success = true;
 737         if (lockee->cas_set_mark(markWord::from_pointer(entry), displaced) != displaced) {
 738           // Is it simple recursive case?
 739           if (THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) {
 740             entry->lock()->set_displaced_header(markWord::from_pointer(nullptr));
 741           } else {
 742             success = false;
 743           }
 744         }



 745       }
 746       if (!success) {
 747         CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
 748       }
 749 
 750       UPDATE_PC_AND_TOS(1, -1);
 751       goto run;
 752     }
 753     default: {
 754       fatal("Unexpected message from frame manager");
 755     }
 756   }
 757 
 758 run:
 759 
 760   DO_UPDATE_INSTRUCTION_COUNT(*pc)
 761   DEBUGGER_SINGLE_STEP_NOTIFY();
 762 #ifdef PREFETCH_OPCCODE
 763   opcode = *pc;  /* prefetch first opcode */
 764 #endif

1657           else if (most_recent->obj() == lockee) break;
1658           most_recent++;
1659         }
1660         if (entry != nullptr) {
1661           entry->set_obj(lockee);
1662 
1663           bool success = false;
1664           if (LockingMode == LM_LEGACY) {
1665             // Traditional fast locking.
1666             markWord displaced = lockee->mark().set_unlocked();
1667             entry->lock()->set_displaced_header(displaced);
1668             success = true;
1669             if (lockee->cas_set_mark(markWord::from_pointer(entry), displaced) != displaced) {
1670               // Is it simple recursive case?
1671               if (THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) {
1672                 entry->lock()->set_displaced_header(markWord::from_pointer(nullptr));
1673               } else {
1674                 success = false;
1675               }
1676             }



1677           }
1678           if (!success) {
1679             CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
1680           }
1681 
1682           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1683         } else {
1684           istate->set_msg(more_monitors);
1685           UPDATE_PC_AND_RETURN(0); // Re-execute
1686         }
1687       }
1688 
1689       CASE(_monitorexit): {
1690         oop lockee = STACK_OBJECT(-1);
1691         CHECK_NULL(lockee);
1692         // derefing's lockee ought to provoke implicit null check
1693         // find our monitor slot
1694         BasicObjectLock* limit = istate->monitor_base();
1695         BasicObjectLock* most_recent = (BasicObjectLock*) istate->stack_base();
1696         while (most_recent != limit ) {
1697           if ((most_recent)->obj() == lockee) {
1698             BasicLock* lock = most_recent->lock();
1699 
1700             bool success = false;
1701             if (LockingMode == LM_LEGACY) {
1702               // If it isn't recursive we either must swap old header or call the runtime
1703               most_recent->set_obj(nullptr);
1704               success = true;
1705               markWord header = lock->displaced_header();
1706               if (header.to_pointer() != nullptr) {
1707                 markWord old_header = markWord::encode(lock);
1708                 if (lockee->cas_set_mark(header, old_header) != old_header) {
1709                   // restore object for the slow case
1710                   most_recent->set_obj(lockee);
1711                   success = false;
1712                 }
1713               }



1714             }
1715             if (!success) {
1716               InterpreterRuntime::monitorexit(most_recent);
1717             }
1718             UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1719           }
1720           most_recent++;
1721         }
1722         // Need to throw illegal monitor state exception
1723         CALL_VM(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD), handle_exception);
1724         ShouldNotReachHere();
1725       }
1726 
1727       /* All of the non-quick opcodes. */
1728 
1729       /* -Set clobbersCpIndex true if the quickened opcode clobbers the
1730        *  constant pool index in the instruction.
1731        */
1732       CASE(_getfield):
1733       CASE(_nofast_getfield):

3134       while (end < base) {
3135         oop lockee = end->obj();
3136         if (lockee != nullptr) {
3137           BasicLock* lock = end->lock();
3138 
3139           bool success = false;
3140           if (LockingMode == LM_LEGACY) {
3141             markWord header = lock->displaced_header();
3142             end->set_obj(nullptr);
3143 
3144             // If it isn't recursive we either must swap old header or call the runtime
3145             success = true;
3146             if (header.to_pointer() != nullptr) {
3147               markWord old_header = markWord::encode(lock);
3148               if (lockee->cas_set_mark(header, old_header) != old_header) {
3149                 // restore object for the slow case
3150                 end->set_obj(lockee);
3151                 success = false;
3152               }
3153             }



3154           }
3155           if (!success) {
3156             InterpreterRuntime::monitorexit(end);
3157           }
3158 
3159           // One error is plenty
3160           if (illegal_state_oop() == nullptr && !suppress_error) {
3161             {
3162               // Prevent any HandleMarkCleaner from freeing our live handles
3163               HandleMark __hm(THREAD);
3164               CALL_VM_NOCHECK(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD));
3165             }
3166             assert(THREAD->has_pending_exception(), "Lost our exception!");
3167             illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
3168             THREAD->clear_pending_exception();
3169           }
3170         }
3171         end++;
3172       }
3173       // Unlock the method if needed

3210           } else {
3211             BasicLock* lock = base->lock();
3212             markWord header = lock->displaced_header();
3213             base->set_obj(nullptr);
3214 
3215             // If it isn't recursive we either must swap old header or call the runtime
3216             bool dec_monitor_count = true;
3217             if (header.to_pointer() != nullptr) {
3218               markWord old_header = markWord::encode(lock);
3219               if (rcvr->cas_set_mark(header, old_header) != old_header) {
3220                 // restore object for the slow case
3221                 base->set_obj(rcvr);
3222                 dec_monitor_count = false;
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               }
3229             }



3230           }
3231         }
3232       }
3233     }
3234     // Clear the do_not_unlock flag now.
3235     THREAD->set_do_not_unlock_if_synchronized(false);
3236 
3237     //
3238     // Notify jvmti/jvmdi
3239     //
3240     // NOTE: we do not notify a method_exit if we have a pending exception,
3241     // including an exception we generate for unlocking checks.  In the former
3242     // case, JVMDI has already been notified by our call for the exception handler
3243     // and in both cases as far as JVMDI is concerned we have already returned.
3244     // If we notify it again JVMDI will be all confused about how many frames
3245     // are still on the stack (4340444).
3246     //
3247     // NOTE Further! It turns out the JVMTI spec in fact expects to see
3248     // method_exit events whenever we leave an activation unless it was done
3249     // for popframe. This is nothing like jvmdi. However we are passing the
< prev index next >