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