1. 程式人生 > >GC日誌中的stop-the-world

GC日誌中的stop-the-world


       通常使用下面的JVM選項在GC日誌中列印”stop-the-world”(STW)暫停時間。

-XX:+PrintGCApplicationStoppedTime
       但是在GC日誌中看,會發現有許多這樣的暫停時間,時間很短,肯定不是垃圾回收引起的。
Total time for which application threads were stopped: 0.0013102 seconds, Stopping threads took: 0.0001792 seconds
Total time for which application threads were stopped: 0.0012521 seconds, Stopping threads took: 0.0001591 seconds
Total time for which application threads were stopped: 0.0008090 seconds, Stopping threads took: 0.0001030 seconds
Total time for which application threads were stopped: 0.0010226 seconds, Stopping threads took: 0.0001058 seconds
       實際上,觸發STW暫停的原因除了垃圾回收外,還有一些其他的操作會觸發STW,例如一些JIT活動、偏向鎖擦除、特定的JVMTI操作,以及許多場景也可能會導致應用程式暫停。
       上述例子中application threads stopped的時間表示應用暫停時間,Stopping threads took 的時間表示等待所有的應用執行緒都到達安全點花費的時間。只有應用程式執行緒到達安全點後,JVM才會做些特殊處理,比如垃圾收集、偏向鎖擦除等等。