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

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 1
2d8a650513c2
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial