1 /*
2 * Copyright (c) 2021, 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 #ifndef SHARE_SERVICES_HEAPOBJECTSTATISTICS_HPP
26 #define SHARE_SERVICES_HEAPOBJECTSTATISTICS_HPP
27
28 #include "memory/allocation.hpp"
29 #include "oops/oopsHierarchy.hpp"
30 #include "runtime/task.hpp"
31 #include "runtime/vmOperation.hpp"
32
33 class outputStream;
34
35 class HeapObjectStatisticsTask : public PeriodicTask {
36 public:
37 HeapObjectStatisticsTask();
38 void task();
39 };
40
41 class HeapObjectStatistics : public CHeapObj<mtGC> {
42 private:
43 static HeapObjectStatistics* _instance;
44
45 HeapObjectStatisticsTask _task;
46 uint64_t _num_samples;
47 uint64_t _num_objects;
48 uint64_t _num_ihashed;
49 uint64_t _num_ihashed_moved;
50 uint64_t _num_locked;
51 uint64_t _lds;
52
53 static void increase_counter(uint64_t& counter, uint64_t val = 1);
54
55 void print(outputStream* out) const;
56
57 public:
58 static void initialize();
59 static void shutdown();
60
61 static HeapObjectStatistics* instance();
62
63 HeapObjectStatistics();
64 void start();
65 void stop();
66
67 void begin_sample();
68 void visit_object(oop object);
69 };
70
71 #endif // SHARE_SERVICES_HEAPOBJECTSTATISTICS_HPP