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
2526 */
2627package com .oracle .svm .core .jfr .logging ;
2728
29+ import static com .oracle .svm .core .heap .RestrictHeapAccess .Access .NO_ALLOCATION ;
30+
2831import java .util .Locale ;
2932import java .util .Set ;
3033
3437import com .oracle .svm .core .SubstrateUtil ;
3538import com .oracle .svm .core .log .Log ;
3639import com .oracle .svm .util .ReflectionUtil ;
40+ import com .oracle .svm .core .heap .RestrictHeapAccess ;
3741
3842import jdk .jfr .internal .LogLevel ;
3943import jdk .jfr .internal .LogTag ;
4044
4145public 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