|
1 /* |
|
2 * Copyright (c) 2019, SAP SE. All rights reserved. |
|
3 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
|
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
5 * |
|
6 * This code is free software; you can redistribute it and/or modify it |
|
7 * under the terms of the GNU General Public License version 2 only, as |
|
8 * published by the Free Software Foundation. |
|
9 * |
|
10 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 * version 2 for more details (a copy is included in the LICENSE file that |
|
14 * accompanied this code). |
|
15 * |
|
16 * You should have received a copy of the GNU General Public License version |
|
17 * 2 along with this work; if not, write to the Free Software Foundation, |
|
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 * |
|
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
21 * or visit www.oracle.com if you need additional information or have any |
|
22 * questions. |
|
23 * |
|
24 */ |
|
25 #include "precompiled.hpp" |
|
26 #include "memory/metaspace/chunkHeaderPool.hpp" |
|
27 #include "runtime/os.hpp" |
|
28 #include "utilities/debug.hpp" |
|
29 #include "utilities/globalDefinitions.hpp" |
|
30 |
|
31 namespace metaspace { |
|
32 |
|
33 |
|
34 // Returns reference to the one global chunk header pool. |
|
35 ChunkHeaderPool ChunkHeaderPool::_chunkHeaderPool(false); |
|
36 |
|
37 |
|
38 ChunkHeaderPool::ChunkHeaderPool(bool delete_on_destruction) |
|
39 : _num_slabs(), _first_slab(NULL), _current_slab(NULL), _delete_on_destruction(delete_on_destruction) |
|
40 { |
|
41 } |
|
42 |
|
43 ChunkHeaderPool::~ChunkHeaderPool() { |
|
44 if (_delete_on_destruction) { |
|
45 // This is only done when tests are running, but not for the global chunk pool, |
|
46 // since that is supposed to live until the process ends. |
|
47 slab_t* s = _first_slab; |
|
48 while (s != NULL) { |
|
49 slab_t* next_slab = s->next; |
|
50 os::free(s); |
|
51 s = next_slab; |
|
52 } |
|
53 } |
|
54 } |
|
55 |
|
56 void ChunkHeaderPool::allocate_new_slab() { |
|
57 slab_t* slab = (slab_t*)os::malloc(sizeof(slab_t), mtInternal); |
|
58 memset(slab, 0, sizeof(slab_t)); |
|
59 if (_current_slab != NULL) { |
|
60 _current_slab->next = slab; |
|
61 } |
|
62 _current_slab = slab; |
|
63 if (_first_slab == NULL) { |
|
64 _first_slab = slab; |
|
65 } |
|
66 _num_slabs.increment(); |
|
67 } |
|
68 |
|
69 // Returns size of memory used. |
|
70 size_t ChunkHeaderPool::memory_footprint_words() const { |
|
71 return (_num_slabs.get() * sizeof(slab_t)) / BytesPerWord; |
|
72 } |
|
73 |
|
74 #ifdef ASSERT |
|
75 void ChunkHeaderPool::verify(bool slow) const { |
|
76 const slab_t* s = _first_slab; |
|
77 int num = 0; |
|
78 while (s != NULL) { |
|
79 assert(s->top >= 0 && s->top <= slab_capacity, |
|
80 "invalid slab at " PTR_FORMAT ", top: %d, slab cap: %d", |
|
81 p2i(s), s->top, slab_capacity ); |
|
82 s = s->next; |
|
83 num ++; |
|
84 } |
|
85 _num_slabs.check(num); |
|
86 } |
|
87 #endif |
|
88 |
|
89 } // namespace metaspace |
|
90 |
|
91 |