src/share/vm/gc_implementation/parallelScavenge/objectStartArray.hpp

Fri, 10 May 2013 08:27:30 -0700

author
minqi
date
Fri, 10 May 2013 08:27:30 -0700
changeset 5097
92ef81e2f571
parent 4153
b9a9ed0f8eeb
child 6876
710a3c8b516e
permissions
-rw-r--r--

8003557: NPG: Klass* const k should be const Klass* k.
Summary: With NPG, const KlassOop klass which is in fact a definition converted to Klass* const, which is not the original intention. The right usage is converting them to const Klass*.
Reviewed-by: coleenp, kvn
Contributed-by: yumin.qi@oracle.com

duke@435 1 /*
mikael@4153 2 * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_OBJECTSTARTARRAY_HPP
stefank@2314 26 #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_OBJECTSTARTARRAY_HPP
stefank@2314 27
stefank@2314 28 #include "gc_implementation/parallelScavenge/psVirtualspace.hpp"
stefank@2314 29 #include "memory/allocation.hpp"
stefank@2314 30 #include "memory/memRegion.hpp"
stefank@2314 31 #include "oops/oop.hpp"
stefank@2314 32
duke@435 33 //
duke@435 34 // This class can be used to locate the beginning of an object in the
duke@435 35 // covered region.
duke@435 36 //
duke@435 37
zgu@3900 38 class ObjectStartArray : public CHeapObj<mtGC> {
duke@435 39 friend class VerifyObjectStartArrayClosure;
duke@435 40
duke@435 41 private:
duke@435 42 PSVirtualSpace _virtual_space;
duke@435 43 MemRegion _reserved_region;
duke@435 44 MemRegion _covered_region;
duke@435 45 MemRegion _blocks_region;
duke@435 46 jbyte* _raw_base;
duke@435 47 jbyte* _offset_base;
duke@435 48
duke@435 49 public:
duke@435 50
duke@435 51 enum BlockValueConstants {
duke@435 52 clean_block = -1
duke@435 53 };
duke@435 54
duke@435 55 enum BlockSizeConstants {
duke@435 56 block_shift = 9,
duke@435 57 block_size = 1 << block_shift,
duke@435 58 block_size_in_words = block_size / sizeof(HeapWord)
duke@435 59 };
duke@435 60
duke@435 61 protected:
duke@435 62
duke@435 63 // Mapping from address to object start array entry
duke@435 64 jbyte* block_for_addr(void* p) const {
duke@435 65 assert(_covered_region.contains(p),
duke@435 66 "out of bounds access to object start array");
duke@435 67 jbyte* result = &_offset_base[uintptr_t(p) >> block_shift];
duke@435 68 assert(_blocks_region.contains(result),
duke@435 69 "out of bounds result in byte_for");
duke@435 70 return result;
duke@435 71 }
duke@435 72
duke@435 73 // Mapping from object start array entry to address of first word
duke@435 74 HeapWord* addr_for_block(jbyte* p) {
duke@435 75 assert(_blocks_region.contains(p),
duke@435 76 "out of bounds access to object start array");
duke@435 77 size_t delta = pointer_delta(p, _offset_base, sizeof(jbyte));
duke@435 78 HeapWord* result = (HeapWord*) (delta << block_shift);
duke@435 79 assert(_covered_region.contains(result),
duke@435 80 "out of bounds accessor from card marking array");
duke@435 81 return result;
duke@435 82 }
duke@435 83
duke@435 84 // Mapping that includes the derived offset.
duke@435 85 // If the block is clean, returns the last address in the covered region.
duke@435 86 // If the block is < index 0, returns the start of the covered region.
duke@435 87 HeapWord* offset_addr_for_block (jbyte* p) const {
duke@435 88 // We have to do this before the assert
duke@435 89 if (p < _raw_base) {
duke@435 90 return _covered_region.start();
duke@435 91 }
duke@435 92
duke@435 93 assert(_blocks_region.contains(p),
duke@435 94 "out of bounds access to object start array");
duke@435 95
duke@435 96 if (*p == clean_block) {
duke@435 97 return _covered_region.end();
duke@435 98 }
duke@435 99
duke@435 100 size_t delta = pointer_delta(p, _offset_base, sizeof(jbyte));
duke@435 101 HeapWord* result = (HeapWord*) (delta << block_shift);
duke@435 102 result += *p;
duke@435 103
duke@435 104 assert(_covered_region.contains(result),
duke@435 105 "out of bounds accessor from card marking array");
duke@435 106
duke@435 107 return result;
duke@435 108 }
duke@435 109
duke@435 110 public:
duke@435 111
duke@435 112 // This method is in lieu of a constructor, so that this class can be
duke@435 113 // embedded inline in other classes.
duke@435 114 void initialize(MemRegion reserved_region);
duke@435 115
duke@435 116 void set_covered_region(MemRegion mr);
duke@435 117
duke@435 118 void reset();
duke@435 119
duke@435 120 MemRegion covered_region() { return _covered_region; }
duke@435 121
duke@435 122 void allocate_block(HeapWord* p) {
duke@435 123 assert(_covered_region.contains(p), "Must be in covered region");
duke@435 124 jbyte* block = block_for_addr(p);
duke@435 125 HeapWord* block_base = addr_for_block(block);
duke@435 126 size_t offset = pointer_delta(p, block_base, sizeof(HeapWord*));
duke@435 127 assert(offset < 128, "Sanity");
duke@435 128 // When doing MT offsets, we can't assert this.
duke@435 129 //assert(offset > *block, "Found backwards allocation");
duke@435 130 *block = (jbyte)offset;
duke@435 131
duke@435 132 // tty->print_cr("[%p]", p);
duke@435 133 }
duke@435 134
duke@435 135 // Optimized for finding the first object that crosses into
duke@435 136 // a given block. The blocks contain the offset of the last
duke@435 137 // object in that block. Scroll backwards by one, and the first
twisti@1040 138 // object hit should be at the beginning of the block
duke@435 139 HeapWord* object_start(HeapWord* addr) const {
duke@435 140 assert(_covered_region.contains(addr), "Must be in covered region");
duke@435 141 jbyte* block = block_for_addr(addr);
duke@435 142 HeapWord* scroll_forward = offset_addr_for_block(block--);
duke@435 143 while (scroll_forward > addr) {
duke@435 144 scroll_forward = offset_addr_for_block(block--);
duke@435 145 }
duke@435 146
duke@435 147 HeapWord* next = scroll_forward;
duke@435 148 while (next <= addr) {
duke@435 149 scroll_forward = next;
duke@435 150 next += oop(next)->size();
duke@435 151 }
duke@435 152 assert(scroll_forward <= addr, "wrong order for current and arg");
duke@435 153 assert(addr <= next, "wrong order for arg and next");
duke@435 154 return scroll_forward;
duke@435 155 }
duke@435 156
duke@435 157 bool is_block_allocated(HeapWord* addr) {
duke@435 158 assert(_covered_region.contains(addr), "Must be in covered region");
duke@435 159 jbyte* block = block_for_addr(addr);
duke@435 160 if (*block == clean_block)
duke@435 161 return false;
duke@435 162
duke@435 163 return true;
duke@435 164 }
duke@435 165
duke@435 166 // Return true if an object starts in the range of heap addresses.
duke@435 167 // If an object starts at an address corresponding to
duke@435 168 // "start", the method will return true.
duke@435 169 bool object_starts_in_range(HeapWord* start_addr, HeapWord* end_addr) const;
duke@435 170 };
stefank@2314 171
stefank@2314 172 #endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_OBJECTSTARTARRAY_HPP

mercurial