changeset 59356:4cd328cdd20f

8244164: AArch64: jaotc generates incorrect code for compressed OOPs with non-zero heap base Reviewed-by: aph
author ngasson
date Mon, 11 May 2020 12:05:55 +0800
parents 5e33db086599
children 725478d023c4
files src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.aarch64/src/org/graalvm/compiler/hotspot/aarch64/AArch64HotSpotMove.java test/hotspot/jtreg/compiler/aot/TestHeapBase.java
diffstat 2 files changed, 86 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.aarch64/src/org/graalvm/compiler/hotspot/aarch64/AArch64HotSpotMove.java	Tue May 19 15:17:00 2020 -0700
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.aarch64/src/org/graalvm/compiler/hotspot/aarch64/AArch64HotSpotMove.java	Mon May 11 12:05:55 2020 +0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2020, 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
@@ -139,8 +139,9 @@
             Register resultRegister = asRegister(result);
             Register ptr = asRegister(input);
             Register base = (isRegister(baseRegister) ? asRegister(baseRegister) : zr);
+            boolean pic = GeneratePIC.getValue(crb.getOptions());
             // result = (ptr - base) >> shift
-            if (!encoding.hasBase()) {
+            if (!pic && !encoding.hasBase()) {
                 if (encoding.hasShift()) {
                     masm.lshr(64, resultRegister, ptr, encoding.getShift());
                 } else {
@@ -189,7 +190,8 @@
         public void emitCode(CompilationResultBuilder crb, AArch64MacroAssembler masm) {
             Register inputRegister = asRegister(input);
             Register resultRegister = asRegister(result);
-            Register base = encoding.hasBase() ? asRegister(baseRegister) : null;
+            boolean pic = GeneratePIC.getValue(crb.getOptions());
+            Register base = pic || encoding.hasBase() ? asRegister(baseRegister) : null;
             emitUncompressCode(masm, inputRegister, resultRegister, base, encoding.getShift(), nonNull);
         }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/compiler/aot/TestHeapBase.java	Mon May 11 12:05:55 2020 +0800
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, Arm Limited. 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 8244164
+ * @requires vm.aot & vm.bits == 64
+ * @library /test/lib /testlibrary /
+ * @modules java.base/jdk.internal.misc
+ * @build compiler.aot.TestHeapBase
+ *        sun.hotspot.WhiteBox
+ * @run driver ClassFileInstaller sun.hotspot.WhiteBox
+ * @run driver compiler.aot.AotCompiler -libname libTestHeapBase.so
+ *     -class compiler.aot.TestHeapBase
+ *     -compile compiler.aot.TestHeapBase.test()V
+ *     -extraopt -XX:+UseCompressedOops -extraopt -Xmx1g
+ * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UseAOT
+ *     -XX:+UseCompressedOops -XX:HeapBaseMinAddress=32g
+ *     -XX:AOTLibrary=./libTestHeapBase.so -Xbootclasspath/a:.
+ *     -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xlog:aot+class+load=trace
+ *     compiler.aot.TestHeapBase
+ * @summary check for crash when jaotc is run with zero-based compressed oops then
+ *          generated code is loaded in vm with non-zero-based compressed oops.
+ */
+
+package compiler.aot;
+
+import java.lang.reflect.Method;
+import jdk.test.lib.Asserts;
+import jdk.test.lib.Utils;
+import sun.hotspot.WhiteBox;
+import compiler.whitebox.CompilerWhiteBoxTest;
+
+public final class TestHeapBase {
+    private static final String TEST_METHOD = "test";
+    private static final WhiteBox WB = WhiteBox.getWhiteBox();
+    private final Method testMethod;
+
+    private TestHeapBase() {
+        try {
+            testMethod = getClass().getDeclaredMethod(TEST_METHOD);
+        } catch (NoSuchMethodException e) {
+            throw new Error("TEST BUG: no test method found", e);
+        }
+    }
+
+    public static void main(String args[]) {
+        new TestHeapBase().test();
+    }
+
+    private void test() {
+        System.out.println("Hello, World!");
+
+        Asserts.assertTrue(WB.isMethodCompiled(testMethod),
+                "Method expected to be compiled");
+        Asserts.assertEQ(WB.getMethodCompilationLevel(testMethod),
+                CompilerWhiteBoxTest.COMP_LEVEL_AOT,
+                "Expected method to be AOT compiled");
+    }
+}