src/hotspot/share/interpreter/bytecodeInterpreter.cpp
changeset 49722 a47d1e21b3f1
parent 49658 8237a91c1cca
child 50429 83aec1d357d4
equal deleted inserted replaced
49721:ea0cc7c74e75 49722:a47d1e21b3f1
     1 /*
     1 /*
     2  * Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
   687             // Try to revoke bias.
   687             // Try to revoke bias.
   688             markOop header = rcvr->klass()->prototype_header();
   688             markOop header = rcvr->klass()->prototype_header();
   689             if (hash != markOopDesc::no_hash) {
   689             if (hash != markOopDesc::no_hash) {
   690               header = header->copy_set_hash(hash);
   690               header = header->copy_set_hash(hash);
   691             }
   691             }
   692             if (Atomic::cmpxchg(header, rcvr->mark_addr(), mark) == mark) {
   692             if (rcvr->cas_set_mark(header, mark) == mark) {
   693               if (PrintBiasedLockingStatistics)
   693               if (PrintBiasedLockingStatistics)
   694                 (*BiasedLocking::revoked_lock_entry_count_addr())++;
   694                 (*BiasedLocking::revoked_lock_entry_count_addr())++;
   695             }
   695             }
   696           } else if ((anticipated_bias_locking_value & epoch_mask_in_place) != 0) {
   696           } else if ((anticipated_bias_locking_value & epoch_mask_in_place) != 0) {
   697             // Try to rebias.
   697             // Try to rebias.
   698             markOop new_header = (markOop) ( (intptr_t) rcvr->klass()->prototype_header() | thread_ident);
   698             markOop new_header = (markOop) ( (intptr_t) rcvr->klass()->prototype_header() | thread_ident);
   699             if (hash != markOopDesc::no_hash) {
   699             if (hash != markOopDesc::no_hash) {
   700               new_header = new_header->copy_set_hash(hash);
   700               new_header = new_header->copy_set_hash(hash);
   701             }
   701             }
   702             if (Atomic::cmpxchg(new_header, rcvr->mark_addr(), mark) == mark) {
   702             if (rcvr->cas_set_mark(new_header, mark) == mark) {
   703               if (PrintBiasedLockingStatistics) {
   703               if (PrintBiasedLockingStatistics) {
   704                 (* BiasedLocking::rebiased_lock_entry_count_addr())++;
   704                 (* BiasedLocking::rebiased_lock_entry_count_addr())++;
   705               }
   705               }
   706             } else {
   706             } else {
   707               CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception);
   707               CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception);
   716               header = header->copy_set_hash(hash);
   716               header = header->copy_set_hash(hash);
   717             }
   717             }
   718             markOop new_header = (markOop) ((uintptr_t) header | thread_ident);
   718             markOop new_header = (markOop) ((uintptr_t) header | thread_ident);
   719             // Debugging hint.
   719             // Debugging hint.
   720             DEBUG_ONLY(mon->lock()->set_displaced_header((markOop) (uintptr_t) 0xdeaddead);)
   720             DEBUG_ONLY(mon->lock()->set_displaced_header((markOop) (uintptr_t) 0xdeaddead);)
   721             if (Atomic::cmpxchg(new_header, rcvr->mark_addr(), header) == header) {
   721             if (rcvr->cas_set_mark(new_header, header) == header) {
   722               if (PrintBiasedLockingStatistics) {
   722               if (PrintBiasedLockingStatistics) {
   723                 (* BiasedLocking::anonymously_biased_lock_entry_count_addr())++;
   723                 (* BiasedLocking::anonymously_biased_lock_entry_count_addr())++;
   724               }
   724               }
   725             } else {
   725             } else {
   726               CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception);
   726               CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception);
   732         // Traditional lightweight locking.
   732         // Traditional lightweight locking.
   733         if (!success) {
   733         if (!success) {
   734           markOop displaced = rcvr->mark()->set_unlocked();
   734           markOop displaced = rcvr->mark()->set_unlocked();
   735           mon->lock()->set_displaced_header(displaced);
   735           mon->lock()->set_displaced_header(displaced);
   736           bool call_vm = UseHeavyMonitors;
   736           bool call_vm = UseHeavyMonitors;
   737           if (call_vm || Atomic::cmpxchg((markOop)mon, rcvr->mark_addr(), displaced) != displaced) {
   737           if (call_vm || rcvr->cas_set_mark((markOop)mon, displaced) != displaced) {
   738             // Is it simple recursive case?
   738             // Is it simple recursive case?
   739             if (!call_vm && THREAD->is_lock_owned((address) displaced->clear_lock_bits())) {
   739             if (!call_vm && THREAD->is_lock_owned((address) displaced->clear_lock_bits())) {
   740               mon->lock()->set_displaced_header(NULL);
   740               mon->lock()->set_displaced_header(NULL);
   741             } else {
   741             } else {
   742               CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception);
   742               CALL_VM(InterpreterRuntime::monitorenter(THREAD, mon), handle_exception);
   873           // try revoke bias
   873           // try revoke bias
   874           markOop header = lockee->klass()->prototype_header();
   874           markOop header = lockee->klass()->prototype_header();
   875           if (hash != markOopDesc::no_hash) {
   875           if (hash != markOopDesc::no_hash) {
   876             header = header->copy_set_hash(hash);
   876             header = header->copy_set_hash(hash);
   877           }
   877           }
   878           if (Atomic::cmpxchg(header, lockee->mark_addr(), mark) == mark) {
   878           if (lockee->cas_set_mark(header, mark) == mark) {
   879             if (PrintBiasedLockingStatistics) {
   879             if (PrintBiasedLockingStatistics) {
   880               (*BiasedLocking::revoked_lock_entry_count_addr())++;
   880               (*BiasedLocking::revoked_lock_entry_count_addr())++;
   881             }
   881             }
   882           }
   882           }
   883         } else if ((anticipated_bias_locking_value & epoch_mask_in_place) !=0) {
   883         } else if ((anticipated_bias_locking_value & epoch_mask_in_place) !=0) {
   884           // try rebias
   884           // try rebias
   885           markOop new_header = (markOop) ( (intptr_t) lockee->klass()->prototype_header() | thread_ident);
   885           markOop new_header = (markOop) ( (intptr_t) lockee->klass()->prototype_header() | thread_ident);
   886           if (hash != markOopDesc::no_hash) {
   886           if (hash != markOopDesc::no_hash) {
   887                 new_header = new_header->copy_set_hash(hash);
   887                 new_header = new_header->copy_set_hash(hash);
   888           }
   888           }
   889           if (Atomic::cmpxchg(new_header, lockee->mark_addr(), mark) == mark) {
   889           if (lockee->cas_set_mark(new_header, mark) == mark) {
   890             if (PrintBiasedLockingStatistics) {
   890             if (PrintBiasedLockingStatistics) {
   891               (* BiasedLocking::rebiased_lock_entry_count_addr())++;
   891               (* BiasedLocking::rebiased_lock_entry_count_addr())++;
   892             }
   892             }
   893           } else {
   893           } else {
   894             CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
   894             CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
   902             header = header->copy_set_hash(hash);
   902             header = header->copy_set_hash(hash);
   903           }
   903           }
   904           markOop new_header = (markOop) ((uintptr_t) header | thread_ident);
   904           markOop new_header = (markOop) ((uintptr_t) header | thread_ident);
   905           // debugging hint
   905           // debugging hint
   906           DEBUG_ONLY(entry->lock()->set_displaced_header((markOop) (uintptr_t) 0xdeaddead);)
   906           DEBUG_ONLY(entry->lock()->set_displaced_header((markOop) (uintptr_t) 0xdeaddead);)
   907           if (Atomic::cmpxchg(new_header, lockee->mark_addr(), header) == header) {
   907           if (lockee->cas_set_mark(new_header, header) == header) {
   908             if (PrintBiasedLockingStatistics) {
   908             if (PrintBiasedLockingStatistics) {
   909               (* BiasedLocking::anonymously_biased_lock_entry_count_addr())++;
   909               (* BiasedLocking::anonymously_biased_lock_entry_count_addr())++;
   910             }
   910             }
   911           } else {
   911           } else {
   912             CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
   912             CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
   918       // traditional lightweight locking
   918       // traditional lightweight locking
   919       if (!success) {
   919       if (!success) {
   920         markOop displaced = lockee->mark()->set_unlocked();
   920         markOop displaced = lockee->mark()->set_unlocked();
   921         entry->lock()->set_displaced_header(displaced);
   921         entry->lock()->set_displaced_header(displaced);
   922         bool call_vm = UseHeavyMonitors;
   922         bool call_vm = UseHeavyMonitors;
   923         if (call_vm || Atomic::cmpxchg((markOop)entry, lockee->mark_addr(), displaced) != displaced) {
   923         if (call_vm || lockee->cas_set_mark((markOop)entry, displaced) != displaced) {
   924           // Is it simple recursive case?
   924           // Is it simple recursive case?
   925           if (!call_vm && THREAD->is_lock_owned((address) displaced->clear_lock_bits())) {
   925           if (!call_vm && THREAD->is_lock_owned((address) displaced->clear_lock_bits())) {
   926             entry->lock()->set_displaced_header(NULL);
   926             entry->lock()->set_displaced_header(NULL);
   927           } else {
   927           } else {
   928             CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
   928             CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
  1814               // try revoke bias
  1814               // try revoke bias
  1815               markOop header = lockee->klass()->prototype_header();
  1815               markOop header = lockee->klass()->prototype_header();
  1816               if (hash != markOopDesc::no_hash) {
  1816               if (hash != markOopDesc::no_hash) {
  1817                 header = header->copy_set_hash(hash);
  1817                 header = header->copy_set_hash(hash);
  1818               }
  1818               }
  1819               if (Atomic::cmpxchg(header, lockee->mark_addr(), mark) == mark) {
  1819               if (lockee->cas_set_mark(header, mark) == mark) {
  1820                 if (PrintBiasedLockingStatistics)
  1820                 if (PrintBiasedLockingStatistics)
  1821                   (*BiasedLocking::revoked_lock_entry_count_addr())++;
  1821                   (*BiasedLocking::revoked_lock_entry_count_addr())++;
  1822               }
  1822               }
  1823             }
  1823             }
  1824             else if ((anticipated_bias_locking_value & epoch_mask_in_place) !=0) {
  1824             else if ((anticipated_bias_locking_value & epoch_mask_in_place) !=0) {
  1825               // try rebias
  1825               // try rebias
  1826               markOop new_header = (markOop) ( (intptr_t) lockee->klass()->prototype_header() | thread_ident);
  1826               markOop new_header = (markOop) ( (intptr_t) lockee->klass()->prototype_header() | thread_ident);
  1827               if (hash != markOopDesc::no_hash) {
  1827               if (hash != markOopDesc::no_hash) {
  1828                 new_header = new_header->copy_set_hash(hash);
  1828                 new_header = new_header->copy_set_hash(hash);
  1829               }
  1829               }
  1830               if (Atomic::cmpxchg(new_header, lockee->mark_addr(), mark) == mark) {
  1830               if (lockee->cas_set_mark(new_header, mark) == mark) {
  1831                 if (PrintBiasedLockingStatistics)
  1831                 if (PrintBiasedLockingStatistics)
  1832                   (* BiasedLocking::rebiased_lock_entry_count_addr())++;
  1832                   (* BiasedLocking::rebiased_lock_entry_count_addr())++;
  1833               }
  1833               }
  1834               else {
  1834               else {
  1835                 CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
  1835                 CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
  1845                 header = header->copy_set_hash(hash);
  1845                 header = header->copy_set_hash(hash);
  1846               }
  1846               }
  1847               markOop new_header = (markOop) ((uintptr_t) header | thread_ident);
  1847               markOop new_header = (markOop) ((uintptr_t) header | thread_ident);
  1848               // debugging hint
  1848               // debugging hint
  1849               DEBUG_ONLY(entry->lock()->set_displaced_header((markOop) (uintptr_t) 0xdeaddead);)
  1849               DEBUG_ONLY(entry->lock()->set_displaced_header((markOop) (uintptr_t) 0xdeaddead);)
  1850               if (Atomic::cmpxchg(new_header, lockee->mark_addr(), header) == header) {
  1850               if (lockee->cas_set_mark(new_header, header) == header) {
  1851                 if (PrintBiasedLockingStatistics)
  1851                 if (PrintBiasedLockingStatistics)
  1852                   (* BiasedLocking::anonymously_biased_lock_entry_count_addr())++;
  1852                   (* BiasedLocking::anonymously_biased_lock_entry_count_addr())++;
  1853               }
  1853               }
  1854               else {
  1854               else {
  1855                 CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
  1855                 CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
  1861           // traditional lightweight locking
  1861           // traditional lightweight locking
  1862           if (!success) {
  1862           if (!success) {
  1863             markOop displaced = lockee->mark()->set_unlocked();
  1863             markOop displaced = lockee->mark()->set_unlocked();
  1864             entry->lock()->set_displaced_header(displaced);
  1864             entry->lock()->set_displaced_header(displaced);
  1865             bool call_vm = UseHeavyMonitors;
  1865             bool call_vm = UseHeavyMonitors;
  1866             if (call_vm || Atomic::cmpxchg((markOop)entry, lockee->mark_addr(), displaced) != displaced) {
  1866             if (call_vm || lockee->cas_set_mark((markOop)entry, displaced) != displaced) {
  1867               // Is it simple recursive case?
  1867               // Is it simple recursive case?
  1868               if (!call_vm && THREAD->is_lock_owned((address) displaced->clear_lock_bits())) {
  1868               if (!call_vm && THREAD->is_lock_owned((address) displaced->clear_lock_bits())) {
  1869                 entry->lock()->set_displaced_header(NULL);
  1869                 entry->lock()->set_displaced_header(NULL);
  1870               } else {
  1870               } else {
  1871                 CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);
  1871                 CALL_VM(InterpreterRuntime::monitorenter(THREAD, entry), handle_exception);