< prev index next >

src/hotspot/share/gc/shenandoah/shenandoahMemoryPool.cpp

Print this page

  1 /*
  2  * Copyright (c) 2013, 2019, Red Hat, Inc. 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/shenandoah/shenandoahMemoryPool.hpp"


 27 
 28 ShenandoahMemoryPool::ShenandoahMemoryPool(ShenandoahHeap* heap) :
 29         CollectedMemoryPool("Shenandoah",

 30                             heap->initial_capacity(),
 31                             heap->max_capacity(),
 32                             true /* support_usage_threshold */),
 33                             _heap(heap) {}
 34 











 35 MemoryUsage ShenandoahMemoryPool::get_memory_usage() {
 36   size_t initial   = initial_size();
 37   size_t max       = max_size();
 38   size_t used      = used_in_bytes();
 39   size_t committed = _heap->committed();
 40 
 41   // These asserts can never fail: max is stable, and all updates to other values never overflow max.
 42   assert(initial <= max,    "initial: "   SIZE_FORMAT ", max: "       SIZE_FORMAT, initial,   max);
 43   assert(used <= max,       "used: "      SIZE_FORMAT ", max: "       SIZE_FORMAT, used,      max);
 44   assert(committed <= max,  "committed: " SIZE_FORMAT ", max: "       SIZE_FORMAT, committed, max);
 45 
 46   // Committed and used are updated concurrently and independently. They can momentarily break
 47   // the assert below, which would also fail in downstream code. To avoid that, adjust values
 48   // to make sense under the race. See JDK-8207200.
 49   committed = MAX2(used, committed);
 50   assert(used <= committed, "used: "      SIZE_FORMAT ", committed: " SIZE_FORMAT, used,      committed);
 51 
 52   return MemoryUsage(initial, used, committed, max);
 53 }























































  1 /*
  2  * Copyright (c) 2013, 2019, Red Hat, Inc. All rights reserved.
  3  * Copyright Amazon.com Inc. 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 
 26 #include "precompiled.hpp"
 27 #include "gc/shenandoah/shenandoahMemoryPool.hpp"
 28 #include "gc/shenandoah/shenandoahYoungGeneration.hpp"
 29 #include "gc/shenandoah/shenandoahOldGeneration.hpp"
 30 
 31 ShenandoahMemoryPool::ShenandoahMemoryPool(ShenandoahHeap* heap,
 32                                            const char* name) :
 33         CollectedMemoryPool(name,
 34                             heap->initial_capacity(),
 35                             heap->max_capacity(),
 36                             true /* support_usage_threshold */),
 37                             _heap(heap) {}
 38 
 39 ShenandoahMemoryPool::ShenandoahMemoryPool(ShenandoahHeap* heap,
 40                                            const char* name,
 41                                            size_t initial_capacity,
 42                                            size_t max_capacity) :
 43         CollectedMemoryPool(name,
 44                             initial_capacity,
 45                             max_capacity,
 46                             true /* support_usage_threshold */),
 47                             _heap(heap) {}
 48 
 49 
 50 MemoryUsage ShenandoahMemoryPool::get_memory_usage() {
 51   size_t initial   = initial_size();
 52   size_t max       = max_size();
 53   size_t used      = used_in_bytes();
 54   size_t committed = _heap->committed();
 55 
 56   // These asserts can never fail: max is stable, and all updates to other values never overflow max.
 57   assert(initial <= max,    "initial: "   SIZE_FORMAT ", max: "       SIZE_FORMAT, initial,   max);
 58   assert(used <= max,       "used: "      SIZE_FORMAT ", max: "       SIZE_FORMAT, used,      max);
 59   assert(committed <= max,  "committed: " SIZE_FORMAT ", max: "       SIZE_FORMAT, committed, max);
 60 
 61   // Committed and used are updated concurrently and independently. They can momentarily break
 62   // the assert below, which would also fail in downstream code. To avoid that, adjust values
 63   // to make sense under the race. See JDK-8207200.
 64   committed = MAX2(used, committed);
 65   assert(used <= committed, "used: "      SIZE_FORMAT ", committed: " SIZE_FORMAT, used,      committed);
 66 
 67   return MemoryUsage(initial, used, committed, max);
 68 }
 69 
 70 size_t ShenandoahMemoryPool::used_in_bytes() {
 71   return _heap->used();
 72 }
 73 
 74 size_t ShenandoahMemoryPool::max_size() const {
 75   return _heap->max_capacity();
 76 }
 77 
 78 ShenandoahYoungGenMemoryPool::ShenandoahYoungGenMemoryPool(ShenandoahHeap* heap) :
 79         ShenandoahMemoryPool(heap,
 80                              "Shenandoah Young Gen",
 81                              0,
 82                              heap->max_capacity()) { }
 83 
 84 MemoryUsage ShenandoahYoungGenMemoryPool::get_memory_usage() {
 85   size_t initial   = initial_size();
 86   size_t max       = max_size();
 87   size_t used      = used_in_bytes();
 88   size_t committed = _heap->young_generation()->used_regions_size();
 89 
 90   return MemoryUsage(initial, used, committed, max);
 91 }
 92 
 93 size_t ShenandoahYoungGenMemoryPool::used_in_bytes() {
 94   return _heap->young_generation()->used();
 95 }
 96 
 97 size_t ShenandoahYoungGenMemoryPool::max_size() const {
 98   return _heap->young_generation()->max_capacity();
 99 }
100 
101 ShenandoahOldGenMemoryPool::ShenandoahOldGenMemoryPool(ShenandoahHeap* heap) :
102         ShenandoahMemoryPool(heap,
103                              "Shenandoah Old Gen",
104                              0,
105                              heap->max_capacity()) { }
106 
107 MemoryUsage ShenandoahOldGenMemoryPool::get_memory_usage() {
108   size_t initial   = initial_size();
109   size_t max       = max_size();
110   size_t used      = used_in_bytes();
111   size_t committed = _heap->old_generation()->used_regions_size();
112 
113   return MemoryUsage(initial, used, committed, max);
114 }
115 
116 size_t ShenandoahOldGenMemoryPool::used_in_bytes() {
117   return _heap->old_generation()->used();
118 }
119 
120 size_t ShenandoahOldGenMemoryPool::max_size() const {
121   return _heap->old_generation()->max_capacity();
122 }
< prev index next >