This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: Wrestling with exceptions on win32 gcj 4.1
- From: Ranjit Mathew <rmathew at gmail dot com>
- To: tHE DPR <dpr at aha dot lt>
- Cc: GCJ <java at gcc dot gnu dot org>
- Date: Thu, 06 Apr 2006 20:14:29 +0530
- Subject: Re: Wrestling with exceptions on win32 gcj 4.1
- Openpgp: url=http://ranjitmathew.hostingzero.com/aa_6C114B8F.txt
- References: <001901c62b29$74bf37a0$8801a8c0@lirosta.local>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
tHE DPR wrote:
> my modified hellow world crashes because of segfault:
>
> public class Test
> {
> public static void main(String[] args)
> {
> System.out.println("Hello, GCJ!");
> try
> {
> new StringBuffer().append("123".toCharArray(), 1, 5);
> }
> catch (Exception ex)
> {
> ex.printStackTrace();
> }
> System.loadLibrary("any-lib");
> }
> }
[...]
> i traced the problem down to the method
> _Jv_StackTrace::UnwindTraceFn (btw, why it is not shown in backtrace?)
The problem is that _Unwind_Backtrace() should not be called
for non-DWARF-2 EH (i.e. SJLJ) targets:
http://gcc.gnu.org/ml/gcc-patches/2003-04/msg00472.html
You need something like the attached patch to prevent this
situation. See if it resolves your segfault.
Note that you *still* won't get proper method names in
stack traces - see the _Jv_StackTrace::GetStackTraceElements()
method in "libjava/stacktrace.cc", which just prints the
instruction pointers (IPs) in hex for SJLJ targets.
The best option is to use DWARF-2 EH for Windows.
(Though this does not work if you're trying to throw an
exception across code that is not using DWARF-2 EH.
For example, in a Windows GUI callback function, you
cannot throw an exception and then hope to catch it
in your event loop.)
HTH,
Ranjit.
- --
Ranjit Mathew Email: rmathew AT gmail DOT com
Bangalore, INDIA. Web: http://rmathew.com/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFENSlNYb1hx2wRS48RAuchAJ9r9PPQxWjjep9H/5O9pA4lfMkTJQCcDF2C
aBY0t1iawcjddEepHRvE3Io=
=0Srw
-----END PGP SIGNATURE-----
Index: stacktrace.cc
===================================================================
--- stacktrace.cc (revision 112731)
+++ stacktrace.cc (working copy)
@@ -418,7 +418,6 @@ void
_Jv_StackTrace::GetCallerInfo (jclass checkClass, jclass *caller_class,
_Jv_Method **caller_meth)
{
-#ifndef SJLJ_EXCEPTIONS
int trace_size = 20;
_Jv_StackFrame frames[trace_size];
_Jv_UnwindState state (trace_size);
@@ -436,15 +435,19 @@ _Jv_StackTrace::GetCallerInfo (jclass ch
//JvSynchronized (ncodeMap);
UpdateNCodeMap ();
+#ifdef SJLJ_EXCEPTIONS
+ // The Unwind interface doesn't work with the SJLJ exception model.
+ // Fall back to a platform-specific unwinder.
+ fallback_backtrace (&state);
+#else /* SJLJ_EXCEPTIONS */
_Unwind_Backtrace (UnwindTraceFn, &state);
+#endif /* SJLJ_EXCEPTIONS */
if (caller_class)
*caller_class = trace_data.foundClass;
if (caller_meth)
*caller_meth = trace_data.foundMeth;
-#else
return;
-#endif
}
// Return a java array containing the Java classes on the stack above CHECKCLASS.
@@ -461,7 +464,13 @@ _Jv_StackTrace::GetClassContext (jclass
//JvSynchronized (ncodeMap);
UpdateNCodeMap ();
+#ifdef SJLJ_EXCEPTIONS
+ // The Unwind interface doesn't work with the SJLJ exception model.
+ // Fall back to a platform-specific unwinder.
+ fallback_backtrace (&state);
+#else /* SJLJ_EXCEPTIONS */
_Unwind_Backtrace (UnwindTraceFn, &state);
+#endif /* SJLJ_EXCEPTIONS */
// Count the number of Java frames on the stack.
int jframe_count = 0;
@@ -531,8 +540,14 @@ _Jv_StackTrace::GetFirstNonSystemClassLo
//JvSynchronized (ncodeMap);
UpdateNCodeMap ();
-
+
+#ifdef SJLJ_EXCEPTIONS
+ // The Unwind interface doesn't work with the SJLJ exception model.
+ // Fall back to a platform-specific unwinder.
+ fallback_backtrace (&state);
+#else /* SJLJ_EXCEPTIONS */
_Unwind_Backtrace (UnwindTraceFn, &state);
+#endif /* SJLJ_EXCEPTIONS */
if (state.trace_data)
return (ClassLoader *) state.trace_data;