J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 1996-2005 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 21 | * have any questions. |
| 22 | */ |
| 23 | /* |
| 24 | A simple Java class definition that helps self-test the runtime |
| 25 | interpreter. Used for getfield/putfield, invoke* opcodes and |
| 26 | their _quick variants. |
| 27 | |
| 28 | See src/share/java/runtime/selftest.c for details of the test |
| 29 | environment. |
| 30 | */ |
| 31 | |
| 32 | /* Used to be sun/misc/SelfTest.java */ |
| 33 | |
| 34 | interface UseAllBytecodesInterface |
| 35 | { |
| 36 | public void test_an_interface(int p1); |
| 37 | } |
| 38 | |
| 39 | public class UseAllBytecodes implements UseAllBytecodesInterface |
| 40 | { |
| 41 | public int i1, i2; |
| 42 | public float f1, f2; |
| 43 | public double d1, d2; |
| 44 | public long l1, l2; |
| 45 | |
| 46 | public static int si1, si2; |
| 47 | public static float sf1, sf2; |
| 48 | public static double sd1, sd2; |
| 49 | public static long sl1, sl2; |
| 50 | |
| 51 | public UseAllBytecodesInterface interfaceObject; |
| 52 | |
| 53 | public int multi[][][]; |
| 54 | |
| 55 | public UseAllBytecodes() |
| 56 | { |
| 57 | /* This constructor is not intended to ever be run. It is here |
| 58 | to force CONSTANT_Methodref constants into the CP */ |
| 59 | set_i1(11); |
| 60 | set_i2(22); |
| 61 | set_f1(1.1f); |
| 62 | set_f2(2.2f); |
| 63 | set_d1(1.0); |
| 64 | set_d2(2.0); |
| 65 | set_l1(3); |
| 66 | set_l2(4); |
| 67 | |
| 68 | set_si1(33); |
| 69 | set_si2(44); |
| 70 | set_sf1(3.3f); |
| 71 | set_sf2(4.4f); |
| 72 | set_sd1(3.0); |
| 73 | set_sd2(4.0); |
| 74 | set_sl1(5); |
| 75 | set_sl2(6); |
| 76 | |
| 77 | test_areturn(); |
| 78 | test_athrow1(); |
| 79 | test_athrow2(); |
| 80 | test_athrow3(); |
| 81 | test_athrow4(); |
| 82 | |
| 83 | /* This puts a CONSTANT_InterfaceMethodref into the CP */ |
| 84 | interfaceObject.test_an_interface(1234); |
| 85 | |
| 86 | /* This creates an array and puts it into the CP */ |
| 87 | multi = new int[2][3][4]; |
| 88 | } |
| 89 | |
| 90 | public UseAllBytecodes(int p1) |
| 91 | { |
| 92 | i1 = p1; |
| 93 | i2 = 12345678; /* This puts a CONSTANT_Integer into the CP */ |
| 94 | d1 = (double) p1; |
| 95 | d2 = 1.2e234; /* This puts a CONSTANT_Double into the CP */ |
| 96 | } |
| 97 | |
| 98 | public UseAllBytecodes(int p1, int p2) |
| 99 | { |
| 100 | i1 = p1; |
| 101 | i2 = p2; |
| 102 | } |
| 103 | |
| 104 | /* These methods should return something other than their |
| 105 | arguments, so the self test can easily determine that |
| 106 | the correct value was returned. */ |
| 107 | public int set_i1(int p1) |
| 108 | { |
| 109 | i1 = p1; |
| 110 | return i1 + 1; |
| 111 | } |
| 112 | |
| 113 | public int set_i2(int p2) |
| 114 | { |
| 115 | i2 = p2; |
| 116 | return i2 + 1; |
| 117 | } |
| 118 | |
| 119 | public float set_f1(float p1) |
| 120 | { |
| 121 | f1 = p1; |
| 122 | return f1 + 1.0e34f; |
| 123 | } |
| 124 | |
| 125 | public float set_f2(float p2) |
| 126 | { |
| 127 | f2 = p2; |
| 128 | return f2 + 1.0e34f; |
| 129 | } |
| 130 | |
| 131 | public double set_d1(double p1) |
| 132 | { |
| 133 | d1 = p1; |
| 134 | return d1 + 1.0e234; |
| 135 | } |
| 136 | |
| 137 | public double set_d2(double p2) |
| 138 | { |
| 139 | d2 = p2; |
| 140 | return d2 + 1.0e234; |
| 141 | } |
| 142 | |
| 143 | public long set_l1(long p1) |
| 144 | { |
| 145 | l1 = p1; |
| 146 | return l1 + 1; |
| 147 | } |
| 148 | |
| 149 | public long set_l2(long p2) |
| 150 | { |
| 151 | l2 = p2; |
| 152 | return l2 + 1; |
| 153 | } |
| 154 | |
| 155 | public static void set_si1(int p1) |
| 156 | { |
| 157 | si1 = p1; |
| 158 | } |
| 159 | |
| 160 | public static void set_si2(int p2) |
| 161 | { |
| 162 | si2 = p2; |
| 163 | } |
| 164 | |
| 165 | public static void set_sf1(float p1) |
| 166 | { |
| 167 | sf1 = p1; |
| 168 | } |
| 169 | |
| 170 | public static void set_sf2(float p2) |
| 171 | { |
| 172 | sf2 = p2; |
| 173 | } |
| 174 | |
| 175 | public static void set_sd1(double p1) |
| 176 | { |
| 177 | sd1 = p1; |
| 178 | } |
| 179 | |
| 180 | public static void set_sd2(double p2) |
| 181 | { |
| 182 | sd2 = p2; |
| 183 | } |
| 184 | |
| 185 | public static void set_sl1(long p1) |
| 186 | { |
| 187 | sl1 = p1; |
| 188 | } |
| 189 | |
| 190 | public static void set_sl2(long p2) |
| 191 | { |
| 192 | sl2 = p2; |
| 193 | } |
| 194 | |
| 195 | public UseAllBytecodes test_areturn() |
| 196 | { |
| 197 | return this; |
| 198 | } |
| 199 | |
| 200 | /* This method does the same thing as set_i1. |
| 201 | It is here to test the invokeinterface opcode. */ |
| 202 | public void test_an_interface(int p1) |
| 203 | { |
| 204 | i1 = p1; |
| 205 | } |
| 206 | |
| 207 | /* The following 10 methods test various permutations of |
| 208 | try-and-catch. */ |
| 209 | public static void test_athrow1() throws NullPointerException |
| 210 | { |
| 211 | try |
| 212 | { |
| 213 | si1 = -1; |
| 214 | throw new NullPointerException(); |
| 215 | } |
| 216 | catch (Exception e) |
| 217 | { |
| 218 | si1 = 1; |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | public static void test_athrow2() |
| 223 | { |
| 224 | int i = 1; |
| 225 | try |
| 226 | { |
| 227 | si1 = -1; |
| 228 | test_athrow1(); |
| 229 | } |
| 230 | catch (Exception e) |
| 231 | { |
| 232 | // This should *not* catch the exception; |
| 233 | // should be caught in test_athrow1. |
| 234 | si1 = i + 1; |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | public static void test_athrow3() |
| 239 | { |
| 240 | int i = 1; |
| 241 | try |
| 242 | { |
| 243 | // Ultimately throws NullPointerException |
| 244 | si1 = -1; |
| 245 | si2 = -1; |
| 246 | test_athrow5(); |
| 247 | } |
| 248 | catch (NullPointerException np) |
| 249 | { |
| 250 | si1 = i + 1; |
| 251 | } |
| 252 | catch (NoSuchMethodException e) |
| 253 | { |
| 254 | si2 = i + 1; |
| 255 | } |
| 256 | si1++; // total is 3 |
| 257 | } |
| 258 | |
| 259 | public static void test_athrow4() |
| 260 | { |
| 261 | int i = 2; |
| 262 | try |
| 263 | { |
| 264 | // Ultimately throws NoSuchMethodException |
| 265 | si1 = -1; |
| 266 | si2 = -1; |
| 267 | test_athrow7(); |
| 268 | } |
| 269 | catch (NullPointerException e) |
| 270 | { |
| 271 | si1 = i + 1; |
| 272 | } |
| 273 | catch (NoSuchMethodException nsm) |
| 274 | { |
| 275 | si2 = i + 1; |
| 276 | } |
| 277 | si2++; // total is 4 |
| 278 | } |
| 279 | |
| 280 | public static void test_throw_nosuchmethod() throws NoSuchMethodException |
| 281 | { |
| 282 | throw new NoSuchMethodException(); |
| 283 | } |
| 284 | |
| 285 | public static void test_throw_nullpointer() throws NullPointerException |
| 286 | { |
| 287 | throw new NullPointerException(); |
| 288 | } |
| 289 | |
| 290 | public static void test_athrow5() throws NullPointerException, NoSuchMethodException |
| 291 | { |
| 292 | test_athrow6(); |
| 293 | } |
| 294 | |
| 295 | public static void test_athrow6() throws NullPointerException, NoSuchMethodException |
| 296 | { |
| 297 | test_throw_nullpointer(); |
| 298 | } |
| 299 | |
| 300 | public static void test_athrow7() throws NullPointerException, NoSuchMethodException |
| 301 | { |
| 302 | test_athrow8(); |
| 303 | } |
| 304 | |
| 305 | public static void test_athrow8() throws NullPointerException, NoSuchMethodException |
| 306 | { |
| 307 | test_throw_nosuchmethod(); |
| 308 | } |
| 309 | } |