From e65fc20b3726654d628c70c999b7322b08a04cd8 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Wed, 7 Feb 2024 15:01:17 +0100 Subject: [PATCH 1/5] svm: annotate Target_java_nio_DirectByteBuffer with @BasedOnJDKFile --- .../oracle/svm/core/jdk/Target_java_nio_DirectByteBuffer.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_nio_DirectByteBuffer.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_nio_DirectByteBuffer.java index c680cd8cdf7f..7aeaebd70ce2 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_nio_DirectByteBuffer.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_nio_DirectByteBuffer.java @@ -30,9 +30,11 @@ import com.oracle.svm.core.annotate.RecomputeFieldValue; import com.oracle.svm.core.annotate.TargetClass; import com.oracle.svm.core.heap.Target_jdk_internal_ref_Cleaner; +import com.oracle.svm.core.util.BasedOnJDKFile; import com.oracle.svm.core.util.VMError; @TargetClass(className = "java.nio.DirectByteBuffer") +@BasedOnJDKFile("src/java.base/share/classes/java/nio/Direct-X-Buffer.java.template") public final class Target_java_nio_DirectByteBuffer { /** From fbb3778bbe5aabba8c5c402cac209d8945ce7c72 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Tue, 20 Feb 2024 08:31:15 +0100 Subject: [PATCH 2/5] svm: annotate *ThreadCpuTimeSupport with @BasedOnJDKFile --- .../svm/core/posix/darwin/DarwinThreadCpuTimeSupport.java | 6 ++---- .../svm/core/posix/linux/LinuxThreadCpuTimeSupport.java | 6 ++---- .../svm/core/windows/WindowsThreadCpuTimeSupport.java | 6 ++---- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinThreadCpuTimeSupport.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinThreadCpuTimeSupport.java index 82314605850b..7ad5ccb58d25 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinThreadCpuTimeSupport.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinThreadCpuTimeSupport.java @@ -24,6 +24,7 @@ */ package com.oracle.svm.core.posix.darwin; +import com.oracle.svm.core.util.BasedOnJDKFile; import org.graalvm.nativeimage.CurrentIsolate; import org.graalvm.nativeimage.IsolateThread; import org.graalvm.nativeimage.StackValue; @@ -54,10 +55,7 @@ public long getThreadCpuTime(IsolateThread isolateThread, boolean includeSystemT return getThreadCpuTime(machThread, includeSystemTime); } - /** - * Based on jdk-20-ga, see os::thread_cpu_time. - */ + @BasedOnJDKFile("src/hotspot/os/bsd/os_bsd.cpp#L2382-L2407") @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) private static long getThreadCpuTime(int machThread, boolean includeSystemTime) { CIntPointer sizePointer = UnsafeStackValue.get(Integer.BYTES); diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxThreadCpuTimeSupport.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxThreadCpuTimeSupport.java index 52d934ee01a3..061fad72cd06 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxThreadCpuTimeSupport.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxThreadCpuTimeSupport.java @@ -24,6 +24,7 @@ */ package com.oracle.svm.core.posix.linux; +import com.oracle.svm.core.util.BasedOnJDKFile; import org.graalvm.nativeimage.CurrentIsolate; import org.graalvm.nativeimage.IsolateThread; import org.graalvm.nativeimage.StackValue; @@ -65,10 +66,7 @@ public long getThreadCpuTime(IsolateThread isolateThread, boolean includeSystemT return fastCpuTime(pthread); } - /** - * Based on jdk-20-ga, see fast_cpu_time(...). - */ + @BasedOnJDKFile("src/hotspot/os/linux/os_linux.cpp#L5072-L5084") @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) private static long fastCpuTime(pthread_t pthread) { CIntPointer threadsClockId = StackValue.get(Integer.BYTES); diff --git a/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsThreadCpuTimeSupport.java b/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsThreadCpuTimeSupport.java index b091fc530dd4..c2ac21eb03ca 100644 --- a/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsThreadCpuTimeSupport.java +++ b/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsThreadCpuTimeSupport.java @@ -24,6 +24,7 @@ */ package com.oracle.svm.core.windows; +import com.oracle.svm.core.util.BasedOnJDKFile; import org.graalvm.nativeimage.CurrentIsolate; import org.graalvm.nativeimage.IsolateThread; import org.graalvm.nativeimage.StackValue; @@ -54,10 +55,7 @@ public long getThreadCpuTime(IsolateThread isolateThread, boolean includeSystemT return getThreadCpuTime(hThread, includeSystemTime); } - /** - * Based on jdk-20-ga, see os::thread_cpu_time. - */ + @BasedOnJDKFile("src/hotspot/os/windows/os_windows.cpp#L4709-L4725") @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) private static long getThreadCpuTime(HANDLE hThread, boolean includeSystemTime) { FILETIME create = StackValue.get(FILETIME.class); From e22e123c41517eca9e7702512c71291b8717c910 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Wed, 21 Feb 2024 09:29:58 +0100 Subject: [PATCH 3/5] svm: Add @BasedOnJDKFile annotations to Module native substitutions --- .../com/oracle/svm/core/jdk/Target_java_lang_Module.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_Module.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_Module.java index ab1b98e77722..f067f2bc0122 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_Module.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_Module.java @@ -33,6 +33,7 @@ import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; import com.oracle.svm.core.annotate.TargetElement; +import com.oracle.svm.core.util.BasedOnJDKFile; @SuppressWarnings("unused") @TargetClass(value = java.lang.Module.class) @@ -53,6 +54,7 @@ public boolean isNativeAccessEnabled() { public native void ensureNativeAccess(Class owner, String methodName, Class currentClass); @Substitute + @BasedOnJDKFile("src/hotspot/share/classfile/modules.cpp#L275-L479") private static void defineModule0(Module module, boolean isOpen, String version, String location, Object[] pns) { if (Arrays.stream(pns).anyMatch(Objects::isNull)) { throw new IllegalArgumentException("Bad package name"); @@ -62,6 +64,7 @@ private static void defineModule0(Module module, boolean isOpen, String version, } @Substitute + @BasedOnJDKFile("src/hotspot/share/classfile/modules.cpp#L763-L799") private static void addReads0(Module from, Module to) { if (Objects.isNull(from)) { throw new NullPointerException("The from_module is null"); @@ -69,6 +72,7 @@ private static void addReads0(Module from, Module to) { } @Substitute + @BasedOnJDKFile("src/hotspot/share/classfile/modules.cpp#L753-L761") private static void addExports0(Module from, String pn, Module to) { if (Objects.isNull(to)) { throw new NullPointerException("The to_module is null"); @@ -79,12 +83,14 @@ private static void addExports0(Module from, String pn, Module to) { } @Substitute + @BasedOnJDKFile("src/hotspot/share/classfile/modules.cpp#L686-L750") private static void addExportsToAll0(Module from, String pn) { ModuleUtil.checkFromModuleAndPackageNullability(from, pn); ModuleUtil.checkIsPackageContainedInModule(pn, from); } @Substitute + @BasedOnJDKFile("src/hotspot/share/classfile/modules.cpp#L869-L918") private static void addExportsToAllUnnamed0(Module from, String pn) { ModuleUtil.checkFromModuleAndPackageNullability(from, pn); if (from.isNamed()) { From f7831ce9b94ea0f617a00b25ec27aac917eb3be9 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Wed, 21 Feb 2024 14:16:05 +0000 Subject: [PATCH 4/5] svm: fix *ThreadCpuTimeSupport @BasedOnJDKFile line ranges --- .../svm/core/posix/darwin/DarwinThreadCpuTimeSupport.java | 2 +- .../oracle/svm/core/posix/linux/LinuxThreadCpuTimeSupport.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinThreadCpuTimeSupport.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinThreadCpuTimeSupport.java index 7ad5ccb58d25..85644065d6a7 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinThreadCpuTimeSupport.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/darwin/DarwinThreadCpuTimeSupport.java @@ -55,7 +55,7 @@ public long getThreadCpuTime(IsolateThread isolateThread, boolean includeSystemT return getThreadCpuTime(machThread, includeSystemTime); } - @BasedOnJDKFile("src/hotspot/os/bsd/os_bsd.cpp#L2382-L2407") + @BasedOnJDKFile("src/hotspot/os/bsd/os_bsd.cpp#L2403-L2428") @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) private static long getThreadCpuTime(int machThread, boolean includeSystemTime) { CIntPointer sizePointer = UnsafeStackValue.get(Integer.BYTES); diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxThreadCpuTimeSupport.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxThreadCpuTimeSupport.java index 061fad72cd06..91c1ba0c35b0 100644 --- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxThreadCpuTimeSupport.java +++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/linux/LinuxThreadCpuTimeSupport.java @@ -66,7 +66,7 @@ public long getThreadCpuTime(IsolateThread isolateThread, boolean includeSystemT return fastCpuTime(pthread); } - @BasedOnJDKFile("src/hotspot/os/linux/os_linux.cpp#L5072-L5084") + @BasedOnJDKFile("src/hotspot/os/linux/os_linux.cpp#L5086-L5098") @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) private static long fastCpuTime(pthread_t pthread) { CIntPointer threadsClockId = StackValue.get(Integer.BYTES); @@ -77,6 +77,7 @@ private static long fastCpuTime(pthread_t pthread) { } @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) + @BasedOnJDKFile("src/hotspot/os/linux/os_linux.cpp#L4290-L4295") private static long fastThreadCpuTime(int clockId) { timespec time = UnsafeStackValue.get(timespec.class); if (LinuxTime.NoTransitions.clock_gettime(clockId, time) != 0) { From caf5d60634a2cf2ea8e86718d4fdeff4693342e9 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Wed, 21 Feb 2024 18:12:17 +0100 Subject: [PATCH 5/5] svm: update line ranges for @BasedOnJDKFile in WindowsUtils --- .../src/com/oracle/svm/core/windows/WindowsUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsUtils.java b/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsUtils.java index c0808ed094dd..81459234e0c3 100644 --- a/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsUtils.java +++ b/substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/WindowsUtils.java @@ -171,8 +171,8 @@ static void writeBytes(FileDescriptor descriptor, byte[] bytes, int off, int len /** Retrieve a nanosecond counter for elapsed time measurement. */ @Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true) - @BasedOnJDKFile("src/hotspot/os/windows/os_windows.cpp#L970-L977") - @BasedOnJDKFile("src/hotspot/os/windows/os_windows.cpp#L1075-L1081") + @BasedOnJDKFile("src/hotspot/os/windows/os_windows.cpp#L990-L997") + @BasedOnJDKFile("src/hotspot/os/windows/os_windows.cpp#L1095-L1101") public static long getNanoCounter() { if (performanceFrequency == 0L) { CLongPointer count = StackValue.get(CLongPointer.class);