1 /* 2 * Copyright (C) 2019 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 foobar; 18 import art.Breakpoint; 19 import art.StackTrace; 20 21 public class NewClass { sayHi()22 static void sayHi() throws Exception { 23 System.out.println("Hello from NewClass sayHi function"); 24 // Doing this would be nice but it would make compiling the test more tricky. Just use 25 // reflection and check the classloader is the same. 26 // TestClass.sayBye(); 27 StackTrace.StackFrameData[] stack = StackTrace.GetStackTrace(Thread.currentThread()); 28 StackTrace.StackFrameData caller = null; 29 System.out.println("Nearby stack:"); 30 for (StackTrace.StackFrameData sfd : stack) { 31 String caller_name = sfd.method.getDeclaringClass().getName(); 32 if (caller_name.startsWith("art.") || caller_name.startsWith("foobar.")) { 33 System.out.println("\t" + sfd.method + "(line: " + 34 Breakpoint.locationToLine(sfd.method, sfd.current_location) + ")"); 35 caller = sfd; 36 } else { 37 break; 38 } 39 } 40 if (NewClass.class.getClassLoader() != caller.method.getDeclaringClass().getClassLoader()) { 41 System.out.println("Different classloader for TestClass and my class."); 42 } 43 } 44 }