Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -25,20 +26,26 @@
*/
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;

import org.graalvm.nativeimage.Platform;
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;

import jdk.jfr.internal.LogLevel;
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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
}

Expand Down Expand Up @@ -138,7 +148,7 @@ private static String[] createLogTagSets() {
Set<JfrLogTag> 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));
Expand Down