< prev index next >

src/hotspot/share/oops/oop.cpp

Print this page
*** 36,10 ***
--- 36,11 ---
  #include "oops/oop.inline.hpp"
  #include "oops/verifyOopClosure.hpp"
  #include "runtime/handles.inline.hpp"
  #include "runtime/javaThread.hpp"
  #include "runtime/synchronizer.hpp"
+ #include "runtime/lightweightSynchronizer.hpp"
  #include "utilities/macros.hpp"
  
  void oopDesc::print_on(outputStream* st) const {
    if (*((juint*)this) == badHeapWordVal) {
      st->print_cr("BAD WORD");

*** 127,10 ***
--- 128,29 ---
      return true;
    }
    return LockingMode == LM_LIGHTWEIGHT || !SafepointSynchronize::is_at_safepoint();
  }
  
+ void oopDesc::initialize_hash_if_necessary(oop obj, Klass* k, markWord m) {
+   assert(UseCompactObjectHeaders, "only with compact object headers");
+   assert(!m.has_displaced_mark_helper(), "must not be displaced header");
+   assert(m.is_hashed_not_expanded(), "must be hashed but not moved");
+   assert(!m.is_hashed_expanded(), "must not be moved: " INTPTR_FORMAT, m.value());
+   uint32_t hash = static_cast<uint32_t>(ObjectSynchronizer::get_next_hash(nullptr, obj));
+   int offset = k->hash_offset_in_bytes(cast_to_oop(this));
+   assert(offset >= 4, "hash offset must not be in header");
+ #ifndef PRODUCT
+   log_trace(ihash)("Initializing hash for " PTR_FORMAT ", old: " PTR_FORMAT ", hash: %d, offset: %d", p2i(this), p2i(obj), hash, offset);
+ #endif
+   int_field_put(offset, (jint) hash);
+   m = m.set_hashed_expanded();
+   assert(static_cast<uint32_t>(LightweightSynchronizer::get_hash(m, cast_to_oop(this), k)) == hash,
+          "hash must remain the same");
+   assert(m.narrow_klass() != 0, "must not be null");
+   set_mark(m);
+ }
+ 
  // used only for asserts and guarantees
  bool oopDesc::is_oop_or_null(oop obj, bool ignore_mark_word) {
    return obj == nullptr ? true : is_oop(obj, ignore_mark_word);
  }
  
< prev index next >