* Added putfieldconst zero for risc architectures
[cacao.git] / tests / codepatching / test.java
1 public class test extends Thread {
2     static boolean doit = true;
3
4     public static void main(String[] argv) {
5         int threadcount = 1;
6
7         if (argv.length > 0) {
8             for (int i = 0; i < argv.length; i++) {
9                 if (argv[i].equals("--help")) {
10                     usage();
11
12                 } else if (argv[i].equals("skip")) {
13                     doit = false;
14
15                 } else {
16                     threadcount = Integer.valueOf(argv[i]).intValue();
17                 }
18             }
19         }
20
21         System.out.println("Running with " + threadcount + " threads.");
22
23         for (int i = 0; i < threadcount; i++) {
24             new test().start();
25         }
26     }
27
28     static void usage() {
29         System.out.println("test [number of threads] [skip]");
30         System.exit(1);
31     }
32
33     public test() {
34     }
35     
36     public void run() {
37         invokestatic();
38
39         getstatic();
40         putstatic();
41
42         getfield();
43         putfield();
44         putfieldconst();
45
46         newarray();
47         multianewarray();
48
49         invokespecial();
50
51         checkcast();
52         _instanceof();
53     }
54
55
56     final private static void invokestatic() {
57         System.out.print("invokestatic: ");
58         try {
59             if (doit)
60                 invokestatic.sub();
61             else
62                 System.out.println("OK");
63         } catch (Throwable t) {
64             System.out.println("FAILED: " + t);
65         }
66     }
67
68
69     public void getstatic() {
70         try {
71             p("getstatic (I): ");
72             if (doit)
73                 check(getstaticI.i, 123);
74             else
75                 ok();
76         } catch (Throwable t) {
77             failed(t);
78         }
79
80         try {
81             p("getstatic (J): ");
82             if (doit)
83                 check(getstaticJ.l, 1234567890123L);
84             else
85                 ok();
86         } catch (Throwable t) {
87             failed(t);
88         }
89
90         try {
91             p("getstatic (F): ");
92             if (doit)
93                 check(getstaticF.f, 123.456F);
94             else
95                 ok();
96         } catch (Throwable t) {
97             failed(t);
98         }
99
100         try {
101             p("getstatic (D): ");
102             if (doit)
103                 check(getstaticD.d, 789.012);
104             else
105                 ok();
106         } catch (Throwable t) {
107             failed(t);
108         }
109
110         try {
111             p("getstatic (L): ");
112             if (doit)
113                 check(getstaticL.o, null);
114             else
115                 ok();
116         } catch (Throwable t) {
117             failed(t);
118         }
119     }
120
121
122     public void putstatic() {
123         try {
124             p("putstatic (I): ");
125             if (doit) {
126                 int i = 123;
127                 putstaticI.i = i;
128                 check(putstaticI.i, i);
129             } else
130                 ok();
131         } catch (Throwable t) {
132             failed(t);
133         }
134
135         try {
136             p("putstatic (J): ");
137             if (doit) {
138                 long l = 1234567890123L;
139                 putstaticJ.l = l;
140                 check(putstaticJ.l, l);
141             } else
142                 ok();
143         } catch (Throwable t) {
144             failed(t);
145         }
146
147         try {
148             p("putstatic (F): ");
149             if (doit) {
150                 float f = 123.456F;
151                 putstaticF.f = f;
152                 check(putstaticF.f, f);
153             } else
154                 ok();
155         } catch (Throwable t) {
156             failed(t);
157         }
158
159         try {
160             p("putstatic (D): ");
161             if (doit) {
162                 double d = 789.012;
163                 putstaticD.d = d;
164                 check(putstaticD.d, d);
165             } else
166                 ok();
167         } catch (Throwable t) {
168             failed(t);
169         }
170
171
172         try {
173             p("putstatic (L): ");
174             if (doit) {
175                 Object o = null;
176                 putstaticL.o = o;
177                 check(putstaticL.o, o);
178             } else
179                 ok();
180         } catch (Throwable t) {
181             failed(t);
182         }
183     }
184
185     public void getfield() {
186         try {
187             p("getfield (I): ");
188             if (doit)
189                 check(new getfieldI().i, 123);
190             else
191                 ok();
192         } catch (Throwable t) {
193             failed(t);
194         }
195
196         try {
197             p("getfield (J): ");
198             if (doit)
199                 check(new getfieldJ().l, 1234567890123L);
200             else
201                 ok();
202         } catch (Throwable t) {
203             failed(t);
204         }
205
206         try {
207             p("getfield (F): ");
208             if (doit)
209                 check(new getfieldF().f, 123.456F);
210             else
211                 ok();
212         } catch (Throwable t) {
213             failed(t);
214         }
215
216         try {
217             p("getfield (D): ");
218             if (doit)
219                 check(new getfieldD().d, 789.012);
220             else
221                 ok();
222         } catch (Throwable t) {
223             failed(t);
224         }
225
226         try {
227             p("getfield (L): ");
228             if (doit)
229                 check(new getfieldL().o, null);
230             else
231                 ok();
232         } catch (Throwable t) {
233             failed(t);
234         }
235     }
236
237
238     public void putfield() {
239         try {
240             p("putfield (I): ");
241             if (doit) {
242                 putfieldI pfi = new putfieldI();
243                 int i = 123;
244                 pfi.i = i;
245                 check(pfi.i, i);
246             } else
247                 ok();
248         } catch (Throwable t) {
249             failed(t);
250         }
251
252         try {
253             p("putfield (J): ");
254             if (doit) {
255                 putfieldJ pfj = new putfieldJ();
256                 long l = 1234567890123L;
257                 pfj.l = l;
258                 check(pfj.l, l);
259             } else
260                 ok();
261         } catch (Throwable t) {
262             failed(t);
263         }
264
265         try {
266             p("putfield (F): ");
267             if (doit) {
268                 putfieldF pff = new putfieldF();
269                 float f = 123.456F;
270                 pff.f = f;
271                 check(pff.f, f);
272             } else
273                 ok();
274         } catch (Throwable t) {
275             failed(t);
276         }
277
278         try {
279             p("putfield (D): ");
280             if (doit) {
281                 putfieldD pfd = new putfieldD();
282                 double d = 789.012;
283                 pfd.d = d;
284                 check(pfd.d, d);
285             } else
286                 ok();
287         } catch (Throwable t) {
288             failed(t);
289         }
290
291         try {
292             p("putfield (L): ");
293             if (doit) {
294                 putfieldL pfl = new putfieldL();
295                 Object o = null;
296                 pfl.o = o;
297                 check(pfl.o, o);
298             } else
299                 ok();
300         } catch (Throwable t) {
301             failed(t);
302         }
303     }
304
305     public void putfieldconst() {
306         try {
307             p("putfieldconst (I,F): ");
308             if (doit) {
309                 putfieldconstIF pfcif = new putfieldconstIF();
310                 pfcif.i = 123;
311                 check(pfcif.i, 123);
312             } else
313                 ok();
314         } catch (Throwable t) {
315             failed(t);
316         }
317  
318         try {
319             p("putfieldconst zero (I,F): ");
320             if (doit) {
321                 putfieldconstIF pfcif = new putfieldconstIF();
322                 pfcif.i = 0;
323                 check(pfcif.i, 0);
324             } else
325                 ok();
326         } catch (Throwable t) {
327             failed(t);
328         }
329  
330         try {
331             p("putfieldconst (J,D,L): ");
332             if (doit) {
333                 putfieldconstJDL pfcjdl = new putfieldconstJDL();
334                 pfcjdl.l = 1234567890123L;
335                 check(pfcjdl.l, 1234567890123L);
336             } else
337                 ok();
338         } catch (Throwable t) {
339             failed(t);
340         }
341
342         try {
343             p("putfieldconst zero (J,D,L): ");
344             if (doit) {
345                 putfieldconstJDL pfcjdl = new putfieldconstJDL();
346                 pfcjdl.l = 0L;
347                 check(pfcjdl.l, 0L);
348             } else
349                 ok();
350         } catch (Throwable t) {
351             failed(t);
352         }
353     }
354
355     private void newarray() {
356         try {
357             p("newarray: ");
358             if (doit) {
359                 newarray[] na = new newarray[1];
360             }
361             ok();
362         } catch (Throwable t) {
363             failed(t);
364         }
365     }
366
367     private void multianewarray() {
368         try {
369             p("multianewarray: ");
370             if (doit) {
371                 multianewarray[][] ma = new multianewarray[1][1];
372             }
373             ok();
374         } catch (Throwable t) {
375             failed(t);
376         }
377     }
378
379     public void invokespecial() {
380         try {
381             p("invokespecial: ");
382             if (doit)
383                 new invokespecial();
384             else
385                 ok();
386         } catch (Throwable t) {
387             failed(t);
388         }
389     }
390
391     private void checkcast() {
392         Object o = new Object();
393
394         // class
395         try {
396             p("checkcast class: ");
397             if (doit) {
398                 checkcastC cc = (checkcastC) o;
399                 failed();
400             } else
401                 ok();
402         } catch (ClassCastException e) {
403             ok();
404         } catch (Throwable t) {
405             failed(t);
406         }
407
408         // interface
409         try {
410             p("checkcast interface: ");
411             if (doit) {
412                 checkcastI ci = (checkcastI) o;
413                 failed();
414             } else
415                 ok();
416         } catch (ClassCastException e) {
417             ok();
418         } catch (Throwable t) {
419             failed(t);
420         }
421
422
423         // array
424
425         Object[] oa = new Object[1];
426
427         try {
428             p("checkcast class array: ");
429             if (doit) {
430                 checkcastC[] cca = (checkcastC[]) oa;
431                 failed();
432             } else
433                 ok();
434         } catch (ClassCastException e) {
435             ok();
436         } catch (Throwable t) {
437             failed(t);
438         }
439     }
440
441     private void _instanceof() {
442         Object o = new Object();
443
444         try {
445             p("instanceof class: ");
446             if (doit)
447                 if (o instanceof instanceofC)
448                     failed();
449                 else
450                     ok();
451             else
452                 ok();
453         } catch (Throwable t) {
454             failed(t);
455         }
456
457         try {
458             p("instanceof interface: ");
459             if (doit)
460                 if (o instanceof instanceofI)
461                     failed();
462                 else
463                     ok();
464             else
465                 ok();
466         } catch (Throwable t) {
467             failed(t);
468         }
469
470
471         // array
472
473         Object[] oa = new Object[1];
474
475         try {
476             p("instanceof class array: ");
477             if (doit)
478                 if (oa instanceof instanceofC[])
479                     failed();
480                 else
481                     ok();
482             else
483                 ok();
484         } catch (Throwable t) {
485             failed(t);
486         }
487     }
488
489     private void ok() {
490         pln("OK");
491     }
492
493     private void failed() {
494         pln("FAILED");
495     }
496
497     private void failed(Throwable t) {
498         pln("FAILED: " + t);
499     }
500
501     public void check(int a, int b) {
502         if (a == b)
503             ok();
504         else
505             pln("FAILED: " + a + " != " + b);
506     }
507
508     public void check(long a, long b) {
509         if (a == b)
510             ok();
511         else
512             pln("FAILED: " + a + " != " + b);
513     }
514
515     public void check(float a, float b) {
516         if (a == b)
517             ok();
518         else
519             pln("FAILED: " + a + " != " + b);
520     }
521
522     public void check(double a, double b) {
523         if (a == b)
524             ok();
525         else
526             pln("FAILED: " + a + " != " + b);
527     }
528
529     public void check(Object a, Object b) {
530         if (a == b)
531             ok();
532         else
533             pln("FAILED: " + a + " != " + b);
534     }
535
536     private final void p(String s) {
537         System.out.print(s);
538     }
539
540     private final void pln(String s) {
541         System.out.println(s);
542     }
543 }