author | stuefe |
Mon, 08 Jul 2019 22:30:19 +0200 | |
branch | stuefe-improved-metaspace |
changeset 57464 | 32e61f51ee09 |
parent 54623 | 1126f0607c70 |
permissions | -rw-r--r-- |
50193 | 1 |
/* |
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
53970
diff
changeset
|
2 |
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. |
50193 | 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 |
#include "precompiled.hpp" |
|
25 |
||
57464 | 26 |
|
27 |
#include "memory/metaspace/chunkAllocSequence.hpp" |
|
28 |
#include "memory/metaspace/chunkLevel.hpp" |
|
50193 | 29 |
#include "memory/metaspace/chunkManager.hpp" |
30 |
#include "memory/metaspace/metachunk.hpp" |
|
31 |
#include "runtime/mutexLocker.hpp" |
|
32 |
#include "utilities/debug.hpp" |
|
33 |
#include "utilities/globalDefinitions.hpp" |
|
34 |
||
35 |
namespace metaspace { |
|
36 |
||
57464 | 37 |
// Creates a chunk manager with a given name (which is for debug purposes only) |
38 |
// and an associated space list which will be used to request new chunks from |
|
39 |
// (see get_chunk()) |
|
40 |
ChunkManager::ChunkManager(const char* name, VirtualSpaceList* space_list) |
|
41 |
: _vs_list(space_list) |
|
42 |
, _name(name) |
|
43 |
, _chunks {} |
|
44 |
, _num_chunks {} |
|
45 |
, _total_word_size(0) |
|
46 |
, _total_num_chunks(0) |
|
47 |
{ |
|
48 |
} |
|
49 |
||
50 |
void ChunkManager::account_for_added_chunk(const Metachunk* c) { |
|
51 |
assert_lock_strong(MetaspaceExpand_lock); |
|
52 |
||
53 |
const chklvl_t lvl = c->level(); |
|
54 |
check_valid_level(lvl); |
|
55 |
||
56 |
_total_num_chunks ++; |
|
57 |
_total_word_size += word_size_for_level(lvl); |
|
58 |
_num_chunks[lvl] ++; |
|
50380
bec342339138
8204195: Clean up macroAssembler.inline.hpp and other inline.hpp files included in .hpp files
coleenp
parents:
50193
diff
changeset
|
59 |
} |
bec342339138
8204195: Clean up macroAssembler.inline.hpp and other inline.hpp files included in .hpp files
coleenp
parents:
50193
diff
changeset
|
60 |
|
57464 | 61 |
void ChunkManager::account_for_removed_chunk(const Metachunk* c) { |
62 |
assert_lock_strong(MetaspaceExpand_lock); |
|
63 |
||
64 |
const chklvl_t lvl = c->level(); |
|
65 |
check_valid_level(lvl); |
|
66 |
||
67 |
assert(_total_num_chunks > 0, "Sanity."); |
|
68 |
_total_num_chunks --; |
|
69 |
const size_t word_size = word_size_for_level(lvl); |
|
70 |
assert(_total_word_size >= word_size, "Sanity."); |
|
71 |
_total_word_size -= word_size_for_level(lvl); |
|
72 |
assert(_num_chunks[lvl] > 0, "Sanity."); |
|
73 |
_num_chunks[lvl] --; |
|
74 |
} |
|
75 |
||
76 |
||
77 |
// Remove a chunk of the given level from its freelist, and adjust accounting. |
|
78 |
// If no chunk of this given level is free, return NULL. |
|
79 |
Metachunk* ChunkManager::get_chunk_simple(chklvl_t level) { |
|
80 |
||
81 |
assert_lock_strong(MetaspaceExpand_lock); |
|
82 |
check_valid_level(level); |
|
83 |
||
84 |
Metachunk* c = _chunks[level]; |
|
85 |
if (c != NULL) { |
|
86 |
account_for_removed_chunk(c); |
|
87 |
} |
|
88 |
return c; |
|
89 |
||
90 |
} |
|
91 |
||
92 |
||
93 |
||
94 |
||
95 |
// Return a chunk to the ChunkManager and adjust accounting. May merge chunk |
|
96 |
// with neighbors. |
|
97 |
// Happens after a Classloader was unloaded and releases its metaspace chunks. |
|
98 |
// !! Note: this may invalidate the chunk. Do not access the chunk after |
|
99 |
// this function returns !! |
|
100 |
void ChunkManager::return_chunk(Metachunk* chunk) { |
|
101 |
||
102 |
||
103 |
} |
|
104 |
||
105 |
||
106 |
// Remove the given chunk from its free list and adjust accounting. |
|
107 |
// (Called during VirtualSpaceNode purging which happens during a Metaspace GC.) |
|
50193 | 108 |
void ChunkManager::remove_chunk(Metachunk* chunk) { |
57464 | 109 |
assert_lock_strong(MetaspaceExpand_lock); |
110 |
chunk->remove_from_list(); |
|
50193 | 111 |
account_for_removed_chunk(chunk); |
112 |
} |
|
113 |
||
114 |
||
115 |
||
116 |
||
117 |
} // namespace metaspace |
|
118 |
||
119 |
||
120 |