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 #ifndef SHARE_GC_Z_ZSERVICEABILITY_HPP
25 #define SHARE_GC_Z_ZSERVICEABILITY_HPP
26 
27 #include "memory/allocation.hpp"
28 #include "services/memoryManager.hpp"
29 #include "services/memoryPool.hpp"
30 #include "services/memoryService.hpp"
31 
32 class ZServiceabilityCounters;
33 
34 class ZServiceabilityMemoryPool : public CollectedMemoryPool {
35 public:
36   ZServiceabilityMemoryPool(size_t min_capacity, size_t max_capacity);
37 
38   virtual size_t used_in_bytes();
39   virtual MemoryUsage get_memory_usage();
40 };
41 
42 class ZServiceabilityMemoryManager : public GCMemoryManager {
43 public:
44   ZServiceabilityMemoryManager(ZServiceabilityMemoryPool* pool);
45 };
46 
47 class ZServiceability {
48 private:
49   const size_t                 _min_capacity;
50   const size_t                 _max_capacity;
51   ZServiceabilityMemoryPool    _memory_pool;
52   ZServiceabilityMemoryManager _memory_manager;
53   ZServiceabilityCounters*     _counters;
54 
55 public:
56   ZServiceability(size_t min_capacity, size_t max_capacity);
57 
58   void initialize();
59 
60   MemoryPool* memory_pool();
61   GCMemoryManager* memory_manager();
62   ZServiceabilityCounters* counters();
63 };
64 
65 class ZServiceabilityMemoryUsageTracker {
66 public:
67   ~ZServiceabilityMemoryUsageTracker();
68 };
69 
70 class ZServiceabilityManagerStatsTracer {
71 private:
72   TraceMemoryManagerStats _stats;
73 
74 public:
75   ZServiceabilityManagerStatsTracer(bool is_gc_begin, bool is_gc_end);
76 };
77 
78 class ZServiceabilityCountersTracer {
79 public:
80   ZServiceabilityCountersTracer();
81   ~ZServiceabilityCountersTracer();
82 };
83 
84 template <bool IsGCStart, bool IsGCEnd>
85 class ZServiceabilityTracer : public StackObj {
86 private:
87   ZServiceabilityMemoryUsageTracker _memory_usage_tracker;
88   ZServiceabilityManagerStatsTracer _manager_stats_tracer;
89   ZServiceabilityCountersTracer     _counters_tracer;
90 
91 public:
ZServiceabilityTracer()92   ZServiceabilityTracer() :
93       _memory_usage_tracker(),
94       _manager_stats_tracer(IsGCStart, IsGCEnd),
95       _counters_tracer() {}
96 };
97 
98 typedef ZServiceabilityTracer<true,  false> ZServiceabilityMarkStartTracer;
99 typedef ZServiceabilityTracer<false, false> ZServiceabilityMarkEndTracer;
100 typedef ZServiceabilityTracer<false, true>  ZServiceabilityRelocateStartTracer;
101 
102 #endif // SHARE_GC_Z_ZSERVICEABILITY_HPP
103