6289149: 4/4 Java Agent will pick wrong execution path while attaching
Summary: Check for a declared premain() or agentmain() method before an inherited one
Reviewed-by: sspitsyn
--- a/jdk/src/share/classes/sun/instrument/InstrumentationImpl.java Mon Mar 24 15:14:31 2008 -0700
+++ b/jdk/src/share/classes/sun/instrument/InstrumentationImpl.java Mon Mar 24 15:20:29 2008 -0700
@@ -303,39 +303,78 @@
NoSuchMethodException firstExc = null;
boolean twoArgAgent = false;
- // The agent class has a premain or agentmain method that has 1 or 2
- // arguments. We first check for a signature of (String, Instrumentation),
- // and if not found we check for (String). If neither is found then we
- // throw the NoSuchMethodException from the first attempt so that the
- // exception text indicates the lookup failed for the 2-arg method
- // (same as JDK5.0).
+ // The agent class must have a premain or agentmain method that
+ // has 1 or 2 arguments. We check in the following order:
+ //
+ // 1) declared with a signature of (String, Instrumentation)
+ // 2) declared with a signature of (String)
+ // 3) inherited with a signature of (String, Instrumentation)
+ // 4) inherited with a signature of (String)
+ //
+ // So the declared version of either 1-arg or 2-arg always takes
+ // primary precedence over an inherited version. After that, the
+ // 2-arg version takes precedence over the 1-arg version.
+ //
+ // If no method is found then we throw the NoSuchMethodException
+ // from the first attempt so that the exception text indicates
+ // the lookup failed for the 2-arg method (same as JDK5.0).
try {
- m = javaAgentClass.getMethod( methodname,
- new Class[] {
- String.class,
- java.lang.instrument.Instrumentation.class
- }
- );
+ m = javaAgentClass.getDeclaredMethod( methodname,
+ new Class[] {
+ String.class,
+ java.lang.instrument.Instrumentation.class
+ }
+ );
twoArgAgent = true;
} catch (NoSuchMethodException x) {
// remember the NoSuchMethodException
firstExc = x;
}
- // check for the 1-arg method
if (m == null) {
+ // now try the declared 1-arg method
+ try {
+ m = javaAgentClass.getDeclaredMethod(methodname,
+ new Class[] { String.class });
+ } catch (NoSuchMethodException x) {
+ // ignore this exception because we'll try
+ // two arg inheritance next
+ }
+ }
+
+ if (m == null) {
+ // now try the inherited 2-arg method
try {
- m = javaAgentClass.getMethod(methodname, new Class[] { String.class });
+ m = javaAgentClass.getMethod( methodname,
+ new Class[] {
+ String.class,
+ java.lang.instrument.Instrumentation.class
+ }
+ );
+ twoArgAgent = true;
} catch (NoSuchMethodException x) {
- // Neither method exists so we throw the first NoSuchMethodException
- // as per 5.0
+ // ignore this exception because we'll try
+ // one arg inheritance next
+ }
+ }
+
+ if (m == null) {
+ // finally try the inherited 1-arg method
+ try {
+ m = javaAgentClass.getMethod(methodname,
+ new Class[] { String.class });
+ } catch (NoSuchMethodException x) {
+ // none of the methods exists so we throw the
+ // first NoSuchMethodException as per 5.0
throw firstExc;
}
}
// the premain method should not be required to be public,
// make it accessible so we can call it
+ // Note: The spec says the following:
+ // The agent class must implement a public static premain method...
setAccessible(m, true);
// invoke the 1 or 2-arg method
--- a/jdk/test/java/lang/instrument/PremainClass/DummyMain.java Mon Mar 24 15:14:31 2008 -0700
+++ b/jdk/test/java/lang/instrument/PremainClass/DummyMain.java Mon Mar 24 15:20:29 2008 -0700
@@ -22,11 +22,10 @@
*/
/*
- *
- *
- * Used by PremainClassTest.sh - dummy "main application" which doesn't do anything
+ * dummy "Hello World"ish application for "premain" tests
*/
public class DummyMain {
public static void main(String[] args) {
+ System.out.println("Hello from DummyMain!");
}
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/instrument/PremainClass/InheritAgent0001.java Mon Mar 24 15:20:29 2008 -0700
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 6289149
+ * @summary test config (0,0,0,1): declared 1-arg in agent class
+ * @author Daniel D. Daugherty, Sun Microsystems
+ *
+ * @run shell ../MakeJAR3.sh InheritAgent0001
+ * @run main/othervm -javaagent:InheritAgent0001.jar DummyMain
+ */
+
+import java.lang.instrument.*;
+
+class InheritAgent0001 extends InheritAgent0001Super {
+
+ //
+ // This agent has a single argument premain() method which
+ // is the one that should be called.
+ //
+ public static void premain (String agentArgs) {
+ System.out.println("Hello from Single-Arg InheritAgent0001!");
+ }
+
+ // This agent does NOT have a double argument premain() method.
+}
+
+class InheritAgent0001Super {
+
+ // This agent does NOT have a single argument premain() method.
+
+ // This agent does NOT have a double argument premain() method.
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/instrument/PremainClass/InheritAgent0010.java Mon Mar 24 15:20:29 2008 -0700
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 6289149
+ * @summary test config (0,0,1,0): declared 2-arg in agent class
+ * @author Daniel D. Daugherty, Sun Microsystems
+ *
+ * @run shell ../MakeJAR3.sh InheritAgent0010
+ * @run main/othervm -javaagent:InheritAgent0010.jar DummyMain
+ */
+
+import java.lang.instrument.*;
+
+class InheritAgent0010 extends InheritAgent0010Super {
+
+ // This agent does NOT have a single argument premain() method.
+
+ //
+ // This agent has a double argument premain() method which
+ // is the one that should be called.
+ //
+ public static void premain (String agentArgs, Instrumentation instArg) {
+ System.out.println("Hello from Double-Arg InheritAgent0010!");
+ }
+}
+
+class InheritAgent0010Super {
+
+ // This agent does NOT have a single argument premain() method.
+
+ // This agent does NOT have a double argument premain() method.
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/instrument/PremainClass/InheritAgent0011.java Mon Mar 24 15:20:29 2008 -0700
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 6289149
+ * @summary test config (0,0,1,1): declared 2-arg and declared 1-arg in agent class
+ * @author Daniel D. Daugherty, Sun Microsystems
+ *
+ * @run shell ../MakeJAR3.sh InheritAgent0011
+ * @run main/othervm -javaagent:InheritAgent0011.jar DummyMain
+ */
+
+import java.lang.instrument.*;
+
+class InheritAgent0011 extends InheritAgent0011Super {
+
+ //
+ // This agent has a single argument premain() method which
+ // is NOT the one that should be called.
+ //
+ public static void premain (String agentArgs) {
+ System.out.println("Hello from Single-Arg InheritAgent0011!");
+ throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
+ }
+
+ //
+ // This agent has a double argument premain() method which
+ // is the one that should be called.
+ //
+ public static void premain (String agentArgs, Instrumentation instArg) {
+ System.out.println("Hello from Double-Arg InheritAgent0011!");
+ }
+}
+
+class InheritAgent0011Super {
+
+ // This agent does NOT have a single argument premain() method.
+
+ // This agent does NOT have a double argument premain() method.
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/instrument/PremainClass/InheritAgent0100.java Mon Mar 24 15:20:29 2008 -0700
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 6289149
+ * @summary test config (0,1,0,0): inherited 1-arg in agent class
+ * @author Daniel D. Daugherty, Sun Microsystems
+ *
+ * @run shell ../MakeJAR3.sh InheritAgent0100
+ * @run main/othervm -javaagent:InheritAgent0100.jar DummyMain
+ */
+
+import java.lang.instrument.*;
+
+class InheritAgent0100 extends InheritAgent0100Super {
+
+ // This agent does NOT have a single argument premain() method.
+
+ // This agent does NOT have a double argument premain() method.
+}
+
+class InheritAgent0100Super {
+
+ //
+ // This agent has a single argument premain() method which
+ // is the one that should be called.
+ //
+ public static void premain (String agentArgs) {
+ System.out.println("Hello from Single-Arg InheritAgent0100Super!");
+ }
+
+ // This agent does NOT have a double argument premain() method.
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/instrument/PremainClass/InheritAgent0101.java Mon Mar 24 15:20:29 2008 -0700
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 6289149
+ * @summary test config (0,1,0,1): inherited 1-arg and declared 1-arg in agent class
+ * @author Daniel D. Daugherty, Sun Microsystems
+ *
+ * @run shell ../MakeJAR3.sh InheritAgent0101
+ * @run main/othervm -javaagent:InheritAgent0101.jar DummyMain
+ */
+
+import java.lang.instrument.*;
+
+class InheritAgent0101 extends InheritAgent0101Super {
+
+ //
+ // This agent has a single argument premain() method which
+ // is the one that should be called.
+ //
+ public static void premain (String agentArgs) {
+ System.out.println("Hello from Single-Arg InheritAgent0101!");
+ }
+
+ // This agent does NOT have a double argument premain() method.
+}
+
+class InheritAgent0101Super {
+
+ //
+ // This agent has a single argument premain() method which
+ // is NOT the one that should be called.
+ //
+ public static void premain (String agentArgs) {
+ System.out.println("Hello from Single-Arg InheritAgent0101Super!");
+ throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
+ }
+
+ // This agent does NOT have a double argument premain() method.
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/instrument/PremainClass/InheritAgent0110.java Mon Mar 24 15:20:29 2008 -0700
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 6289149
+ * @summary test config (0,1,1,0): inherited 1-arg and declared 2-arg in agent class
+ * @author Daniel D. Daugherty, Sun Microsystems
+ *
+ * @run shell ../MakeJAR3.sh InheritAgent0110
+ * @run main/othervm -javaagent:InheritAgent0110.jar DummyMain
+ */
+
+import java.lang.instrument.*;
+
+class InheritAgent0110 extends InheritAgent0110Super {
+
+ // This agent does NOT have a one argument premain() method.
+
+ //
+ // This agent has a double argument premain() method which
+ // is the one that should be called.
+ //
+ public static void premain (String agentArgs, Instrumentation instArg) {
+ System.out.println("Hello from Double-Arg InheritAgent0110!");
+ }
+}
+
+class InheritAgent0110Super {
+
+ //
+ // This agent has a single argument premain() method which
+ // is NOT the one that should be called.
+ //
+ public static void premain (String agentArgs) {
+ System.out.println("Hello from Single-Arg InheritAgent0110Super!");
+ throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
+ }
+
+ // This agent does NOT have a double argument premain() method.
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/instrument/PremainClass/InheritAgent0111.java Mon Mar 24 15:20:29 2008 -0700
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 6289149
+ * @summary test config (0,1,1,1): inherited 1-arg, declared 2-arg and declared 1-arg in agent class
+ * @author Daniel D. Daugherty, Sun Microsystems
+ *
+ * @run shell ../MakeJAR3.sh InheritAgent0111
+ * @run main/othervm -javaagent:InheritAgent0111.jar DummyMain
+ */
+
+import java.lang.instrument.*;
+
+class InheritAgent0111 extends InheritAgent0111Super {
+
+ //
+ // This agent has a single argument premain() method which
+ // is NOT the one that should be called.
+ //
+ public static void premain (String agentArgs) {
+ System.out.println("Hello from Single-Arg InheritAgent0111!");
+ throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
+ }
+
+ //
+ // This agent has a double argument premain() method which
+ // is the one that should be called.
+ //
+ public static void premain (String agentArgs, Instrumentation instArg) {
+ System.out.println("Hello from Double-Arg InheritAgent0111!");
+ }
+
+}
+
+class InheritAgent0111Super {
+
+ //
+ // This agent has a single argument premain() method which
+ // is NOT the one that should be called.
+ //
+ public static void premain (String agentArgs) {
+ System.out.println("Hello from Single-Arg InheritAgent0111Super!");
+ throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
+ }
+
+ // This agent does NOT have a double argument premain() method.
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/instrument/PremainClass/InheritAgent1000.java Mon Mar 24 15:20:29 2008 -0700
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 6289149
+ * @summary test config (1,0,0,0): inherited 2-arg in agent class
+ * @author Daniel D. Daugherty, Sun Microsystems
+ *
+ * @run shell ../MakeJAR3.sh InheritAgent1000
+ * @run main/othervm -javaagent:InheritAgent1000.jar DummyMain
+ */
+
+import java.lang.instrument.*;
+
+class InheritAgent1000 extends InheritAgent1000Super {
+
+ // This agent does NOT have a single argument premain() method.
+
+ // This agent does NOT have a double argument premain() method.
+}
+
+class InheritAgent1000Super {
+
+ // This agent does NOT have a single argument premain() method.
+
+ //
+ // This agent has a double argument premain() method which
+ // is the one that should be called.
+ //
+ public static void premain (String agentArgs, Instrumentation instArg) {
+ System.out.println("Hello from Double-Arg InheritAgent1000Super!");
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/instrument/PremainClass/InheritAgent1001.java Mon Mar 24 15:20:29 2008 -0700
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 6289149
+ * @summary test config (1,0,0,1): inherited 2-arg, and declared 1-arg in agent class
+ * @author Daniel D. Daugherty, Sun Microsystems
+ *
+ * @run shell ../MakeJAR3.sh InheritAgent1001
+ * @run main/othervm -javaagent:InheritAgent1001.jar DummyMain
+ */
+
+import java.lang.instrument.*;
+
+class InheritAgent1001 extends InheritAgent1001Super {
+
+ //
+ // This agent has a single argument premain() method which
+ // is the one that should be called.
+ //
+ public static void premain (String agentArgs) {
+ System.out.println("Hello from Single-Arg InheritAgent1001!");
+ }
+
+ // This agent does NOT have a double argument premain() method.
+}
+
+class InheritAgent1001Super {
+
+ // This agent does NOT have a single argument premain() method.
+
+ //
+ // This agent has a double argument premain() method which
+ // is NOT the one that should be called.
+ //
+ public static void premain (String agentArgs, Instrumentation instArg) {
+ System.out.println("Hello from Double-Arg InheritAgent1001Super!");
+ throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/instrument/PremainClass/InheritAgent1010.java Mon Mar 24 15:20:29 2008 -0700
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 6289149
+ * @summary test config (1,0,1,0): inherited 2-arg, and declared 2-arg in agent class
+ * @author Daniel D. Daugherty, Sun Microsystems
+ *
+ * @run shell ../MakeJAR3.sh InheritAgent1010
+ * @run main/othervm -javaagent:InheritAgent1010.jar DummyMain
+ */
+
+import java.lang.instrument.*;
+
+class InheritAgent1010 extends InheritAgent1010Super {
+
+ // This agent does NOT have a single argument premain() method.
+
+ //
+ // This agent has a double argument premain() method which
+ // is the one that should be called.
+ //
+ public static void premain (String agentArgs, Instrumentation instArg) {
+ System.out.println("Hello from Double-Arg InheritAgent1010!");
+ }
+}
+
+class InheritAgent1010Super {
+
+ // This agent does NOT have a single argument premain() method.
+
+ //
+ // This agent has a double argument premain() method which
+ // is NOT the one that should be called.
+ //
+ public static void premain (String agentArgs, Instrumentation instArg) {
+ System.out.println("Hello from Double-Arg InheritAgent1010Super!");
+ throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/instrument/PremainClass/InheritAgent1011.java Mon Mar 24 15:20:29 2008 -0700
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 6289149
+ * @summary test config (1,0,1,1): inherited 2-arg, declared 2-arg and declared 1-arg in agent class
+ * @author Daniel D. Daugherty, Sun Microsystems
+ *
+ * @run shell ../MakeJAR3.sh InheritAgent1011
+ * @run main/othervm -javaagent:InheritAgent1011.jar DummyMain
+ */
+
+import java.lang.instrument.*;
+
+class InheritAgent1011 extends InheritAgent1011Super {
+
+ //
+ // This agent has a single argument premain() method which
+ // is NOT the one that should be called.
+ //
+ public static void premain (String agentArgs) {
+ System.out.println("Hello from Single-Arg InheritAgent1011!");
+ throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
+ }
+
+ //
+ // This agent has a double argument premain() method which
+ // is the one that should be called.
+ //
+ public static void premain (String agentArgs, Instrumentation instArg) {
+ System.out.println("Hello from Double-Arg InheritAgent1011!");
+ }
+}
+
+class InheritAgent1011Super {
+
+ // This agent does NOT have a single argument premain() method.
+
+ //
+ // This agent has a double argument premain() method which
+ // is NOT the one that should be called.
+ //
+ public static void premain (String agentArgs, Instrumentation instArg) {
+ System.out.println("Hello from Double-Arg InheritAgent1011Super!");
+ throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/instrument/PremainClass/InheritAgent1100.java Mon Mar 24 15:20:29 2008 -0700
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 6289149
+ * @summary test config (1,1,0,0): inherited 2-arg and inherited 1-arg in agent class
+ * @author Daniel D. Daugherty, Sun Microsystems
+ *
+ * @run shell ../MakeJAR3.sh InheritAgent1100
+ * @run main/othervm -javaagent:InheritAgent1100.jar DummyMain
+ */
+
+import java.lang.instrument.*;
+
+class InheritAgent1100 extends InheritAgent1100Super {
+
+ // This agent does NOT have a single argument premain() method.
+
+ // This agent does NOT have a double argument premain() method.
+}
+
+class InheritAgent1100Super {
+
+ //
+ // This agent has a single argument premain() method which
+ // is NOT the one that should be called.
+ //
+ public static void premain (String agentArgs) {
+ System.out.println("Hello from Single-Arg InheritAgent1100Super!");
+ throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
+ }
+
+ //
+ // This agent has a double argument premain() method which
+ // is the one that should be called.
+ //
+ public static void premain (String agentArgs, Instrumentation instArg) {
+ System.out.println("Hello from Double-Arg InheritAgent1100Super!");
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/instrument/PremainClass/InheritAgent1101.java Mon Mar 24 15:20:29 2008 -0700
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 6289149
+ * @summary test config (1,1,0,1): inherited 2-arg, inherited 1-arg, and declared 1-arg in agent class
+ * @author Daniel D. Daugherty, Sun Microsystems
+ *
+ * @run shell ../MakeJAR3.sh InheritAgent1101
+ * @run main/othervm -javaagent:InheritAgent1101.jar DummyMain
+ */
+
+import java.lang.instrument.*;
+
+class InheritAgent1101 extends InheritAgent1101Super {
+
+ //
+ // This agent has a single argument premain() method which
+ // is the one that should be called.
+ //
+ public static void premain (String agentArgs) {
+ System.out.println("Hello from Single-Arg InheritAgent1101!");
+ }
+
+ // This agent does NOT have a double argument premain() method.
+}
+
+class InheritAgent1101Super {
+
+ //
+ // This agent has a single argument premain() method which
+ // is NOT the one that should be called.
+ //
+ public static void premain (String agentArgs) {
+ System.out.println("Hello from Single-Arg InheritAgent1101Super!");
+ throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
+ }
+
+ //
+ // This agent has a double argument premain() method which
+ // is NOT the one that should be called.
+ //
+ public static void premain (String agentArgs, Instrumentation instArg) {
+ System.out.println("Hello from Double-Arg InheritAgent1101Super!");
+ throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/instrument/PremainClass/InheritAgent1110.java Mon Mar 24 15:20:29 2008 -0700
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 6289149
+ * @summary test config (1,1,1,0): inherited 2-arg, inherited 1-arg, and declared 2-arg in agent class
+ * @author Daniel D. Daugherty, Sun Microsystems
+ *
+ * @run shell ../MakeJAR3.sh InheritAgent1110
+ * @run main/othervm -javaagent:InheritAgent1110.jar DummyMain
+ */
+
+import java.lang.instrument.*;
+
+class InheritAgent1110 extends InheritAgent1110Super {
+
+ // This agent does NOT have a single argument premain() method.
+
+ //
+ // This agent has a double argument premain() method which
+ // is the one that should be called.
+ //
+ public static void premain (String agentArgs, Instrumentation instArg) {
+ System.out.println("Hello from Double-Arg InheritAgent1110!");
+ }
+}
+
+class InheritAgent1110Super {
+
+ //
+ // This agent has a single argument premain() method which
+ // is NOT the one that should be called.
+ //
+ public static void premain (String agentArgs) {
+ System.out.println("Hello from Single-Arg InheritAgent1110Super!");
+ throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
+ }
+
+ //
+ // This agent has a double argument premain() method which
+ // is NOT the one that should be called.
+ //
+ public static void premain (String agentArgs, Instrumentation instArg) {
+ System.out.println("Hello from Double-Arg InheritAgent1110Super!");
+ throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/instrument/PremainClass/InheritAgent1111.java Mon Mar 24 15:20:29 2008 -0700
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 6289149
+ * @summary test config (1,1,1,1): inherited 2-arg, inherited 1-arg, declared 2-arg and declared 1-arg in agent class
+ * @author Daniel D. Daugherty, Sun Microsystems
+ *
+ * @run shell ../MakeJAR3.sh InheritAgent1111
+ * @run main/othervm -javaagent:InheritAgent1111.jar DummyMain
+ */
+
+import java.lang.instrument.*;
+
+class InheritAgent1111 extends InheritAgent1111Super {
+
+ //
+ // This agent has a single argument premain() method which
+ // is NOT the one that should be called.
+ //
+ public static void premain (String agentArgs) {
+ System.out.println("Hello from Single-Arg InheritAgent1111!");
+ throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
+ }
+
+ //
+ // This agent has a double argument premain() method which
+ // is the one that should be called.
+ //
+ public static void premain (String agentArgs, Instrumentation instArg) {
+ System.out.println("Hello from Double-Arg InheritAgent1111!");
+ }
+}
+
+class InheritAgent1111Super {
+
+ //
+ // This agent has a single argument premain() method which
+ // is NOT the one that should be called.
+ //
+ public static void premain (String agentArgs) {
+ System.out.println("Hello from Single-Arg InheritAgent1111Super!");
+ throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
+ }
+
+ //
+ // This agent has a double argument premain() method which
+ // is NOT the one that should be called.
+ //
+ public static void premain (String agentArgs, Instrumentation instArg) {
+ System.out.println("Hello from Double-Arg InheritAgent1111Super!");
+ throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/instrument/PremainClass/NoPremainAgent.java Mon Mar 24 15:20:29 2008 -0700
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+import java.lang.instrument.*;
+
+class NoPremainAgent {
+
+ // This agent is missing the premain() function.
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/instrument/PremainClass/NoPremainAgent.sh Mon Mar 24 15:20:29 2008 -0700
@@ -0,0 +1,68 @@
+#
+# Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+# CA 95054 USA or visit www.sun.com if you need additional information or
+# have any questions.
+#
+
+# @test
+# @bug 6289149
+# @summary test when the agent's class is missing the premain() function.
+# @author Daniel D. Daugherty, Sun Microsystems
+#
+# @run build DummyMain
+# @run shell ../MakeJAR3.sh NoPremainAgent
+# @run shell NoPremainAgent.sh
+#
+
+if [ "${TESTJAVA}" = "" ]
+then
+ echo "TESTJAVA not set. Test cannot execute. Failed."
+ exit 1
+fi
+
+if [ "${TESTSRC}" = "" ]
+then
+ echo "TESTSRC not set. Test cannot execute. Failed."
+ exit 1
+fi
+
+if [ "${TESTCLASSES}" = "" ]
+then
+ echo "TESTCLASSES not set. Test cannot execute. Failed."
+ exit 1
+fi
+
+JAVAC="${TESTJAVA}"/bin/javac
+JAVA="${TESTJAVA}"/bin/java
+
+"${JAVA}" ${TESTVMOPTS} -javaagent:NoPremainAgent.jar \
+ -classpath "${TESTCLASSES}" DummyMain > output.log 2>&1
+cat output.log
+
+MESG="java.lang.NoSuchMethodException"
+grep "$MESG" output.log
+result=$?
+if [ "$result" = 0 ]; then
+ echo "PASS: found '$MESG' in the test output"
+else
+ echo "FAIL: did NOT find '$MESG' in the test output"
+fi
+
+exit $result
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/instrument/PremainClass/ZeroArgPremainAgent.java Mon Mar 24 15:20:29 2008 -0700
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+import java.lang.instrument.*;
+
+class ZeroArgPremainAgent {
+
+ // This agent has a zero arg premain() function.
+ public static void premain () {
+ System.out.println("Hello from ZeroArgInheritAgent!");
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/lang/instrument/PremainClass/ZeroArgPremainAgent.sh Mon Mar 24 15:20:29 2008 -0700
@@ -0,0 +1,68 @@
+#
+# Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+# CA 95054 USA or visit www.sun.com if you need additional information or
+# have any questions.
+#
+
+# @test
+# @bug 6289149
+# @summary test when the agent's class has a zero arg premain() function.
+# @author Daniel D. Daugherty, Sun Microsystems
+#
+# @run build DummyMain
+# @run shell ../MakeJAR3.sh ZeroArgPremainAgent
+# @run shell ZeroArgPremainAgent.sh
+#
+
+if [ "${TESTJAVA}" = "" ]
+then
+ echo "TESTJAVA not set. Test cannot execute. Failed."
+ exit 1
+fi
+
+if [ "${TESTSRC}" = "" ]
+then
+ echo "TESTSRC not set. Test cannot execute. Failed."
+ exit 1
+fi
+
+if [ "${TESTCLASSES}" = "" ]
+then
+ echo "TESTCLASSES not set. Test cannot execute. Failed."
+ exit 1
+fi
+
+JAVAC="${TESTJAVA}"/bin/javac
+JAVA="${TESTJAVA}"/bin/java
+
+"${JAVA}" ${TESTVMOPTS} -javaagent:ZeroArgPremainAgent.jar \
+ -classpath "${TESTCLASSES}" DummyMain > output.log 2>&1
+cat output.log
+
+MESG="java.lang.NoSuchMethodException"
+grep "$MESG" output.log
+result=$?
+if [ "$result" = 0 ]; then
+ echo "PASS: found '$MESG' in the test output"
+else
+ echo "FAIL: did NOT find '$MESG' in the test output"
+fi
+
+exit $result