JVM 的各種調校

看到「JVM Anatomy Park」這篇,作者是 Red HatOpenJDK 團隊的人,寫了二十則與 JVM 效能相關的主題,裡面提到每則大約花五到十分鐘可以看完,不過我覺得應該會再久一點 (需要翻資料交叉查)。

除了網頁版外,也提供 EPUB、MOBI 與 PDF 格式可以下載。

都是講效能相關的,從不同角度看。以第一個 Lock Coarsening and Loops 來說,已知這段程式碼:

synchronized (obj) {
  // statements 1
}
synchronized (obj) {
  // statements 2
}

會被轉換成這樣等效的程式碼:

synchronized (obj) {
  // statements 1
  // statements 2
}

作者就問了,那這樣的話,這段:

for (...) {
  synchronized (obj) {
    // something
  }
}

會不會轉成這段呢:

synchronized (this) {
  for (...) {
     // something
  }
}

答案是不會,但可以橋:

While lock coarsening does not work on the entire loop, another loop optimization — loop unrolling — sets up the stage for the regular lock coarsening, once the intermediate representation starts to look as if there are N adjacent lock-unlock sequences. This reaps the performance benefits, and helps to limit the scope of coarsening, to avoid over-coarsening over fat loops.

就大概是這樣的主題 XD 每天看個一兩篇慢慢消化還不錯...

Leave a Reply

Your email address will not be published. Required fields are marked *