On Sat, 14 Nov 2026 16:20:11 GMT, Alan Bateman <[email protected]> wrote:

> The "blocked in write" tests in BlockingSocketOps and BlockingChannelOps are 
> problematic as the underlying non-blocking socket may be polled as writable 
> several times before the virtual thread writer blocks indefinitely. The tests 
> were updated recently to additionally test the blocked thread's parkBlocker, 
> which makes it harder to test when it wakes up several times.
> 
> The tests are simplified to avoid special casing the writing case. The 
> runAfterParkedAsync method in both tests now polls the thread until it parks 
> and the parkBlocker is set. BlockingChannelOps tests the expected parkBlocker 
> whereas BlockingSocketOps just observed a non-null parkBlocker.
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

I reviewed this and ran both updated tests on a linux-x86_64 build of this 
branch (54059cfc). All four configurations of both tests pass (8 test ids, 390 
JUnit test methods).

The approach looks right. The old assertion was inherently racy, since the 
write can be polled writable several times, so by the time the test checks 
`parkBlocker()` the thread may have left the park. Making "parked with the 
expected blocker" a precondition for running the task removes that window. I 
checked the expected blockers against the implementation and they all match: 
`NioSocketImpl.park`, `SelChImpl.park` (SocketChannel, ServerSocketChannel) and 
`DatagramChannelImpl.park` all pass `this` to `Poller.poll`, so 
`sc/sc1/sc2/ssc/dc2` are the right objects, and BlockingSocketOps can only 
check for non-null because the blocker there is the internal `NioSocketImpl` 
rather than the `Socket`.

One thing I'd like to see addressed is that `awaitParked` has no bound. If the 
expected park never happens then the test hangs until the jtreg timeout with no 
diagnostic, whereas before this change the same situation failed immediately. I 
hit this when running the tests against a JDK whose `Poller.poll` doesn't take 
a blocker (Temurin 27.0.1, i.e. before JDK-8396676). That's not a supported 
configuration, but it's a convenient way to exercise the path where the blocker 
never shows up, and with the version in master the tests fail in a few seconds 
with `expected: not <null>` (BlockingSocketOps) and `expected: 
<sun.nio.ch.DatagramChannelImpl@...> but was: <null>` (BlockingChannelOps), 
while with the updated tests BlockingSocketOps#default just hangs until the 
timeout. Related to this, `assertNotEquals(TERMINATED, ...)` in `isParked()` 
runs on the helper thread, so an AssertionError there doesn't fail the test, it 
just kills the helper while the test thread waits.

Smaller points:

- `@return the unparker thread` in both `runAfterParkedAsync` javadocs is 
stale, there's no unparker any more.
- `@param parkBlocker non-null if the the expected park blocker is known` has a 
duplicated "the".
- In BlockingSocketOps `awaitParked` the `parkBlocker` local is assigned but 
never read, so `LockSupport.getBlocker(target) == null` would do.
- The two `awaitParked` methods have drifted apart (one is a negated `while`, 
the other is `while (true)` plus `if`; one declares `throws 
InterruptedException`, the other `throws Exception`). The two files are 
otherwise near copies, so keeping these identical would make them easier to 
compare.
- Comments in BlockingChannelOps: "currnet" at line 320 (that line is touched 
by this change anyway), "connect when current thread when it blocks" at 362, 
and "interrupt current thread when it blocks in ssc.accept" at 428, where the 
task is actually a connect.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/33907#issuecomment-6889496573

Reply via email to