511 return (volatile void*)align_size_down((intptr_t)ptr, (intptr_t)alignment); 512 } 513 514 // Align metaspace objects by rounding up to natural word boundary 515 516 inline intptr_t align_metadata_size(intptr_t size) { 517 return align_size_up(size, 1); 518 } 519 520 // Align objects in the Java Heap by rounding up their size, in HeapWord units. 521 // Since the size is given in words this is somewhat of a nop, but 522 // distinguishes it from align_object_size. 523 inline intptr_t align_object_size(intptr_t size) { 524 return align_size_up(size, MinObjAlignment); 525 } 526 527 inline bool is_object_aligned(intptr_t addr) { 528 return addr == align_object_size(addr); 529 } 530 531 // Pad out certain offsets to jlong alignment, in HeapWord units. 532 533 inline intptr_t align_object_offset(intptr_t offset) { 534 return align_size_up(offset, HeapWordsPerLong); 535 } 536 537 // Align down with a lower bound. If the aligning results in 0, return 'alignment'. 538 539 inline size_t align_size_down_bounded(size_t size, size_t alignment) { 540 size_t aligned_size = align_size_down_(size, alignment); 541 return aligned_size > 0 ? aligned_size : alignment; 542 } 543 544 // Clamp an address to be within a specific page 545 // 1. If addr is on the page it is returned as is 546 // 2. If addr is above the page_address the start of the *next* page will be returned 547 // 3. Otherwise, if addr is below the page_address the start of the page will be returned 548 inline address clamp_address_in_page(address addr, address page_address, intptr_t page_size) { 549 if (align_size_down(intptr_t(addr), page_size) == align_size_down(intptr_t(page_address), page_size)) { 550 // address is in the specified page, just return it as is | 511 return (volatile void*)align_size_down((intptr_t)ptr, (intptr_t)alignment); 512 } 513 514 // Align metaspace objects by rounding up to natural word boundary 515 516 inline intptr_t align_metadata_size(intptr_t size) { 517 return align_size_up(size, 1); 518 } 519 520 // Align objects in the Java Heap by rounding up their size, in HeapWord units. 521 // Since the size is given in words this is somewhat of a nop, but 522 // distinguishes it from align_object_size. 523 inline intptr_t align_object_size(intptr_t size) { 524 return align_size_up(size, MinObjAlignment); 525 } 526 527 inline bool is_object_aligned(intptr_t addr) { 528 return addr == align_object_size(addr); 529 } 530 531 inline bool is_ptr_object_aligned(const void* addr) { 532 return is_ptr_aligned(addr, MinObjAlignmentInBytes); 533 } 534 535 // Pad out certain offsets to jlong alignment, in HeapWord units. 536 537 inline intptr_t align_object_offset(intptr_t offset) { 538 return align_size_up(offset, HeapWordsPerLong); 539 } 540 541 // Align down with a lower bound. If the aligning results in 0, return 'alignment'. 542 543 inline size_t align_size_down_bounded(size_t size, size_t alignment) { 544 size_t aligned_size = align_size_down_(size, alignment); 545 return aligned_size > 0 ? aligned_size : alignment; 546 } 547 548 // Clamp an address to be within a specific page 549 // 1. If addr is on the page it is returned as is 550 // 2. If addr is above the page_address the start of the *next* page will be returned 551 // 3. Otherwise, if addr is below the page_address the start of the page will be returned 552 inline address clamp_address_in_page(address addr, address page_address, intptr_t page_size) { 553 if (align_size_down(intptr_t(addr), page_size) == align_size_down(intptr_t(page_address), page_size)) { 554 // address is in the specified page, just return it as is |