1 /* 2 * Copyright (C) 2007 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 dalvik.system; 18 19 import dalvik.annotation.compat.UnsupportedAppUsage; 20 import dalvik.annotation.optimization.FastNative; 21 22 /** 23 * Provides a limited interface to the Dalvik VM stack. This class is mostly 24 * used for implementing security checks. 25 * 26 * @hide 27 */ 28 @libcore.api.CorePlatformApi 29 public final class VMStack { 30 VMStack()31 private VMStack() { 32 } 33 34 /** 35 * Returns the defining class loader of the caller's caller. 36 * 37 * @return the requested class loader, or {@code null} if this is the 38 * bootstrap class loader. 39 * @deprecated Use {@code ClassLoader.getClassLoader(sun.reflect.Reflection.getCallerClass())}. 40 * Note that that can return {@link BootClassLoader} on Android where the RI 41 * would have returned null. 42 */ 43 @UnsupportedAppUsage 44 @FastNative 45 @Deprecated getCallingClassLoader()46 native public static ClassLoader getCallingClassLoader(); 47 48 /** 49 * Returns the class of the caller's caller. 50 * 51 * @return the requested class, or {@code null}. 52 * @deprecated Use {@link sun.reflect.Reflection#getCallerClass()}. 53 */ 54 @Deprecated getStackClass1()55 public static Class<?> getStackClass1() { 56 return getStackClass2(); 57 } 58 59 /** 60 * Returns the class of the caller's caller's caller. 61 * 62 * @return the requested class, or {@code null}. 63 */ 64 @UnsupportedAppUsage 65 @FastNative getStackClass2()66 native public static Class<?> getStackClass2(); 67 68 /** 69 * Returns the first ClassLoader on the call stack that isn't the 70 * bootstrap class loader. 71 */ 72 @FastNative getClosestUserClassLoader()73 public native static ClassLoader getClosestUserClassLoader(); 74 75 /** 76 * Retrieves the stack trace from the specified thread. 77 * 78 * @param t 79 * thread of interest 80 * @return an array of stack trace elements, or null if the thread 81 * doesn't have a stack trace (e.g. because it exited) 82 */ 83 @UnsupportedAppUsage 84 @FastNative getThreadStackTrace(Thread t)85 native public static StackTraceElement[] getThreadStackTrace(Thread t); 86 87 /** 88 * Retrieves an annotated stack trace from the specified thread. 89 * 90 * @param t 91 * thread of interest 92 * @return an array of annotated stack frames, or null if the thread 93 * doesn't have a stack trace (e.g. because it exited) 94 */ 95 @libcore.api.CorePlatformApi 96 @FastNative 97 native public static AnnotatedStackTraceElement[] getAnnotatedThreadStackTrace(Thread t)98 getAnnotatedThreadStackTrace(Thread t); 99 100 /** 101 * Retrieves a partial stack trace from the specified thread into 102 * the provided array. 103 * 104 * @param t 105 * thread of interest 106 * @param stackTraceElements 107 * preallocated array for use when only the top of stack is 108 * desired. Unused elements will be filled with null values. 109 * @return the number of elements filled 110 */ 111 @UnsupportedAppUsage 112 @FastNative fillStackTraceElements(Thread t, StackTraceElement[] stackTraceElements)113 native public static int fillStackTraceElements(Thread t, 114 StackTraceElement[] stackTraceElements); 115 } 116