Closed quadhier closed 1 year ago
@quadhier Thanks for this effort!
Did this test pass on your testing box? It just failed with my macOS and Kona JDK (Fiber) 8u362.
test YieldQueuing.testYieldWithEmptyLocalQueue(): failure
java.lang.AssertionError: Lists differ at element [0]: A != B expected [A] but found [B]
...
test YieldQueuing.testYieldWithNonEmptyLocalQueue(): failure
java.lang.AssertionError: Lists differ at element [0]: A != C expected [A] but found [C]
...
Did this test pass on your testing box? It just failed with my macOS and Kona JDK (Fiber) 8u362.
Thanks for your reviews @johnshajiang ! After adding public
modifiers to the classes and methods under test, this test also fails on my environment. (It seems that the test methods didn’t get executed before that). I’ll look into it.
可以列一下,合入Kona Fiber的测试用例和loom原始测试用例的差异(类似git diff就行,看起来更清楚一点)
可以列一下,合入Kona Fiber的测试用例和loom原始测试用例的差异(类似git diff就行,看起来更清楚一点)
好的,谢谢你的建议 @miao-zheng ,已更新。鉴于当前还有测试用例没有调通,我已将PR状态改为Draft。
Hi, @johnshajiang and @miao-zheng , I have updated the test case and comments. Now it could pass on my linux x64 version of KonaFiber-8 (which is a fresh build from the latest source code of KonaFiber-8) and my macos version of x64 KonaFiber-8 (which is the latest release 1.8.0_362_fiber). I would appreciate it if you could try this jtreg test again whenever you have time. And I will add detailed analysis of these changes later. Thanks in advance!
@quadhier The updated test just passed on my macOS x64 with KonaFIber 8u362.
Hi @johnshajiang and @miao-zheng , thanks for your reviews! I have addressed the review comments and added detailed explainations for the changes.
This patch mainly transplants jtreg test
test/jdk/java/lang/Thread/virtual/YieldQueuing.java
of Loom to KonaFiber-8.Code changes
Changes for successful compilation:
@requires vm.continuations
in jtreg header since this is always satisfied inKonaFiber
testng
instead ofjunit
in jtreg header and import statementsvar
keywords with specific class names andList.of()
call withArrays.asList()
callThread.onSpinWait()
calls since it is just an optimization hint (please refer to JEP 285) that we have not implemented yetChanges for successful test:
public
access modifiers to the test class and methods for unit test to work-Djdk.virtualThreadScheduler.maxPoolSize=1
vm option since it doesn't take effect in KonaFiber-8testYieldWithEmptyLocalQueue()
, use a scheduler created byExecutors.newSingleThreadExecutor()
instead of the defaultForkJoinPool
since this test is intended to execute with only one carrier threadtestYieldWithNonEmptyLocalQueue()
, use a scheduler created byExecutors.newSingleThreadExecutor()
as well and update test oracle according toThreadPoolExecutor
's (which is the scheduler here) implementation on KonaFiber-8Reason behind major changes of
testYieldWithEmptyLocalQueue()
According to the Java option
-Djdk.virtualThreadScheduler.maxPoolSize=1
set in jtreg header, this test is indicated to be executed using a scheduler with only one carrier thread.The default scheduler is
ForkJoinPool
but KonaFiber-8 doesn't have this option to set a fixed number of carrier threads forForkJoinPool
,Executors.newSingleThreadExecutor()
is used instead to create such a scheduler.Reason behind major changes of
testYieldWithNonEmptyLocalQueue()
Original version of this test case uses
ForkJoinPool
as a scheduler but nowThreadPoolExecutor
is used instead. These two schedulers have different orders of handling tasks submitted from their worker thread.In this test, roughly speaking, 5 tasks are submitted to the scheduler. They are (in the order of submission time from earliest to latest):
start()
calls to submit continuations of thread virtual threadsThread.unpark()
called in VirtualThread-B to submit the continuation of VirtualThreadd-AThread.yield()
called in VirtualThread-B to submit the continuation of VirtualThread-BFor
ForkJoinPool
, since 2-nd and 3-rd submissions happen in its worker thread, and VirtualThread-C is not executed yet, they are executed before VirtualThread-C. (Please refer toForkJoinPool
's implementation.) And the last three output should be"A", "B", "C"
.For
ThreadPoolExecutor
, the execution order is exactly same as the submission order, so the VirtualThread-C is executed before continuations of VirtualThread-A and VirtualThread-B. The last three output should be"C", "A", "B"
.With different schedulers come different testing results.
Detailed diff output
The following diff output shows all the changes (you could also see it here in GitHub):
Progress
testYieldWithEmptyLocalQueue()
testYieldWithNonEmptyLocalQueue()
Path consideration
BTW, just a minor problem: shall I put the
YieldQueuing.java
file in the pathjdk/test/java/lang/VirtualThread
orjdk/test/java/lang/VirtualThread/loom
? I believe the former is the corresponding path of what this test used to be in Loom but I see most of the transplanted tests in the latter. :P