Path: blob/master/test/hotspot/jtreg/compiler/codegen/TestOopCmp.java
41149 views
/*1* Copyright (c) 2019 SAP SE. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 822108326* @requires vm.gc.Serial27* @requires vm.bits == 64 & vm.opt.final.UseCompressedOops == true28* @summary On ppc64, C1 erroneously emits a 32-bit compare instruction for oop compares.29* @modules java.base/jdk.internal.misc:+open30* @library /test/lib /31* @build sun.hotspot.WhiteBox32* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox33* @run main/othervm -Xbatch -XX:-UseTLAB -Xmx4m -XX:+UseSerialGC -XX:HeapBaseMinAddress=0x70000000034* -XX:CompileCommand=compileonly,compiler.codegen.TestOopCmp::nullTest35* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:.36* compiler.codegen.TestOopCmp37* @author [email protected]38*/3940package compiler.codegen;4142import sun.hotspot.WhiteBox;4344public class TestOopCmp {4546private static Object nullObj = null;4748public static boolean nullTest(Object o) {49if (o == nullObj) {50return true;51} else {52return false;53}54}5556public static void main(String args[]) {5758WhiteBox WB = WhiteBox.getWhiteBox();5960// The test is started with -XX:HeapBaseMinAddress=0x700000000 and a61// small heap of only 4mb. This works pretty reliable and at least on62// Linux/Windows we will get a heap starting at 0x700000000.63// The test also runs with -XX:+UseSerialGC which means that we'll get64// eden starting at 0x700000000.65// Calling 'System.gc()' will clean up all the objects from eden, so if66// eden starts at 0x700000000 the first allocation right after the67// system GC will be allcoated right at address 0x700000000.68System.gc();69String s = new String("I'm not null!!!");70if (WB.getObjectAddress(s) == 0x700000000L) {71System.out.println("Got object at address 0x700000000");72}7374// We call 'nullTest()' with the newly allocated String object. If it was75// allocated at 0x700000000, its 32 least-significant bits will be 0 and a76// 32-bit comparison with 'nullObj' (which is 'null') will yield true and77// result in a test failure.78// If the code generated for 'nullTest()' correctly performs a 64-bit79// comparison or if we didn't manage to allcoate 's' at 0x700000000 the80// test will always succeed.81for (int i = 0; i < 30_000; i++) {82if (nullTest(s)) {83throw new RuntimeException("Comparing non-null object with null returned 'true'");84}85}86}87}888990