annotate src/share/vm/gc_implementation/parallelScavenge/psVirtualspace.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) 2003, 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: 579
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 579
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: 579
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_PSVIRTUALSPACE_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSVIRTUALSPACE_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 "runtime/virtualspace.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29
0
a61af66fc99e Initial load
duke
parents:
diff changeset
30 // VirtualSpace for the parallel scavenge collector.
a61af66fc99e Initial load
duke
parents:
diff changeset
31 //
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // VirtualSpace is data structure for committing a previously reserved address
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // range in smaller chunks.
a61af66fc99e Initial load
duke
parents:
diff changeset
34
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
35 class PSVirtualSpace : public CHeapObj<mtGC> {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
36 friend class VMStructs;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
38 // The space is committed/uncommited in chunks of size _alignment. The
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // ReservedSpace passed to initialize() must be aligned to this value.
a61af66fc99e Initial load
duke
parents:
diff changeset
40 const size_t _alignment;
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // Reserved area
a61af66fc99e Initial load
duke
parents:
diff changeset
43 char* _reserved_low_addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 char* _reserved_high_addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // Committed area
a61af66fc99e Initial load
duke
parents:
diff changeset
47 char* _committed_low_addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 char* _committed_high_addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 // The entire space has been committed and pinned in memory, no
a61af66fc99e Initial load
duke
parents:
diff changeset
51 // os::commit_memory() or os::uncommit_memory().
a61af66fc99e Initial load
duke
parents:
diff changeset
52 bool _special;
a61af66fc99e Initial load
duke
parents:
diff changeset
53
a61af66fc99e Initial load
duke
parents:
diff changeset
54 // Convenience wrapper.
a61af66fc99e Initial load
duke
parents:
diff changeset
55 inline static size_t pointer_delta(const char* left, const char* right);
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
58 PSVirtualSpace(ReservedSpace rs, size_t alignment);
a61af66fc99e Initial load
duke
parents:
diff changeset
59 PSVirtualSpace(ReservedSpace rs);
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 ~PSVirtualSpace();
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // Eventually all instances should be created with the above 1- or 2-arg
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // constructors. Then the 1st constructor below should become protected and
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // the 2nd ctor and initialize() removed.
a61af66fc99e Initial load
duke
parents:
diff changeset
66 PSVirtualSpace(size_t alignment): _alignment(alignment) { }
a61af66fc99e Initial load
duke
parents:
diff changeset
67 PSVirtualSpace();
a61af66fc99e Initial load
duke
parents:
diff changeset
68 bool initialize(ReservedSpace rs, size_t commit_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70 bool contains(void* p) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 // Accessors (all sizes are bytes).
a61af66fc99e Initial load
duke
parents:
diff changeset
73 size_t alignment() const { return _alignment; }
a61af66fc99e Initial load
duke
parents:
diff changeset
74 char* reserved_low_addr() const { return _reserved_low_addr; }
a61af66fc99e Initial load
duke
parents:
diff changeset
75 char* reserved_high_addr() const { return _reserved_high_addr; }
a61af66fc99e Initial load
duke
parents:
diff changeset
76 char* committed_low_addr() const { return _committed_low_addr; }
a61af66fc99e Initial load
duke
parents:
diff changeset
77 char* committed_high_addr() const { return _committed_high_addr; }
a61af66fc99e Initial load
duke
parents:
diff changeset
78 bool special() const { return _special; }
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 inline size_t committed_size() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
81 inline size_t reserved_size() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
82 inline size_t uncommitted_size() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // Operations.
a61af66fc99e Initial load
duke
parents:
diff changeset
85 inline void set_reserved(char* low_addr, char* high_addr, bool special);
a61af66fc99e Initial load
duke
parents:
diff changeset
86 inline void set_reserved(ReservedSpace rs);
a61af66fc99e Initial load
duke
parents:
diff changeset
87 inline void set_committed(char* low_addr, char* high_addr);
535
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 0
diff changeset
88 virtual bool expand_by(size_t bytes);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
89 virtual bool shrink_by(size_t bytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
90 virtual size_t expand_into(PSVirtualSpace* space, size_t bytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
91 void release();
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
94 // Debugging
a61af66fc99e Initial load
duke
parents:
diff changeset
95 static bool is_aligned(size_t val, size_t align);
a61af66fc99e Initial load
duke
parents:
diff changeset
96 bool is_aligned(size_t val) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 bool is_aligned(char* val) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
98 void verify() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
99 void print() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
100 virtual bool grows_up() const { return true; }
a61af66fc99e Initial load
duke
parents:
diff changeset
101 bool grows_down() const { return !grows_up(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 // Helper class to verify a space when entering/leaving a block.
a61af66fc99e Initial load
duke
parents:
diff changeset
104 class PSVirtualSpaceVerifier: public StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
105 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
106 const PSVirtualSpace* const _space;
a61af66fc99e Initial load
duke
parents:
diff changeset
107 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
108 PSVirtualSpaceVerifier(PSVirtualSpace* space): _space(space) {
a61af66fc99e Initial load
duke
parents:
diff changeset
109 _space->verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
111 ~PSVirtualSpaceVerifier() { _space->verify(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
112 };
a61af66fc99e Initial load
duke
parents:
diff changeset
113 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 virtual void print_space_boundaries_on(outputStream* st) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 // Included for compatibility with the original VirtualSpace.
a61af66fc99e Initial load
duke
parents:
diff changeset
118 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // Committed area
a61af66fc99e Initial load
duke
parents:
diff changeset
120 char* low() const { return committed_low_addr(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
121 char* high() const { return committed_high_addr(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123 // Reserved area
a61af66fc99e Initial load
duke
parents:
diff changeset
124 char* low_boundary() const { return reserved_low_addr(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
125 char* high_boundary() const { return reserved_high_addr(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
126 };
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128 // A virtual space that grows from high addresses to low addresses.
a61af66fc99e Initial load
duke
parents:
diff changeset
129 class PSVirtualSpaceHighToLow : public PSVirtualSpace {
a61af66fc99e Initial load
duke
parents:
diff changeset
130 friend class VMStructs;
a61af66fc99e Initial load
duke
parents:
diff changeset
131 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
132 PSVirtualSpaceHighToLow(ReservedSpace rs, size_t alignment);
a61af66fc99e Initial load
duke
parents:
diff changeset
133 PSVirtualSpaceHighToLow(ReservedSpace rs);
a61af66fc99e Initial load
duke
parents:
diff changeset
134
535
4e400c36026f 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 0
diff changeset
135 virtual bool expand_by(size_t bytes);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
136 virtual bool shrink_by(size_t bytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
137 virtual size_t expand_into(PSVirtualSpace* space, size_t bytes);
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 virtual void print_space_boundaries_on(outputStream* st) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
140
a61af66fc99e Initial load
duke
parents:
diff changeset
141 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
142 // Debugging
a61af66fc99e Initial load
duke
parents:
diff changeset
143 virtual bool grows_up() const { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
144 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
145 };
a61af66fc99e Initial load
duke
parents:
diff changeset
146
a61af66fc99e Initial load
duke
parents:
diff changeset
147 //
a61af66fc99e Initial load
duke
parents:
diff changeset
148 // PSVirtualSpace inlines.
a61af66fc99e Initial load
duke
parents:
diff changeset
149 //
a61af66fc99e Initial load
duke
parents:
diff changeset
150 inline size_t
a61af66fc99e Initial load
duke
parents:
diff changeset
151 PSVirtualSpace::pointer_delta(const char* left, const char* right) {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 return ::pointer_delta((void *)left, (void*)right, sizeof(char));
a61af66fc99e Initial load
duke
parents:
diff changeset
153 }
a61af66fc99e Initial load
duke
parents:
diff changeset
154
a61af66fc99e Initial load
duke
parents:
diff changeset
155 inline size_t PSVirtualSpace::committed_size() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
156 return pointer_delta(committed_high_addr(), committed_low_addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
157 }
a61af66fc99e Initial load
duke
parents:
diff changeset
158
a61af66fc99e Initial load
duke
parents:
diff changeset
159 inline size_t PSVirtualSpace::reserved_size() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
160 return pointer_delta(reserved_high_addr(), reserved_low_addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
161 }
a61af66fc99e Initial load
duke
parents:
diff changeset
162
a61af66fc99e Initial load
duke
parents:
diff changeset
163 inline size_t PSVirtualSpace::uncommitted_size() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
164 return reserved_size() - committed_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
165 }
a61af66fc99e Initial load
duke
parents:
diff changeset
166
a61af66fc99e Initial load
duke
parents:
diff changeset
167 inline void PSVirtualSpace::set_reserved(char* low_addr, char* high_addr, bool special) {
a61af66fc99e Initial load
duke
parents:
diff changeset
168 _reserved_low_addr = low_addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
169 _reserved_high_addr = high_addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
170 _special = special;
a61af66fc99e Initial load
duke
parents:
diff changeset
171 }
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 inline void PSVirtualSpace::set_reserved(ReservedSpace rs) {
a61af66fc99e Initial load
duke
parents:
diff changeset
174 set_reserved(rs.base(), rs.base() + rs.size(), rs.special());
a61af66fc99e Initial load
duke
parents:
diff changeset
175 }
a61af66fc99e Initial load
duke
parents:
diff changeset
176
a61af66fc99e Initial load
duke
parents:
diff changeset
177 inline void PSVirtualSpace::set_committed(char* low_addr, char* high_addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
178 _committed_low_addr = low_addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
179 _committed_high_addr = high_addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
181
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
182 #endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSVIRTUALSPACE_HPP