Skip to content

Commit 1e083db

Browse files
committed
svm: adopt 'JDK-8304732: jdk/jfr/api/consumer/recordingstream/TestStop.java failed again with "Expected outer stream to have 3 events"'
1 parent b864acb commit 1e083db

File tree

8 files changed

+239
-4
lines changed

8 files changed

+239
-4
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.oracle.svm.core.posix;
26+
27+
import org.graalvm.nativeimage.StackValue;
28+
29+
import com.oracle.svm.core.feature.AutomaticallyRegisteredImageSingleton;
30+
import com.oracle.svm.core.posix.headers.Time;
31+
import com.oracle.svm.core.util.BasedOnJDKFile;
32+
import com.oracle.svm.core.util.PlatformTimeUtils;
33+
34+
@AutomaticallyRegisteredImageSingleton(PlatformTimeUtils.class)
35+
public final class PosixPlatformTimeUtils extends PlatformTimeUtils {
36+
37+
@Override
38+
@BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-24+3/src/hotspot/os/posix/os_posix.cpp#L1409-L1415")
39+
protected SecondsNanos javaTimeSystemUTC() {
40+
Time.timespec ts = StackValue.get(Time.timespec.class);
41+
int status = PosixUtils.clock_gettime(Time.CLOCK_REALTIME(), ts);
42+
PosixUtils.checkStatusIs0(status, "javaTimeSystemUTC: clock_gettime(CLOCK_REALTIME) failed.");
43+
return new SecondsNanos(ts.tv_sec(), ts.tv_nsec());
44+
}
45+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.oracle.svm.core.windows;
26+
27+
import static com.oracle.svm.core.windows.headers.SysinfoAPI.GetSystemTimeAsFileTime;
28+
29+
import org.graalvm.nativeimage.StackValue;
30+
import org.graalvm.word.WordFactory;
31+
32+
import com.oracle.svm.core.feature.AutomaticallyRegisteredImageSingleton;
33+
import com.oracle.svm.core.util.BasedOnJDKFile;
34+
import com.oracle.svm.core.util.PlatformTimeUtils;
35+
import com.oracle.svm.core.windows.headers.WinBase.FILETIME;
36+
37+
@AutomaticallyRegisteredImageSingleton(PlatformTimeUtils.class)
38+
public final class WindowsPlatformTimeUtils extends PlatformTimeUtils {
39+
// Checkstyle: stop
40+
41+
@BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-24+3/src/hotspot/os/windows/os_windows.cpp#L1123") //
42+
private static final long OFFSET = 116444736000000000L;
43+
44+
@BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-24+3/src/hotspot/os/windows/os_windows.cpp#L1153-L1155")
45+
private static long offset() {
46+
return OFFSET;
47+
}
48+
49+
/* Returns time ticks in (10th of micro seconds) */
50+
@BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-24+3/src/hotspot/os/windows/os_windows.cpp#L1158-L1161")
51+
private static long windowsToTimeTicks(FILETIME wt) {
52+
long a = WordFactory.unsigned(wt.dwHighDateTime()).shiftLeft(32).or(WordFactory.unsigned(wt.dwLowDateTime())).rawValue();
53+
return (a - offset());
54+
}
55+
56+
@Override
57+
@BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-24+3/src/hotspot/os/windows/os_windows.cpp#L1198-L1205")
58+
protected SecondsNanos javaTimeSystemUTC() {
59+
FILETIME wt = StackValue.get(FILETIME.class);
60+
GetSystemTimeAsFileTime(wt);
61+
long ticks = windowsToTimeTicks(wt); // 10th of micros
62+
long secs = ticks / 10000000L; // 10000 * 1000
63+
long seconds = secs;
64+
long nanos = (ticks - (secs * 10000000L)) * 100L;
65+
return new SecondsNanos(seconds, nanos);
66+
}
67+
68+
}

substratevm/src/com.oracle.svm.core.windows/src/com/oracle/svm/core/windows/headers/SysinfoAPI.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.graalvm.nativeimage.c.type.CCharPointer;
3535
import org.graalvm.word.PointerBase;
3636

37+
import com.oracle.svm.core.windows.headers.WinBase.FILETIME;
3738
import com.oracle.svm.core.windows.headers.WindowsLibC.WCharPointer;
3839

3940
// Checkstyle: stop
@@ -89,6 +90,13 @@ public interface SYSTEM_INFO extends PointerBase {
8990
short wProcessorRevision();
9091
}
9192

93+
/**
94+
* Retrieves the current system date and time. The information is in Coordinated Universal Time
95+
* (UTC) format.
96+
*/
97+
@CFunction(transition = NO_TRANSITION)
98+
public static native void GetSystemTimeAsFileTime(FILETIME lpSystemTimeAsFileTime);
99+
92100
/** Retrieves the path of the Windows directory. */
93101
@CFunction(transition = NO_TRANSITION)
94102
public static native int GetWindowsDirectoryW(WCharPointer lpBuffer, int uSize);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2023, 2023, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2023, 2023, Red Hat Inc. All rights reserved.
4+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation. Oracle designates this
9+
* particular file as subject to the "Classpath" exception as provided
10+
* by Oracle in the LICENSE file that accompanied this code.
11+
*
12+
* This code is distributed in the hope that it will be useful, but WITHOUT
13+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15+
* version 2 for more details (a copy is included in the LICENSE file that
16+
* accompanied this code).
17+
*
18+
* You should have received a copy of the GNU General Public License version
19+
* 2 along with this work; if not, write to the Free Software Foundation,
20+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21+
*
22+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
23+
* or visit www.oracle.com if you need additional information or have any
24+
* questions.
25+
*/
26+
27+
package com.oracle.svm.core.jfr;
28+
29+
import com.oracle.svm.core.annotate.TargetClass;
30+
import com.oracle.svm.core.jdk.JDK23OrLater;
31+
32+
@TargetClass(className = "jdk.jfr.internal.HiddenWait", onlyWith = {HasJfrSupport.class, JDK23OrLater.class})
33+
public final class Target_jdk_jfr_internal_HiddenWait {
34+
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_JVM.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import com.oracle.svm.core.jdk.JDK22OrLater;
4444
import com.oracle.svm.core.jdk.JDK23OrLater;
4545
import com.oracle.svm.core.jfr.traceid.JfrTraceId;
46+
import com.oracle.svm.core.util.PlatformTimeUtils;
4647
import com.oracle.svm.core.util.VMError;
4748
import com.oracle.svm.util.ReflectionUtil;
4849

@@ -198,6 +199,13 @@ public static long getTicksFrequency() {
198199
return JfrTicks.getTicksFrequency();
199200
}
200201

202+
/** See {@code JVM#nanosNow}. */
203+
@Substitute
204+
@TargetElement(onlyWith = JDK23OrLater.class)
205+
public static long nanosNow() {
206+
return PlatformTimeUtils.singleton().nanosNow();
207+
}
208+
201209
/** See {@link JVM#log}. */
202210
@Substitute
203211
public static void log(int tagSetId, int level, String message) {

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_JVM_ChunkRotationMonitor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
package com.oracle.svm.core.jfr;
2828

2929
import com.oracle.svm.core.annotate.TargetClass;
30+
import com.oracle.svm.core.jdk.JDK21OrEarlier;
3031

31-
@TargetClass(className = "jdk.jfr.internal.JVM$ChunkRotationMonitor", onlyWith = HasJfrSupport.class)
32+
@TargetClass(className = "jdk.jfr.internal.JVM$ChunkRotationMonitor", onlyWith = {HasJfrSupport.class, JDK21OrEarlier.class})
3233
public final class Target_jdk_jfr_internal_JVM_ChunkRotationMonitor {
3334
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/events/JavaMonitorWaitEvent.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626

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

29-
import jdk.graal.compiler.word.Word;
30-
3129
import com.oracle.svm.core.Uninterruptible;
3230
import com.oracle.svm.core.jfr.HasJfrSupport;
3331
import com.oracle.svm.core.jfr.JfrEvent;
@@ -36,11 +34,14 @@
3634
import com.oracle.svm.core.jfr.JfrNativeEventWriterDataAccess;
3735
import com.oracle.svm.core.jfr.JfrTicks;
3836
import com.oracle.svm.core.jfr.SubstrateJVM;
37+
import com.oracle.svm.core.jfr.Target_jdk_jfr_internal_HiddenWait;
3938
import com.oracle.svm.core.jfr.Target_jdk_jfr_internal_JVM_ChunkRotationMonitor;
4039

40+
import jdk.graal.compiler.word.Word;
41+
4142
public class JavaMonitorWaitEvent {
4243
public static void emit(long startTicks, Object obj, long notifier, long timeout, boolean timedOut) {
43-
if (HasJfrSupport.get() && obj != null && !Target_jdk_jfr_internal_JVM_ChunkRotationMonitor.class.equals(obj.getClass())) {
44+
if (HasJfrSupport.get() && obj != null && !Target_jdk_jfr_internal_JVM_ChunkRotationMonitor.class.equals(obj.getClass()) && !Target_jdk_jfr_internal_HiddenWait.class.equals(obj.getClass())) {
4445
emit0(startTicks, obj, notifier, timeout, timedOut);
4546
}
4647
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.oracle.svm.core.util;
26+
27+
import org.graalvm.nativeimage.ImageSingletons;
28+
import org.graalvm.nativeimage.Platform;
29+
import org.graalvm.nativeimage.Platforms;
30+
31+
import jdk.graal.compiler.api.replacements.Fold;
32+
33+
/**
34+
* Platform dependent time related utils. See also {@link TimeUtils} for platform independent utils.
35+
*/
36+
public abstract class PlatformTimeUtils {
37+
38+
@Fold
39+
public static PlatformTimeUtils singleton() {
40+
return ImageSingletons.lookup(PlatformTimeUtils.class);
41+
}
42+
43+
@Platforms(Platform.HOSTED_ONLY.class)
44+
protected PlatformTimeUtils() {
45+
}
46+
47+
private long last = 0;
48+
49+
public record SecondsNanos(long seconds, long nanos) {
50+
}
51+
52+
@BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-24+3/src/hotspot/share/jfr/recorder/repository/jfrChunk.cpp#L38-L54")
53+
public long nanosNow() {
54+
// Use same clock source as Instant.now() to ensure
55+
// that Recording::getStopTime() returns an Instant that
56+
// is in sync.
57+
var t = javaTimeSystemUTC();
58+
long seconds = t.seconds;
59+
long nanos = t.nanos;
60+
long now = seconds * 1000000000 + nanos;
61+
if (now > last) {
62+
last = now;
63+
} else {
64+
++last;
65+
}
66+
return last;
67+
}
68+
69+
protected abstract SecondsNanos javaTimeSystemUTC();
70+
}

0 commit comments

Comments
 (0)