Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8324241

Always record evol_method deps to avoid excessive method flushing

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Fixed
    • P4
    • 23
    • 17, 21
    • hotspot
    • b08

    Description

      Currently we don't record dependencies on redefined methods (i.e. `evol_method` dependencies) in JIT compiled methods if none of the `can_redefine_classes`, `can_retransform_classes` or `can_generate_breakpoint_events` JVMTI capabalities is set. This means that if a JVMTI agent which requests one of these capabilities is dynamically attached, all the methods which have been JIT compiled until that point, will be marked for deoptimization and flushed from the code cache. For large, warmed-up applications this mean deoptimization and instant recompilation of thousends if not then-thousands of methods, which can lead to dramatic performance/latency dropw-downs for several minutes.

      One could argue that dynamic agent attach is now deprecated anyway (see JEP 451: Prepare to Disallow the Dynamic Loading of Agents [1]) and this problem could be solved by making the recording of `evol_method` dependencies dependent on the new `-XX:+EnableDynamicAgentLoading` flag isntead of the concrete JVMTI capabilities (because the presence of the flag indicates that an agent will be loaded eventually).

      But there is a single, however important exception to this rule and that's JFR. JFR is advertised as low overhead profiler which can be enabled in production at any time. However, when JFR is started dynamically (e.g. through JCMD or JMX) it will silently load a HotSpot internl JVMTI agent which requests the `can_retransform_classes` and retransforms some classes. This will inevitably trigger the deoptimization of all compiled methods as described above.

      I'd therfor like to propose to *always* and unconditionally record `evol_method` dependencies in JIT compiled code by exporting the relevant properties right at startup in `init_globals()`:
      ```
       jint init_globals() {
         management_init();
         JvmtiExport::initialize_oop_storage();
      +#if INCLUDE_JVMTI
      + JvmtiExport::set_can_hotswap_or_post_breakpoint(true);
      + JvmtiExport::set_all_dependencies_are_recorded(true);
      +#endif
      ```

      My measurements indicate that the overhead of doing so is minimal (around 1% increase of nmethod size) and justifies the benefit. E.g. a Spring Petclinic application started with `-Xbatch -XX:+UnlockDiagnosticVMOptions -XX:+LogCompilation` compiles about ~11500 methods (~9000 with C1 and ~2500 with C2) resulting in an aggregated nmethod size of around ~40bm. Additionally recording `evol_method` dependencies only increases this size be about 400kb. The ratio remains about the same if we run the same experiment with only C1 or only C2.

      Instead of unconditionally recording `evol_method` dependencies we could guard the recording by a new flag. But this would only make sense if that flag would be on by default and I don't know if such a flag is justified just for the rare (or non-existent?) cases where somebody wants to disable the recording of the dependencies.

      Another alternative would be to remove the `set_can_hotswap_or_post_breakpoint()`/`set_all_dependencies_are_recorded()` from `JvmtiExport` altogether (and always record the dependencies). It is currently only used at a few call sites in the C1/C2 compiler (`set_can_hotswap_or_post_breakpoint()`) and once when redefining classes (`set_all_dependencies_are_recorded()`).

      [1] https://openjdk.org/jeps/451

      Attachments

        Issue Links

          Activity

            People

              simonis Volker Simonis
              simonis Volker Simonis
              Votes:
              1 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: