1 /*
2  * Copyright (C) 2011 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 
17 // This test depends on the exact format of the DEX file. Since dx is deprecated,
18 // the classes.dex file is packaged as a test input. It was created with:
19 //
20 // $ javac -g -Xlint:-options -source 1.7 -target 1.7 -d classes src/Main.java
21 // $ dx --debug --dex --output=classes.dex classes
22 
23 public class Main {
Main()24   public Main() {
25   }
26 
$noinline$f()27   int $noinline$f() throws Exception {
28     $noinline$g(1);
29     $noinline$g(2);
30     return 0;
31   }
32 
$noinline$g(int num_calls)33   void $noinline$g(int num_calls) {
34     if (num_calls == 1) {
35       System.out.println("1st call");
36     } else if (num_calls == 2) {
37       System.out.println("2nd call");
38     }
39     System.out.println(shlemiel());
40   }
41 
shlemiel()42   String shlemiel() {
43     String s0 = new String("0");
44     String s1 = new String("1");
45     String s2 = new String("2");
46     String s3 = new String("3");
47     String s4 = new String("4");
48     String s5 = new String("5");
49     String s6 = new String("6");
50     String s7 = new String("7");
51     String s8 = new String("8");
52     String s9 = new String("9");
53     String s10 = new String("10");
54     String s11 = new String("11");
55     String s12 = new String("12");
56     String s13 = new String("13");
57     String s14 = new String("14");
58     String s15 = new String("15");
59     String s16 = new String("16");
60     String s17 = new String("17");
61     String s18 = new String("18");
62     String s19 = new String("19");
63     String s20 = new String("20");
64     String s = new String();
65     s += s0;
66     s += s1;
67     s += s2;
68     s += s3;
69     s += s4;
70     s += s5;
71     s += s6;
72     s += s7;
73     s += s8;
74     s += s9;
75     s += s10;
76     s += s11;
77     s += s12;
78     s += s13;
79     s += s14;
80     s += s15;
81     s += s16;
82     s += s17;
83     s += s18;
84     s += s19;
85     s += s20;
86 
87     s += s6;
88     s += s5;
89     s += s2;
90     s += s3;
91 
92     s10 = s + s10;
93     s10 += s20;
94 
95     s20 += s10;
96     s = s17 + s20;
97 
98     s4 = s18 = s19;
99     s += s4;
100     s += s18;
101     // Add a branch to workaround ART's large methods without branches heuristic.
102     if (testStackWalk(0) != 0) {
103       return s;
104     }
105     return s18;
106   }
107 
testStackWalk(int x)108   native int testStackWalk(int x);
109 
main(String[] args)110   public static void main(String[] args) throws Exception {
111     System.loadLibrary(args[0]);
112     Main st = new Main();
113     st.$noinline$f();
114   }
115 }
116