JDWP thread suspending user java threads

E

Ethan

Hi,

I came to know that JDWP thread is used for debugging and that it is
used by the debugger to suspend other user java threads. In a previous
post, it seems like most modern JVMs leave thread management to their
native OS, hence it wouldn't be possible for JDWP to directly suspend
other user java threads and it could at the best hope to have them
finish their work and move out of ready queue.

If this is the case, how would it work with a java thread that is in
an infinite loop, good enough to ensure that it doesn't finish at all?
If not please share any links as to how it works. TIA.
 
A

Arne Vajhøj

I came to know that JDWP thread is used for debugging and that it is
used by the debugger to suspend other user java threads. In a previous
post, it seems like most modern JVMs leave thread management to their
native OS, hence it wouldn't be possible for JDWP to directly suspend
other user java threads and it could at the best hope to have them
finish their work and move out of ready queue.

If this is the case, how would it work with a java thread that is in
an infinite loop, good enough to ensure that it doesn't finish at all?
If not please share any links as to how it works.

If the native thread API allows for suspension then the JVM
can use that.

Otherwise I guess that it would need to get something
put in the code running in the thread.

Arne
 
M

Mike Schilling

Arne Vajhøj said:
If the native thread API allows for suspension then the JVM
can use that.

Otherwise I guess that it would need to get something
put in the code running in the thread.

The JVM is (mostly) an interpreter; that gives it control over all the
threads.
 
A

Arne Vajhøj

The JVM is (mostly) an interpreter; that gives it control over all the
threads.

I would have expected it to be JIT compiled.

But I think you are correct - when executing under the debugger
it will probably interpret.

Arne
 
K

Kevin McMurtrie

Ethan said:
Hi,

I came to know that JDWP thread is used for debugging and that it is
used by the debugger to suspend other user java threads. In a previous
post, it seems like most modern JVMs leave thread management to their
native OS, hence it wouldn't be possible for JDWP to directly suspend
other user java threads and it could at the best hope to have them
finish their work and move out of ready queue.

If this is the case, how would it work with a java thread that is in
an infinite loop, good enough to ensure that it doesn't finish at all?
If not please share any links as to how it works. TIA.

HotSpot sprinkles "safepoint polling" throughout the native code so it
can have features like interpreted code. Seeing the safepoint set
executes some code to tidy up the stack frame, acknowledge the
safepoint, and suspend the thread. It's how GC operates safely and it's
how you can get a stack trace from a running thread.

It's up to the HotSpot optimizer to calculate where these checks need to
be. There have been a few JVM builds where those calculations have been
wrong.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top