Extremely strange crash problem in JNI

Discussion in 'Java' started by outsiderjustice@gmail.com, Apr 3, 2006.

  1. Guest

    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
     
    , Apr 3, 2006
    #1
    1. Advertising

  2. On 3 Apr 2006 12:37:58 -0700, wrote:
    > 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

    --
    [ do not email me copies of your followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
     
    Gordon Beaton, Apr 3, 2006
    #2
    1. Advertising

  3. Gordon Beaton, Apr 4, 2006
    #3
  4. Guest

    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.

    Gordon Beaton wrote:
    > On 3 Apr 2006 21:57:49 +0100, Gordon Beaton wrote:
    > > 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

    >
    > Hmm, I actually meant to post this link, but both (and others in the
    > same document) apply...
    >
    > http://www.eskimo.com/~scs/c-faq.com/strangeprob/segv.html
    >
    > /gordon
    >
    > --
    > [ do not email me copies of your followups ]
    > g o r d o n + n e w s @ b a l d e r 1 3 . s e
     
    , Apr 4, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fuma
    Replies:
    0
    Views:
    2,879
  2. Replies:
    1
    Views:
    351
    Tor Rustad
    Nov 30, 2007
  3. column
    Replies:
    2
    Views:
    898
    column
    Jan 31, 2010
  4. Luke A. Kanies

    extremely strange segfault

    Luke A. Kanies, Dec 15, 2003, in forum: Ruby
    Replies:
    13
    Views:
    247
    Luke A. Kanies
    Dec 16, 2003
  5. Zhang Weiwu
    Replies:
    4
    Views:
    120
Loading...

Share This Page