Hello,
any idea how to catch a crash in JNI / JNA adapted native code? I have
to use large code collections (codecs etc.) that are crash prone by
design (eg. they have to handle damaged media files etc.). So in case of
a trap/crash, the JVM should exit native code, throw an (maybe
unprecise) exception and go on as usual.
Is there any (maybe native) library to implement this?
thanks very mutch
Paul
|
|
0
|
|
|
|
Reply
|
paul.geisler (6)
|
12/6/2009 5:04:38 AM |
|
In article <7o0sb6F3o39juU1@mid.uni-berlin.de>,
Paul Geisler <paul.geisler@web.de> wrote:
> Hello,
>
> any idea how to catch a crash in JNI / JNA adapted native code? I have
> to use large code collections (codecs etc.) that are crash prone by
> design (eg. they have to handle damaged media files etc.). So in case of
> a trap/crash, the JVM should exit native code, throw an (maybe
> unprecise) exception and go on as usual.
>
>
> Is there any (maybe native) library to implement this?
>
>
> thanks very mutch
>
> Paul
There's nothing you can do to trap crashes inside the JVM. The crash is
often an indirect symptom of the bug - innocent code failing when it
hits corrupted data or a smashed stack.
You can use ProcessBuilder to execute the native code in an expendable
process and pass data along stdin, stdout, and stderr. I did this with
a custom build of FFmpeg that was modified to stream data correctly (and
crash a little less). One FFmpeg process decoded and multiple FFmepg
processes in parallel encoded at different bitrates.
For some reason it didn't work well on Linux. Other processes became so
starved of resources that the machine appeared to be dead until FFmpeg
finished. It worked fine on Solaris and MacOS X.
--
I won't see Goolge Groups replies because I must filter them as spam
|
|
0
|
|
|
|
Reply
|
Kevin
|
12/6/2009 7:14:34 AM
|
|
On 2009-12-06 00:04:38 -0500, Paul Geisler <paul.geisler@web.de> said:
> Hello,
>
> any idea how to catch a crash in JNI / JNA adapted native code? I have
> to use large code collections (codecs etc.) that are crash prone by
> design (eg. they have to handle damaged media files etc.). So in case of
> a trap/crash, the JVM should exit native code, throw an (maybe
> unprecise) exception and go on as usual.
That depends on what you mean by "crash." A "hard" crash -- for
example, a segmentation fault, or a bus error, or an arithmetic trap
like dividing by zero -- can't be recovered from; the JVM can't simply
trust that its internal state was not corrupted by whatever error
caused the signal, so the VM exits. A "soft" crash, on the other hand
-- where the library aborts what it's doing in an orderly fashion,
normally by returning an error code to the caller -- can be recovered
from.
A library that causes hard crashes is buggy, regardless of the problem
it's meant to solve. Plenty of media codecs handle bogus data by
aborting the decoding process and reporting an error; since most media
formats have fairly well-defined specs, it's not even terribly hard to
make this happen. On the other hand, a library that causes a segfault
on bad input probably also contains security vulnerabilities that can
allow arbitrary code execution: bad juju, man, just don't do it.
This isn't really a Java-specific question. The same thing comes up
even if you're writing native code, and it's very difficult to write a
correct, useful handler for SIGSEGV and friends even when you control
*all* of the code in a process; it's nearly impossible when so much of
the code is outside your control (the JVM itself, the Java standard
library, libc, the codec libraries themselves...).
If you cannot accept your application crashing on a library crash, you
need you separate code that uses that library into its own process,
with the IPC headaches that come with that. The whole concept of
separate processes exists to protect programs from each others' errors
and failures. You should also file bugs with the authors of crash-prone
libraries and consider finding alternative implementations that aren't
so likely to bite you later.
Cheers,
-o
|
|
0
|
|
|
|
Reply
|
Owen
|
12/6/2009 7:42:09 AM
|
|
Paul Geisler wrote:
> Hello,
>
> any idea how to catch a crash in JNI / JNA adapted native code? I
> have
> to use large code collections (codecs etc.) that are crash prone by
> design (eg. they have to handle damaged media files etc.). So in
> case
> of a trap/crash, the JVM should exit native code, throw an (maybe
> unprecise) exception and go on as usual.
>
>
> Is there any (maybe native) library to implement this?
A vague thought: if you wrapped the existing JNI calls with C++ that
catches the SegV (or whatever the crash amounts to) as an exception,
and then reports that exception to the JVM nicely, you'd have some
chance of contusing normal processing. You'd very likely have a
memory leak, since the unwinding of the stack would lose track of any
memory allocated by the discarded stack frames, but if you're lucky,
it's no worse than that (i.e. memory hasn't been scribbled over, the
heap hasn't been used up, the number of files left open doesn't use up
your process's quota, etc.)
A much more robust solution is, as others have suggested, to run the
questionable code in a different process, so that after a crash its
resources can be cleaned up by the OS.
|
|
0
|
|
|
|
Reply
|
Mike
|
12/7/2009 2:13:41 AM
|
|
|
3 Replies
138 Views
(page loaded in 0.06 seconds)
Similiar Articles: matlab r2009b starting problem - comp.soft-sys.matlab... to submit a bug report, please visit: # http://java.sun.com/webapps/bugreport/crash.jsp # The crash happened outside the Java Virtual Machine in native code. # See ... Something bad happened to my gfortran installation - comp.lang ...>> I do see the crash with "character(len=c_sizeof(structure_constructor()) >> :: string ... target=i686-pc-mingw32 --prefix=/home/gfortran/gc c-home/binary/mingw32/native ... comp.soft-sys.matlab - page 319... created a Simulink block library FOO with a subsystem block BAR that contains a native ... Whereas u dont see it in 6.5. Is there a way to make it works in 6.5 using ... Critical section in parallel computing - comp.soft-sys.matlab ...Protect a semaphore of crash in the critical area - comp ... wrote: > Hi, > Can you please tell me where I can see ... Studio vNext Forums > Parallel Computing in C++ and Native ... Need to dump the contents of the Registry - comp.os.ms-windows ...See results below. -Ramon ... has also made helper classes you can use in your native or ... how to get ifconfig info from a crash dump - comp.unix ... newbie: awk not working for multi-byte charsets? - comp.lang.awk ...Also, as a native English speaker who grew up in the USA ... although apparently this is a serendipitous accident, and ... support and a mortgage to pay, and I have yet to see ... [bochs][nasm][video memory] - comp.lang.asm.x86Probably crash, eventually - probably before it formats ... Haven't got Bochs (see my reply to "johny_cage"... isn ... is the lack of access to the disk images from the native ... Where did Fortran go? - comp.lang.fortranThe boost I see with regards to gfortran and g95 is not ... needs of HEP, there is probably no alternative to native C ... brokenness had not (yet???) been demonstrated to crash ... top 10 uses for random data compression?? anyone? - comp ...things like stock-markets would crash quickly, when ... If you can postulate something impossible I see no ... To be native or bad will arrange enthusiastic forms to ... [comp.publish.cdrom] CD-Recordable FAQ, Part 1/4 - comp.publish ...Archive-name: cdrom/cd-recordable/part1 Posting-Frequency: monthly Last-modified: 2008/10/09 Version: 2.71 Send corrections and updates to And... catch native crash - Velocity Reviews - Computer HardwareHello, any idea how to catch a crash in JNI / JNA adapted native code? I have to use large code collections (codecs etc.) that are crash prone by design (eg. they have to How to: Catch Exceptions in Native Code Thrown from MSILIn native code, you can catch native C++ exception from MSIL. You can catch CLR exceptions with __try and __except. 7/21/2012 3:38:37 AM
|