Skip to content

Commit 0e98770

Browse files
committed
svm: adopt "JDK-8351594: JFR: Rate-limited sampling of Java events"
1 parent 991768a commit 0e98770

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/KnownTruffleTypes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ private static ResolvedJavaField getThrowableJFRTracingField(MetaAccessProvider
221221
ResolvedJavaType throwableType = metaAccess.lookupJavaType(Throwable.class);
222222
for (ResolvedJavaField staticField : throwableType.getStaticFields()) {
223223
if (staticField.getName().equals("jfrTracing") &&
224-
staticField.getType().equals(metaAccess.lookupJavaType(boolean.class)) && staticField.isVolatile()) {
224+
staticField.getType().equals(metaAccess.lookupJavaType(boolean.class))) {
225225
return staticField;
226226
}
227227
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2025, 2025, 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+
package com.oracle.svm.core.jfr;
26+
27+
import java.util.Random;
28+
29+
import com.oracle.svm.core.annotate.Alias;
30+
import com.oracle.svm.core.annotate.InjectAccessors;
31+
import com.oracle.svm.core.annotate.TargetClass;
32+
33+
@TargetClass(className = "jdk.jfr.internal.settings.Throttler")
34+
public final class Target_jdk_jfr_internal_settings_Throttler {
35+
@Alias //
36+
@InjectAccessors(ThrottlerRandomAccessor.class) //
37+
private Random randomGenerator;
38+
}
39+
40+
final class ThrottlerRandomAccessor {
41+
private static Random cachedRandom;
42+
43+
@SuppressWarnings("unused")
44+
static Random get(Target_jdk_jfr_internal_settings_Throttler receiver) {
45+
if (cachedRandom != null) {
46+
return cachedRandom;
47+
}
48+
return initializeRandom();
49+
}
50+
51+
private static synchronized Random initializeRandom() {
52+
if (cachedRandom != null) {
53+
return cachedRandom;
54+
}
55+
56+
cachedRandom = new Random();
57+
return cachedRandom;
58+
}
59+
60+
@SuppressWarnings("unused")
61+
static synchronized void set(Target_jdk_jfr_internal_settings_Throttler receiver, Random value) {
62+
throw new RuntimeException("The field jdk.jfr.internal.settings.Throttler.randomGenerator cannot be set");
63+
}
64+
}

0 commit comments

Comments
 (0)