blob: 1224e407b033f83372d69a9a159bc440fed97b27 [file] [log] [blame]
Mingyao Yang504a6902016-04-28 16:23:01 -07001/*
2 * Copyright (C) 2016 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
17public class Main implements Runnable {
18 static final int numberOfThreads = 2;
19 static final int totalOperations = 40000;
20 static boolean sFlag = false;
21 static volatile boolean done = false;
22 int threadIndex;
23
24 public static native void deoptimizeAll();
25 public static native void undeoptimizeAll();
26
27 Main(int index) {
28 threadIndex = index;
29 }
30
31 public static void main(String[] args) throws Exception {
32 System.loadLibrary(args[0]);
33
34 final Thread[] threads = new Thread[numberOfThreads];
35 for (int t = 0; t < threads.length; t++) {
36 threads[t] = new Thread(new Main(t));
37 threads[t].start();
38 }
39 for (Thread t : threads) {
40 t.join();
41 }
42 System.out.println("Finishing");
43 }
44
45 public String $noinline$run0() {
46 // Prevent inlining.
47 if (sFlag) {
48 throw new Error();
49 }
50 char[] arr = {'a', 'b', 'c'};
Hiroshi Yamauchi695e2c42016-05-19 00:15:12 +000051 return new String(arr, 0, arr.length);
Mingyao Yang504a6902016-04-28 16:23:01 -070052 }
53
54 public void run() {
55 if (threadIndex == 0) {
56 // This thread keeps doing deoptimization of all threads.
57 // Hopefully that will trigger one deoptimization when returning from
58 // StringFactory.newEmptyString() in one of the other threads.
59 for (int i = 0; i < totalOperations; ++i) {
60 if (i % 50 == 0) {
61 deoptimizeAll();
62 }
63 if (i % 50 == 25) {
64 undeoptimizeAll();
65 }
66 }
67 done = true;
68 } else {
69 // This thread keeps doing new String() from a char array.
70 while (!done) {
Hiroshi Yamauchi695e2c42016-05-19 00:15:12 +000071 $noinline$run0();
Mingyao Yang504a6902016-04-28 16:23:01 -070072 }
73 }
74 }
75}