blob: 1f1dee33dd026c77443cbfc931da624902105a66 [file] [log] [blame]
jeffhao5d1ac922011-09-29 17:41:15 -07001/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import java.util.concurrent.*;
18
19/**
20 * Test for Jit regressions.
21 */
22public class Main {
23 public static void main(String args[]) throws Exception {
24 b2296099Test();
25 b2302318Test();
26 b2487514Test();
27 }
28
29 static void b2296099Test() throws Exception {
30 int x = -1190771042;
31 int dist = 360530809;
32 int xl = -1190771042;
33 int distl = 360530809;
34
35 for (int i = 0; i < 100000; i++) {
36 int b = rotateLeft(x, dist);
37 if (b != 1030884493)
38 throw new RuntimeException("Unexpected value: " + b
39 + " after " + i + " iterations");
40 }
41 for (int i = 0; i < 100000; i++) {
42 long bl = rotateLeft(xl, distl);
43 if (bl != 1030884493)
44 throw new RuntimeException("Unexpected value: " + bl
45 + " after " + i + " iterations");
46 }
47 System.out.println("b2296099 passes");
48 }
49
50 static int rotateLeft(int i, int distance) {
51 return ((i << distance) | (i >>> (-distance)));
52 }
53
54 static void b2302318Test() {
55 System.gc();
56
57 SpinThread slow = new SpinThread(Thread.MIN_PRIORITY);
58 SpinThread fast1 = new SpinThread(Thread.NORM_PRIORITY);
59 SpinThread fast2 = new SpinThread(Thread.MAX_PRIORITY);
60
61 slow.setDaemon(true);
62 fast1.setDaemon(true);
63 fast2.setDaemon(true);
64
65 fast2.start();
66 slow.start();
67 fast1.start();
68 try {
69 Thread.sleep(3000);
70 } catch (InterruptedException ie) {/*ignore */}
71 System.gc();
72
73 System.out.println("b2302318 passes");
74 }
75
76 static void b2487514Test() {
77 PriorityBlockingQueue q = new PriorityBlockingQueue(10);
78 int catchCount = 0;
79
80 q.offer(new Integer(0));
81 /*
82 * Warm up the code cache to have toArray() compiled. The key here is
83 * to pass a compatible type so that there are no exceptions when
84 * executing the method body (ie the APUT_OBJECT bytecode).
85 */
86 for (int i = 0; i < 1000; i++) {
87 Integer[] ints = (Integer[]) q.toArray(new Integer[5]);
88 }
89
90 /* Now pass an incompatible type which is guaranteed to throw */
91 for (int i = 0; i < 1000; i++) {
92 try {
93 Object[] obj = q.toArray(new String[5]);
94 }
95 catch (ArrayStoreException success) {
96 catchCount++;
97 }
98 }
99
100 if (catchCount == 1000) {
101 System.out.println("b2487514 passes");
102 }
103 else {
104 System.out.println("b2487514 fails: catchCount is " + catchCount +
105 " (expecting 1000)");
106 }
107 }
108}
109
110class SpinThread extends Thread {
111 int mPriority;
112
113 SpinThread(int prio) {
114 super("Spin prio=" + prio);
115 mPriority = prio;
116 }
117
118 public void run() {
119 setPriority(mPriority);
120 while (true) {}
121 }
122}