blob: a879b464475536c258851f2ef53dd31fb02a309d [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
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 */
Shih-wei Liao9407c602011-09-16 10:36:43 -070016
Shih-wei Liao9407c602011-09-16 10:36:43 -070017public class StackWalk2 {
18 // use v1 for this
19
20 String str = new String(); // use v0 for str in <init>
21
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
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
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
51 native int refmap2(int x);
52
53 static {
54 System.loadLibrary("arttest");
55 }
56
57 public static void main(String[] args) {
58 StackWalk2 st = new StackWalk2();
59 st.f();
60 }
61}