tonyp@1524: /* trims@1907: * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. tonyp@1524: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. tonyp@1524: * tonyp@1524: * This code is free software; you can redistribute it and/or modify it tonyp@1524: * under the terms of the GNU General Public License version 2 only, as tonyp@1524: * published by the Free Software Foundation. tonyp@1524: * tonyp@1524: * This code is distributed in the hope that it will be useful, but WITHOUT tonyp@1524: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or tonyp@1524: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License tonyp@1524: * version 2 for more details (a copy is included in the LICENSE file that tonyp@1524: * accompanied this code). tonyp@1524: * tonyp@1524: * You should have received a copy of the GNU General Public License version tonyp@1524: * 2 along with this work; if not, write to the Free Software Foundation, tonyp@1524: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. tonyp@1524: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. tonyp@1524: * tonyp@1524: */ tonyp@1524: stefank@2314: #include "precompiled.hpp" stefank@2314: #include "gc_implementation/g1/g1CollectedHeap.hpp" stefank@2314: #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" stefank@2314: #include "gc_implementation/g1/g1CollectorPolicy.hpp" stefank@2314: #include "gc_implementation/g1/heapRegion.hpp" stefank@2314: #include "services/g1MemoryPool.hpp" tonyp@1524: tonyp@1524: G1MemoryPoolSuper::G1MemoryPoolSuper(G1CollectedHeap* g1h, tonyp@1524: const char* name, tonyp@1524: size_t init_size, tonyp@1524: bool support_usage_threshold) : tonyp@1524: _g1h(g1h), CollectedMemoryPool(name, tonyp@1524: MemoryPool::Heap, tonyp@1524: init_size, tonyp@2109: undefined_max(), tonyp@1524: support_usage_threshold) { tonyp@1524: assert(UseG1GC, "sanity"); tonyp@1524: } tonyp@1524: tonyp@1524: // See the comment at the top of g1MemoryPool.hpp tonyp@1524: size_t G1MemoryPoolSuper::eden_space_committed(G1CollectedHeap* g1h) { tonyp@1529: return MAX2(eden_space_used(g1h), (size_t) HeapRegion::GrainBytes); tonyp@1524: } tonyp@1524: tonyp@1524: // See the comment at the top of g1MemoryPool.hpp tonyp@1524: size_t G1MemoryPoolSuper::eden_space_used(G1CollectedHeap* g1h) { johnc@1829: size_t young_list_length = g1h->young_list()->length(); tonyp@1524: size_t eden_used = young_list_length * HeapRegion::GrainBytes; tonyp@1524: size_t survivor_used = survivor_space_used(g1h); tonyp@1524: eden_used = subtract_up_to_zero(eden_used, survivor_used); tonyp@1524: return eden_used; tonyp@1524: } tonyp@1524: tonyp@1524: // See the comment at the top of g1MemoryPool.hpp tonyp@1524: size_t G1MemoryPoolSuper::survivor_space_committed(G1CollectedHeap* g1h) { tonyp@1529: return MAX2(survivor_space_used(g1h), (size_t) HeapRegion::GrainBytes); tonyp@1524: } tonyp@1524: tonyp@1524: // See the comment at the top of g1MemoryPool.hpp tonyp@1524: size_t G1MemoryPoolSuper::survivor_space_used(G1CollectedHeap* g1h) { tonyp@1524: size_t survivor_num = g1h->g1_policy()->recorded_survivor_regions(); tonyp@1524: size_t survivor_used = survivor_num * HeapRegion::GrainBytes; tonyp@1524: return survivor_used; tonyp@1524: } tonyp@1524: tonyp@1524: // See the comment at the top of g1MemoryPool.hpp tonyp@1524: size_t G1MemoryPoolSuper::old_space_committed(G1CollectedHeap* g1h) { tonyp@1524: size_t committed = overall_committed(g1h); tonyp@1524: size_t eden_committed = eden_space_committed(g1h); tonyp@1524: size_t survivor_committed = survivor_space_committed(g1h); tonyp@1524: committed = subtract_up_to_zero(committed, eden_committed); tonyp@1524: committed = subtract_up_to_zero(committed, survivor_committed); tonyp@1529: committed = MAX2(committed, (size_t) HeapRegion::GrainBytes); tonyp@1524: return committed; tonyp@1524: } tonyp@1524: tonyp@1524: // See the comment at the top of g1MemoryPool.hpp tonyp@1524: size_t G1MemoryPoolSuper::old_space_used(G1CollectedHeap* g1h) { tonyp@1524: size_t used = overall_used(g1h); tonyp@1524: size_t eden_used = eden_space_used(g1h); tonyp@1524: size_t survivor_used = survivor_space_used(g1h); tonyp@1524: used = subtract_up_to_zero(used, eden_used); tonyp@1524: used = subtract_up_to_zero(used, survivor_used); tonyp@1524: return used; tonyp@1524: } tonyp@1524: tonyp@1524: G1EdenPool::G1EdenPool(G1CollectedHeap* g1h) : tonyp@1524: G1MemoryPoolSuper(g1h, tonyp@1524: "G1 Eden", tonyp@1524: eden_space_committed(g1h), /* init_size */ tonyp@2109: false /* support_usage_threshold */) { } tonyp@1524: tonyp@1524: MemoryUsage G1EdenPool::get_memory_usage() { tonyp@1527: size_t initial_sz = initial_size(); tonyp@1527: size_t max_sz = max_size(); tonyp@1527: size_t used = used_in_bytes(); tonyp@1528: size_t committed = eden_space_committed(_g1h); tonyp@1524: tonyp@1527: return MemoryUsage(initial_sz, used, committed, max_sz); tonyp@1524: } tonyp@1524: tonyp@1524: G1SurvivorPool::G1SurvivorPool(G1CollectedHeap* g1h) : tonyp@1524: G1MemoryPoolSuper(g1h, tonyp@1524: "G1 Survivor", tonyp@1524: survivor_space_committed(g1h), /* init_size */ tonyp@2109: false /* support_usage_threshold */) { } tonyp@1524: tonyp@1524: MemoryUsage G1SurvivorPool::get_memory_usage() { tonyp@1527: size_t initial_sz = initial_size(); tonyp@1527: size_t max_sz = max_size(); tonyp@1527: size_t used = used_in_bytes(); tonyp@1528: size_t committed = survivor_space_committed(_g1h); tonyp@1524: tonyp@1527: return MemoryUsage(initial_sz, used, committed, max_sz); tonyp@1524: } tonyp@1524: tonyp@1524: G1OldGenPool::G1OldGenPool(G1CollectedHeap* g1h) : tonyp@1524: G1MemoryPoolSuper(g1h, tonyp@1524: "G1 Old Gen", tonyp@1524: old_space_committed(g1h), /* init_size */ tonyp@2109: true /* support_usage_threshold */) { } tonyp@1524: tonyp@1524: MemoryUsage G1OldGenPool::get_memory_usage() { tonyp@1527: size_t initial_sz = initial_size(); tonyp@1527: size_t max_sz = max_size(); tonyp@1527: size_t used = used_in_bytes(); tonyp@1528: size_t committed = old_space_committed(_g1h); tonyp@1524: tonyp@1527: return MemoryUsage(initial_sz, used, committed, max_sz); tonyp@1524: }