Merged gcj-eclipse branch to trunk.
[official-gcc.git] / libjava / gnu / classpath / natVMStackWalker.cc
blob07ec48c030a3936704312899d1013eef66c1aede
1 // natVMStackWalker.cc
3 /* Copyright (C) 2006 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9 details. */
11 #include <config.h>
12 #include <platform.h>
14 #include <gcj/cni.h>
15 #include <jvm.h>
16 #include <java-stack.h>
17 #include <gnu/classpath/VMStackWalker.h>
18 #include <gnu/gcj/RawData.h>
19 #include <java/lang/ClassLoader.h>
21 JArray<jclass> *
22 gnu::classpath::VMStackWalker::getClassContext(void)
24 return _Jv_StackTrace::GetStackWalkerStack ();
27 jclass
28 gnu::classpath::VMStackWalker::getCallingClass(void)
30 return _Jv_StackTrace::GetStackWalkerCallingClass ();
33 jclass
34 gnu::classpath::VMStackWalker::getCallingClass(::gnu::gcj::RawData *pc)
36 void *f = _Unwind_FindEnclosingFunction (pc);
38 // FIXME: it might well be a good idea to cache pc values here in
39 // order to avoid repeated invocations of
40 // _Unwind_FindEnclosingFunction, which is quite expensive. On the
41 // other hand, which not simply write a caching version of
42 // _Unwind_FindEnclosingFunction itself? That would probably be
43 // worthwhile.
45 _Jv_StackTrace::UpdateNCodeMap ();
46 jclass klass = (jclass) _Jv_StackTrace::ncodeMap->get ((jobject) f);
48 // If the caller is a compiled frame and the caller of the caller
49 // is an interpreted frame then klass will be null and we need to
50 // unwind the stack.
51 if (klass == NULL)
52 klass = _Jv_StackTrace::GetStackWalkerCallingClass ();
54 return klass;
57 ::java::lang::ClassLoader *
58 gnu::classpath::VMStackWalker::getClassLoader(::java::lang::Class *c)
60 return c->getClassLoaderInternal ();
63 ::java::lang::ClassLoader *
64 gnu::classpath::VMStackWalker::getCallingClassLoader(void)
66 return
67 _Jv_StackTrace::GetStackWalkerCallingClass ()->getClassLoaderInternal ();
70 ::java::lang::ClassLoader *
71 gnu::classpath::VMStackWalker::getCallingClassLoader(::gnu::gcj::RawData *pc)
73 return getCallingClass (pc)->getClassLoaderInternal ();
76 ::java::lang::ClassLoader *
77 gnu::classpath::VMStackWalker::firstNonNullClassLoader(void)
79 return _Jv_StackTrace::GetStackWalkerFirstNonNullLoader ();