From d43dde128a37ade7065ca4149f1c95be26316173 Mon Sep 17 00:00:00 2001 From: liach Date: Sun, 18 May 2025 17:28:00 -0400 Subject: [PATCH 1/3] Fix problems with class value tests --- test/jdk/java/lang/invoke/ClassValueTest.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/test/jdk/java/lang/invoke/ClassValueTest.java b/test/jdk/java/lang/invoke/ClassValueTest.java index fa026955e2549..c6e2af3050033 100644 --- a/test/jdk/java/lang/invoke/ClassValueTest.java +++ b/test/jdk/java/lang/invoke/ClassValueTest.java @@ -176,11 +176,13 @@ public void testGetMany() { } private static final long COMPUTE_TIME_MILLIS = 100; - private static final Duration TIMEOUT = Duration.of(2, ChronoUnit.SECONDS); + private static final Duration TIMEOUT = Duration.ofNanos((long) ( + Duration.of(1, ChronoUnit.SECONDS).toNanos() + * Double.parseDouble(System.getProperty("test.timeout.factor", "1.0")))); private static void await(CountDownLatch latch) { try { - if (!latch.await(2L, TimeUnit.SECONDS)) { + if (!latch.await(TIMEOUT.toNanos(), TimeUnit.NANOSECONDS)) { fail("No signal received"); } } catch (InterruptedException e) { @@ -209,7 +211,6 @@ private static void awaitThreads(Iterable threads) { * Uses junit to do basic stress. */ @Test - @Timeout(value = 4, unit = TimeUnit.SECONDS) void testRemoveStale() throws InterruptedException { CountDownLatch oldInputUsed = new CountDownLatch(1); CountDownLatch inputUpdated = new CountDownLatch(1); @@ -241,7 +242,6 @@ protected Integer computeValue(Class type) { * Tests that calling get() from computeValue() terminates. */ @Test - @Timeout(value = 4, unit = TimeUnit.SECONDS) void testGetInCompute() { ClassValue cv = new ClassValue<>() { @Override @@ -263,7 +263,6 @@ protected Object computeValue(Class type) { * Tests that calling remove() from computeValue() terminates. */ @Test - @Timeout(value = 4, unit = TimeUnit.SECONDS) void testRemoveInCompute() { ClassValue cv = new ClassValue<>() { @Override @@ -304,7 +303,6 @@ protected int[] computeValue(Class type) { } @Test - @Disabled // JDK-8352622 void testWeakAgainstClassValue() { ClassValue cv = new ClassValue<>() { @Override @@ -315,7 +313,10 @@ protected int[] computeValue(Class type) { WeakReference ref = new WeakReference<>(cv.get(int.class)); cv = null; // Remove reference for interpreter - if (!ForceGC.wait(() -> ref.refersTo(null))) { + if (!ForceGC.wait(() -> { + CV1.get(int.class); // flush the weak maps + return ref.refersTo(null); + })) { fail("Timeout"); } } @@ -352,7 +353,6 @@ protected int[] computeValue(Class type) { } @Test - @Timeout(value = 4, unit = TimeUnit.SECONDS) void testRacyRemoveInCompute() { ClassValue cv = new ClassValue<>() { @Override @@ -398,7 +398,6 @@ record One() { private static final ScopedValue THREAD_ID = ScopedValue.newInstance(); @Test - @Timeout(value = 4, unit = TimeUnit.SECONDS) void testNoRecomputeOnUnrelatedRemoval() throws InterruptedException { CountDownLatch t1Started = new CountDownLatch(1); CountDownLatch removeTamper = new CountDownLatch(1); @@ -443,7 +442,6 @@ protected Object computeValue(Class type) { } @Test - @Timeout(value = 4, unit = TimeUnit.SECONDS) void testNoObsoleteInstallation() throws InterruptedException { CountDownLatch slowComputationStart = new CountDownLatch(1); CountDownLatch slowComputationContinue = new CountDownLatch(1); From 792d683ee9e226e70fb685907a26cbc1246de7e2 Mon Sep 17 00:00:00 2001 From: liach Date: Sun, 18 May 2025 17:53:53 -0400 Subject: [PATCH 2/3] Restore incorrectly removed annotation --- test/jdk/java/lang/invoke/ClassValueTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/test/jdk/java/lang/invoke/ClassValueTest.java b/test/jdk/java/lang/invoke/ClassValueTest.java index c6e2af3050033..70ea00c44dc1a 100644 --- a/test/jdk/java/lang/invoke/ClassValueTest.java +++ b/test/jdk/java/lang/invoke/ClassValueTest.java @@ -303,6 +303,7 @@ protected int[] computeValue(Class type) { } @Test + @Disabled // JDK-8352622 void testWeakAgainstClassValue() { ClassValue cv = new ClassValue<>() { @Override From 68a13bb3cc8aea82475565fc3cf09071970998b2 Mon Sep 17 00:00:00 2001 From: liach Date: Wed, 21 May 2025 12:05:35 -0500 Subject: [PATCH 3/3] Increase timeout, add comment for adjust for debugging --- test/jdk/java/lang/invoke/ClassValueTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/jdk/java/lang/invoke/ClassValueTest.java b/test/jdk/java/lang/invoke/ClassValueTest.java index 70ea00c44dc1a..856653b3f92f2 100644 --- a/test/jdk/java/lang/invoke/ClassValueTest.java +++ b/test/jdk/java/lang/invoke/ClassValueTest.java @@ -176,8 +176,9 @@ public void testGetMany() { } private static final long COMPUTE_TIME_MILLIS = 100; + // Adjust this timeout to fail faster for test stalls private static final Duration TIMEOUT = Duration.ofNanos((long) ( - Duration.of(1, ChronoUnit.SECONDS).toNanos() + Duration.of(1, ChronoUnit.MINUTES).toNanos() * Double.parseDouble(System.getProperty("test.timeout.factor", "1.0")))); private static void await(CountDownLatch latch) {