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 public class StackWalk2 {
18   // use v1 for this
19 
20   String str = new String();  // use v0 for str in <init>
21 
f()22   int f() {
23     g(1);  // use v0 for 1, v1 for this
24     g(2);  // use v0 for 2, v1 for this
25     strTest();  // use v1 for this
26     return 0;
27   }
28 
g(int num_calls)29   void g(int num_calls) throws RuntimeException {
30     if (num_calls == 1) {  // use v0 for 1, v3 for num_calls
31       System.logI("1st call");  // use v0 for PrintStream, v1 for "1st call"
32       refmap2(24);  // use v0 for 24, v2 for this
33     } else if (num_calls == 2) {  // use v0 for 2, v3 for num_calls
34       System.logI("2nd call");  // use v0 for PrintStream, v1 for "2nd call"
35       refmap2(25);  // use v0 for 24, v2 for this
36     }
37     throw new RuntimeException();  // use v0 for new RuntimeException
38   }
39 
strTest()40   void strTest() {
41     System.logI(str);  // use v1 for PrintStream, v2, v3 for str
42     str = null;  // use v1 for null, v3 for str
43     str = new String("ya");  // use v2 for "ya", v1 for new String
44     String s = str;  // use v0, v1, v3
45     System.logI(str);  // use v1 for PrintStream, v2, v3 for str
46     System.logI(s);  // use v1 for PrintStream, v0 for s
47     s = null;  // use v0
48     System.logI(s);  // use v1 for PrintStream, v0 for s
49   }
50 
refmap2(int x)51   native int refmap2(int x);
52 
53   static {
54     System.loadLibrary("arttest");
55   }
56 
main(String[] args)57   public static void main(String[] args) {
58     StackWalk2 st = new StackWalk2();
59     st.f();
60   }
61 }
62