8230203: Replace markWord enums with typed constants
authorstefank
Fri, 30 Aug 2019 09:06:46 +0200
changeset 57959 6b539901e79e
parent 57958 bfb76c34e5c5
child 57960 28915ebc6510
8230203: Replace markWord enums with typed constants Reviewed-by: kbarrett, dholmes
src/hotspot/cpu/aarch64/aarch64.ad
src/hotspot/cpu/arm/macroAssembler_arm.cpp
src/hotspot/cpu/ppc/macroAssembler_ppc.cpp
src/hotspot/share/interpreter/bytecodeInterpreter.cpp
src/hotspot/share/oops/markWord.hpp
src/hotspot/share/opto/macro.cpp
src/hotspot/share/runtime/thread.cpp
--- a/src/hotspot/cpu/aarch64/aarch64.ad	Fri Aug 30 01:21:14 2019 -0400
+++ b/src/hotspot/cpu/aarch64/aarch64.ad	Fri Aug 30 09:06:46 2019 +0200
@@ -3547,7 +3547,7 @@
     // markWord of object (disp_hdr) with the stack pointer.
     __ mov(rscratch1, sp);
     __ sub(disp_hdr, disp_hdr, rscratch1);
-    __ mov(tmp, (address) (~(os::vm_page_size()-1) | (uintptr_t)markWord::lock_mask_in_place));
+    __ mov(tmp, (address) (~(os::vm_page_size()-1) | markWord::lock_mask_in_place));
     // If condition is true we are cont and hence we can store 0 as the
     // displaced header in the box, which indicates that it is a recursive lock.
     __ ands(tmp/*==0?*/, disp_hdr, tmp);   // Sets flags for result
@@ -3616,7 +3616,8 @@
 
     // Handle existing monitor.
     __ bind(object_has_monitor);
-    __ add(tmp, tmp, -markWord::monitor_value); // monitor
+    STATIC_ASSERT(markWord::monitor_value <= INT_MAX);
+    __ add(tmp, tmp, -(int)markWord::monitor_value); // monitor
     __ ldr(rscratch1, Address(tmp, ObjectMonitor::owner_offset_in_bytes()));
     __ ldr(disp_hdr, Address(tmp, ObjectMonitor::recursions_offset_in_bytes()));
     __ eor(rscratch1, rscratch1, rthread); // Will be 0 if we are the owner.
--- a/src/hotspot/cpu/arm/macroAssembler_arm.cpp	Fri Aug 30 01:21:14 2019 -0400
+++ b/src/hotspot/cpu/arm/macroAssembler_arm.cpp	Fri Aug 30 09:06:46 2019 +0200
@@ -1367,7 +1367,7 @@
   // On MP platform loads could return 'stale' values in some cases.
   // That is acceptable since either CAS or slow case path is taken in the worst case.
 
-  andr(tmp_reg, swap_reg, (uintx)markWord::biased_lock_mask_in_place);
+  andr(tmp_reg, swap_reg, markWord::biased_lock_mask_in_place);
   cmp(tmp_reg, markWord::biased_lock_pattern);
 
   b(cas_label, ne);
@@ -1401,7 +1401,7 @@
   // If the low three bits in the xor result aren't clear, that means
   // the prototype header is no longer biased and we have to revoke
   // the bias on this object.
-  tst(tmp_reg, (uintx)markWord::biased_lock_mask_in_place);
+  tst(tmp_reg, markWord::biased_lock_mask_in_place);
   b(try_revoke_bias, ne);
 
   // Biasing is still enabled for this data type. See whether the
@@ -1413,7 +1413,7 @@
   // that the current epoch is invalid in order to do this because
   // otherwise the manipulations it performs on the mark word are
   // illegal.
-  tst(tmp_reg, (uintx)markWord::epoch_mask_in_place);
+  tst(tmp_reg, markWord::epoch_mask_in_place);
   b(try_rebias, ne);
 
   // tmp_reg has the age, epoch and pattern bits cleared
@@ -1519,7 +1519,7 @@
   // the bias bit would be clear.
   ldr(tmp_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
 
-  andr(tmp_reg, tmp_reg, (uintx)markWord::biased_lock_mask_in_place);
+  andr(tmp_reg, tmp_reg, markWord::biased_lock_mask_in_place);
   cmp(tmp_reg, markWord::biased_lock_pattern);
   b(done, eq);
 }
--- a/src/hotspot/cpu/ppc/macroAssembler_ppc.cpp	Fri Aug 30 01:21:14 2019 -0400
+++ b/src/hotspot/cpu/ppc/macroAssembler_ppc.cpp	Fri Aug 30 09:06:46 2019 +0200
@@ -3000,7 +3000,8 @@
   b(cont);
 
   bind(object_has_monitor);
-  addi(current_header, current_header, -markWord::monitor_value); // monitor
+  STATIC_ASSERT(markWord::monitor_value <= INT_MAX);
+  addi(current_header, current_header, -(int)markWord::monitor_value); // monitor
   ld(temp,             ObjectMonitor::owner_offset_in_bytes(), current_header);
 
     // It's inflated.
--- a/src/hotspot/share/interpreter/bytecodeInterpreter.cpp	Fri Aug 30 01:21:14 2019 -0400
+++ b/src/hotspot/share/interpreter/bytecodeInterpreter.cpp	Fri Aug 30 09:06:46 2019 +0200
@@ -666,7 +666,7 @@
         BasicObjectLock* mon = &istate->monitor_base()[-1];
         mon->set_obj(rcvr);
         bool success = false;
-        uintptr_t epoch_mask_in_place = (uintptr_t)markWord::epoch_mask_in_place;
+        uintptr_t epoch_mask_in_place = markWord::epoch_mask_in_place;
         markWord mark = rcvr->mark();
         intptr_t hash = (intptr_t) markWord::no_hash;
         // Implies UseBiasedLocking.
@@ -675,8 +675,8 @@
           uintptr_t anticipated_bias_locking_value;
           thread_ident = (uintptr_t)istate->thread();
           anticipated_bias_locking_value =
-            (((uintptr_t)rcvr->klass()->prototype_header().value() | thread_ident) ^ mark.value()) &
-            ~((uintptr_t) markWord::age_mask_in_place);
+            ((rcvr->klass()->prototype_header().value() | thread_ident) ^ mark.value()) &
+            ~(markWord::age_mask_in_place);
 
           if (anticipated_bias_locking_value == 0) {
             // Already biased towards this thread, nothing to do.
@@ -711,8 +711,8 @@
           } else {
             // Try to bias towards thread in case object is anonymously biased.
             markWord header(mark.value() &
-                            ((uintptr_t)markWord::biased_lock_mask_in_place |
-                             (uintptr_t)markWord::age_mask_in_place | epoch_mask_in_place));
+                            (markWord::biased_lock_mask_in_place |
+                             markWord::age_mask_in_place | epoch_mask_in_place));
             if (hash != markWord::no_hash) {
               header = header.copy_set_hash(hash);
             }
@@ -851,7 +851,7 @@
       assert(entry->obj() == NULL, "Frame manager didn't allocate the monitor");
       entry->set_obj(lockee);
       bool success = false;
-      uintptr_t epoch_mask_in_place = (uintptr_t)markWord::epoch_mask_in_place;
+      uintptr_t epoch_mask_in_place = markWord::epoch_mask_in_place;
 
       markWord mark = lockee->mark();
       intptr_t hash = (intptr_t) markWord::no_hash;
@@ -861,8 +861,8 @@
         uintptr_t anticipated_bias_locking_value;
         thread_ident = (uintptr_t)istate->thread();
         anticipated_bias_locking_value =
-          (((uintptr_t)lockee->klass()->prototype_header().value() | thread_ident) ^ mark.value()) &
-          ~((uintptr_t) markWord::age_mask_in_place);
+          ((lockee->klass()->prototype_header().value() | thread_ident) ^ mark.value()) &
+          ~(markWord::age_mask_in_place);
 
         if  (anticipated_bias_locking_value == 0) {
           // already biased towards this thread, nothing to do
@@ -897,8 +897,8 @@
           success = true;
         } else {
           // try to bias towards thread in case object is anonymously biased
-          markWord header(mark.value() & ((uintptr_t)markWord::biased_lock_mask_in_place |
-                                          (uintptr_t)markWord::age_mask_in_place | epoch_mask_in_place));
+          markWord header(mark.value() & (markWord::biased_lock_mask_in_place |
+                                          markWord::age_mask_in_place | epoch_mask_in_place));
           if (hash != markWord::no_hash) {
             header = header.copy_set_hash(hash);
           }
@@ -1791,7 +1791,7 @@
         if (entry != NULL) {
           entry->set_obj(lockee);
           int success = false;
-          uintptr_t epoch_mask_in_place = (uintptr_t)markWord::epoch_mask_in_place;
+          uintptr_t epoch_mask_in_place = markWord::epoch_mask_in_place;
 
           markWord mark = lockee->mark();
           intptr_t hash = (intptr_t) markWord::no_hash;
@@ -1801,8 +1801,8 @@
             uintptr_t anticipated_bias_locking_value;
             thread_ident = (uintptr_t)istate->thread();
             anticipated_bias_locking_value =
-              (((uintptr_t)lockee->klass()->prototype_header().value() | thread_ident) ^ mark.value()) &
-              ~((uintptr_t) markWord::age_mask_in_place);
+              ((lockee->klass()->prototype_header().value() | thread_ident) ^ mark.value()) &
+              ~(markWord::age_mask_in_place);
 
             if  (anticipated_bias_locking_value == 0) {
               // already biased towards this thread, nothing to do
@@ -1839,8 +1839,8 @@
             }
             else {
               // try to bias towards thread in case object is anonymously biased
-              markWord header(mark.value() & ((uintptr_t)markWord::biased_lock_mask_in_place |
-                                              (uintptr_t)markWord::age_mask_in_place |
+              markWord header(mark.value() & (markWord::biased_lock_mask_in_place |
+                                              markWord::age_mask_in_place |
                                               epoch_mask_in_place));
               if (hash != markWord::no_hash) {
                 header = header.copy_set_hash(hash);
--- a/src/hotspot/share/oops/markWord.hpp	Fri Aug 30 01:21:14 2019 -0400
+++ b/src/hotspot/share/oops/markWord.hpp	Fri Aug 30 09:06:46 2019 +0200
@@ -131,61 +131,54 @@
   uintptr_t value() const { return _value; }
 
   // Constants
-  enum { age_bits                 = 4,
-         lock_bits                = 2,
-         biased_lock_bits         = 1,
-         max_hash_bits            = BitsPerWord - age_bits - lock_bits - biased_lock_bits,
-         hash_bits                = max_hash_bits > 31 ? 31 : max_hash_bits,
-         cms_bits                 = LP64_ONLY(1) NOT_LP64(0),
-         epoch_bits               = 2
-  };
+  static const int age_bits                       = 4;
+  static const int lock_bits                      = 2;
+  static const int biased_lock_bits               = 1;
+  static const int max_hash_bits                  = BitsPerWord - age_bits - lock_bits - biased_lock_bits;
+  static const int hash_bits                      = max_hash_bits > 31 ? 31 : max_hash_bits;
+  static const int cms_bits                       = LP64_ONLY(1) NOT_LP64(0);
+  static const int epoch_bits                     = 2;
 
   // The biased locking code currently requires that the age bits be
   // contiguous to the lock bits.
-  enum { lock_shift               = 0,
-         biased_lock_shift        = lock_bits,
-         age_shift                = lock_bits + biased_lock_bits,
-         cms_shift                = age_shift + age_bits,
-         hash_shift               = cms_shift + cms_bits,
-         epoch_shift              = hash_shift
-  };
+  static const int lock_shift                     = 0;
+  static const int biased_lock_shift              = lock_bits;
+  static const int age_shift                      = lock_bits + biased_lock_bits;
+  static const int cms_shift                      = age_shift + age_bits;
+  static const int hash_shift                     = cms_shift + cms_bits;
+  static const int epoch_shift                    = hash_shift;
 
-  enum { lock_mask                = right_n_bits(lock_bits),
-         lock_mask_in_place       = lock_mask << lock_shift,
-         biased_lock_mask         = right_n_bits(lock_bits + biased_lock_bits),
-         biased_lock_mask_in_place= biased_lock_mask << lock_shift,
-         biased_lock_bit_in_place = 1 << biased_lock_shift,
-         age_mask                 = right_n_bits(age_bits),
-         age_mask_in_place        = age_mask << age_shift,
-         epoch_mask               = right_n_bits(epoch_bits),
-         epoch_mask_in_place      = epoch_mask << epoch_shift,
-         cms_mask                 = right_n_bits(cms_bits),
-         cms_mask_in_place        = cms_mask << cms_shift
-  };
+  static const uintptr_t lock_mask                = right_n_bits(lock_bits);
+  static const uintptr_t lock_mask_in_place       = lock_mask << lock_shift;
+  static const uintptr_t biased_lock_mask         = right_n_bits(lock_bits + biased_lock_bits);
+  static const uintptr_t biased_lock_mask_in_place= biased_lock_mask << lock_shift;
+  static const uintptr_t biased_lock_bit_in_place = 1 << biased_lock_shift;
+  static const uintptr_t age_mask                 = right_n_bits(age_bits);
+  static const uintptr_t age_mask_in_place        = age_mask << age_shift;
+  static const uintptr_t epoch_mask               = right_n_bits(epoch_bits);
+  static const uintptr_t epoch_mask_in_place      = epoch_mask << epoch_shift;
+  static const uintptr_t cms_mask                 = right_n_bits(cms_bits);
+  static const uintptr_t cms_mask_in_place        = cms_mask << cms_shift;
 
-  const static uintptr_t hash_mask = right_n_bits(hash_bits);
-  const static uintptr_t hash_mask_in_place = hash_mask << hash_shift;
+  static const uintptr_t hash_mask                = right_n_bits(hash_bits);
+  static const uintptr_t hash_mask_in_place       = hash_mask << hash_shift;
 
   // Alignment of JavaThread pointers encoded in object header required by biased locking
-  enum { biased_lock_alignment    = 2 << (epoch_shift + epoch_bits)
-  };
+  static const size_t biased_lock_alignment       = 2 << (epoch_shift + epoch_bits);
 
-  enum { locked_value             = 0,
-         unlocked_value           = 1,
-         monitor_value            = 2,
-         marked_value             = 3,
-         biased_lock_pattern      = 5
-  };
+  static const uintptr_t locked_value             = 0;
+  static const uintptr_t unlocked_value           = 1;
+  static const uintptr_t monitor_value            = 2;
+  static const uintptr_t marked_value             = 3;
+  static const uintptr_t biased_lock_pattern      = 5;
 
-  enum { no_hash                  = 0 };  // no hash value assigned
+  static const uintptr_t no_hash                  = 0 ;  // no hash value assigned
+  static const uintptr_t no_hash_in_place         = (address_word)no_hash << hash_shift;
+  static const uintptr_t no_lock_in_place         = unlocked_value;
 
-  enum { no_hash_in_place         = (address_word)no_hash << hash_shift,
-         no_lock_in_place         = unlocked_value
-  };
+  static const uint max_age                       = age_mask;
 
-  enum { max_age                  = age_mask };
-
-  enum { max_bias_epoch           = epoch_mask };
+  static const int max_bias_epoch                 = epoch_mask;
 
   // Creates a markWord with all bits set to zero.
   static markWord zero() { return markWord(uintptr_t(0)); }
@@ -201,7 +194,7 @@
   }
   JavaThread* biased_locker() const {
     assert(has_bias_pattern(), "should not call this otherwise");
-    return (JavaThread*) ((intptr_t) (mask_bits(value(), ~(biased_lock_mask_in_place | age_mask_in_place | epoch_mask_in_place))));
+    return (JavaThread*) mask_bits(value(), ~(biased_lock_mask_in_place | age_mask_in_place | epoch_mask_in_place));
   }
   // Indicates that the mark has the bias bit set but that it has not
   // yet been biased toward a particular thread
@@ -308,16 +301,16 @@
   }
   markWord displaced_mark_helper() const {
     assert(has_displaced_mark_helper(), "check");
-    intptr_t ptr = (value() & ~monitor_value);
+    uintptr_t ptr = (value() & ~monitor_value);
     return *(markWord*)ptr;
   }
   void set_displaced_mark_helper(markWord m) const {
     assert(has_displaced_mark_helper(), "check");
-    intptr_t ptr = (value() & ~monitor_value);
+    uintptr_t ptr = (value() & ~monitor_value);
     ((markWord*)ptr)->_value = m._value;
   }
   markWord copy_set_hash(intptr_t hash) const {
-    intptr_t tmp = value() & (~hash_mask_in_place);
+    uintptr_t tmp = value() & (~hash_mask_in_place);
     tmp |= ((hash & hash_mask) << hash_shift);
     return markWord(tmp);
   }
@@ -332,11 +325,11 @@
     return from_pointer(lock);
   }
   static markWord encode(ObjectMonitor* monitor) {
-    intptr_t tmp = (intptr_t) monitor;
+    uintptr_t tmp = (uintptr_t) monitor;
     return markWord(tmp | monitor_value);
   }
   static markWord encode(JavaThread* thread, uint age, int bias_epoch) {
-    intptr_t tmp = (intptr_t) thread;
+    uintptr_t tmp = (uintptr_t) thread;
     assert(UseBiasedLocking && ((tmp & (epoch_mask_in_place | age_mask_in_place | biased_lock_mask_in_place)) == 0), "misaligned JavaThread pointer");
     assert(age <= max_age, "age too large");
     assert(bias_epoch <= max_bias_epoch, "bias epoch too large");
@@ -353,7 +346,7 @@
   uint     age()           const { return mask_bits(value() >> age_shift, age_mask); }
   markWord set_age(uint v) const {
     assert((v & ~age_mask) == 0, "shouldn't overflow age field");
-    return markWord((value() & ~age_mask_in_place) | (((uintptr_t)v & age_mask) << age_shift));
+    return markWord((value() & ~age_mask_in_place) | ((v & age_mask) << age_shift));
   }
   markWord incr_age()      const { return age() == max_age ? markWord(_value) : set_age(age() + 1); }
 
@@ -400,7 +393,7 @@
 
 #ifdef _LP64
   static markWord cms_free_prototype() {
-    return markWord(((intptr_t)prototype().value() & ~cms_mask_in_place) |
+    return markWord((prototype().value() & ~cms_mask_in_place) |
                     ((cms_free_chunk_pattern & cms_mask) << cms_shift));
   }
   uintptr_t cms_encoding() const {
@@ -414,8 +407,8 @@
   size_t get_size() const       { return (size_t)(value() >> size_shift); }
   static markWord set_size_and_free(size_t size) {
     assert((size & ~size_mask) == 0, "shouldn't overflow size field");
-    return markWord(((intptr_t)cms_free_prototype().value() & ~size_mask_in_place) |
-                    (((intptr_t)size & size_mask) << size_shift));
+    return markWord((cms_free_prototype().value() & ~size_mask_in_place) |
+                    ((size & size_mask) << size_shift));
   }
 #endif // _LP64
 };
--- a/src/hotspot/share/opto/macro.cpp	Fri Aug 30 01:21:14 2019 -0400
+++ b/src/hotspot/share/opto/macro.cpp	Fri Aug 30 09:06:46 2019 +0200
@@ -2225,8 +2225,9 @@
     Node* x_node = transform_later(new XorXNode(o_node, mark_node));
 
     // Get slow path - mark word does NOT match the value.
+    STATIC_ASSERT(markWord::age_mask_in_place <= INT_MAX);
     Node* not_biased_ctrl =  opt_bits_test(ctrl, region, 3, x_node,
-                                      (~markWord::age_mask_in_place), 0);
+                                      (~(int)markWord::age_mask_in_place), 0);
     // region->in(3) is set to fast path - the object is biased to the current thread.
     mem_phi->init_req(3, mem);
 
--- a/src/hotspot/share/runtime/thread.cpp	Fri Aug 30 01:21:14 2019 -0400
+++ b/src/hotspot/share/runtime/thread.cpp	Fri Aug 30 09:06:46 2019 +0200
@@ -173,7 +173,7 @@
 // Support for forcing alignment of thread objects for biased locking
 void* Thread::allocate(size_t size, bool throw_excpt, MEMFLAGS flags) {
   if (UseBiasedLocking) {
-    const int alignment = markWord::biased_lock_alignment;
+    const size_t alignment = markWord::biased_lock_alignment;
     size_t aligned_size = size + (alignment - sizeof(intptr_t));
     void* real_malloc_addr = throw_excpt? AllocateHeap(aligned_size, flags, CURRENT_PC)
                                           : AllocateHeap(aligned_size, flags, CURRENT_PC,
@@ -301,9 +301,9 @@
 #endif // CHECK_UNHANDLED_OOPS
 #ifdef ASSERT
   if (UseBiasedLocking) {
-    assert((((uintptr_t) this) & (markWord::biased_lock_alignment - 1)) == 0, "forced alignment of thread object failed");
+    assert(is_aligned(this, markWord::biased_lock_alignment), "forced alignment of thread object failed");
     assert(this == _real_malloc_address ||
-           this == align_up(_real_malloc_address, (int)markWord::biased_lock_alignment),
+           this == align_up(_real_malloc_address, markWord::biased_lock_alignment),
            "bug in forced alignment of thread objects");
   }
 #endif // ASSERT