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 57 // against both the RI and ART and also to prevent front-end compiler changes from 58 // affecting output. 59 if (LAST_LINE_NUMBER == NO_LAST_LINE_NUMBER || LAST_LINE_NUMBER != cur_line) { 60 LAST_LINE_NUMBER = cur_line; 61 System.out.println("Single step: " + e + " @ line=" + cur_line); 62 } 63 } 64 resetTest()65 public static void resetTest() { 66 LAST_LINE_NUMBER = NO_LAST_LINE_NUMBER; 67 } 68 run()69 public static void run() throws Exception { 70 boolean[] values = new boolean[] { true, false }; 71 Trace.enableSingleStepTracing(Test997.class, 72 Test997.class.getDeclaredMethod( 73 "notifySingleStep", Thread.class, Executable.class, Long.TYPE), 74 Thread.currentThread()); 75 for (boolean arg : values) { 76 System.out.println("Stepping through doMultiPath(" + arg + ")"); 77 resetTest(); 78 doMultiPath(arg); 79 } 80 81 Trace.disableTracing(Thread.currentThread()); 82 } 83 } 84