1 /* 2 * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 // test the conditional expressions 24 25 26 /* 27 * @test 28 * 29 * @summary converted from VM Testbase jit/CondExpr. 30 * VM Testbase keywords: [jit, quick] 31 * 32 * @library /vmTestbase 33 * /test/lib 34 * @run driver jdk.test.lib.FileInstaller . . 35 * @run main/othervm jit.CondExpr.CondExpr 36 */ 37 38 package jit.CondExpr; 39 40 import nsk.share.TestFailure; 41 42 public class CondExpr { 43 trace(String s, int res)44 public static void trace (String s, int res) { 45 System.out.println("test result for " + s + " is " + res); 46 } 47 test_int1(int arg)48 public static int test_int1(int arg) { return (arg==10) ? 1 : 2; } 49 test_int(int arg)50 public static int test_int(int arg) { return test_int1(arg) + test_int1(arg+1); } 51 test_long1(long arg)52 public static long test_long1(long arg) { return (arg==10) ? 1l : 2l; } 53 test_long(long arg)54 public static int test_long(long arg) { return (int)(test_long1(arg) + test_long1(arg+1)); } 55 test_float1(float arg)56 public static float test_float1(float arg) { return (arg==10.0f) ? 1.0f : 2.0f; } 57 test_float(float arg)58 public static int test_float(float arg) { return (int)(test_float1(arg) + test_float1(arg+1)); } 59 test_double1(double arg)60 public static double test_double1(double arg) { return (arg==10.0) ? 1.0 : 2.0; } 61 test_double(double arg)62 public static int test_double(double arg) { return (int)(test_double1(arg) + test_double1(arg+1)); } 63 64 nested_test_int1(int arg)65 public static int nested_test_int1(int arg) { 66 return (arg>1) ? ((arg==10) ? 1 : 2) : ((arg==-10) ? 3: 4); 67 } 68 69 70 nested_test_int(int arg)71 public static int nested_test_int (int arg) { 72 return (nested_test_int1 (arg) + nested_test_int1 (arg+1) + nested_test_int1 (-arg) + nested_test_int1 (-arg-1)); } 73 main(String s[])74 public static void main(String s[]) { 75 System.out.println ("Testing conditional expressions (srm 10/22)"); 76 boolean correct = true; 77 int res = 0; 78 res = test_int(10); trace("test_int", res); 79 correct = correct & ( res == 3); 80 res = test_long(10l); trace("test_long", res); 81 correct = correct & ( res == 3); 82 res = test_float(10.0f); trace("test_float", res); 83 correct = correct & ( res == 3); 84 res = test_double(10.0); trace("test_double", res); 85 correct = correct & ( res == 3); 86 87 res = nested_test_int(10); trace("nested_test_int", res); 88 correct = correct & ( res == 10); 89 90 if (correct) System.out.println("Correct!"); 91 else throw new TestFailure("ERRROR in conditional expressions"); 92 } 93 } 94