|
#include "stdio.h" |
|
|
|
|
|
//from macros.hpp |
|
#ifdef _LP64 |
|
#define LP64_ONLY(code) code |
|
#define NOT_LP64(code) |
|
#else // !_LP64 |
|
#define LP64_ONLY(code) |
|
#define NOT_LP64(code) code |
|
#endif // _LP64 |
|
|
|
|
|
|
|
|
|
//from globalDefinitions_gcc.hpp |
|
typedef int intptr_t; |
|
typedef unsigned int uintptr_t; |
|
|
|
|
|
|
|
|
|
//from globalDefinitions.hpp |
|
typedef uintptr_t address_word; // unsigned integer which will hold a pointer |
|
|
|
#ifdef _LP64 |
|
const int LogBytesPerWord = 3; |
|
#else |
|
const int LogBytesPerWord = 2; |
|
#endif |
|
const int LogBitsPerByte = 3; |
|
const int LogBitsPerWord = LogBitsPerByte + LogBytesPerWord; |
|
const int BytesPerWord = 1 << LogBytesPerWord; |
|
const int BitsPerWord = 1 << LogBitsPerWord; |
|
|
|
const intptr_t OneBit = 1; // only right_most bit set in a word |
|
|
|
#define nth_bit(n) (n >= BitsPerWord ? 0 : OneBit << (n)) |
|
#define right_n_bits(n) (nth_bit(n) - 1) |
|
|
|
|
|
|
|
|
|
//from markOop.hpp |
|
enum { age_bits = 4, |
|
lock_bits = 2, |
|
biased_lock_bits = 1, |
|
max_hash_bits = BitsPerWord - age_bits - lock_bits - biased_lock_bits, |
|
hash_bits = max_hash_bits > 31 ? 31 : max_hash_bits, |
|
cms_bits = LP64_ONLY(1) NOT_LP64(0), |
|
epoch_bits = 2 |
|
}; |
|
|
|
// The biased locking code currently requires that the age bits be |
|
// contiguous to the lock bits. |
|
enum { lock_shift = 0, |
|
biased_lock_shift = lock_bits, |
|
age_shift = lock_bits + biased_lock_bits, |
|
cms_shift = age_shift + age_bits, |
|
hash_shift = cms_shift + cms_bits, |
|
epoch_shift = hash_shift |
|
}; |
|
|
|
enum { lock_mask = right_n_bits(lock_bits), |
|
lock_mask_in_place = lock_mask << lock_shift, |
|
biased_lock_mask = right_n_bits(lock_bits + biased_lock_bits), |
|
biased_lock_mask_in_place= biased_lock_mask << lock_shift, |
|
biased_lock_bit_in_place = 1 << biased_lock_shift, |
|
age_mask = right_n_bits(age_bits), |
|
age_mask_in_place = age_mask << age_shift, |
|
epoch_mask = right_n_bits(epoch_bits), |
|
epoch_mask_in_place = epoch_mask << epoch_shift, |
|
cms_mask = right_n_bits(cms_bits), |
|
cms_mask_in_place = cms_mask << cms_shift |
|
#ifndef _WIN64 |
|
,hash_mask = right_n_bits(hash_bits), |
|
hash_mask_in_place = (address_word)hash_mask << hash_shift |
|
#endif |
|
}; |
|
|
|
#ifdef _WIN64 |
|
// These values are too big for Win64 |
|
const static uintptr_t hash_mask = right_n_bits(hash_bits); |
|
const static uintptr_t hash_mask_in_place = |
|
(address_word)hash_mask << hash_shift; |
|
#endif |
|
|
|
|
|
|
|
//test |
|
int main(int argc, char* argv[]) { |
|
printf("age_bits = %d\n", age_bits); |
|
printf("lock_bits = %d\n", lock_bits); |
|
printf("biased_lock_bits = %d\n", biased_lock_bits); |
|
printf("max_hash_bits = %d\n", max_hash_bits); |
|
printf("hash_bits = %d\n", hash_bits); |
|
printf("cms_bits = %d\n", cms_bits); |
|
printf("epoch_bits = %d\n", epoch_bits); |
|
printf("\n"); |
|
|
|
printf("lock_shift = %d\n", lock_shift); |
|
printf("biased_lock_shift = %d\n", biased_lock_shift); |
|
printf("age_shift = %d\n", age_shift); |
|
printf("cms_shift = %d\n", cms_shift); |
|
printf("hash_shift = %d\n", hash_shift); |
|
printf("epoch_shift = %d\n", epoch_shift); |
|
printf("\n"); |
|
|
|
printf("lock_mask = %d\n", lock_mask); |
|
printf("lock_mask_in_place = %d\n", lock_mask_in_place); |
|
printf("biased_lock_mask = %d\n", biased_lock_mask); |
|
printf("biased_lock_bit_in_place = %d\n", biased_lock_bit_in_place); |
|
printf("age_mask = %d\n", age_mask); |
|
printf("age_mask_in_place = %d\n", age_mask_in_place); |
|
printf("epoch_mask = %d\n", epoch_mask); |
|
printf("epoch_mask_in_place = %d\n", epoch_mask_in_place); |
|
printf("cms_mask = %d\n", cms_mask); |
|
printf("cms_mask_in_place = %d\n", cms_mask_in_place); |
|
printf("hash_mask = %d\n", hash_mask); |
|
printf("hash_mask_in_place = %d\n", hash_mask_in_place); |
|
} |
|
|