Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/gc_implementation/parallelScavenge/objectStartArray.hpp
38920 views
/*1* Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_OBJECTSTARTARRAY_HPP25#define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_OBJECTSTARTARRAY_HPP2627#include "gc_implementation/parallelScavenge/psVirtualspace.hpp"28#include "memory/allocation.hpp"29#include "memory/memRegion.hpp"30#include "oops/oop.hpp"3132//33// This class can be used to locate the beginning of an object in the34// covered region.35//3637class ObjectStartArray : public CHeapObj<mtGC> {38friend class VerifyObjectStartArrayClosure;3940private:41PSVirtualSpace _virtual_space;42MemRegion _reserved_region;43MemRegion _covered_region;44MemRegion _blocks_region;45jbyte* _raw_base;46jbyte* _offset_base;4748public:4950enum BlockValueConstants {51clean_block = -152};5354enum BlockSizeConstants {55block_shift = 9,56block_size = 1 << block_shift,57block_size_in_words = block_size / sizeof(HeapWord)58};5960protected:6162// Mapping from address to object start array entry63jbyte* block_for_addr(void* p) const {64assert(_covered_region.contains(p),65"out of bounds access to object start array");66jbyte* result = &_offset_base[uintptr_t(p) >> block_shift];67assert(_blocks_region.contains(result),68"out of bounds result in byte_for");69return result;70}7172// Mapping from object start array entry to address of first word73HeapWord* addr_for_block(jbyte* p) {74assert(_blocks_region.contains(p),75"out of bounds access to object start array");76size_t delta = pointer_delta(p, _offset_base, sizeof(jbyte));77HeapWord* result = (HeapWord*) (delta << block_shift);78assert(_covered_region.contains(result),79"out of bounds accessor from card marking array");80return result;81}8283// Mapping that includes the derived offset.84// If the block is clean, returns the last address in the covered region.85// If the block is < index 0, returns the start of the covered region.86HeapWord* offset_addr_for_block (jbyte* p) const {87// We have to do this before the assert88if (p < _raw_base) {89return _covered_region.start();90}9192assert(_blocks_region.contains(p),93"out of bounds access to object start array");9495if (*p == clean_block) {96return _covered_region.end();97}9899size_t delta = pointer_delta(p, _offset_base, sizeof(jbyte));100HeapWord* result = (HeapWord*) (delta << block_shift);101result += *p;102103assert(_covered_region.contains(result),104"out of bounds accessor from card marking array");105106return result;107}108109public:110111// This method is in lieu of a constructor, so that this class can be112// embedded inline in other classes.113void initialize(MemRegion reserved_region);114115void set_covered_region(MemRegion mr);116117void reset();118119MemRegion covered_region() { return _covered_region; }120121void allocate_block(HeapWord* p) {122assert(_covered_region.contains(p), "Must be in covered region");123jbyte* block = block_for_addr(p);124HeapWord* block_base = addr_for_block(block);125size_t offset = pointer_delta(p, block_base, sizeof(HeapWord*));126assert(offset < 128, "Sanity");127// When doing MT offsets, we can't assert this.128//assert(offset > *block, "Found backwards allocation");129*block = (jbyte)offset;130131// tty->print_cr("[%p]", p);132}133134// Optimized for finding the first object that crosses into135// a given block. The blocks contain the offset of the last136// object in that block. Scroll backwards by one, and the first137// object hit should be at the beginning of the block138HeapWord* object_start(HeapWord* addr) const {139assert(_covered_region.contains(addr), "Must be in covered region");140jbyte* block = block_for_addr(addr);141HeapWord* scroll_forward = offset_addr_for_block(block--);142while (scroll_forward > addr) {143scroll_forward = offset_addr_for_block(block--);144}145146HeapWord* next = scroll_forward;147while (next <= addr) {148scroll_forward = next;149next += oop(next)->size();150}151assert(scroll_forward <= addr, "wrong order for current and arg");152assert(addr <= next, "wrong order for arg and next");153return scroll_forward;154}155156bool is_block_allocated(HeapWord* addr) {157assert(_covered_region.contains(addr), "Must be in covered region");158jbyte* block = block_for_addr(addr);159if (*block == clean_block)160return false;161162return true;163}164165// Return true if an object starts in the range of heap addresses.166// If an object starts at an address corresponding to167// "start", the method will return true.168bool object_starts_in_range(HeapWord* start_addr, HeapWord* end_addr) const;169};170171#endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_OBJECTSTARTARRAY_HPP172173174