classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Implementation details of VMStackWalker


From: Andrew Haley
Subject: Re: Implementation details of VMStackWalker
Date: Fri, 22 Jul 2005 18:01:05 +0100

Ingo Prötel writes:

 > I just implemented VMStackWalker for our VM and have some questions.
 > 
 > The reference implementation of 'getCallingClass()' and
 > 'getCallingClassLoader()' just look at the third entry in the class
 > context. Would it not be better to return the first class that is not
 > assignable to the class in context[0] ? That way we could cope with
 > classes that first call some private or protected classes an then ends
 > up calling the stack walker. 

In gcj, we have a method called GetCallingClass(Class c).  It searches
firstly for a method declared in class c, then for a method not
declared in c.  We have found, after a certain amount of trouble, that
this is the right way to do things; it means that an arbitrary number
of stack frames can be between the direct caller of GetCallingClass
and the user code, and it also means that you don't have to check for
assignability, but for an exact match.

For example, you may have

class Foo
{
bar (Object O)
{
   return baz(O);
}

baz (Object O)
{
  ... GetCallingClass (Foo) ...
}
}

... and you will get class of the caller of bar, not Foo.class.

We use it like this:

java::lang::ClassLoader *
java::io::ObjectInputStream::currentLoader ()
{
  jclass caller = _Jv_StackTrace::GetCallingClass (&ObjectInputStream::class$);
  if (caller)
    return caller->getClassLoaderInternal();
  return NULL;
}

Andrew.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]