JNI_GetCreatedJavaVMs

I have 2 applications - one java the other c++.
The java app is a simple loop that I run from the cammand line - right now its purpose is just to make sure a jvm is running - it is started first. I then start the C++ app which uses JNI_GetCreatedJavaVMs to try to find the jvm being used by the java app, unfortunalely the count of found jvm's is always 0.
Any ideas as to why I cannot find a jvm?

I have 2 applications - one java the other c++.
The java app is a simple loop that I run from the
cammand line - right now its purpose is just to make
sure a jvm is running - it is started first. I then
start the C++ app which uses JNI_GetCreatedJavaVMs
to try to find the jvm being used by the java app,
unfortunalely the count of found jvm's is always 0.
ny ideas as to why I cannot find a jvm?The documentation is a bit sketchy, but
JNI_GetCreatedJavaVMsreturns only those VMs created in the process from which the call is made.

Similar Messages

  • JNI_GetCreatedJavaVMs() returns 0 nVMs

    Hello all
    I am currently experiencing a very annoying problem.
    I have a function CallJavaClient() that I need to call twice.
    (See below for listing).
    When I do the calls from within a console application, everything
    works fine, but when I perform the calls from within a DLL (as required)
    the second call of CallJavaClient() doesn't succeed.
    The problem seems to stem from the call to JNI_GetCreatedJavaVMs().
    This function always return nVMs == 0 when calling from the DLL.
    So then the function JNI_CreateJavaVM() is called, which causes
    the program to stop since a VM is running.
    Can anyone suggest what might be going on here?
    Thanks in advance
    G
    (JDK 1.2.2; JRE 1.3.1 / Hotspot; Windows NT/2000;)
    static int CallJavaClient(
    const char* tssServletURL,
    const char* DTD_Spec,
    const char* sessionID,
    const char* requestID,
    const char* userID,
    const char* mechanismType,
    const char* operationType,
    const char* transactionData,
    const char* signature,
    const char* className,
    const char* methodName,
    const char* jvmOption_compilerMode,
    const char* jvmOption_classPath,
    const char* jvmOption_nativeLibPath,
    const char* jvmOption_verboseMode,
    char* tssString,
    char* usrMessage)
    int rc = SM_AUTHAPI_SUCCESS;
    jint jvmCreate = 0;
    JNIEnv* env = NULL;
    JavaVM* jvm = NULL;
    JavaVMInitArgs vm_args;
    JavaVMOption options[4];
    JavaVMAttachArgs attArgs;
    jint res;
    JavaVM* vmBuf[10];
    jsize bufLen = 10;
    jsize nVMs;
    char jvmOptionParam_ComplierMode[128];
    char jvmOptionParam_ClassPath[128];
    char jvmOptionParam_NativeLibPath[128];
    char jvmOptionParam_VerboseMode[128];
    sprintf( jvmOptionParam_ComplierMode, "-Djava.compiler=%s", jvmOption_compilerMode );
    sprintf( jvmOptionParam_ClassPath, "-Djava.class.path=%s", jvmOption_classPath );
    sprintf( jvmOptionParam_NativeLibPath, "-Djava.library.path=%s", jvmOption_nativeLibPath );
    sprintf( jvmOptionParam_VerboseMode, "-verbose:%s", jvmOption_verboseMode );
    options[0].optionString = (char*) jvmOptionParam_ComplierMode;
    options[1].optionString = (char*) jvmOptionParam_ClassPath;
    options[2].optionString = (char*) jvmOptionParam_NativeLibPath;
    options[3].optionString = (char*) jvmOptionParam_VerboseMode;
    vm_args.version = JNI_VERSION_1_2;
    vm_args.options = options;
    vm_args.nOptions = 4;
    vm_args.ignoreUnrecognized = TRUE;
    attArgs.version = JNI_VERSION_1_2;
    attArgs.name = NULL;
    attArgs.group = NULL;
    res = JNI_GetCreatedJavaVMs( vmBuf, bufLen, &nVMs );
    printf( "JNI_GetCreatedJavaVMs() res = %d nVMs = %d\n", res, nVMs );
    if (res < 0)
    printf("No Java VM is created\n");
    else if (nVMs == 1)
    printf("A Java VM is already created.\n");
    jvm = vmBuf[0];
    else if (nVMs == 0)
    // In JDK 1.2, there is no longer any need to call JNI_GetDefaultJavaVMInitArgs.
    jvmCreate = JNI_CreateJavaVM( &jvm, (void**) &env, &vm_args );
    if( jvmCreate < 0 )
    sprintf( usrMessage, "Failed to create Java Virtual Machine. %d\n", jvmCreate );
    rc = SM_AUTHAPI_FAILURE;
    if( rc == SM_AUTHAPI_SUCCESS )
    res = jvm->AttachCurrentThread( (void**) &env, &attArgs );
    if (res < 0)
    sprintf( usrMessage, "Can't attach current thread\n" );
    rc = SM_AUTHAPI_FAILURE;
    if( rc == SM_AUTHAPI_SUCCESS )
    // Find class.method
    jclass cls = env->FindClass( className );
    // Catch Exception
    if( cls != 0 )
    jmethodID mid =
    env->GetStaticMethodID( cls, methodName, "([Ljava/lang/String;)Ljava/lang/String;" );
          if( mid != 0 )
            jstring jstr = NULL;
            // Attempt to allocate an empty string object for later use
            if( ( jstr = env->NewStringUTF ("") ) != NULL )
              int numberOfArguments = sizeof( SM_AUTHAPI_JVM_ARGUMENT_LIST ) / sizeof( SM_AUTHAPI_JVM_ARGUMENT_LIST[0] );
    jobjectArray args = env->NewObjectArray( numberOfArguments, env->FindClass("java/lang/String"), jstr );
    env->SetObjectArrayElement( args, SM_AUTHAPI_JVM_ARGUMENT_INDEX_URL, env->NewStringUTF( tssServletURL ) );
    env->SetObjectArrayElement( args, SM_AUTHAPI_JVM_ARGUMENT_INDEX_DTD, env->NewStringUTF( DTD_Spec ) );
    env->SetObjectArrayElement( args, SM_AUTHAPI_JVM_ARGUMENT_INDEX_SESSIONID, env->NewStringUTF( sessionID ) );
    env->SetObjectArrayElement( args, SM_AUTHAPI_JVM_ARGUMENT_INDEX_REQUESTID, env->NewStringUTF( requestID ) );
    env->SetObjectArrayElement( args, SM_AUTHAPI_JVM_ARGUMENT_INDEX_USERID, env->NewStringUTF( userID ) );
    env->SetObjectArrayElement( args, SM_AUTHAPI_JVM_ARGUMENT_INDEX_MECHANISMTYPE, env->NewStringUTF( mechanismType ) );
    env->SetObjectArrayElement( args, SM_AUTHAPI_JVM_ARGUMENT_INDEX_OPERATIONTYPE, env->NewStringUTF( operationType ) );
    env->SetObjectArrayElement( args, SM_AUTHAPI_JVM_ARGUMENT_INDEX_TRANSACTIONDATA, env->NewStringUTF( transactionData ) );
    env->SetObjectArrayElement( args, SM_AUTHAPI_JVM_ARGUMENT_INDEX_SIGNATURE, env->NewStringUTF( signature ) );
    // Call the Java method
    //jstr = (jstring) env -> CallStaticObjectMethod( cls, mid, "c:\\tss\\testdata\\verify.xml", "http://nsmse80:450/servlet/verifysig" );
    jstr = (jstring) env->CallStaticObjectMethod( cls, mid, args );
    if( jstr != 0 )
    // Java String to C++ char array (warning: error checking omitted)
    const char* cstr = env->GetStringUTFChars( jstr, 0 );
    strcpy( tssString, cstr );
    env->ReleaseStringUTFChars( jstr, cstr );
    env->DeleteLocalRef( jstr );
    ParseTSSString( tssString, usrMessage );
    rc = SM_AUTHAPI_SUCCESS;
    else
    sprintf( usrMessage, "Error retieving value from TSS\n" );
    rc = SM_AUTHAPI_FAILURE;
    else //if( ( jstr = env->NewStringUTF ("") ) == NULL )
    sprintf( usrMessage, "Memory allocation error (jstr)\n" );
    rc = SM_AUTHAPI_FAILURE;
    else //if( mid == 0 )
    sprintf( usrMessage, "Error calling static method %s\n", methodName );
    rc = SM_AUTHAPI_FAILURE;
    else
    sprintf( usrMessage, "Can't find class %s\n", className );
    rc = SM_AUTHAPI_FAILURE;
    res = jvm->DetachCurrentThread();
    printf( "DetachCurrentThread() res = %d\n", res );
    res = JNI_GetCreatedJavaVMs( vmBuf, bufLen, &nVMs );
    printf( "res = %d nVMs = %d\n", res, nVMs );
    printf( "Calling DestroyJavaVM() ...\n" );
    res = jvm->DestroyJavaVM();
    printf( "DestroyJavaVM() res = %d nVMs = %d\n", res, nVMs );
    else
    sprintf( usrMessage, "Failed to create Java Virtual Machine. %d\n", jvmCreate );
    rc = SM_AUTHAPI_FAILURE;
    return( rc );

    Not making the call to DestroyJavaVM() seems to solve the problem.

  • JNI_GetCreatedJavaVMs not working

    I was trying to use the JNI_GetCreatedJavaVMs to work and it gives me an error within my C++ program:
    C:\Examples\Conversation\MSGpumper\MSGpumperDlg.cpp(193) : error C2039: 'JNI_GetCreatedJavaVMs' : is not a member of 'JNIEnv_'
    c:\jbuilder8\jdk1.4\include\jni.h(750) : see declaration of 'JNIEnv_'
    I have placed jvm.dll in my debug and jvm.lib in my source directory ...everything is linked correctly but it does't know what JNI_Get... is
    JavaVM * jvm;
         JNIEnv * env;
         jsize buflen;
         jsize * nVMs;
         env->JNI_GetCreatedJavaVMs(&jvm, buflen, nVMs);any suggestions?

    The error message tells you exactly what the problem is.
    The method is not part of the JNIEnv.
    Instead of
       env->JNI_GetCreatedJavaVMs(&jvm, buflen, nVMs);Use
       JNI_GetCreatedJavaVMs(&jvm, buflen, nVMs);

  • JNI_GetCreatedJavaVMs always return zero

    Why does pfnGetCreatedJavaVMs(&jvmBuf, 1, &no_vms) always return 0(success) even though there is no created JVM?
    typedef jint (JNICALL GetCreatedJVMs_t)(JavaVM *vmBuf, jsize bufLen,jsize *nVMs);
    GetCreatedJVMs_t pfnGetCreatedJavaVMs=(GetCreatedJVMs_t)GetProcAddress(handle,"JNI_GetCreatedJavaVMs");
              JavaVM* jvmBuf=NULL;
              jsize no_vms=0;
              if(pfnGetCreatedJavaVMs(&jvmBuf, 1, &no_vms)==JNI_OK)
                   OutputDebugString("VM Found!! Trying to attach to it..");
                   jvm = &jvmBuf[0];
                   if(jvm!=NULL && no_vms!=0)
                        (*jvm).AttachCurrentThread((void **)&env, NULL);
              else{
                   OutputDebugString("Cannot find created VMs");
    /*****************************************************

    Here is sample code:
    if (m_vm == NULL){
         env->GetJavaVM(&mvm);
    jobj = env->NewGlobalRef(_jobj);
    m_vm->AttachCurrentThread((void **)&_env, NULL);
    jclass jcls = env->GetObjectClass(_jobj);
    jmethodID id = env->GetMethodID(_jcls, "OnRecvData", "(Ljava/lang/String;)V");
    jint jint = env->CallIntMethod(_jobj, id, jstr);

  • Using Swing as interface to a dll

    I am trying to use Swing as my cross platform GUI for c++ dll's. Each dll has its own GUI. However, one of my dll's controls what other dlls are loaded. This works fine until I try to load a second instance of the control dll. I get an access violation message when I try to update my gui. If I try to load the two dlls from the c++ everything works fine, but if I load one from the Java GUI I get an null access exception. I'm guessing its caused by one of two problems:
    1) The DLL loading is trashing the executing stack of either the JAVA or the native code.
    2) As the code returns from the constructor call to the newly loaded dll JNI is deleting the interface objects that it is creating on the heap.
    Any ideas would be greatly appreciated.
    Unfortunately I don't get an error log from JAVA.
    VisualStudio gives me:
    Unhandled exception at 0x10014a7d (nativedll.dll) in testjava.exe: 0xC0000005: Access violation reading location 0xfeeefef6.
    The print out reads:
    Creating Java VM
    No. Created VMs 0
    Creating Frame
    Created frame
    Begin master update loop
    Calling Update
    Updated Frame 0
    Creating Java VM
    No. Created VMs 1
    Creating Frame
    Created frame
    Calling Update
    I am using Visual Studio .Net 2003 and jdk 1.4.4, 1.5.0_08 and 1.6.0.
    Main application:
    #include "Windows.h"
    #include "nativelibrary.h"
    #include <stdlib.h>
    #include <string.h>
    #include "jni.h"
    int main(int argc, char* argv[])
           //Load first library
         HMODULE handle = LoadLibrary( "../../nativedll/debug/nativedll.dll");
         nativelibrary* (*funcPtr)();
         funcPtr = (nativelibrary*(*)())GetProcAddress( handle, "createObj");
         nativelibrary* newObj = (*funcPtr)();
            // update each library
         for (int i = 0; i < 10000; i++)
              printf ("Begin master update loop\n");
              void (*funcPtr2)();
              funcPtr2 = (void(*)())GetProcAddress( handle, "update");
              (*funcPtr2)();
              printf ("End master update loop\n");
              Sleep(10);
         // Sleep(100000);
         return 0;
    }Main Library
    #include <iostream>
    #include "jni.h"
    #include "MyFrame.h"
    #include "StaticFunc.h"
    #include <stdlib.h>
    #include <vector>
    #include "Windows.h"
    using namespace std;
    class nativelibrary
    public:
         JavaVM *jvm;
         JNIEnv *env;
         jclass cls;
         jobject myFrame;
         nativelibrary();
         void locupdate();
         static vector<nativelibrary*> objects;
    vector<nativelibrary*> nativelibrary::objects;
    nativelibrary* createObj()
         return new nativelibrary();
    nativelibrary::nativelibrary()
         // JavaVMOption options[0];
         JavaVMInitArgs vm_args;
         memset(&vm_args, 0, sizeof(vm_args));
         vm_args.version = JNI_VERSION_1_4;
         vm_args.nOptions = 0;
         vm_args.ignoreUnrecognized = true;
         vm_args.nOptions = 0;
         // vm_args.options = options;
         JavaVM** jvmBuf = (JavaVM**)malloc(sizeof(JavaVM*));
         jsize buflen = 1;
         jsize nVMs =0;
         // vm_args.options[0].optionString = "-Djava.class.path=../../bin/Debug";
         // Create the Java VM
         printf("Creating Java VM\n");
         jint res = JNI_GetCreatedJavaVMs(jvmBuf, buflen, &nVMs);
         if ( res >= 0)
              printf("No. Created VMs %i\n", nVMs);
              if ( nVMs > 0)
                   jvm = jvmBuf[0];
                   res = jvm->GetEnv((void**)&env,vm_args.version);
              else
                   res = JNI_CreateJavaVM(&jvm,(void**)&env,&vm_args);
         else
              res = JNI_CreateJavaVM(&jvm,(void**)&env,&vm_args);
         cls = env->FindClass("LMyFrame;");     
         if ( cls == 0 ) printf("Cannot find MyFrame");
         jmethodID mid = env->GetMethodID(cls, "<init>", "()V");
         if ( mid == 0 ) printf("Cannot find constructor");
         printf("Creating Frame\n");
         myFrame = env->NewObject(cls, mid);
         if (env->ExceptionOccurred())
              env->ExceptionDescribe();
         printf("Created frame\n");
         objects.push_back(this);
    void nativelibrary::locupdate()
         printf("Calling Update\n");
         jmethodID updatemid = env->GetMethodID(cls, "update", "()V");
         if ( updatemid == 0 ) printf("Cannot find update");
         env->CallVoidMethod(myFrame, updatemid);
         if (env->ExceptionOccurred())
              env->ExceptionDescribe();
    void update()
         vector<nativelibrary*>::iterator it = nativelibrary::objects.begin();
         while (it != nativelibrary::objects.end())
              nativelibrary* lib = *it;
              lib->locupdate();
              it++;
    JNIEXPORT void JNICALL Java_MyFrame__1createObj
      (JNIEnv *, jclass)
         createObj();
    }Java Class (User interface)
    class MyFrame
         static native void _createObj();
         static int creations = 0;
         int framenum;
         MyFrame()
              System.loadLibrary("../../nativedll/Debug/nativedll");
              framenum = creations++;
         void update()
              System.out.println("Updated Frame " + framenum);
              if ( creations == 1)
                   // load dll as a result of the user clicking on the interface
                   createObj();
         public static void createObj()
              _createObj();
    }

    I am trying to use Swing as my cross platform GUI for c++ dll's. Each dll has its own GUI. However, one of my dll's controls what other dlls are loaded. This works fine until I try to load a second instance of the control dll. I get an access violation message when I try to update my gui. If I try to load the two dlls from the c++ everything works fine, but if I load one from the Java GUI I get an null access exception. I'm guessing its caused by one of two problems:
    1) The DLL loading is trashing the executing stack of either the JAVA or the native code.
    2) As the code returns from the constructor call to the newly loaded dll JNI is deleting the interface objects that it is creating on the heap.
    Any ideas would be greatly appreciated.
    Unfortunately I don't get an error log from JAVA.
    VisualStudio gives me:
    Unhandled exception at 0x10014a7d (nativedll.dll) in testjava.exe: 0xC0000005: Access violation reading location 0xfeeefef6.
    The print out reads:
    Creating Java VM
    No. Created VMs 0
    Creating Frame
    Created frame
    Begin master update loop
    Calling Update
    Updated Frame 0
    Creating Java VM
    No. Created VMs 1
    Creating Frame
    Created frame
    Calling Update
    I am using Visual Studio .Net 2003 and jdk 1.4.4, 1.5.0_08 and 1.6.0.
    Main application:
    #include "Windows.h"
    #include "nativelibrary.h"
    #include <stdlib.h>
    #include <string.h>
    #include "jni.h"
    int main(int argc, char* argv[])
           //Load first library
         HMODULE handle = LoadLibrary( "../../nativedll/debug/nativedll.dll");
         nativelibrary* (*funcPtr)();
         funcPtr = (nativelibrary*(*)())GetProcAddress( handle, "createObj");
         nativelibrary* newObj = (*funcPtr)();
            // update each library
         for (int i = 0; i < 10000; i++)
              printf ("Begin master update loop\n");
              void (*funcPtr2)();
              funcPtr2 = (void(*)())GetProcAddress( handle, "update");
              (*funcPtr2)();
              printf ("End master update loop\n");
              Sleep(10);
         // Sleep(100000);
         return 0;
    }Main Library
    #include <iostream>
    #include "jni.h"
    #include "MyFrame.h"
    #include "StaticFunc.h"
    #include <stdlib.h>
    #include <vector>
    #include "Windows.h"
    using namespace std;
    class nativelibrary
    public:
         JavaVM *jvm;
         JNIEnv *env;
         jclass cls;
         jobject myFrame;
         nativelibrary();
         void locupdate();
         static vector<nativelibrary*> objects;
    vector<nativelibrary*> nativelibrary::objects;
    nativelibrary* createObj()
         return new nativelibrary();
    nativelibrary::nativelibrary()
         // JavaVMOption options[0];
         JavaVMInitArgs vm_args;
         memset(&vm_args, 0, sizeof(vm_args));
         vm_args.version = JNI_VERSION_1_4;
         vm_args.nOptions = 0;
         vm_args.ignoreUnrecognized = true;
         vm_args.nOptions = 0;
         // vm_args.options = options;
         JavaVM** jvmBuf = (JavaVM**)malloc(sizeof(JavaVM*));
         jsize buflen = 1;
         jsize nVMs =0;
         // vm_args.options[0].optionString = "-Djava.class.path=../../bin/Debug";
         // Create the Java VM
         printf("Creating Java VM\n");
         jint res = JNI_GetCreatedJavaVMs(jvmBuf, buflen, &nVMs);
         if ( res >= 0)
              printf("No. Created VMs %i\n", nVMs);
              if ( nVMs > 0)
                   jvm = jvmBuf[0];
                   res = jvm->GetEnv((void**)&env,vm_args.version);
              else
                   res = JNI_CreateJavaVM(&jvm,(void**)&env,&vm_args);
         else
              res = JNI_CreateJavaVM(&jvm,(void**)&env,&vm_args);
         cls = env->FindClass("LMyFrame;");     
         if ( cls == 0 ) printf("Cannot find MyFrame");
         jmethodID mid = env->GetMethodID(cls, "<init>", "()V");
         if ( mid == 0 ) printf("Cannot find constructor");
         printf("Creating Frame\n");
         myFrame = env->NewObject(cls, mid);
         if (env->ExceptionOccurred())
              env->ExceptionDescribe();
         printf("Created frame\n");
         objects.push_back(this);
    void nativelibrary::locupdate()
         printf("Calling Update\n");
         jmethodID updatemid = env->GetMethodID(cls, "update", "()V");
         if ( updatemid == 0 ) printf("Cannot find update");
         env->CallVoidMethod(myFrame, updatemid);
         if (env->ExceptionOccurred())
              env->ExceptionDescribe();
    void update()
         vector<nativelibrary*>::iterator it = nativelibrary::objects.begin();
         while (it != nativelibrary::objects.end())
              nativelibrary* lib = *it;
              lib->locupdate();
              it++;
    JNIEXPORT void JNICALL Java_MyFrame__1createObj
      (JNIEnv *, jclass)
         createObj();
    }Java Class (User interface)
    class MyFrame
         static native void _createObj();
         static int creations = 0;
         int framenum;
         MyFrame()
              System.loadLibrary("../../nativedll/Debug/nativedll");
              framenum = creations++;
         void update()
              System.out.println("Updated Frame " + framenum);
              if ( creations == 1)
                   // load dll as a result of the user clicking on the interface
                   createObj();
         public static void createObj()
              _createObj();
    }

  • Error while running pw_agent_util.sh -create on golden gate instance

    ./pw_agent_util.sh -create Please create a password for Java Agent: Exception in thread "Thread-2" java.lang.NoClassDefFoundError: java.util.concurrent.TimeUnit
    at com.goldengate.wallet.PasswordMasker$StreamMasker.run(PasswordMasker.java:204)
    at java.lang.Thread.run(libgcj.so.7rh)
    password123 Please confirm password for Java Agent: Exception in thread "Thread-4" java.lang.NoClassDefFoundError: java.util.concurrent.TimeUnit
    at com.goldengate.wallet.PasswordMasker$StreamMasker.run(PasswordMasker.java:204)
    at java.lang.Thread.run(libgcj.so.7rh)
    password123 Please enter Monitor Server JMX password: Exception in thread "Thread-6" java.lang.NoClassDefFoundError: java.util.concurrent.TimeUnit
    at com.goldengate.wallet.PasswordMasker$StreamMasker.run(PasswordMasker.java:204)
    at java.lang.Thread.run(libgcj.so.7rh)
    jmxuser Please confirm Monitor Server JMX password: Exception in thread "Thread-8" java.lang.NoClassDefFoundError: java.util.concurrent.TimeUnit
    at com.goldengate.wallet.PasswordMasker$StreamMasker.run(PasswordMasker.java:204)
    at java.lang.Thread.run(libgcj.so.7rh)
    jmxuser
    Exception in thread "main" java.lang.UnsatisfiedLinkError: ggLog
    at com.goldengate.monitor.jagent.eventlog.JagentAppender.append(JagentAppender.java:53)
    at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251)
    at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:66)
    at org.apache.log4j.Category.callAppenders(Category.java:206)
    at org.apache.log4j.Category.forcedLog(Category.java:391)
    at org.apache.log4j.Category.error(Category.java:305)
    at com.goldengate.wallet.WalletHelper.open(WalletHelper.java:105)
    at com.goldengate.monitor.jagent.security.PWAgentUtil.main(PWAgentUtil.java:56)
    jagnet.log shows this error.
    2013-03-01 19:20:46 [main] ERROR WalletHelper - java.lang.ExceptionInInitializerError
    2013-03-01 19:20:46 [main] ERROR WalletHelper - java.lang.ExceptionInInitializerError
    ~

    Hi Joe,
    Thanks for the info.
    This is the error I am seeing in mgr report file.
    2013-03-12 21:49:59 INFO OGG-00975 JavaVMService::stop() shutdownClass.
    Source Context :
    SourceModule : [ggif.JavaVMActiveObject]
    SourceID : [net/ap1012nap-vlan900/vol/ifarm_ports/ifarm_views/aime_oggcore_59854/oggcore/OpenSys/src/gglib/ggif/JavaVMActiveObject.cpp]
    SourceFunction : [invokeJavaClassMethod]
    SourceLine : [400]
    ThreadBacktrace : [10] elements
    : [./mgr(CMessageContext::AddThreadContext()+0x26) [0x8231706]]
    : [./mgr(CMessageFactory::CreateMessage(CSourceContext*, unsigned int, ...)+0x817) [0x8227e57]]
    : [./mgr(_MSG_ERR_SHARED_LIB_GET_FUNCTION(CSourceContext*, char const*, char const*, char const*, CMessageFactory::MessageDisposition)+0x8b) [0x82019eb
    : [./mgr(ggs::gglib::ggif::JavaVMActiveObject::invokeJavaClassMethod(ggs::gglib::ggif::CReferenceCountedContext<std::string>&, ggs::gglib::ggif::CRefer
    enceCountedContext<std::string>&, ggs::gglib::ggif::CReferenceCountedContext<std::string>&, ggs::gglib::ggif::CReferenceCountedContext<std::string>&, ggs::gglib::ggif::CStatus&)
    +0x139) [0x82dbcc9]]
    : [./mgr(JavaVMService::stop(ggs::gglib::ggif::CStatus&)+0x722) [0x8135832]]
    : [./mgr(Manager::shutdown(ggs::gglib::ggif::CStatus&)+0x547) [0x8141487]]
    : [./mgr(new_main_loop(int, char**)+0xb04) [0x80ff474]]
    : [./mgr(main+0x105) [0x8104f65]]
    : [lib/libc.so.6(__libc_start_main+0xdc) [0x49ddee9c]]
    : [./mgr(__gxx_personality_v0+0x145) [0x80f0511]]
    2013-03-12 21:49:59 ERROR OGG-01123 Error loading function jvm from JNI_GetCreatedJavaVMs - ./mgr: undefined symbol: JNI_GetCreatedJavaVMs].
    2013-03-12 21:49:59 ERROR OGG-01668 PROCESS ABENDING.
    Here I am able to stop and start the MGR on other server with jdk1.7.0_15 with no errors.
    I will try to download the 1.6 version and try it on this server.
    Thanks,

  • Low level synchronization in legacy library

    I have an existing C++ library that I need to make available from Java. The library itself is not multithreaded, but it has some global data that it protects using Posix (i.e. native) mutexes. I have no problem with the JNI layer making the library callable, with the exception of the synchronization.
    As near as I can tell, the right way to integrate this is to use MonitorEnter/Exit calls. The problem with this is that I don't have the JNIEnv available at that point in the code, and to make it directly available, I'd have to propagate it through many layers of calls.
    The one possible workaround that I have is to use JNI_GetCreatedJavaVMs to get the VM pointer, and then use GetEnv to get the JNIEnv. This seems to rely on the current constraint of only one VM per process. However, I don't know if that constraint applies to platforms other than Sun's (with the obvious example, for me at least, being WebLogic). Also, this seems to be a temporary solution, as the design of JNI_GetCreatedJavaVMs clearly shows an intent to have more than one VM in the future, but with no easy global way to find the current VM (or JNIEnv, for that matter).
    Any suggestions or corrections would be welcome.
    Gary

    Thanks for your suggestion. It wouldn't work directly for me, since I have no control over the clients of this library, and the clients are already multithreaded. However, I can achieve locking at a similar level of granularity by using JNI callbacks at the very top level of my interface. It's possible that the performance impact of such large granularity locking would not be a problem, though that's very difficult to determine.
    At the moment, though, I'm still strongly leaning towards simply asserting that native implementations of Java threads are a requirement for use of this package.
    Gary

  • JNI Calling Java code when attaching to existing JVM

    I've got an Active/X that runs within IE, and also makes JNI calls (via the Invocation API) to Java code. Running within IE means there's already a JVM around, so I attach to it using JNI_GetCreatedJavaVMs
    This is fine. The problem is that I can't use the JNI findClass() to locate my Java classes, because I have no control over the classpath that the JVM is using to locate classes. The only solution I can think of so far is to either add my classes as part of the JVM, OR find out the classpath of the existing JVM (using System.getProperty("java.class.path") and copy my classes into that directory.
    Both solutions look ugly - anyone know of a cleaner way ?
    Mark.

    Toby, thanks for the reply.
    You're welcome.
    I notice from elsewhere on this forum, you're clearly a JNI expert.
    I've been known to work with it a little from time to time. =)
    My code has to work with JDK 1.1 so URLClassLoader is out. Writing my own classloader is fine, but how do I load it in the first place ? Is there something in JNI I've missed ?
    Possibly. Using DefineClass() you can load a class into the virtual machine, given it's byte-code. Now here's the tricky part. First, write your ClassLoader. It will be easiest if it doesn't rely on any other classes other than what is core to the JRE. Once you compile that classloader, you then need to include the bytecode as a resource in your executable/dll. Then, at runtime, you can load that resource, and use DefineClass to class-load it. Once you've class-loaded it, you can use NewObject, GetMethodID, CallXXXMethod, etc... to do the other class loading you need to do.
    Trust me, this really isn't as hard as it might sound.
    God bless,
    -Toby Reyelts
    As always, I recommend you check out the free, open-source JNI toolkit, Jace, at http://jace.reyelts.com/jace.

  • JNI Callback from remote process

    I have an application that calls back from C to Java in multiple situations. In some, I have been successful using the technique of calling AttachCurrentThread as described, for example, in various places, e.g.,
    http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jniref.html#invoke
    and recently in this forum
    http://forum.java.sun.com/thread.jspa?threadID=763205&tstart=45`
    This is an accessibility application and one of the situations I need to callback from is a global keyboard hook. In this context, I call from Java to a C DLL which sets up the keyboard hook using the standard Windows procedure SetWindowsHookEx.
          SetWindowsHookEx(    
                      WH_KEYBOARD,    // type of hook to install
                     (HOOKPROC) mykeyboardProc,    // address of hook procedure
                    ( HINSTANCE__* )hDll,    // handle of application instance
                    0     // identity of thread to install hook for  (all threds)      );The keyboard hook functions in Windows by being "injected" into running applications so that it runs in their process space and therein, apparently, lies the problem.
    The keyboard hook gets callbacks from Windows whenever a key is pressed. This is the information I want to learn about back in Java. Our current approach is to have the keyboard hook write the key data to shared memory. Then the Java application makes polling calls into the previously mentioned C DLL which checks the shared memory and returns anything it finds. The C DLL is compiled with the current MinGW compiler.
    This procedure works alright-- I can access the information using shared memory in C and polling that from Java. It is, however, a tad slow. I'd like to use a callback from C directly to eliminate the extra layer of polling. I could, of course, do the polling in the C DLL and call back to Java from there. That would eliminate a process switch every time we poll, but would still leave the polling.
    In my attempts to set up a direct callback from the keyboard hook to Java, the C code uses AttachCurrentThread using the env pointer obtained from the JNI_OnLoad method. When my application has the focus and I type, I get print statements from the C DLL and the callbacks work fine. When any other application has focus, the callback does not work and there are no print statements. In fact, the keyboard hook crashes and stops responding to any key events.
    Since I do not get print statements when another application has focus (or they go into the ether), I do not know directly whether the JNI_OnLoad function actually gets called each time the DLL is loaded into another application. However, the JVM pointer I cache in the JNI_OnLoad function is NULL when I get a key event callback (when another application has focus). I tested this by putting an "exit" call if the cached JVM was NULL in the keyboard procedure (mykeyboardProc above). When any application has focus and I type a key, that application exits. From this I assume that JNI_OnLoad is not getting called, but since the cached JVM is NULL, that is irrelevant.
    One option I have attempted is to use JNI_GetCreatedJavaVMs to get a list of the JVMs running on the machine. From this, I hoped to somehow deduce which JVM was running my application and use its pointer. However, despite putting some of the the directories` with the jvm.dll into my library path:
       g++ -I/c/Programs/Java/JDK15~1.0_0/include
           -I/c/Programs/Java/JDK15~1.0_0/include/win32
           -L/c/Programs/Java/JDK15~1.0_0/jre/bin \
           ....I get the error:
    undefined reference to `JNI_GetCreatedJavaVMs@12'
    I would be grateful for any suggestions or solutions.
    Rick

    Thanks for the reply Jim,
    I've been compiling in the Msys environment.
    I created the jvm.def and generated the jvm.a as you
    suggested.
    This apparently required copying the jvm.dll from
    /c/Programs/Java/JDK15~1.0_0/jre/bin/client
    de]
    to my working directory.  Before I did that I got a
    message
    about stripping the path components from the dll
    name.
    Then I tried to make the DLL in the fashion I had
    been:g++ -I/c/Programs/Java/JDK15~1.0_0/include \
    -I/c/Programs/Java/JDK15~1.0_0/include/win32 \
    L/c/Programs/Java/JDK15~1.0_0/jre/bin/client \
    -shared -o JKeyboardInterface.dll \     
    jvm.a \
    JKeyboardInterface_wrapper.cpp \
    JKeyboardDllMain.cpp \
    JKeyboardInterface.cpp \
    -Wl,--out-implib,libJKeyboardInterface.a \
         -Wl,--add-stdcall-alias -mno-cygwin \
    -fno-rtti -fno-exceptions -s
    This resulted in this error:
    Creating library file: libJKeyboardInterface.a
    K:/DOCUME~1/rick/LOCALS~1/Temp/ccU1daaa.o:JKeyboardInt
    erface.cpp:(.text+0xafb):
    undefined reference to
    `_imp__JNI_GetCreatedJavaVMs@12'
    collect2: ld returned 1 exit status
    Hmmmmm. What happens if you remove the '-Wl,--out-implib,libJKeyboardInterface.a'? It seems to be failing in the step creating the static lib, which may prevent the DLL from being properly created.
    Since this was a different undefined reference, I
    re-did the jmv.def step
    using imp_JNI_GetCreatedJavaVMs@12 instead of
    JNI_GetCreatedJavaVMs@12
    This generated the same error.Yeah. I'm sure I never had to do anything like that.
    >
    Then I tried to use dllwrap with both versions of the
    jvm.a generated above::
    dllwrap --driver-name=c++ \
    --add-stdcall-alias \
    -o JKeyboardInterface.dll \
           jvm.a \
           JKeyboardInterface_wrapper.cpp \
           JKeyboardDllMain.cpp \
           JKeyboardInterface.cpp \With both versions of the jvm.a, I got the error:
    K:/DOCUME~1/rick/LOCALS~1/Temp/ccSccaaa.o:JKeyboardInt
    erface.cpp:(.text+0xafb):
    undefined reference to `JNI_GetCreatedJavaVMs@12'
    ollect2: ld returned 1 exit statusI'm not clear why the two approaches (g++ -shared and
    dllwrap) yield different reference problems.
    I've read that dllwrap is "deprecated" Probably.
    (http://www.mingw.org/MinGWiki/index.php/dllwrap).
    Do you have any other suggestions about how to do
    this?Have a look at:
    http://www.inonit.com/cygwin/
    Msys (which is Mingw) follows cygwin pretty closely.
    I'm not near a Windows machine to try this at the moment. All I can say is that I have an application using CreateJavaVM, compiled with MSYS and it works. CreateJavaVM has the same problems as GetCreatedJavaVMs that you are seeing. The root cause is that the jvm.lib shipped with the JDK for Windows is not compatible with GCC. Hence the need to create the jvm.a library.
    I build my code using an ANT script. It build the objects first and then links them. Deciphering the build script, it looks like the two steps would have the following command line syntax:
    Compile to object files:
    gcc -D REENTRANT -I <paths to include> somefiles.cpp somefiles.c
    (I have a mix of C and C++)
    Link object files to create DLL:
    gcc -shared -D REENTRANT --kill-at -lstdc++ somefiles.o jvm.a
    Try it in two steps and see if it makes a difference.
    >
    Is trying to use GetCreatedJavaVMs the correct
    approach here?
    If more than one exists, how do I determine which one
    I want to attach to and get an env pointer for?From you original post, it is difficult to understand exactly what you are trying to achieve.
    It seems like you are starting with a Java app that calls into some native code to create the keyboard hook. This hook will then call a callback method in native code when a key is pressed. You want the Java code to see this and act appropriately.
    In Java callbacks are usually handled with events. Just have your native code fire an event in Java and have a Listener on the Java side. I do this in some of my code. Say I have an event called FooEvent and a listener called FooListener. There is also an object called Bar which can fire FooEvents and have FooListeners attached to it. The Bar class has an addFooListener() method which is actually a native method. The native implementation sets up the callback stuff on the native side. When an event occurs on the native side, the callback function is called and it does something like this:
    jclass cls;
    jmethodID mid;
    cls = env->GetObjectClass(javaSource);
    mid = env->GetMethodID(cls, "fireSomeEvent", "()V");
    env->CallVoidMethod(javaSource, mid);In the code above, the 'cls' variable would be the Bar class object and the 'javaSource' variable is a global reference ot the Bar object to which the event listener was added. The 'env' variable is acquired by calling 'AttachCurrentThread' on a cached JavaVM pointer stored in a global reference.
    The Bar class has a fireSomeEvent() method, which calls the event listeners using the event generator idiom:
    http://www.javaworld.com/javaworld/jw-09-1998/jw-09-techniques.html
    The listener on the Java side gets notification when the event occurs and you can take the appropriate action. No polling, no shared memory.
    Jim S.

  • Access Violation in CallStaticVoidMethod() using JNI

    Hey all,
    I have a C++ app which I successfully used about a year ago to put up a Java dialog from within QuarkXPress, which has a C/C++ API. I got it out and rebuilt it and ran it, and I am now getting an Access Violation (0xC0000005) exception in JVM.dll somewhere. I am getting the exception in the CallStaticVoidMethod() call. Here is the relevant snippet from the method I am using: if anyone can spot anything obviously amiss, I would appreciate knowing about it! (This snippet borrows heavily from the "invoke.c" example program in the JNI tutorial.)
      JavaVM *jvm;
      jint res;
      jclass cls;
      jmethodID mid;
      jthrowable except = NULL;
      JavaVMInitArgs vm_args;
      JavaVMOption options[2];
      char newcpath[512];
      char newlibpath[512];
      sprintf (newcpath, "-Djava.class.path=.;C:\\Program Files\\QuarkXpress 4.0\\XTENSION"); 
      sprintf (newlibpath, "-Djava.library.path=.;C:\\Program Files\\QuarkXpress 4.0\\XTENSION");
      options[0].optionString = newcpath;
      options[1].optionString = newlibpath;
      vm_args.version = 0x00010002;
      vm_args.options = options;
      vm_args.nOptions = 2;
      vm_args.ignoreUnrecognized = JNI_TRUE;
      /* Create the Java VM */
      res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
      if (res == JNI_EEXIST)
        JavaVM *jvms[1];
        jsize nVMs;
        res = JNI_GetCreatedJavaVMs(jvms, 1, &nVMs);
        jvm = jvms[0];
        jvm->AttachCurrentThread((void**)&env, NULL);
      else if (res < 0)
        return UNKNOWN_ERROR;
      cls = env->FindClass(g_javaName);
      if (cls == 0)
        checkException();
        destroy(jvm);
        return MISSING_CLASS;
      mid = env->GetStaticMethodID(cls, "main", "([Ljava/lang/String;)V");
      if (mid == 0)
        destroy(jvm);
        return MISSING_METHOD;
      env->CallStaticVoidMethod(cls, mid);

    Hi ,
    The method id that you get is for the public static void main(String args[]) of a class.
    mid = env->GetStaticMethodID(cls, "main", "([Ljava/lang/String;)V");  if (mid == 0)  
    destroy(jvm);   
    return MISSING_METHOD; 
    env->CallStaticVoidMethod(cls, mid);
    Change the above line to
    jstring jStringArgs[];
    env->CallStaticVoidMethod(cls, mid, jStringArgs);
    You need to pass an argument i.e. an array of jstring .
    It is immaterial that they possess valid value or not .
    LathaDhamo

  • How to use loaded JVM instance?

    I have made a browser extension for Internet Explorer - a vertical explorer bar. The main code for my program is in Java. I have written some native code in C++ also which loads the JVM and runs the Java classes. The java code runs fine when I run one instance of the internet explorer. But when I open a new window, the JVM cannot be loaded again. How could I use the JVM instance that has aready been loaded?
    However, when running a new instance of the internet explorer from the start menu, a new JVM instance is loaded and everything works fine.
    Would anybody please help me.

    If I read the question correctly...see JNI_GetCreatedJavaVMs()

  • Single Process Multiple JVM

    What are the possible ways of emboding multiple JVMs to a single java process.
    Please post good articles if any. I have searched in google. But I couldnt get much. My requirement is to know how the heap ,stack, and inter JVM communication occures.
    I have seen many applications like Quartz/OpenSymphony runs like multiple JVMs on single process.
    thanks
    Renjith.

    Hi,
    Declare the JavaVM *jvm instance as static... so u can get the jvm using JNI_GetCreatedJavaVMs during the next time                                                                                                                                                                                                                                               

  • AttachCurrentThread fails when several VMs running in different threads

    Hi,
    I would like to build an application that runs several JVMs in parallel. I'm using Java6 and according to the JNI specs this should be possible as long as each VM instance is running in a separate thread.
    In the below mentioned demo application two threads are created. Both instantiate a VM (which works well). But only one thread seems to be able to run AttachCurrentThread. When AttachCurrentThread is called for the second one I get the following error:
    # An unexpected error has been detected by Java Runtime Environment:
    #  SIGSEGV (0xb) at pc=0x080486ae, pid=1428, tid=3035118512
    # Java VM: Java HotSpot(TM) Client VM (1.6.0_03-b05 mixed mode, sharing)
    # Problematic frame:
    # C  [jvmthreads+0x6ae]But because one thread successfully instantiates a java class I think that the basic code structure is OK. It seems to be a threading issue. My application looks as follows:
    #include <stdlib.h>
    #include <jni.h>
    #include <pthread.h>
    #define USER_CLASSPATH "myclasses.jar"
    #define CLASS_NAME "com.foobar/DummyRtbosFiller"
    JavaVM* JavaThreads_createJVM(){
         JNIEnv *env;
        JavaVM *vm;
        jint res;
        setenv("JAVA_VM_VERSION", "1.5", 1);
    //    setenv("JAVA_VM_VERSION", "1.5", 0);
        JavaVMInitArgs vm_args;
        JavaVMOption options[7];
        options[0].optionString = malloc(3000*sizeof(char));
        sprintf(options[0].optionString, "-Djava.class.path="USER_CLASSPATH);
        options[1].optionString = "-Xmx64m";
         int enableRemDebugging = 0;
         if(enableRemDebugging){
             printf("enable remote debugging");
              // intellij remote debugging support
              options[2].optionString = "-Xdebug";
              options[3].optionString = "-Xnoagent";
              options[4].optionString = "-Djava.compiler=NONE";
              options[5].optionString = "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=34343";
              vm_args.nOptions = 6;
         }else{
              vm_args.nOptions = 2;
         vm_args.options = options;
        vm_args.version = JNI_VERSION_1_4;
        vm_args.ignoreUnrecognized = JNI_TRUE;
        /* Create the Java VM */
        res = JNI_CreateJavaVM(&vm, (void**)&env, &vm_args);
        printf("java started.\n");
         return vm;
    * \brief Shuts down an existing java virtual machine.
    * \param jvm Pointer to the jvm to be destroyed.
    * This method is used to shut down an existing java virtual machine.
    int JavaThreads_destroyJVM(JavaVM *jvm){
    //     JNIEnv *env = getAttachedEnv(self, jvm);
    //     if ((*env)->ExceptionOccurred(env)) {
    //        (*env)->ExceptionDescribe(env);
          // detach the current thread from the vm
        (*jvm)->DetachCurrentThread(jvm);
        (*jvm)->DestroyJavaVM(jvm);
         return 0;
    * \brief Attaches the current thread to a given vm instance
    * \param self Pointer to bbcm-instance
    * \param jvm Pointer to the jvm use for attachment
    * This method is used to attach the current thread to a given vm instance
    JNIEnv* getAttachedEnv(JavaVM *jvm){
         JNIEnv *localEnv = NULL;
         int envErr = 0;
         /* get a local java env */
         envErr = (*jvm)->AttachCurrentThread( jvm, (void**)&localEnv, NULL );
         if ( envErr != 0 ){
              if ( (*localEnv)->ExceptionCheck( localEnv ) == JNI_TRUE ){
                (*localEnv)->ExceptionDescribe( localEnv );
         if((*localEnv)->ExceptionOccurred(localEnv)){
             (*localEnv)->ExceptionDescribe(localEnv);
         if (localEnv == NULL) {
            printf("ERROR: failed to get ENV pointer in pushContext");
              //  JavaThreads_destroyJVM(jvm);
            return (JNIEnv*) NULL;
         return localEnv;
    * \brief Create a new instance of the transcriber application
    * \return Pointer to the java object
    * This method is used to create a new instance transcriber application
    jobject startJavaSubSystem(JavaVM *jvm, char* argString){
        printf("attaching env pointer.\n");
         JNIEnv *env = getAttachedEnv(jvm);
        printf("thread attachment done.\n");
         jclass cls;
         jmethodID mid;
         jobject transcriber;
         cls = (*env)->FindClass(env, CLASS_NAME);
        if (cls == NULL) {
            JavaThreads_destroyJVM(jvm);
         jstring jArgumentString = (*env)->NewStringUTF(env, argString);
        mid = (*env)->GetMethodID(env, cls, "<init>", "(ILjava/lang/String;)V");
         if (mid == NULL) {
            JavaThreads_destroyJVM(jvm);
        printf("starting object instantiation\n");
        (*env)->NewObject(env, cls, mid, 1, jArgumentString);
         return transcriber;
    void startJavaThread(char* arg){
         JavaVM *jvm;
        printf("create a jvm instance for component '%s'\n", arg);
         jvm = JavaThreads_createJVM();
        printf("attempting to start component '%s'\n", arg);
        startJavaSubSystem(jvm, arg);
        printf("component '%s' started !\n", arg);
        // sleep forever to keep the thread alive
        sleep(10000);
    int main(int argc, char **argv) {
          pthread_t thread1, thread2;
          /* Create independent threads each of which will instantiate a java VM. */
         int iret1 = pthread_create( &thread1, NULL, startJavaThread,  (void*) "test47");
         sleep(1);
         int iret2 = pthread_create( &thread2, NULL, startJavaThread, (void*) "test48");
         pthread_join( thread1, NULL);
         pthread_join( thread2, NULL);
         printf("Thread 1 returns: %d\n",iret1);
         printf("Thread 2 returns: %d\n",iret2);
         return 0;
    }What could be my mistake?
    Any help (links, docs, ideas) is welcome.
    Best regards, Holger

    You're right. I got confused by the specs of JNI_GetCreatedJVMs:
    JNI_GetCreatedJavaVMs function returns all virtual machine instances
    that have been created in the current process.But unfortunately you're completely right (cf. http://java.sun.com/javase/6/docs/technotes/guides/jni/spec/invocation.html#wp9502 )
    As of JDK/JRE 1.2, creation of multiple VMs in a single process is not supported.Nothing seems to have changed since then. :-(
    thanks for the help, bg, holger

  • AttachCurrentThread SEGV linux Itanium 64 Java 6

    I have a Java application which is core dumping. This application has a JNI component. The JNI component tries to attach a native thread to VM to do a call back to Java method. SEGC occurs while doing AttachCurrentThread. Here is a code snippet.
    JNIEnv *env;
    JavaVM *jvm_local;
    jsize nVMs;
    /* Get the JNI Env from the JVM */
    /* JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize nVMs); /
    if(JNI_GetCreatedJavaVMs(&jvm_local, 1, &nVMs) != JNI_OK) return -1;
    (*jvm_local)->AttachCurrentThread(jvm_local, (void **)&env, NULL);
    Java dump
    # A fatal error has been detected by the Java Runtime Environment:
    # SIGSEGV (0xb) at pc=0x2000000000b30560, pid=7537, tid=2305843011812471424
    # JRE version: 6.0_17
    # Java VM: Java HotSpot(TM) 64-Bit Server VM (14.3-b01 mixed mode linux-ia64 )
    # Problematic frame:
    # V [libjvm.so+0x7dc560]
    # If you would like to submit a bug report, please visit:
    # http://java.sun.com/webapps/bugreport/crash.jsp
    --------------- T H R E A D ---------------
    Current thread (0x60000000002bf000): JavaThread "<no-name - thread is attaching>" [_thread_in_vm, id=7737, stack(0x200000009ae50000,0x200000009ae64000)]
    siginfo:si_signo=SIGSEGV: si_errno=0, si_code=2 (SEGV_ACCERR), si_addr=0x0000000000000030
    I looked at the core generated. See below:
    (gdb) where
    #0 0xa000000000010640 in __kernel_syscall_via_break ()
    #1 0x20000000001274b0 in raise () from /lib/tls/libc.so.6.1
    #2 0x2000000000129db0 in abort () from /lib/tls/libc.so.6.1
    #3 0x200000000115dff0 in os::abort ()
    from /strnas02/local/java/jdk1.6.0_17/jre/lib/ia64/server/libjvm.so
    #4 0x200000000143c540 in VMError::report_and_die ()
    from /strnas02/local/java/jdk1.6.0_17/jre/lib/ia64/server/libjvm.so
    #5 0x200000000116a720 in JVM_handle_linux_signal ()
    from /strnas02/local/java/jdk1.6.0_17/jre/lib/ia64/server/libjvm.so
    #6 0x200000000115adb0 in signalHandler ()
    from /strnas02/local/java/jdk1.6.0_17/jre/lib/ia64/server/libjvm.so
    #7 <signal handler called>
    #8 0x2000000000b30560 in frame::compiled_sender_sp ()
    from /strnas02/local/java/jdk1.6.0_17/jre/lib/ia64/server/libjvm.so
    #9 0x2000000000b334b0 in frame::sender ()
    from /strnas02/local/java/jdk1.6.0_17/jre/lib/ia64/server/libjvm.so
    #10 0x2000000000cfc230 in java_lang_Throwable::fill_in_stack_trace ()
    from /strnas02/local/java/jdk1.6.0_17/jre/lib/ia64/server/libjvm.so
    #11 0x2000000000cfc850 in java_lang_Throwable::fill_in_stack_trace ()
    from /strnas02/local/java/jdk1.6.0_17/jre/lib/ia64/server/libjvm.so
    #12 0x2000000000b17900 in Exceptions::throw_stack_overflow_exception ()
    from /strnas02/local/java/jdk1.6.0_17/jre/lib/ia64/server/libjvm.so
    #13 0x2000000000ce6f00 in JavaCalls::call_helper ()
    from /strnas02/local/java/jdk1.6.0_17/jre/lib/ia64/server/libjvm.so
    #14 0x2000000001157d40 in os::os_exception_wrapper ()
    from /strnas02/local/java/jdk1.6.0_17/jre/lib/ia64/server/libjvm.so
    #15 0x2000000000ce48d0 in JavaCalls::call ()
    from /strnas02/local/java/jdk1.6.0_17/jre/lib/ia64/server/libjvm.so
    #16 0x2000000000ce4ca0 in JavaCalls::call_special ()
    from /strnas02/local/java/jdk1.6.0_17/jre/lib/ia64/server/libjvm.so
    #17 0x2000000000ce5130 in JavaCalls::call_special ()
    from /strnas02/local/java/jdk1.6.0_17/jre/lib/ia64/server/libjvm.so
    #18 0x200000000138aee0 in JavaThread::allocate_threadObj ()
    from /strnas02/local/java/jdk1.6.0_17/jre/lib/ia64/server/libjvm.so
    #19 0x2000000000d00780 in attach_current_thread ()
    from /strnas02/local/java/jdk1.6.0_17/jre/lib/ia64/server/libjvm.so
    #20 0x2000000000d00c80 in jni_AttachCurrentThread ()
    from /strnas02/local/java/jdk1.6.0_17/jre/lib/ia64/server/libjvm.so
    #21 0x200000008b33bd30 in genericACFConnectionCallback (
    hdbc=0x60000000003b6bd0, param=0x0, foType=0, foEvent=1) at JdbcOdbc.c:4627
    #22 0x200000008b3ada40 in FailoverCallbackThread (a=0x600000000021cf60)
    at /ade/mardhana_him_gcia64linux1/timesten/VisiChannel/oc/src/vocctx.cpp:666
    #23 0x200000000006d7f0 in start_thread () from /lib/tls/libpthread.so.0
    #24 0x200000000026f9f0 in __clone2 () from /lib/tls/libc.so.6.1
    I see Exceptions::throw_stack_overflow_exception (). Is this a "reliable" indication that there was stack overflow? Here is the VM info:
    OS:Red Hat Enterprise Linux AS release 4 (Nahant Update 3)
    uname:Linux 2.6.9-34.0.1.0.11.EL #1 SMP Mon Dec 4 14:42:32 PST 2006 ia64
    libc:glibc 2.3.4 NPTL 2.3.4
    rlimit: STACK 16000k, CORE infinity, NPROC 16315, NOFILE 1024, AS infinity
    load average:1.37 1.24 1.23
    CPU:total 4 Itanium 2 Madison 9M, family 31 model 2 revision 1, lb
    Memory: 16k page, physical 8244064k(688096k free), swap 2097120k(2095872k free)
    vm_info: Java HotSpot(TM) 64-Bit Server VM (14.3-b01) for linux-ia64 JRE (1.6.0_17-b0405), built on Oct 14 2009 21:17:59 by "lab_ipfjbld" with gcc 4.2.0
    I will appreciate any pointers.
    With regards,
    mp

    jschell wrote:
    # SIGSEGV The most likely cause of that in an app with JNI code is a C/C++ pointer bug. That is followed by a misuse of an API (which is going to end up resolving to a pointer error too.)
    Pointer bugs do not necessarily produce immediate errors. They can cause the app to fail in unexpected ways almost anywhere after the point where the bug occurred. A common indicator of this is if the code changes or the execution through the code changes then a different bug (location) occurs.I suspected that "stack overflow" is not a good indicator (especially based on some of your older posts). I do not understand what you mean by -- That is followed by a misuse of an API (which is going to end up resolving to a pointer error too.). I am using the VM pointer and am attaching a native thread to it to call back into Java layer. Can you please elaborate on the misuse?
    Edited by: coffeeguy on Apr 8, 2010 1:11 PM
    Edited by: coffeeguy on Apr 8, 2010 1:27 PM

  • Access java properties from C++/JNI program

    Hello all,
    Is it possible to access the Java properties of a JNI VM from a C++ program?
    If so, could the code or process be explained to me.
    I want to be able to identify a specific VM that is retrieved by the JNI_GetCreatedJavaVMs
    call. I set a user property when the VM was created, and would like to verify its value
    before calling AttachCurrentThread.
    Thanks in advance.
    Mark

    Are you saying that you set a system property (via System.setProperty() or -D)?
    If so, just use the JNI invocation API to call System.getProperty().
    Without error checking, that looks something like this:bool isMySystem( JNIEnv* env ) {
      const string PropertyName = "IsMySystem";
      jclass systemClass = env->FindClass( "java/lang/System" );
      jmethodID getPropertyMethod = env->GetStaticMethodID( systemClass, "getProperty", "(Ljava/lang/String;)Ljava/lang/String;" );
      jstring propertyNameString = env->NewStringUTF( PropertyName.c_str() );
      jstring propertyString = env->CallStaticObjectMethod( systemClass, getPropertyMethod, propertyNameString );
      if ( propertyString == 0 ) {
        return false;
      const char* property = env->GetStringUTFChars( propertyString, 0 );
      boolean isMine = ! strcmp( property, "Yes" );
      env->ReleaseStringUTFChars( propertyString, property );
      return isMine;
    }Using Jace, http://jace.reyelts.com/jace (a free, open-source toolkit), this would look more like:bool isMySystem() {
      String property = System::getProperty( "IsMySystem" );
      return property.isNull() ? false : prop == "Yes";
    }In the end, Jace ends up making all of the exact same calls, but you can see how much easier it is to use.
    God bless,
    -Toby Reyelts

Maybe you are looking for