markOop.hpp revision 1466
2362N/A * Copyright 1997-2008 Sun Microsystems, Inc. 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 2362N/A * published by the Free Software Foundation. 2362N/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. 0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 0N/A * CA 95054 USA or visit www.sun.com if you need additional information or 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. 0N/A// Bit-format of an object header (most significant first, big endian layout below): 0N/A// hash:25 ------------>| age:4 biased_lock:1 lock:2 (normal object) 0N/A// JavaThread*:23 epoch:2 age:4 biased_lock:1 lock:2 (biased object) 0N/A// size:32 ------------------------------------------>| (CMS free block) 0N/A// PromotedObject*:29 ---------->| promo_bits:3 ----->| (CMS promoted object) 0N/A// unused:25 hash:31 -->| unused:1 age:4 biased_lock:1 lock:2 (normal object) 0N/A// JavaThread*:54 epoch:2 unused:1 age:4 biased_lock:1 lock:2 (biased object) 0N/A// PromotedObject*:61 --------------------->| promo_bits:3 ----->| (CMS promoted object) 0N/A// size:64 ----------------------------------------------------->| (CMS free block) 0N/A// unused:25 hash:31 -->| cms_free:1 age:4 biased_lock:1 lock:2 (COOPs && normal object) 0N/A// JavaThread*:54 epoch:2 cms_free:1 age:4 biased_lock:1 lock:2 (COOPs && biased object) 0N/A// narrowOop:32 unused:24 cms_free:1 unused:4 promo_bits:3 ----->| (COOPs && CMS promoted object) 0N/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 4632N/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 // contained in the object header. Large increases in scavenge // times were seen when these bits were absent and an arbitrary age // assigned to all biased objects, because they tended to consume a // significant fraction of the eden semispaces and were not // promoted promptly, causing an increase in the amount of copying // performed. The runtime system aligns all JavaThread* pointers to // a very large value (currently 128 bytes (32bVM) or 256 bytes (64bVM)) // to make room for the age bits & the epoch bits (used in support of // biased locking), and for the CMS "freeness" bit in the 64bVM (+COOPs). // [JavaThread* | epoch | age | 1 | 01] lock is biased toward given thread // [0 | epoch | age | 1 | 01] lock is anonymously biased // - the two lock bits are used to describe three states: locked/unlocked and monitor. // [ptr | 00] locked ptr points to real header on stack // [header | 0 | 01] unlocked regular object header // [ptr | 10] monitor inflated lock (header is wapped out) // [ptr | 11] marked used by markSweep to mark an object // not valid at any other time // We assume that stack/thread pointers have the lowest two bits cleared. // The biased locking code currently requires that the age bits be // contiguous to the lock bits. Class data sharing would prefer the // hash bits to be lower down to provide more random hash codes for // shared read-only symbolOop objects, because these objects' mark // words are set to their own address with marked_value in the lock // bit, and using lower bits would make their identity hash values // more random. However, the performance decision was made in favor // of the biased locking code. // Alignment of JavaThread pointers encoded in object header required by biased locking // These values are too big for Win64 enum {
no_hash = 0 };
// no hash value assigned // Biased Locking accessors. // These must be checked by all code which calls into the // ObjectSynchronizer and other code. The biasing is not understood // by the lower-level CAS-based locking code, although the runtime // fixes up biased locks to be compatible with it when a bias is // Indicates that the mark has the bias bit set but that it has not // yet been biased toward a particular thread // Indicates epoch in which this bias was acquired. If the epoch // changes due to too many bias revocations occurring, the biases // from the previous epochs are all considered invalid. // Prototype mark for initialization // lock accessors (note that these assume lock_shift == 0) // Special temporary state of the markOop while being inflated. // Code that looks at mark outside a lock need to take this into account. // Distinguished markword value - used when inflating over // an existing stacklock. 0 indicates the markword is "BUSY". // Lockword mutators that use a LD...CAS idiom should always // check for and avoid overwriting a 0 value installed by some // other thread. (They should spin or block instead. The 0 value // is transient and *should* be short-lived). // Should this header be preserved during GC? // Should this header (including its age bits) be preserved in the // case of a promotion failure during scavenge? // Note that we special case this situation. We want to avoid // calling BiasedLocking::preserve_marks()/restore_marks() (which // decrease the number of mark words that need to be preserved // during GC) during each scavenge. During scavenges in which there // is no promotion failure, we actually don't need to call the above // routines at all, since we don't mutate and re-initialize the // marks of promoted objects using init_mark(). However, during // scavenges which result in promotion failure, we do re-initialize // the mark words of objects, meaning that we should have called // these mark word preservation routines. Currently there's no good // place in which to call them in any of the scavengers (although // guarded by appropriate locks we could make one), but the // observation is that promotion failures are quite rare and // reducing the number of mark words preserved during them isn't a // Should this header be preserved during a scavenge where CMS is // (This is basically the same body as must_be_preserved_for_promotion_failure(), // but takes the klassOop as argument instead) // WARNING: The following routines are used EXCLUSIVELY by // synchronization functions. They are not really gc safe. // They must get updated if markOop layout get changed. // Use xor instead of &~ to provide one extra tag-bit check. // it is only used to be stored into BasicLock as the // indicator that the lock is using heavyweight monitor // the following two functions create the markOop to be // stored into object header, it encodes monitor info // used to encode pointers during GC // Prototype mark for initialization // Helper function for restoration of unmarked mark oops during GC // Prepare address of oop for placement into mark // Recover address of oop from encoded form used in mark // see the definition in markOop.cpp for the gory details // These markOops indicate cms free chunk blocks and not objects. // In 64 bit, the markOop is set to distinguish them from oops. // These are defined in 32 bit mode for vmStructs. // Constants for the size field. size_bits =
35 // need for compressed oops 32G // These values are too big for Win64