/source_aosp/android29/VMStack.java

https://github.com/androidmalin/AMSHook · Java · 115 lines · 32 code · 11 blank · 72 comment · 0 complexity · 7b19fa21b10ebb58a0276addb2fa83e1 MD5 · raw file

  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. package dalvik.system;
  17. import dalvik.annotation.compat.UnsupportedAppUsage;
  18. import dalvik.annotation.optimization.FastNative;
  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. @libcore.api.CorePlatformApi
  26. public final class VMStack {
  27. private VMStack() {
  28. }
  29. /**
  30. * Returns the defining class loader of the caller's caller.
  31. *
  32. * @return the requested class loader, or {@code null} if this is the
  33. * bootstrap class loader.
  34. * @deprecated Use {@code ClassLoader.getClassLoader(sun.reflect.Reflection.getCallerClass())}.
  35. * Note that that can return {@link BootClassLoader} on Android where the RI
  36. * would have returned null.
  37. */
  38. @UnsupportedAppUsage
  39. @FastNative
  40. @Deprecated
  41. native public static ClassLoader getCallingClassLoader();
  42. /**
  43. * Returns the class of the caller's caller.
  44. *
  45. * @return the requested class, or {@code null}.
  46. * @deprecated Use {@link sun.reflect.Reflection#getCallerClass()}.
  47. */
  48. @Deprecated
  49. public static Class<?> getStackClass1() {
  50. return getStackClass2();
  51. }
  52. /**
  53. * Returns the class of the caller's caller's caller.
  54. *
  55. * @return the requested class, or {@code null}.
  56. */
  57. @UnsupportedAppUsage
  58. @FastNative
  59. native public static Class<?> getStackClass2();
  60. /**
  61. * Returns the first ClassLoader on the call stack that isn't the
  62. * bootstrap class loader.
  63. */
  64. @FastNative
  65. public native static ClassLoader getClosestUserClassLoader();
  66. /**
  67. * Retrieves the stack trace from the specified thread.
  68. *
  69. * @param t
  70. * thread of interest
  71. * @return an array of stack trace elements, or null if the thread
  72. * doesn't have a stack trace (e.g. because it exited)
  73. */
  74. @UnsupportedAppUsage
  75. @FastNative
  76. native public static StackTraceElement[] getThreadStackTrace(Thread t);
  77. /**
  78. * Retrieves an annotated stack trace from the specified thread.
  79. *
  80. * @param t
  81. * thread of interest
  82. * @return an array of annotated stack frames, or null if the thread
  83. * doesn't have a stack trace (e.g. because it exited)
  84. */
  85. @libcore.api.CorePlatformApi
  86. @FastNative
  87. native public static AnnotatedStackTraceElement[]
  88. getAnnotatedThreadStackTrace(Thread t);
  89. /**
  90. * Retrieves a partial stack trace from the specified thread into
  91. * the provided array.
  92. *
  93. * @param t
  94. * thread of interest
  95. * @param stackTraceElements
  96. * preallocated array for use when only the top of stack is
  97. * desired. Unused elements will be filled with null values.
  98. * @return the number of elements filled
  99. */
  100. @UnsupportedAppUsage
  101. @FastNative
  102. native public static int fillStackTraceElements(Thread t,
  103. StackTraceElement[] stackTraceElements);
  104. }