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 // srm 961012 24 // Test if array stores and reads are correct for 25 // integral types and floating points 26 27 28 /* 29 * @test 30 * 31 * @summary converted from VM Testbase jit/Arrays/ArrayTests. 32 * VM Testbase keywords: [jit, quick] 33 * 34 * @library /vmTestbase 35 * /test/lib 36 * @run driver jdk.test.lib.FileInstaller . . 37 * @run main/othervm jit.Arrays.ArrayTests.ArrayTests 38 */ 39 40 package jit.Arrays.ArrayTests; 41 42 import nsk.share.TestFailure; 43 44 public class ArrayTests { 45 int base_array[]; 46 static int the_int_res = 200; 47 static int the_char_res = 13041864; 48 static int the_byte_res = -312; 49 static int n = 400; 50 51 ArrayTests() { 52 base_array = new int [n]; 53 int start_value = n/2; 54 for (int i=0; i<n; i++) { 55 base_array[i]= start_value; 56 start_value--; 57 } 58 }; 59 60 void print() { 61 for (int i=0; i<base_array.length; i++) 62 System.out.print(" "+base_array[i]); 63 // System.out.println("Result is " + the_res); 64 } 65 66 boolean with_chars () { 67 char char_array[] = new char[n]; 68 int res = 0; 69 for (int i=0; i<n; i++) { 70 char_array[i] = (char)base_array[i]; 71 // System.out.print (" " + (int) char_array[i]); 72 } 73 for (int i=0; i<n; i++) { 74 res += (int) char_array[i]; 75 } 76 System.out.println("chars " + res + " == " + the_char_res); 77 return (res==the_char_res); 78 } 79 80 boolean with_bytes () { 81 byte byte_array[] = new byte[n]; 82 int res = 0; 83 for (int i=0; i<n; i++) { 84 byte_array[i] = (byte)base_array[i]; 85 } 86 for (int i=0; i<n; i++) { 87 res += (int) byte_array[i]; 88 } 89 System.out.println("bytes " + res + " == " + the_byte_res); 90 return res==the_byte_res; 91 } 92 93 boolean with_shorts () { 94 short short_array[] = new short[n]; 95 int res = 0; 96 for (int i=0; i<n; i++) { 97 short_array[i] = (short)base_array[i]; 98 } 99 for (int i=0; i<n; i++) { 100 res += (int) short_array[i]; 101 } 102 System.out.println("shorts " + res + " == " + the_int_res); 103 return res==the_int_res; 104 } 105 106 boolean with_ints () { 107 int res = 0; 108 for (int i=0; i<n; i++) { 109 res += base_array[i]; 110 } 111 // base_array is integer 112 return (res==the_int_res); 113 } 114 115 boolean with_longs() { 116 long long_array[] = new long[n]; 117 int res = 0; 118 for (int i=0; i<n; i++) { 119 long_array[i] = (long)base_array[i]; 120 } 121 for (int i=0; i<n; i++) { 122 res += (int) long_array[i]; 123 } 124 System.out.println("longs " + res + " == " + the_int_res); 125 return res==the_int_res; 126 } 127 128 boolean with_floats () { 129 float float_array[] = new float[n]; 130 int res = 0; 131 for (int i=0; i<n; i++) { 132 float_array[i] = (float)base_array[i]; 133 } 134 for (int i=0; i<n; i++) { 135 res += (int) float_array[i]; 136 } 137 System.out.println("floats " + res + " == " + the_int_res); 138 return res==the_int_res; 139 } 140 141 boolean with_doubles () { 142 double double_array[] = new double[n]; 143 int res = 0; 144 for (int i=0; i<n; i++) { 145 double_array[i] = (double)base_array[i]; 146 } 147 for (int i=0; i<n; i++) { 148 res += (int) double_array[i]; 149 } 150 System.out.println("doubles " + res + " == " + the_int_res); 151 return res==the_int_res; 152 } 153 154 void check(String msg, boolean flag) { 155 if (!flag) { 156 System.out.println("ERROR in " + msg); 157 } 158 } 159 160 boolean execute() { 161 // print(); 162 boolean res = true; 163 res = res & with_chars(); check("chars",res); 164 res = res & with_shorts(); check("shorts",res); 165 res = res & with_bytes(); check("bytes",res); 166 res = res & with_ints(); check("ints",res); 167 res = res & with_longs(); check("longs",res); 168 res = res & with_floats(); check("floats",res); 169 res = res & with_doubles(); check("doubles",res); 170 171 return res; 172 } 173 174 175 public static void main (String s[]) { 176 boolean res = true; 177 ArrayTests at = new ArrayTests(); 178 res = res & at.execute(); 179 180 if (res) System.out.println("Array read/write testsOK (srm 10/22/96)"); 181 else throw new TestFailure("Error in read/write array tests!"); 182 } 183 184 }