1 /*
2 * Copyright (c) 2003, 2015, 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 #ifndef SHARE_VM_SERVICES_MEMORYSERVICE_HPP
26 #define SHARE_VM_SERVICES_MEMORYSERVICE_HPP
27
28 #include "gc/shared/gcCause.hpp"
29 #include "gc/shared/generation.hpp"
30 #include "logging/log.hpp"
31 #include "memory/allocation.hpp"
32 #include "runtime/handles.hpp"
33 #include "services/memoryUsage.hpp"
34
35 // Forward declaration
36 class MemoryPool;
37 class MemoryManager;
38 class GCMemoryManager;
39 class CollectedHeap;
40 class Generation;
41 class DefNewGeneration;
42 class PSYoungGen;
43 class PSOldGen;
44 class CodeHeap;
45 class ContiguousSpace;
46 class CompactibleFreeListSpace;
47 class GenCollectedHeap;
48 class ParallelScavengeHeap;
49 class G1CollectedHeap;
50
51 // VM Monitoring and Management Support
52
53 class MemoryService : public AllStatic {
54 private:
55 enum {
56 init_pools_list_size = 10,
57 init_managers_list_size = 5,
58 init_code_heap_pools_size = 9
59 };
60
61 static GrowableArray<MemoryPool*>* _pools_list;
62 static GrowableArray<MemoryManager*>* _managers_list;
63
64 // memory managers for minor and major GC statistics
65 static GCMemoryManager* _major_gc_manager;
66 static GCMemoryManager* _minor_gc_manager;
67
68 // memory manager and code heap pools for the CodeCache
69 static MemoryManager* _code_cache_manager;
70 static GrowableArray<MemoryPool*>* _code_heap_pools;
71
72 static MemoryPool* _metaspace_pool;
73 static MemoryPool* _compressed_class_pool;
74
75 static void add_generation_memory_pool(Generation* gen,
76 MemoryManager* major_mgr,
77 MemoryManager* minor_mgr);
78 static void add_generation_memory_pool(Generation* gen,
79 MemoryManager* major_mgr) {
80 add_generation_memory_pool(gen, major_mgr, NULL);
81 }
82
83
84 static void add_psYoung_memory_pool(PSYoungGen* young_gen,
85 MemoryManager* major_mgr,
86 MemoryManager* minor_mgr);
87 static void add_psOld_memory_pool(PSOldGen* old_gen,
88 MemoryManager* mgr);
89
90 static void add_g1YoungGen_memory_pool(G1CollectedHeap* g1h,
91 MemoryManager* major_mgr,
92 MemoryManager* minor_mgr);
93 static void add_g1OldGen_memory_pool(G1CollectedHeap* g1h,
94 MemoryManager* mgr);
95
96 static MemoryPool* add_space(ContiguousSpace* space,
97 const char* name,
98 bool is_heap,
99 size_t max_size,
100 bool support_usage_threshold);
101 static MemoryPool* add_survivor_spaces(DefNewGeneration* young_gen,
102 const char* name,
103 bool is_heap,
104 size_t max_size,
105 bool support_usage_threshold);
106 static MemoryPool* add_gen(Generation* gen,
107 const char* name,
108 bool is_heap,
109 bool support_usage_threshold);
110 static MemoryPool* add_cms_space(CompactibleFreeListSpace* space,
111 const char* name,
112 bool is_heap,
113 size_t max_size,
114 bool support_usage_threshold);
115
116 static void add_gen_collected_heap_info(GenCollectedHeap* heap);
117 static void add_parallel_scavenge_heap_info(ParallelScavengeHeap* heap);
118 static void add_g1_heap_info(G1CollectedHeap* g1h);
119
120 public:
121 static void set_universe_heap(CollectedHeap* heap);
122 static void add_code_heap_memory_pool(CodeHeap* heap, const char* name);
123 static void add_metaspace_memory_pools();
124
125 static MemoryPool* get_memory_pool(instanceHandle pool);
126 static MemoryManager* get_memory_manager(instanceHandle mgr);
127
128 static const int num_memory_pools() {
129 return _pools_list->length();
130 }
131 static const int num_memory_managers() {
132 return _managers_list->length();
133 }
134
135 static MemoryPool* get_memory_pool(int index) {
136 return _pools_list->at(index);
137 }
138
139 static MemoryManager* get_memory_manager(int index) {
140 return _managers_list->at(index);
141 }
142
143 static void track_memory_usage();
144 static void track_code_cache_memory_usage() {
145 // Track memory pool usage of all CodeCache memory pools
146 for (int i = 0; i < _code_heap_pools->length(); ++i) {
147 track_memory_pool_usage(_code_heap_pools->at(i));
148 }
149 }
150 static void track_metaspace_memory_usage() {
151 track_memory_pool_usage(_metaspace_pool);
152 }
153 static void track_compressed_class_memory_usage() {
154 track_memory_pool_usage(_compressed_class_pool);
155 }
156 static void track_memory_pool_usage(MemoryPool* pool);
157
158 static void gc_begin(bool fullGC, bool recordGCBeginTime,
159 bool recordAccumulatedGCTime,
160 bool recordPreGCUsage, bool recordPeakUsage);
161 static void gc_end(bool fullGC, bool recordPostGCUsage,
162 bool recordAccumulatedGCTime,
163 bool recordGCEndTime, bool countCollection,
164 GCCause::Cause cause);
165
166 static void oops_do(OopClosure* f);
167
168 static bool get_verbose() { return log_is_enabled(Info, gc); }
169 static bool set_verbose(bool verbose);
170
171 // Create an instance of java/lang/management/MemoryUsage
172 static Handle create_MemoryUsage_obj(MemoryUsage usage, TRAPS);
173
174 static const GCMemoryManager* get_minor_gc_manager() {
175 return _minor_gc_manager;
176 }
177
178 static const GCMemoryManager* get_major_gc_manager() {
179 return _major_gc_manager;
180 }
181 };
182
183 class TraceMemoryManagerStats : public StackObj {
184 private:
185 bool _fullGC;
186 bool _recordGCBeginTime;
187 bool _recordPreGCUsage;
188 bool _recordPeakUsage;
189 bool _recordPostGCUsage;
190 bool _recordAccumulatedGCTime;
191 bool _recordGCEndTime;
192 bool _countCollection;
193 GCCause::Cause _cause;
194 public:
195 TraceMemoryManagerStats() {}
196 TraceMemoryManagerStats(bool fullGC,
197 GCCause::Cause cause,
198 bool recordGCBeginTime = true,
199 bool recordPreGCUsage = true,
200 bool recordPeakUsage = true,
201 bool recordPostGCUsage = true,
202 bool recordAccumulatedGCTime = true,
203 bool recordGCEndTime = true,
204 bool countCollection = true);
205
206 void initialize(bool fullGC,
207 GCCause::Cause cause,
208 bool recordGCBeginTime,
209 bool recordPreGCUsage,
210 bool recordPeakUsage,
211 bool recordPostGCUsage,
212 bool recordAccumulatedGCTime,
213 bool recordGCEndTime,
214 bool countCollection);
215
216 TraceMemoryManagerStats(Generation::Name kind, GCCause::Cause cause);
217 ~TraceMemoryManagerStats();
218 };
219
220 #endif // SHARE_VM_SERVICES_MEMORYSERVICE_HPP
|
1 /*
2 * Copyright (c) 2003, 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 #ifndef SHARE_VM_SERVICES_MEMORYSERVICE_HPP
26 #define SHARE_VM_SERVICES_MEMORYSERVICE_HPP
27
28 #include "gc/shared/gcCause.hpp"
29 #include "logging/log.hpp"
30 #include "memory/allocation.hpp"
31 #include "runtime/handles.hpp"
32 #include "services/memoryUsage.hpp"
33
34 // Forward declaration
35 class MemoryPool;
36 class MemoryManager;
37 class GCMemoryManager;
38 class CollectedHeap;
39 class CodeHeap;
40
41 // VM Monitoring and Management Support
42
43 class MemoryService : public AllStatic {
44 private:
45 enum {
46 init_pools_list_size = 10,
47 init_managers_list_size = 5,
48 init_code_heap_pools_size = 9
49 };
50
51 static GrowableArray<MemoryPool*>* _pools_list;
52 static GrowableArray<MemoryManager*>* _managers_list;
53
54 // memory manager and code heap pools for the CodeCache
55 static MemoryManager* _code_cache_manager;
56 static GrowableArray<MemoryPool*>* _code_heap_pools;
57
58 static MemoryPool* _metaspace_pool;
59 static MemoryPool* _compressed_class_pool;
60
61 public:
62 static void set_universe_heap(CollectedHeap* heap);
63 static void add_code_heap_memory_pool(CodeHeap* heap, const char* name);
64 static void add_metaspace_memory_pools();
65
66 static MemoryPool* get_memory_pool(instanceHandle pool);
67 static MemoryManager* get_memory_manager(instanceHandle mgr);
68
69 static const int num_memory_pools() {
70 return _pools_list->length();
71 }
72 static const int num_memory_managers() {
73 return _managers_list->length();
74 }
75
76 static MemoryPool* get_memory_pool(int index) {
77 return _pools_list->at(index);
78 }
79
80 static MemoryManager* get_memory_manager(int index) {
81 return _managers_list->at(index);
82 }
83
84 static void track_memory_usage();
85 static void track_code_cache_memory_usage() {
86 // Track memory pool usage of all CodeCache memory pools
87 for (int i = 0; i < _code_heap_pools->length(); ++i) {
88 track_memory_pool_usage(_code_heap_pools->at(i));
89 }
90 }
91 static void track_metaspace_memory_usage() {
92 track_memory_pool_usage(_metaspace_pool);
93 }
94 static void track_compressed_class_memory_usage() {
95 track_memory_pool_usage(_compressed_class_pool);
96 }
97 static void track_memory_pool_usage(MemoryPool* pool);
98
99 static void gc_begin(GCMemoryManager* mgr, bool recordGCBeginTime,
100 bool recordAccumulatedGCTime,
101 bool recordPreGCUsage, bool recordPeakUsage);
102 static void gc_end(GCMemoryManager* mgr, bool recordPostGCUsage,
103 bool recordAccumulatedGCTime,
104 bool recordGCEndTime, bool countCollection,
105 GCCause::Cause cause);
106
107 static void oops_do(OopClosure* f);
108
109 static bool get_verbose() { return log_is_enabled(Info, gc); }
110 static bool set_verbose(bool verbose);
111
112 // Create an instance of java/lang/management/MemoryUsage
113 static Handle create_MemoryUsage_obj(MemoryUsage usage, TRAPS);
114 };
115
116 class TraceMemoryManagerStats : public StackObj {
117 private:
118 GCMemoryManager* _gc_mem_mgr;
119 bool _recordGCBeginTime;
120 bool _recordPreGCUsage;
121 bool _recordPeakUsage;
122 bool _recordPostGCUsage;
123 bool _recordAccumulatedGCTime;
124 bool _recordGCEndTime;
125 bool _countCollection;
126 GCCause::Cause _cause;
127 public:
128 TraceMemoryManagerStats() {}
129 TraceMemoryManagerStats(GCMemoryManager* gc_mem_mgr,
130 GCCause::Cause cause,
131 bool recordGCBeginTime = true,
132 bool recordPreGCUsage = true,
133 bool recordPeakUsage = true,
134 bool recordPostGCUsage = true,
135 bool recordAccumulatedGCTime = true,
136 bool recordGCEndTime = true,
137 bool countCollection = true);
138
139 void initialize(GCMemoryManager* gc_mem_mgr,
140 GCCause::Cause cause,
141 bool recordGCBeginTime,
142 bool recordPreGCUsage,
143 bool recordPeakUsage,
144 bool recordPostGCUsage,
145 bool recordAccumulatedGCTime,
146 bool recordGCEndTime,
147 bool countCollection);
148
149 ~TraceMemoryManagerStats();
150 };
151
152 #endif // SHARE_VM_SERVICES_MEMORYSERVICE_HPP
|