< prev index next >

src/hotspot/share/runtime/lightweightSynchronizer.cpp

Print this page
*** 49,10 ***
--- 49,22 ---
  #include "runtime/trimNativeHeap.hpp"
  #include "utilities/concurrentHashTable.inline.hpp"
  #include "utilities/concurrentHashTableTasks.inline.hpp"
  #include "utilities/globalDefinitions.hpp"
  
+ static uintx objhash(oop obj) {
+   if (UseCompactObjectHeaders) {
+     uintx hash = LightweightSynchronizer::get_hash(obj->mark(), obj);
+     assert(hash != 0, "should have a hash");
+     return hash;
+   } else {
+     uintx hash = obj->mark().hash();
+     assert(hash != 0, "should have a hash");
+     return hash;
+   }
+ }
+ 
  // ConcurrentHashTable storing links from objects to ObjectMonitors
  class ObjectMonitorTable : AllStatic {
    struct Config {
      using Value = ObjectMonitor*;
      static uintx get_hash(Value const& value, bool* is_dead) {

*** 79,13 ***
  
     public:
      explicit Lookup(oop obj) : _obj(obj) {}
  
      uintx get_hash() const {
!       uintx hash = _obj->mark().hash();
-       assert(hash != 0, "should have a hash");
-       return hash;
      }
  
      bool equals(ObjectMonitor** value) {
        assert(*value != nullptr, "must be");
        return (*value)->object_refers_to(_obj);
--- 91,11 ---
  
     public:
      explicit Lookup(oop obj) : _obj(obj) {}
  
      uintx get_hash() const {
!       return objhash(_obj);
      }
  
      bool equals(ObjectMonitor** value) {
        assert(*value != nullptr, "must be");
        return (*value)->object_refers_to(_obj);

*** 283,10 ***
--- 293,11 ---
      // Enter the monitor into the concurrent hashtable.
      ObjectMonitor* result = monitor;
      Lookup lookup_f(obj);
      auto found_f = [&](ObjectMonitor** found) {
        assert((*found)->object_peek() == obj, "must be");
+       assert(objhash(obj) == (uintx)(*found)->hash(), "hash must match");
        result = *found;
      };
      bool grow;
      _table->insert_get(current, lookup_f, monitor, found_f, &grow);
      verify_monitor_get_result(obj, result);

*** 315,11 ***
      auto printer = [&] (ObjectMonitor** entry) {
         ObjectMonitor* om = *entry;
         oop obj = om->object_peek();
         st->print("monitor=" PTR_FORMAT ", ", p2i(om));
         st->print("object=" PTR_FORMAT, p2i(obj));
!        assert(obj->mark().hash() == om->hash(), "hash must match");
         st->cr();
         return true;
      };
      if (SafepointSynchronize::is_at_safepoint()) {
        _table->do_safepoint_scan(printer);
--- 326,11 ---
      auto printer = [&] (ObjectMonitor** entry) {
         ObjectMonitor* om = *entry;
         oop obj = om->object_peek();
         st->print("monitor=" PTR_FORMAT ", ", p2i(om));
         st->print("object=" PTR_FORMAT, p2i(obj));
!        assert(objhash(obj) == (uintx)om->hash(), "hash must match");
         st->cr();
         return true;
      };
      if (SafepointSynchronize::is_at_safepoint()) {
        _table->do_safepoint_scan(printer);

*** 404,11 ***
  // Add the hashcode to the monitor to match the object and put it in the hashtable.
  ObjectMonitor* LightweightSynchronizer::add_monitor(JavaThread* current, ObjectMonitor* monitor, oop obj) {
    assert(UseObjectMonitorTable, "must be");
    assert(obj == monitor->object(), "must be");
  
!   intptr_t hash = obj->mark().hash();
    assert(hash != 0, "must be set when claiming the object monitor");
    monitor->set_hash(hash);
  
    return ObjectMonitorTable::monitor_put_get(current, monitor, obj);
  }
--- 415,11 ---
  // Add the hashcode to the monitor to match the object and put it in the hashtable.
  ObjectMonitor* LightweightSynchronizer::add_monitor(JavaThread* current, ObjectMonitor* monitor, oop obj) {
    assert(UseObjectMonitorTable, "must be");
    assert(obj == monitor->object(), "must be");
  
!   intptr_t hash = objhash(obj);
    assert(hash != 0, "must be set when claiming the object monitor");
    monitor->set_hash(hash);
  
    return ObjectMonitorTable::monitor_put_get(current, monitor, obj);
  }

*** 1215,5 ***
--- 1226,23 ---
    }
  
    // Slow-path.
    return false;
  }
+ 
+ uint32_t LightweightSynchronizer::get_hash(markWord mark, oop obj, Klass* klass) {
+   assert(UseCompactObjectHeaders, "Only with compact i-hash");
+   //assert(mark.is_neutral() | mark.is_fast_locked(), "only from neutral or fast-locked mark: " INTPTR_FORMAT, mark.value());
+   assert(mark.is_hashed(), "only from hashed or copied object");
+   if (mark.is_hashed_expanded()) {
+     return obj->int_field(klass->hash_offset_in_bytes(obj));
+   } else {
+     assert(mark.is_hashed_not_expanded(), "must be hashed");
+     assert(hashCode == 6 || hashCode == 2, "must have idempotent hashCode");
+     // Already marked as hashed, but not yet copied. Recompute hash and return it.
+     return ObjectSynchronizer::get_next_hash(nullptr, obj); // recompute hash
+   }
+ }
+ 
+ uint32_t LightweightSynchronizer::get_hash(markWord mark, oop obj) {
+   return get_hash(mark, obj, mark.klass());
+ }
< prev index next >