-// natVMThrowable.cc - native helper methods for Throwable
+// natVMThrowable.cc - Native part of VMThrowable class.
-/* Copyright (C) 2000, 2002 Free Software Foundation, Inc
+/* Copyright (C) 2003, 2006 Free Software Foundation
This file is part of libgcj.
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
-/**
- * @author Andrew Haley <aph@cygnus.com>
- * @author Mark Wielaard <mark@klomp.org>
- *
- * Native helper methods for VM specific Throwable support.
- */
-
#include <config.h>
-#include <string.h>
+#include <stdlib.h>
-#include <jvm.h>
#include <gcj/cni.h>
-#include <gnu/gcj/RawData.h>
-#include <java/lang/Object.h>
-#include <java-threads.h>
+#include <jvm.h>
+#include <java-stack.h>
+
#include <java/lang/Throwable.h>
#include <java/lang/VMThrowable.h>
-#include <sys/types.h>
-
-#include <stdlib.h>
-
-#include <unistd.h>
-
-#ifdef HAVE_EXECINFO_H
-#include <execinfo.h>
-#endif
-
-/* FIXME: size of the stack trace is limited to 128 elements. It's
- undoubtedly sensible to limit the stack trace, but 128 is rather
- arbitrary. It may be better to configure this. */
+using namespace gnu::gcj;
java::lang::VMThrowable *
-java::lang::VMThrowable::fillInStackTrace (java::lang::Throwable* t)
+java::lang::VMThrowable::fillInStackTrace (java::lang::Throwable *)
{
- if (! trace_enabled)
+ using namespace java::lang;
+
+ // Don't trace stack during initialization of the runtime.
+ if (! gcj::runtimeInitialized)
return NULL;
-#if defined (HAVE_BACKTRACE)
- VMThrowable* state = new VMThrowable;
- void *p[128];
- // We subtract 1 from the number of elements because we don't want
- // to include the calls to fillInStackTrace in the trace.
- int n = backtrace (p, 128) - 1;
-
- void **addrs;
- if (n > 0)
- {
- state->length = n;
- addrs = (void **) _Jv_Malloc (n * sizeof p[0]);
- while (n--)
- addrs[n] = p[n];
- }
- else
- addrs = NULL;
+ _Jv_StackTrace *trace = _Jv_StackTrace::GetStackTrace ();
+ VMThrowable *vmthrowable = new VMThrowable ();
+ vmthrowable->data = (RawDataManaged *) trace;
+ return vmthrowable;
+}
- state->stackTraceAddrs = reinterpret_cast<gnu::gcj::RawData *> (addrs);
- return state;
-#endif
- return NULL;
+JArray< ::java::lang::StackTraceElement *> *
+java::lang::VMThrowable::getStackTrace (java::lang::Throwable *throwable)
+{
+ _Jv_StackTrace *trace = reinterpret_cast <_Jv_StackTrace *> (data);
+ return _Jv_StackTrace::GetStackTraceElements (trace, throwable);
}