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
3134import org .graalvm .nativeimage .Platform ;
3235import org .graalvm .nativeimage .Platforms ;
3336
3437import com .oracle .svm .core .SubstrateUtil ;
38+ import com .oracle .svm .core .heap .RestrictHeapAccess ;
3539import com .oracle .svm .core .log .Log ;
3640import com .oracle .svm .util .ReflectionUtil ;
3741
3842import jdk .jfr .internal .LogLevel ;
3943import jdk .jfr .internal .LogTag ;
4044
4145public 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