Home | History | Annotate | Download | only in system
      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      */
     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      */
     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      */
     48     native public static Class<?> getStackClass2();
     49 
     50     /**
     51      * Returns the first ClassLoader on the call stack that isn't either of
     52      * the passed-in ClassLoaders.
     53      */
     54     public native static ClassLoader getClosestUserClassLoader(ClassLoader bootstrap,
     55                                                                ClassLoader system);
     56 
     57     /**
     58      * Retrieves the stack trace from the specified thread.
     59      *
     60      * @param t
     61      *      thread of interest
     62      * @return an array of stack trace elements, or null if the thread
     63      *      doesn't have a stack trace (e.g. because it exited)
     64      */
     65     native public static StackTraceElement[] getThreadStackTrace(Thread t);
     66 
     67     /**
     68      * Retrieves a partial stack trace from the specified thread into
     69      * the provided array.
     70      *
     71      * @param t
     72      *      thread of interest
     73      * @param stackTraceElements
     74      *      preallocated array for use when only the top of stack is
     75      *      desired. Unused elements will be filled with null values.
     76      * @return the number of elements filled
     77      */
     78     native public static int fillStackTraceElements(Thread t,
     79         StackTraceElement[] stackTraceElements);
     80 }
     81