1 /* 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_VM_OOPS_MARKOOP_HPP 26 #define SHARE_VM_OOPS_MARKOOP_HPP 27 28 #include "oops/oop.hpp" 29 30 // The markOop describes the header of an object. 31 // 32 // Note that the mark is not a real oop but just a word. 33 // It is placed in the oop hierarchy for historical reasons. 34 // 35 // Bit-format of an object header (most significant first, big endian layout below): 36 // 37 // 32 bits: 38 // -------- 39 // hash:25 ------------>| age:4 biased_lock:1 lock:2 (normal object) 40 // JavaThread*:23 epoch:2 age:4 biased_lock:1 lock:2 (biased object) 41 // size:32 ------------------------------------------>| (CMS free block) 42 // PromotedObject*:29 ---------->| promo_bits:3 ----->| (CMS promoted object) 43 // 44 // 64 bits: 45 // -------- 46 // unused:25 hash:31 -->| unused:1 age:4 biased_lock:1 lock:2 (normal object) 47 // JavaThread*:54 epoch:2 unused:1 age:4 biased_lock:1 lock:2 (biased object) 48 // PromotedObject*:61 --------------------->| promo_bits:3 ----->| (CMS promoted object) 49 // size:64 ----------------------------------------------------->| (CMS free block) 50 // 51 // unused:25 hash:31 -->| cms_free:1 age:4 biased_lock:1 lock:2 (COOPs && normal object) 52 // JavaThread*:54 epoch:2 cms_free:1 age:4 biased_lock:1 lock:2 (COOPs && biased object) 53 // narrowOop:32 unused:24 cms_free:1 unused:4 promo_bits:3 ----->| (COOPs && CMS promoted object) 54 // unused:21 size:35 -->| cms_free:1 unused:7 ------------------>| (COOPs && CMS free block) 55 // 56 // - hash contains the identity hash value: largest value is 57 // 31 bits, see os::random(). Also, 64-bit vm's require 58 // a hash value no bigger than 32 bits because they will not 59 // properly generate a mask larger than that: see library_call.cpp 60 // and c1_CodePatterns_sparc.cpp. 61 // 62 // - the biased lock pattern is used to bias a lock toward a given 63 // thread. When this pattern is set in the low three bits, the lock 64 // is either biased toward a given thread or "anonymously" biased, 65 // indicating that it is possible for it to be biased. When the 66 // lock is biased toward a given thread, locking and unlocking can 67 // be performed by that thread without using atomic operations. 68 // When a lock's bias is revoked, it reverts back to the normal 69 // locking scheme described below. 70 // 71 // Note that we are overloading the meaning of the "unlocked" state 72 // of the header. Because we steal a bit from the age we can 73 // guarantee that the bias pattern will never be seen for a truly 74 // unlocked object. 75 // 76 // Note also that the biased state contains the age bits normally 77 // contained in the object header. Large increases in scavenge 78 // times were seen when these bits were absent and an arbitrary age 79 // assigned to all biased objects, because they tended to consume a 80 // significant fraction of the eden semispaces and were not 81 // promoted promptly, causing an increase in the amount of copying 82 // performed. The runtime system aligns all JavaThread* pointers to 83 // a very large value (currently 128 bytes (32bVM) or 256 bytes (64bVM)) 84 // to make room for the age bits & the epoch bits (used in support of 85 // biased locking), and for the CMS "freeness" bit in the 64bVM (+COOPs). 86 // 87 // [JavaThread* | epoch | age | 1 | 01] lock is biased toward given thread 88 // [0 | epoch | age | 1 | 01] lock is anonymously biased 89 // 90 // - the two lock bits are used to describe three states: locked/unlocked and monitor. 91 // 92 // [ptr | 00] locked ptr points to real header on stack 93 // [header | 0 | 01] unlocked regular object header 94 // [ptr | 10] monitor inflated lock (header is wapped out) 95 // [ptr | 11] marked used by markSweep to mark an object 96 // not valid at any other time 97 // 98 // We assume that stack/thread pointers have the lowest two bits cleared. 99 100 class BasicLock; 101 class ObjectMonitor; 102 class JavaThread; 103 104 class markOopDesc: public oopDesc { 105 private: 106 // Conversion 107 uintptr_t value() const { return (uintptr_t) this; } 108 109 public: 110 // Constants 111 enum { age_bits = 4, 112 lock_bits = 2, 113 biased_lock_bits = 1, 114 max_hash_bits = BitsPerWord - age_bits - lock_bits - biased_lock_bits, 115 hash_bits = max_hash_bits > 31 ? 31 : max_hash_bits, 116 cms_bits = LP64_ONLY(1) NOT_LP64(0), 117 epoch_bits = 2 118 }; 119 120 // The biased locking code currently requires that the age bits be 121 // contiguous to the lock bits. 122 enum { lock_shift = 0, 123 biased_lock_shift = lock_bits, 124 age_shift = lock_bits + biased_lock_bits, 125 cms_shift = age_shift + age_bits, 126 hash_shift = cms_shift + cms_bits, 127 epoch_shift = hash_shift 128 }; 129 130 enum { lock_mask = right_n_bits(lock_bits), 131 lock_mask_in_place = lock_mask << lock_shift, 132 biased_lock_mask = right_n_bits(lock_bits + biased_lock_bits), 133 biased_lock_mask_in_place= biased_lock_mask << lock_shift, 134 biased_lock_bit_in_place = 1 << biased_lock_shift, 135 age_mask = right_n_bits(age_bits), 136 age_mask_in_place = age_mask << age_shift, 137 epoch_mask = right_n_bits(epoch_bits), 138 epoch_mask_in_place = epoch_mask << epoch_shift, 139 cms_mask = right_n_bits(cms_bits), 140 cms_mask_in_place = cms_mask << cms_shift 141 #ifndef _WIN64 142 ,hash_mask = right_n_bits(hash_bits), 143 hash_mask_in_place = (address_word)hash_mask << hash_shift 144 #endif 145 }; 146 147 // Alignment of JavaThread pointers encoded in object header required by biased locking 148 enum { biased_lock_alignment = 2 << (epoch_shift + epoch_bits) 149 }; 150 151 #ifdef _WIN64 152 // These values are too big for Win64 153 const static uintptr_t hash_mask = right_n_bits(hash_bits); 154 const static uintptr_t hash_mask_in_place = 155 (address_word)hash_mask << hash_shift; 156 #endif 157 158 enum { locked_value = 0, 159 unlocked_value = 1, 160 monitor_value = 2, 161 marked_value = 3, 162 biased_lock_pattern = 5 163 }; 164 165 enum { no_hash = 0 }; // no hash value assigned 166 167 enum { no_hash_in_place = (address_word)no_hash << hash_shift, 168 no_lock_in_place = unlocked_value | 1 /* 2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_VM_OOPS_MARKOOP_HPP 26 #define SHARE_VM_OOPS_MARKOOP_HPP 27 28 #include "oops/oop.hpp" 29 30 // The markOop describes the header of an object. 31 // 32 // Note that the mark is not a real oop but just a word. 33 // It is placed in the oop hierarchy for historical reasons. 34 // 35 // Bit-format of an object header (most significant first, big endian layout below): 36 // 37 // 32 bits: 38 // -------- 39 // hash:24 ------------>| age:5 biased_lock:1 lock:2 (normal object) 40 // JavaThread*:22 epoch:2 age:5 biased_lock:1 lock:2 (biased object) 41 // size:32 ------------------------------------------>| (CMS free block) 42 // PromotedObject*:29 ---------->| promo_bits:3 ----->| (CMS promoted object) 43 // 44 // 64 bits: 45 // -------- 46 // unused:24 hash:31 -->| unused:1 age:5 biased_lock:1 lock:2 (normal object) 47 // JavaThread*:53 epoch:2 unused:1 age:5 biased_lock:1 lock:2 (biased object) 48 // PromotedObject*:61 --------------------->| promo_bits:3 ----->| (CMS promoted object) 49 // size:64 ----------------------------------------------------->| (CMS free block) 50 // 51 // unused:24 hash:31 -->| cms_free:1 age:5 biased_lock:1 lock:2 (COOPs && normal object) 52 // JavaThread*:53 epoch:2 cms_free:1 age:5 biased_lock:1 lock:2 (COOPs && biased object) 53 // narrowOop:32 unused:23 cms_free:1 unused:5 promo_bits:3 ----->| (COOPs && CMS promoted object) 54 // unused:20 size:35 -->| cms_free:1 unused:8 ------------------>| (COOPs && CMS free block) 55 // 56 // - hash contains the identity hash value: largest value is 57 // 31 bits, see os::random(). Also, 64-bit vm's require 58 // a hash value no bigger than 32 bits because they will not 59 // properly generate a mask larger than that: see library_call.cpp 60 // and c1_CodePatterns_sparc.cpp. 61 // 62 // - the biased lock pattern is used to bias a lock toward a given 63 // thread. When this pattern is set in the low three bits, the lock 64 // is either biased toward a given thread or "anonymously" biased, 65 // indicating that it is possible for it to be biased. When the 66 // lock is biased toward a given thread, locking and unlocking can 67 // be performed by that thread without using atomic operations. 68 // When a lock's bias is revoked, it reverts back to the normal 69 // locking scheme described below. 70 // 71 // Note that we are overloading the meaning of the "unlocked" state 72 // of the header. Because we steal a bit from the age we can 73 // guarantee that the bias pattern will never be seen for a truly 74 // unlocked object. 75 // 76 // Note also that the biased state contains the age bits normally 77 // contained in the object header. Large increases in scavenge 78 // times were seen when these bits were absent and an arbitrary age 79 // assigned to all biased objects, because they tended to consume a 80 // significant fraction of the eden semispaces and were not 81 // promoted promptly, causing an increase in the amount of copying 82 // performed. The runtime system aligns all JavaThread* pointers to 83 // a very large value (currently 1024 bytes (32bVM) or 2048 bytes (64bVM)) 84 // to make room for the age bits & the epoch bits (used in support of 85 // biased locking), and for the CMS "freeness" bit in the 64bVM (+COOPs). 86 // 87 // [JavaThread* | epoch | age | 1 | 01] lock is biased toward given thread 88 // [0 | epoch | age | 1 | 01] lock is anonymously biased 89 // 90 // - the two lock bits are used to describe three states: locked/unlocked and monitor. 91 // 92 // [ptr | 00] locked ptr points to real header on stack 93 // [header | 0 | 01] unlocked regular object header 94 // [ptr | 10] monitor inflated lock (header is wapped out) 95 // [ptr | 11] marked used by markSweep to mark an object 96 // not valid at any other time 97 // 98 // We assume that stack/thread pointers have the lowest two bits cleared. 99 100 class BasicLock; 101 class ObjectMonitor; 102 class JavaThread; 103 104 class markOopDesc: public oopDesc { 105 private: 106 // Conversion 107 uintptr_t value() const { return (uintptr_t) this; } 108 109 public: 110 // Constants 111 enum { age_bits = 5, 112 lock_bits = 2, 113 biased_lock_bits = 1, 114 max_hash_bits = BitsPerWord - age_bits - lock_bits - biased_lock_bits, 115 hash_bits = max_hash_bits > 31 ? 31 : max_hash_bits, 116 cms_bits = LP64_ONLY(1) NOT_LP64(0), 117 epoch_bits = 2 118 }; 119 120 // The biased locking code currently requires that the age bits be 121 // contiguous to the lock bits. 122 enum { lock_shift = 0, 123 biased_lock_shift = lock_bits, 124 age_shift = lock_bits + biased_lock_bits, 125 cms_shift = age_shift + age_bits, 126 hash_shift = cms_shift + cms_bits, 127 epoch_shift = hash_shift 128 }; 129 130 enum { lock_mask = right_n_bits(lock_bits), 131 lock_mask_in_place = lock_mask << lock_shift, 132 biased_lock_mask = right_n_bits(lock_bits + biased_lock_bits), 133 biased_lock_mask_in_place= biased_lock_mask << lock_shift, 134 biased_lock_bit_in_place = 1 << biased_lock_shift, 135 age_mask = right_n_bits(age_bits), 136 age_mask_in_place = age_mask << age_shift, 137 epoch_mask = right_n_bits(epoch_bits), 138 epoch_mask_in_place = epoch_mask << epoch_shift, 139 cms_mask = right_n_bits(cms_bits), 140 cms_mask_in_place = cms_mask << cms_shift 141 #ifndef _WIN64 142 ,hash_mask = right_n_bits(hash_bits), 143 hash_mask_in_place = (address_word)hash_mask << hash_shift 144 #endif 145 }; 146 147 // Alignment of JavaThread pointers encoded in object header required by biased locking 148 enum { biased_lock_alignment = 1 << (epoch_shift + epoch_bits) 149 }; 150 151 #ifdef _WIN64 152 // These values are too big for Win64 153 const static uintptr_t hash_mask = right_n_bits(hash_bits); 154 const static uintptr_t hash_mask_in_place = 155 (address_word)hash_mask << hash_shift; 156 #endif 157 158 enum { locked_value = 0, 159 unlocked_value = 1, 160 monitor_value = 2, 161 marked_value = 3, 162 biased_lock_pattern = 5 163 }; 164 165 enum { no_hash = 0 }; // no hash value assigned 166 167 enum { no_hash_in_place = (address_word)no_hash << hash_shift, 168 no_lock_in_place = unlocked_value |