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

Log what methods are touched at run-time



    • Subcomponent:
    • Resolved In Build:



        Add new diagnostic flags to list all methods that have been touched at run time. Based on this information, we can rearrange the methods in the CDS archive so that infrequently touched methods are never loaded into memory.

        [1] Add new options "-XX:+LogTouchedMethods -XX:+PrintTouchedMethodsAtExit"
        [2] Add new "jcmd VM.print_touched_methods"

        There are already other mechanisms for getting method invocation count (such as a profiler). This RFE is not intended to be a duplicated feature. Rather, we want to have a very low overhead mechanism to provide the kind of "touched" information needed by CDS. The implementation in this RFE has much lower overhead than a profiler, since it doesn't change compiled code at all.

        What does "touched" mean in the context of this RFE?

           In this RFE, "Method" refers to the HotSpot Method data structure. The enhancement is for improving CDS memory usage.

           A Method is considered to be "touched" whenever a Method* pointer is dereferenced. If
           this Method is stored inside the CDS archive, the first time it is used would
           cause the page containing the Method will be mapped to memory.

           If we can identify all the Methods that are touched and group them
           together, it will increase the locality of the CDS pages, and allow
           more CDS pages to be never mapped.

           For CDS's optimization purposes, the count of methods touched is not so important.
           Once a method is touched it's page will be loaded into memory.

        Does "touched" mean invocation?

           For CDS, "touch a method" does not necessarily mean "invocation" of
           a method. Rather, it's any attempt to read the contents of a Method
           or ConstMethod C++ object.

           For example, when the compiler "looks at" a method M (in ciMethod::ciMethod(methodHandle h_m, ciInstanceKlass* holder))
           during compilation, the compiler may inline the body of M into its caller. In some cases,
           the inlined method M may never be invoked. However, for the purpose of CDS,
           the memory page containing M has been referenced and thus would have been
           mapped from disk during compilation time.

        You put the hook in ciMethod.cpp -- does this catch interpreter calls to a method?

           When a method is interpreted, the JVM would update its invocation counter by calling Method::build_method_counters().
           We record the "touch" of a method inside this function.


            Issue Links



                minqi Yumin Qi (Inactive)
                iklam Ioi Lam
                0 Vote for this issue
                4 Start watching this issue