< prev index next >

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

Print this page

 610       if (METHOD->is_synchronized()) {
 611         // oop rcvr = locals[0].j.r;
 612         oop rcvr;
 613         if (METHOD->is_static()) {
 614           rcvr = METHOD->constants()->pool_holder()->java_mirror();
 615         } else {
 616           rcvr = LOCALS_OBJECT(0);
 617           VERIFY_OOP(rcvr);
 618         }
 619 
 620         // The initial monitor is ours for the taking.
 621         // Monitor not filled in frame manager any longer as this caused race condition with biased locking.
 622         BasicObjectLock* mon = &istate->monitor_base()[-1];
 623         mon->set_obj(rcvr);
 624 
 625         assert(!UseBiasedLocking, "Not implemented");
 626 
 627         // Traditional lightweight locking.
 628         markWord displaced = rcvr->mark().set_unlocked();
 629         mon->lock()->set_displaced_header(displaced);
 630         bool call_vm = UseHeavyMonitors;
 631         if (call_vm || rcvr->cas_set_mark(markWord::from_pointer(mon), displaced) != displaced) {
 632           // Is it simple recursive case?
 633           if (!call_vm && THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) {
 634             mon->lock()->set_displaced_header(markWord::from_pointer(NULL));
 635           } else {
 636             CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception);
 637           }
 638         }
 639       }
 640       THREAD->clr_do_not_unlock();
 641 
 642       // Notify jvmti.
 643       // Whenever JVMTI puts a thread in interp_only_mode, method
 644       // entry/exit events are sent for that thread to track stack depth.
 645       if (JVMTI_ENABLED && THREAD->is_interp_only_mode()) {
 646         CALL_VM(InterpreterRuntime::post_method_entry(THREAD),
 647                 handle_exception);
 648       }
 649 
 650       goto run;

 706       UPDATE_PC(Bytecodes::length_at(METHOD, pc));
 707       if (THREAD->has_pending_exception()) goto handle_exception;
 708       goto run;
 709     }
 710     case got_monitors: {
 711       // continue locking now that we have a monitor to use
 712       // we expect to find newly allocated monitor at the "top" of the monitor stack.
 713       oop lockee = STACK_OBJECT(-1);
 714       VERIFY_OOP(lockee);
 715       // derefing's lockee ought to provoke implicit null check
 716       // find a free monitor
 717       BasicObjectLock* entry = (BasicObjectLock*) istate->stack_base();
 718       assert(entry->obj() == NULL, "Frame manager didn't allocate the monitor");
 719       entry->set_obj(lockee);
 720 
 721       assert(!UseBiasedLocking, "Not implemented");
 722 
 723       // traditional lightweight locking
 724       markWord displaced = lockee->mark().set_unlocked();
 725       entry->lock()->set_displaced_header(displaced);
 726       bool call_vm = UseHeavyMonitors;
 727       if (call_vm || lockee->cas_set_mark(markWord::from_pointer(entry), displaced) != displaced) {
 728         // Is it simple recursive case?
 729         if (!call_vm && THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) {
 730           entry->lock()->set_displaced_header(markWord::from_pointer(NULL));
 731         } else {
 732           CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
 733         }
 734       }
 735       UPDATE_PC_AND_TOS(1, -1);
 736       goto run;
 737     }
 738     default: {
 739       fatal("Unexpected message from frame manager");
 740     }
 741   }
 742 
 743 run:
 744 
 745   DO_UPDATE_INSTRUCTION_COUNT(*pc)
 746   DEBUGGER_SINGLE_STEP_NOTIFY();

1616         CHECK_NULL(lockee);
1617         // find a free monitor or one already allocated for this object
1618         // if we find a matching object then we need a new monitor
1619         // since this is recursive enter
1620         BasicObjectLock* limit = istate->monitor_base();
1621         BasicObjectLock* most_recent = (BasicObjectLock*) istate->stack_base();
1622         BasicObjectLock* entry = NULL;
1623         while (most_recent != limit ) {
1624           if (most_recent->obj() == NULL) entry = most_recent;
1625           else if (most_recent->obj() == lockee) break;
1626           most_recent++;
1627         }
1628         if (entry != NULL) {
1629           entry->set_obj(lockee);
1630 
1631           assert(!UseBiasedLocking, "Not implemented");
1632 
1633           // traditional lightweight locking
1634           markWord displaced = lockee->mark().set_unlocked();
1635           entry->lock()->set_displaced_header(displaced);
1636           bool call_vm = UseHeavyMonitors;
1637           if (call_vm || lockee->cas_set_mark(markWord::from_pointer(entry), displaced) != displaced) {
1638             // Is it simple recursive case?
1639             if (!call_vm && THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) {
1640               entry->lock()->set_displaced_header(markWord::from_pointer(NULL));
1641             } else {
1642               CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
1643             }
1644           }
1645           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1646         } else {
1647           istate->set_msg(more_monitors);
1648           UPDATE_PC_AND_RETURN(0); // Re-execute
1649         }
1650       }
1651 
1652       CASE(_monitorexit): {
1653         oop lockee = STACK_OBJECT(-1);
1654         CHECK_NULL(lockee);
1655         // derefing's lockee ought to provoke implicit null check
1656         // find our monitor slot
1657         BasicObjectLock* limit = istate->monitor_base();
1658         BasicObjectLock* most_recent = (BasicObjectLock*) istate->stack_base();
1659         while (most_recent != limit ) {
1660           if ((most_recent)->obj() == lockee) {
1661             BasicLock* lock = most_recent->lock();
1662             markWord header = lock->displaced_header();
1663             most_recent->set_obj(NULL);
1664 
1665             assert(!UseBiasedLocking, "Not implemented");
1666 
1667             // If it isn't recursive we either must swap old header or call the runtime
1668             bool call_vm = UseHeavyMonitors;
1669             if (header.to_pointer() != NULL || call_vm) {
1670               markWord old_header = markWord::encode(lock);
1671               if (call_vm || lockee->cas_set_mark(header, old_header) != old_header) {
1672                 // restore object for the slow case
1673                 most_recent->set_obj(lockee);
1674                 InterpreterRuntime::monitorexit(most_recent);
1675               }
1676             }
1677             UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1678           }
1679           most_recent++;
1680         }
1681         // Need to throw illegal monitor state exception
1682         CALL_VM(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD), handle_exception);
1683         ShouldNotReachHere();
1684       }
1685 
1686       /* All of the non-quick opcodes. */
1687 
1688       /* -Set clobbersCpIndex true if the quickened opcode clobbers the

1938         if (UseTLAB && !constants->tag_at(index).is_unresolved_klass()) {
1939           Klass* entry = constants->resolved_klass_at(index);
1940           InstanceKlass* ik = InstanceKlass::cast(entry);
1941           if (ik->is_initialized() && ik->can_be_fastpath_allocated()) {
1942             size_t obj_size = ik->size_helper();
1943             HeapWord* result = THREAD->tlab().allocate(obj_size);
1944             if (result != NULL) {
1945               // Initialize object field block:
1946               //   - if TLAB is pre-zeroed, we can skip this path
1947               //   - in debug mode, ThreadLocalAllocBuffer::allocate mangles
1948               //     this area, and we still need to initialize it
1949               if (DEBUG_ONLY(true ||) !ZeroTLAB) {
1950                 size_t hdr_size = oopDesc::header_size();
1951                 Copy::fill_to_words(result + hdr_size, obj_size - hdr_size, 0);
1952               }
1953 
1954               oop obj = cast_to_oop(result);
1955 
1956               // Initialize header
1957               assert(!UseBiasedLocking, "Not implemented");
1958               obj->set_mark(markWord::prototype());
1959               obj->set_klass_gap(0);
1960               obj->set_klass(ik);
1961 


1962               // Must prevent reordering of stores for object initialization
1963               // with stores that publish the new object.
1964               OrderAccess::storestore();
1965               SET_STACK_OBJECT(obj, 0);
1966               UPDATE_PC_AND_TOS_AND_CONTINUE(3, 1);
1967             }
1968           }
1969         }
1970         // Slow case allocation
1971         CALL_VM(InterpreterRuntime::_new(THREAD, METHOD->constants(), index),
1972                 handle_exception);
1973         // Must prevent reordering of stores for object initialization
1974         // with stores that publish the new object.
1975         OrderAccess::storestore();
1976         SET_STACK_OBJECT(THREAD->vm_result(), 0);
1977         THREAD->set_vm_result(NULL);
1978         UPDATE_PC_AND_TOS_AND_CONTINUE(3, 1);
1979       }
1980       CASE(_anewarray): {
1981         u2 index = Bytes::get_Java_u2(pc+1);

3129             illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
3130             THREAD->clear_pending_exception();
3131           }
3132         } else {
3133           //
3134           // The initial monitor is always used for the method
3135           // However if that slot is no longer the oop for the method it was unlocked
3136           // and reused by something that wasn't unlocked!
3137           //
3138           // deopt can come in with rcvr dead because c2 knows
3139           // its value is preserved in the monitor. So we can't use locals[0] at all
3140           // and must use first monitor slot.
3141           //
3142           oop rcvr = base->obj();
3143           if (rcvr == NULL) {
3144             if (!suppress_error) {
3145               VM_JAVA_ERROR_NO_JUMP(vmSymbols::java_lang_NullPointerException(), "");
3146               illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
3147               THREAD->clear_pending_exception();
3148             }
3149           } else if (UseHeavyMonitors) {
3150             InterpreterRuntime::monitorexit(base);
3151             if (THREAD->has_pending_exception()) {
3152               if (!suppress_error) illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
3153               THREAD->clear_pending_exception();
3154             }
3155           } else {
3156             BasicLock* lock = base->lock();
3157             markWord header = lock->displaced_header();
3158             base->set_obj(NULL);
3159 
3160             assert(!UseBiasedLocking, "Not implemented");
3161 
3162             // If it isn't recursive we either must swap old header or call the runtime
3163             if (header.to_pointer() != NULL) {
3164               markWord old_header = markWord::encode(lock);
3165               if (rcvr->cas_set_mark(header, old_header) != old_header) {
3166                 // restore object for the slow case
3167                 base->set_obj(rcvr);
3168                 InterpreterRuntime::monitorexit(base);
3169                 if (THREAD->has_pending_exception()) {

 610       if (METHOD->is_synchronized()) {
 611         // oop rcvr = locals[0].j.r;
 612         oop rcvr;
 613         if (METHOD->is_static()) {
 614           rcvr = METHOD->constants()->pool_holder()->java_mirror();
 615         } else {
 616           rcvr = LOCALS_OBJECT(0);
 617           VERIFY_OOP(rcvr);
 618         }
 619 
 620         // The initial monitor is ours for the taking.
 621         // Monitor not filled in frame manager any longer as this caused race condition with biased locking.
 622         BasicObjectLock* mon = &istate->monitor_base()[-1];
 623         mon->set_obj(rcvr);
 624 
 625         assert(!UseBiasedLocking, "Not implemented");
 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         if (call_vm || rcvr->cas_set_mark(markWord::from_pointer(mon), displaced) != displaced) {
 632           // Is it simple recursive case?
 633           if (!call_vm && THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) {
 634             mon->lock()->set_displaced_header(markWord::from_pointer(NULL));
 635           } else {
 636             CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception);
 637           }
 638         }
 639       }
 640       THREAD->clr_do_not_unlock();
 641 
 642       // Notify jvmti.
 643       // Whenever JVMTI puts a thread in interp_only_mode, method
 644       // entry/exit events are sent for that thread to track stack depth.
 645       if (JVMTI_ENABLED && THREAD->is_interp_only_mode()) {
 646         CALL_VM(InterpreterRuntime::post_method_entry(THREAD),
 647                 handle_exception);
 648       }
 649 
 650       goto run;

 706       UPDATE_PC(Bytecodes::length_at(METHOD, pc));
 707       if (THREAD->has_pending_exception()) goto handle_exception;
 708       goto run;
 709     }
 710     case got_monitors: {
 711       // continue locking now that we have a monitor to use
 712       // we expect to find newly allocated monitor at the "top" of the monitor stack.
 713       oop lockee = STACK_OBJECT(-1);
 714       VERIFY_OOP(lockee);
 715       // derefing's lockee ought to provoke implicit null check
 716       // find a free monitor
 717       BasicObjectLock* entry = (BasicObjectLock*) istate->stack_base();
 718       assert(entry->obj() == NULL, "Frame manager didn't allocate the monitor");
 719       entry->set_obj(lockee);
 720 
 721       assert(!UseBiasedLocking, "Not implemented");
 722 
 723       // traditional lightweight locking
 724       markWord displaced = lockee->mark().set_unlocked();
 725       entry->lock()->set_displaced_header(displaced);
 726       bool call_vm = (LockingMode == LM_MONITOR);
 727       if (call_vm || lockee->cas_set_mark(markWord::from_pointer(entry), displaced) != displaced) {
 728         // Is it simple recursive case?
 729         if (!call_vm && THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) {
 730           entry->lock()->set_displaced_header(markWord::from_pointer(NULL));
 731         } else {
 732           CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
 733         }
 734       }
 735       UPDATE_PC_AND_TOS(1, -1);
 736       goto run;
 737     }
 738     default: {
 739       fatal("Unexpected message from frame manager");
 740     }
 741   }
 742 
 743 run:
 744 
 745   DO_UPDATE_INSTRUCTION_COUNT(*pc)
 746   DEBUGGER_SINGLE_STEP_NOTIFY();

1616         CHECK_NULL(lockee);
1617         // find a free monitor or one already allocated for this object
1618         // if we find a matching object then we need a new monitor
1619         // since this is recursive enter
1620         BasicObjectLock* limit = istate->monitor_base();
1621         BasicObjectLock* most_recent = (BasicObjectLock*) istate->stack_base();
1622         BasicObjectLock* entry = NULL;
1623         while (most_recent != limit ) {
1624           if (most_recent->obj() == NULL) entry = most_recent;
1625           else if (most_recent->obj() == lockee) break;
1626           most_recent++;
1627         }
1628         if (entry != NULL) {
1629           entry->set_obj(lockee);
1630 
1631           assert(!UseBiasedLocking, "Not implemented");
1632 
1633           // traditional lightweight locking
1634           markWord displaced = lockee->mark().set_unlocked();
1635           entry->lock()->set_displaced_header(displaced);
1636           bool call_vm = (LockingMode == LM_MONITOR);
1637           if (call_vm || lockee->cas_set_mark(markWord::from_pointer(entry), displaced) != displaced) {
1638             // Is it simple recursive case?
1639             if (!call_vm && THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) {
1640               entry->lock()->set_displaced_header(markWord::from_pointer(NULL));
1641             } else {
1642               CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
1643             }
1644           }
1645           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1646         } else {
1647           istate->set_msg(more_monitors);
1648           UPDATE_PC_AND_RETURN(0); // Re-execute
1649         }
1650       }
1651 
1652       CASE(_monitorexit): {
1653         oop lockee = STACK_OBJECT(-1);
1654         CHECK_NULL(lockee);
1655         // derefing's lockee ought to provoke implicit null check
1656         // find our monitor slot
1657         BasicObjectLock* limit = istate->monitor_base();
1658         BasicObjectLock* most_recent = (BasicObjectLock*) istate->stack_base();
1659         while (most_recent != limit ) {
1660           if ((most_recent)->obj() == lockee) {
1661             BasicLock* lock = most_recent->lock();
1662             markWord header = lock->displaced_header();
1663             most_recent->set_obj(NULL);
1664 
1665             assert(!UseBiasedLocking, "Not implemented");
1666 
1667             // If it isn't recursive we either must swap old header or call the runtime
1668             bool call_vm = (LockingMode == LM_MONITOR);
1669             if (header.to_pointer() != NULL || call_vm) {
1670               markWord old_header = markWord::encode(lock);
1671               if (call_vm || lockee->cas_set_mark(header, old_header) != old_header) {
1672                 // restore object for the slow case
1673                 most_recent->set_obj(lockee);
1674                 InterpreterRuntime::monitorexit(most_recent);
1675               }
1676             }
1677             UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1678           }
1679           most_recent++;
1680         }
1681         // Need to throw illegal monitor state exception
1682         CALL_VM(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD), handle_exception);
1683         ShouldNotReachHere();
1684       }
1685 
1686       /* All of the non-quick opcodes. */
1687 
1688       /* -Set clobbersCpIndex true if the quickened opcode clobbers the

1938         if (UseTLAB && !constants->tag_at(index).is_unresolved_klass()) {
1939           Klass* entry = constants->resolved_klass_at(index);
1940           InstanceKlass* ik = InstanceKlass::cast(entry);
1941           if (ik->is_initialized() && ik->can_be_fastpath_allocated()) {
1942             size_t obj_size = ik->size_helper();
1943             HeapWord* result = THREAD->tlab().allocate(obj_size);
1944             if (result != NULL) {
1945               // Initialize object field block:
1946               //   - if TLAB is pre-zeroed, we can skip this path
1947               //   - in debug mode, ThreadLocalAllocBuffer::allocate mangles
1948               //     this area, and we still need to initialize it
1949               if (DEBUG_ONLY(true ||) !ZeroTLAB) {
1950                 size_t hdr_size = oopDesc::header_size();
1951                 Copy::fill_to_words(result + hdr_size, obj_size - hdr_size, 0);
1952               }
1953 
1954               oop obj = cast_to_oop(result);
1955 
1956               // Initialize header
1957               assert(!UseBiasedLocking, "Not implemented");
1958               if (UseCompactObjectHeaders) {
1959                 oopDesc::release_set_mark(result, ik->prototype_header());
1960               } else {
1961                 obj->set_mark(markWord::prototype());
1962                 obj->set_klass(ik);
1963               }
1964               // Must prevent reordering of stores for object initialization
1965               // with stores that publish the new object.
1966               OrderAccess::storestore();
1967               SET_STACK_OBJECT(obj, 0);
1968               UPDATE_PC_AND_TOS_AND_CONTINUE(3, 1);
1969             }
1970           }
1971         }
1972         // Slow case allocation
1973         CALL_VM(InterpreterRuntime::_new(THREAD, METHOD->constants(), index),
1974                 handle_exception);
1975         // Must prevent reordering of stores for object initialization
1976         // with stores that publish the new object.
1977         OrderAccess::storestore();
1978         SET_STACK_OBJECT(THREAD->vm_result(), 0);
1979         THREAD->set_vm_result(NULL);
1980         UPDATE_PC_AND_TOS_AND_CONTINUE(3, 1);
1981       }
1982       CASE(_anewarray): {
1983         u2 index = Bytes::get_Java_u2(pc+1);

3131             illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
3132             THREAD->clear_pending_exception();
3133           }
3134         } else {
3135           //
3136           // The initial monitor is always used for the method
3137           // However if that slot is no longer the oop for the method it was unlocked
3138           // and reused by something that wasn't unlocked!
3139           //
3140           // deopt can come in with rcvr dead because c2 knows
3141           // its value is preserved in the monitor. So we can't use locals[0] at all
3142           // and must use first monitor slot.
3143           //
3144           oop rcvr = base->obj();
3145           if (rcvr == NULL) {
3146             if (!suppress_error) {
3147               VM_JAVA_ERROR_NO_JUMP(vmSymbols::java_lang_NullPointerException(), "");
3148               illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
3149               THREAD->clear_pending_exception();
3150             }
3151           } else if (LockingMode == LM_MONITOR) {
3152             InterpreterRuntime::monitorexit(base);
3153             if (THREAD->has_pending_exception()) {
3154               if (!suppress_error) illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
3155               THREAD->clear_pending_exception();
3156             }
3157           } else {
3158             BasicLock* lock = base->lock();
3159             markWord header = lock->displaced_header();
3160             base->set_obj(NULL);
3161 
3162             assert(!UseBiasedLocking, "Not implemented");
3163 
3164             // If it isn't recursive we either must swap old header or call the runtime
3165             if (header.to_pointer() != NULL) {
3166               markWord old_header = markWord::encode(lock);
3167               if (rcvr->cas_set_mark(header, old_header) != old_header) {
3168                 // restore object for the slow case
3169                 base->set_obj(rcvr);
3170                 InterpreterRuntime::monitorexit(base);
3171                 if (THREAD->has_pending_exception()) {
< prev index next >