author | stuefe |
Mon, 08 Jul 2019 22:30:19 +0200 | |
branch | stuefe-improved-metaspace |
changeset 57464 | 32e61f51ee09 |
parent 53244 | 9807daeb47c4 |
permissions | -rw-r--r-- |
50193 | 1 |
/* |
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50193
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 |
||
25 |
#ifndef SHARE_MEMORY_METASPACE_SPACEMANAGER_HPP |
|
26 |
#define SHARE_MEMORY_METASPACE_SPACEMANAGER_HPP |
|
27 |
||
28 |
#include "memory/allocation.hpp" |
|
29 |
#include "memory/metaspace.hpp" |
|
30 |
#include "memory/metaspace/blockFreelist.hpp" |
|
57464 | 31 |
#include "memory/metaspace/chunkAllocSequence.hpp" |
32 |
#include "memory/metaspace/chunkManager.hpp" |
|
50193 | 33 |
#include "memory/metaspace/metaspaceCommon.hpp" |
34 |
||
35 |
class outputStream; |
|
36 |
class Mutex; |
|
37 |
||
38 |
namespace metaspace { |
|
39 |
||
57464 | 40 |
|
41 |
// The SpaceManager: |
|
42 |
// - keeps a list of chunks-in-use by the class loader, as well as a current chunk used |
|
43 |
// to allocate from |
|
44 |
// - keeps a dictionary of free MetaBlocks. Those can be remnants of a retired chunk or |
|
45 |
// allocations which were not needed anymore for some reason (e.g. releasing half-allocated |
|
46 |
// structures when class loading fails) |
|
47 |
||
50193 | 48 |
class SpaceManager : public CHeapObj<mtClass> { |
49 |
||
57464 | 50 |
// Lock handed down from the associated ClassLoaderData. |
51 |
// Protects allocations from this space. |
|
50193 | 52 |
Mutex* const _lock; |
53 |
||
57464 | 54 |
// The chunk manager to allocate chunks from. |
55 |
ChunkManager* const _chunk_manager; |
|
50193 | 56 |
|
57464 | 57 |
// The chunk allocation strategy to use. |
58 |
const ChunkAllocSequence* const _chunk_alloc_sequence; |
|
50193 | 59 |
|
60 |
// List of chunks in use by this SpaceManager. Allocations |
|
61 |
// are done from the current chunk. The list is used for deallocating |
|
62 |
// chunks when the SpaceManager is freed. |
|
57464 | 63 |
Metachunk* _first_chunk; |
50193 | 64 |
Metachunk* _current_chunk; |
65 |
||
57464 | 66 |
// Prematurely released metablocks. |
67 |
BlockFreelist* _block_freelist; |
|
50193 | 68 |
|
69 |
||
57464 | 70 |
// Statistics |
50193 | 71 |
|
57464 | 72 |
// Running counters. |
50193 | 73 |
// Note: capacity = used + free + waste + overhead. We do not keep running counters for |
74 |
// free and waste. Their sum can be deduced from the three other values. |
|
75 |
size_t _overhead_words; |
|
76 |
size_t _capacity_words; |
|
77 |
size_t _used_words; |
|
57464 | 78 |
uint32_t _num_chunks_by_type[NUM_CHUNK_LEVELS]; |
50193 | 79 |
|
80 |
||
57464 | 81 |
Mutex* lock() const { return _lock; } |
82 |
ChunkManager* chunk_manager() const { return _chunk_manager; } |
|
83 |
const ChunkAllocSequence* chunk_alloc_sequence() const { return _chunk_alloc_sequence; } |
|
50193 | 84 |
|
57464 | 85 |
Metachunk* first_chunk() { return _first_chunk; } |
86 |
BlockFreelist* block_freelist(); // created on demand only |
|
50193 | 87 |
|
57464 | 88 |
// The current chunk is unable to service a request. The remainder of the chunk is |
89 |
// chopped into blocks and fed into the _block_freelists, in the hope of later reuse. |
|
50193 | 90 |
void retire_current_chunk(); |
91 |
||
57464 | 92 |
public: |
50193 | 93 |
|
57464 | 94 |
SpaceManager(ChunkManager* chunk_manager, const ChunkAllocSequence* alloc_sequence, Mutex* lock); |
50193 | 95 |
|
96 |
~SpaceManager(); |
|
97 |
||
57464 | 98 |
// Allocate memory from Metaspace. Will attempt to allocate from the _block_freelists, |
99 |
// failing that, from the current chunk; failing that, attempt to get a new chunk from |
|
100 |
// the associated ChunkManager. |
|
50193 | 101 |
MetaWord* allocate(size_t word_size); |
102 |
||
57464 | 103 |
// Prematurely returns a metaspace allocation to the _block_freelists because it is not |
104 |
// needed anymore. |
|
50193 | 105 |
void deallocate(MetaWord* p, size_t word_size); |
106 |
||
57464 | 107 |
// Run verifications. slow=true: verify chunk-internal integrity too. |
108 |
DEBUG_ONLY(void locked_verify(bool slow) const;) |
|
50193 | 109 |
|
110 |
}; |
|
111 |
||
112 |
} // namespace metaspace |
|
113 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50193
diff
changeset
|
114 |
#endif // SHARE_MEMORY_METASPACE_SPACEMANAGER_HPP |