JNI problem with Garbage Collector ?

Discussion in 'Java' started by bart59, Jun 17, 2004.

  1. bart59

    bart59 Guest

    Hi,
    I've got a JNI methode, which ceate and lauch a Process in c++ (a
    process to make VoIP).
    - this methode is returning an int=the pointer to the instance (which
    implement this process) so that othet JNI methode can have access to
    the main instance.

    Under windows, everything works fine, but

    Using linux:
    I add a memory wathcher on my program to see the memory used by the
    application / memory available for the JVM.
    The memory used by the application is growing (this is normal at this
    point), but when the GC is callled (by the system) the Java
    application is frozen (no error message), and I have to kill it. On
    the oter side, the Dll is running normally !

    My theory is that under Linux, the GC is "feeing" the memory used by
    the c++ process , then java is trying to write on it, but have no
    access, or somehing like that.

    Is there any option to be check this theory: as Java is retunring no
    error, but just freezing, it is not very clear to understand.

    I tried, using JNI, but removing the Process in it, just calling a
    basic operation, and there is no bug.

    Is there a special procedure to do on LINUX, for managing the Garbage
    Collector with JNI ?

    Here is a piece of code :

    /***********Java Side******************/
    //The JNI def:
    public class JNIWrapper {
    public JNIWrapper() {

    }
    // create the h323 Process
    public native int create();
    }

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ///The class managing the JNI methodes and containing the pointer to
    the dll main class
    public class CallControlH323 implements CallControl {

    int h323StackPtr; //Pointer to the h323stack, needed in the c++ side
    JNIWrapper myJNIWrapper;
    String options; //option for the CallControl configuration
    public CallControlH323(){
    myJNIWrapper = new JNIWrapper();
    }

    public void configure(String options, String codecs) {
    h323StackPtr = myJNIWrapper.create();
    }
    }

    /*************************C++ side*****************/

    //JNI functions (file JNITerminal.cxx)

    #include "JNITerminal.h"
    #include <stdio.h>

    // Java Global Variables
    jobject jobj;
    JavaVM *jvm;

    /** Create the MainInterface **/
    JNIEXPORT jint JNICALL
    Java_ca_sess_voicesess_terminal_JNIWrapper_create
    (JNIEnv *env, jobject obj)
    {
    // Make object a Global Reference
    jobj = env->NewGlobalRef(obj);
    // Get Java VM
    env->GetJavaVM(&jvm);

    //create and start the main Process
    MainInterface * mainInterface;
    mainInterface = new MainInterface();

    return ( ( jint ) mainInterface );
    }

    ///////////////////////////////////////////////
    MainInterface inherite from PProcess (from Pwlib), it is the top
    process of the dll application
    MainInterface::MainInterface():pProcess("", "", MAJOR_VERSION,
    MINOR_VERSION, BUILD_TYPE, BUILD_NUMBER)
    #ifdef _MSC_VER
    #pragma warning(disable:4355)
    #endif
    #ifdef _MSC_VER
    #pragma warning(default:4355)
    #endif
    {
    ShowOutputs("H323Lib: Create Main Interface");
    }

    void MainInterface::Main () {}

    MainInterface::~MainInterface()
    { }
    ......
    /////////////////////////////////////////////////////////////////////////7

    If you have any suggestion, comment, help, don hesitate !!

    Thanks for your help

    Bart
    bart59, Jun 17, 2004
    #1
    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. Rob Tillie

    Garbage Collector Debugging

    Rob Tillie, Aug 15, 2003, in forum: ASP .Net
    Replies:
    11
    Views:
    1,739
    JerryK
    Aug 18, 2003
  2. Pyramis
    Replies:
    0
    Views:
    387
    Pyramis
    Jan 25, 2004
  3. Colt

    Garbage collector problem

    Colt, Nov 15, 2003, in forum: Java
    Replies:
    9
    Views:
    668
    Tim Ward
    Nov 18, 2003
  4. julien
    Replies:
    6
    Views:
    540
    Tom Anderson
    Jul 25, 2008
  5. shiretu

    Strange .NET garbage collector problem

    shiretu, Jan 10, 2006, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    114
    shiretu
    Jan 10, 2006
Loading...

Share This Page