Merge
authorcoleenp
Fri, 09 Mar 2018 13:06:36 -0500
changeset 49369 62dd99c3a6f9
parent 49368 2ed1c37df3a5 (current diff)
parent 49367 6a532ba7d9e9 (diff)
child 49370 81bc1dc36a53
Merge
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/compiler/aot/fingerprint/CDSDumper.java	Fri Mar 09 13:06:36 2018 -0500
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2016, 2018, 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.
+ */
+
+package compiler.aot.fingerprint;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.PrintStream;
+
+import jdk.test.lib.process.OutputAnalyzer;
+import jdk.test.lib.process.ProcessTools;
+
+// Usage:
+// java CDSDumper <classpath> <classlist> <archive> <class1> <class2> ...
+public class CDSDumper {
+    public static void main(String[] args) throws Exception {
+        String classpath = args[0];
+        String classlist = args[1];
+        String archive = args[2];
+
+        // Prepare the classlist
+        FileOutputStream fos = new FileOutputStream(classlist);
+        PrintStream ps = new PrintStream(fos);
+
+        for (int i=3; i<args.length; i++) {
+            ps.println(args[i].replace('.', '/'));
+        }
+        ps.close();
+        fos.close();
+
+        // Dump the archive
+        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
+            "-XX:+IgnoreUnrecognizedVMOptions",
+            "-XX:+UnlockCommercialFeatures",
+            "-XX:+UseAppCDS",
+            "-XX:+UnlockDiagnosticVMOptions",
+            "-cp", classpath,
+            "-XX:ExtraSharedClassListFile=" + classlist,
+            "-XX:SharedArchiveFile=" + archive,
+            "-Xshare:dump",
+            "-Xlog:cds");
+
+        OutputAnalyzer output = new OutputAnalyzer(pb.start());
+        output.shouldContain("Loading classes to share");
+        output.shouldHaveExitValue(0);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/compiler/aot/fingerprint/CDSRunner.java	Fri Mar 09 13:06:36 2018 -0500
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2016, 2018, 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.
+ */
+
+package compiler.aot.fingerprint;
+
+import jdk.test.lib.process.OutputAnalyzer;
+import jdk.test.lib.process.ProcessTools;
+
+// Usage:
+// java CDSRunner <vmargs> <class> <args> ...
+public class CDSRunner {
+    public static void main(String[] args) throws Exception {
+        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args);
+        OutputAnalyzer output = new OutputAnalyzer(pb.start());
+
+        System.out.println("[stdout = " + output.getStdout() + "]");
+        System.out.println("[stderr = " + output.getStderr() + "]");
+
+        output.shouldContain("PASSED");
+        output.shouldHaveExitValue(0);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/compiler/aot/fingerprint/SelfChanged.java	Fri Mar 09 13:06:36 2018 -0500
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2016, 2018, 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
+ * @summary AOT methods should be swept if a super class has changed.
+ * @library /test/lib /
+ * @modules java.base/jdk.internal.misc
+ *          java.management
+ * @requires vm.aot
+ * @build compiler.aot.fingerprint.SelfChanged
+ *        compiler.aot.AotCompiler
+ *
+ * @run main
+ *      compiler.aot.fingerprint.SelfChanged WRITE-UNMODIFIED-CLASS
+ * @run driver compiler.aot.AotCompiler -libname libSelfChanged.so
+ *      -class compiler.aot.fingerprint.Blah
+ *
+ * @run main/othervm
+ *      compiler.aot.fingerprint.SelfChanged TEST-UNMODIFIED
+ * @run main/othervm -XX:+UseAOT -XX:+PrintAOT -XX:AOTLibrary=./libSelfChanged.so
+ *      -Xlog:aot+class+fingerprint=trace -Xlog:aot+class+load=trace
+ *      compiler.aot.fingerprint.SelfChanged TEST-UNMODIFIED
+ *
+ * @run main
+ *      compiler.aot.fingerprint.SelfChanged WRITE-MODIFIED-CLASS
+ * @run main
+ *      compiler.aot.fingerprint.SelfChanged TEST-MODIFIED
+ * @run main/othervm -XX:+UseAOT -XX:+PrintAOT -XX:AOTLibrary=./libSelfChanged.so
+ *      -Xlog:aot+class+fingerprint=trace -Xlog:aot+class+load=trace
+ *      compiler.aot.fingerprint.SelfChanged TEST-MODIFIED
+ */
+
+package compiler.aot.fingerprint;
+
+import jdk.test.lib.Asserts;
+import jdk.test.lib.compiler.InMemoryJavaCompiler;
+
+import java.io.*;
+
+class Blah {
+    volatile int z;
+    int getX() {
+        for (z = 0; z < 10000; z++) {
+            if (z % 7 == 1) {
+                z += 2;
+            }
+        }
+        return 0;
+    }
+}
+
+public class SelfChanged {
+    public static void main(String args[]) throws Throwable {
+        Blah f = new Blah();
+        System.out.println("f.getX = " + f.getX());
+        switch (args[0]) {
+        case "WRITE-UNMODIFIED-CLASS":
+            compileClass(false);
+            break;
+        case "WRITE-MODIFIED-CLASS":
+            compileClass(true);
+            break;
+        case "TEST-UNMODIFIED":
+            Asserts.assertTrue(f.getX() == 0, "getX from unmodified Blah class should return 0");
+            break;
+        case "TEST-MODIFIED":
+            Asserts.assertTrue(f.getX() == 1, "getX from modified Blah class should return 1");
+            break;
+        default:
+            throw new RuntimeException("unexpected option: " + args[0]);
+        }
+    }
+
+    static void compileClass(boolean isModified) throws Throwable {
+        String src =
+               "package compiler.aot.fingerprint;"
+             + "public class Blah {"
+             + "    volatile int z;"
+             + "    int getX() {"
+             + "        for (z = 0; z < 10000; z++) {"
+             + "            if (z % 7 == 1) {"
+             + "                z += 2;"
+             + "            }"
+             + "        }"
+             + "        return " + ((isModified) ? "1" : "0") + ";"
+             + "    }"
+             + "    int getY() {return 255;}"
+
+            // The following is for the SelfChangedCDS.java test case. We always load an unmodified
+            // version of Blah from the CDS archive. However, we would load an AOT library that
+            // was compiled using a modified version of Blah. The getX method in this AOT library should
+            // not be used.
+
+            + "    public static void main(String args[]) {"
+             + "        Blah b = new Blah();"
+             + "        int n = b.getX();"
+             + "        if (n != 0) {"
+             + "            throw new RuntimeException(args[0] +  \" : \" + n);"
+             + "        }"
+             + "        System.out.println(\"PASSED\");"
+             + "    }"
+             + "}";
+
+        String filename = System.getProperty("test.classes") + "/compiler/aot/fingerprint/Blah.class";
+        FileOutputStream fos = new FileOutputStream(filename);
+        fos.write(InMemoryJavaCompiler.compile("compiler.aot.fingerprint.Blah", src));
+        fos.close();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/compiler/aot/fingerprint/SelfChangedCDS.java	Fri Mar 09 13:06:36 2018 -0500
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2016, 2018, 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
+ * @summary AOT methods should be swept if a super class has changed (with CDS).
+ * @library /test/lib /
+ * @modules java.base/jdk.internal.misc
+ *          java.management
+ * @requires vm.aot
+ * @build compiler.aot.fingerprint.SelfChanged
+ *        compiler.aot.AotCompiler
+ *
+ * @run main compiler.aot.fingerprint.SelfChanged WRITE-UNMODIFIED-CLASS
+ * @run driver compiler.aot.AotCompiler -libname libSelfChanged.so
+ *      -class compiler.aot.fingerprint.Blah
+ *
+ * @run driver ClassFileInstaller -jar SelfChangedCDS.jar compiler.aot.fingerprint.Blah
+ * @run main compiler.aot.fingerprint.CDSDumper SelfChangedCDS.jar SelfChangedCDS.classlist SelfChangedCDS.jsa
+ *      compiler.aot.fingerprint.Blah
+ *
+ * @run main compiler.aot.fingerprint.CDSRunner -cp SelfChangedCDS.jar
+ *      compiler.aot.fingerprint.Blah TEST-UNMODIFIED
+ * @run main compiler.aot.fingerprint.CDSRunner -cp SelfChangedCDS.jar
+ *      -XX:+UseAOT -XX:+PrintAOT -XX:AOTLibrary=./libSelfChanged.so
+ *      -XX:+UnlockDiagnosticVMOptions -XX:SharedArchiveFile=SelfChangedCDS.jsa
+ *      -XX:+IgnoreUnrecognizedVMOptions
+ *      -Xshare:auto -XX:+UnlockCommercialFeatures -XX:+UseAppCDS -showversion
+ *      -Xlog:aot+class+fingerprint=trace -Xlog:aot+class+load=trace
+ *      compiler.aot.fingerprint.Blah TEST-UNMODIFIED
+ *
+ * @run main
+ *      compiler.aot.fingerprint.SelfChanged WRITE-MODIFIED-CLASS
+ * @run driver compiler.aot.AotCompiler -libname libSelfChanged.so
+ *      -class compiler.aot.fingerprint.Blah
+ *
+ * @run main compiler.aot.fingerprint.CDSRunner -cp SelfChangedCDS.jar
+ *      compiler.aot.fingerprint.Blah TEST-MODIFIED
+ * @run main compiler.aot.fingerprint.CDSRunner -cp SelfChangedCDS.jar
+ *      -XX:+UseAOT -XX:+PrintAOT -XX:AOTLibrary=./libSelfChanged.so
+ *      -XX:+UnlockDiagnosticVMOptions -XX:SharedArchiveFile=SelfChangedCDS.jsa
+ *      -XX:+IgnoreUnrecognizedVMOptions
+ *      -Xshare:auto -XX:+UnlockCommercialFeatures -XX:+UseAppCDS -showversion
+ *      -Xlog:aot+class+fingerprint=trace -Xlog:aot+class+load=trace
+ *      compiler.aot.fingerprint.Blah TEST-MODIFIED
+ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/compiler/aot/fingerprint/SuperChanged.java	Fri Mar 09 13:06:36 2018 -0500
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2016, 2018, 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
+ * @summary AOT methods should be swept if a super class has changed.
+ * @library /test/lib /
+ * @modules java.base/jdk.internal.misc
+ *          java.management
+ * @requires vm.aot
+ * @build compiler.aot.fingerprint.SuperChanged
+ *        compiler.aot.AotCompiler
+ *
+ * @run main
+ *      compiler.aot.fingerprint.SuperChanged WRITE-UNMODIFIED-CLASS
+ * @run driver compiler.aot.AotCompiler -libname libSuperChanged.so
+ *      -class compiler.aot.fingerprint.Foo
+ *
+ * @run main
+ *      compiler.aot.fingerprint.SuperChanged TEST-UNMODIFIED
+ * @run main/othervm -XX:+UseAOT -XX:+PrintAOT -XX:AOTLibrary=./libSuperChanged.so
+ *      -Xlog:aot+class+fingerprint=trace -Xlog:aot+class+load=trace
+ *      compiler.aot.fingerprint.SuperChanged TEST-UNMODIFIED
+  *
+ * @run main
+ *      compiler.aot.fingerprint.SuperChanged WRITE-MODIFIED-CLASS
+ * @run main
+ *      compiler.aot.fingerprint.SuperChanged TEST-MODIFIED
+ * @run main/othervm -XX:+UseAOT -XX:+PrintAOT -XX:AOTLibrary=./libSuperChanged.so
+ *      -Xlog:aot+class+fingerprint=trace -Xlog:aot+class+load=trace
+ *      compiler.aot.fingerprint.SuperChanged TEST-MODIFIED
+ */
+
+package compiler.aot.fingerprint;
+
+import jdk.test.lib.Asserts;
+import jdk.test.lib.compiler.InMemoryJavaCompiler;
+
+import java.io.*;
+
+class Bar {
+    volatile int x = 0;
+    volatile int y = 1;
+}
+
+class Foo extends Bar {
+
+    volatile int z;
+    int getX() {
+        for (z = 0; z < 10000; z++) {
+            if (z % 7 == 1) {
+                z += 2;
+            }
+        }
+        return x;
+    }
+}
+
+public class SuperChanged {
+    public static void main(String args[]) throws Throwable {
+        Foo f = new Foo();
+        System.out.println("f.getX = " + f.getX());
+        switch (args[0]) {
+        case "WRITE-UNMODIFIED-CLASS":
+            compileClass(false);
+            break;
+        case "WRITE-MODIFIED-CLASS":
+            compileClass(true);
+            break;
+        case "TEST-UNMODIFIED":
+            Asserts.assertTrue(f.getX() == 0, "getX from unmodified Foo class should return 0");
+            break;
+        case "TEST-MODIFIED":
+            Asserts.assertTrue(f.getX() == 1, "getX from modified Foo class should return 1");
+            break;
+        default:
+            throw new RuntimeException("unexpected option: " + args[0]);
+        }
+    }
+
+    static void compileClass(boolean isModified) throws Throwable {
+        String class_src_0 = "package compiler.aot.fingerprint; class Bar {volatile int x = 0;  volatile int y = 1;}";
+        String class_src_1 = "package compiler.aot.fingerprint; class Bar {volatile int y = 0;  volatile int x = 1;}";
+        String src = (isModified) ? class_src_1 : class_src_0;
+
+        String filename = System.getProperty("test.classes") + "/compiler/aot/fingerprint/Bar.class";
+        FileOutputStream fos = new FileOutputStream(filename);
+        fos.write(InMemoryJavaCompiler.compile("compiler.aot.fingerprint.Bar", src));
+        fos.close();
+    }
+}