Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 572000

Summary: [18] Project Loom (virtual threads) support
Product: [Eclipse Project] JDT Reporter: Andrey Loskutov <loskutov>
Component: DebugAssignee: JDT-Debug-Inbox <jdt-debug-inbox>
Status: CLOSED MOVED QA Contact:
Severity: enhancement    
Priority: P3 CC: jinbwan, sarika.sinha
Version: 4.20   
Target Milestone: ---   
Hardware: All   
OS: All   
See Also: https://github.com/eclipse-jdt/eclipse.jdt.debug/issues/38
Whiteboard:
Attachments:
Description Flags
Example snippet to play with
none
VirtualThread in VariablesView
none
Debug view with Virtual thread none

Description Andrey Loskutov CLA 2021-03-16 13:05:30 EDT
Created attachment 285857 [details]
Example snippet to play with

Project Loom with virtual threads is coming, and we have to be prepared.

Some pointers:
* http://jdk.java.net/loom/
* Linux JVM build: https://download.java.net/java/early_access/loom/4/openjdk-17-loom+4-174_linux-x64_bin.tar.gz
* https://wiki.openjdk.java.net/display/loom/Getting+started
* https://wiki.openjdk.java.net/display/loom/Notes+for+debugger+maintainers

Attached is the simple example from the "getting started" above.
Some immediate observations:

- Breakpoints inside the code executed on virtual threads aren't working.
- I do not see virtual threads appearing at all in the Debug view
Comment 1 Sarika Sinha CLA 2021-03-23 04:37:42 EDT
Created attachment 285922 [details]
VirtualThread in VariablesView

I get to see the Virtual thread in Variables view and inspect.
Comment 2 Sarika Sinha CLA 2021-03-23 04:39:39 EDT
Created attachment 285923 [details]
Debug view with Virtual thread

Debug view with Virtual thread
Comment 3 Sarika Sinha CLA 2021-03-23 04:40:12 EDT
@Andrey,
Did you observe the same ?
Comment 4 Andrey Loskutov CLA 2021-03-23 05:02:54 EDT
(In reply to Sarika Sinha from comment #3)
> @Andrey,
> Did you observe the same ?

Now, with the new build, yes: https://download.java.net/java/early_access/loom/5/openjdk-17-loom+5-191_linux-x64_bin.tar.gz

So breakpoints on virtual threads seem to work now.
Comment 5 Andrey Loskutov CLA 2021-03-23 05:23:30 EDT
(In reply to Andrey Loskutov from comment #4)
> So breakpoints on virtual threads seem to work now.

Also not in all places, and other things don't work too.

Step over/step return don't work, and "drop to frame" shows an InvalidStackFrameException.

At stopped breakpoint, just try to use step over/step return - nothing happens. Now suspend and see the code hangs in VirtualThread$VThreadContinuation(Continuation).yield0(ContinuationScope, Continuation) line: 438.

public void run() {
	try {
		Thread.sleep(Duration.ofSeconds(10)); // put a breakpoint here
		String x = "Hello";
		System.out.println(x);
		queue.put("done: " + number); // put another breakpoint here
	} catch (InterruptedException e) { }
}

In the snippet, create "another" breakpoint like shown above. Debugger can't show the system stopped at the second breakpoint at all (but the JVM suspended).

OK, found out that breakpoints after sleep() don't work:

public void run() {
	try {
		String x = "Hello"; // put a breakpoint here
		System.out.println(x);
		Thread.sleep(Duration.ofSeconds(10));
		System.out.println(x + x); // put another breakpoint here
		queue.put("done: " + number);
	} catch (InterruptedException e) { }
}

One can debug as expected from the first breakpoint, but after JVM reached Thread.sleep() call, no further debugging with the current thread possible.
Comment 6 Sarika Sinha CLA 2021-03-23 07:44:53 EDT
(In reply to Andrey Loskutov from comment #5)
> (In reply to Andrey Loskutov from comment #4)
> > So breakpoints on virtual threads seem to work now.
> 
> Also not in all places, and other things don't work too.
> 
> Step over/step return don't work, and "drop to frame" shows an
> InvalidStackFrameException.
> 
> At stopped breakpoint, just try to use step over/step return - nothing
> happens. Now suspend and see the code hangs in
> VirtualThread$VThreadContinuation(Continuation).yield0(ContinuationScope,
> Continuation) line: 438.
> 
> public void run() {
> 	try {
> 		Thread.sleep(Duration.ofSeconds(10)); // put a breakpoint here
> 		String x = "Hello";
> 		System.out.println(x);
> 		queue.put("done: " + number); // put another breakpoint here
> 	} catch (InterruptedException e) { }
> }
> 
> In the snippet, create "another" breakpoint like shown above. Debugger can't
> show the system stopped at the second breakpoint at all (but the JVM
> suspended).
> 
> OK, found out that breakpoints after sleep() don't work:
> 
> public void run() {
> 	try {
> 		String x = "Hello"; // put a breakpoint here
> 		System.out.println(x);
> 		Thread.sleep(Duration.ofSeconds(10));
> 		System.out.println(x + x); // put another breakpoint here
> 		queue.put("done: " + number);
> 	} catch (InterruptedException e) { }
> }
> 
> One can debug as expected from the first breakpoint, but after JVM reached
> Thread.sleep() call, no further debugging with the current thread possible.

Same observation.
If we step into thread sleep it works ok. Basically If we reach java.lang.VirtualThread.sleepNanos(long) and then resume it works fine.
Comment 7 Sarika Sinha CLA 2021-03-24 10:04:53 EDT
Another observation:
 int maxThreads = 16;

Our debugger is responsive for breakpoints and sleep till the count of 16. If we increase the count to 17 or more, it cannot comeback from Stepping or any such operation.
Comment 8 Andrey Loskutov CLA 2022-05-02 07:46:09 EDT
Created github issue for future work: https://github.com/eclipse-jdt/eclipse.jdt.debug/issues/38