annotate src/share/vm/gc_implementation/parallelScavenge/objectStartArray.hpp @ 6197:d2a62e0f25eb

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