Extremely strange crash problem in JNI

  • Thread starter outsiderjustice
  • Start date
O

outsiderjustice

Hi All,

This is a question to those Java/JNI/C++ experts, personally I think
the problem is very tough, so please answer it if you are an experts in
all three areas.

We have a Java application that can make calls to some C++ module
functions through JNI, this all works fine until we introduced
std::fstream in the C++ module, suddenly stack is corrupted in some C++
JNI call that cause the java application to generate random signals
(SIGBUS, SIGILL, SIGSEGV etc, this is on Solaris 8) and crash, the
strange part is that it would crash even if we don't create any actual
std::fstream object or execute any std::fstream related code at all at
runtime, the bare existence of a reference (declaration) of
std::fstream in the C++ module caused the problem, once I changed
std::fstream to use the standard stdio FILE stream, the crash problem
goes away. We don't have this problem on Windows.

We thought the problem might be caused by some namespace conflict
between java and the std::fstream in the C++ module, but we can not
prove it.

Now the questions to the experts:

1. Does java have problem if std::fstream is used in JNI C++ code?
2. Is there a possible name conflict?
3. What you think might be the problem here?

Thanks.

Yufeng
 
G

Gordon Beaton

1. Does java have problem if std::fstream is used in JNI C++ code?
2. Is there a possible name conflict?

No and no.
3. What you think might be the problem here?

Typical memory corruption error, possibly due to a stray pointer
(unitialized or null) or a bounds error (overwriting the bounds of an
array or struct).

These and other typical causes are described here (its a C FAQ but
most of it applies just as well to C++):

http://www.eskimo.com/~scs/c-faq.com/strangeprob/funnybugs.html

/gordon
 
O

outsiderjustice

Please note that this problem is not caused by any runtime code, as I
said, simply replace the std::fstream reference to a stdio FILE stream
solved the problem, even when there's no actual stream object is
created.

We have done extensive code analysis to eliminate all possible memory
corruptions, but that does not seem to be related with the actual
problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top