Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/share/classes/jdk/internal/perf/PerfCounter.java
41159 views
1
/*
2
* Copyright (c) 2009, 2021, 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. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package jdk.internal.perf;
27
28
import java.nio.ByteBuffer;
29
import java.nio.ByteOrder;
30
import java.nio.LongBuffer;
31
import java.security.AccessController;
32
33
/**
34
* Performance counter support for internal JRE classes.
35
* This class defines a fixed list of counters for the platform
36
* to use as an interim solution until RFE# 6209222 is implemented.
37
* The perf counters will be created in the jvmstat perf buffer
38
* that the HotSpot VM creates. The default size is 32K and thus
39
* the number of counters is bounded. You can alter the size
40
* with {@code -XX:PerfDataMemorySize=<bytes>} option. If there is
41
* insufficient memory in the jvmstat perf buffer, the C heap memory
42
* will be used and thus the application will continue to run if
43
* the counters added exceeds the buffer size but the counters
44
* will be missing.
45
*
46
* See HotSpot jvmstat implementation for certain circumstances
47
* that the jvmstat perf buffer is not supported.
48
*
49
*/
50
public class PerfCounter {
51
@SuppressWarnings("removal")
52
private static final Perf perf =
53
AccessController.doPrivileged(new Perf.GetPerfAction());
54
55
// Must match values defined in hotspot/src/share/vm/runtime/perfdata.hpp
56
private static final int V_Constant = 1;
57
private static final int V_Monotonic = 2;
58
private static final int V_Variable = 3;
59
private static final int U_None = 1;
60
61
private final String name;
62
private final LongBuffer lb;
63
64
private PerfCounter(String name, int type) {
65
this.name = name;
66
ByteBuffer bb = perf.createLong(name, type, U_None, 0L);
67
bb.order(ByteOrder.nativeOrder());
68
this.lb = bb.asLongBuffer();
69
}
70
71
public static PerfCounter newPerfCounter(String name) {
72
return new PerfCounter(name, V_Variable);
73
}
74
75
public static PerfCounter newConstantPerfCounter(String name) {
76
PerfCounter c = new PerfCounter(name, V_Constant);
77
return c;
78
}
79
80
/**
81
* Returns the current value of the perf counter.
82
*/
83
public synchronized long get() {
84
return lb.get(0);
85
}
86
87
/**
88
* Sets the value of the perf counter to the given newValue.
89
*/
90
public synchronized void set(long newValue) {
91
lb.put(0, newValue);
92
}
93
94
/**
95
* Adds the given value to the perf counter.
96
*/
97
public synchronized void add(long value) {
98
long res = get() + value;
99
lb.put(0, res);
100
}
101
102
/**
103
* Increments the perf counter with 1.
104
*/
105
public void increment() {
106
add(1);
107
}
108
109
/**
110
* Adds the given interval to the perf counter.
111
*/
112
public void addTime(long interval) {
113
add(interval);
114
}
115
116
/**
117
* Adds the elapsed time from the given start time (ns) to the perf counter.
118
*/
119
public void addElapsedTimeFrom(long startTime) {
120
add(System.nanoTime() - startTime);
121
}
122
123
@Override
124
public String toString() {
125
return name + " = " + get();
126
}
127
128
static class CoreCounters {
129
static final PerfCounter pdt = newPerfCounter("sun.classloader.parentDelegationTime");
130
static final PerfCounter lc = newPerfCounter("sun.classloader.findClasses");
131
static final PerfCounter lct = newPerfCounter("sun.classloader.findClassTime");
132
static final PerfCounter rcbt = newPerfCounter("sun.urlClassLoader.readClassBytesTime");
133
static final PerfCounter zfc = newPerfCounter("sun.zip.zipFiles");
134
static final PerfCounter zfot = newPerfCounter("sun.zip.zipFile.openTime");
135
}
136
137
/**
138
* Number of findClass calls
139
*/
140
public static PerfCounter getFindClasses() {
141
return CoreCounters.lc;
142
}
143
144
/**
145
* Time (ns) spent in finding classes that includes
146
* lookup and read class bytes and defineClass
147
*/
148
public static PerfCounter getFindClassTime() {
149
return CoreCounters.lct;
150
}
151
152
/**
153
* Time (ns) spent in finding classes
154
*/
155
public static PerfCounter getReadClassBytesTime() {
156
return CoreCounters.rcbt;
157
}
158
159
/**
160
* Time (ns) spent in the parent delegation to
161
* the parent of the defining class loader
162
*/
163
public static PerfCounter getParentDelegationTime() {
164
return CoreCounters.pdt;
165
}
166
167
/**
168
* Number of zip files opened.
169
*/
170
public static PerfCounter getZipFileCount() {
171
return CoreCounters.zfc;
172
}
173
174
/**
175
* Time (ns) spent in opening the zip files that
176
* includes building the entries hash table
177
*/
178
public static PerfCounter getZipFileOpenTime() {
179
return CoreCounters.zfot;
180
}
181
182
}
183
184