src/hotspot/share/oops/markWord.hpp
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 57959 6b539901e79e
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 47216
diff changeset
     2
 * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5541
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5541
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5541
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
57811
947252a54b98 8229838: Rename markOop files to markWord
stefank
parents: 57777
diff changeset
    25
#ifndef SHARE_OOPS_MARKWORD_HPP
947252a54b98 8229838: Rename markOop files to markWord
stefank
parents: 57777
diff changeset
    26
#define SHARE_OOPS_MARKWORD_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
    28
#include "metaprogramming/integralConstant.hpp"
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
    29
#include "metaprogramming/primitiveConversions.hpp"
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
    30
#include "oops/oopsHierarchy.hpp"
57875
427b38332f20 8229836: Remove include of globals.hpp from allocation.hpp
stefank
parents: 57812
diff changeset
    31
#include "runtime/globals.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
    33
// The markWord describes the header of an object.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
//
5541
19c39d42a747 6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents: 1388
diff changeset
    35
// Bit-format of an object header (most significant first, big endian layout below):
19c39d42a747 6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents: 1388
diff changeset
    36
//
19c39d42a747 6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents: 1388
diff changeset
    37
//  32 bits:
19c39d42a747 6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents: 1388
diff changeset
    38
//  --------
19c39d42a747 6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents: 1388
diff changeset
    39
//             hash:25 ------------>| age:4    biased_lock:1 lock:2 (normal object)
19c39d42a747 6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents: 1388
diff changeset
    40
//             JavaThread*:23 epoch:2 age:4    biased_lock:1 lock:2 (biased object)
19c39d42a747 6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents: 1388
diff changeset
    41
//             size:32 ------------------------------------------>| (CMS free block)
19c39d42a747 6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents: 1388
diff changeset
    42
//             PromotedObject*:29 ---------->| promo_bits:3 ----->| (CMS promoted object)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
//
5541
19c39d42a747 6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents: 1388
diff changeset
    44
//  64 bits:
19c39d42a747 6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents: 1388
diff changeset
    45
//  --------
19c39d42a747 6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents: 1388
diff changeset
    46
//  unused:25 hash:31 -->| unused:1   age:4    biased_lock:1 lock:2 (normal object)
19c39d42a747 6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents: 1388
diff changeset
    47
//  JavaThread*:54 epoch:2 unused:1   age:4    biased_lock:1 lock:2 (biased object)
19c39d42a747 6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents: 1388
diff changeset
    48
//  PromotedObject*:61 --------------------->| promo_bits:3 ----->| (CMS promoted object)
19c39d42a747 6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents: 1388
diff changeset
    49
//  size:64 ----------------------------------------------------->| (CMS free block)
19c39d42a747 6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents: 1388
diff changeset
    50
//
19c39d42a747 6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents: 1388
diff changeset
    51
//  unused:25 hash:31 -->| cms_free:1 age:4    biased_lock:1 lock:2 (COOPs && normal object)
19c39d42a747 6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents: 1388
diff changeset
    52
//  JavaThread*:54 epoch:2 cms_free:1 age:4    biased_lock:1 lock:2 (COOPs && biased object)
19c39d42a747 6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents: 1388
diff changeset
    53
//  narrowOop:32 unused:24 cms_free:1 unused:4 promo_bits:3 ----->| (COOPs && CMS promoted object)
19c39d42a747 6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents: 1388
diff changeset
    54
//  unused:21 size:35 -->| cms_free:1 unused:7 ------------------>| (COOPs && CMS free block)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
//  - hash contains the identity hash value: largest value is
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
//    31 bits, see os::random().  Also, 64-bit vm's require
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
//    a hash value no bigger than 32 bits because they will not
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
//    properly generate a mask larger than that: see library_call.cpp
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
//    and c1_CodePatterns_sparc.cpp.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
//  - the biased lock pattern is used to bias a lock toward a given
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
//    thread. When this pattern is set in the low three bits, the lock
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
//    is either biased toward a given thread or "anonymously" biased,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
//    indicating that it is possible for it to be biased. When the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
//    lock is biased toward a given thread, locking and unlocking can
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
//    be performed by that thread without using atomic operations.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
//    When a lock's bias is revoked, it reverts back to the normal
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
//    locking scheme described below.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
//    Note that we are overloading the meaning of the "unlocked" state
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
//    of the header. Because we steal a bit from the age we can
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
//    guarantee that the bias pattern will never be seen for a truly
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
//    unlocked object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
//    Note also that the biased state contains the age bits normally
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
//    contained in the object header. Large increases in scavenge
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
//    times were seen when these bits were absent and an arbitrary age
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
//    assigned to all biased objects, because they tended to consume a
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
//    significant fraction of the eden semispaces and were not
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
//    promoted promptly, causing an increase in the amount of copying
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
//    performed. The runtime system aligns all JavaThread* pointers to
5541
19c39d42a747 6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents: 1388
diff changeset
    83
//    a very large value (currently 128 bytes (32bVM) or 256 bytes (64bVM))
19c39d42a747 6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents: 1388
diff changeset
    84
//    to make room for the age bits & the epoch bits (used in support of
19c39d42a747 6948539: CMS+UseCompressedOops: placement of cms_free bit interferes with promoted object link
ysr
parents: 1388
diff changeset
    85
//    biased locking), and for the CMS "freeness" bit in the 64bVM (+COOPs).
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
//    [JavaThread* | epoch | age | 1 | 01]       lock is biased toward given thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
//    [0           | epoch | age | 1 | 01]       lock is anonymously biased
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
//  - the two lock bits are used to describe three states: locked/unlocked and monitor.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
//    [ptr             | 00]  locked             ptr points to real header on stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
//    [header      | 0 | 01]  unlocked           regular object header
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
//    [ptr             | 10]  monitor            inflated lock (header is wapped out)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
//    [ptr             | 11]  marked             used by markSweep to mark an object
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
//                                               not valid at any other time
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
//    We assume that stack/thread pointers have the lowest two bits cleared.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
class BasicLock;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
class ObjectMonitor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
class JavaThread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   104
class markWord {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
 private:
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   106
  uintptr_t _value;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
 public:
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   109
  explicit markWord(uintptr_t value) : _value(value) {}
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   110
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   111
  markWord() { /* uninitialized */}
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   112
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   113
  // It is critical for performance that this class be trivially
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   114
  // destructable, copyable, and assignable.
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   115
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   116
  static markWord from_pointer(void* ptr) {
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   117
    return markWord((uintptr_t)ptr);
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   118
  }
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   119
  void* to_pointer() const {
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   120
    return (void*)_value;
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   121
  }
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   122
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   123
  bool operator==(const markWord& other) const {
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   124
    return _value == other._value;
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   125
  }
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   126
  bool operator!=(const markWord& other) const {
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   127
    return !operator==(other);
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   128
  }
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   129
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   130
  // Conversion
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   131
  uintptr_t value() const { return _value; }
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   132
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  // Constants
57959
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   134
  static const int age_bits                       = 4;
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   135
  static const int lock_bits                      = 2;
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   136
  static const int biased_lock_bits               = 1;
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   137
  static const int max_hash_bits                  = BitsPerWord - age_bits - lock_bits - biased_lock_bits;
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   138
  static const int hash_bits                      = max_hash_bits > 31 ? 31 : max_hash_bits;
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   139
  static const int cms_bits                       = LP64_ONLY(1) NOT_LP64(0);
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   140
  static const int epoch_bits                     = 2;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  // The biased locking code currently requires that the age bits be
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   143
  // contiguous to the lock bits.
57959
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   144
  static const int lock_shift                     = 0;
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   145
  static const int biased_lock_shift              = lock_bits;
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   146
  static const int age_shift                      = lock_bits + biased_lock_bits;
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   147
  static const int cms_shift                      = age_shift + age_bits;
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   148
  static const int hash_shift                     = cms_shift + cms_bits;
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   149
  static const int epoch_shift                    = hash_shift;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
57959
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   151
  static const uintptr_t lock_mask                = right_n_bits(lock_bits);
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   152
  static const uintptr_t lock_mask_in_place       = lock_mask << lock_shift;
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   153
  static const uintptr_t biased_lock_mask         = right_n_bits(lock_bits + biased_lock_bits);
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   154
  static const uintptr_t biased_lock_mask_in_place= biased_lock_mask << lock_shift;
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   155
  static const uintptr_t biased_lock_bit_in_place = 1 << biased_lock_shift;
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   156
  static const uintptr_t age_mask                 = right_n_bits(age_bits);
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   157
  static const uintptr_t age_mask_in_place        = age_mask << age_shift;
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   158
  static const uintptr_t epoch_mask               = right_n_bits(epoch_bits);
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   159
  static const uintptr_t epoch_mask_in_place      = epoch_mask << epoch_shift;
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   160
  static const uintptr_t cms_mask                 = right_n_bits(cms_bits);
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   161
  static const uintptr_t cms_mask_in_place        = cms_mask << cms_shift;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
57959
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   163
  static const uintptr_t hash_mask                = right_n_bits(hash_bits);
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   164
  static const uintptr_t hash_mask_in_place       = hash_mask << hash_shift;
54335
d9f6d16299b1 8221408: Windows 32bit build build errors/warnings in hotspot
stuefe
parents: 53244
diff changeset
   165
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  // Alignment of JavaThread pointers encoded in object header required by biased locking
57959
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   167
  static const size_t biased_lock_alignment       = 2 << (epoch_shift + epoch_bits);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
57959
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   169
  static const uintptr_t locked_value             = 0;
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   170
  static const uintptr_t unlocked_value           = 1;
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   171
  static const uintptr_t monitor_value            = 2;
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   172
  static const uintptr_t marked_value             = 3;
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   173
  static const uintptr_t biased_lock_pattern      = 5;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
57959
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   175
  static const uintptr_t no_hash                  = 0 ;  // no hash value assigned
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   176
  static const uintptr_t no_hash_in_place         = (address_word)no_hash << hash_shift;
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   177
  static const uintptr_t no_lock_in_place         = unlocked_value;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
57959
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   179
  static const uint max_age                       = age_mask;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
57959
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   181
  static const int max_bias_epoch                 = epoch_mask;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   183
  // Creates a markWord with all bits set to zero.
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   184
  static markWord zero() { return markWord(uintptr_t(0)); }
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   185
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  // Biased Locking accessors.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  // These must be checked by all code which calls into the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  // ObjectSynchronizer and other code. The biasing is not understood
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  // by the lower-level CAS-based locking code, although the runtime
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  // fixes up biased locks to be compatible with it when a bias is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  // revoked.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  bool has_bias_pattern() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    return (mask_bits(value(), biased_lock_mask_in_place) == biased_lock_pattern);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  JavaThread* biased_locker() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    assert(has_bias_pattern(), "should not call this otherwise");
57959
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   197
    return (JavaThread*) mask_bits(value(), ~(biased_lock_mask_in_place | age_mask_in_place | epoch_mask_in_place));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  // Indicates that the mark has the bias bit set but that it has not
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  // yet been biased toward a particular thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  bool is_biased_anonymously() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    return (has_bias_pattern() && (biased_locker() == NULL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  // Indicates epoch in which this bias was acquired. If the epoch
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  // changes due to too many bias revocations occurring, the biases
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  // from the previous epochs are all considered invalid.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  int bias_epoch() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    assert(has_bias_pattern(), "should not call this otherwise");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    return (mask_bits(value(), epoch_mask_in_place) >> epoch_shift);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  }
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   211
  markWord set_bias_epoch(int epoch) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    assert(has_bias_pattern(), "should not call this otherwise");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
    assert((epoch & (~epoch_mask)) == 0, "epoch overflow");
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   214
    return markWord(mask_bits(value(), ~epoch_mask_in_place) | (epoch << epoch_shift));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  }
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   216
  markWord incr_bias_epoch() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    return set_bias_epoch((1 + bias_epoch()) & epoch_mask);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  // Prototype mark for initialization
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   220
  static markWord biased_locking_prototype() {
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   221
    return markWord( biased_lock_pattern );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  // lock accessors (note that these assume lock_shift == 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  bool is_locked()   const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    return (mask_bits(value(), lock_mask_in_place) != unlocked_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  bool is_unlocked() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    return (mask_bits(value(), biased_lock_mask_in_place) == unlocked_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  bool is_marked()   const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    return (mask_bits(value(), lock_mask_in_place) == marked_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  bool is_neutral()  const { return (mask_bits(value(), biased_lock_mask_in_place) == unlocked_value); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   236
  // Special temporary state of the markWord while being inflated.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  // Code that looks at mark outside a lock need to take this into account.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  bool is_being_inflated() const { return (value() == 0); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  // Distinguished markword value - used when inflating over
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  // an existing stacklock.  0 indicates the markword is "BUSY".
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  // Lockword mutators that use a LD...CAS idiom should always
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  // check for and avoid overwriting a 0 value installed by some
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  // other thread.  (They should spin or block instead.  The 0 value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  // is transient and *should* be short-lived).
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   246
  static markWord INFLATING() { return zero(); }    // inflate-in-progress
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  // Should this header be preserved during GC?
57812
9bb28ccc6106 8229839: Break circular dependency between oop.inline.hpp and markWord.inline.hpp
stefank
parents: 57811
diff changeset
   249
  template <typename KlassProxy>
9bb28ccc6106 8229839: Break circular dependency between oop.inline.hpp and markWord.inline.hpp
stefank
parents: 57811
diff changeset
   250
  inline bool must_be_preserved(KlassProxy klass) const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  // Should this header (including its age bits) be preserved in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  // case of a promotion failure during scavenge?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  // Note that we special case this situation. We want to avoid
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  // calling BiasedLocking::preserve_marks()/restore_marks() (which
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  // decrease the number of mark words that need to be preserved
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  // during GC) during each scavenge. During scavenges in which there
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  // is no promotion failure, we actually don't need to call the above
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  // routines at all, since we don't mutate and re-initialize the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  // marks of promoted objects using init_mark(). However, during
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  // scavenges which result in promotion failure, we do re-initialize
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  // the mark words of objects, meaning that we should have called
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  // these mark word preservation routines. Currently there's no good
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  // place in which to call them in any of the scavengers (although
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  // guarded by appropriate locks we could make one), but the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  // observation is that promotion failures are quite rare and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  // reducing the number of mark words preserved during them isn't a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  // high priority.
57812
9bb28ccc6106 8229839: Break circular dependency between oop.inline.hpp and markWord.inline.hpp
stefank
parents: 57811
diff changeset
   269
  template <typename KlassProxy>
9bb28ccc6106 8229839: Break circular dependency between oop.inline.hpp and markWord.inline.hpp
stefank
parents: 57811
diff changeset
   270
  inline bool must_be_preserved_for_promotion_failure(KlassProxy klass) const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  // Should this header be preserved during a scavenge where CMS is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  // the old generation?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  // (This is basically the same body as must_be_preserved_for_promotion_failure(),
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 8921
diff changeset
   275
  // but takes the Klass* as argument instead)
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 8921
diff changeset
   276
  inline bool must_be_preserved_for_cms_scavenge(Klass* klass_of_obj_containing_mark) const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  // WARNING: The following routines are used EXCLUSIVELY by
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  // synchronization functions. They are not really gc safe.
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   280
  // They must get updated if markWord layout get changed.
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   281
  markWord set_unlocked() const {
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   282
    return markWord(value() | unlocked_value);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  bool has_locker() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    return ((value() & lock_mask_in_place) == locked_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  BasicLock* locker() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
    assert(has_locker(), "check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
    return (BasicLock*) value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  bool has_monitor() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
    return ((value() & monitor_value) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  ObjectMonitor* monitor() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
    assert(has_monitor(), "check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
    // Use xor instead of &~ to provide one extra tag-bit check.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
    return (ObjectMonitor*) (value() ^ monitor_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  bool has_displaced_mark_helper() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    return ((value() & unlocked_value) == 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  }
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   302
  markWord displaced_mark_helper() const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
    assert(has_displaced_mark_helper(), "check");
57959
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   304
    uintptr_t ptr = (value() & ~monitor_value);
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   305
    return *(markWord*)ptr;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  }
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   307
  void set_displaced_mark_helper(markWord m) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    assert(has_displaced_mark_helper(), "check");
57959
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   309
    uintptr_t ptr = (value() & ~monitor_value);
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   310
    ((markWord*)ptr)->_value = m._value;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  }
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   312
  markWord copy_set_hash(intptr_t hash) const {
57959
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   313
    uintptr_t tmp = value() & (~hash_mask_in_place);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
    tmp |= ((hash & hash_mask) << hash_shift);
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   315
    return markWord(tmp);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  // it is only used to be stored into BasicLock as the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  // indicator that the lock is using heavyweight monitor
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   319
  static markWord unused_mark() {
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   320
    return markWord(marked_value);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  }
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   322
  // the following two functions create the markWord to be
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  // stored into object header, it encodes monitor info
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   324
  static markWord encode(BasicLock* lock) {
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   325
    return from_pointer(lock);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  }
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   327
  static markWord encode(ObjectMonitor* monitor) {
57959
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   328
    uintptr_t tmp = (uintptr_t) monitor;
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   329
    return markWord(tmp | monitor_value);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  }
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   331
  static markWord encode(JavaThread* thread, uint age, int bias_epoch) {
57959
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   332
    uintptr_t tmp = (uintptr_t) thread;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
    assert(UseBiasedLocking && ((tmp & (epoch_mask_in_place | age_mask_in_place | biased_lock_mask_in_place)) == 0), "misaligned JavaThread pointer");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
    assert(age <= max_age, "age too large");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
    assert(bias_epoch <= max_bias_epoch, "bias epoch too large");
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   336
    return markWord(tmp | (bias_epoch << epoch_shift) | (age << age_shift) | biased_lock_pattern);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  // used to encode pointers during GC
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   340
  markWord clear_lock_bits() { return markWord(value() & ~lock_mask_in_place); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
  // age operations
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   343
  markWord set_marked()   { return markWord((value() & ~lock_mask_in_place) | marked_value); }
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   344
  markWord set_unmarked() { return markWord((value() & ~lock_mask_in_place) | unlocked_value); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   346
  uint     age()           const { return mask_bits(value() >> age_shift, age_mask); }
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   347
  markWord set_age(uint v) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
    assert((v & ~age_mask) == 0, "shouldn't overflow age field");
57959
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   349
    return markWord((value() & ~age_mask_in_place) | ((v & age_mask) << age_shift));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  }
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   351
  markWord incr_age()      const { return age() == max_age ? markWord(_value) : set_age(age() + 1); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  // hash operations
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  intptr_t hash() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
    return mask_bits(value() >> hash_shift, hash_mask);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  bool has_no_hash() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
    return hash() == no_hash;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  // Prototype mark for initialization
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   363
  static markWord prototype() {
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   364
    return markWord( no_hash_in_place | no_lock_in_place );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  // Helper function for restoration of unmarked mark oops during GC
57812
9bb28ccc6106 8229839: Break circular dependency between oop.inline.hpp and markWord.inline.hpp
stefank
parents: 57811
diff changeset
   368
  static inline markWord prototype_for_klass(const Klass* klass);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  // Debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
  void print_on(outputStream* st) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  // Prepare address of oop for placement into mark
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   374
  inline static markWord encode_pointer_as_mark(void* p) { return from_pointer(p).set_marked(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  // Recover address of oop from encoded form used in mark
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   377
  inline void* decode_pointer() { if (UseBiasedLocking && has_bias_pattern()) return NULL; return (void*)clear_lock_bits().value(); }
221
ec745a0fe922 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 1
diff changeset
   378
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   379
  // These markWords indicate cms free chunk blocks and not objects.
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   380
  // In 64 bit, the markWord is set to distinguish them from oops.
613
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   381
  // These are defined in 32 bit mode for vmStructs.
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   382
  const static uintptr_t cms_free_chunk_pattern  = 0x1;
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   383
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   384
  // Constants for the size field.
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   385
  enum { size_shift                = cms_shift + cms_bits,
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   386
         size_bits                 = 35    // need for compressed oops 32G
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   387
       };
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   388
  // These values are too big for Win64
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   389
  const static uintptr_t size_mask = LP64_ONLY(right_n_bits(size_bits))
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   390
                                     NOT_LP64(0);
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   391
  const static uintptr_t size_mask_in_place =
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   392
                                     (address_word)size_mask << size_shift;
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   393
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   394
#ifdef _LP64
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   395
  static markWord cms_free_prototype() {
57959
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   396
    return markWord((prototype().value() & ~cms_mask_in_place) |
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   397
                    ((cms_free_chunk_pattern & cms_mask) << cms_shift));
613
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   398
  }
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   399
  uintptr_t cms_encoding() const {
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   400
    return mask_bits(value() >> cms_shift, cms_mask);
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   401
  }
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   402
  bool is_cms_free_chunk() const {
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   403
    return is_neutral() &&
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   404
           (cms_encoding() & cms_free_chunk_pattern) == cms_free_chunk_pattern;
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   405
  }
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   406
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   407
  size_t get_size() const       { return (size_t)(value() >> size_shift); }
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   408
  static markWord set_size_and_free(size_t size) {
613
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   409
    assert((size & ~size_mask) == 0, "shouldn't overflow size field");
57959
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   410
    return markWord((cms_free_prototype().value() & ~size_mask_in_place) |
6b539901e79e 8230203: Replace markWord enums with typed constants
stefank
parents: 57875
diff changeset
   411
                    ((size & size_mask) << size_shift));
613
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   412
  }
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   413
#endif // _LP64
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   415
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   416
// Support atomic operations.
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   417
template<>
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   418
struct PrimitiveConversions::Translate<markWord> : public TrueType {
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   419
  typedef markWord Value;
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   420
  typedef uintptr_t Decayed;
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   421
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   422
  static Decayed decay(const Value& x) { return x.value(); }
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   423
  static Value recover(Decayed x) { return Value(x); }
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   424
};
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 54335
diff changeset
   425
57811
947252a54b98 8229838: Rename markOop files to markWord
stefank
parents: 57777
diff changeset
   426
#endif // SHARE_OOPS_MARKWORD_HPP