[prev in list] [next in list] [prev in thread] [next in thread]
List: openjdk-serviceability-dev
Subject: [PATCH] 7142035 assert in j.l.instrument agents during shutdown when daemon thread is running
From: "Chan, Sunny" <Sunny.Chan () gs ! com>
Date: 2013-12-23 7:57:36
Message-ID: 1CF6FDFD0639DF478B44651D79ECE7049BCE8691 () GSCMHKP12EX ! firmwide ! corp ! gs ! com
[Download RAW message or body]
Hello,
I would like to proposed the following patch to fix the bug 7142035. The mi=
ssing assert could cause an Assertion failure message if you install a java=
.lang.instrument agent and have a daemon thread running in the JVM. I have =
also included a regression test that demonstrate the issue.
Please review this and let me know if we need to modify the patch in any wa=
y.
Sunny Chan, Executive Director, Technology
Goldman Sachs (Asia) L.L.C. | 68th Floor | Cheung Kong Center | 2 Queens Ro=
ad Central | Hong Kong
email: sunny.chan@gs.com | Tel: +852 2978 6481 | Fax: +852 2978 0633
This message may contain information that is confidential or privileged. I=
f you are not the intended recipient, please advise the sender immediately =
and delete this message. See http://www.gs.com/disclaimer/email for furthe=
r information on confidentiality and the risks inherent in electronic commu=
nication.
["7142035.patch" (application/octet-stream)]
# HG changeset patch
# User Sunny Chan <sunny.chan@gs.com>
# Date 1387784601 18000
# Node ID 15c562dd2c9194157358a4460387a5bc538f1eb0
# Parent ce05e132b1370fe8a66ab9373014d12328c591c4
7142035 assert in j.l.instrument agents during shutdown when daemon thread is running
diff --git a/src/share/instrument/Reentrancy.c b/src/share/instrument/Reentrancy.c
--- a/src/share/instrument/Reentrancy.c
+++ b/src/share/instrument/Reentrancy.c
@@ -158,6 +158,7 @@
error = confirmingTLSSet( jvmtienv,
thread,
JPLIS_CURRENTLY_OUTSIDE_TOKEN);
+ check_phase_ret(error);
jplis_assert(error == JVMTI_ERROR_NONE);
}
diff --git a/test/java/lang/instrument/DummyAgent.java \
b/test/java/lang/instrument/DummyAgent.java new file mode 100644
--- /dev/null
+++ b/test/java/lang/instrument/DummyAgent.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2013 Goldman Sachs.
+ * Copyright (c) 2013, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.lang.instrument.ClassFileTransformer;
+import java.lang.instrument.IllegalClassFormatException;
+import java.lang.instrument.Instrumentation;
+import java.security.ProtectionDomain;
+
+
+public class DummyAgent implements ClassFileTransformer {
+
+ @Override
+ public byte[] transform(ClassLoader loader, String className,
+ Class<?> classBeingRedefined, ProtectionDomain \
protectionDomain, + byte[] classfileBuffer) throws \
IllegalClassFormatException { +
+ System.out.println("seen "+className);
+ return classfileBuffer;
+ }
+
+ public static void premain(String agentArgs, Instrumentation inst) {
+ inst.addTransformer(new DummyAgent(), false);
+ }
+
+}
diff --git a/test/java/lang/instrument/GenerateLotsOfClasses.sh \
b/test/java/lang/instrument/GenerateLotsOfClasses.sh new file mode 100755
--- /dev/null
+++ b/test/java/lang/instrument/GenerateLotsOfClasses.sh
@@ -0,0 +1,62 @@
+#
+# Copyright 2013 Goldman Sachs.
+# Copyright (c) 2008, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+if [ "${TESTJAVA}" = "" ]
+then
+ echo "TESTJAVA not set. Test cannot execute. Failed."
+ exit 1
+fi
+
+if [ "${COMPILEJAVA}" = "" ]
+then
+ COMPILEJAVA="${TESTJAVA}"
+fi
+echo "COMPILEJAVA=${COMPILEJAVA}"
+
+JAVAC="${COMPILEJAVA}"/bin/javac
+JAR="${COMPILEJAVA}"/bin/jar
+JAVA="${TESTJAVA}"/bin/java
+
+count=1
+while [ "$count" -lt 5001 ]
+do
+ cat > Class$count.java <<- ENDCLASS
+ public class Class$count {
+ }
+ ENDCLASS
+
+ if [ `expr $count % 100` -eq 0 ]; then
+ $JAVAC Class*.java
+
+ if [ -e LotsOfClasses.jar ]; then
+ $JAR -uf LotsOfClasses.jar Class*.class
+ else
+ $JAR -cf LotsOfClasses.jar Class*.class
+ fi
+
+ rm Class*.java Class*.class
+ fi
+
+ count=`expr $count + 1`
+done
diff --git a/test/java/lang/instrument/TestDaemonThread.java \
b/test/java/lang/instrument/TestDaemonThread.java new file mode 100644
--- /dev/null
+++ b/test/java/lang/instrument/TestDaemonThread.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2013 Goldman Sachs.
+ * Copyright (c) 2013, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.File;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.jar.JarFile;
+
+class LoadClasses implements Runnable {
+ URLClassLoader loader = null;
+
+ public LoadClasses(File f) throws Exception {
+ loader = new URLClassLoader(new URL[] {f.toURI().toURL()});
+ }
+
+ public void run() {
+ for(int i=1; i<=5000; i++) {
+ try {
+ Class c = loader.loadClass("Class"+i);
+ System.out.println("Loaded:"+c.getName());
+ } catch (Exception e) {
+ System.err.println("Can't load class");
+ e.printStackTrace();
+ }
+ }
+ }
+}
+
+public class TestDaemonThread {
+
+ public static void main(String[] args) throws Exception {
+ Thread t = new Thread(new LoadClasses(new File(args[0])));
+ t.setDaemon(true);
+ t.start();
+ Thread.sleep(1000);
+ }
+}
diff --git a/test/java/lang/instrument/TestDaemonThread.sh \
b/test/java/lang/instrument/TestDaemonThread.sh new file mode 100644
--- /dev/null
+++ b/test/java/lang/instrument/TestDaemonThread.sh
@@ -0,0 +1,82 @@
+#
+# Copyright 2013 Goldman Sachs.
+# Copyright (c) 2008, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+# @test
+# @bug 7142035
+# @summary assert in java.lang.instrument agents during shutdown when daemon thread \
is running +# @author Sunny Chan
+#
+# @run shell MakeJAR3.sh DummyAgent
+# @run shell GenerateLotsOfClasses.sh
+# @run build TestDaemonThread
+# @run shell TestDaemonThread.sh
+#
+
+if [ "${TESTJAVA}" = "" ]
+then
+ echo "TESTJAVA not set. Test cannot execute. Failed."
+ exit 1
+fi
+
+if [ "${COMPILEJAVA}" = "" ]
+then
+ COMPILEJAVA="${TESTJAVA}"
+fi
+echo "COMPILEJAVA=${COMPILEJAVA}"
+
+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="${COMPILEJAVA}"/bin/javac
+JAVA="${TESTJAVA}"/bin/java
+
+ERR_MESGS="ASSERTION ERROR"
+
+for i in `seq 1 50`; do
+ ${JAVA} ${TESTVMOPTS} -javaagent:DummyAgent.jar \
+ -classpath "${TESTCLASSES}" TestDaemonThread LotsOfClasses.jar > output.log \
2>&1 +
+ for MESG in $ERR_MESGS; do
+ grep -i "$MESG" output.log
+ result=$?
+ if [ "$result" = 0 ]; then
+ echo "FAIL: found '$MESG' in the test output"
+ exit 1
+ fi
+ done
+done
+
+echo "PASS: did NOT find '$MESG' in the test output"
+exit 0;
+
+
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic