1
1
/*
2
2
* Copyright (c) 2021, 2021, Oracle and/or its affiliates. All rights reserved.
3
3
* Copyright (c) 2021, 2021, Red Hat Inc. All rights reserved.
4
+ * Copyright (c) 2025, 2025, IBM Inc. All rights reserved.
4
5
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
6
*
6
7
* This code is free software; you can redistribute it and/or modify it
25
26
*/
26
27
package com .oracle .svm .core .jfr .logging ;
27
28
29
+ import static com .oracle .svm .core .heap .RestrictHeapAccess .Access .NO_ALLOCATION ;
30
+
28
31
import java .util .Locale ;
29
32
import java .util .Set ;
30
33
31
34
import org .graalvm .nativeimage .Platform ;
32
35
import org .graalvm .nativeimage .Platforms ;
33
36
34
37
import com .oracle .svm .core .SubstrateUtil ;
38
+ import com .oracle .svm .core .heap .RestrictHeapAccess ;
35
39
import com .oracle .svm .core .log .Log ;
36
40
import com .oracle .svm .util .ReflectionUtil ;
37
41
38
42
import jdk .jfr .internal .LogLevel ;
39
43
import jdk .jfr .internal .LogTag ;
40
44
41
45
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
+
42
49
private final String [] logLevels ;
43
50
private final String [] logTagSets ;
44
51
private int levelDecorationFill = 0 ;
@@ -54,11 +61,13 @@ public void parseConfiguration(String config) {
54
61
JfrLogConfiguration .parse (config );
55
62
}
56
63
64
+ @ RestrictHeapAccess (access = NO_ALLOCATION , reason = "May be used during OOME emergency dump." )
57
65
public void warnInternal (String message ) {
58
66
int tagSetId = SubstrateUtil .cast (LogTag .JFR_SYSTEM , Target_jdk_jfr_internal_LogTag .class ).id ;
59
67
log (tagSetId , JfrLogConfiguration .JfrLogLevel .WARNING .level , message );
60
68
}
61
69
70
+ @ RestrictHeapAccess (access = NO_ALLOCATION , reason = "May be used during OOME emergency dump." )
62
71
public void log (int tagSetId , int level , String message ) {
63
72
if (message == null ) {
64
73
return ;
@@ -85,6 +94,7 @@ public void log(int tagSetId, int level, String message) {
85
94
log .string (message ).newline ();
86
95
}
87
96
97
+ @ RestrictHeapAccess (access = NO_ALLOCATION , reason = "May be used during OOME emergency dump." )
88
98
public void logEvent (int level , String [] lines , boolean system ) {
89
99
if (lines == null ) {
90
100
return ;
@@ -100,13 +110,13 @@ public void logEvent(int level, String[] lines, boolean system) {
100
110
101
111
private void verifyLogLevel (int level ) {
102
112
if (level < 0 || level >= logLevels .length || logLevels [level ] == null ) {
103
- throw new IllegalArgumentException ( "LogLevel passed is outside valid range" ) ;
113
+ throw verifyLogLevelException ;
104
114
}
105
115
}
106
116
107
117
private void verifyLogTagSetId (int tagSetId ) {
108
118
if (tagSetId < 0 || tagSetId >= logTagSets .length ) {
109
- throw new IllegalArgumentException ( "LogTagSet id is outside valid range" ) ;
119
+ throw verifyLogTagSetIdException ;
110
120
}
111
121
}
112
122
@@ -138,7 +148,7 @@ private static String[] createLogTagSets() {
138
148
Set <JfrLogTag > set = JfrLogConfiguration .LOG_TAG_SETS .get (logTagSet );
139
149
if (set != null ) {
140
150
for (JfrLogTag logTag : set ) {
141
- if (builder .length () > 0 ) {
151
+ if (! builder .isEmpty () ) {
142
152
builder .append ("," );
143
153
}
144
154
builder .append (logTag .toString ().toLowerCase (Locale .ROOT ));
0 commit comments