Path: blob/master/test/hotspot/jtreg/compiler/c2/Test6443505.java
41149 views
/*1* Copyright (c) 2013, Oracle and/or its affiliates. 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 644350526* @summary Some cases for CmpLTMask missed; also wrong code.27*28* @run main/othervm -Xcomp29* -XX:CompileCommand=compileonly,compiler.c2.Test6443505::compiled30* compiler.c2.Test644350531*/3233package compiler.c2;3435public class Test6443505 {3637public static void main(String[] args) throws InterruptedException {38test(Integer.MIN_VALUE, 0);39test(0, Integer.MIN_VALUE);40test(Integer.MIN_VALUE, -1);41test(-1, Integer.MIN_VALUE);42test(Integer.MIN_VALUE, 1);43test(1, Integer.MIN_VALUE);4445test(Integer.MAX_VALUE, 0);46test(0, Integer.MAX_VALUE);47test(Integer.MAX_VALUE, -1);48test(-1, Integer.MAX_VALUE);49test(Integer.MAX_VALUE, 1);50test(1, Integer.MAX_VALUE);5152test(Integer.MIN_VALUE, Integer.MAX_VALUE);53test(Integer.MAX_VALUE, Integer.MIN_VALUE);5455test(1, -1);56test(1, 0);57test(1, 1);58test(-1, -1);59test(-1, 0);60test(-1, 1);61test(0, -1);62test(0, 0);63test(0, 1);64}6566public static void test(int a, int b) throws InterruptedException {67int C = compiled(4, a, b);68int I = interpreted(4, a, b);69if (C != I) {70System.err.println("#1 C = " + C + ", I = " + I);71System.err.println("#1 C != I, FAIL");72System.exit(97);73}7475C = compiled(a, b, q, 4);76I = interpreted(a, b, q, 4);77if (C != I) {78System.err.println("#2 C = " + C + ", I = " + I);79System.err.println("#2 C != I, FAIL");80System.exit(97);81}8283}8485static int q = 4;8687// If improperly compiled, uses carry/borrow bit, which is wrong.88// with -XX:+PrintOptoAssembly, look for cadd_cmpLTMask89static int compiled(int p, int x, int y) {90return (x < y) ? q + (x - y) : (x - y);91}9293// interpreted reference94static int interpreted(int p, int x, int y) {95return (x < y) ? q + (x - y) : (x - y);96}9798// Test new code with a range of cases99// with -XX:+PrintOptoAssembly, look for and_cmpLTMask100static int compiled(int x, int y, int q, int p) {101return (x < y) ? p + q : q;102}103104// interpreted reference105static int interpreted(int x, int y, int q, int p) {106return (x < y) ? p + q : q;107}108109}110111112