Search code examples
jvm

What's the _all_dependencies_are_recorded flag used for in JVM


it was comment as follow,but I can't find any usage of this flag

  // Flag to indicate if the compiler has recorded all dependencies. When the
  // can_redefine_classes capability is enabled in the OnLoad phase then the compiler
  // records all dependencies from startup. However if the capability is first
  // enabled some time later then the dependencies recorded by the compiler
  // are incomplete. This flag is used by RedefineClasses to know if the
  // dependency information is complete or not.
  static bool _all_dependencies_are_recorded;

searched the jvm codebase, but found nothing


Solution

  • As written in the cited comment, the flag is used to determine if RedefineClasses needs to deoptimize only compiled methods that depend on the class being redefined (if _all_dependencies_are_recorded == true) or to deoptimize all compiled methods otherwise (if not all nmethod dependencies are recorded).

    The flag is checked in VM_RedefineClasses::flush_dependent_code:

      // This is the first redefinition, mark all the nmethods for deoptimization
      if (!JvmtiExport::all_dependencies_are_recorded()) {
        CodeCache::mark_all_nmethods_for_evol_deoptimization(&deopt_scope);
        log_debug(redefine, class, nmethod)("Marked all nmethods for deopt");
      } else {
        CodeCache::mark_dependents_for_evol_deoptimization(&deopt_scope);
        log_debug(redefine, class, nmethod)("Marked dependent nmethods for deopt");
      }
    

    Find more details on the underlying problem in JDK-8324241.

    A recent fix for this issue adds the JVM flag -XX:+AlwaysRecordEvolDependencies (on by default) which forces the JVM to record all nmethod dependencies unconditionally from the very beginning. Once this new behavior is always enabled, there will be no need for the _all_dependencies_are_recorded flag.