< prev index next >

src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp

Print this page

   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
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 

  25 #include "asm/assembler.hpp"
  26 #include "asm/assembler.inline.hpp"
  27 #include "gc/shared/barrierSet.hpp"
  28 #include "gc/shared/barrierSetAssembler.hpp"
  29 #include "oops/methodData.hpp"
  30 #include "opto/c2_MacroAssembler.hpp"
  31 #include "opto/intrinsicnode.hpp"
  32 #include "opto/output.hpp"
  33 #include "opto/opcodes.hpp"
  34 #include "opto/subnode.hpp"
  35 #include "runtime/globals.hpp"
  36 #include "runtime/objectMonitor.hpp"
  37 #include "runtime/objectMonitorTable.hpp"
  38 #include "runtime/stubRoutines.hpp"
  39 #include "runtime/synchronizer.hpp"
  40 #include "utilities/checkedCast.hpp"
  41 #include "utilities/globalDefinitions.hpp"
  42 #include "utilities/powerOfTwo.hpp"
  43 #include "utilities/sizes.hpp"
  44 

 296     const Register monitor = t;
 297 
 298     if (!UseObjectMonitorTable) {
 299       assert(mark == monitor, "should be the same here");
 300     } else {
 301       const Register hash = t;
 302       Label monitor_found;
 303 
 304       // Look for the monitor in the om_cache.
 305 
 306       ByteSize cache_offset   = JavaThread::om_cache_oops_offset();
 307       ByteSize monitor_offset = OMCache::oop_to_monitor_difference();
 308       const int num_unrolled  = OMCache::CAPACITY;
 309       for (int i = 0; i < num_unrolled; i++) {
 310         movptr(monitor, Address(thread,  cache_offset + monitor_offset));
 311         cmpptr(obj, Address(thread, cache_offset));
 312         jccb(Assembler::equal, monitor_found);
 313         cache_offset = cache_offset + OMCache::oop_to_oop_difference();
 314       }
 315 
 316       // Look for the monitor in the table.
 317 
 318       // Get the hash code.
 319       movptr(hash, Address(obj, oopDesc::mark_offset_in_bytes()));
 320       shrq(hash, markWord::hash_shift);
 321       andq(hash, markWord::hash_mask);
 322 
 323       // Get the table and calculate the bucket's address.
 324       lea(rax_reg, ExternalAddress(ObjectMonitorTable::current_table_address()));
 325       movptr(rax_reg, Address(rax_reg));
 326       andq(hash, Address(rax_reg, ObjectMonitorTable::table_capacity_mask_offset()));
 327       movptr(rax_reg, Address(rax_reg, ObjectMonitorTable::table_buckets_offset()));
 328 
 329       // Read the monitor from the bucket.
 330       movptr(monitor, Address(rax_reg, hash, Address::times_ptr));
 331 
 332       // Check if the monitor in the bucket is special (empty, tombstone or removed)
 333       cmpptr(monitor, ObjectMonitorTable::SpecialPointerValues::below_is_special);
 334       jcc(Assembler::below, slow_path);
 335 
 336       // Check if object matches.
 337       movptr(rax_reg, Address(monitor, ObjectMonitor::object_offset()));
 338       BarrierSetAssembler* bs_asm = BarrierSet::barrier_set()->barrier_set_assembler();
 339       bs_asm->try_resolve_weak_handle_in_c2(this, rax_reg, slow_path);
 340       cmpptr(rax_reg, obj);
 341       jcc(Assembler::notEqual, slow_path);
 342 






 343       bind(monitor_found);
 344     }
 345     const ByteSize monitor_tag = in_ByteSize(UseObjectMonitorTable ? 0 : checked_cast<int>(markWord::monitor_value));
 346     const Address recursions_address(monitor, ObjectMonitor::recursions_offset() - monitor_tag);
 347     const Address owner_address(monitor, ObjectMonitor::owner_offset() - monitor_tag);
 348 
 349     Label monitor_locked;
 350     // Lock the monitor.
 351 
 352     if (UseObjectMonitorTable) {
 353       // Cache the monitor for unlock before trashing box. On failure to acquire
 354       // the lock, the slow path will reset the entry accordingly (see CacheSetter).
 355       movptr(Address(box, BasicLock::object_monitor_cache_offset_in_bytes()), monitor);
 356     }
 357 
 358     // Try to CAS owner (no owner => current thread's _monitor_owner_id).
 359     xorptr(rax_reg, rax_reg);
 360     movptr(box, Address(thread, JavaThread::monitor_owner_id_offset()));
 361     lock(); cmpxchgptr(box, owner_address);
 362     jccb(Assembler::equal, monitor_locked);

   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
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "../../share/runtime/globals.hpp"
  26 #include "asm/assembler.hpp"
  27 #include "asm/assembler.inline.hpp"
  28 #include "gc/shared/barrierSet.hpp"
  29 #include "gc/shared/barrierSetAssembler.hpp"
  30 #include "oops/methodData.hpp"
  31 #include "opto/c2_MacroAssembler.hpp"
  32 #include "opto/intrinsicnode.hpp"
  33 #include "opto/output.hpp"
  34 #include "opto/opcodes.hpp"
  35 #include "opto/subnode.hpp"
  36 #include "runtime/globals.hpp"
  37 #include "runtime/objectMonitor.hpp"
  38 #include "runtime/objectMonitorTable.hpp"
  39 #include "runtime/stubRoutines.hpp"
  40 #include "runtime/synchronizer.hpp"
  41 #include "utilities/checkedCast.hpp"
  42 #include "utilities/globalDefinitions.hpp"
  43 #include "utilities/powerOfTwo.hpp"
  44 #include "utilities/sizes.hpp"
  45 

 297     const Register monitor = t;
 298 
 299     if (!UseObjectMonitorTable) {
 300       assert(mark == monitor, "should be the same here");
 301     } else {
 302       const Register hash = t;
 303       Label monitor_found;
 304 
 305       // Look for the monitor in the om_cache.
 306 
 307       ByteSize cache_offset   = JavaThread::om_cache_oops_offset();
 308       ByteSize monitor_offset = OMCache::oop_to_monitor_difference();
 309       const int num_unrolled  = OMCache::CAPACITY;
 310       for (int i = 0; i < num_unrolled; i++) {
 311         movptr(monitor, Address(thread,  cache_offset + monitor_offset));
 312         cmpptr(obj, Address(thread, cache_offset));
 313         jccb(Assembler::equal, monitor_found);
 314         cache_offset = cache_offset + OMCache::oop_to_oop_difference();
 315       }
 316 
 317       if (UseCompactObjectHeaders) {
 318         // TODO: The fast-path table lookup currently doesn't work with Lilliput's
 319         // compact identity-hashcode implementation.
 320         // See: https://bugs.openjdk.org/browse/JDK-8380981
 321         jmp(slow_path);
 322       } else {
 323         // Look for the monitor in the table.
 324 
 325         // Get the hash code.
 326         movptr(hash, Address(obj, oopDesc::mark_offset_in_bytes()));
 327         shrq(hash, markWord::hash_shift);
 328         andq(hash, markWord::hash_mask);
 329 
 330         // Get the table and calculate the bucket's address.
 331         lea(rax_reg, ExternalAddress(ObjectMonitorTable::current_table_address()));
 332         movptr(rax_reg, Address(rax_reg));
 333         andq(hash, Address(rax_reg, ObjectMonitorTable::table_capacity_mask_offset()));
 334         movptr(rax_reg, Address(rax_reg, ObjectMonitorTable::table_buckets_offset()));
 335 
 336         // Read the monitor from the bucket.
 337         movptr(monitor, Address(rax_reg, hash, Address::times_ptr));
 338 
 339         // Check if the monitor in the bucket is special (empty, tombstone or removed)
 340         cmpptr(monitor, ObjectMonitorTable::SpecialPointerValues::below_is_special);
 341         jcc(Assembler::below, slow_path);
 342 
 343         // Check if object matches.
 344         movptr(rax_reg, Address(monitor, ObjectMonitor::object_offset()));
 345         BarrierSetAssembler* bs_asm = BarrierSet::barrier_set()->barrier_set_assembler();
 346         bs_asm->try_resolve_weak_handle_in_c2(this, rax_reg, slow_path);
 347         cmpptr(rax_reg, obj);
 348         jcc(Assembler::notEqual, slow_path);
 349       }
 350       bind(monitor_found);
 351     }
 352     const ByteSize monitor_tag = in_ByteSize(UseObjectMonitorTable ? 0 : checked_cast<int>(markWord::monitor_value));
 353     const Address recursions_address(monitor, ObjectMonitor::recursions_offset() - monitor_tag);
 354     const Address owner_address(monitor, ObjectMonitor::owner_offset() - monitor_tag);
 355 
 356     Label monitor_locked;
 357     // Lock the monitor.
 358 
 359     if (UseObjectMonitorTable) {
 360       // Cache the monitor for unlock before trashing box. On failure to acquire
 361       // the lock, the slow path will reset the entry accordingly (see CacheSetter).
 362       movptr(Address(box, BasicLock::object_monitor_cache_offset_in_bytes()), monitor);
 363     }
 364 
 365     // Try to CAS owner (no owner => current thread's _monitor_owner_id).
 366     xorptr(rax_reg, rax_reg);
 367     movptr(box, Address(thread, JavaThread::monitor_owner_id_offset()));
 368     lock(); cmpxchgptr(box, owner_address);
 369     jccb(Assembler::equal, monitor_locked);
< prev index next >