VMStack.java revision 4fefecee9d4a5d2a4510f516b4015607b19e8d09
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
17package 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 * @deprecated this is an internal Dalvik class that is not appropriate for
24 *      general use. It will be removed from the public API in a future release.
25 */
26public final class VMStack {
27    /**
28     * Returns the defining class loader of the caller's caller.
29     *
30     * @return the requested class loader, or {@code null} if this is the
31     *         bootstrap class loader.
32     */
33    native public static ClassLoader getCallingClassLoader();
34
35    /**
36     * Returns the defining class loader of the caller's caller's caller.
37     *
38     * @return the requested class loader, or {@code null} if this is the
39     *         bootstrap class loader.
40     */
41    native public static ClassLoader getCallingClassLoader2();
42
43    /**
44     * Returns the class of the caller's caller's caller.
45     *
46     * @hide
47     * @return the requested class, or {@code null}.
48     */
49    native public static Class<?> getStackClass2();
50
51    /**
52     * Creates an array of classes from the methods at the top of the stack.
53     * We continue until we reach the bottom of the stack or exceed the
54     * specified maximum depth.  If stopAtPrivileged is set, the last
55     * element of the array will be the caller of the most-recent privileged
56     * method.
57     * <p>
58     * The topmost stack frame (this method) and the one above that (the
59     * caller) are excluded from the array.  Frames with java.lang.reflect
60     * classes are skipped over.
61     * <p>
62     * The classes in the array are the defining classes of the methods.
63     * <p>
64     * This is expected to be identical to Harmony's VMStack.getClasses.
65     *
66     * @param maxDepth
67     *      maximum number of classes to return, or -1 for all
68     * @param stopAtPrivileged
69     *      stop when a privileged frame is reached
70     * @return an array with classes for the most-recent methods on the stack
71     */
72    native public static Class<?>[] getClasses(int maxDepth,
73        boolean stopAtPrivileged);
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    native public static StackTraceElement[] getThreadStackTrace(Thread t);
84}
85
86