Re: [Sablevm-developer] types of stack frames
Brought to you by:
egagnon
|
From: Chris P. <chr...@ma...> - 2004-04-02 03:16:50
|
Chris Pickett wrote:
> I wrote a simple function to count Java stack frames, but it gives me
> more frames than those that are pushed directly with (PREPARE_)INVOKE<X>
> (as calculated by a more indirect method). I assume it's because some
> Java frames are pushed without (PREPARE_)INVOKE<X>. I would really like
> to know if it's possible to count frames pushed only with
> (PREPARE_)INVOKE<X> by simply looking at the stack
It seems that I can do this if I don't count any frame that has a
non-"pushed by (PREPARE_)INVOKE<X>" frame below it. The code following
almost works, but appears to be off-by-one. If you can spot an obvious
error I'd be grateful, otherwise I'll just keep digging (into source and
specifications).
Cheers,
Chris
inline static size_t
_svmf_count_java_stack_frames (_svmt_JNIEnv *env)
{
_svmt_stack_frame *frame = env->stack.current_frame;
_svmt_method_info *method = frame->method;
jint count = 0;
while (method != &env->vm->stack_bottom_method)
{
jboolean found_java_frame = JNI_FALSE;
/* is the current frame internal? */
if (_svmf_is_set_flag (method->access_flags, SVM_ACC_INTERNAL)
== JNI_FALSE)
{
found_java_frame = JNI_TRUE;
}
/* pop stack frame */
frame = (_svmt_stack_frame *)
(((char *) frame) - frame->previous_offset);
method = frame->method;
/* if the previous frame was not internal and this one
is not internal, increment the count of
pushed-by-java frames
*/
if (_svmf_is_set_flag (method->access_flags, SVM_ACC_INTERNAL)
== JNI_FALSE &&
found_java_frame == JNI_TRUE)
{
count++;
}
}
return count;
}
|