markOop.hpp revision 1472
1472N/A * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A// The markOop describes the header of an object. 0N/A// Note that the mark is not a real oop but just a word. 0N/A// It is placed in the oop hierarchy for historical reasons. 1466N/A// Bit-format of an object header (most significant first, big endian layout below): 1466N/A// hash:25 ------------>| age:4 biased_lock:1 lock:2 (normal object) 1466N/A// JavaThread*:23 epoch:2 age:4 biased_lock:1 lock:2 (biased object) 1466N/A// size:32 ------------------------------------------>| (CMS free block) 1466N/A// PromotedObject*:29 ---------->| promo_bits:3 ----->| (CMS promoted object) 1466N/A// unused:25 hash:31 -->| unused:1 age:4 biased_lock:1 lock:2 (normal object) 1466N/A// JavaThread*:54 epoch:2 unused:1 age:4 biased_lock:1 lock:2 (biased object) 1466N/A// PromotedObject*:61 --------------------->| promo_bits:3 ----->| (CMS promoted object) 1466N/A// size:64 ----------------------------------------------------->| (CMS free block) 1466N/A// unused:25 hash:31 -->| cms_free:1 age:4 biased_lock:1 lock:2 (COOPs && normal object) 1466N/A// JavaThread*:54 epoch:2 cms_free:1 age:4 biased_lock:1 lock:2 (COOPs && biased object) 1466N/A// narrowOop:32 unused:24 cms_free:1 unused:4 promo_bits:3 ----->| (COOPs && CMS promoted object) 1466N/A// unused:21 size:35 -->| cms_free:1 unused:7 ------------------>| (COOPs && CMS free block) 0N/A// - hash contains the identity hash value: largest value is 0N/A// 31 bits, see os::random(). Also, 64-bit vm's require 0N/A// a hash value no bigger than 32 bits because they will not 0N/A// - the biased lock pattern is used to bias a lock toward a given 0N/A// thread. When this pattern is set in the low three bits, the lock 0N/A// is either biased toward a given thread or "anonymously" biased, 0N/A// indicating that it is possible for it to be biased. When the 0N/A// lock is biased toward a given thread, locking and unlocking can 0N/A// be performed by that thread without using atomic operations. 0N/A// When a lock's bias is revoked, it reverts back to the normal 0N/A// locking scheme described below. 0N/A// Note that we are overloading the meaning of the "unlocked" state 0N/A// of the header. Because we steal a bit from the age we can 0N/A// guarantee that the bias pattern will never be seen for a truly 0N/A// Note also that the biased state contains the age bits normally 0N/A// contained in the object header. Large increases in scavenge 0N/A// times were seen when these bits were absent and an arbitrary age 0N/A// assigned to all biased objects, because they tended to consume a 0N/A// significant fraction of the eden semispaces and were not 0N/A// promoted promptly, causing an increase in the amount of copying 0N/A// performed. The runtime system aligns all JavaThread* pointers to 1466N/A// a very large value (currently 128 bytes (32bVM) or 256 bytes (64bVM)) 1466N/A// to make room for the age bits & the epoch bits (used in support of 1466N/A// biased locking), and for the CMS "freeness" bit in the 64bVM (+COOPs). 0N/A// [JavaThread* | epoch | age | 1 | 01] lock is biased toward given thread 0N/A// [0 | epoch | age | 1 | 01] lock is anonymously biased 0N/A// - the two lock bits are used to describe three states: locked/unlocked and monitor. 0N/A// [ptr | 00] locked ptr points to real header on stack 0N/A// [header | 0 | 01] unlocked regular object header 0N/A// [ptr | 10] monitor inflated lock (header is wapped out) 0N/A// [ptr | 11] marked used by markSweep to mark an object 0N/A// not valid at any other time 0N/A// We assume that stack/thread pointers have the lowest two bits cleared. 0N/A // The biased locking code currently requires that the age bits be 0N/A // contiguous to the lock bits. Class data sharing would prefer the 0N/A // hash bits to be lower down to provide more random hash codes for 0N/A // shared read-only symbolOop objects, because these objects' mark 0N/A // words are set to their own address with marked_value in the lock 0N/A // bit, and using lower bits would make their identity hash values 0N/A // more random. However, the performance decision was made in favor 0N/A // of the biased locking code. 0N/A // Alignment of JavaThread pointers encoded in object header required by biased locking 0N/A // These values are too big for Win64 0N/A // Biased Locking accessors. 0N/A // These must be checked by all code which calls into the 0N/A // ObjectSynchronizer and other code. The biasing is not understood 0N/A // by the lower-level CAS-based locking code, although the runtime 0N/A // fixes up biased locks to be compatible with it when a bias is 0N/A // Indicates that the mark has the bias bit set but that it has not 0N/A // yet been biased toward a particular thread 0N/A // Indicates epoch in which this bias was acquired. If the epoch 0N/A // changes due to too many bias revocations occurring, the biases 0N/A // from the previous epochs are all considered invalid. 0N/A // Prototype mark for initialization 0N/A // lock accessors (note that these assume lock_shift == 0) 0N/A // Special temporary state of the markOop while being inflated. 0N/A // Code that looks at mark outside a lock need to take this into account. 0N/A // Distinguished markword value - used when inflating over 0N/A // an existing stacklock. 0 indicates the markword is "BUSY". 0N/A // Lockword mutators that use a LD...CAS idiom should always 0N/A // check for and avoid overwriting a 0 value installed by some 0N/A // other thread. (They should spin or block instead. The 0 value 0N/A // is transient and *should* be short-lived). 0N/A // Should this header be preserved during GC? 0N/A // Should this header (including its age bits) be preserved in the 0N/A // case of a promotion failure during scavenge? 0N/A // Note that we special case this situation. We want to avoid 0N/A // calling BiasedLocking::preserve_marks()/restore_marks() (which 0N/A // decrease the number of mark words that need to be preserved 0N/A // during GC) during each scavenge. During scavenges in which there 0N/A // is no promotion failure, we actually don't need to call the above 0N/A // routines at all, since we don't mutate and re-initialize the 0N/A // marks of promoted objects using init_mark(). However, during 0N/A // scavenges which result in promotion failure, we do re-initialize 0N/A // the mark words of objects, meaning that we should have called 0N/A // these mark word preservation routines. Currently there's no good 0N/A // place in which to call them in any of the scavengers (although 0N/A // guarded by appropriate locks we could make one), but the 0N/A // observation is that promotion failures are quite rare and 0N/A // reducing the number of mark words preserved during them isn't a 0N/A // Should this header be preserved during a scavenge where CMS is 0N/A // the old generation? 0N/A // (This is basically the same body as must_be_preserved_for_promotion_failure(), 0N/A // but takes the klassOop as argument instead) 0N/A // WARNING: The following routines are used EXCLUSIVELY by 0N/A // synchronization functions. They are not really gc safe. 0N/A // They must get updated if markOop layout get changed. 0N/A // Use xor instead of &~ to provide one extra tag-bit check. 0N/A // it is only used to be stored into BasicLock as the 0N/A // indicator that the lock is using heavyweight monitor 0N/A // the following two functions create the markOop to be 0N/A // stored into object header, it encodes monitor info 0N/A // used to encode pointers during GC 0N/A // Prototype mark for initialization 0N/A // Helper function for restoration of unmarked mark oops during GC 0N/A // Prepare address of oop for placement into mark 0N/A // Recover address of oop from encoded form used in mark 187N/A // These markOops indicate cms free chunk blocks and not objects. 187N/A // In 64 bit, the markOop is set to distinguish them from oops. 187N/A // These are defined in 32 bit mode for vmStructs. 187N/A // Constants for the size field. 187N/A // These values are too big for Win64