Thread.getState() very slow

Bob Lee crazybob at crazybob.org
Sat Aug 14 16:03:59 UTC 2010


Doug,

I ran into similar problems not too long ago. Dalvik uses a volatile field
for the thread state.

I wrote a sampling profiler for Dalvik. See
SamplingProfiler.c<http://android.git.kernel.org/?p=platform/libcore.git;a=blob;f=dalvik/src/main/java/dalvik/system/SamplingProfiler.java;h=1d88dd17001886c274db909477d077c6247af128;hb=HEAD>and
dalvik_system_SamplingProfiler.c<http://android.git.kernel.org/?p=platform/dalvik.git;a=blob;f=vm/native/dalvik_system_SamplingProfiler.c;h=5642bde15fe29d3b036d0460cecfe0414baa802a;hb=HEAD>
.

It records the thread state with each sample. The Java thread state wasn't
particularly helpful, so when a thread is in native code, it reads the
thread state from the system. See
SystemThread.c<http://android.git.kernel.org/?p=platform/dalvik.git;a=blob;f=vm/native/SystemThread.c;h=bd2be03e71331e1d0b5d799b04dc7a50fb5fa4b3;hb=HEAD>.
It reads /proc/self/task/[TID]/stat.

Linux really should provide a more efficient API for this.

Bob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/core-libs-dev/attachments/20100814/c211f957/attachment.html>


More information about the core-libs-dev mailing list