annotate src/share/vm/memory/heap.cpp @ 20543:e7d0505c8a30

8059758: Footprint regressions with JDK-8038423 Summary: Changes in JDK-8038423 always initialize (zero out) virtual memory used for auxiliary data structures. This causes a footprint regression for G1 in startup benchmarks. This is because they do not touch that memory at all, so the operating system does not actually commit these pages. The fix is to, if the initialization value of the data structures matches the default value of just committed memory (=0), do not do anything. Reviewed-by: jwilhelm, brutisso
author tschatzl
date Fri, 10 Oct 2014 15:51:58 +0200
parents 740e263c80c6
children 58fc8e2b7b6d 63a4eb8bcd23
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 10114
diff changeset
2 * Copyright (c) 1997, 2013, 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: 1123
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1123
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: 1123
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 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #include "memory/heap.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27 #include "oops/oop.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "runtime/os.hpp"
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 2426
diff changeset
29 #include "services/memTracker.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 size_t CodeHeap::header_size() {
a61af66fc99e Initial load
duke
parents:
diff changeset
32 return sizeof(HeapBlock);
a61af66fc99e Initial load
duke
parents:
diff changeset
33 }
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // Implementation of Heap
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 CodeHeap::CodeHeap() {
a61af66fc99e Initial load
duke
parents:
diff changeset
39 _number_of_committed_segments = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 _number_of_reserved_segments = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 _segment_size = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 _log2_segment_size = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 _next_segment = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 _freelist = NULL;
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
45 _freelist_segments = 0;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
46 }
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48
a61af66fc99e Initial load
duke
parents:
diff changeset
49 void CodeHeap::mark_segmap_as_free(size_t beg, size_t end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
50 assert(0 <= beg && beg < _number_of_committed_segments, "interval begin out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
51 assert(beg < end && end <= _number_of_committed_segments, "interval end out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // setup _segmap pointers for faster indexing
a61af66fc99e Initial load
duke
parents:
diff changeset
53 address p = (address)_segmap.low() + beg;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 address q = (address)_segmap.low() + end;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 // initialize interval
a61af66fc99e Initial load
duke
parents:
diff changeset
56 while (p < q) *p++ = 0xFF;
a61af66fc99e Initial load
duke
parents:
diff changeset
57 }
a61af66fc99e Initial load
duke
parents:
diff changeset
58
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 void CodeHeap::mark_segmap_as_used(size_t beg, size_t end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
61 assert(0 <= beg && beg < _number_of_committed_segments, "interval begin out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
62 assert(beg < end && end <= _number_of_committed_segments, "interval end out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // setup _segmap pointers for faster indexing
a61af66fc99e Initial load
duke
parents:
diff changeset
64 address p = (address)_segmap.low() + beg;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 address q = (address)_segmap.low() + end;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 // initialize interval
a61af66fc99e Initial load
duke
parents:
diff changeset
67 int i = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
68 while (p < q) {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 *p++ = i++;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 if (i == 0xFF) i = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
71 }
a61af66fc99e Initial load
duke
parents:
diff changeset
72 }
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 static size_t align_to_page_size(size_t size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
76 const size_t alignment = (size_t)os::vm_page_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
77 assert(is_power_of_2(alignment), "no kidding ???");
a61af66fc99e Initial load
duke
parents:
diff changeset
78 return (size + alignment - 1) & ~(alignment - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
79 }
a61af66fc99e Initial load
duke
parents:
diff changeset
80
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82 void CodeHeap::on_code_mapping(char* base, size_t size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 #ifdef LINUX
a61af66fc99e Initial load
duke
parents:
diff changeset
84 extern void linux_wrap_code(char* base, size_t size);
a61af66fc99e Initial load
duke
parents:
diff changeset
85 linux_wrap_code(base, size);
a61af66fc99e Initial load
duke
parents:
diff changeset
86 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
87 }
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 bool CodeHeap::reserve(size_t reserved_size, size_t committed_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
91 size_t segment_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 assert(reserved_size >= committed_size, "reserved < committed");
a61af66fc99e Initial load
duke
parents:
diff changeset
93 assert(segment_size >= sizeof(FreeBlock), "segment size is too small");
a61af66fc99e Initial load
duke
parents:
diff changeset
94 assert(is_power_of_2(segment_size), "segment_size must be a power of 2");
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 _segment_size = segment_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 _log2_segment_size = exact_log2(segment_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 // Reserve and initialize space for _memory.
79
82db0859acbe 6642862: Code cache allocation fails with large pages after 6588638
jcoomes
parents: 0
diff changeset
100 const size_t page_size = os::can_execute_large_page_memory() ?
82db0859acbe 6642862: Code cache allocation fails with large pages after 6588638
jcoomes
parents: 0
diff changeset
101 os::page_size_for_region(committed_size, reserved_size, 8) :
82db0859acbe 6642862: Code cache allocation fails with large pages after 6588638
jcoomes
parents: 0
diff changeset
102 os::vm_page_size();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
103 const size_t granularity = os::vm_allocation_granularity();
a61af66fc99e Initial load
duke
parents:
diff changeset
104 const size_t r_align = MAX2(page_size, granularity);
a61af66fc99e Initial load
duke
parents:
diff changeset
105 const size_t r_size = align_size_up(reserved_size, r_align);
a61af66fc99e Initial load
duke
parents:
diff changeset
106 const size_t c_size = align_size_up(committed_size, page_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 const size_t rs_align = page_size == (size_t) os::vm_page_size() ? 0 :
a61af66fc99e Initial load
duke
parents:
diff changeset
109 MAX2(page_size, granularity);
656
6bdd6923ba16 6541756: Reduce executable C-heap
coleenp
parents: 196
diff changeset
110 ReservedCodeSpace rs(r_size, rs_align, rs_align > 0);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
111 os::trace_page_sizes("code heap", committed_size, reserved_size, page_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
112 rs.base(), rs.size());
a61af66fc99e Initial load
duke
parents:
diff changeset
113 if (!_memory.initialize(rs, c_size)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117 on_code_mapping(_memory.low(), _memory.committed_size());
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
118 _number_of_committed_segments = size_to_segments(_memory.committed_size());
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
119 _number_of_reserved_segments = size_to_segments(_memory.reserved_size());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
120 assert(_number_of_reserved_segments >= _number_of_committed_segments, "just checking");
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 10114
diff changeset
121 const size_t reserved_segments_alignment = MAX2((size_t)os::vm_page_size(), granularity);
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 10114
diff changeset
122 const size_t reserved_segments_size = align_size_up(_number_of_reserved_segments, reserved_segments_alignment);
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 10114
diff changeset
123 const size_t committed_segments_size = align_to_page_size(_number_of_committed_segments);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 // reserve space for _segmap
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 10114
diff changeset
126 if (!_segmap.initialize(reserved_segments_size, committed_segments_size)) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
127 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 2426
diff changeset
129
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 2426
diff changeset
130 MemTracker::record_virtual_memory_type((address)_segmap.low_boundary(), mtCode);
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 2426
diff changeset
131
0
a61af66fc99e Initial load
duke
parents:
diff changeset
132 assert(_segmap.committed_size() >= (size_t) _number_of_committed_segments, "could not commit enough space for segment map");
a61af66fc99e Initial load
duke
parents:
diff changeset
133 assert(_segmap.reserved_size() >= (size_t) _number_of_reserved_segments , "could not reserve enough space for segment map");
a61af66fc99e Initial load
duke
parents:
diff changeset
134 assert(_segmap.reserved_size() >= _segmap.committed_size() , "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 // initialize remaining instance variables
a61af66fc99e Initial load
duke
parents:
diff changeset
137 clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
138 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142 void CodeHeap::release() {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 Unimplemented();
a61af66fc99e Initial load
duke
parents:
diff changeset
144 }
a61af66fc99e Initial load
duke
parents:
diff changeset
145
a61af66fc99e Initial load
duke
parents:
diff changeset
146
a61af66fc99e Initial load
duke
parents:
diff changeset
147 bool CodeHeap::expand_by(size_t size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
148 // expand _memory space
a61af66fc99e Initial load
duke
parents:
diff changeset
149 size_t dm = align_to_page_size(_memory.committed_size() + size) - _memory.committed_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
150 if (dm > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
151 char* base = _memory.low() + _memory.committed_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
152 if (!_memory.expand_by(dm)) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
153 on_code_mapping(base, dm);
a61af66fc99e Initial load
duke
parents:
diff changeset
154 size_t i = _number_of_committed_segments;
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
155 _number_of_committed_segments = size_to_segments(_memory.committed_size());
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
156 assert(_number_of_reserved_segments == size_to_segments(_memory.reserved_size()), "number of reserved segments should not change");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
157 assert(_number_of_reserved_segments >= _number_of_committed_segments, "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
158 // expand _segmap space
a61af66fc99e Initial load
duke
parents:
diff changeset
159 size_t ds = align_to_page_size(_number_of_committed_segments) - _segmap.committed_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
160 if (ds > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
161 if (!_segmap.expand_by(ds)) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
162 }
a61af66fc99e Initial load
duke
parents:
diff changeset
163 assert(_segmap.committed_size() >= (size_t) _number_of_committed_segments, "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
164 // initialize additional segmap entries
a61af66fc99e Initial load
duke
parents:
diff changeset
165 mark_segmap_as_free(i, _number_of_committed_segments);
a61af66fc99e Initial load
duke
parents:
diff changeset
166 }
a61af66fc99e Initial load
duke
parents:
diff changeset
167 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
168 }
a61af66fc99e Initial load
duke
parents:
diff changeset
169
a61af66fc99e Initial load
duke
parents:
diff changeset
170
a61af66fc99e Initial load
duke
parents:
diff changeset
171 void CodeHeap::shrink_by(size_t size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
172 Unimplemented();
a61af66fc99e Initial load
duke
parents:
diff changeset
173 }
a61af66fc99e Initial load
duke
parents:
diff changeset
174
a61af66fc99e Initial load
duke
parents:
diff changeset
175
a61af66fc99e Initial load
duke
parents:
diff changeset
176 void CodeHeap::clear() {
a61af66fc99e Initial load
duke
parents:
diff changeset
177 _next_segment = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
178 mark_segmap_as_free(0, _number_of_committed_segments);
a61af66fc99e Initial load
duke
parents:
diff changeset
179 }
a61af66fc99e Initial load
duke
parents:
diff changeset
180
a61af66fc99e Initial load
duke
parents:
diff changeset
181
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
182 void* CodeHeap::allocate(size_t instance_size, bool is_critical) {
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
183 size_t number_of_segments = size_to_segments(instance_size + sizeof(HeapBlock));
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
184 assert(segments_to_size(number_of_segments) >= sizeof(FreeBlock), "not enough room for FreeList");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
185
a61af66fc99e Initial load
duke
parents:
diff changeset
186 // First check if we can satify request from freelist
a61af66fc99e Initial load
duke
parents:
diff changeset
187 debug_only(verify());
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
188 HeapBlock* block = search_freelist(number_of_segments, is_critical);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
189 debug_only(if (VerifyCodeCacheOften) verify());
a61af66fc99e Initial load
duke
parents:
diff changeset
190 if (block != NULL) {
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
191 assert(block->length() >= number_of_segments && block->length() < number_of_segments + CodeCacheMinBlockLength, "sanity check");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
192 assert(!block->free(), "must be marked free");
a61af66fc99e Initial load
duke
parents:
diff changeset
193 #ifdef ASSERT
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
194 memset((void *)block->allocated_space(), badCodeHeapNewVal, instance_size);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
195 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
196 return block->allocated_space();
a61af66fc99e Initial load
duke
parents:
diff changeset
197 }
a61af66fc99e Initial load
duke
parents:
diff changeset
198
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
199 // Ensure minimum size for allocation to the heap.
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
200 if (number_of_segments < CodeCacheMinBlockLength) {
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
201 number_of_segments = CodeCacheMinBlockLength;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
203
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
204 if (!is_critical) {
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
205 // Make sure the allocation fits in the unallocated heap without using
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
206 // the CodeCacheMimimumFreeSpace that is reserved for critical allocations.
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
207 if (segments_to_size(number_of_segments) > (heap_unallocated_capacity() - CodeCacheMinimumFreeSpace)) {
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
208 // Fail allocation
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
209 return NULL;
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
210 }
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
211 }
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
212
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
213 if (_next_segment + number_of_segments <= _number_of_committed_segments) {
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
214 mark_segmap_as_used(_next_segment, _next_segment + number_of_segments);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
215 HeapBlock* b = block_at(_next_segment);
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
216 b->initialize(number_of_segments);
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
217 _next_segment += number_of_segments;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
218 #ifdef ASSERT
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
219 memset((void *)b->allocated_space(), badCodeHeapNewVal, instance_size);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
220 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
221 return b->allocated_space();
a61af66fc99e Initial load
duke
parents:
diff changeset
222 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
223 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
224 }
a61af66fc99e Initial load
duke
parents:
diff changeset
225 }
a61af66fc99e Initial load
duke
parents:
diff changeset
226
a61af66fc99e Initial load
duke
parents:
diff changeset
227
a61af66fc99e Initial load
duke
parents:
diff changeset
228 void CodeHeap::deallocate(void* p) {
a61af66fc99e Initial load
duke
parents:
diff changeset
229 assert(p == find_start(p), "illegal deallocation");
a61af66fc99e Initial load
duke
parents:
diff changeset
230 // Find start of HeapBlock
a61af66fc99e Initial load
duke
parents:
diff changeset
231 HeapBlock* b = (((HeapBlock *)p) - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
232 assert(b->allocated_space() == p, "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
233 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
234 memset((void *)b->allocated_space(),
a61af66fc99e Initial load
duke
parents:
diff changeset
235 badCodeHeapFreeVal,
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
236 segments_to_size(b->length()) - sizeof(HeapBlock));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
237 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
238 add_to_freelist(b);
a61af66fc99e Initial load
duke
parents:
diff changeset
239
a61af66fc99e Initial load
duke
parents:
diff changeset
240 debug_only(if (VerifyCodeCacheOften) verify());
a61af66fc99e Initial load
duke
parents:
diff changeset
241 }
a61af66fc99e Initial load
duke
parents:
diff changeset
242
a61af66fc99e Initial load
duke
parents:
diff changeset
243
a61af66fc99e Initial load
duke
parents:
diff changeset
244 void* CodeHeap::find_start(void* p) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
245 if (!contains(p)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
246 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
247 }
a61af66fc99e Initial load
duke
parents:
diff changeset
248 size_t i = segment_for(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
249 address b = (address)_segmap.low();
a61af66fc99e Initial load
duke
parents:
diff changeset
250 if (b[i] == 0xFF) {
a61af66fc99e Initial load
duke
parents:
diff changeset
251 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
252 }
a61af66fc99e Initial load
duke
parents:
diff changeset
253 while (b[i] > 0) i -= (int)b[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
254 HeapBlock* h = block_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
255 if (h->free()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
256 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
257 }
a61af66fc99e Initial load
duke
parents:
diff changeset
258 return h->allocated_space();
a61af66fc99e Initial load
duke
parents:
diff changeset
259 }
a61af66fc99e Initial load
duke
parents:
diff changeset
260
a61af66fc99e Initial load
duke
parents:
diff changeset
261
a61af66fc99e Initial load
duke
parents:
diff changeset
262 size_t CodeHeap::alignment_unit() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
263 // this will be a power of two
a61af66fc99e Initial load
duke
parents:
diff changeset
264 return _segment_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
265 }
a61af66fc99e Initial load
duke
parents:
diff changeset
266
a61af66fc99e Initial load
duke
parents:
diff changeset
267
a61af66fc99e Initial load
duke
parents:
diff changeset
268 size_t CodeHeap::alignment_offset() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
269 // The lowest address in any allocated block will be
a61af66fc99e Initial load
duke
parents:
diff changeset
270 // equal to alignment_offset (mod alignment_unit).
a61af66fc99e Initial load
duke
parents:
diff changeset
271 return sizeof(HeapBlock) & (_segment_size - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
272 }
a61af66fc99e Initial load
duke
parents:
diff changeset
273
a61af66fc99e Initial load
duke
parents:
diff changeset
274 // Finds the next free heapblock. If the current one is free, that it returned
a61af66fc99e Initial load
duke
parents:
diff changeset
275 void* CodeHeap::next_free(HeapBlock *b) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
276 // Since free blocks are merged, there is max. on free block
a61af66fc99e Initial load
duke
parents:
diff changeset
277 // between two used ones
a61af66fc99e Initial load
duke
parents:
diff changeset
278 if (b != NULL && b->free()) b = next_block(b);
a61af66fc99e Initial load
duke
parents:
diff changeset
279 assert(b == NULL || !b->free(), "must be in use or at end of heap");
a61af66fc99e Initial load
duke
parents:
diff changeset
280 return (b == NULL) ? NULL : b->allocated_space();
a61af66fc99e Initial load
duke
parents:
diff changeset
281 }
a61af66fc99e Initial load
duke
parents:
diff changeset
282
a61af66fc99e Initial load
duke
parents:
diff changeset
283 // Returns the first used HeapBlock
a61af66fc99e Initial load
duke
parents:
diff changeset
284 HeapBlock* CodeHeap::first_block() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
285 if (_next_segment > 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
286 return block_at(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
287 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
288 }
a61af66fc99e Initial load
duke
parents:
diff changeset
289
a61af66fc99e Initial load
duke
parents:
diff changeset
290 HeapBlock *CodeHeap::block_start(void *q) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
291 HeapBlock* b = (HeapBlock*)find_start(q);
a61af66fc99e Initial load
duke
parents:
diff changeset
292 if (b == NULL) return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
293 return b - 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
294 }
a61af66fc99e Initial load
duke
parents:
diff changeset
295
a61af66fc99e Initial load
duke
parents:
diff changeset
296 // Returns the next Heap block an offset into one
a61af66fc99e Initial load
duke
parents:
diff changeset
297 HeapBlock* CodeHeap::next_block(HeapBlock *b) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
298 if (b == NULL) return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
299 size_t i = segment_for(b) + b->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
300 if (i < _next_segment)
a61af66fc99e Initial load
duke
parents:
diff changeset
301 return block_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
302 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
303 }
a61af66fc99e Initial load
duke
parents:
diff changeset
304
a61af66fc99e Initial load
duke
parents:
diff changeset
305
a61af66fc99e Initial load
duke
parents:
diff changeset
306 // Returns current capacity
a61af66fc99e Initial load
duke
parents:
diff changeset
307 size_t CodeHeap::capacity() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
308 return _memory.committed_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
309 }
a61af66fc99e Initial load
duke
parents:
diff changeset
310
a61af66fc99e Initial load
duke
parents:
diff changeset
311 size_t CodeHeap::max_capacity() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
312 return _memory.reserved_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
313 }
a61af66fc99e Initial load
duke
parents:
diff changeset
314
a61af66fc99e Initial load
duke
parents:
diff changeset
315 size_t CodeHeap::allocated_capacity() const {
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
316 // size of used heap - size on freelist
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
317 return segments_to_size(_next_segment - _freelist_segments);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
318 }
a61af66fc99e Initial load
duke
parents:
diff changeset
319
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
320 // Returns size of the unallocated heap block
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
321 size_t CodeHeap::heap_unallocated_capacity() const {
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
322 // Total number of segments - number currently used
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
323 return segments_to_size(_number_of_reserved_segments - _next_segment);
2091
51bd2d261853 7008325: CodeCache exhausted on sparc starting from hs20b04
kvn
parents: 1972
diff changeset
324 }
51bd2d261853 7008325: CodeCache exhausted on sparc starting from hs20b04
kvn
parents: 1972
diff changeset
325
0
a61af66fc99e Initial load
duke
parents:
diff changeset
326 // Free list management
a61af66fc99e Initial load
duke
parents:
diff changeset
327
a61af66fc99e Initial load
duke
parents:
diff changeset
328 FreeBlock *CodeHeap::following_block(FreeBlock *b) {
a61af66fc99e Initial load
duke
parents:
diff changeset
329 return (FreeBlock*)(((address)b) + _segment_size * b->length());
a61af66fc99e Initial load
duke
parents:
diff changeset
330 }
a61af66fc99e Initial load
duke
parents:
diff changeset
331
a61af66fc99e Initial load
duke
parents:
diff changeset
332 // Inserts block b after a
a61af66fc99e Initial load
duke
parents:
diff changeset
333 void CodeHeap::insert_after(FreeBlock* a, FreeBlock* b) {
a61af66fc99e Initial load
duke
parents:
diff changeset
334 assert(a != NULL && b != NULL, "must be real pointers");
a61af66fc99e Initial load
duke
parents:
diff changeset
335
a61af66fc99e Initial load
duke
parents:
diff changeset
336 // Link b into the list after a
a61af66fc99e Initial load
duke
parents:
diff changeset
337 b->set_link(a->link());
a61af66fc99e Initial load
duke
parents:
diff changeset
338 a->set_link(b);
a61af66fc99e Initial load
duke
parents:
diff changeset
339
a61af66fc99e Initial load
duke
parents:
diff changeset
340 // See if we can merge blocks
a61af66fc99e Initial load
duke
parents:
diff changeset
341 merge_right(b); // Try to make b bigger
a61af66fc99e Initial load
duke
parents:
diff changeset
342 merge_right(a); // Try to make a include b
a61af66fc99e Initial load
duke
parents:
diff changeset
343 }
a61af66fc99e Initial load
duke
parents:
diff changeset
344
a61af66fc99e Initial load
duke
parents:
diff changeset
345 // Try to merge this block with the following block
a61af66fc99e Initial load
duke
parents:
diff changeset
346 void CodeHeap::merge_right(FreeBlock *a) {
a61af66fc99e Initial load
duke
parents:
diff changeset
347 assert(a->free(), "must be a free block");
a61af66fc99e Initial load
duke
parents:
diff changeset
348 if (following_block(a) == a->link()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
349 assert(a->link() != NULL && a->link()->free(), "must be free too");
a61af66fc99e Initial load
duke
parents:
diff changeset
350 // Update block a to include the following block
a61af66fc99e Initial load
duke
parents:
diff changeset
351 a->set_length(a->length() + a->link()->length());
a61af66fc99e Initial load
duke
parents:
diff changeset
352 a->set_link(a->link()->link());
a61af66fc99e Initial load
duke
parents:
diff changeset
353 // Update find_start map
a61af66fc99e Initial load
duke
parents:
diff changeset
354 size_t beg = segment_for(a);
a61af66fc99e Initial load
duke
parents:
diff changeset
355 mark_segmap_as_used(beg, beg + a->length());
a61af66fc99e Initial load
duke
parents:
diff changeset
356 }
a61af66fc99e Initial load
duke
parents:
diff changeset
357 }
a61af66fc99e Initial load
duke
parents:
diff changeset
358
a61af66fc99e Initial load
duke
parents:
diff changeset
359 void CodeHeap::add_to_freelist(HeapBlock *a) {
a61af66fc99e Initial load
duke
parents:
diff changeset
360 FreeBlock* b = (FreeBlock*)a;
a61af66fc99e Initial load
duke
parents:
diff changeset
361 assert(b != _freelist, "cannot be removed twice");
a61af66fc99e Initial load
duke
parents:
diff changeset
362
a61af66fc99e Initial load
duke
parents:
diff changeset
363 // Mark as free and update free space count
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
364 _freelist_segments += b->length();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
365 b->set_free();
a61af66fc99e Initial load
duke
parents:
diff changeset
366
a61af66fc99e Initial load
duke
parents:
diff changeset
367 // First element in list?
a61af66fc99e Initial load
duke
parents:
diff changeset
368 if (_freelist == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
369 _freelist = b;
a61af66fc99e Initial load
duke
parents:
diff changeset
370 b->set_link(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
371 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
372 }
a61af66fc99e Initial load
duke
parents:
diff changeset
373
a61af66fc99e Initial load
duke
parents:
diff changeset
374 // Scan for right place to put into list. List
a61af66fc99e Initial load
duke
parents:
diff changeset
375 // is sorted by increasing addresseses
a61af66fc99e Initial load
duke
parents:
diff changeset
376 FreeBlock* prev = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
377 FreeBlock* cur = _freelist;
a61af66fc99e Initial load
duke
parents:
diff changeset
378 while(cur != NULL && cur < b) {
a61af66fc99e Initial load
duke
parents:
diff changeset
379 assert(prev == NULL || prev < cur, "must be ordered");
a61af66fc99e Initial load
duke
parents:
diff changeset
380 prev = cur;
a61af66fc99e Initial load
duke
parents:
diff changeset
381 cur = cur->link();
a61af66fc99e Initial load
duke
parents:
diff changeset
382 }
a61af66fc99e Initial load
duke
parents:
diff changeset
383
a61af66fc99e Initial load
duke
parents:
diff changeset
384 assert( (prev == NULL && b < _freelist) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
385 (prev < b && (cur == NULL || b < cur)), "list must be ordered");
a61af66fc99e Initial load
duke
parents:
diff changeset
386
a61af66fc99e Initial load
duke
parents:
diff changeset
387 if (prev == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
388 // Insert first in list
a61af66fc99e Initial load
duke
parents:
diff changeset
389 b->set_link(_freelist);
a61af66fc99e Initial load
duke
parents:
diff changeset
390 _freelist = b;
a61af66fc99e Initial load
duke
parents:
diff changeset
391 merge_right(_freelist);
a61af66fc99e Initial load
duke
parents:
diff changeset
392 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
393 insert_after(prev, b);
a61af66fc99e Initial load
duke
parents:
diff changeset
394 }
a61af66fc99e Initial load
duke
parents:
diff changeset
395 }
a61af66fc99e Initial load
duke
parents:
diff changeset
396
a61af66fc99e Initial load
duke
parents:
diff changeset
397 // Search freelist for an entry on the list with the best fit
a61af66fc99e Initial load
duke
parents:
diff changeset
398 // Return NULL if no one was found
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
399 FreeBlock* CodeHeap::search_freelist(size_t length, bool is_critical) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
400 FreeBlock *best_block = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
401 FreeBlock *best_prev = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
402 size_t best_length = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
403
a61af66fc99e Initial load
duke
parents:
diff changeset
404 // Search for smallest block which is bigger than length
a61af66fc99e Initial load
duke
parents:
diff changeset
405 FreeBlock *prev = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
406 FreeBlock *cur = _freelist;
a61af66fc99e Initial load
duke
parents:
diff changeset
407 while(cur != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
408 size_t l = cur->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
409 if (l >= length && (best_block == NULL || best_length > l)) {
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
410
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
411 // Non critical allocations are not allowed to use the last part of the code heap.
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
412 if (!is_critical) {
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
413 // Make sure the end of the allocation doesn't cross into the last part of the code heap
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
414 if (((size_t)cur + length) > ((size_t)high_boundary() - CodeCacheMinimumFreeSpace)) {
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
415 // the freelist is sorted by address - if one fails, all consecutive will also fail.
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
416 break;
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
417 }
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
418 }
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
419
0
a61af66fc99e Initial load
duke
parents:
diff changeset
420 // Remember best block, its previous element, and its length
a61af66fc99e Initial load
duke
parents:
diff changeset
421 best_block = cur;
a61af66fc99e Initial load
duke
parents:
diff changeset
422 best_prev = prev;
a61af66fc99e Initial load
duke
parents:
diff changeset
423 best_length = best_block->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
424 }
a61af66fc99e Initial load
duke
parents:
diff changeset
425
a61af66fc99e Initial load
duke
parents:
diff changeset
426 // Next element in list
a61af66fc99e Initial load
duke
parents:
diff changeset
427 prev = cur;
a61af66fc99e Initial load
duke
parents:
diff changeset
428 cur = cur->link();
a61af66fc99e Initial load
duke
parents:
diff changeset
429 }
a61af66fc99e Initial load
duke
parents:
diff changeset
430
a61af66fc99e Initial load
duke
parents:
diff changeset
431 if (best_block == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
432 // None found
a61af66fc99e Initial load
duke
parents:
diff changeset
433 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
434 }
a61af66fc99e Initial load
duke
parents:
diff changeset
435
a61af66fc99e Initial load
duke
parents:
diff changeset
436 assert((best_prev == NULL && _freelist == best_block ) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
437 (best_prev != NULL && best_prev->link() == best_block), "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
438
a61af66fc99e Initial load
duke
parents:
diff changeset
439 // Exact (or at least good enough) fit. Remove from list.
a61af66fc99e Initial load
duke
parents:
diff changeset
440 // Don't leave anything on the freelist smaller than CodeCacheMinBlockLength.
a61af66fc99e Initial load
duke
parents:
diff changeset
441 if (best_length < length + CodeCacheMinBlockLength) {
a61af66fc99e Initial load
duke
parents:
diff changeset
442 length = best_length;
a61af66fc99e Initial load
duke
parents:
diff changeset
443 if (best_prev == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
444 assert(_freelist == best_block, "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
445 _freelist = _freelist->link();
a61af66fc99e Initial load
duke
parents:
diff changeset
446 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
447 // Unmap element
a61af66fc99e Initial load
duke
parents:
diff changeset
448 best_prev->set_link(best_block->link());
a61af66fc99e Initial load
duke
parents:
diff changeset
449 }
a61af66fc99e Initial load
duke
parents:
diff changeset
450 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
451 // Truncate block and return a pointer to the following block
a61af66fc99e Initial load
duke
parents:
diff changeset
452 best_block->set_length(best_length - length);
a61af66fc99e Initial load
duke
parents:
diff changeset
453 best_block = following_block(best_block);
a61af66fc99e Initial load
duke
parents:
diff changeset
454 // Set used bit and length on new block
a61af66fc99e Initial load
duke
parents:
diff changeset
455 size_t beg = segment_for(best_block);
a61af66fc99e Initial load
duke
parents:
diff changeset
456 mark_segmap_as_used(beg, beg + length);
a61af66fc99e Initial load
duke
parents:
diff changeset
457 best_block->set_length(length);
a61af66fc99e Initial load
duke
parents:
diff changeset
458 }
a61af66fc99e Initial load
duke
parents:
diff changeset
459
a61af66fc99e Initial load
duke
parents:
diff changeset
460 best_block->set_used();
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
461 _freelist_segments -= length;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
462 return best_block;
a61af66fc99e Initial load
duke
parents:
diff changeset
463 }
a61af66fc99e Initial load
duke
parents:
diff changeset
464
a61af66fc99e Initial load
duke
parents:
diff changeset
465 //----------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
466 // Non-product code
a61af66fc99e Initial load
duke
parents:
diff changeset
467
a61af66fc99e Initial load
duke
parents:
diff changeset
468 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
469
a61af66fc99e Initial load
duke
parents:
diff changeset
470 void CodeHeap::print() {
a61af66fc99e Initial load
duke
parents:
diff changeset
471 tty->print_cr("The Heap");
a61af66fc99e Initial load
duke
parents:
diff changeset
472 }
a61af66fc99e Initial load
duke
parents:
diff changeset
473
a61af66fc99e Initial load
duke
parents:
diff changeset
474 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
475
a61af66fc99e Initial load
duke
parents:
diff changeset
476 void CodeHeap::verify() {
a61af66fc99e Initial load
duke
parents:
diff changeset
477 // Count the number of blocks on the freelist, and the amount of space
a61af66fc99e Initial load
duke
parents:
diff changeset
478 // represented.
a61af66fc99e Initial load
duke
parents:
diff changeset
479 int count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
480 size_t len = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
481 for(FreeBlock* b = _freelist; b != NULL; b = b->link()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
482 len += b->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
483 count++;
a61af66fc99e Initial load
duke
parents:
diff changeset
484 }
a61af66fc99e Initial load
duke
parents:
diff changeset
485
a61af66fc99e Initial load
duke
parents:
diff changeset
486 // Verify that freelist contains the right amount of free space
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
487 // guarantee(len == _freelist_segments, "wrong freelist");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
488
a61af66fc99e Initial load
duke
parents:
diff changeset
489 // Verify that the number of free blocks is not out of hand.
a61af66fc99e Initial load
duke
parents:
diff changeset
490 static int free_block_threshold = 10000;
a61af66fc99e Initial load
duke
parents:
diff changeset
491 if (count > free_block_threshold) {
a61af66fc99e Initial load
duke
parents:
diff changeset
492 warning("CodeHeap: # of free blocks > %d", free_block_threshold);
a61af66fc99e Initial load
duke
parents:
diff changeset
493 // Double the warning limit
a61af66fc99e Initial load
duke
parents:
diff changeset
494 free_block_threshold *= 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
495 }
a61af66fc99e Initial load
duke
parents:
diff changeset
496
a61af66fc99e Initial load
duke
parents:
diff changeset
497 // Verify that the freelist contains the same number of free blocks that is
a61af66fc99e Initial load
duke
parents:
diff changeset
498 // found on the full list.
a61af66fc99e Initial load
duke
parents:
diff changeset
499 for(HeapBlock *h = first_block(); h != NULL; h = next_block(h)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
500 if (h->free()) count--;
a61af66fc99e Initial load
duke
parents:
diff changeset
501 }
1123
167c2986d91b 6843629: Make current hotspot build part of jdk5 control build
phh
parents: 844
diff changeset
502 // guarantee(count == 0, "missing free blocks");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
503 }