annotate src/share/vm/memory/heap.hpp @ 2368:dde920245681

6896099: Integrate CMS heap ergo with default heap sizing ergo 6627787: CMS: JVM refuses to start up with -Xms16m -Xmx16m 7000125: CMS: Anti-monotone young gen sizing with respect to maximum whole heap size specification 7027529: CMS: retire CMSUseOldDefaults flag Summary: Simplify CMS heap sizing code, relying on ergonomic initial sizing consistent with other collectors for the most part, controlling only young gen sizing to rein in pause times. Make CMS young gen sizing default statically cpu-dependant. Remove inconsistencies wrt generation sizing and policy code, allowing for the fixing for 6627787 and 7000125. For 7027529, retire the flag CMSUseOldDefaults which had been introduced as a bridge from JDK 5 to JDK 6 a number of years ago. Reviewed-by: brutisso, poonam
author ysr
date Wed, 16 Mar 2011 10:37:08 -0700
parents 51bd2d261853
children d2a62e0f25eb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1907
1e9a9d2e6509 6970683: improvements to hs_err output
never
parents: 1552
diff changeset
2 * Copyright (c) 1997, 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: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
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: 0
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: 1907
diff changeset
25 #ifndef SHARE_VM_MEMORY_HEAP_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1907
diff changeset
26 #define SHARE_VM_MEMORY_HEAP_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1907
diff changeset
27
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1907
diff changeset
28 #include "memory/allocation.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1907
diff changeset
29 #include "runtime/virtualspace.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1907
diff changeset
30
0
a61af66fc99e Initial load
duke
parents:
diff changeset
31 // Blocks
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 class HeapBlock VALUE_OBJ_CLASS_SPEC {
a61af66fc99e Initial load
duke
parents:
diff changeset
34 friend class VMStructs;
a61af66fc99e Initial load
duke
parents:
diff changeset
35
a61af66fc99e Initial load
duke
parents:
diff changeset
36 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
37 struct Header {
a61af66fc99e Initial load
duke
parents:
diff changeset
38 size_t _length; // the length in segments
a61af66fc99e Initial load
duke
parents:
diff changeset
39 bool _used; // Used bit
a61af66fc99e Initial load
duke
parents:
diff changeset
40 };
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
43 union {
a61af66fc99e Initial load
duke
parents:
diff changeset
44 Header _header;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 int64_t _padding[ (sizeof(Header) + sizeof(int64_t)-1) / sizeof(int64_t) ];
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // pad to 0 mod 8
a61af66fc99e Initial load
duke
parents:
diff changeset
47 };
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 // Initialization
a61af66fc99e Initial load
duke
parents:
diff changeset
51 void initialize(size_t length) { _header._length = length; set_used(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 // Accessors
a61af66fc99e Initial load
duke
parents:
diff changeset
54 void* allocated_space() const { return (void*)(this + 1); }
a61af66fc99e Initial load
duke
parents:
diff changeset
55 size_t length() const { return _header._length; }
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // Used/free
a61af66fc99e Initial load
duke
parents:
diff changeset
58 void set_used() { _header._used = true; }
a61af66fc99e Initial load
duke
parents:
diff changeset
59 void set_free() { _header._used = false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
60 bool free() { return !_header._used; }
a61af66fc99e Initial load
duke
parents:
diff changeset
61 };
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63 class FreeBlock: public HeapBlock {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 friend class VMStructs;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
66 FreeBlock* _link;
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
69 // Initialization
a61af66fc99e Initial load
duke
parents:
diff changeset
70 void initialize(size_t length) { HeapBlock::initialize(length); _link= NULL; }
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 // Merging
a61af66fc99e Initial load
duke
parents:
diff changeset
73 void set_length(size_t l) { _header._length = l; }
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 // Accessors
a61af66fc99e Initial load
duke
parents:
diff changeset
76 FreeBlock* link() const { return _link; }
a61af66fc99e Initial load
duke
parents:
diff changeset
77 void set_link(FreeBlock* link) { _link = link; }
a61af66fc99e Initial load
duke
parents:
diff changeset
78 };
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 class CodeHeap : public CHeapObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
81 friend class VMStructs;
a61af66fc99e Initial load
duke
parents:
diff changeset
82 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
83 VirtualSpace _memory; // the memory holding the blocks
a61af66fc99e Initial load
duke
parents:
diff changeset
84 VirtualSpace _segmap; // the memory holding the segment map
a61af66fc99e Initial load
duke
parents:
diff changeset
85
a61af66fc99e Initial load
duke
parents:
diff changeset
86 size_t _number_of_committed_segments;
a61af66fc99e Initial load
duke
parents:
diff changeset
87 size_t _number_of_reserved_segments;
a61af66fc99e Initial load
duke
parents:
diff changeset
88 size_t _segment_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
89 int _log2_segment_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 size_t _next_segment;
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93 FreeBlock* _freelist;
a61af66fc99e Initial load
duke
parents:
diff changeset
94 size_t _free_segments; // No. of segments in freelist
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 // Helper functions
a61af66fc99e Initial load
duke
parents:
diff changeset
97 size_t number_of_segments(size_t size) const { return (size + _segment_size - 1) >> _log2_segment_size; }
a61af66fc99e Initial load
duke
parents:
diff changeset
98 size_t size(size_t number_of_segments) const { return number_of_segments << _log2_segment_size; }
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 size_t segment_for(void* p) const { return ((char*)p - _memory.low()) >> _log2_segment_size; }
a61af66fc99e Initial load
duke
parents:
diff changeset
101 HeapBlock* block_at(size_t i) const { return (HeapBlock*)(_memory.low() + (i << _log2_segment_size)); }
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 void mark_segmap_as_free(size_t beg, size_t end);
a61af66fc99e Initial load
duke
parents:
diff changeset
104 void mark_segmap_as_used(size_t beg, size_t end);
a61af66fc99e Initial load
duke
parents:
diff changeset
105
a61af66fc99e Initial load
duke
parents:
diff changeset
106 // Freelist management helpers
a61af66fc99e Initial load
duke
parents:
diff changeset
107 FreeBlock* following_block(FreeBlock *b);
a61af66fc99e Initial load
duke
parents:
diff changeset
108 void insert_after(FreeBlock* a, FreeBlock* b);
a61af66fc99e Initial load
duke
parents:
diff changeset
109 void merge_right (FreeBlock* a);
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 // Toplevel freelist management
a61af66fc99e Initial load
duke
parents:
diff changeset
112 void add_to_freelist(HeapBlock *b);
a61af66fc99e Initial load
duke
parents:
diff changeset
113 FreeBlock* search_freelist(size_t length);
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 // Iteration helpers
a61af66fc99e Initial load
duke
parents:
diff changeset
116 void* next_free(HeapBlock* b) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
117 HeapBlock* first_block() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
118 HeapBlock* next_block(HeapBlock* b) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
119 HeapBlock* block_start(void* p) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 // to perform additional actions on creation of executable code
a61af66fc99e Initial load
duke
parents:
diff changeset
122 void on_code_mapping(char* base, size_t size);
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
125 CodeHeap();
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127 // Heap extents
a61af66fc99e Initial load
duke
parents:
diff changeset
128 bool reserve(size_t reserved_size, size_t committed_size, size_t segment_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
129 void release(); // releases all allocated memory
a61af66fc99e Initial load
duke
parents:
diff changeset
130 bool expand_by(size_t size); // expands commited memory by size
a61af66fc99e Initial load
duke
parents:
diff changeset
131 void shrink_by(size_t size); // shrinks commited memory by size
a61af66fc99e Initial load
duke
parents:
diff changeset
132 void clear(); // clears all heap contents
a61af66fc99e Initial load
duke
parents:
diff changeset
133
a61af66fc99e Initial load
duke
parents:
diff changeset
134 // Memory allocation
a61af66fc99e Initial load
duke
parents:
diff changeset
135 void* allocate (size_t size); // allocates a block of size or returns NULL
a61af66fc99e Initial load
duke
parents:
diff changeset
136 void deallocate(void* p); // deallocates a block
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138 // Attributes
a61af66fc99e Initial load
duke
parents:
diff changeset
139 void* begin() const { return _memory.low (); }
a61af66fc99e Initial load
duke
parents:
diff changeset
140 void* end() const { return _memory.high(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
141 bool contains(void* p) const { return begin() <= p && p < end(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
142 void* find_start(void* p) const; // returns the block containing p or NULL
a61af66fc99e Initial load
duke
parents:
diff changeset
143 size_t alignment_unit() const; // alignment of any block
a61af66fc99e Initial load
duke
parents:
diff changeset
144 size_t alignment_offset() const; // offset of first byte of any block, within the enclosing alignment unit
a61af66fc99e Initial load
duke
parents:
diff changeset
145 static size_t header_size(); // returns the header size for each heap block
a61af66fc99e Initial load
duke
parents:
diff changeset
146
a61af66fc99e Initial load
duke
parents:
diff changeset
147 // Returns reserved area high and low addresses
a61af66fc99e Initial load
duke
parents:
diff changeset
148 char *low_boundary() const { return _memory.low_boundary (); }
1907
1e9a9d2e6509 6970683: improvements to hs_err output
never
parents: 1552
diff changeset
149 char *high() const { return _memory.high(); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
150 char *high_boundary() const { return _memory.high_boundary(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 // Iteration
a61af66fc99e Initial load
duke
parents:
diff changeset
153
a61af66fc99e Initial load
duke
parents:
diff changeset
154 // returns the first block or NULL
a61af66fc99e Initial load
duke
parents:
diff changeset
155 void* first() const { return next_free(first_block()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
156 // returns the next block given a block p or NULL
a61af66fc99e Initial load
duke
parents:
diff changeset
157 void* next(void* p) const { return next_free(next_block(block_start(p))); }
a61af66fc99e Initial load
duke
parents:
diff changeset
158
a61af66fc99e Initial load
duke
parents:
diff changeset
159 // Statistics
a61af66fc99e Initial load
duke
parents:
diff changeset
160 size_t capacity() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
161 size_t max_capacity() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
162 size_t allocated_capacity() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
163 size_t unallocated_capacity() const { return max_capacity() - allocated_capacity(); }
2091
51bd2d261853 7008325: CodeCache exhausted on sparc starting from hs20b04
kvn
parents: 1972
diff changeset
164 size_t largest_free_block() const;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166 // Debugging
a61af66fc99e Initial load
duke
parents:
diff changeset
167 void verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
168 void print() PRODUCT_RETURN;
a61af66fc99e Initial load
duke
parents:
diff changeset
169 };
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1907
diff changeset
170
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1907
diff changeset
171 #endif // SHARE_VM_MEMORY_HEAP_HPP