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

Java Agent will pick wrong execution path while attaching.

XMLWordPrintable

    • b26
    • generic
    • generic
    • Verified

      Source:
      http://oldsunweb.ireland/~ab23780/mustang/282/j2se/webrev/src/share/classes/sun/instrument/InstrumentationImpl.java.html
      <your code>
      166 try {
      167 m = javaAgentClass.getMethod( methodname,
      168 new Class[] {
      169 String.class,
      170 java.lang.instrument.Instrumentation.class
      171 }
      172 );
      173 twoArgAgent = true;
      174 } catch (NoSuchMethodException x) {
      175 // remember the NoSuchMethodException
      176 firstExc = x;
      177 }
      178
      179 // check for the 1-arg method
      180 if (m == null) {
      181 try {
      182 m = javaAgentClass.getMethod(methodname, new Class[] { String.class });
      183 } catch (NoSuchMethodException x) {
      184 // Neither method exists so we throw the first NoSuchMethodException
      185 // as per 5.0
      186 throw firstExc;
      187 }
      188 }
      189
      190 // invoke the 1 or 2-arg method
      191 if (twoArgAgent) {
      192 m.invoke(null, new Object[] { optionsString, this });
      193 } else {
      194 m.invoke(null, new Object[] { optionsString });
      195 }
      <your code>
      ###@###.### 2005-06-22 02:12:48 GMT

      <moved problem description here from comment note #1>

      This code can cause a small issue.
      if my agentclass has a super class or interfaces that has a two parameter method, then we will pick up a wrong path.
      Some thing like this.
      public class X {
         public static void premain/agentmain() // two parameter method.
      }
      public class Y extends X {
         public static void premain/agentMain() // single parameter method.
      }
      if my manifest has
          Agent-Class: Y
      then
      Y.class.getMethod("premain",new Class[] {String.class, String.class}) --> X.premain(String, String);
      Y.class.getDeclaredMethod("premain",new Class[] {String.class, String.class}) --> null;

      We will start agent running from X, instead of Y, because we will get two parameter method from X first.
      ###@###.### 2005-06-22 02:12:48 GMT
      The code is a little bit different in Dolphin-B24, but
      the bug is still there.
      The following two new tests will fail without this fix in
      a promoted JDK:

          java/lang/instrument/PremainClass/InheritAgent1001.java
          java/lang/instrument/PremainClass/InheritAgent1101.java

            dcubed Daniel Daugherty
            vvegurusunw Viswadeep Veguru (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: