@StubMethod public static ClassMirror getCallerClassMirror(int depth) { // Filter out any non-holographic frames int nativeDepth = 1; Class<?> klass = sun.reflect.Reflection.getCallerClass(nativeDepth); while (klass != null) { ClassLoader loader = klass.getClassLoader(); if (loader instanceof HologramClassLoader) { if (depth == 0) { HologramClassLoader hologramClassLoader = (HologramClassLoader) klass.getClassLoader(); String className = HologramClassGenerator.getOriginalBinaryClassName(klass.getName()); return hologramClassLoader.loadOriginalClassMirror(className); } depth--; } nativeDepth++; klass = sun.reflect.Reflection.getCallerClass(nativeDepth); } // Off the top of the holographic stack, so refer to the original stack. ThreadMirror currentThread = ThreadHolograph.currentThreadMirror(); List<FrameMirror> stack = currentThread.getStackTrace(); int frameIndex = stack.size() - 1 - depth; if (frameIndex < 0) { return null; } FrameMirror frame = stack.get(frameIndex); return frame.declaringClass(); }
@StubMethod public ObjectArrayMirror getStackTrace(ThreadMirror thread) { VirtualMachineMirror vm = getVM(); List<FrameMirror> trace = thread.getStackTrace(); int size = trace.size(); ClassMirror stackTraceElementClass = vm.findBootstrapClassMirror(StackTraceElement.class.getName()); ObjectArrayMirror result = (ObjectArrayMirror) stackTraceElementClass.newArray(size); for (int i = 0; i < size; i++) { result.set(i, HolographInternalUtils.stackTraceElementForFrameMirror(vm, trace.get(i))); } return result; }
@StubMethod public boolean isAlive(ThreadMirror thread) { // TODO-RS: This may need more precision in the API return !thread.getStackTrace().isEmpty(); }