From 64a843dbbee744bdc6c82c8fe8ccdbd3cf15abcd Mon Sep 17 00:00:00 2001 From: Axel Boldt-Christmas Date: Wed, 19 Nov 2025 17:05:22 +0000 Subject: [PATCH] OSX: Semaphore.trywait requires os::Bsd::clock_init --- test/hotspot/gtest/runtime/test_semaphore.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/hotspot/gtest/runtime/test_semaphore.cpp b/test/hotspot/gtest/runtime/test_semaphore.cpp index 2daa49d5885..06d38c6a623 100644 --- a/test/hotspot/gtest/runtime/test_semaphore.cpp +++ b/test/hotspot/gtest/runtime/test_semaphore.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -22,6 +22,7 @@ */ #include "runtime/semaphore.hpp" +#include "runtime/os.inline.hpp" #include "unittest.hpp" static void test_semaphore_single_separate(uint count) { @@ -96,6 +97,13 @@ TEST(Semaphore, many) { } TEST(Semaphore, trywait) { +#ifdef __APPLE__ + // On __APPLE__ semaphore trywait uses os::javaTimeNanos() which requires the + // clock to be initialized. os::Bsd::clock_init() currently allows for multiple + // invocations, so this test is fine to run either before or after another VM + // gtest. + os::Bsd::clock_init(); +#endif // __APPLE__ for (uint max = 0; max < 10; max++) { for (uint value = 0; value < max; value++) { test_semaphore_trywait(value, max);