Path: blob/master/test/hotspot/jtreg/vmTestbase/jit/Arrays/ArrayTests/ArrayTests.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// srm 96101223// Test if array stores and reads are correct for24// integral types and floating points252627/*28* @test29*30* @summary converted from VM Testbase jit/Arrays/ArrayTests.31* VM Testbase keywords: [jit, quick]32*33* @library /vmTestbase34* /test/lib35* @run main/othervm jit.Arrays.ArrayTests.ArrayTests36*/3738package jit.Arrays.ArrayTests;3940import nsk.share.TestFailure;4142public class ArrayTests {43int base_array[];44static int the_int_res = 200;45static int the_char_res = 13041864;46static int the_byte_res = -312;47static int n = 400;4849ArrayTests() {50base_array = new int [n];51int start_value = n/2;52for (int i=0; i<n; i++) {53base_array[i]= start_value;54start_value--;55}56};5758void print() {59for (int i=0; i<base_array.length; i++)60System.out.print(" "+base_array[i]);61// System.out.println("Result is " + the_res);62}6364boolean with_chars () {65char char_array[] = new char[n];66int res = 0;67for (int i=0; i<n; i++) {68char_array[i] = (char)base_array[i];69// System.out.print (" " + (int) char_array[i]);70}71for (int i=0; i<n; i++) {72res += (int) char_array[i];73}74System.out.println("chars " + res + " == " + the_char_res);75return (res==the_char_res);76}7778boolean with_bytes () {79byte byte_array[] = new byte[n];80int res = 0;81for (int i=0; i<n; i++) {82byte_array[i] = (byte)base_array[i];83}84for (int i=0; i<n; i++) {85res += (int) byte_array[i];86}87System.out.println("bytes " + res + " == " + the_byte_res);88return res==the_byte_res;89}9091boolean with_shorts () {92short short_array[] = new short[n];93int res = 0;94for (int i=0; i<n; i++) {95short_array[i] = (short)base_array[i];96}97for (int i=0; i<n; i++) {98res += (int) short_array[i];99}100System.out.println("shorts " + res + " == " + the_int_res);101return res==the_int_res;102}103104boolean with_ints () {105int res = 0;106for (int i=0; i<n; i++) {107res += base_array[i];108}109// base_array is integer110return (res==the_int_res);111}112113boolean with_longs() {114long long_array[] = new long[n];115int res = 0;116for (int i=0; i<n; i++) {117long_array[i] = (long)base_array[i];118}119for (int i=0; i<n; i++) {120res += (int) long_array[i];121}122System.out.println("longs " + res + " == " + the_int_res);123return res==the_int_res;124}125126boolean with_floats () {127float float_array[] = new float[n];128int res = 0;129for (int i=0; i<n; i++) {130float_array[i] = (float)base_array[i];131}132for (int i=0; i<n; i++) {133res += (int) float_array[i];134}135System.out.println("floats " + res + " == " + the_int_res);136return res==the_int_res;137}138139boolean with_doubles () {140double double_array[] = new double[n];141int res = 0;142for (int i=0; i<n; i++) {143double_array[i] = (double)base_array[i];144}145for (int i=0; i<n; i++) {146res += (int) double_array[i];147}148System.out.println("doubles " + res + " == " + the_int_res);149return res==the_int_res;150}151152void check(String msg, boolean flag) {153if (!flag) {154System.out.println("ERROR in " + msg);155}156}157158boolean execute() {159// print();160boolean res = true;161res = res & with_chars(); check("chars",res);162res = res & with_shorts(); check("shorts",res);163res = res & with_bytes(); check("bytes",res);164res = res & with_ints(); check("ints",res);165res = res & with_longs(); check("longs",res);166res = res & with_floats(); check("floats",res);167res = res & with_doubles(); check("doubles",res);168169return res;170}171172173public static void main (String s[]) {174boolean res = true;175ArrayTests at = new ArrayTests();176res = res & at.execute();177178if (res) System.out.println("Array read/write testsOK (srm 10/22/96)");179else throw new TestFailure("Error in read/write array tests!");180}181182}183184185