Java core cpu dump or just waiting?

I copied a suspicious thread dump. I see 173 threads in IN_NATIVE state on call java.net.SocketInputStream.socketRead0()

and 30 threads in BLOCKED state on the same call.
I think the BLOCKED state does not consume cpu, but they are expecting IO.

How about threads in IN_NATIVE state? do they consume the processor? Any idea why I see different thread states for the same socketRead0 () call?

173 threads
Thread 40283 - threadId:Thread 40283 - state:IN_NATIVE
stackTrace:
java.net.SocketInputStream.socketRead0(java.io.FileDescriptor, byte[], int, int, int) @bci=0 (Compiled frame; information may be imprecise)
java.net.SocketInputStream.read(byte[], int, int, int) @bci=87, line=152 (Compiled frame)
java.net.SocketInputStream.read(byte[], int, int) @bci=11, line=122 (Compiled frame)
com.sun.mail.util.TraceInputStream.read(byte[], int, int) @bci=7, line=110 (Compiled frame)
java.io.BufferedInputStream.fill() @bci=175, line=235 (Compiled frame)
java.io.BufferedInputStream.read() @bci=12, line=254 (Compiled frame)
com.sun.mail.util.LineInputStream.readLine() @bci=33, line=88 (Compiled frame)
com.sun.mail.smtp.SMTPTransport.readServerResponse() @bci=43, line=1589 (Compiled frame)
com.sun.mail.smtp.SMTPTransport.openServer(java.lang.String, int) @bci=117, line=1369 (Compiled frame)
com.sun.mail.smtp.SMTPTransport.protocolConnect(java.lang.String, int, java.lang.String, java.lang.String) @bci=270, line=412 (Compiled frame)
javax.mail.Service.connect(java.lang.String, int, java.lang.String, java.lang.String) @bci=380, line=288 (Compiled frame)
com.healthies.push.injectors.mailsenders.DefaultMailSender.sendMessage(com.healthies.push.messages.EmailMessage, javax.mail.internet.MimeMessage) @bci=28, line=63 (Compiled frame)
com.healthies.push.injectors.SMTPMessageInjector.sendMessage(com.healthies.push.injectors.mailsenders.MailSender, com.healthies.push.messages.EmailMessage, javax.mail.internet.MimeMessage) @bci=55, line=140 (Compiled frame)
com.healthies.push.injectors.SMTPMessageInjector.inject(com.healthies.push.messages.EmailMessage) @bci=210, line=117 (Compiled frame)
com.healthies.push.injectors.SMTPMessageInjector.inject(com.healthies.push.messages.Message) @bci=5, line=35 (Compiled frame)
com.healthies.push.injectors.EmailInjectorPool$1.run() @bci=85, line=40 (Compiled frame)
java.util.concurrent.Executors$RunnableAdapter.call() @bci=4, line=471 (Compiled frame)
java.util.concurrent.FutureTask.run() @bci=42, line=262 (Compiled frame)
java.util.concurrent.ThreadPoolExecutor.runWorker(java.util.concurrent.ThreadPoolExecutor$Worker) @bci=95, line=1145 (Compiled frame)
java.util.concurrent.ThreadPoolExecutor$Worker.run() @bci=5, line=615 (Interpreted frame)
java.lang.Thread.run() @bci=11, line=745 (Interpreted frame)
--------------------------------------------------------------------
30 threads 
Thread 40276 - threadId:Thread 40276 - state:BLOCKED
stackTrace:
java.net.SocketInputStream.socketRead0(java.io.FileDescriptor, byte[], int, int, int) @bci=0 (Compiled frame; information may be imprecise)
java.net.SocketInputStream.read(byte[], int, int, int) @bci=87, line=152 (Compiled frame)
java.net.SocketInputStream.read(byte[], int, int) @bci=11, line=122 (Compiled frame)
com.sun.mail.util.TraceInputStream.read(byte[], int, int) @bci=7, line=110 (Compiled frame)
java.io.BufferedInputStream.fill() @bci=175, line=235 (Compiled frame)
java.io.BufferedInputStream.read() @bci=12, line=254 (Compiled frame)
com.sun.mail.util.LineInputStream.readLine() @bci=33, line=88 (Compiled frame)
com.sun.mail.smtp.SMTPTransport.readServerResponse() @bci=43, line=1589 (Compiled frame)
com.sun.mail.smtp.SMTPTransport.issueSendCommand(java.lang.String, int) @bci=6, line=1494 (Compiled frame)
com.sun.mail.smtp.SMTPTransport.finishData() @bci=34, line=1321 (Compiled frame)
com.sun.mail.smtp.SMTPTransport.sendMessage(javax.mail.Message, javax.mail.Address[]) @bci=281, line=637 (Compiled frame)
com.healthies.push.injectors.mailsenders.DefaultMailSender.sendMessage(com.healthies.push.messages.EmailMessage, javax.mail.internet.MimeMessage) @bci=37, line=64 (Compiled frame)
com.healthies.push.injectors.SMTPMessageInjector.sendMessage(com.healthies.push.injectors.mailsenders.MailSender, com.healthies.push.messages.EmailMessage, javax.mail.internet.MimeMessage) @bci=55, line=140 (Compiled frame)
com.healthies.push.injectors.SMTPMessageInjector.inject(com.healthies.push.messages.EmailMessage) @bci=210, line=117 (Compiled frame)
com.healthies.push.injectors.SMTPMessageInjector.inject(com.healthies.push.messages.Message) @bci=5, line=35 (Compiled frame)
com.healthies.push.injectors.EmailInjectorPool$1.run() @bci=85, line=40 (Compiled frame)
java.util.concurrent.Executors$RunnableAdapter.call() @bci=4, line=471 (Compiled frame)
java.util.concurrent.FutureTask.run() @bci=42, line=262 (Compiled frame)
java.util.concurrent.ThreadPoolExecutor.runWorker(java.util.concurrent.ThreadPoolExecutor$Worker) @bci=95, line=1145 (Compiled frame)
java.util.concurrent.ThreadPoolExecutor$Worker.run() @bci=5, line=615 (Interpreted frame)
java.lang.Thread.run() @bci=11, line=745 (Interpreted frame)

      

+3


source to share


1 answer


Typically you will never see a thread executing an unsynchronized native method in a state BLOCKED

. But this dump was obtained in force mode (jstack -F), which works differently .

It seems that the JVM requested a safepoint operation . All threads executing Java code must be stopped at safepoint, but built-in methods can still execute. Whenever a native method returns, it checks to see if the safepoint operation is in progress, and if so, blocks the current thread until the VM operation completes.

So in your case



  • threads in the state BLOCKED

    have already completed their own call and are waiting for the safepoint operation to complete when the method returns;
  • threads in the state IN_NATIVE

    are still doing their own call, which might block while reading the socket.

The JVM has no way of distinguishing between a native method that is blocked by a system call from a native method that is actually CPU-intensive. In both cases, it will show the flow in state IN_NATIVE

. You cannot infer from a thread dump whether these threads are busy or not.

To find out if a native method uses the CPU, you need a utility like top

, perf

or a profiler with internal code, / a>.

+1


source







All Articles