JDK-8270798 : Test java/foreign/TestResourceScope.java fails: expected [M] but found [N]
  • Type: Bug
  • Component: core-libs
  • Affected Version: 17
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2021-07-15
  • Updated: 2021-12-07
  • Resolved: 2021-12-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 18
18Resolved
Related Reports
Blocks :  
Duplicate :  
Relates :  
Description
Failure has returned after JDK-8268428 was fixed a few weeks ago:

test TestResourceScope.testSharedMultiThread(TestResourceScope$$Lambda$92/0x0000000800c35168@277f549): failure
java.lang.AssertionError: expected [4950] but found [4852]
	at org.testng.Assert.fail(Assert.java:99)
	at org.testng.Assert.failNotEquals(Assert.java:1037)
	at org.testng.Assert.assertEqualsImpl(Assert.java:140)
	at org.testng.Assert.assertEquals(Assert.java:122)
	at org.testng.Assert.assertEquals(Assert.java:907)
	at org.testng.Assert.assertEquals(Assert.java:917)
	at TestResourceScope.testSharedMultiThread(TestResourceScope.java:149)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:132)
	at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:599)
	at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:174)
	at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
	at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:822)
	at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:147)
	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at org.testng.TestRunner.privateRun(TestRunner.java:764)
	at org.testng.TestRunner.run(TestRunner.java:585)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:384)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:378)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:337)
	at org.testng.SuiteRunner.run(SuiteRunner.java:286)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1218)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
	at org.testng.TestNG.runSuites(TestNG.java:1069)
	at org.testng.TestNG.run(TestNG.java:1037)
	at com.sun.javatest.regtest.agent.TestNGRunner.main(TestNGRunner.java:94)
	at com.sun.javatest.regtest.agent.TestNGRunner.main(TestNGRunner.java:54)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at com.sun.javatest.regtest.agent.MainWrapper$MainThread.run(MainWrapper.java:127)
	at java.base/java.lang.Thread.run(Thread.java:833)
test TestResourceScope.testSharedMultiThread(TestResourceScope$$Lambda$93/0x0000000800c35388@524bbb19): success
Comments
[~mcimadamore] only issues for which a changeset has been pushed should be marked as fixed. Please reopen this and close as a duplicate of the JEP-419 implementation issue. Thanks.
07-12-2021

Resolved as part of JEP-419
07-12-2021

Here's a log file snippet from the jdk-18+17-971-tier6 sighting on windows-x64: ----------System.out:(69/5352)---------- test TestResourceScope.testCloseConfinedLock(): success test TestResourceScope.testCloseEmptyConfinedScope(): success test TestResourceScope.testCloseEmptySharedScope(): success test TestResourceScope.testConfined(TestResourceScope$$Lambda$88/0x0000000800c349d0@5001f892): success test TestResourceScope.testConfined(TestResourceScope$$Lambda$89/0x0000000800c34bd8@545fe428): success test TestResourceScope.testConfined(TestResourceScope$$Lambda$90/0x0000000800c34de0@109a4a16): success test TestResourceScope.testLockSharedMultiThread(TestResourceScope$$Lambda$88/0x0000000800c349d0@5001f892): success test TestResourceScope.testLockSharedMultiThread(TestResourceScope$$Lambda$89/0x0000000800c34bd8@545fe428): success test TestResourceScope.testLockSharedMultiThread(TestResourceScope$$Lambda$90/0x0000000800c34de0@109a4a16): success test TestResourceScope.testLockSingleThread(TestResourceScope$$Lambda$88/0x0000000800c349d0@5001f892): success test TestResourceScope.testLockSingleThread(TestResourceScope$$Lambda$89/0x0000000800c34bd8@545fe428): success test TestResourceScope.testLockSingleThread(TestResourceScope$$Lambda$90/0x0000000800c34de0@109a4a16): success test TestResourceScope.testScopeHandles(TestResourceScope$$Lambda$96/0x0000000800c35e60@6640cf9): success test TestResourceScope.testScopeHandles(TestResourceScope$$Lambda$97/0x0000000800c36068@4e001adb): success test TestResourceScope.testScopeHandles(TestResourceScope$$Lambda$98/0x0000000800c36270@40af5572): success test TestResourceScope.testScopeHandles(TestResourceScope$$Lambda$99/0x0000000800c36478@1cb0d1ed): success test TestResourceScope.testSharedMultiThread(TestResourceScope$$Lambda$88/0x0000000800c349d0@5001f892): failure java.lang.AssertionError: expected [4950] but found [4853] at org.testng.Assert.fail(Assert.java:99) at org.testng.Assert.failNotEquals(Assert.java:1037) at org.testng.Assert.assertEqualsImpl(Assert.java:140) at org.testng.Assert.assertEquals(Assert.java:122) at org.testng.Assert.assertEquals(Assert.java:907) at org.testng.Assert.assertEquals(Assert.java:917) at TestResourceScope.testSharedMultiThread(TestResourceScope.java:149) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:132) at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:599) at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:174) at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46) at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:822) at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:147) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128) at java.base/java.util.ArrayList.forEach(ArrayList.java:1511) at org.testng.TestRunner.privateRun(TestRunner.java:764) at org.testng.TestRunner.run(TestRunner.java:585) at org.testng.SuiteRunner.runTest(SuiteRunner.java:384) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:378) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:337) at org.testng.SuiteRunner.run(SuiteRunner.java:286) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1218) at org.testng.TestNG.runSuitesLocally(TestNG.java:1140) at org.testng.TestNG.runSuites(TestNG.java:1069) at org.testng.TestNG.run(TestNG.java:1037) at com.sun.javatest.regtest.agent.TestNGRunner.main(TestNGRunner.java:94) at com.sun.javatest.regtest.agent.TestNGRunner.main(TestNGRunner.java:54) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at com.sun.javatest.regtest.agent.MainWrapper$MainThread.run(MainWrapper.java:127) at java.base/java.lang.Thread.run(Thread.java:833) test TestResourceScope.testSharedMultiThread(TestResourceScope$$Lambda$89/0x0000000800c34bd8@545fe428): success test TestResourceScope.testSharedMultiThread(TestResourceScope$$Lambda$90/0x0000000800c34de0@109a4a16): success test TestResourceScope.testSharedSingleThread(TestResourceScope$$Lambda$88/0x0000000800c349d0@5001f892): success test TestResourceScope.testSharedSingleThread(TestResourceScope$$Lambda$89/0x0000000800c34bd8@545fe428): success test TestResourceScope.testSharedSingleThread(TestResourceScope$$Lambda$90/0x0000000800c34de0@109a4a16): success =============================================== java/foreign/TestResourceScope.java Total tests run: 22, Passes: 21, Failures: 1, Skips: 0 =============================================== ----------System.err:(15/929)---------- WARNING: Using incubator modules: jdk.incubator.foreign java.lang.Exception: failures: 1 at com.sun.javatest.regtest.agent.TestNGRunner.main(TestNGRunner.java:96) at com.sun.javatest.regtest.agent.TestNGRunner.main(TestNGRunner.java:54) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at com.sun.javatest.regtest.agent.MainWrapper$MainThread.run(MainWrapper.java:127) at java.base/java.lang.Thread.run(Thread.java:833) JavaTest Message: Test threw exception: java.lang.Exception: failures: 1 JavaTest Message: shutting down test STATUS:Failed.`main' threw exception: java.lang.Exception: failures: 1 ----------rerun:(45/5290)*----------
26-09-2021

Another ARM failure - John and I went through the synchronization code several times and could not spot anything wrong. Maybe there's an issue with getAcquire/setRelease semantics on ARM platform?
25-08-2021

After a chat with John, it seems like VarHandle javadoc leaves something to be desired and that the code is doing the right thing (e.g. the semantics of the CAS operations used here should be good enough). Need to dig deeper.
16-07-2021

Possible fix: ``` diff --git a/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/SharedScope.java b/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/SharedScope.java index 8bbeaaab829..952ba57fe6a 100644 --- a/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/SharedScope.java +++ b/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/SharedScope.java @@ -133,9 +133,9 @@ class SharedScope extends ResourceScopeImpl { @Override void add(ResourceCleanup cleanup) { while (true) { - ResourceCleanup prev = (ResourceCleanup) FST.getAcquire(this); + ResourceCleanup prev = (ResourceCleanup) FST.getVolatile(this); cleanup.next = prev; - ResourceCleanup newSegment = (ResourceCleanup) FST.compareAndExchangeRelease(this, prev, cleanup); + ResourceCleanup newSegment = (ResourceCleanup) FST.compareAndExchange(this, prev, cleanup); if (newSegment == ResourceCleanup.CLOSED_LIST) { // too late throw new IllegalStateException("Already closed"); @@ -155,9 +155,9 @@ class SharedScope extends ResourceScopeImpl { //ok now we're really closing down ResourceCleanup prev = null; while (true) { - prev = (ResourceCleanup) FST.getAcquire(this); + prev = (ResourceCleanup) FST.getVolatile(this); // no need to check for DUMMY, since only one thread can get here! - if (FST.weakCompareAndSetRelease(this, prev, ResourceCleanup.CLOSED_LIST)) { + if (FST.compareAndSet(this, prev, ResourceCleanup.CLOSED_LIST)) { break; } } ```
16-07-2021

There is no obvious issue in the test. Instead, the implementation use of compareAndExchangeAcquire and weakCompareAndSetRelease might well be the problem, as these primitive just use a plain get (and not a get acquire) in order to determine the witness value. Such a plain get might miss concurrent updates on same variables by a different thread - which means the CAS loop might fail.
16-07-2021

This is a different failure than the one in JDK-8268428 - the test class is the same, but the test method is different.
16-07-2021