void G1PageBasedVirtualSpace::initialize_with_page_size(ReservedSpace rs, size_t used_size, size_t page_size) { guarantee(rs.is_reserved(), "Given reserved space must have been reserved already."); vmassert(_low_boundary == NULL, "VirtualSpace already initialized"); vmassert(page_size > 0, "Page size must be non-zero."); guarantee(is_ptr_aligned(rs.base(), page_size), "Reserved space base " PTR_FORMAT " is not aligned to requested page size " SIZE_FORMAT, p2i(rs.base()), page_size); guarantee(is_size_aligned(used_size, os::vm_page_size()), "Given used reserved space size needs to be OS page size aligned (%d bytes) but is " SIZE_FORMAT, os::vm_page_size(), used_size); guarantee(used_size <= rs.size(), "Used size of reserved space " SIZE_FORMAT " bytes is smaller than reservation at " SIZE_FORMAT " bytes", used_size, rs.size()); guarantee(is_size_aligned(rs.size(), page_size), "Expected that the virtual space is size aligned, but " SIZE_FORMAT " is not aligned to page size " SIZE_FORMAT, rs.size(), page_size); _low_boundary = rs.base(); _high_boundary = _low_boundary + used_size; _special = rs.special(); _executable = rs.executable(); _page_size = page_size; vmassert(_committed.size() == 0, "virtual space initialized more than once"); BitMap::idx_t size_in_pages = rs.size() / page_size; _committed.initialize(size_in_pages); if (_special) { _dirty.initialize(size_in_pages); } _tail_size = used_size % _page_size; }
bool is_ptr_aligned_nz (const T *ptr, int align) { assert (align > 0); assert ((align & -align) == align); return (ptr != 0 && is_ptr_aligned (ptr, align)); }
HeapWord* ContiguousSpace::allocate_aligned(size_t size) { assert(Heap_lock->owned_by_self() || (SafepointSynchronize::is_at_safepoint() && Thread::current()->is_VM_thread()), "not locked"); HeapWord* end_value = end(); HeapWord* obj = CollectedHeap::align_allocation_or_fail(top(), end_value, SurvivorAlignmentInBytes); if (obj == NULL) { return NULL; } if (pointer_delta(end_value, obj) >= size) { HeapWord* new_top = obj + size; set_top(new_top); assert(is_ptr_aligned(obj, SurvivorAlignmentInBytes) && is_aligned(new_top), "checking alignment"); return obj; } else { set_top(obj); return NULL; } }
HeapWord* PSYoungPromotionLAB::allocate(size_t size) { // Can't assert this, when young fills, we keep the LAB around, but flushed. // assert(_state != flushed, "Sanity"); HeapWord* obj = CollectedHeap::align_allocation_or_fail(top(), end(), SurvivorAlignmentInBytes); if (obj == NULL) { return NULL; } HeapWord* new_top = obj + size; // The 'new_top>obj' check is needed to detect overflow of obj+size. if (new_top > obj && new_top <= end()) { set_top(new_top); assert(is_ptr_aligned(obj, SurvivorAlignmentInBytes) && is_object_aligned((intptr_t)new_top), "checking alignment"); return obj; } else { set_top(obj); return NULL; } }
// Is the last page only partially covered by this space? bool is_last_page_partial() const { return !is_ptr_aligned(_high_boundary, _page_size); }