< prev index next >

src/share/vm/utilities/globalDefinitions.hpp

Print this page




 189  private:
 190   char* i;
 191 };
 192 
 193 // HeapWordSize must be 2^LogHeapWordSize.
 194 const int HeapWordSize        = sizeof(HeapWord);
 195 #ifdef _LP64
 196 const int LogHeapWordSize     = 3;
 197 #else
 198 const int LogHeapWordSize     = 2;
 199 #endif
 200 const int HeapWordsPerLong    = BytesPerLong / HeapWordSize;
 201 const int LogHeapWordsPerLong = LogBytesPerLong - LogHeapWordSize;
 202 
 203 // The larger HeapWordSize for 64bit requires larger heaps
 204 // for the same application running in 64bit.  See bug 4967770.
 205 // The minimum alignment to a heap word size is done.  Other
 206 // parts of the memory system may require additional alignment
 207 // and are responsible for those alignments.
 208 #ifdef _LP64
 209 #define ScaleForWordSize(x) align_size_down_((x) * 13 / 10, HeapWordSize)
 210 #else
 211 #define ScaleForWordSize(x) (x)
 212 #endif
 213 
 214 // The minimum number of native machine words necessary to contain "byte_size"
 215 // bytes.
 216 inline size_t heap_word_size(size_t byte_size) {
 217   return (byte_size + (HeapWordSize-1)) >> LogHeapWordSize;
 218 }
 219 
 220 //-------------------------------------------
 221 // Constant for jlong (standardized by C++11)
 222 
 223 // Build a 64bit integer constant
 224 #define CONST64(x)  (x ## LL)
 225 #define UCONST64(x) (x ## ULL)
 226 
 227 const jlong min_jlong = CONST64(0x8000000000000000);
 228 const jlong max_jlong = CONST64(0x7fffffffffffffff);
 229 


 497 #endif
 498 
 499 // The byte alignment to be used by Arena::Amalloc.  See bugid 4169348.
 500 // Note: this value must be a power of 2
 501 
 502 #define ARENA_AMALLOC_ALIGNMENT (2*BytesPerWord)
 503 
 504 // Signed variants of alignment helpers.  There are two versions of each, a macro
 505 // for use in places like enum definitions that require compile-time constant
 506 // expressions and a function for all other places so as to get type checking.
 507 
 508 // Using '(what) & ~align_mask(alignment)' to align 'what' down is broken when
 509 // 'alignment' is an unsigned int and 'what' is a wider type. The & operation
 510 // will widen the inverted mask, and not sign extend it, leading to a mask with
 511 // zeros in the most significant bits. The use of align_mask_widened() solves
 512 // this problem.
 513 #define align_mask(alignment) ((alignment) - 1)
 514 #define widen_to_type_of(what, type_carrier) (true ? (what) : (type_carrier))
 515 #define align_mask_widened(alignment, type_carrier) widen_to_type_of(align_mask(alignment), (type_carrier))
 516 
 517 #define align_size_down_(size, alignment) ((size) & ~align_mask_widened((alignment), (size)))
 518 
 519 #define align_size_up_(size, alignment) (align_size_down_((size) + align_mask(alignment), (alignment)))
 520 
 521 #define is_size_aligned_(size, alignment) ((size) == (align_size_up_(size, alignment)))
 522 
 523 // Helpers to align sizes and check for alignment
 524 
 525 template <typename T, typename A>
 526 inline T align_size_up(T size, A alignment) {
 527   return align_size_up_(size, alignment);
 528 }
 529 
 530 template <typename T, typename A>
 531 inline T align_size_down(T size, A alignment) {
 532   return align_size_down_(size, alignment);
 533 }
 534 
 535 template <typename T, typename A>
 536 inline bool is_size_aligned(T size, A alignment) {
 537   return is_size_aligned_(size, alignment);
 538 }
 539 
 540 // Align down with a lower bound. If the aligning results in 0, return 'alignment'.
 541 template <typename T, typename A>
 542 inline T align_size_down_bounded(T size, A alignment) {
 543   A aligned_size = align_size_down(size, alignment);
 544   return aligned_size > 0 ? aligned_size : alignment;
 545 }
 546 
 547 // Helpers to align pointers and check for alignment.
 548 
 549 template <typename T, typename A>
 550 inline T* align_ptr_up(T* ptr, A alignment) {
 551   return (T*)align_size_up((uintptr_t)ptr, alignment);
 552 }
 553 
 554 template <typename T, typename A>
 555 inline T* align_ptr_down(T* ptr, A alignment) {
 556   return (T*)align_size_down((uintptr_t)ptr, alignment);
 557 }
 558 
 559 template <typename T, typename A>
 560 inline bool is_ptr_aligned(T* ptr, A alignment) {
 561   return is_size_aligned((uintptr_t)ptr, alignment);
 562 }
 563 
 564 // Align metaspace objects by rounding up to natural word boundary
 565 template <typename T>
 566 inline T align_metadata_size(T size) {
 567   return align_size_up(size, 1);
 568 }
 569 
 570 // Align objects in the Java Heap by rounding up their size, in HeapWord units.
 571 template <typename T>
 572 inline T align_object_size(T word_size) {
 573   return align_size_up(word_size, MinObjAlignment);
 574 }
 575 
 576 inline bool is_object_aligned(size_t word_size) {
 577   return is_size_aligned(word_size, MinObjAlignment);
 578 }
 579 
 580 inline bool is_ptr_object_aligned(const void* addr) {
 581   return is_ptr_aligned(addr, MinObjAlignmentInBytes);
 582 }
 583 
 584 // Pad out certain offsets to jlong alignment, in HeapWord units.
 585 template <typename T>
 586 inline T align_object_offset(T offset) {
 587   return align_size_up(offset, HeapWordsPerLong);
 588 }
 589 
 590 // Clamp an address to be within a specific page
 591 // 1. If addr is on the page it is returned as is
 592 // 2. If addr is above the page_address the start of the *next* page will be returned
 593 // 3. Otherwise, if addr is below the page_address the start of the page will be returned
 594 template <typename T>
 595 inline T* clamp_address_in_page(T* addr, T* page_address, size_t page_size) {
 596   if (align_ptr_down(addr, page_size) == align_ptr_down(page_address, page_size)) {
 597     // address is in the specified page, just return it as is
 598     return addr;
 599   } else if (addr > page_address) {
 600     // address is above specified page, return start of next page
 601     return align_ptr_down(page_address, page_size) + page_size;
 602   } else {
 603     // address is below specified page, return start of page
 604     return align_ptr_down(page_address, page_size);
 605   }
 606 }
 607 
 608 
 609 // The expected size in bytes of a cache line, used to pad data structures.
 610 #ifndef DEFAULT_CACHE_LINE_SIZE
 611   #define DEFAULT_CACHE_LINE_SIZE 64
 612 #endif
 613 
 614 
 615 //----------------------------------------------------------------------------------------------------
 616 // Utility macros for compilers
 617 // used to silence compiler warnings
 618 
 619 #define Unused_Variable(var) var
 620 
 621 
 622 //----------------------------------------------------------------------------------------------------
 623 // Miscellaneous
 624 




 189  private:
 190   char* i;
 191 };
 192 
 193 // HeapWordSize must be 2^LogHeapWordSize.
 194 const int HeapWordSize        = sizeof(HeapWord);
 195 #ifdef _LP64
 196 const int LogHeapWordSize     = 3;
 197 #else
 198 const int LogHeapWordSize     = 2;
 199 #endif
 200 const int HeapWordsPerLong    = BytesPerLong / HeapWordSize;
 201 const int LogHeapWordsPerLong = LogBytesPerLong - LogHeapWordSize;
 202 
 203 // The larger HeapWordSize for 64bit requires larger heaps
 204 // for the same application running in 64bit.  See bug 4967770.
 205 // The minimum alignment to a heap word size is done.  Other
 206 // parts of the memory system may require additional alignment
 207 // and are responsible for those alignments.
 208 #ifdef _LP64
 209 #define ScaleForWordSize(x) align_down_((x) * 13 / 10, HeapWordSize)
 210 #else
 211 #define ScaleForWordSize(x) (x)
 212 #endif
 213 
 214 // The minimum number of native machine words necessary to contain "byte_size"
 215 // bytes.
 216 inline size_t heap_word_size(size_t byte_size) {
 217   return (byte_size + (HeapWordSize-1)) >> LogHeapWordSize;
 218 }
 219 
 220 //-------------------------------------------
 221 // Constant for jlong (standardized by C++11)
 222 
 223 // Build a 64bit integer constant
 224 #define CONST64(x)  (x ## LL)
 225 #define UCONST64(x) (x ## ULL)
 226 
 227 const jlong min_jlong = CONST64(0x8000000000000000);
 228 const jlong max_jlong = CONST64(0x7fffffffffffffff);
 229 


 497 #endif
 498 
 499 // The byte alignment to be used by Arena::Amalloc.  See bugid 4169348.
 500 // Note: this value must be a power of 2
 501 
 502 #define ARENA_AMALLOC_ALIGNMENT (2*BytesPerWord)
 503 
 504 // Signed variants of alignment helpers.  There are two versions of each, a macro
 505 // for use in places like enum definitions that require compile-time constant
 506 // expressions and a function for all other places so as to get type checking.
 507 
 508 // Using '(what) & ~align_mask(alignment)' to align 'what' down is broken when
 509 // 'alignment' is an unsigned int and 'what' is a wider type. The & operation
 510 // will widen the inverted mask, and not sign extend it, leading to a mask with
 511 // zeros in the most significant bits. The use of align_mask_widened() solves
 512 // this problem.
 513 #define align_mask(alignment) ((alignment) - 1)
 514 #define widen_to_type_of(what, type_carrier) (true ? (what) : (type_carrier))
 515 #define align_mask_widened(alignment, type_carrier) widen_to_type_of(align_mask(alignment), (type_carrier))
 516 
 517 #define align_down_(size, alignment) ((size) & ~align_mask_widened((alignment), (size)))
 518 
 519 #define align_up_(size, alignment) (align_down_((size) + align_mask(alignment), (alignment)))
 520 
 521 #define is_aligned_(size, alignment) ((size) == (align_up_(size, alignment)))
 522 
 523 // Helpers to align sizes and check for alignment
 524 
 525 template <typename T, typename A>
 526 inline T align_up(T size, A alignment) {
 527   return align_up_(size, alignment);
 528 }
 529 
 530 template <typename T, typename A>
 531 inline T align_down(T size, A alignment) {
 532   return align_down_(size, alignment);
 533 }
 534 
 535 template <typename T, typename A>
 536 inline bool is_aligned(T size, A alignment) {
 537   return is_aligned_(size, alignment);
 538 }
 539 
 540 // Align down with a lower bound. If the aligning results in 0, return 'alignment'.
 541 template <typename T, typename A>
 542 inline T align_down_bounded(T size, A alignment) {
 543   A aligned_size = align_down(size, alignment);
 544   return aligned_size > 0 ? aligned_size : alignment;
 545 }
 546 
 547 // Helpers to align pointers and check for alignment.
 548 
 549 template <typename T, typename A>
 550 inline T* align_up(T* ptr, A alignment) {
 551   return (T*)align_up((uintptr_t)ptr, alignment);
 552 }
 553 
 554 template <typename T, typename A>
 555 inline T* align_down(T* ptr, A alignment) {
 556   return (T*)align_down((uintptr_t)ptr, alignment);
 557 }
 558 
 559 template <typename T, typename A>
 560 inline bool is_aligned(T* ptr, A alignment) {
 561   return is_aligned((uintptr_t)ptr, alignment);
 562 }
 563 
 564 // Align metaspace objects by rounding up to natural word boundary
 565 template <typename T>
 566 inline T align_metadata_size(T size) {
 567   return align_up(size, 1);
 568 }
 569 
 570 // Align objects in the Java Heap by rounding up their size, in HeapWord units.
 571 template <typename T>
 572 inline T align_object_size(T word_size) {
 573   return align_up(word_size, MinObjAlignment);
 574 }
 575 
 576 inline bool is_object_aligned(size_t word_size) {
 577   return is_aligned(word_size, MinObjAlignment);
 578 }
 579 
 580 inline bool is_object_aligned(const void* addr) {
 581   return is_aligned(addr, MinObjAlignmentInBytes);
 582 }
 583 
 584 // Pad out certain offsets to jlong alignment, in HeapWord units.
 585 template <typename T>
 586 inline T align_object_offset(T offset) {
 587   return align_up(offset, HeapWordsPerLong);
 588 }
 589 
 590 // Clamp an address to be within a specific page
 591 // 1. If addr is on the page it is returned as is
 592 // 2. If addr is above the page_address the start of the *next* page will be returned
 593 // 3. Otherwise, if addr is below the page_address the start of the page will be returned
 594 template <typename T>
 595 inline T* clamp_address_in_page(T* addr, T* page_address, size_t page_size) {
 596   if (align_down(addr, page_size) == align_down(page_address, page_size)) {
 597     // address is in the specified page, just return it as is
 598     return addr;
 599   } else if (addr > page_address) {
 600     // address is above specified page, return start of next page
 601     return align_down(page_address, page_size) + page_size;
 602   } else {
 603     // address is below specified page, return start of page
 604     return align_down(page_address, page_size);
 605   }
 606 }
 607 
 608 
 609 // The expected size in bytes of a cache line, used to pad data structures.
 610 #ifndef DEFAULT_CACHE_LINE_SIZE
 611   #define DEFAULT_CACHE_LINE_SIZE 64
 612 #endif
 613 
 614 
 615 //----------------------------------------------------------------------------------------------------
 616 // Utility macros for compilers
 617 // used to silence compiler warnings
 618 
 619 #define Unused_Variable(var) var
 620 
 621 
 622 //----------------------------------------------------------------------------------------------------
 623 // Miscellaneous
 624 


< prev index next >