comparison src/share/vm/utilities/globalDefinitions.hpp @ 14412:e2722a66aba7

Merge
author kvn
date Thu, 05 Sep 2013 11:04:39 -0700
parents bdd155477289 4c84d351cca9
children 2b8e28fdf503
comparison
equal deleted inserted replaced
14411:bdd155477289 14412:e2722a66aba7
363 const int KlassAlignment = KlassAlignmentInBytes / HeapWordSize; 363 const int KlassAlignment = KlassAlignmentInBytes / HeapWordSize;
364 364
365 // Klass encoding metaspace max size 365 // Klass encoding metaspace max size
366 const uint64_t KlassEncodingMetaspaceMax = (uint64_t(max_juint) + 1) << LogKlassAlignmentInBytes; 366 const uint64_t KlassEncodingMetaspaceMax = (uint64_t(max_juint) + 1) << LogKlassAlignmentInBytes;
367 367
368 const jlong CompressedKlassPointersBase = NOT_LP64(0) LP64_ONLY(CONST64(0x800000000)); // 32*G
369
368 // Machine dependent stuff 370 // Machine dependent stuff
369 371
370 #ifdef TARGET_ARCH_x86 372 #ifdef TARGET_ARCH_x86
371 # include "globalDefinitions_x86.hpp" 373 # include "globalDefinitions_x86.hpp"
372 #endif 374 #endif
401 // for use in places like enum definitions that require compile-time constant 403 // for use in places like enum definitions that require compile-time constant
402 // expressions and a function for all other places so as to get type checking. 404 // expressions and a function for all other places so as to get type checking.
403 405
404 #define align_size_up_(size, alignment) (((size) + ((alignment) - 1)) & ~((alignment) - 1)) 406 #define align_size_up_(size, alignment) (((size) + ((alignment) - 1)) & ~((alignment) - 1))
405 407
408 inline bool is_size_aligned(size_t size, size_t alignment) {
409 return align_size_up_(size, alignment) == size;
410 }
411
412 inline bool is_ptr_aligned(void* ptr, size_t alignment) {
413 return align_size_up_((intptr_t)ptr, (intptr_t)alignment) == (intptr_t)ptr;
414 }
415
406 inline intptr_t align_size_up(intptr_t size, intptr_t alignment) { 416 inline intptr_t align_size_up(intptr_t size, intptr_t alignment) {
407 return align_size_up_(size, alignment); 417 return align_size_up_(size, alignment);
408 } 418 }
409 419
410 #define align_size_down_(size, alignment) ((size) & ~((alignment) - 1)) 420 #define align_size_down_(size, alignment) ((size) & ~((alignment) - 1))
411 421
412 inline intptr_t align_size_down(intptr_t size, intptr_t alignment) { 422 inline intptr_t align_size_down(intptr_t size, intptr_t alignment) {
413 return align_size_down_(size, alignment); 423 return align_size_down_(size, alignment);
414 } 424 }
415 425
426 #define is_size_aligned_(size, alignment) ((size) == (align_size_up_(size, alignment)))
427
428 inline void* align_ptr_up(void* ptr, size_t alignment) {
429 return (void*)align_size_up((intptr_t)ptr, (intptr_t)alignment);
430 }
431
432 inline void* align_ptr_down(void* ptr, size_t alignment) {
433 return (void*)align_size_down((intptr_t)ptr, (intptr_t)alignment);
434 }
435
416 // Align objects by rounding up their size, in HeapWord units. 436 // Align objects by rounding up their size, in HeapWord units.
417 437
418 #define align_object_size_(size) align_size_up_(size, MinObjAlignment) 438 #define align_object_size_(size) align_size_up_(size, MinObjAlignment)
419 439
420 inline intptr_t align_object_size(intptr_t size) { 440 inline intptr_t align_object_size(intptr_t size) {
427 447
428 // Pad out certain offsets to jlong alignment, in HeapWord units. 448 // Pad out certain offsets to jlong alignment, in HeapWord units.
429 449
430 inline intptr_t align_object_offset(intptr_t offset) { 450 inline intptr_t align_object_offset(intptr_t offset) {
431 return align_size_up(offset, HeapWordsPerLong); 451 return align_size_up(offset, HeapWordsPerLong);
452 }
453
454 inline void* align_pointer_up(const void* addr, size_t size) {
455 return (void*) align_size_up_((uintptr_t)addr, size);
432 } 456 }
433 457
434 // Clamp an address to be within a specific page 458 // Clamp an address to be within a specific page
435 // 1. If addr is on the page it is returned as is 459 // 1. If addr is on the page it is returned as is
436 // 2. If addr is above the page_address the start of the *next* page will be returned 460 // 2. If addr is above the page_address the start of the *next* page will be returned
450 474
451 475
452 // The expected size in bytes of a cache line, used to pad data structures. 476 // The expected size in bytes of a cache line, used to pad data structures.
453 #define DEFAULT_CACHE_LINE_SIZE 64 477 #define DEFAULT_CACHE_LINE_SIZE 64
454 478
455 // Bytes needed to pad type to avoid cache-line sharing; alignment should be the
456 // expected cache line size (a power of two). The first addend avoids sharing
457 // when the start address is not a multiple of alignment; the second maintains
458 // alignment of starting addresses that happen to be a multiple.
459 #define PADDING_SIZE(type, alignment) \
460 ((alignment) + align_size_up_(sizeof(type), alignment))
461
462 // Templates to create a subclass padded to avoid cache line sharing. These are
463 // effective only when applied to derived-most (leaf) classes.
464
465 // When no args are passed to the base ctor.
466 template <class T, size_t alignment = DEFAULT_CACHE_LINE_SIZE>
467 class Padded: public T {
468 private:
469 char _pad_buf_[PADDING_SIZE(T, alignment)];
470 };
471
472 // When either 0 or 1 args may be passed to the base ctor.
473 template <class T, typename Arg1T, size_t alignment = DEFAULT_CACHE_LINE_SIZE>
474 class Padded01: public T {
475 public:
476 Padded01(): T() { }
477 Padded01(Arg1T arg1): T(arg1) { }
478 private:
479 char _pad_buf_[PADDING_SIZE(T, alignment)];
480 };
481 479
482 //---------------------------------------------------------------------------------------------------- 480 //----------------------------------------------------------------------------------------------------
483 // Utility macros for compilers 481 // Utility macros for compilers
484 // used to silence compiler warnings 482 // used to silence compiler warnings
485 483