annotate src/share/vm/memory/heap.cpp @ 14704:b51e29501f30

Merged with jdk9/dev/hotspot changeset 9486a41de3b7
author twisti
date Tue, 18 Mar 2014 20:19:10 -0700
parents d8041d695d19 480b0109db65
children 92aa6797d639
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;
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
46 _freelist_length = 0;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
47 }
a61af66fc99e Initial load
duke
parents:
diff changeset
48
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 void CodeHeap::mark_segmap_as_free(size_t beg, size_t end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
51 assert(0 <= beg && beg < _number_of_committed_segments, "interval begin out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
52 assert(beg < end && end <= _number_of_committed_segments, "interval end out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
53 // setup _segmap pointers for faster indexing
a61af66fc99e Initial load
duke
parents:
diff changeset
54 address p = (address)_segmap.low() + beg;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 address q = (address)_segmap.low() + end;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 // initialize interval
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
57 while (p < q) *p++ = free_sentinel;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
58 }
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 void CodeHeap::mark_segmap_as_used(size_t beg, size_t end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
62 assert(0 <= beg && beg < _number_of_committed_segments, "interval begin out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
63 assert(beg < end && end <= _number_of_committed_segments, "interval end out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // setup _segmap pointers for faster indexing
a61af66fc99e Initial load
duke
parents:
diff changeset
65 address p = (address)_segmap.low() + beg;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 address q = (address)_segmap.low() + end;
a61af66fc99e Initial load
duke
parents:
diff changeset
67 // initialize interval
a61af66fc99e Initial load
duke
parents:
diff changeset
68 int i = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 while (p < q) {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 *p++ = i++;
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
71 if (i == free_sentinel) i = 1;
0
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
a61af66fc99e Initial load
duke
parents:
diff changeset
76 static size_t align_to_page_size(size_t size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 const size_t alignment = (size_t)os::vm_page_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
78 assert(is_power_of_2(alignment), "no kidding ???");
a61af66fc99e Initial load
duke
parents:
diff changeset
79 return (size + alignment - 1) & ~(alignment - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
80 }
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 void CodeHeap::on_code_mapping(char* base, size_t size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 #ifdef LINUX
a61af66fc99e Initial load
duke
parents:
diff changeset
85 extern void linux_wrap_code(char* base, size_t size);
a61af66fc99e Initial load
duke
parents:
diff changeset
86 linux_wrap_code(base, size);
a61af66fc99e Initial load
duke
parents:
diff changeset
87 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
88 }
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 bool CodeHeap::reserve(size_t reserved_size, size_t committed_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
92 size_t segment_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 assert(reserved_size >= committed_size, "reserved < committed");
a61af66fc99e Initial load
duke
parents:
diff changeset
94 assert(segment_size >= sizeof(FreeBlock), "segment size is too small");
a61af66fc99e Initial load
duke
parents:
diff changeset
95 assert(is_power_of_2(segment_size), "segment_size must be a power of 2");
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97 _segment_size = segment_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
98 _log2_segment_size = exact_log2(segment_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 // Reserve and initialize space for _memory.
79
82db0859acbe 6642862: Code cache allocation fails with large pages after 6588638
jcoomes
parents: 0
diff changeset
101 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
102 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
103 os::vm_page_size();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
104 const size_t granularity = os::vm_allocation_granularity();
a61af66fc99e Initial load
duke
parents:
diff changeset
105 const size_t r_align = MAX2(page_size, granularity);
a61af66fc99e Initial load
duke
parents:
diff changeset
106 const size_t r_size = align_size_up(reserved_size, r_align);
a61af66fc99e Initial load
duke
parents:
diff changeset
107 const size_t c_size = align_size_up(committed_size, page_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 const size_t rs_align = page_size == (size_t) os::vm_page_size() ? 0 :
a61af66fc99e Initial load
duke
parents:
diff changeset
110 MAX2(page_size, granularity);
656
6bdd6923ba16 6541756: Reduce executable C-heap
coleenp
parents: 196
diff changeset
111 ReservedCodeSpace rs(r_size, rs_align, rs_align > 0);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
112 os::trace_page_sizes("code heap", committed_size, reserved_size, page_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
113 rs.base(), rs.size());
a61af66fc99e Initial load
duke
parents:
diff changeset
114 if (!_memory.initialize(rs, c_size)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 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
119 _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
120 _number_of_reserved_segments = size_to_segments(_memory.reserved_size());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
121 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
122 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
123 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
124 const size_t committed_segments_size = align_to_page_size(_number_of_committed_segments);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 // reserve space for _segmap
12056
740e263c80c6 8003424: Enable Class Data Sharing for CompressedOops
hseigel
parents: 10114
diff changeset
127 if (!_segmap.initialize(reserved_segments_size, committed_segments_size)) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
128 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 2426
diff changeset
130
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 2426
diff changeset
131 MemTracker::record_virtual_memory_type((address)_segmap.low_boundary(), mtCode);
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 2426
diff changeset
132
0
a61af66fc99e Initial load
duke
parents:
diff changeset
133 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
134 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
135 assert(_segmap.reserved_size() >= _segmap.committed_size() , "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137 // initialize remaining instance variables
a61af66fc99e Initial load
duke
parents:
diff changeset
138 clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
139 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
140 }
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 bool CodeHeap::expand_by(size_t size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 // expand _memory space
a61af66fc99e Initial load
duke
parents:
diff changeset
145 size_t dm = align_to_page_size(_memory.committed_size() + size) - _memory.committed_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
146 if (dm > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
147 char* base = _memory.low() + _memory.committed_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
148 if (!_memory.expand_by(dm)) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
149 on_code_mapping(base, dm);
a61af66fc99e Initial load
duke
parents:
diff changeset
150 size_t i = _number_of_committed_segments;
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
151 _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
152 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
153 assert(_number_of_reserved_segments >= _number_of_committed_segments, "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
154 // expand _segmap space
a61af66fc99e Initial load
duke
parents:
diff changeset
155 size_t ds = align_to_page_size(_number_of_committed_segments) - _segmap.committed_size();
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
156 if ((ds > 0) && !_segmap.expand_by(ds)) {
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
157 return false;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
158 }
a61af66fc99e Initial load
duke
parents:
diff changeset
159 assert(_segmap.committed_size() >= (size_t) _number_of_committed_segments, "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
160 // initialize additional segmap entries
a61af66fc99e Initial load
duke
parents:
diff changeset
161 mark_segmap_as_free(i, _number_of_committed_segments);
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 void CodeHeap::clear() {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 _next_segment = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
168 mark_segmap_as_free(0, _number_of_committed_segments);
a61af66fc99e Initial load
duke
parents:
diff changeset
169 }
a61af66fc99e Initial load
duke
parents:
diff changeset
170
a61af66fc99e Initial load
duke
parents:
diff changeset
171
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
172 void* CodeHeap::allocate(size_t instance_size, bool is_critical) {
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
173 size_t number_of_segments = size_to_segments(instance_size + header_size());
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
174 assert(segments_to_size(number_of_segments) >= sizeof(FreeBlock), "not enough room for FreeList");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
175
14309
63a4eb8bcd23 8025856: Fix typos in the GC code
jwilhelm
parents: 12056
diff changeset
176 // First check if we can satisfy request from freelist
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
177 NOT_PRODUCT(verify());
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
178 HeapBlock* block = search_freelist(number_of_segments, is_critical);
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
179 NOT_PRODUCT(verify());
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
180
0
a61af66fc99e Initial load
duke
parents:
diff changeset
181 if (block != NULL) {
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
182 assert(block->length() >= number_of_segments && block->length() < number_of_segments + CodeCacheMinBlockLength, "sanity check");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
183 assert(!block->free(), "must be marked free");
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
184 DEBUG_ONLY(memset((void*)block->allocated_space(), badCodeHeapNewVal, instance_size));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
185 return block->allocated_space();
a61af66fc99e Initial load
duke
parents:
diff changeset
186 }
a61af66fc99e Initial load
duke
parents:
diff changeset
187
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
188 // Ensure minimum size for allocation to the heap.
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
189 number_of_segments = MAX2((int)CodeCacheMinBlockLength, (int)number_of_segments);
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
190
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
191 if (!is_critical) {
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
192 // 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
193 // the CodeCacheMimimumFreeSpace that is reserved for critical allocations.
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
194 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
195 // Fail allocation
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
196 return NULL;
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
197 }
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
198 }
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
199
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
200 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
201 mark_segmap_as_used(_next_segment, _next_segment + number_of_segments);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
202 HeapBlock* b = block_at(_next_segment);
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
203 b->initialize(number_of_segments);
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
204 _next_segment += number_of_segments;
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
205 DEBUG_ONLY(memset((void *)b->allocated_space(), badCodeHeapNewVal, instance_size));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
206 return b->allocated_space();
a61af66fc99e Initial load
duke
parents:
diff changeset
207 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
208 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
209 }
a61af66fc99e Initial load
duke
parents:
diff changeset
210 }
a61af66fc99e Initial load
duke
parents:
diff changeset
211
a61af66fc99e Initial load
duke
parents:
diff changeset
212
a61af66fc99e Initial load
duke
parents:
diff changeset
213 void CodeHeap::deallocate(void* p) {
a61af66fc99e Initial load
duke
parents:
diff changeset
214 assert(p == find_start(p), "illegal deallocation");
a61af66fc99e Initial load
duke
parents:
diff changeset
215 // Find start of HeapBlock
a61af66fc99e Initial load
duke
parents:
diff changeset
216 HeapBlock* b = (((HeapBlock *)p) - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
217 assert(b->allocated_space() == p, "sanity check");
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
218 DEBUG_ONLY(memset((void *)b->allocated_space(), badCodeHeapFreeVal,
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
219 segments_to_size(b->length()) - sizeof(HeapBlock)));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
220 add_to_freelist(b);
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
221 NOT_PRODUCT(verify());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
222 }
a61af66fc99e Initial load
duke
parents:
diff changeset
223
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
224 /**
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
225 * Uses segment map to find the the start (header) of a nmethod. This works as follows:
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
226 * The memory of the code cache is divided into 'segments'. The size of a segment is
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
227 * determined by -XX:CodeCacheSegmentSize=XX. Allocation in the code cache can only
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
228 * happen at segment boundaries. A pointer in the code cache can be mapped to a segment
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
229 * by calling segment_for(addr). Each time memory is requested from the code cache,
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
230 * the segmap is updated accordingly. See the following example, which illustrates the
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
231 * state of code cache and the segment map: (seg -> segment, nm ->nmethod)
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
232 *
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
233 * code cache segmap
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
234 * ----------- ---------
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
235 * seg 1 | nm 1 | -> | 0 |
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
236 * seg 2 | nm 1 | -> | 1 |
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
237 * ... | nm 1 | -> | .. |
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
238 * seg m | nm 2 | -> | 0 |
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
239 * seg m+1 | nm 2 | -> | 1 |
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
240 * ... | nm 2 | -> | 2 |
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
241 * ... | nm 2 | -> | .. |
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
242 * ... | nm 2 | -> | 0xFE |
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
243 * seg m+n | nm 2 | -> | 1 |
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
244 * ... | nm 2 | -> | |
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
245 *
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
246 * A value of '0' in the segmap indicates that this segment contains the beginning of
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
247 * an nmethod. Let's walk through a simple example: If we want to find the start of
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
248 * an nmethod that falls into seg 2, we read the value of the segmap[2]. The value
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
249 * is an offset that points to the segment that contains the start of the nmethod.
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
250 * Another example: If we want to get the start of nm 2, and we happen to get a pointer
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
251 * that points to seg m+n, we first read seg[n+m], which returns '1'. So we have to
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
252 * do one more read of the segmap[m+n-1] to finally get the segment header.
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
253 */
0
a61af66fc99e Initial load
duke
parents:
diff changeset
254 void* CodeHeap::find_start(void* p) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
255 if (!contains(p)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
256 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
257 }
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
258 size_t seg_idx = segment_for(p);
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
259 address seg_map = (address)_segmap.low();
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
260 if (is_segment_unused(seg_map[seg_idx])) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
261 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
262 }
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
263 while (seg_map[seg_idx] > 0) {
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
264 seg_idx -= (int)seg_map[seg_idx];
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
265 }
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
266
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
267 HeapBlock* h = block_at(seg_idx);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
268 if (h->free()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
269 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
270 }
a61af66fc99e Initial load
duke
parents:
diff changeset
271 return h->allocated_space();
a61af66fc99e Initial load
duke
parents:
diff changeset
272 }
a61af66fc99e Initial load
duke
parents:
diff changeset
273
a61af66fc99e Initial load
duke
parents:
diff changeset
274
a61af66fc99e Initial load
duke
parents:
diff changeset
275 size_t CodeHeap::alignment_unit() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
276 // this will be a power of two
a61af66fc99e Initial load
duke
parents:
diff changeset
277 return _segment_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
278 }
a61af66fc99e Initial load
duke
parents:
diff changeset
279
a61af66fc99e Initial load
duke
parents:
diff changeset
280
a61af66fc99e Initial load
duke
parents:
diff changeset
281 size_t CodeHeap::alignment_offset() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
282 // The lowest address in any allocated block will be
a61af66fc99e Initial load
duke
parents:
diff changeset
283 // equal to alignment_offset (mod alignment_unit).
a61af66fc99e Initial load
duke
parents:
diff changeset
284 return sizeof(HeapBlock) & (_segment_size - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
285 }
a61af66fc99e Initial load
duke
parents:
diff changeset
286
a61af66fc99e Initial load
duke
parents:
diff changeset
287 // Finds the next free heapblock. If the current one is free, that it returned
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
288 void* CodeHeap::next_free(HeapBlock* b) const {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
289 // Since free blocks are merged, there is max. on free block
a61af66fc99e Initial load
duke
parents:
diff changeset
290 // between two used ones
a61af66fc99e Initial load
duke
parents:
diff changeset
291 if (b != NULL && b->free()) b = next_block(b);
a61af66fc99e Initial load
duke
parents:
diff changeset
292 assert(b == NULL || !b->free(), "must be in use or at end of heap");
a61af66fc99e Initial load
duke
parents:
diff changeset
293 return (b == NULL) ? NULL : b->allocated_space();
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 first used HeapBlock
a61af66fc99e Initial load
duke
parents:
diff changeset
297 HeapBlock* CodeHeap::first_block() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
298 if (_next_segment > 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
299 return block_at(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
300 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
301 }
a61af66fc99e Initial load
duke
parents:
diff changeset
302
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
303 HeapBlock* CodeHeap::block_start(void* q) const {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
304 HeapBlock* b = (HeapBlock*)find_start(q);
a61af66fc99e Initial load
duke
parents:
diff changeset
305 if (b == NULL) return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
306 return b - 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
307 }
a61af66fc99e Initial load
duke
parents:
diff changeset
308
a61af66fc99e Initial load
duke
parents:
diff changeset
309 // Returns the next Heap block an offset into one
a61af66fc99e Initial load
duke
parents:
diff changeset
310 HeapBlock* CodeHeap::next_block(HeapBlock *b) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
311 if (b == NULL) return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
312 size_t i = segment_for(b) + b->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
313 if (i < _next_segment)
a61af66fc99e Initial load
duke
parents:
diff changeset
314 return block_at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
315 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
316 }
a61af66fc99e Initial load
duke
parents:
diff changeset
317
a61af66fc99e Initial load
duke
parents:
diff changeset
318
a61af66fc99e Initial load
duke
parents:
diff changeset
319 // Returns current capacity
a61af66fc99e Initial load
duke
parents:
diff changeset
320 size_t CodeHeap::capacity() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
321 return _memory.committed_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
322 }
a61af66fc99e Initial load
duke
parents:
diff changeset
323
a61af66fc99e Initial load
duke
parents:
diff changeset
324 size_t CodeHeap::max_capacity() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
325 return _memory.reserved_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
326 }
a61af66fc99e Initial load
duke
parents:
diff changeset
327
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
328 int CodeHeap::allocated_segments() const {
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
329 return (int)_next_segment;
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
330 }
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
331
0
a61af66fc99e Initial load
duke
parents:
diff changeset
332 size_t CodeHeap::allocated_capacity() const {
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
333 // size of used heap - size on freelist
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
334 return segments_to_size(_next_segment - _freelist_segments);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
335 }
a61af66fc99e Initial load
duke
parents:
diff changeset
336
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
337 // Returns size of the unallocated heap block
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
338 size_t CodeHeap::heap_unallocated_capacity() const {
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
339 // Total number of segments - number currently used
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
340 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
341 }
51bd2d261853 7008325: CodeCache exhausted on sparc starting from hs20b04
kvn
parents: 1972
diff changeset
342
0
a61af66fc99e Initial load
duke
parents:
diff changeset
343 // Free list management
a61af66fc99e Initial load
duke
parents:
diff changeset
344
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
345 FreeBlock* CodeHeap::following_block(FreeBlock *b) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
346 return (FreeBlock*)(((address)b) + _segment_size * b->length());
a61af66fc99e Initial load
duke
parents:
diff changeset
347 }
a61af66fc99e Initial load
duke
parents:
diff changeset
348
a61af66fc99e Initial load
duke
parents:
diff changeset
349 // Inserts block b after a
a61af66fc99e Initial load
duke
parents:
diff changeset
350 void CodeHeap::insert_after(FreeBlock* a, FreeBlock* b) {
a61af66fc99e Initial load
duke
parents:
diff changeset
351 assert(a != NULL && b != NULL, "must be real pointers");
a61af66fc99e Initial load
duke
parents:
diff changeset
352
a61af66fc99e Initial load
duke
parents:
diff changeset
353 // Link b into the list after a
a61af66fc99e Initial load
duke
parents:
diff changeset
354 b->set_link(a->link());
a61af66fc99e Initial load
duke
parents:
diff changeset
355 a->set_link(b);
a61af66fc99e Initial load
duke
parents:
diff changeset
356
a61af66fc99e Initial load
duke
parents:
diff changeset
357 // See if we can merge blocks
a61af66fc99e Initial load
duke
parents:
diff changeset
358 merge_right(b); // Try to make b bigger
a61af66fc99e Initial load
duke
parents:
diff changeset
359 merge_right(a); // Try to make a include b
a61af66fc99e Initial load
duke
parents:
diff changeset
360 }
a61af66fc99e Initial load
duke
parents:
diff changeset
361
a61af66fc99e Initial load
duke
parents:
diff changeset
362 // Try to merge this block with the following block
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
363 bool CodeHeap::merge_right(FreeBlock* a) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
364 assert(a->free(), "must be a free block");
a61af66fc99e Initial load
duke
parents:
diff changeset
365 if (following_block(a) == a->link()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
366 assert(a->link() != NULL && a->link()->free(), "must be free too");
a61af66fc99e Initial load
duke
parents:
diff changeset
367 // Update block a to include the following block
a61af66fc99e Initial load
duke
parents:
diff changeset
368 a->set_length(a->length() + a->link()->length());
a61af66fc99e Initial load
duke
parents:
diff changeset
369 a->set_link(a->link()->link());
a61af66fc99e Initial load
duke
parents:
diff changeset
370 // Update find_start map
a61af66fc99e Initial load
duke
parents:
diff changeset
371 size_t beg = segment_for(a);
a61af66fc99e Initial load
duke
parents:
diff changeset
372 mark_segmap_as_used(beg, beg + a->length());
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
373 _freelist_length--;
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
374 return true;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
375 }
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
376 return false;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
377 }
a61af66fc99e Initial load
duke
parents:
diff changeset
378
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
379
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
380 void CodeHeap::add_to_freelist(HeapBlock* a) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
381 FreeBlock* b = (FreeBlock*)a;
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
382 _freelist_length++;
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
383
0
a61af66fc99e Initial load
duke
parents:
diff changeset
384 assert(b != _freelist, "cannot be removed twice");
a61af66fc99e Initial load
duke
parents:
diff changeset
385
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
386
0
a61af66fc99e Initial load
duke
parents:
diff changeset
387 // 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
388 _freelist_segments += b->length();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
389 b->set_free();
a61af66fc99e Initial load
duke
parents:
diff changeset
390
a61af66fc99e Initial load
duke
parents:
diff changeset
391 // First element in list?
a61af66fc99e Initial load
duke
parents:
diff changeset
392 if (_freelist == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
393 _freelist = b;
a61af66fc99e Initial load
duke
parents:
diff changeset
394 b->set_link(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
395 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
396 }
a61af66fc99e Initial load
duke
parents:
diff changeset
397
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
398 // Since the freelist is ordered (smaller addresses -> larger addresses) and the
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
399 // element we want to insert into the freelist has a smaller address than the first
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
400 // element, we can simply add 'b' as the first element and we are done.
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
401 if (b < _freelist) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
402 // Insert first in list
a61af66fc99e Initial load
duke
parents:
diff changeset
403 b->set_link(_freelist);
a61af66fc99e Initial load
duke
parents:
diff changeset
404 _freelist = b;
a61af66fc99e Initial load
duke
parents:
diff changeset
405 merge_right(_freelist);
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
406 return;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
407 }
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
408
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
409 // Scan for right place to put into list. List
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
410 // is sorted by increasing addresses
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
411 FreeBlock* prev = _freelist;
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
412 FreeBlock* cur = _freelist->link();
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
413 while(cur != NULL && cur < b) {
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
414 assert(prev < cur, "Freelist must be ordered");
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
415 prev = cur;
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
416 cur = cur->link();
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
417 }
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
418 assert((prev < b) && (cur == NULL || b < cur), "free-list must be ordered");
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
419 insert_after(prev, b);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
420 }
a61af66fc99e Initial load
duke
parents:
diff changeset
421
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
422 /**
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
423 * Search freelist for an entry on the list with the best fit.
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
424 * @return NULL, if no one was found
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
425 */
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
426 FreeBlock* CodeHeap::search_freelist(size_t length, bool is_critical) {
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
427 FreeBlock* found_block = NULL;
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
428 FreeBlock* found_prev = NULL;
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
429 size_t found_length = 0;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
430
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
431 FreeBlock* prev = NULL;
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
432 FreeBlock* cur = _freelist;
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
433 const size_t critical_boundary = (size_t)high_boundary() - CodeCacheMinimumFreeSpace;
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
434
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
435 // Search for first block that fits
0
a61af66fc99e Initial load
duke
parents:
diff changeset
436 while(cur != NULL) {
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
437 if (cur->length() >= length) {
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
438 // Non critical allocations are not allowed to use the last part of the code heap.
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
439 // Make sure the end of the allocation doesn't cross into the last part of the code heap.
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
440 if (!is_critical && (((size_t)cur + length) > critical_boundary)) {
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
441 // The freelist is sorted by address - if one fails, all consecutive will also fail.
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
442 break;
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
443 }
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
444 // Remember block, its previous element, and its length
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
445 found_block = cur;
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
446 found_prev = prev;
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
447 found_length = found_block->length();
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
448
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
449 break;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
450 }
a61af66fc99e Initial load
duke
parents:
diff changeset
451 // Next element in list
a61af66fc99e Initial load
duke
parents:
diff changeset
452 prev = cur;
a61af66fc99e Initial load
duke
parents:
diff changeset
453 cur = cur->link();
a61af66fc99e Initial load
duke
parents:
diff changeset
454 }
a61af66fc99e Initial load
duke
parents:
diff changeset
455
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
456 if (found_block == NULL) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
457 // None found
a61af66fc99e Initial load
duke
parents:
diff changeset
458 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
459 }
a61af66fc99e Initial load
duke
parents:
diff changeset
460
a61af66fc99e Initial load
duke
parents:
diff changeset
461 // Exact (or at least good enough) fit. Remove from list.
a61af66fc99e Initial load
duke
parents:
diff changeset
462 // Don't leave anything on the freelist smaller than CodeCacheMinBlockLength.
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
463 if (found_length - length < CodeCacheMinBlockLength) {
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
464 _freelist_length--;
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
465 length = found_length;
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
466 if (found_prev == NULL) {
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
467 assert(_freelist == found_block, "sanity check");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
468 _freelist = _freelist->link();
a61af66fc99e Initial load
duke
parents:
diff changeset
469 } else {
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
470 assert((found_prev->link() == found_block), "sanity check");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
471 // Unmap element
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
472 found_prev->set_link(found_block->link());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
473 }
a61af66fc99e Initial load
duke
parents:
diff changeset
474 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
475 // Truncate block and return a pointer to the following block
a61af66fc99e Initial load
duke
parents:
diff changeset
476 // Set used bit and length on new block
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
477 found_block->set_length(found_length - length);
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
478 found_block = following_block(found_block);
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
479
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
480 size_t beg = segment_for(found_block);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
481 mark_segmap_as_used(beg, beg + length);
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
482 found_block->set_length(length);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
483 }
a61af66fc99e Initial load
duke
parents:
diff changeset
484
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
485 found_block->set_used();
10114
a7fb14888912 8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents: 9060
diff changeset
486 _freelist_segments -= length;
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
487 return found_block;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
488 }
a61af66fc99e Initial load
duke
parents:
diff changeset
489
a61af66fc99e Initial load
duke
parents:
diff changeset
490 //----------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
491 // Non-product code
a61af66fc99e Initial load
duke
parents:
diff changeset
492
a61af66fc99e Initial load
duke
parents:
diff changeset
493 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
494
a61af66fc99e Initial load
duke
parents:
diff changeset
495 void CodeHeap::print() {
a61af66fc99e Initial load
duke
parents:
diff changeset
496 tty->print_cr("The Heap");
a61af66fc99e Initial load
duke
parents:
diff changeset
497 }
a61af66fc99e Initial load
duke
parents:
diff changeset
498
a61af66fc99e Initial load
duke
parents:
diff changeset
499 void CodeHeap::verify() {
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
500 if (VerifyCodeCache) {
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
501 size_t len = 0;
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
502 int count = 0;
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
503 for(FreeBlock* b = _freelist; b != NULL; b = b->link()) {
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
504 len += b->length();
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
505 count++;
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
506 // Check if we have merged all free blocks
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
507 assert(merge_right(b) == false, "Missed merging opportunity");
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
508 }
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
509 // Verify that freelist contains the right amount of free space
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
510 assert(len == _freelist_segments, "wrong freelist");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
511
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
512 for(HeapBlock* h = first_block(); h != NULL; h = next_block(h)) {
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
513 if (h->free()) count--;
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
514 }
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
515 // Verify that the freelist contains the same number of blocks
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
516 // than free blocks found on the full list.
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
517 assert(count == 0, "missing free blocks");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
518
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
519 // Verify that the number of free blocks is not out of hand.
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
520 static int free_block_threshold = 10000;
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
521 if (count > free_block_threshold) {
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
522 warning("CodeHeap: # of free blocks > %d", free_block_threshold);
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
523 // Double the warning limit
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
524 free_block_threshold *= 2;
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
525 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
526 }
a61af66fc99e Initial load
duke
parents:
diff changeset
527 }
14687
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
528
480b0109db65 8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents: 14309
diff changeset
529 #endif