| 1 | /* |
| 2 | * Copyright (c) 2015, 2018, Red Hat, Inc. All rights reserved. |
| 3 | * |
| 4 | * This code is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of the GNU General Public License version 2 only, as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 11 | * version 2 for more details (a copy is included in the LICENSE file that |
| 12 | * accompanied this code). |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License version |
| 15 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 17 | * |
| 18 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 19 | * or visit www.oracle.com if you need additional information or have any |
| 20 | * questions. |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include "precompiled.hpp" |
| 25 | #include "gc/shared/collectorCounters.hpp" |
| 26 | #include "gc/shared/generationCounters.hpp" |
| 27 | #include "gc/shared/hSpaceCounters.hpp" |
| 28 | #include "gc/shenandoah/shenandoahMonitoringSupport.hpp" |
| 29 | #include "gc/shenandoah/shenandoahHeap.hpp" |
| 30 | #include "gc/shenandoah/shenandoahHeapRegionCounters.hpp" |
| 31 | #include "memory/metaspaceCounters.hpp" |
| 32 | #include "services/memoryService.hpp" |
| 33 | |
| 34 | class ShenandoahYoungGenerationCounters : public GenerationCounters { |
| 35 | public: |
| 36 | ShenandoahYoungGenerationCounters() : |
| 37 | GenerationCounters("Young" , 0, 0, 0, (size_t)0, (size_t)0) {}; |
| 38 | |
| 39 | virtual void update_all() { |
| 40 | // no update |
| 41 | } |
| 42 | }; |
| 43 | |
| 44 | class ShenandoahGenerationCounters : public GenerationCounters { |
| 45 | private: |
| 46 | ShenandoahHeap* _heap; |
| 47 | public: |
| 48 | ShenandoahGenerationCounters(ShenandoahHeap* heap) : |
| 49 | GenerationCounters("Heap" , 1, 1, heap->initial_capacity(), heap->max_capacity(), heap->capacity()), |
| 50 | _heap(heap) |
| 51 | {}; |
| 52 | |
| 53 | virtual void update_all() { |
| 54 | _current_size->set_value(_heap->capacity()); |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | ShenandoahMonitoringSupport::ShenandoahMonitoringSupport(ShenandoahHeap* heap) : |
| 59 | _partial_counters(NULL), |
| 60 | _full_counters(NULL) |
| 61 | { |
| 62 | // Collection counters do not fit Shenandoah very well. |
| 63 | // We record partial cycles as "young", and full cycles (including full STW GC) as "old". |
| 64 | _partial_counters = new CollectorCounters("Shenandoah partial" , 0); |
| 65 | _full_counters = new CollectorCounters("Shenandoah full" , 1); |
| 66 | |
| 67 | // We report young gen as unused. |
| 68 | _young_counters = new ShenandoahYoungGenerationCounters(); |
| 69 | _heap_counters = new ShenandoahGenerationCounters(heap); |
| 70 | _space_counters = new HSpaceCounters(_heap_counters->name_space(), "Heap" , 0, heap->max_capacity(), heap->initial_capacity()); |
| 71 | |
| 72 | _heap_region_counters = new ShenandoahHeapRegionCounters(); |
| 73 | } |
| 74 | |
| 75 | CollectorCounters* ShenandoahMonitoringSupport::stw_collection_counters() { |
| 76 | return _full_counters; |
| 77 | } |
| 78 | |
| 79 | CollectorCounters* ShenandoahMonitoringSupport::full_stw_collection_counters() { |
| 80 | return _full_counters; |
| 81 | } |
| 82 | |
| 83 | CollectorCounters* ShenandoahMonitoringSupport::concurrent_collection_counters() { |
| 84 | return _full_counters; |
| 85 | } |
| 86 | |
| 87 | CollectorCounters* ShenandoahMonitoringSupport::partial_collection_counters() { |
| 88 | return _partial_counters; |
| 89 | } |
| 90 | |
| 91 | void ShenandoahMonitoringSupport::update_counters() { |
| 92 | MemoryService::track_memory_usage(); |
| 93 | |
| 94 | if (UsePerfData) { |
| 95 | ShenandoahHeap* heap = ShenandoahHeap::heap(); |
| 96 | size_t used = heap->used(); |
| 97 | size_t capacity = heap->max_capacity(); |
| 98 | _heap_counters->update_all(); |
| 99 | _space_counters->update_all(capacity, used); |
| 100 | _heap_region_counters->update(); |
| 101 | |
| 102 | MetaspaceCounters::update_performance_counters(); |
| 103 | CompressedClassSpaceCounters::update_performance_counters(); |
| 104 | } |
| 105 | } |
| 106 | |