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 /**
20  * Provides a limited interface to the Dalvik VM stack. This class is mostly
21  * used for implementing security checks.
22  *
23  * @hide
24  */
25 public final class VMStack {
26     /**
27      * Returns the defining class loader of the caller's caller.
28      *
29      * @return the requested class loader, or {@code null} if this is the
30      *         bootstrap class loader.
31      */
getCallingClassLoader()32     native public static ClassLoader getCallingClassLoader();
33 
34     /**
35      * Returns the class of the caller's caller.
36      *
37      * @return the requested class, or {@code null}.
38      */
getStackClass1()39     public static Class<?> getStackClass1() {
40         return getStackClass2();
41     }
42 
43     /**
44      * Returns the class of the caller's caller's caller.
45      *
46      * @return the requested class, or {@code null}.
47      */
getStackClass2()48     native public static Class<?> getStackClass2();
49 
50     /**
51      * Returns the first ClassLoader on the call stack that isn't the
52      * bootstrap class loader.
53      */
getClosestUserClassLoader()54     public native static ClassLoader getClosestUserClassLoader();
55 
56     /**
57      * Retrieves the stack trace from the specified thread.
58      *
59      * @param t
60      *      thread of interest
61      * @return an array of stack trace elements, or null if the thread
62      *      doesn't have a stack trace (e.g. because it exited)
63      */
getThreadStackTrace(Thread t)64     native public static StackTraceElement[] getThreadStackTrace(Thread t);
65 
66     /**
67      * Retrieves a partial stack trace from the specified thread into
68      * the provided array.
69      *
70      * @param t
71      *      thread of interest
72      * @param stackTraceElements
73      *      preallocated array for use when only the top of stack is
74      *      desired. Unused elements will be filled with null values.
75      * @return the number of elements filled
76      */
fillStackTraceElements(Thread t, StackTraceElement[] stackTraceElements)77     native public static int fillStackTraceElements(Thread t,
78         StackTraceElement[] stackTraceElements);
79 }
80