Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loom Support #7367

Merged
merged 19 commits into from Jan 3, 2023
Merged

Loom Support #7367

merged 19 commits into from Jan 3, 2023

Conversation

yschimke
Copy link
Collaborator

@yschimke yschimke commented Jul 4, 2022

Change the synchronized/wait/notify calls to Lock/Condition.

Also change OkHttpClientTestRule to configure Loom in the default test client.

@yschimke yschimke requested a review from swankjesse July 4, 2022 06:05
@yschimke
Copy link
Collaborator Author

yschimke commented Jul 4, 2022

Some thread states during a test

 TIMED_WAITING
java.base/java.lang.Object.wait0(Native Method)
java.base/java.lang.Object.wait(Object.java:366)
java.base/java.lang.Object.wait(Object.java:488)
okhttp3.loom.LoomBackend.coordinatorWait(LoomBackend.kt:47)
okhttp3.internal.concurrent.TaskRunner.awaitTaskToRun(TaskRunner.kt:219)
okhttp3.internal.concurrent.TaskRunner$runnable$1.run(TaskRunner.kt:60)
java.base/java.util.concurrent.ThreadPerTaskExecutor$TaskRunner.run(ThreadPerTaskExecutor.java:314)
java.base/java.lang.VirtualThread.run(VirtualThread.java:287)
java.base/java.lang.VirtualThread$VThreadContinuation.lambda$new$0(VirtualThread.java:174)

Think we need to avoid object.wait in loom backend.

@yschimke
Copy link
Collaborator Author

yschimke commented Jul 4, 2022

Looks good.

OkHttp www.google.com WAITING
java.base/jdk.internal.vm.Continuation.yield(Continuation.java:357)
java.base/java.lang.VirtualThread.yieldContinuation(VirtualThread.java:370)
java.base/java.lang.VirtualThread.park(VirtualThread.java:499)
java.base/java.lang.System$2.parkVirtualThread(System.java:2596)
java.base/jdk.internal.misc.VirtualThreads.park(VirtualThreads.java:54)
java.base/java.util.concurrent.locks.LockSupport.park(LockSupport.java:369)
java.base/sun.nio.ch.Poller.poll2(Poller.java:139)
java.base/sun.nio.ch.Poller.poll(Poller.java:102)
java.base/sun.nio.ch.Poller.poll(Poller.java:87)
java.base/sun.nio.ch.NioSocketImpl.park(NioSocketImpl.java:175)

@yschimke
Copy link
Collaborator Author

@swankjesse Seems ok replacing wait/notify. What are next steps?

Respond to loom email?

Split out the Condition changes? Or roll them out more widely?

@yschimke yschimke added the providers Non core security providers label Jul 10, 2022
@yschimke yschimke mentioned this pull request Aug 8, 2022
8 tasks
@yschimke
Copy link
Collaborator Author

Closing for now, blocked on okio for complete support.

@yschimke yschimke closed this Aug 15, 2022
This was referenced Dec 25, 2022
# Conflicts:
#	gradle/wrapper/gradle-wrapper.properties
#	settings.gradle.kts
@yschimke yschimke reopened this Jan 2, 2023
@yschimke yschimke changed the title Experiment with Loom Loom Support Jan 2, 2023
@yschimke yschimke marked this pull request as ready for review January 2, 2023 11:02
@yschimke yschimke added loom Relates to Loom JDK support and removed providers Non core security providers labels Jan 2, 2023
@yschimke yschimke marked this pull request as draft January 2, 2023 11:34
@yschimke
Copy link
Collaborator Author

yschimke commented Jan 2, 2023

Failing on

Thread Test worker MUST hold lock on okhttp3.internal.concurrent.TaskRunner@6ca320ab
java.lang.AssertionError: Thread Test worker MUST hold lock on okhttp3.internal.concurrent.TaskRunner@6ca320ab
	at okhttp3.internal.concurrent.TaskFaker$taskRunner$1.execute(TaskFaker.kt:341)
	at okhttp3.internal.concurrent.TaskRunner.kickCoordinator$okhttp(TaskRunner.kt:101)
	at okhttp3.internal.concurrent.TaskQueue.schedule(TaskQueue.kt:77)
	at okhttp3.internal.concurrent.TaskQueue.execute(TaskQueue.kt:104)
	at okhttp3.internal.concurrent.TaskQueue.execute$default(TaskQueue.kt:98)
	at okhttp3.internal.http2.Http2Connection.start(Http2Connection.kt:506)

@yschimke yschimke marked this pull request as ready for review January 2, 2023 11:57
@yschimke yschimke removed the loom Relates to Loom JDK support label Jan 2, 2023
@yschimke yschimke added the loom Relates to Loom JDK support label Jan 2, 2023
@@ -68,7 +74,7 @@ class TaskRunner(
} finally {
// If the task is crashing start another thread to service the queues.
if (!completedNormally) {
synchronized(this@TaskRunner) {
lock.withLock {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Being able to avoid the hazard of dereferencing the wrong this is a very nice improvement

okhttp/api/okhttp.api Outdated Show resolved Hide resolved
@yschimke yschimke merged commit 33ace75 into square:master Jan 3, 2023
))

constructor(
connectionListener: ConnectionListener = ConnectionListener.NONE,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: surprising that the new parameter is first?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can reorder. It seemed right to me. But should we go full Builder mode on it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow up #7631

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No Builder.

@yschimke yschimke deleted the loom2 branch May 27, 2023 11:26
@kkotamar
Copy link

kkotamar commented Oct 1, 2023

Is there a release date for this support in okhttpclient?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
loom Relates to Loom JDK support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants