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
34
37
import com .oracle .svm .core .SubstrateUtil ;
35
38
import com .oracle .svm .core .log .Log ;
36
39
import com .oracle .svm .util .ReflectionUtil ;
40
+ import com .oracle .svm .core .heap .RestrictHeapAccess ;
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 final IllegalArgumentException verifyLogLevelException ;
47
+ private final IllegalArgumentException verifyLogTagSetIdException ;
42
48
private final String [] logLevels ;
43
49
private final String [] logTagSets ;
44
50
private int levelDecorationFill = 0 ;
45
51
private int tagSetDecorationFill = 0 ;
46
52
47
53
@ Platforms (Platform .HOSTED_ONLY .class )
48
54
public JfrLogging () {
55
+ verifyLogLevelException = new IllegalArgumentException ("LogLevel passed is outside valid range" );
56
+ verifyLogTagSetIdException = new IllegalArgumentException ("LogTagSet id is outside valid range" );
49
57
logLevels = createLogLevels ();
50
58
logTagSets = createLogTagSets ();
51
59
}
@@ -54,11 +62,13 @@ public void parseConfiguration(String config) {
54
62
JfrLogConfiguration .parse (config );
55
63
}
56
64
65
+ @ RestrictHeapAccess (access = NO_ALLOCATION , reason = "May be used during OOME emergency dump." )
57
66
public void warnInternal (String message ) {
58
67
int tagSetId = SubstrateUtil .cast (LogTag .JFR_SYSTEM , Target_jdk_jfr_internal_LogTag .class ).id ;
59
68
log (tagSetId , JfrLogConfiguration .JfrLogLevel .WARNING .level , message );
60
69
}
61
70
71
+ @ RestrictHeapAccess (access = NO_ALLOCATION , reason = "May be used during OOME emergency dump." )
62
72
public void log (int tagSetId , int level , String message ) {
63
73
if (message == null ) {
64
74
return ;
@@ -85,6 +95,7 @@ public void log(int tagSetId, int level, String message) {
85
95
log .string (message ).newline ();
86
96
}
87
97
98
+ @ RestrictHeapAccess (access = NO_ALLOCATION , reason = "May be used during OOME emergency dump." )
88
99
public void logEvent (int level , String [] lines , boolean system ) {
89
100
if (lines == null ) {
90
101
return ;
@@ -100,13 +111,13 @@ public void logEvent(int level, String[] lines, boolean system) {
100
111
101
112
private void verifyLogLevel (int level ) {
102
113
if (level < 0 || level >= logLevels .length || logLevels [level ] == null ) {
103
- throw new IllegalArgumentException ( "LogLevel passed is outside valid range" ) ;
114
+ throw verifyLogLevelException ;
104
115
}
105
116
}
106
117
107
118
private void verifyLogTagSetId (int tagSetId ) {
108
119
if (tagSetId < 0 || tagSetId >= logTagSets .length ) {
109
- throw new IllegalArgumentException ( "LogTagSet id is outside valid range" ) ;
120
+ throw verifyLogTagSetIdException ;
110
121
}
111
122
}
112
123
0 commit comments