Package dalvik.system

Class VMStack

java.lang.Object
dalvik.system.VMStack

public final class VMStack
extends Object
Provides a limited interface to the Dalvik VM stack. This class is mostly used for implementing security checks.
  • Constructor Details

    • VMStack

      public VMStack()
  • Method Details

    • getCallingClassLoader

      public static ClassLoader getCallingClassLoader()
      Returns the defining class loader of the caller's caller.
      Returns:
      the requested class loader, or null if this is the bootstrap class loader.
    • getStackClass2

      public static Class<?> getStackClass2()
      Returns the class of the caller's caller's caller.
      Returns:
      the requested class, or null.
    • getClasses

      public static Class<?>[] getClasses​(int maxDepth)
      Creates an array of classes from the methods at the top of the stack. We continue until we reach the bottom of the stack or exceed the specified maximum depth.

      The topmost stack frame (this method) and the one above that (the caller) are excluded from the array. Frames with java.lang.reflect classes are skipped over.

      The classes in the array are the defining classes of the methods.

      This is similar to Harmony's VMStack.getClasses, except that this implementation doesn't have a concept of "privileged" frames.

      Parameters:
      maxDepth - maximum number of classes to return, or -1 for all
      Returns:
      an array with classes for the most-recent methods on the stack
    • getClosestUserClassLoader

      public static ClassLoader getClosestUserClassLoader​(ClassLoader bootstrap, ClassLoader system)
      Returns the first ClassLoader on the call stack that isn't either of the passed-in ClassLoaders.
    • getThreadStackTrace

      public static StackTraceElement[] getThreadStackTrace​(Thread t)
      Retrieves the stack trace from the specified thread.
      Parameters:
      t - thread of interest
      Returns:
      an array of stack trace elements, or null if the thread doesn't have a stack trace (e.g. because it exited)
    • fillStackTraceElements

      public static int fillStackTraceElements​(Thread t, StackTraceElement[] stackTraceElements)
      Retrieves a partial stack trace from the specified thread into the provided array.
      Parameters:
      t - thread of interest
      stackTraceElements - preallocated array for use when only the top of stack is desired. Unused elements will be filled with null values.
      Returns:
      the number of elements filled