author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 46674 | hotspot/src/share/vm/gc/cms/adaptiveFreeList.cpp@a9e42ff6158f |
child 49708 | 6709f13dccd3 |
permissions | -rw-r--r-- |
14123 | 1 |
/* |
46674
a9e42ff6158f
8183923: Get rid of FreeBlockDictionary and dithering
mgerdin
parents:
33105
diff
changeset
|
2 |
* Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved. |
14123 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
#include "precompiled.hpp" |
|
30764 | 26 |
#include "gc/cms/adaptiveFreeList.hpp" |
27 |
#include "gc/cms/freeChunk.hpp" |
|
28 |
#include "gc/shared/collectedHeap.hpp" |
|
14123 | 29 |
#include "runtime/globals.hpp" |
30 |
#include "runtime/mutex.hpp" |
|
25468
5331df506290
8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents:
24424
diff
changeset
|
31 |
#include "runtime/orderAccess.inline.hpp" |
14123 | 32 |
#include "runtime/vmThread.hpp" |
33 |
||
34 |
template <> |
|
35 |
void AdaptiveFreeList<FreeChunk>::print_on(outputStream* st, const char* c) const { |
|
36 |
if (c != NULL) { |
|
37 |
st->print("%16s", c); |
|
38 |
} else { |
|
39 |
st->print(SIZE_FORMAT_W(16), size()); |
|
40 |
} |
|
41 |
st->print("\t" |
|
42 |
SSIZE_FORMAT_W(14) "\t" SSIZE_FORMAT_W(14) "\t" SSIZE_FORMAT_W(14) "\t" SSIZE_FORMAT_W(14) "\t" SSIZE_FORMAT_W(14) "\t" |
|
43 |
SSIZE_FORMAT_W(14) "\t" SSIZE_FORMAT_W(14) "\t" SSIZE_FORMAT_W(14) "\t" SSIZE_FORMAT_W(14) "\t" SSIZE_FORMAT_W(14) "\n", |
|
44 |
bfr_surp(), surplus(), desired(), prev_sweep(), before_sweep(), |
|
45 |
count(), coal_births(), coal_deaths(), split_births(), split_deaths()); |
|
46 |
} |
|
47 |
||
48 |
template <class Chunk> |
|
49 |
AdaptiveFreeList<Chunk>::AdaptiveFreeList() : FreeList<Chunk>(), _hint(0) { |
|
50 |
init_statistics(); |
|
51 |
} |
|
52 |
||
53 |
template <class Chunk> |
|
54 |
void AdaptiveFreeList<Chunk>::initialize() { |
|
55 |
FreeList<Chunk>::initialize(); |
|
56 |
set_hint(0); |
|
57 |
init_statistics(true /* split_birth */); |
|
58 |
} |
|
59 |
||
60 |
template <class Chunk> |
|
61 |
void AdaptiveFreeList<Chunk>::reset(size_t hint) { |
|
62 |
FreeList<Chunk>::reset(); |
|
63 |
set_hint(hint); |
|
64 |
} |
|
65 |
||
66 |
template <class Chunk> |
|
67 |
void AdaptiveFreeList<Chunk>::init_statistics(bool split_birth) { |
|
68 |
_allocation_stats.initialize(split_birth); |
|
69 |
} |
|
70 |
||
71 |
template <class Chunk> |
|
72 |
size_t AdaptiveFreeList<Chunk>::get_better_size() { |
|
73 |
||
74 |
// A candidate chunk has been found. If it is already under |
|
75 |
// populated and there is a hinT, REturn the hint(). Else |
|
76 |
// return the size of this chunk. |
|
77 |
if (surplus() <= 0) { |
|
78 |
if (hint() != 0) { |
|
79 |
return hint(); |
|
80 |
} else { |
|
81 |
return size(); |
|
82 |
} |
|
83 |
} else { |
|
84 |
// This list has a surplus so use it. |
|
85 |
return size(); |
|
86 |
} |
|
87 |
} |
|
88 |
||
89 |
||
90 |
template <class Chunk> |
|
91 |
void AdaptiveFreeList<Chunk>::return_chunk_at_head(Chunk* chunk) { |
|
92 |
assert_proper_lock_protection(); |
|
93 |
return_chunk_at_head(chunk, true); |
|
94 |
} |
|
95 |
||
96 |
template <class Chunk> |
|
97 |
void AdaptiveFreeList<Chunk>::return_chunk_at_head(Chunk* chunk, bool record_return) { |
|
98 |
FreeList<Chunk>::return_chunk_at_head(chunk, record_return); |
|
99 |
#ifdef ASSERT |
|
100 |
if (record_return) { |
|
101 |
increment_returned_bytes_by(size()*HeapWordSize); |
|
102 |
} |
|
103 |
#endif |
|
104 |
} |
|
105 |
||
106 |
template <class Chunk> |
|
107 |
void AdaptiveFreeList<Chunk>::return_chunk_at_tail(Chunk* chunk) { |
|
22827 | 108 |
AdaptiveFreeList<Chunk>::return_chunk_at_tail(chunk, true); |
14123 | 109 |
} |
110 |
||
111 |
template <class Chunk> |
|
112 |
void AdaptiveFreeList<Chunk>::return_chunk_at_tail(Chunk* chunk, bool record_return) { |
|
113 |
FreeList<Chunk>::return_chunk_at_tail(chunk, record_return); |
|
114 |
#ifdef ASSERT |
|
115 |
if (record_return) { |
|
116 |
increment_returned_bytes_by(size()*HeapWordSize); |
|
117 |
} |
|
118 |
#endif |
|
119 |
} |
|
120 |
||
121 |
#ifndef PRODUCT |
|
122 |
template <class Chunk> |
|
123 |
void AdaptiveFreeList<Chunk>::verify_stats() const { |
|
124 |
// The +1 of the LH comparand is to allow some "looseness" in |
|
125 |
// checking: we usually call this interface when adding a block |
|
126 |
// and we'll subsequently update the stats; we cannot update the |
|
127 |
// stats beforehand because in the case of the large-block BT |
|
128 |
// dictionary for example, this might be the first block and |
|
129 |
// in that case there would be no place that we could record |
|
130 |
// the stats (which are kept in the block itself). |
|
131 |
assert((_allocation_stats.prev_sweep() + _allocation_stats.split_births() |
|
132 |
+ _allocation_stats.coal_births() + 1) // Total Production Stock + 1 |
|
133 |
>= (_allocation_stats.split_deaths() + _allocation_stats.coal_deaths() |
|
134 |
+ (ssize_t)count()), // Total Current Stock + depletion |
|
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
30764
diff
changeset
|
135 |
"FreeList " PTR_FORMAT " of size " SIZE_FORMAT |
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
30764
diff
changeset
|
136 |
" violates Conservation Principle: " |
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
30764
diff
changeset
|
137 |
"prev_sweep(" SIZE_FORMAT ")" |
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
30764
diff
changeset
|
138 |
" + split_births(" SIZE_FORMAT ")" |
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
30764
diff
changeset
|
139 |
" + coal_births(" SIZE_FORMAT ") + 1 >= " |
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
30764
diff
changeset
|
140 |
" split_deaths(" SIZE_FORMAT ")" |
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
30764
diff
changeset
|
141 |
" coal_deaths(" SIZE_FORMAT ")" |
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
30764
diff
changeset
|
142 |
" + count(" SSIZE_FORMAT ")", |
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
30764
diff
changeset
|
143 |
p2i(this), size(), _allocation_stats.prev_sweep(), _allocation_stats.split_births(), |
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
30764
diff
changeset
|
144 |
_allocation_stats.coal_births(), _allocation_stats.split_deaths(), |
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
30764
diff
changeset
|
145 |
_allocation_stats.coal_deaths(), count()); |
14123 | 146 |
} |
147 |
#endif |
|
148 |
||
149 |
// Needs to be after the definitions have been seen. |
|
150 |
template class AdaptiveFreeList<FreeChunk>; |