< prev index next >

src/hotspot/share/interpreter/bytecodeInterpreter.cpp

Print this page




 653 
 654       // Lock method if synchronized.
 655       if (METHOD->is_synchronized()) {
 656         // oop rcvr = locals[0].j.r;
 657         oop rcvr;
 658         if (METHOD->is_static()) {
 659           rcvr = METHOD->constants()->pool_holder()->java_mirror();
 660         } else {
 661           rcvr = LOCALS_OBJECT(0);
 662           VERIFY_OOP(rcvr);
 663         }
 664         // The initial monitor is ours for the taking.
 665         // Monitor not filled in frame manager any longer as this caused race condition with biased locking.
 666         BasicObjectLock* mon = &istate->monitor_base()[-1];
 667         mon->set_obj(rcvr);
 668         bool success = false;
 669         uintptr_t epoch_mask_in_place = (uintptr_t)markWord::epoch_mask_in_place;
 670         markWord mark = rcvr->mark();
 671         intptr_t hash = (intptr_t) markWord::no_hash;
 672         // Implies UseBiasedLocking.
 673         if (mark->has_bias_pattern()) {
 674           uintptr_t thread_ident;
 675           uintptr_t anticipated_bias_locking_value;
 676           thread_ident = (uintptr_t)istate->thread();
 677           anticipated_bias_locking_value =
 678             (((uintptr_t)rcvr->klass()->prototype_header() | thread_ident) ^ (uintptr_t)mark) &
 679             ~((uintptr_t) markWord::age_mask_in_place);
 680 
 681           if (anticipated_bias_locking_value == 0) {
 682             // Already biased towards this thread, nothing to do.
 683             if (PrintBiasedLockingStatistics) {
 684               (* BiasedLocking::biased_lock_entry_count_addr())++;
 685             }
 686             success = true;
 687           } else if ((anticipated_bias_locking_value & markWord::biased_lock_mask_in_place) != 0) {
 688             // Try to revoke bias.
 689             markWord header = rcvr->klass()->prototype_header();
 690             if (hash != markWord::no_hash) {
 691               header = header->copy_set_hash(hash);
 692             }
 693             if (rcvr->cas_set_mark(header, mark) == mark) {
 694               if (PrintBiasedLockingStatistics)
 695                 (*BiasedLocking::revoked_lock_entry_count_addr())++;
 696             }
 697           } else if ((anticipated_bias_locking_value & epoch_mask_in_place) != 0) {
 698             // Try to rebias.
 699             markWord new_header = (markWord) ( (intptr_t) rcvr->klass()->prototype_header() | thread_ident);
 700             if (hash != markWord::no_hash) {
 701               new_header = new_header->copy_set_hash(hash);
 702             }
 703             if (rcvr->cas_set_mark(new_header, mark) == mark) {
 704               if (PrintBiasedLockingStatistics) {
 705                 (* BiasedLocking::rebiased_lock_entry_count_addr())++;
 706               }
 707             } else {
 708               CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception);
 709             }
 710             success = true;
 711           } else {
 712             // Try to bias towards thread in case object is anonymously biased.
 713             markWord header = (markWord) ((uintptr_t) mark &
 714                                         ((uintptr_t)markWord::biased_lock_mask_in_place |
 715                                          (uintptr_t)markWord::age_mask_in_place | epoch_mask_in_place));
 716             if (hash != markWord::no_hash) {
 717               header = header->copy_set_hash(hash);
 718             }
 719             markWord new_header = (markWord) ((uintptr_t) header | thread_ident);
 720             // Debugging hint.
 721             DEBUG_ONLY(mon->lock()->set_displaced_header((markWord) (uintptr_t) 0xdeaddead);)
 722             if (rcvr->cas_set_mark(new_header, header) == header) {
 723               if (PrintBiasedLockingStatistics) {
 724                 (* BiasedLocking::anonymously_biased_lock_entry_count_addr())++;
 725               }
 726             } else {
 727               CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception);
 728             }
 729             success = true;
 730           }
 731         }
 732 
 733         // Traditional lightweight locking.
 734         if (!success) {
 735           markWord displaced = rcvr->mark()->set_unlocked();
 736           mon->lock()->set_displaced_header(displaced);
 737           bool call_vm = UseHeavyMonitors;
 738           if (call_vm || rcvr->cas_set_mark((markWord)mon, displaced) != displaced) {
 739             // Is it simple recursive case?
 740             if (!call_vm && THREAD->is_lock_owned((address) displaced->clear_lock_bits())) {
 741               mon->lock()->set_displaced_header(NULL);
 742             } else {
 743               CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception);
 744             }
 745           }
 746         }
 747       }
 748       THREAD->clr_do_not_unlock();
 749 
 750       // Notify jvmti
 751 #ifdef VM_JVMTI
 752       if (_jvmti_interp_events) {
 753         // Whenever JVMTI puts a thread in interp_only_mode, method
 754         // entry/exit events are sent for that thread to track stack depth.
 755         if (THREAD->is_interp_only_mode()) {
 756           CALL_VM(InterpreterRuntime::post_method_entry(THREAD),
 757                   handle_exception);
 758         }
 759       }
 760 #endif /* VM_JVMTI */
 761 


 839         BI_PROFILE_GET_OR_CREATE_METHOD_DATA(handle_exception);
 840       }
 841       goto run;
 842     }
 843     case got_monitors: {
 844       // continue locking now that we have a monitor to use
 845       // we expect to find newly allocated monitor at the "top" of the monitor stack.
 846       oop lockee = STACK_OBJECT(-1);
 847       VERIFY_OOP(lockee);
 848       // derefing's lockee ought to provoke implicit null check
 849       // find a free monitor
 850       BasicObjectLock* entry = (BasicObjectLock*) istate->stack_base();
 851       assert(entry->obj() == NULL, "Frame manager didn't allocate the monitor");
 852       entry->set_obj(lockee);
 853       bool success = false;
 854       uintptr_t epoch_mask_in_place = (uintptr_t)markWord::epoch_mask_in_place;
 855 
 856       markWord mark = lockee->mark();
 857       intptr_t hash = (intptr_t) markWord::no_hash;
 858       // implies UseBiasedLocking
 859       if (mark->has_bias_pattern()) {
 860         uintptr_t thread_ident;
 861         uintptr_t anticipated_bias_locking_value;
 862         thread_ident = (uintptr_t)istate->thread();
 863         anticipated_bias_locking_value =
 864           (((uintptr_t)lockee->klass()->prototype_header() | thread_ident) ^ (uintptr_t)mark) &
 865           ~((uintptr_t) markWord::age_mask_in_place);
 866 
 867         if  (anticipated_bias_locking_value == 0) {
 868           // already biased towards this thread, nothing to do
 869           if (PrintBiasedLockingStatistics) {
 870             (* BiasedLocking::biased_lock_entry_count_addr())++;
 871           }
 872           success = true;
 873         } else if ((anticipated_bias_locking_value & markWord::biased_lock_mask_in_place) != 0) {
 874           // try revoke bias
 875           markWord header = lockee->klass()->prototype_header();
 876           if (hash != markWord::no_hash) {
 877             header = header->copy_set_hash(hash);
 878           }
 879           if (lockee->cas_set_mark(header, mark) == mark) {
 880             if (PrintBiasedLockingStatistics) {
 881               (*BiasedLocking::revoked_lock_entry_count_addr())++;
 882             }
 883           }
 884         } else if ((anticipated_bias_locking_value & epoch_mask_in_place) !=0) {
 885           // try rebias
 886           markWord new_header = (markWord) ( (intptr_t) lockee->klass()->prototype_header() | thread_ident);
 887           if (hash != markWord::no_hash) {
 888                 new_header = new_header->copy_set_hash(hash);
 889           }
 890           if (lockee->cas_set_mark(new_header, mark) == mark) {
 891             if (PrintBiasedLockingStatistics) {
 892               (* BiasedLocking::rebiased_lock_entry_count_addr())++;
 893             }
 894           } else {
 895             CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
 896           }
 897           success = true;
 898         } else {
 899           // try to bias towards thread in case object is anonymously biased
 900           markWord header = (markWord) ((uintptr_t) mark & ((uintptr_t)markWord::biased_lock_mask_in_place |
 901                                                           (uintptr_t)markWord::age_mask_in_place | epoch_mask_in_place));
 902           if (hash != markWord::no_hash) {
 903             header = header->copy_set_hash(hash);
 904           }
 905           markWord new_header = (markWord) ((uintptr_t) header | thread_ident);
 906           // debugging hint
 907           DEBUG_ONLY(entry->lock()->set_displaced_header((markWord) (uintptr_t) 0xdeaddead);)
 908           if (lockee->cas_set_mark(new_header, header) == header) {
 909             if (PrintBiasedLockingStatistics) {
 910               (* BiasedLocking::anonymously_biased_lock_entry_count_addr())++;
 911             }
 912           } else {
 913             CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
 914           }
 915           success = true;
 916         }
 917       }
 918 
 919       // traditional lightweight locking
 920       if (!success) {
 921         markWord displaced = lockee->mark()->set_unlocked();
 922         entry->lock()->set_displaced_header(displaced);
 923         bool call_vm = UseHeavyMonitors;
 924         if (call_vm || lockee->cas_set_mark((markWord)entry, displaced) != displaced) {
 925           // Is it simple recursive case?
 926           if (!call_vm && THREAD->is_lock_owned((address) displaced->clear_lock_bits())) {
 927             entry->lock()->set_displaced_header(NULL);
 928           } else {
 929             CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
 930           }
 931         }
 932       }
 933       UPDATE_PC_AND_TOS(1, -1);
 934       goto run;
 935     }
 936     default: {
 937       fatal("Unexpected message from frame manager");
 938     }
 939   }
 940 
 941 run:
 942 
 943   DO_UPDATE_INSTRUCTION_COUNT(*pc)
 944   DEBUGGER_SINGLE_STEP_NOTIFY();
 945 #ifdef PREFETCH_OPCCODE
 946   opcode = *pc;  /* prefetch first opcode */
 947 #endif


1779         CHECK_NULL(lockee);
1780         // find a free monitor or one already allocated for this object
1781         // if we find a matching object then we need a new monitor
1782         // since this is recursive enter
1783         BasicObjectLock* limit = istate->monitor_base();
1784         BasicObjectLock* most_recent = (BasicObjectLock*) istate->stack_base();
1785         BasicObjectLock* entry = NULL;
1786         while (most_recent != limit ) {
1787           if (most_recent->obj() == NULL) entry = most_recent;
1788           else if (most_recent->obj() == lockee) break;
1789           most_recent++;
1790         }
1791         if (entry != NULL) {
1792           entry->set_obj(lockee);
1793           int success = false;
1794           uintptr_t epoch_mask_in_place = (uintptr_t)markWord::epoch_mask_in_place;
1795 
1796           markWord mark = lockee->mark();
1797           intptr_t hash = (intptr_t) markWord::no_hash;
1798           // implies UseBiasedLocking
1799           if (mark->has_bias_pattern()) {
1800             uintptr_t thread_ident;
1801             uintptr_t anticipated_bias_locking_value;
1802             thread_ident = (uintptr_t)istate->thread();
1803             anticipated_bias_locking_value =
1804               (((uintptr_t)lockee->klass()->prototype_header() | thread_ident) ^ (uintptr_t)mark) &
1805               ~((uintptr_t) markWord::age_mask_in_place);
1806 
1807             if  (anticipated_bias_locking_value == 0) {
1808               // already biased towards this thread, nothing to do
1809               if (PrintBiasedLockingStatistics) {
1810                 (* BiasedLocking::biased_lock_entry_count_addr())++;
1811               }
1812               success = true;
1813             }
1814             else if ((anticipated_bias_locking_value & markWord::biased_lock_mask_in_place) != 0) {
1815               // try revoke bias
1816               markWord header = lockee->klass()->prototype_header();
1817               if (hash != markWord::no_hash) {
1818                 header = header->copy_set_hash(hash);
1819               }
1820               if (lockee->cas_set_mark(header, mark) == mark) {
1821                 if (PrintBiasedLockingStatistics)
1822                   (*BiasedLocking::revoked_lock_entry_count_addr())++;
1823               }
1824             }
1825             else if ((anticipated_bias_locking_value & epoch_mask_in_place) !=0) {
1826               // try rebias
1827               markWord new_header = (markWord) ( (intptr_t) lockee->klass()->prototype_header() | thread_ident);
1828               if (hash != markWord::no_hash) {
1829                 new_header = new_header->copy_set_hash(hash);
1830               }
1831               if (lockee->cas_set_mark(new_header, mark) == mark) {
1832                 if (PrintBiasedLockingStatistics)
1833                   (* BiasedLocking::rebiased_lock_entry_count_addr())++;
1834               }
1835               else {
1836                 CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
1837               }
1838               success = true;
1839             }
1840             else {
1841               // try to bias towards thread in case object is anonymously biased
1842               markWord header = (markWord) ((uintptr_t) mark & ((uintptr_t)markWord::biased_lock_mask_in_place |
1843                                                               (uintptr_t)markWord::age_mask_in_place |
1844                                                               epoch_mask_in_place));
1845               if (hash != markWord::no_hash) {
1846                 header = header->copy_set_hash(hash);
1847               }
1848               markWord new_header = (markWord) ((uintptr_t) header | thread_ident);
1849               // debugging hint
1850               DEBUG_ONLY(entry->lock()->set_displaced_header((markWord) (uintptr_t) 0xdeaddead);)
1851               if (lockee->cas_set_mark(new_header, header) == header) {
1852                 if (PrintBiasedLockingStatistics)
1853                   (* BiasedLocking::anonymously_biased_lock_entry_count_addr())++;
1854               }
1855               else {
1856                 CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
1857               }
1858               success = true;
1859             }
1860           }
1861 
1862           // traditional lightweight locking
1863           if (!success) {
1864             markWord displaced = lockee->mark()->set_unlocked();
1865             entry->lock()->set_displaced_header(displaced);
1866             bool call_vm = UseHeavyMonitors;
1867             if (call_vm || lockee->cas_set_mark((markWord)entry, displaced) != displaced) {
1868               // Is it simple recursive case?
1869               if (!call_vm && THREAD->is_lock_owned((address) displaced->clear_lock_bits())) {
1870                 entry->lock()->set_displaced_header(NULL);
1871               } else {
1872                 CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
1873               }
1874             }
1875           }
1876           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1877         } else {
1878           istate->set_msg(more_monitors);
1879           UPDATE_PC_AND_RETURN(0); // Re-execute
1880         }
1881       }
1882 
1883       CASE(_monitorexit): {
1884         oop lockee = STACK_OBJECT(-1);
1885         CHECK_NULL(lockee);
1886         // derefing's lockee ought to provoke implicit null check
1887         // find our monitor slot
1888         BasicObjectLock* limit = istate->monitor_base();
1889         BasicObjectLock* most_recent = (BasicObjectLock*) istate->stack_base();
1890         while (most_recent != limit ) {
1891           if ((most_recent)->obj() == lockee) {
1892             BasicLock* lock = most_recent->lock();
1893             markWord header = lock->displaced_header();
1894             most_recent->set_obj(NULL);
1895             if (!lockee->mark()->has_bias_pattern()) {
1896               bool call_vm = UseHeavyMonitors;
1897               // If it isn't recursive we either must swap old header or call the runtime
1898               if (header != NULL || call_vm) {
1899                 markWord old_header = markWord::encode(lock);
1900                 if (call_vm || lockee->cas_set_mark(header, old_header) != old_header) {
1901                   // restore object for the slow case
1902                   most_recent->set_obj(lockee);
1903                   CALL_VM(InterpreterRuntime::monitorexit(THREAD, most_recent), handle_exception);
1904                 }
1905               }
1906             }
1907             UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1908           }
1909           most_recent++;
1910         }
1911         // Need to throw illegal monitor state exception
1912         CALL_VM(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD), handle_exception);
1913         ShouldNotReachHere();
1914       }
1915 
1916       /* All of the non-quick opcodes. */
1917 
1918       /* -Set clobbersCpIndex true if the quickened opcode clobbers the


3021       // unlock as we find them. If we find the method monitor before
3022       // we are at the initial entry then we should throw an exception.
3023       // It is not clear the template based interpreter does this
3024       // correctly
3025 
3026       BasicObjectLock* base = istate->monitor_base();
3027       BasicObjectLock* end = (BasicObjectLock*) istate->stack_base();
3028       bool method_unlock_needed = METHOD->is_synchronized();
3029       // We know the initial monitor was used for the method don't check that
3030       // slot in the loop
3031       if (method_unlock_needed) base--;
3032 
3033       // Check all the monitors to see they are unlocked. Install exception if found to be locked.
3034       while (end < base) {
3035         oop lockee = end->obj();
3036         if (lockee != NULL) {
3037           BasicLock* lock = end->lock();
3038           markWord header = lock->displaced_header();
3039           end->set_obj(NULL);
3040 
3041           if (!lockee->mark()->has_bias_pattern()) {
3042             // If it isn't recursive we either must swap old header or call the runtime
3043             if (header != NULL) {
3044               markWord old_header = markWord::encode(lock);
3045               if (lockee->cas_set_mark(header, old_header) != old_header) {
3046                 // restore object for the slow case
3047                 end->set_obj(lockee);
3048                 {
3049                   // Prevent any HandleMarkCleaner from freeing our live handles
3050                   HandleMark __hm(THREAD);
3051                   CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(THREAD, end));
3052                 }
3053               }
3054             }
3055           }
3056           // One error is plenty
3057           if (illegal_state_oop() == NULL && !suppress_error) {
3058             {
3059               // Prevent any HandleMarkCleaner from freeing our live handles
3060               HandleMark __hm(THREAD);
3061               CALL_VM_NOCHECK(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD));
3062             }
3063             assert(THREAD->has_pending_exception(), "Lost our exception!");


3096             if (!suppress_error) {
3097               VM_JAVA_ERROR_NO_JUMP(vmSymbols::java_lang_NullPointerException(), "", note_nullCheck_trap);
3098               illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
3099               THREAD->clear_pending_exception();
3100             }
3101           } else if (UseHeavyMonitors) {
3102             {
3103               // Prevent any HandleMarkCleaner from freeing our live handles.
3104               HandleMark __hm(THREAD);
3105               CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(THREAD, base));
3106             }
3107             if (THREAD->has_pending_exception()) {
3108               if (!suppress_error) illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
3109               THREAD->clear_pending_exception();
3110             }
3111           } else {
3112             BasicLock* lock = base->lock();
3113             markWord header = lock->displaced_header();
3114             base->set_obj(NULL);
3115 
3116             if (!rcvr->mark()->has_bias_pattern()) {
3117               base->set_obj(NULL);
3118               // If it isn't recursive we either must swap old header or call the runtime
3119               if (header != NULL) {
3120                 markWord old_header = markWord::encode(lock);
3121                 if (rcvr->cas_set_mark(header, old_header) != old_header) {
3122                   // restore object for the slow case
3123                   base->set_obj(rcvr);
3124                   {
3125                     // Prevent any HandleMarkCleaner from freeing our live handles
3126                     HandleMark __hm(THREAD);
3127                     CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(THREAD, base));
3128                   }
3129                   if (THREAD->has_pending_exception()) {
3130                     if (!suppress_error) illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
3131                     THREAD->clear_pending_exception();
3132                   }
3133                 }
3134               }
3135             }
3136           }
3137         }
3138       }
3139     }




 653 
 654       // Lock method if synchronized.
 655       if (METHOD->is_synchronized()) {
 656         // oop rcvr = locals[0].j.r;
 657         oop rcvr;
 658         if (METHOD->is_static()) {
 659           rcvr = METHOD->constants()->pool_holder()->java_mirror();
 660         } else {
 661           rcvr = LOCALS_OBJECT(0);
 662           VERIFY_OOP(rcvr);
 663         }
 664         // The initial monitor is ours for the taking.
 665         // Monitor not filled in frame manager any longer as this caused race condition with biased locking.
 666         BasicObjectLock* mon = &istate->monitor_base()[-1];
 667         mon->set_obj(rcvr);
 668         bool success = false;
 669         uintptr_t epoch_mask_in_place = (uintptr_t)markWord::epoch_mask_in_place;
 670         markWord mark = rcvr->mark();
 671         intptr_t hash = (intptr_t) markWord::no_hash;
 672         // Implies UseBiasedLocking.
 673         if (mark.has_bias_pattern()) {
 674           uintptr_t thread_ident;
 675           uintptr_t anticipated_bias_locking_value;
 676           thread_ident = (uintptr_t)istate->thread();
 677           anticipated_bias_locking_value =
 678             (((uintptr_t)rcvr->klass()->prototype_header().value() | thread_ident) ^ mark.value()) &
 679             ~((uintptr_t) markWord::age_mask_in_place);
 680 
 681           if (anticipated_bias_locking_value == 0) {
 682             // Already biased towards this thread, nothing to do.
 683             if (PrintBiasedLockingStatistics) {
 684               (* BiasedLocking::biased_lock_entry_count_addr())++;
 685             }
 686             success = true;
 687           } else if ((anticipated_bias_locking_value & markWord::biased_lock_mask_in_place) != 0) {
 688             // Try to revoke bias.
 689             markWord header = rcvr->klass()->prototype_header();
 690             if (hash != markWord::no_hash) {
 691               header = header.copy_set_hash(hash);
 692             }
 693             if (rcvr->cas_set_mark(header, mark) == mark) {
 694               if (PrintBiasedLockingStatistics)
 695                 (*BiasedLocking::revoked_lock_entry_count_addr())++;
 696             }
 697           } else if ((anticipated_bias_locking_value & epoch_mask_in_place) != 0) {
 698             // Try to rebias.
 699             markWord new_header( (intptr_t) rcvr->klass()->prototype_header().value() | thread_ident);
 700             if (hash != markWord::no_hash) {
 701               new_header = new_header.copy_set_hash(hash);
 702             }
 703             if (rcvr->cas_set_mark(new_header, mark) == mark) {
 704               if (PrintBiasedLockingStatistics) {
 705                 (* BiasedLocking::rebiased_lock_entry_count_addr())++;
 706               }
 707             } else {
 708               CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception);
 709             }
 710             success = true;
 711           } else {
 712             // Try to bias towards thread in case object is anonymously biased.
 713             markWord header(mark.value() &
 714                             ((uintptr_t)markWord::biased_lock_mask_in_place |
 715                              (uintptr_t)markWord::age_mask_in_place | epoch_mask_in_place));
 716             if (hash != markWord::no_hash) {
 717               header = header.copy_set_hash(hash);
 718             }
 719             markWord new_header(header.value() | thread_ident);
 720             // Debugging hint.
 721             DEBUG_ONLY(mon->lock()->set_displaced_header(markWord((uintptr_t) 0xdeaddead));)
 722             if (rcvr->cas_set_mark(new_header, header) == header) {
 723               if (PrintBiasedLockingStatistics) {
 724                 (* BiasedLocking::anonymously_biased_lock_entry_count_addr())++;
 725               }
 726             } else {
 727               CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception);
 728             }
 729             success = true;
 730           }
 731         }
 732 
 733         // Traditional lightweight locking.
 734         if (!success) {
 735           markWord displaced = rcvr->mark().set_unlocked();
 736           mon->lock()->set_displaced_header(displaced);
 737           bool call_vm = UseHeavyMonitors;
 738           if (call_vm || rcvr->cas_set_mark(markWord::from_pointer(mon), displaced) != displaced) {
 739             // Is it simple recursive case?
 740             if (!call_vm && THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) {
 741               mon->lock()->set_displaced_header(markWord::from_pointer(NULL));
 742             } else {
 743               CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception);
 744             }
 745           }
 746         }
 747       }
 748       THREAD->clr_do_not_unlock();
 749 
 750       // Notify jvmti
 751 #ifdef VM_JVMTI
 752       if (_jvmti_interp_events) {
 753         // Whenever JVMTI puts a thread in interp_only_mode, method
 754         // entry/exit events are sent for that thread to track stack depth.
 755         if (THREAD->is_interp_only_mode()) {
 756           CALL_VM(InterpreterRuntime::post_method_entry(THREAD),
 757                   handle_exception);
 758         }
 759       }
 760 #endif /* VM_JVMTI */
 761 


 839         BI_PROFILE_GET_OR_CREATE_METHOD_DATA(handle_exception);
 840       }
 841       goto run;
 842     }
 843     case got_monitors: {
 844       // continue locking now that we have a monitor to use
 845       // we expect to find newly allocated monitor at the "top" of the monitor stack.
 846       oop lockee = STACK_OBJECT(-1);
 847       VERIFY_OOP(lockee);
 848       // derefing's lockee ought to provoke implicit null check
 849       // find a free monitor
 850       BasicObjectLock* entry = (BasicObjectLock*) istate->stack_base();
 851       assert(entry->obj() == NULL, "Frame manager didn't allocate the monitor");
 852       entry->set_obj(lockee);
 853       bool success = false;
 854       uintptr_t epoch_mask_in_place = (uintptr_t)markWord::epoch_mask_in_place;
 855 
 856       markWord mark = lockee->mark();
 857       intptr_t hash = (intptr_t) markWord::no_hash;
 858       // implies UseBiasedLocking
 859       if (mark.has_bias_pattern()) {
 860         uintptr_t thread_ident;
 861         uintptr_t anticipated_bias_locking_value;
 862         thread_ident = (uintptr_t)istate->thread();
 863         anticipated_bias_locking_value =
 864           (((uintptr_t)lockee->klass()->prototype_header().value() | thread_ident) ^ mark.value()) &
 865           ~((uintptr_t) markWord::age_mask_in_place);
 866 
 867         if  (anticipated_bias_locking_value == 0) {
 868           // already biased towards this thread, nothing to do
 869           if (PrintBiasedLockingStatistics) {
 870             (* BiasedLocking::biased_lock_entry_count_addr())++;
 871           }
 872           success = true;
 873         } else if ((anticipated_bias_locking_value & markWord::biased_lock_mask_in_place) != 0) {
 874           // try revoke bias
 875           markWord header = lockee->klass()->prototype_header();
 876           if (hash != markWord::no_hash) {
 877             header = header.copy_set_hash(hash);
 878           }
 879           if (lockee->cas_set_mark(header, mark) == mark) {
 880             if (PrintBiasedLockingStatistics) {
 881               (*BiasedLocking::revoked_lock_entry_count_addr())++;
 882             }
 883           }
 884         } else if ((anticipated_bias_locking_value & epoch_mask_in_place) !=0) {
 885           // try rebias
 886           markWord new_header( (intptr_t) lockee->klass()->prototype_header().value() | thread_ident);
 887           if (hash != markWord::no_hash) {
 888             new_header = new_header.copy_set_hash(hash);
 889           }
 890           if (lockee->cas_set_mark(new_header, mark) == mark) {
 891             if (PrintBiasedLockingStatistics) {
 892               (* BiasedLocking::rebiased_lock_entry_count_addr())++;
 893             }
 894           } else {
 895             CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
 896           }
 897           success = true;
 898         } else {
 899           // try to bias towards thread in case object is anonymously biased
 900           markWord header(mark.value() & ((uintptr_t)markWord::biased_lock_mask_in_place |
 901                                           (uintptr_t)markWord::age_mask_in_place | epoch_mask_in_place));
 902           if (hash != markWord::no_hash) {
 903             header = header.copy_set_hash(hash);
 904           }
 905           markWord new_header(header.value() | thread_ident);
 906           // debugging hint
 907           DEBUG_ONLY(entry->lock()->set_displaced_header(markWord((uintptr_t) 0xdeaddead));)
 908           if (lockee->cas_set_mark(new_header, header) == header) {
 909             if (PrintBiasedLockingStatistics) {
 910               (* BiasedLocking::anonymously_biased_lock_entry_count_addr())++;
 911             }
 912           } else {
 913             CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
 914           }
 915           success = true;
 916         }
 917       }
 918 
 919       // traditional lightweight locking
 920       if (!success) {
 921         markWord displaced = lockee->mark().set_unlocked();
 922         entry->lock()->set_displaced_header(displaced);
 923         bool call_vm = UseHeavyMonitors;
 924         if (call_vm || lockee->cas_set_mark(markWord::from_pointer(entry), displaced) != displaced) {
 925           // Is it simple recursive case?
 926           if (!call_vm && THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) {
 927             entry->lock()->set_displaced_header(markWord::from_pointer(NULL));
 928           } else {
 929             CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
 930           }
 931         }
 932       }
 933       UPDATE_PC_AND_TOS(1, -1);
 934       goto run;
 935     }
 936     default: {
 937       fatal("Unexpected message from frame manager");
 938     }
 939   }
 940 
 941 run:
 942 
 943   DO_UPDATE_INSTRUCTION_COUNT(*pc)
 944   DEBUGGER_SINGLE_STEP_NOTIFY();
 945 #ifdef PREFETCH_OPCCODE
 946   opcode = *pc;  /* prefetch first opcode */
 947 #endif


1779         CHECK_NULL(lockee);
1780         // find a free monitor or one already allocated for this object
1781         // if we find a matching object then we need a new monitor
1782         // since this is recursive enter
1783         BasicObjectLock* limit = istate->monitor_base();
1784         BasicObjectLock* most_recent = (BasicObjectLock*) istate->stack_base();
1785         BasicObjectLock* entry = NULL;
1786         while (most_recent != limit ) {
1787           if (most_recent->obj() == NULL) entry = most_recent;
1788           else if (most_recent->obj() == lockee) break;
1789           most_recent++;
1790         }
1791         if (entry != NULL) {
1792           entry->set_obj(lockee);
1793           int success = false;
1794           uintptr_t epoch_mask_in_place = (uintptr_t)markWord::epoch_mask_in_place;
1795 
1796           markWord mark = lockee->mark();
1797           intptr_t hash = (intptr_t) markWord::no_hash;
1798           // implies UseBiasedLocking
1799           if (mark.has_bias_pattern()) {
1800             uintptr_t thread_ident;
1801             uintptr_t anticipated_bias_locking_value;
1802             thread_ident = (uintptr_t)istate->thread();
1803             anticipated_bias_locking_value =
1804               (((uintptr_t)lockee->klass()->prototype_header().value() | thread_ident) ^ mark.value()) &
1805               ~((uintptr_t) markWord::age_mask_in_place);
1806 
1807             if  (anticipated_bias_locking_value == 0) {
1808               // already biased towards this thread, nothing to do
1809               if (PrintBiasedLockingStatistics) {
1810                 (* BiasedLocking::biased_lock_entry_count_addr())++;
1811               }
1812               success = true;
1813             }
1814             else if ((anticipated_bias_locking_value & markWord::biased_lock_mask_in_place) != 0) {
1815               // try revoke bias
1816               markWord header = lockee->klass()->prototype_header();
1817               if (hash != markWord::no_hash) {
1818                 header = header.copy_set_hash(hash);
1819               }
1820               if (lockee->cas_set_mark(header, mark) == mark) {
1821                 if (PrintBiasedLockingStatistics)
1822                   (*BiasedLocking::revoked_lock_entry_count_addr())++;
1823               }
1824             }
1825             else if ((anticipated_bias_locking_value & epoch_mask_in_place) !=0) {
1826               // try rebias
1827               markWord new_header( (intptr_t) lockee->klass()->prototype_header().value() | thread_ident);
1828               if (hash != markWord::no_hash) {
1829                 new_header = new_header.copy_set_hash(hash);
1830               }
1831               if (lockee->cas_set_mark(new_header, mark) == mark) {
1832                 if (PrintBiasedLockingStatistics)
1833                   (* BiasedLocking::rebiased_lock_entry_count_addr())++;
1834               }
1835               else {
1836                 CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
1837               }
1838               success = true;
1839             }
1840             else {
1841               // try to bias towards thread in case object is anonymously biased
1842               markWord header(mark.value() & ((uintptr_t)markWord::biased_lock_mask_in_place |
1843                                               (uintptr_t)markWord::age_mask_in_place |
1844                                               epoch_mask_in_place));
1845               if (hash != markWord::no_hash) {
1846                 header = header.copy_set_hash(hash);
1847               }
1848               markWord new_header(header.value() | thread_ident);
1849               // debugging hint
1850               DEBUG_ONLY(entry->lock()->set_displaced_header(markWord((uintptr_t) 0xdeaddead));)
1851               if (lockee->cas_set_mark(new_header, header) == header) {
1852                 if (PrintBiasedLockingStatistics)
1853                   (* BiasedLocking::anonymously_biased_lock_entry_count_addr())++;
1854               }
1855               else {
1856                 CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
1857               }
1858               success = true;
1859             }
1860           }
1861 
1862           // traditional lightweight locking
1863           if (!success) {
1864             markWord displaced = lockee->mark().set_unlocked();
1865             entry->lock()->set_displaced_header(displaced);
1866             bool call_vm = UseHeavyMonitors;
1867             if (call_vm || lockee->cas_set_mark(markWord::from_pointer(entry), displaced) != displaced) {
1868               // Is it simple recursive case?
1869               if (!call_vm && THREAD->is_lock_owned((address) displaced.clear_lock_bits().to_pointer())) {
1870                 entry->lock()->set_displaced_header(markWord::from_pointer(NULL));
1871               } else {
1872                 CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
1873               }
1874             }
1875           }
1876           UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1877         } else {
1878           istate->set_msg(more_monitors);
1879           UPDATE_PC_AND_RETURN(0); // Re-execute
1880         }
1881       }
1882 
1883       CASE(_monitorexit): {
1884         oop lockee = STACK_OBJECT(-1);
1885         CHECK_NULL(lockee);
1886         // derefing's lockee ought to provoke implicit null check
1887         // find our monitor slot
1888         BasicObjectLock* limit = istate->monitor_base();
1889         BasicObjectLock* most_recent = (BasicObjectLock*) istate->stack_base();
1890         while (most_recent != limit ) {
1891           if ((most_recent)->obj() == lockee) {
1892             BasicLock* lock = most_recent->lock();
1893             markWord header = lock->displaced_header();
1894             most_recent->set_obj(NULL);
1895             if (!lockee->mark().has_bias_pattern()) {
1896               bool call_vm = UseHeavyMonitors;
1897               // If it isn't recursive we either must swap old header or call the runtime
1898               if (header.to_pointer() != NULL || call_vm) {
1899                 markWord old_header = markWord::encode(lock);
1900                 if (call_vm || lockee->cas_set_mark(header, old_header) != old_header) {
1901                   // restore object for the slow case
1902                   most_recent->set_obj(lockee);
1903                   CALL_VM(InterpreterRuntime::monitorexit(THREAD, most_recent), handle_exception);
1904                 }
1905               }
1906             }
1907             UPDATE_PC_AND_TOS_AND_CONTINUE(1, -1);
1908           }
1909           most_recent++;
1910         }
1911         // Need to throw illegal monitor state exception
1912         CALL_VM(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD), handle_exception);
1913         ShouldNotReachHere();
1914       }
1915 
1916       /* All of the non-quick opcodes. */
1917 
1918       /* -Set clobbersCpIndex true if the quickened opcode clobbers the


3021       // unlock as we find them. If we find the method monitor before
3022       // we are at the initial entry then we should throw an exception.
3023       // It is not clear the template based interpreter does this
3024       // correctly
3025 
3026       BasicObjectLock* base = istate->monitor_base();
3027       BasicObjectLock* end = (BasicObjectLock*) istate->stack_base();
3028       bool method_unlock_needed = METHOD->is_synchronized();
3029       // We know the initial monitor was used for the method don't check that
3030       // slot in the loop
3031       if (method_unlock_needed) base--;
3032 
3033       // Check all the monitors to see they are unlocked. Install exception if found to be locked.
3034       while (end < base) {
3035         oop lockee = end->obj();
3036         if (lockee != NULL) {
3037           BasicLock* lock = end->lock();
3038           markWord header = lock->displaced_header();
3039           end->set_obj(NULL);
3040 
3041           if (!lockee->mark().has_bias_pattern()) {
3042             // If it isn't recursive we either must swap old header or call the runtime
3043             if (header.to_pointer() != NULL) {
3044               markWord old_header = markWord::encode(lock);
3045               if (lockee->cas_set_mark(header, old_header) != old_header) {
3046                 // restore object for the slow case
3047                 end->set_obj(lockee);
3048                 {
3049                   // Prevent any HandleMarkCleaner from freeing our live handles
3050                   HandleMark __hm(THREAD);
3051                   CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(THREAD, end));
3052                 }
3053               }
3054             }
3055           }
3056           // One error is plenty
3057           if (illegal_state_oop() == NULL && !suppress_error) {
3058             {
3059               // Prevent any HandleMarkCleaner from freeing our live handles
3060               HandleMark __hm(THREAD);
3061               CALL_VM_NOCHECK(InterpreterRuntime::throw_illegal_monitor_state_exception(THREAD));
3062             }
3063             assert(THREAD->has_pending_exception(), "Lost our exception!");


3096             if (!suppress_error) {
3097               VM_JAVA_ERROR_NO_JUMP(vmSymbols::java_lang_NullPointerException(), "", note_nullCheck_trap);
3098               illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
3099               THREAD->clear_pending_exception();
3100             }
3101           } else if (UseHeavyMonitors) {
3102             {
3103               // Prevent any HandleMarkCleaner from freeing our live handles.
3104               HandleMark __hm(THREAD);
3105               CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(THREAD, base));
3106             }
3107             if (THREAD->has_pending_exception()) {
3108               if (!suppress_error) illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
3109               THREAD->clear_pending_exception();
3110             }
3111           } else {
3112             BasicLock* lock = base->lock();
3113             markWord header = lock->displaced_header();
3114             base->set_obj(NULL);
3115 
3116             if (!rcvr->mark().has_bias_pattern()) {
3117               base->set_obj(NULL);
3118               // If it isn't recursive we either must swap old header or call the runtime
3119               if (header.to_pointer() != NULL) {
3120                 markWord old_header = markWord::encode(lock);
3121                 if (rcvr->cas_set_mark(header, old_header) != old_header) {
3122                   // restore object for the slow case
3123                   base->set_obj(rcvr);
3124                   {
3125                     // Prevent any HandleMarkCleaner from freeing our live handles
3126                     HandleMark __hm(THREAD);
3127                     CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(THREAD, base));
3128                   }
3129                   if (THREAD->has_pending_exception()) {
3130                     if (!suppress_error) illegal_state_oop = Handle(THREAD, THREAD->pending_exception());
3131                     THREAD->clear_pending_exception();
3132                   }
3133                 }
3134               }
3135             }
3136           }
3137         }
3138       }
3139     }


< prev index next >