diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/logging/JfrLogging.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/logging/JfrLogging.java index f4243c721b2f..2ce716570fc1 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/logging/JfrLogging.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/logging/JfrLogging.java @@ -1,6 +1,7 @@ /* * Copyright (c) 2021, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2021, 2021, Red Hat Inc. All rights reserved. + * Copyright (c) 2025, 2025, IBM Inc. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,6 +26,8 @@ */ package com.oracle.svm.core.jfr.logging; +import static com.oracle.svm.core.heap.RestrictHeapAccess.Access.NO_ALLOCATION; + import java.util.Locale; import java.util.Set; @@ -32,6 +35,7 @@ import org.graalvm.nativeimage.Platforms; import com.oracle.svm.core.SubstrateUtil; +import com.oracle.svm.core.heap.RestrictHeapAccess; import com.oracle.svm.core.log.Log; import com.oracle.svm.util.ReflectionUtil; @@ -39,6 +43,9 @@ import jdk.jfr.internal.LogTag; public class JfrLogging { + private static final IllegalArgumentException verifyLogLevelException = new IllegalArgumentException("LogLevel passed is outside valid range"); + private static final IllegalArgumentException verifyLogTagSetIdException = new IllegalArgumentException("LogTagSet id is outside valid range"); + private final String[] logLevels; private final String[] logTagSets; private int levelDecorationFill = 0; @@ -54,11 +61,13 @@ public void parseConfiguration(String config) { JfrLogConfiguration.parse(config); } + @RestrictHeapAccess(access = NO_ALLOCATION, reason = "May be used during OOME emergency dump.") public void warnInternal(String message) { int tagSetId = SubstrateUtil.cast(LogTag.JFR_SYSTEM, Target_jdk_jfr_internal_LogTag.class).id; log(tagSetId, JfrLogConfiguration.JfrLogLevel.WARNING.level, message); } + @RestrictHeapAccess(access = NO_ALLOCATION, reason = "May be used during OOME emergency dump.") public void log(int tagSetId, int level, String message) { if (message == null) { return; @@ -85,6 +94,7 @@ public void log(int tagSetId, int level, String message) { log.string(message).newline(); } + @RestrictHeapAccess(access = NO_ALLOCATION, reason = "May be used during OOME emergency dump.") public void logEvent(int level, String[] lines, boolean system) { if (lines == null) { return; @@ -100,13 +110,13 @@ public void logEvent(int level, String[] lines, boolean system) { private void verifyLogLevel(int level) { if (level < 0 || level >= logLevels.length || logLevels[level] == null) { - throw new IllegalArgumentException("LogLevel passed is outside valid range"); + throw verifyLogLevelException; } } private void verifyLogTagSetId(int tagSetId) { if (tagSetId < 0 || tagSetId >= logTagSets.length) { - throw new IllegalArgumentException("LogTagSet id is outside valid range"); + throw verifyLogTagSetIdException; } } @@ -138,7 +148,7 @@ private static String[] createLogTagSets() { Set set = JfrLogConfiguration.LOG_TAG_SETS.get(logTagSet); if (set != null) { for (JfrLogTag logTag : set) { - if (builder.length() > 0) { + if (!builder.isEmpty()) { builder.append(","); } builder.append(logTag.toString().toLowerCase(Locale.ROOT));