Skip to content

Commit 6c9f79d

Browse files
[GR-69654] Make JFR logging methods allocation free.
PullRequest: graal/22133
2 parents 5fd35d5 + 4bbf1ad commit 6c9f79d

File tree

1 file changed

+13
-3
lines changed
  • substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/logging

1 file changed

+13
-3
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/logging/JfrLogging.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
* Copyright (c) 2021, 2021, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2021, 2021, Red Hat Inc. All rights reserved.
4+
* Copyright (c) 2025, 2025, IBM Inc. All rights reserved.
45
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
56
*
67
* This code is free software; you can redistribute it and/or modify it
@@ -25,20 +26,26 @@
2526
*/
2627
package com.oracle.svm.core.jfr.logging;
2728

29+
import static com.oracle.svm.core.heap.RestrictHeapAccess.Access.NO_ALLOCATION;
30+
2831
import java.util.Locale;
2932
import java.util.Set;
3033

3134
import org.graalvm.nativeimage.Platform;
3235
import org.graalvm.nativeimage.Platforms;
3336

3437
import com.oracle.svm.core.SubstrateUtil;
38+
import com.oracle.svm.core.heap.RestrictHeapAccess;
3539
import com.oracle.svm.core.log.Log;
3640
import com.oracle.svm.util.ReflectionUtil;
3741

3842
import jdk.jfr.internal.LogLevel;
3943
import jdk.jfr.internal.LogTag;
4044

4145
public class JfrLogging {
46+
private static final IllegalArgumentException verifyLogLevelException = new IllegalArgumentException("LogLevel passed is outside valid range");
47+
private static final IllegalArgumentException verifyLogTagSetIdException = new IllegalArgumentException("LogTagSet id is outside valid range");
48+
4249
private final String[] logLevels;
4350
private final String[] logTagSets;
4451
private int levelDecorationFill = 0;
@@ -54,11 +61,13 @@ public void parseConfiguration(String config) {
5461
JfrLogConfiguration.parse(config);
5562
}
5663

64+
@RestrictHeapAccess(access = NO_ALLOCATION, reason = "May be used during OOME emergency dump.")
5765
public void warnInternal(String message) {
5866
int tagSetId = SubstrateUtil.cast(LogTag.JFR_SYSTEM, Target_jdk_jfr_internal_LogTag.class).id;
5967
log(tagSetId, JfrLogConfiguration.JfrLogLevel.WARNING.level, message);
6068
}
6169

70+
@RestrictHeapAccess(access = NO_ALLOCATION, reason = "May be used during OOME emergency dump.")
6271
public void log(int tagSetId, int level, String message) {
6372
if (message == null) {
6473
return;
@@ -85,6 +94,7 @@ public void log(int tagSetId, int level, String message) {
8594
log.string(message).newline();
8695
}
8796

97+
@RestrictHeapAccess(access = NO_ALLOCATION, reason = "May be used during OOME emergency dump.")
8898
public void logEvent(int level, String[] lines, boolean system) {
8999
if (lines == null) {
90100
return;
@@ -100,13 +110,13 @@ public void logEvent(int level, String[] lines, boolean system) {
100110

101111
private void verifyLogLevel(int level) {
102112
if (level < 0 || level >= logLevels.length || logLevels[level] == null) {
103-
throw new IllegalArgumentException("LogLevel passed is outside valid range");
113+
throw verifyLogLevelException;
104114
}
105115
}
106116

107117
private void verifyLogTagSetId(int tagSetId) {
108118
if (tagSetId < 0 || tagSetId >= logTagSets.length) {
109-
throw new IllegalArgumentException("LogTagSet id is outside valid range");
119+
throw verifyLogTagSetIdException;
110120
}
111121
}
112122

@@ -138,7 +148,7 @@ private static String[] createLogTagSets() {
138148
Set<JfrLogTag> set = JfrLogConfiguration.LOG_TAG_SETS.get(logTagSet);
139149
if (set != null) {
140150
for (JfrLogTag logTag : set) {
141-
if (builder.length() > 0) {
151+
if (!builder.isEmpty()) {
142152
builder.append(",");
143153
}
144154
builder.append(logTag.toString().toLowerCase(Locale.ROOT));

0 commit comments

Comments
 (0)