0
|
1 /*
|
|
2 * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 *
|
|
5 * This code is free software; you can redistribute it and/or modify it
|
|
6 * under the terms of the GNU General Public License version 2 only, as
|
|
7 * published by the Free Software Foundation.
|
|
8 *
|
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 * version 2 for more details (a copy is included in the LICENSE file that
|
|
13 * accompanied this code).
|
|
14 *
|
|
15 * You should have received a copy of the GNU General Public License version
|
|
16 * 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 *
|
|
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 * have any questions.
|
|
22 *
|
|
23 */
|
|
24
|
|
25 // VirtualSpace for the parallel scavenge collector.
|
|
26 //
|
|
27 // VirtualSpace is data structure for committing a previously reserved address
|
|
28 // range in smaller chunks.
|
|
29
|
|
30 class PSVirtualSpace : public CHeapObj {
|
|
31 friend class VMStructs;
|
|
32 protected:
|
|
33 // The space is committed/uncommited in chunks of size _alignment. The
|
|
34 // ReservedSpace passed to initialize() must be aligned to this value.
|
|
35 const size_t _alignment;
|
|
36
|
|
37 // Reserved area
|
|
38 char* _reserved_low_addr;
|
|
39 char* _reserved_high_addr;
|
|
40
|
|
41 // Committed area
|
|
42 char* _committed_low_addr;
|
|
43 char* _committed_high_addr;
|
|
44
|
|
45 // The entire space has been committed and pinned in memory, no
|
|
46 // os::commit_memory() or os::uncommit_memory().
|
|
47 bool _special;
|
|
48
|
|
49 // Convenience wrapper.
|
|
50 inline static size_t pointer_delta(const char* left, const char* right);
|
|
51
|
|
52 public:
|
|
53 PSVirtualSpace(ReservedSpace rs, size_t alignment);
|
|
54 PSVirtualSpace(ReservedSpace rs);
|
|
55
|
|
56 ~PSVirtualSpace();
|
|
57
|
|
58 // Eventually all instances should be created with the above 1- or 2-arg
|
|
59 // constructors. Then the 1st constructor below should become protected and
|
|
60 // the 2nd ctor and initialize() removed.
|
|
61 PSVirtualSpace(size_t alignment): _alignment(alignment) { }
|
|
62 PSVirtualSpace();
|
|
63 bool initialize(ReservedSpace rs, size_t commit_size);
|
|
64
|
|
65 bool contains(void* p) const;
|
|
66
|
|
67 // Accessors (all sizes are bytes).
|
|
68 size_t alignment() const { return _alignment; }
|
|
69 char* reserved_low_addr() const { return _reserved_low_addr; }
|
|
70 char* reserved_high_addr() const { return _reserved_high_addr; }
|
|
71 char* committed_low_addr() const { return _committed_low_addr; }
|
|
72 char* committed_high_addr() const { return _committed_high_addr; }
|
|
73 bool special() const { return _special; }
|
|
74
|
|
75 inline size_t committed_size() const;
|
|
76 inline size_t reserved_size() const;
|
|
77 inline size_t uncommitted_size() const;
|
|
78
|
|
79 // Operations.
|
|
80 inline void set_reserved(char* low_addr, char* high_addr, bool special);
|
|
81 inline void set_reserved(ReservedSpace rs);
|
|
82 inline void set_committed(char* low_addr, char* high_addr);
|
|
83 virtual bool expand_by(size_t bytes, bool pre_touch = false);
|
|
84 virtual bool shrink_by(size_t bytes);
|
|
85 virtual size_t expand_into(PSVirtualSpace* space, size_t bytes);
|
|
86 void release();
|
|
87
|
|
88 #ifndef PRODUCT
|
|
89 // Debugging
|
|
90 static bool is_aligned(size_t val, size_t align);
|
|
91 bool is_aligned(size_t val) const;
|
|
92 bool is_aligned(char* val) const;
|
|
93 void verify() const;
|
|
94 void print() const;
|
|
95 virtual bool grows_up() const { return true; }
|
|
96 bool grows_down() const { return !grows_up(); }
|
|
97
|
|
98 // Helper class to verify a space when entering/leaving a block.
|
|
99 class PSVirtualSpaceVerifier: public StackObj {
|
|
100 private:
|
|
101 const PSVirtualSpace* const _space;
|
|
102 public:
|
|
103 PSVirtualSpaceVerifier(PSVirtualSpace* space): _space(space) {
|
|
104 _space->verify();
|
|
105 }
|
|
106 ~PSVirtualSpaceVerifier() { _space->verify(); }
|
|
107 };
|
|
108 #endif
|
|
109
|
|
110 virtual void print_space_boundaries_on(outputStream* st) const;
|
|
111
|
|
112 // Included for compatibility with the original VirtualSpace.
|
|
113 public:
|
|
114 // Committed area
|
|
115 char* low() const { return committed_low_addr(); }
|
|
116 char* high() const { return committed_high_addr(); }
|
|
117
|
|
118 // Reserved area
|
|
119 char* low_boundary() const { return reserved_low_addr(); }
|
|
120 char* high_boundary() const { return reserved_high_addr(); }
|
|
121 };
|
|
122
|
|
123 // A virtual space that grows from high addresses to low addresses.
|
|
124 class PSVirtualSpaceHighToLow : public PSVirtualSpace {
|
|
125 friend class VMStructs;
|
|
126 public:
|
|
127 PSVirtualSpaceHighToLow(ReservedSpace rs, size_t alignment);
|
|
128 PSVirtualSpaceHighToLow(ReservedSpace rs);
|
|
129
|
|
130 virtual bool expand_by(size_t bytes, bool pre_touch = false);
|
|
131 virtual bool shrink_by(size_t bytes);
|
|
132 virtual size_t expand_into(PSVirtualSpace* space, size_t bytes);
|
|
133
|
|
134 virtual void print_space_boundaries_on(outputStream* st) const;
|
|
135
|
|
136 #ifndef PRODUCT
|
|
137 // Debugging
|
|
138 virtual bool grows_up() const { return false; }
|
|
139 #endif
|
|
140 };
|
|
141
|
|
142 //
|
|
143 // PSVirtualSpace inlines.
|
|
144 //
|
|
145 inline size_t
|
|
146 PSVirtualSpace::pointer_delta(const char* left, const char* right) {
|
|
147 return ::pointer_delta((void *)left, (void*)right, sizeof(char));
|
|
148 }
|
|
149
|
|
150 inline size_t PSVirtualSpace::committed_size() const {
|
|
151 return pointer_delta(committed_high_addr(), committed_low_addr());
|
|
152 }
|
|
153
|
|
154 inline size_t PSVirtualSpace::reserved_size() const {
|
|
155 return pointer_delta(reserved_high_addr(), reserved_low_addr());
|
|
156 }
|
|
157
|
|
158 inline size_t PSVirtualSpace::uncommitted_size() const {
|
|
159 return reserved_size() - committed_size();
|
|
160 }
|
|
161
|
|
162 inline void PSVirtualSpace::set_reserved(char* low_addr, char* high_addr, bool special) {
|
|
163 _reserved_low_addr = low_addr;
|
|
164 _reserved_high_addr = high_addr;
|
|
165 _special = special;
|
|
166 }
|
|
167
|
|
168 inline void PSVirtualSpace::set_reserved(ReservedSpace rs) {
|
|
169 set_reserved(rs.base(), rs.base() + rs.size(), rs.special());
|
|
170 }
|
|
171
|
|
172 inline void PSVirtualSpace::set_committed(char* low_addr, char* high_addr) {
|
|
173 _committed_low_addr = low_addr;
|
|
174 _committed_high_addr = high_addr;
|
|
175 }
|