Consuming stack traces noticeably slower in Java 11 than Java 8

前端 未结 2 2002
攒了一身酷
攒了一身酷 2020-12-24 06:33

I was comparing the performance of JDK 8 and 11 using jmh 1.21 when I ran across some surprising numbers:

Java versi         


        
2条回答
  •  醉梦人生
    2020-12-24 07:17

    I suspect this is due to several changes.

    8->9 regression happened while switching to StackWalker for generating the stack traces (JDK-8150778). Unfortunately, this made VM native code intern a lot of strings, and StringTable becomes the bottleneck. If you profile OP's benchmark, you will see the profile like in JDK-8151751. It should be enough to perf record -g the entire JVM that runs the benchmark, and then look into perf report. (Hint, hint, you can do it yourself next time!)

    And 10->11 regression must have happened later. I suspect this is due to StringTable preparations for switching to fully concurrent hash table (JDK-8195100, which, as Claes points out, is not entirely in 11) or something else (class data sharing changes?).

    Either way, interning on fast path is a bad idea, and patch for JDK-8151751 should have dealt with both regressions.

    Watch this:

    8u191: 15108 ± 99 ns/op [so far so good]

    -   54.55%     0.37%  java     libjvm.so           [.] JVM_GetStackTraceElement 
       - 54.18% JVM_GetStackTraceElement                          
          - 52.22% java_lang_Throwable::get_stack_trace_element   
             - 48.23% java_lang_StackTraceElement::create         
                - 17.82% StringTable::intern                      
                - 13.92% StringTable::intern                      
                - 4.83% Klass::external_name                      
                + 3.41% Method::line_number_from_bci              
    

    "head": 22382 ± 134 ns/op [regression]

    -   69.79%     0.05%  org.sample.MyBe  libjvm.so  [.] JVM_InitStackTraceElement
       - 69.73% JVM_InitStackTraceElementArray                    
          - 69.14% java_lang_Throwable::get_stack_trace_elements  
             - 66.86% java_lang_StackTraceElement::fill_in        
                - 38.48% StringTable::intern                      
                - 21.81% StringTable::intern                      
                - 2.21% Klass::external_name                      
                  1.82% Method::line_number_from_bci              
                  0.97% AccessInternal::PostRuntimeDispatch

    "head" + JDK-8151751 patch: 7511 ± 26 ns/op [woot, even better than 8u]

    -   22.53%     0.12%  org.sample.MyBe  libjvm.so  [.] JVM_InitStackTraceElement
       - 22.40% JVM_InitStackTraceElementArray                    
          - 20.25% java_lang_Throwable::get_stack_trace_elements  
             - 12.69% java_lang_StackTraceElement::fill_in        
                + 6.86% Method::line_number_from_bci              
                  2.08% AccessInternal::PostRuntimeDispatch

提交回复
热议问题