hotspot/src/share/vm/oops/markOop.hpp
author ysr
Thu, 12 Jun 2008 13:50:55 -0700
changeset 1376 f7fc7a708b63
parent 1374 4c24294029a9
parent 613 2aa2b913106c
child 1388 3677f5f3d66b
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
// The markOop describes the header of an object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
// Note that the mark is not a real oop but just a word.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// It is placed in the oop hierarchy for historical reasons.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// Bit-format of an object header (most significant first):
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
//
613
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
    32
//  32 bits: unused:0  hash:25 age:4 biased_lock:1 lock:2
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
    33
//  64 bits: unused:24 hash:31 cms:2 age:4 biased_lock:1 lock:2
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
    34
//           unused:20 size:35 cms:2 age:4 biased_lock:1 lock:2 (if cms
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
    35
//                                                               free chunk)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
//  - hash contains the identity hash value: largest value is
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
//    31 bits, see os::random().  Also, 64-bit vm's require
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
//    a hash value no bigger than 32 bits because they will not
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
//    properly generate a mask larger than that: see library_call.cpp
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
//    and c1_CodePatterns_sparc.cpp.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
//  - the biased lock pattern is used to bias a lock toward a given
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
//    thread. When this pattern is set in the low three bits, the lock
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
//    is either biased toward a given thread or "anonymously" biased,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
//    indicating that it is possible for it to be biased. When the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
//    lock is biased toward a given thread, locking and unlocking can
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
//    be performed by that thread without using atomic operations.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
//    When a lock's bias is revoked, it reverts back to the normal
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
//    locking scheme described below.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
//    Note that we are overloading the meaning of the "unlocked" state
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
//    of the header. Because we steal a bit from the age we can
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
//    guarantee that the bias pattern will never be seen for a truly
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
//    unlocked object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
//    Note also that the biased state contains the age bits normally
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
//    contained in the object header. Large increases in scavenge
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
//    times were seen when these bits were absent and an arbitrary age
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
//    assigned to all biased objects, because they tended to consume a
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
//    significant fraction of the eden semispaces and were not
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
//    promoted promptly, causing an increase in the amount of copying
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
//    performed. The runtime system aligns all JavaThread* pointers to
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
//    a very large value (currently 128 bytes) to make room for the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
//    age bits when biased locking is enabled.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
//    [JavaThread* | epoch | age | 1 | 01]       lock is biased toward given thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
//    [0           | epoch | age | 1 | 01]       lock is anonymously biased
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
//  - the two lock bits are used to describe three states: locked/unlocked and monitor.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
//    [ptr             | 00]  locked             ptr points to real header on stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
//    [header      | 0 | 01]  unlocked           regular object header
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
//    [ptr             | 10]  monitor            inflated lock (header is wapped out)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
//    [ptr             | 11]  marked             used by markSweep to mark an object
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
//                                               not valid at any other time
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
//    We assume that stack/thread pointers have the lowest two bits cleared.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
class BasicLock;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
class ObjectMonitor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
class JavaThread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
class markOopDesc: public oopDesc {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  // Conversion
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  uintptr_t value() const { return (uintptr_t) this; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  // Constants
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  enum { age_bits                 = 4,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
         lock_bits                = 2,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
         biased_lock_bits         = 1,
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 221
diff changeset
    94
         max_hash_bits            = BitsPerWord - age_bits - lock_bits - biased_lock_bits,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
         hash_bits                = max_hash_bits > 31 ? 31 : max_hash_bits,
613
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
    96
         cms_bits                 = LP64_ONLY(1) NOT_LP64(0),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
         epoch_bits               = 2
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  // The biased locking code currently requires that the age bits be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  // contiguous to the lock bits. Class data sharing would prefer the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  // hash bits to be lower down to provide more random hash codes for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  // shared read-only symbolOop objects, because these objects' mark
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  // words are set to their own address with marked_value in the lock
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  // bit, and using lower bits would make their identity hash values
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  // more random. However, the performance decision was made in favor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  // of the biased locking code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  enum { lock_shift               = 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
         biased_lock_shift        = lock_bits,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
         age_shift                = lock_bits + biased_lock_bits,
613
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   112
         cms_shift                = age_shift + age_bits,
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   113
         hash_shift               = cms_shift + cms_bits,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
         epoch_shift              = hash_shift
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  enum { lock_mask                = right_n_bits(lock_bits),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
         lock_mask_in_place       = lock_mask << lock_shift,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
         biased_lock_mask         = right_n_bits(lock_bits + biased_lock_bits),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
         biased_lock_mask_in_place= biased_lock_mask << lock_shift,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
         biased_lock_bit_in_place = 1 << biased_lock_shift,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
         age_mask                 = right_n_bits(age_bits),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
         age_mask_in_place        = age_mask << age_shift,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
         epoch_mask               = right_n_bits(epoch_bits),
613
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   125
         epoch_mask_in_place      = epoch_mask << epoch_shift,
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   126
         cms_mask                 = right_n_bits(cms_bits),
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   127
         cms_mask_in_place        = cms_mask << cms_shift
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
#ifndef _WIN64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
         ,hash_mask               = right_n_bits(hash_bits),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
         hash_mask_in_place       = (address_word)hash_mask << hash_shift
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  // Alignment of JavaThread pointers encoded in object header required by biased locking
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  enum { biased_lock_alignment    = 2 << (epoch_shift + epoch_bits)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
#ifdef _WIN64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    // These values are too big for Win64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    const static uintptr_t hash_mask = right_n_bits(hash_bits);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    const static uintptr_t hash_mask_in_place  =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
                            (address_word)hash_mask << hash_shift;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  enum { locked_value             = 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
         unlocked_value           = 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
         monitor_value            = 2,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
         marked_value             = 3,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
         biased_lock_pattern      = 5
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  enum { no_hash                  = 0 };  // no hash value assigned
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  enum { no_hash_in_place         = (address_word)no_hash << hash_shift,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
         no_lock_in_place         = unlocked_value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  enum { max_age                  = age_mask };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  enum { max_bias_epoch           = epoch_mask };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  // Biased Locking accessors.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  // These must be checked by all code which calls into the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  // ObjectSynchronizer and other code. The biasing is not understood
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  // by the lower-level CAS-based locking code, although the runtime
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  // fixes up biased locks to be compatible with it when a bias is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  // revoked.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  bool has_bias_pattern() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    return (mask_bits(value(), biased_lock_mask_in_place) == biased_lock_pattern);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  JavaThread* biased_locker() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    assert(has_bias_pattern(), "should not call this otherwise");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
    return (JavaThread*) ((intptr_t) (mask_bits(value(), ~(biased_lock_mask_in_place | age_mask_in_place | epoch_mask_in_place))));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  // Indicates that the mark has the bias bit set but that it has not
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  // yet been biased toward a particular thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  bool is_biased_anonymously() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    return (has_bias_pattern() && (biased_locker() == NULL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  // Indicates epoch in which this bias was acquired. If the epoch
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  // changes due to too many bias revocations occurring, the biases
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  // from the previous epochs are all considered invalid.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  int bias_epoch() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    assert(has_bias_pattern(), "should not call this otherwise");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    return (mask_bits(value(), epoch_mask_in_place) >> epoch_shift);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  markOop set_bias_epoch(int epoch) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    assert(has_bias_pattern(), "should not call this otherwise");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    assert((epoch & (~epoch_mask)) == 0, "epoch overflow");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    return markOop(mask_bits(value(), ~epoch_mask_in_place) | (epoch << epoch_shift));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  markOop incr_bias_epoch() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    return set_bias_epoch((1 + bias_epoch()) & epoch_mask);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  // Prototype mark for initialization
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  static markOop biased_locking_prototype() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    return markOop( biased_lock_pattern );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  // lock accessors (note that these assume lock_shift == 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  bool is_locked()   const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    return (mask_bits(value(), lock_mask_in_place) != unlocked_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  bool is_unlocked() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    return (mask_bits(value(), biased_lock_mask_in_place) == unlocked_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  bool is_marked()   const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    return (mask_bits(value(), lock_mask_in_place) == marked_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  bool is_neutral()  const { return (mask_bits(value(), biased_lock_mask_in_place) == unlocked_value); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  // Special temporary state of the markOop while being inflated.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  // Code that looks at mark outside a lock need to take this into account.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  bool is_being_inflated() const { return (value() == 0); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  // Distinguished markword value - used when inflating over
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  // an existing stacklock.  0 indicates the markword is "BUSY".
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  // Lockword mutators that use a LD...CAS idiom should always
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  // check for and avoid overwriting a 0 value installed by some
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  // other thread.  (They should spin or block instead.  The 0 value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  // is transient and *should* be short-lived).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  static markOop INFLATING() { return (markOop) 0; }    // inflate-in-progress
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  // Should this header be preserved during GC?
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   225
  inline bool must_be_preserved(oop obj_containing_mark) const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  inline bool must_be_preserved_with_bias(oop obj_containing_mark) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  // Should this header (including its age bits) be preserved in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  // case of a promotion failure during scavenge?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  // Note that we special case this situation. We want to avoid
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  // calling BiasedLocking::preserve_marks()/restore_marks() (which
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  // decrease the number of mark words that need to be preserved
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  // during GC) during each scavenge. During scavenges in which there
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  // is no promotion failure, we actually don't need to call the above
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  // routines at all, since we don't mutate and re-initialize the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  // marks of promoted objects using init_mark(). However, during
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  // scavenges which result in promotion failure, we do re-initialize
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  // the mark words of objects, meaning that we should have called
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  // these mark word preservation routines. Currently there's no good
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  // place in which to call them in any of the scavengers (although
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  // guarded by appropriate locks we could make one), but the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  // observation is that promotion failures are quite rare and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  // reducing the number of mark words preserved during them isn't a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  // high priority.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   245
  inline bool must_be_preserved_for_promotion_failure(oop obj_containing_mark) const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  inline bool must_be_preserved_with_bias_for_promotion_failure(oop obj_containing_mark) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  // Should this header be preserved during a scavenge where CMS is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  // the old generation?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  // (This is basically the same body as must_be_preserved_for_promotion_failure(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  // but takes the klassOop as argument instead)
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 360
diff changeset
   252
  inline bool must_be_preserved_for_cms_scavenge(klassOop klass_of_obj_containing_mark) const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  inline bool must_be_preserved_with_bias_for_cms_scavenge(klassOop klass_of_obj_containing_mark) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  // WARNING: The following routines are used EXCLUSIVELY by
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  // synchronization functions. They are not really gc safe.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  // They must get updated if markOop layout get changed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  markOop set_unlocked() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
    return markOop(value() | unlocked_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  bool has_locker() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
    return ((value() & lock_mask_in_place) == locked_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  BasicLock* locker() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
    assert(has_locker(), "check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    return (BasicLock*) value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  bool has_monitor() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
    return ((value() & monitor_value) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  ObjectMonitor* monitor() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    assert(has_monitor(), "check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    // Use xor instead of &~ to provide one extra tag-bit check.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    return (ObjectMonitor*) (value() ^ monitor_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  bool has_displaced_mark_helper() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
    return ((value() & unlocked_value) == 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  markOop displaced_mark_helper() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
    assert(has_displaced_mark_helper(), "check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
    intptr_t ptr = (value() & ~monitor_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
    return *(markOop*)ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  void set_displaced_mark_helper(markOop m) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    assert(has_displaced_mark_helper(), "check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    intptr_t ptr = (value() & ~monitor_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
    *(markOop*)ptr = m;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  markOop copy_set_hash(intptr_t hash) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
    intptr_t tmp = value() & (~hash_mask_in_place);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
    tmp |= ((hash & hash_mask) << hash_shift);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
    return (markOop)tmp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  // it is only used to be stored into BasicLock as the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  // indicator that the lock is using heavyweight monitor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  static markOop unused_mark() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
    return (markOop) marked_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  // the following two functions create the markOop to be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  // stored into object header, it encodes monitor info
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  static markOop encode(BasicLock* lock) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    return (markOop) lock;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  static markOop encode(ObjectMonitor* monitor) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    intptr_t tmp = (intptr_t) monitor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
    return (markOop) (tmp | monitor_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  static markOop encode(JavaThread* thread, int age, int bias_epoch) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
    intptr_t tmp = (intptr_t) thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
    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
   311
    assert(age <= max_age, "age too large");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
    assert(bias_epoch <= max_bias_epoch, "bias epoch too large");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
    return (markOop) (tmp | (bias_epoch << epoch_shift) | (age << age_shift) | biased_lock_pattern);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  // used to encode pointers during GC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  markOop clear_lock_bits() { return markOop(value() & ~lock_mask_in_place); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  // age operations
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  markOop set_marked()   { return markOop((value() & ~lock_mask_in_place) | marked_value); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  int     age()               const { return mask_bits(value() >> age_shift, age_mask); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  markOop set_age(int v) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
    assert((v & ~age_mask) == 0, "shouldn't overflow age field");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
    return markOop((value() & ~age_mask_in_place) | (((intptr_t)v & age_mask) << age_shift));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  markOop incr_age()          const { return age() == max_age ? markOop(this) : set_age(age() + 1); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  // hash operations
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  intptr_t hash() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
    return mask_bits(value() >> hash_shift, hash_mask);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  bool has_no_hash() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
    return hash() == no_hash;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  // Prototype mark for initialization
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  static markOop prototype() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
    return markOop( no_hash_in_place | no_lock_in_place );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  // Helper function for restoration of unmarked mark oops during GC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  static inline markOop prototype_for_object(oop obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
  // Debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  void print_on(outputStream* st) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  // Prepare address of oop for placement into mark
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  inline static markOop encode_pointer_as_mark(void* p) { return markOop(p)->set_marked(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  // Recover address of oop from encoded form used in mark
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  inline void* decode_pointer() { if (UseBiasedLocking && has_bias_pattern()) return NULL; return clear_lock_bits(); }
221
ec745a0fe922 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 1
diff changeset
   354
ec745a0fe922 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 1
diff changeset
   355
  // see the definition in markOop.cpp for the gory details
ec745a0fe922 6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
dcubed
parents: 1
diff changeset
   356
  bool should_not_be_cached() const;
613
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   357
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   358
  // These markOops indicate cms free chunk blocks and not objects.
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   359
  // In 64 bit, the markOop is set to distinguish them from oops.
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   360
  // These are defined in 32 bit mode for vmStructs.
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   361
  const static uintptr_t cms_free_chunk_pattern  = 0x1;
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   362
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   363
  // Constants for the size field.
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   364
  enum { size_shift                = cms_shift + cms_bits,
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   365
         size_bits                 = 35    // need for compressed oops 32G
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   366
       };
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   367
  // These values are too big for Win64
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   368
  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
   369
                                     NOT_LP64(0);
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   370
  const static uintptr_t size_mask_in_place =
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   371
                                     (address_word)size_mask << size_shift;
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   372
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   373
#ifdef _LP64
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   374
  static markOop cms_free_prototype() {
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   375
    return markOop(((intptr_t)prototype() & ~cms_mask_in_place) |
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   376
                   ((cms_free_chunk_pattern & cms_mask) << cms_shift));
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   377
  }
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   378
  uintptr_t cms_encoding() const {
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   379
    return mask_bits(value() >> cms_shift, cms_mask);
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   380
  }
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   381
  bool is_cms_free_chunk() const {
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   382
    return is_neutral() &&
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   383
           (cms_encoding() & cms_free_chunk_pattern) == cms_free_chunk_pattern;
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   384
  }
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   385
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   386
  size_t get_size() const       { return (size_t)(value() >> size_shift); }
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   387
  static markOop set_size_and_free(size_t size) {
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   388
    assert((size & ~size_mask) == 0, "shouldn't overflow size field");
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   389
    return markOop(((intptr_t)cms_free_prototype() & ~size_mask_in_place) |
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   390
                   (((intptr_t)size & size_mask) << size_shift));
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   391
  }
2aa2b913106c 6687581: Make CMS work with compressed oops
coleenp
parents: 360
diff changeset
   392
#endif // _LP64
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
};