Go Back   ZeroC Forums > Help Center

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 04-27-2004
chappich chappich is offline
Registered User
 
 
Join Date: Apr 2004
Location: Bielefeld, Germany
Posts: 5
Unhappy [JNI] Java VM aborts on Ice::initialize

Hi,

I am trying to write a JNI wrapper for a library that uses ICE. It did not work and after
some debugging I found out that it seems to be ICE, to be specific Ice::initialize().

The Java VM crashes with a simple "unexpected exception" out of my control. I thought
about threads in general, but a simple pthreads example caused no problems. I tried
catching exceptions from Ice::initialize(), but none came. Some other ICE routines caused
no problems, either.

Did anyone have a similar problem with JNI and ICE? Is there anybody else who tried
something linke that?
Maybe it's just my machine or I missed something very, very important ...

I wrote some code which crashes for me. Thanks in advance for any help,

Christoph


File Demo.java
Code:
public class Demo {
        public static void main ( String[] _ ) {
                System.loadLibrary( "Demo" );
                jniDemo();
        }

        private static native void jniDemo ();
}
File Demo.cc
Code:
#include <Ice/Ice.h>
#include "Demo.h"

JNIEXPORT void JNICALL Java_Demo_jniDemo ( JNIEnv *, jclass ) {
        int a;
        Ice::initialize( a, 0 );
}
'best of' error message
Code:
An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : 11 occurred at PC=0x810DFE7
Function=[Unknown.]
Library=(N/A)
Demo.h was created with javah -jni -o Demo.h Demo
libDemo.so was build by g++ -shared -o libDemo.so -lIce

I am using Suse Linux, Kernel 2.4.20, GCC 3.2.3, Ice 1.3, Java 1.4.0

Last edited by chappich : 04-27-2004 at 01:12 PM.
Reply With Quote
  #2 (permalink)  
Old 04-27-2004
mes's Avatar
mes mes is offline
ZeroC Staff
 
Name: Mark Spruiell
Organization: ZeroC, Inc.
Project: Ice Developer
 
Join Date: Feb 2003
Location: California
Posts: 971
Hi,

I suspect the problem resides in the C++ code:
Code:
JNIEXPORT void JNICALL Java_Demo_jniDemo ( JNIEnv *, jclass ) {
        int a;
        Ice::initialize( a, 0 );
}
The variable a is not initialized, therefore an arbitrary value could cause a segmentation fault. You should do something like this instead:
Code:
JNIEXPORT void JNICALL Java_Demo_jniDemo ( JNIEnv *, jclass ) {
    int argc = 0;
    char* argv[] = { 0 };
    Ice::initialize( argc, argv );
}
I tried this and it worked correctly.

Take care,
- Mark
Reply With Quote
  #3 (permalink)  
Old 04-27-2004
chappich chappich is offline
Registered User
 
 
Join Date: Apr 2004
Location: Bielefeld, Germany
Posts: 5
Hi,

the code I posted was the shortest to reproduce my error. I tried that already, but after I altered the code again -- you never know -- I still had the same problem. I asume it's something wrong with my machine, gcc or whatever.

Just for the sake of completeness: Did you test the unpatched code? What was your testing environment?

Thanks, Christoph
Reply With Quote
  #4 (permalink)  
Old 04-27-2004
mes's Avatar
mes mes is offline
ZeroC Staff
 
Name: Mark Spruiell
Organization: ZeroC, Inc.
Project: Ice Developer
 
Join Date: Feb 2003
Location: California
Posts: 971
Hi Christoph,

Yes, I tried the unpatched code as well. It also worked, but after adding a line to print the value of a, I learned that it was being initialized to a negative value, therefore it wasn't triggering the error condition. Changing the code to initialize it to a positive value caused the same error message you received (signal 11, i.e., segfault).

- Mark
Reply With Quote
  #5 (permalink)  
Old 04-27-2004
chappich chappich is offline
Registered User
 
 
Join Date: Apr 2004
Location: Bielefeld, Germany
Posts: 5
Hi Mark,

interesting. I now tried all three versions:
If I initialize a as positive value, I get a simple "Aborted" from the VM, which makes sense as Ice::initialize() will try to read argv. Anyhow I get the very bad and ugly "unexpected exception" on a zero and negative values for a.

Best regards, Christoph
Reply With Quote
  #6 (permalink)  
Old 04-27-2004
mes's Avatar
mes mes is offline
ZeroC Staff
 
Name: Mark Spruiell
Organization: ZeroC, Inc.
Project: Ice Developer
 
Join Date: Feb 2003
Location: California
Posts: 971
Can you post the exact code you're trying to use?

BTW, I'm using RedHat Linux 9, gcc 3.2.2, Ice 1.3.0, JDK 1.4.2.

- Mark
Reply With Quote
  #7 (permalink)  
Old 04-27-2004
chappich chappich is offline
Registered User
 
 
Join Date: Apr 2004
Location: Bielefeld, Germany
Posts: 5
Actually it's the one you posted in your first reply.
I tried it with argc as 1, -1 and 0. It get the error message I posted in extracts in my initial posting on -1 and 0. An 1 is replied by "Aborted" -- nothing else.

If I fill argv with a value to match argc, I again get the 'big' message.
Code:
JNIEXPORT void JNICALL Java_Demo_jniDemo ( JNIEnv *, jclass ) {
        int argc = 1;
        char* argv[] = { "a" };
        Ice::initialize( argc, argv );
}
Christoph
Reply With Quote
  #8 (permalink)  
Old 04-27-2004
marc's Avatar
marc marc is offline
ZeroC Staff
 
Name: Marc Laukien
Organization: ZeroC, Inc.
Project: The Internet Communications Engine
 
Join Date: Feb 2003
Location: Florida
Posts: 1,781
Note that you must null-terminate argv:

char* argv[] = { "a", 0 };
Reply With Quote
  #9 (permalink)  
Old 04-27-2004
mes's Avatar
mes mes is offline
ZeroC Staff
 
Name: Mark Spruiell
Organization: ZeroC, Inc.
Project: Ice Developer
 
Join Date: Feb 2003
Location: California
Posts: 971
Christoph,

Are any core files created? If so, do the stack traces provide any helpful information?

I've tried to reproduce the crash you describe, but so far I haven't been able to.

- Mark
Reply With Quote
  #10 (permalink)  
Old 04-28-2004
chappich chappich is offline
Registered User
 
 
Join Date: Apr 2004
Location: Bielefeld, Germany
Posts: 5
Hi,

unfortunately there is no stack trace. The error message I posted in my initial posting is followed by a library listing, nothing else.
As I mentioned before I am using a library which uses Ice itself. I am sure, Ice::initalize() is used correctly in there.

Anyway (I think) I found the solution for my problem. I updated to Java 1.4.2_04 as this was a significant difference between your and my environment. It works now, I am able to call remote functions through Ice!

If you want to, you should be able to reproduce the crash with Java 1.4.0.

Thanks again for your help,

Christoph
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bug during Ice::initialize (argc, argv) wvalcke Bug Reports 8 08-31-2005 06:08 AM
Ice::initialize panic Comments 1 10-14-2004 05:01 PM
Initialize the communicator? lisiliao Help Center 1 04-19-2004 11:42 AM
Ice::initialize hangs on Panther taweili Help Center 0 11-02-2003 07:28 AM
Alternative Ice::initialize in Client amrufon Help Center 2 08-08-2003 12:29 AM


All times are GMT -4. The time now is 11:31 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
(c) 2008 ZeroC, Inc.