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

Enhance java.lang.instrument API to inform whether a class can be retransformed

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: 19
    • Component/s: core-svc
    • Labels:
      None

      Description

      retransformClasses() throws java.lang.InternalError while re-transforming a class if it could not re-transform it for some reason. For instance, if it couldn't link the class while retransforming:
      ---------
      java.lang.InternalError
      at sun.instrument.InstrumentationImpl.retransformClasses0(Native Method)
      at sun.instrument.InstrumentationImpl.retransformClasses(InstrumentationImpl.java:144) at Main.main(Main.java:36)
      --------------

      It would be useful to have an API to check if a class can be retransformed successfully before actually making a call to do it. A few suggestions from a user of these APIs:

        * java.lang.instrument.Instrumentation.isModifiableClass(badClass) returns
      false
        * java.lang.Class.isNotLoaded() returns true (for badClass)
        * java.lang.Class.isNotVerified() returns true (for badClass)
        * <or-anything-else>

      These new and enhanced APIs can be used when deciding on which classes to retransform. Example:

      % cat -n moreRealTest/agent-src/Agent.java
      ...
         20 for (Class c : inst.getAllLoadedClasses()) {
          21 if (c == null ||
          22 !inst.isModifiableClass(c) ||
          23 skip(c.getName()))
          24 continue;
          25 classList.add(c);

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            poonam Poonam Bajaj Parhar
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: