Path: blob/master/test/hotspot/jtreg/vmTestbase/jit/CondExpr/CondExpr.java
40948 views
/*1* Copyright (c) 2008, 2020, 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*/22// test the conditional expressions232425/*26* @test27*28* @summary converted from VM Testbase jit/CondExpr.29* VM Testbase keywords: [jit, quick]30*31* @library /vmTestbase32* /test/lib33* @run main/othervm jit.CondExpr.CondExpr34*/3536package jit.CondExpr;3738import nsk.share.TestFailure;3940public class CondExpr {4142public static void trace (String s, int res) {43System.out.println("test result for " + s + " is " + res);44}4546public static int test_int1(int arg) { return (arg==10) ? 1 : 2; }4748public static int test_int(int arg) { return test_int1(arg) + test_int1(arg+1); }4950public static long test_long1(long arg) { return (arg==10) ? 1l : 2l; }5152public static int test_long(long arg) { return (int)(test_long1(arg) + test_long1(arg+1)); }5354public static float test_float1(float arg) { return (arg==10.0f) ? 1.0f : 2.0f; }5556public static int test_float(float arg) { return (int)(test_float1(arg) + test_float1(arg+1)); }5758public static double test_double1(double arg) { return (arg==10.0) ? 1.0 : 2.0; }5960public static int test_double(double arg) { return (int)(test_double1(arg) + test_double1(arg+1)); }616263public static int nested_test_int1(int arg) {64return (arg>1) ? ((arg==10) ? 1 : 2) : ((arg==-10) ? 3: 4);65}66676869public static int nested_test_int (int arg) {70return (nested_test_int1 (arg) + nested_test_int1 (arg+1) + nested_test_int1 (-arg) + nested_test_int1 (-arg-1)); }7172public static void main(String s[]) {73System.out.println ("Testing conditional expressions (srm 10/22)");74boolean correct = true;75int res = 0;76res = test_int(10); trace("test_int", res);77correct = correct & ( res == 3);78res = test_long(10l); trace("test_long", res);79correct = correct & ( res == 3);80res = test_float(10.0f); trace("test_float", res);81correct = correct & ( res == 3);82res = test_double(10.0); trace("test_double", res);83correct = correct & ( res == 3);8485res = nested_test_int(10); trace("nested_test_int", res);86correct = correct & ( res == 10);8788if (correct) System.out.println("Correct!");89else throw new TestFailure("ERRROR in conditional expressions");90}91}929394