Skip to content

Commit d41e892

Browse files
make logging methods allocation free
1 parent 4b023a1 commit d41e892

File tree

1 file changed

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

1 file changed

+13
-2
lines changed

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

Lines changed: 13 additions & 2 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,6 +26,8 @@
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

@@ -34,18 +37,23 @@
3437
import com.oracle.svm.core.SubstrateUtil;
3538
import com.oracle.svm.core.log.Log;
3639
import com.oracle.svm.util.ReflectionUtil;
40+
import com.oracle.svm.core.heap.RestrictHeapAccess;
3741

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

4145
public class JfrLogging {
46+
private final IllegalArgumentException verifyLogLevelException;
47+
private final IllegalArgumentException verifyLogTagSetIdException;
4248
private final String[] logLevels;
4349
private final String[] logTagSets;
4450
private int levelDecorationFill = 0;
4551
private int tagSetDecorationFill = 0;
4652

4753
@Platforms(Platform.HOSTED_ONLY.class)
4854
public JfrLogging() {
55+
verifyLogLevelException = new IllegalArgumentException("LogLevel passed is outside valid range");
56+
verifyLogTagSetIdException = new IllegalArgumentException("LogTagSet id is outside valid range");
4957
logLevels = createLogLevels();
5058
logTagSets = createLogTagSets();
5159
}
@@ -54,11 +62,13 @@ public void parseConfiguration(String config) {
5462
JfrLogConfiguration.parse(config);
5563
}
5664

65+
@RestrictHeapAccess(access = NO_ALLOCATION, reason = "May be used during OOME emergency dump.")
5766
public void warnInternal(String message) {
5867
int tagSetId = SubstrateUtil.cast(LogTag.JFR_SYSTEM, Target_jdk_jfr_internal_LogTag.class).id;
5968
log(tagSetId, JfrLogConfiguration.JfrLogLevel.WARNING.level, message);
6069
}
6170

71+
@RestrictHeapAccess(access = NO_ALLOCATION, reason = "May be used during OOME emergency dump.")
6272
public void log(int tagSetId, int level, String message) {
6373
if (message == null) {
6474
return;
@@ -85,6 +95,7 @@ public void log(int tagSetId, int level, String message) {
8595
log.string(message).newline();
8696
}
8797

98+
@RestrictHeapAccess(access = NO_ALLOCATION, reason = "May be used during OOME emergency dump.")
8899
public void logEvent(int level, String[] lines, boolean system) {
89100
if (lines == null) {
90101
return;
@@ -100,13 +111,13 @@ public void logEvent(int level, String[] lines, boolean system) {
100111

101112
private void verifyLogLevel(int level) {
102113
if (level < 0 || level >= logLevels.length || logLevels[level] == null) {
103-
throw new IllegalArgumentException("LogLevel passed is outside valid range");
114+
throw verifyLogLevelException;
104115
}
105116
}
106117

107118
private void verifyLogTagSetId(int tagSetId) {
108119
if (tagSetId < 0 || tagSetId >= logTagSets.length) {
109-
throw new IllegalArgumentException("LogTagSet id is outside valid range");
120+
throw verifyLogTagSetIdException;
110121
}
111122
}
112123

0 commit comments

Comments
 (0)