1/*
2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
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"
26#include "gc/shared/generation.hpp"
27#include "gc/shared/genMemoryPools.hpp"
28#include "gc/shared/space.hpp"
29#if INCLUDE_SERIALGC
30#include "gc/serial/defNewGeneration.hpp"
31#endif
32
33ContiguousSpacePool::ContiguousSpacePool(ContiguousSpace* space,
34 const char* name,
35 size_t max_size,
36 bool support_usage_threshold) :
37 CollectedMemoryPool(name, space->capacity(), max_size,
38 support_usage_threshold), _space(space) {
39}
40
41size_t ContiguousSpacePool::used_in_bytes() {
42 return space()->used();
43}
44
45MemoryUsage ContiguousSpacePool::get_memory_usage() {
46 size_t maxSize = (available_for_allocation() ? max_size() : 0);
47 size_t used = used_in_bytes();
48 size_t committed = _space->capacity();
49
50 return MemoryUsage(initial_size(), used, committed, maxSize);
51}
52
53#if INCLUDE_SERIALGC
54
55SurvivorContiguousSpacePool::SurvivorContiguousSpacePool(DefNewGeneration* young_gen,
56 const char* name,
57 size_t max_size,
58 bool support_usage_threshold) :
59 CollectedMemoryPool(name, young_gen->from()->capacity(), max_size,
60 support_usage_threshold), _young_gen(young_gen) {
61}
62
63size_t SurvivorContiguousSpacePool::used_in_bytes() {
64 return _young_gen->from()->used();
65}
66
67size_t SurvivorContiguousSpacePool::committed_in_bytes() {
68 return _young_gen->from()->capacity();
69}
70
71MemoryUsage SurvivorContiguousSpacePool::get_memory_usage() {
72 size_t maxSize = (available_for_allocation() ? max_size() : 0);
73 size_t used = used_in_bytes();
74 size_t committed = committed_in_bytes();
75
76 return MemoryUsage(initial_size(), used, committed, maxSize);
77}
78
79#endif // INCLUDE_SERIALGC
80
81GenerationPool::GenerationPool(Generation* gen,
82 const char* name,
83 bool support_usage_threshold) :
84 CollectedMemoryPool(name, gen->capacity(), gen->max_capacity(),
85 support_usage_threshold), _gen(gen) {
86}
87
88size_t GenerationPool::used_in_bytes() {
89 return _gen->used();
90}
91
92MemoryUsage GenerationPool::get_memory_usage() {
93 size_t used = used_in_bytes();
94 size_t committed = _gen->capacity();
95 size_t maxSize = (available_for_allocation() ? max_size() : 0);
96
97 return MemoryUsage(initial_size(), used, committed, maxSize);
98}
99