• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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 package art;
18 
19 import java.util.Arrays;
20 import java.lang.reflect.Executable;
21 import java.lang.reflect.Method;
22 
23 public class Test997 {
24   static final int NO_LAST_LINE_NUMBER = -1;
25   static int LAST_LINE_NUMBER = NO_LAST_LINE_NUMBER;
26   static Method DO_MULTIPATH_METHOD;
27 
28   static {
29     try {
30       DO_MULTIPATH_METHOD = Test997.class.getDeclaredMethod("doMultiPath", Boolean.TYPE);
31     } catch (Exception e) {
32       throw new Error("could not find method doMultiPath", e);
33     }
34   }
35 
36   // Function that acts simply to ensure there are multiple lines.
doNothing()37   public static void doNothing() {}
38 
39   // Method with multiple paths we can break on.
doMultiPath(boolean bit)40   public static void doMultiPath(boolean bit) {
41     doNothing();
42     if (bit) {
43       doNothing();
44     } else {
45       doNothing();
46     }
47     doNothing();
48   }
49 
notifySingleStep(Thread thr, Executable e, long loc)50   public static void notifySingleStep(Thread thr, Executable e, long loc) {
51     if (!e.equals(DO_MULTIPATH_METHOD)) {
52       // Only report steps in doMultiPath
53       return;
54     }
55     int cur_line = Breakpoint.locationToLine(e, loc);
56     // Only report anything when the line number changes. This is so we can run this test against
57     // both the RI and ART and also to prevent front-end compiler changes from affecting output.
58     if (LAST_LINE_NUMBER == NO_LAST_LINE_NUMBER || LAST_LINE_NUMBER != cur_line) {
59       LAST_LINE_NUMBER = cur_line;
60       System.out.println("Single step: " + e + " @ line=" + cur_line);
61     }
62   }
63 
resetTest()64   public static void resetTest() {
65     LAST_LINE_NUMBER = NO_LAST_LINE_NUMBER;
66   }
67 
run()68   public static void run() throws Exception {
69     boolean[] values = new boolean[] { true, false };
70     Trace.enableSingleStepTracing(Test997.class,
71         Test997.class.getDeclaredMethod(
72             "notifySingleStep", Thread.class, Executable.class, Long.TYPE),
73         Thread.currentThread());
74     for (boolean arg : values) {
75       System.out.println("Stepping through doMultiPath(" + arg + ")");
76       resetTest();
77       doMultiPath(arg);
78     }
79 
80     Trace.disableTracing(Thread.currentThread());
81   }
82 }
83