Path: blob/master/src/hotspot/share/gc/parallel/objectStartArray.hpp
41149 views
/*1* Copyright (c) 2001, 2019, 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_GC_PARALLEL_OBJECTSTARTARRAY_HPP25#define SHARE_GC_PARALLEL_OBJECTSTARTARRAY_HPP2627#include "gc/parallel/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; }120121#define assert_covered_region_contains(addr) \122assert(_covered_region.contains(addr), \123#addr " (" PTR_FORMAT ") is not in covered region [" PTR_FORMAT ", " PTR_FORMAT "]", \124p2i(addr), p2i(_covered_region.start()), p2i(_covered_region.end()))125126void allocate_block(HeapWord* p) {127assert_covered_region_contains(p);128jbyte* block = block_for_addr(p);129HeapWord* block_base = addr_for_block(block);130size_t offset = pointer_delta(p, block_base, sizeof(HeapWord*));131assert(offset < 128, "Sanity");132// When doing MT offsets, we can't assert this.133//assert(offset > *block, "Found backwards allocation");134*block = (jbyte)offset;135}136137// Optimized for finding the first object that crosses into138// a given block. The blocks contain the offset of the last139// object in that block. Scroll backwards by one, and the first140// object hit should be at the beginning of the block141inline HeapWord* object_start(HeapWord* addr) const;142143bool is_block_allocated(HeapWord* addr) {144assert_covered_region_contains(addr);145jbyte* block = block_for_addr(addr);146return *block != clean_block;147}148149// Return true if an object starts in the range of heap addresses.150// If an object starts at an address corresponding to151// "start", the method will return true.152bool object_starts_in_range(HeapWord* start_addr, HeapWord* end_addr) const;153};154155#endif // SHARE_GC_PARALLEL_OBJECTSTARTARRAY_HPP156157158