Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[24.1] Backport: Updated JFR substitutions from [GR-54877] #764

Merged
merged 2 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
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
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.core.posix;

import org.graalvm.nativeimage.StackValue;

import com.oracle.svm.core.feature.AutomaticallyRegisteredImageSingleton;
import com.oracle.svm.core.posix.headers.Time;
import com.oracle.svm.core.util.BasedOnJDKFile;
import com.oracle.svm.core.util.PlatformTimeUtils;

@AutomaticallyRegisteredImageSingleton(PlatformTimeUtils.class)
public final class PosixPlatformTimeUtils extends PlatformTimeUtils {

@Override
@BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-23+9/src/hotspot/os/posix/os_posix.cpp#L1387-L1393")
protected SecondsNanos javaTimeSystemUTC() {
Time.timespec ts = StackValue.get(Time.timespec.class);
int status = PosixUtils.clock_gettime(Time.CLOCK_REALTIME(), ts);
PosixUtils.checkStatusIs0(status, "javaTimeSystemUTC: clock_gettime(CLOCK_REALTIME) failed.");
return new SecondsNanos(ts.tv_sec(), ts.tv_nsec());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.core.windows;

import static com.oracle.svm.core.windows.headers.SysinfoAPI.GetSystemTimeAsFileTime;

import org.graalvm.nativeimage.StackValue;
import org.graalvm.word.WordFactory;

import com.oracle.svm.core.feature.AutomaticallyRegisteredImageSingleton;
import com.oracle.svm.core.util.BasedOnJDKFile;
import com.oracle.svm.core.util.PlatformTimeUtils;
import com.oracle.svm.core.windows.headers.WinBase.FILETIME;

@AutomaticallyRegisteredImageSingleton(PlatformTimeUtils.class)
public final class WindowsPlatformTimeUtils extends PlatformTimeUtils {

@BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-23+9/src/hotspot/os/windows/os_windows.cpp#L1012") //
private static final long OFFSET = 116444736000000000L;

@BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-23+9/src/hotspot/os/windows/os_windows.cpp#L1042-L1044")
private static long offset() {
return OFFSET;
}

/* Returns time ticks in (10th of micro seconds) */
@BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-23+9/src/hotspot/os/windows/os_windows.cpp#L1047-L1050")
private static long windowsToTimeTicks(FILETIME wt) {
long a = WordFactory.unsigned(wt.dwHighDateTime()).shiftLeft(32).or(WordFactory.unsigned(wt.dwLowDateTime())).rawValue();
return (a - offset());
}

@Override
@BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-23+9/src/hotspot/os/windows/os_windows.cpp#L1087-L1094")
protected SecondsNanos javaTimeSystemUTC() {
FILETIME wt = StackValue.get(FILETIME.class);
GetSystemTimeAsFileTime(wt);
long ticks = windowsToTimeTicks(wt); // 10th of micros
long secs = ticks / 10000000L; // 10000 * 1000
long seconds = secs;
long nanos = (ticks - (secs * 10000000L)) * 100L;
return new SecondsNanos(seconds, nanos);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.graalvm.nativeimage.c.type.CCharPointer;
import org.graalvm.word.PointerBase;

import com.oracle.svm.core.windows.headers.WinBase.FILETIME;
import com.oracle.svm.core.windows.headers.WindowsLibC.WCharPointer;

// Checkstyle: stop
Expand Down Expand Up @@ -89,6 +90,13 @@ public interface SYSTEM_INFO extends PointerBase {
short wProcessorRevision();
}

/**
* Retrieves the current system date and time. The information is in Coordinated Universal Time
* (UTC) format.
*/
@CFunction(transition = NO_TRANSITION)
public static native void GetSystemTimeAsFileTime(FILETIME lpSystemTimeAsFileTime);

/** Retrieves the path of the Windows directory. */
@CFunction(transition = NO_TRANSITION)
public static native int GetWindowsDirectoryW(WCharPointer lpBuffer, int uSize);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2023, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2023, Red Hat 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package com.oracle.svm.core.jfr;

import com.oracle.svm.core.annotate.TargetClass;
import com.oracle.svm.core.jdk.JDK23OrLater;

@TargetClass(className = "jdk.jfr.internal.HiddenWait", onlyWith = {HasJfrSupport.class, JDK23OrLater.class})
public final class Target_jdk_jfr_internal_HiddenWait {
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.oracle.svm.core.jdk.JDK22OrLater;
import com.oracle.svm.core.jdk.JDK23OrLater;
import com.oracle.svm.core.jfr.traceid.JfrTraceId;
import com.oracle.svm.core.util.PlatformTimeUtils;
import com.oracle.svm.core.util.VMError;
import com.oracle.svm.util.ReflectionUtil;

Expand Down Expand Up @@ -198,6 +199,13 @@ public static long getTicksFrequency() {
return JfrTicks.getTicksFrequency();
}

/** See {@code JVM#nanosNow}. */
@Substitute
@TargetElement(onlyWith = JDK23OrLater.class)
public static long nanosNow() {
return PlatformTimeUtils.singleton().nanosNow();
}

/** See {@link JVM#log}. */
@Substitute
public static void log(int tagSetId, int level, String message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
package com.oracle.svm.core.jfr;

import com.oracle.svm.core.annotate.TargetClass;
import com.oracle.svm.core.jdk.JDK21OrEarlier;

@TargetClass(className = "jdk.jfr.internal.JVM$ChunkRotationMonitor", onlyWith = HasJfrSupport.class)
@TargetClass(className = "jdk.jfr.internal.JVM$ChunkRotationMonitor", onlyWith = {HasJfrSupport.class, JDK21OrEarlier.class})
public final class Target_jdk_jfr_internal_JVM_ChunkRotationMonitor {
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

package com.oracle.svm.core.jfr.events;

import jdk.graal.compiler.word.Word;

import com.oracle.svm.core.Uninterruptible;
import com.oracle.svm.core.jfr.HasJfrSupport;
import com.oracle.svm.core.jfr.JfrEvent;
Expand All @@ -36,11 +34,14 @@
import com.oracle.svm.core.jfr.JfrNativeEventWriterDataAccess;
import com.oracle.svm.core.jfr.JfrTicks;
import com.oracle.svm.core.jfr.SubstrateJVM;
import com.oracle.svm.core.jfr.Target_jdk_jfr_internal_HiddenWait;
import com.oracle.svm.core.jfr.Target_jdk_jfr_internal_JVM_ChunkRotationMonitor;

import jdk.graal.compiler.word.Word;

public class JavaMonitorWaitEvent {
public static void emit(long startTicks, Object obj, long notifier, long timeout, boolean timedOut) {
if (HasJfrSupport.get() && obj != null && !Target_jdk_jfr_internal_JVM_ChunkRotationMonitor.class.equals(obj.getClass())) {
if (HasJfrSupport.get() && obj != null && !Target_jdk_jfr_internal_JVM_ChunkRotationMonitor.class.equals(obj.getClass()) && !Target_jdk_jfr_internal_HiddenWait.class.equals(obj.getClass())) {
emit0(startTicks, obj, notifier, timeout, timedOut);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.core.util;

import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;

import jdk.graal.compiler.api.replacements.Fold;

/**
* Platform dependent time related utils. See also {@link TimeUtils} for platform independent utils.
*/
public abstract class PlatformTimeUtils {

@Fold
public static PlatformTimeUtils singleton() {
return ImageSingletons.lookup(PlatformTimeUtils.class);
}

@Platforms(Platform.HOSTED_ONLY.class)
protected PlatformTimeUtils() {
}

private long last = 0;

public record SecondsNanos(long seconds, long nanos) {
}

@BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-23+9/src/hotspot/share/jfr/recorder/repository/jfrChunk.cpp#L38-L54")
public long nanosNow() {
// Use same clock source as Instant.now() to ensure
// that Recording::getStopTime() returns an Instant that
// is in sync.
var t = javaTimeSystemUTC();
long seconds = t.seconds;
long nanos = t.nanos;
long now = seconds * 1000000000 + nanos;
if (now > last) {
last = now;
} else {
++last;
}
return last;
}

protected abstract SecondsNanos javaTimeSystemUTC();
}
Loading