MacOSX / jni / jvm fmk 1.4.2 / passive long to a native static mtd get 0 !

I am on MacOSX 10.3.8 working with the java framework 1.4.2.
I have a problem with the JNI by passing long to a static native method (a class method). It is ok with a non static native method.
The method is in a OnX.Test class with a signature :
public static native void nativeTestStatic(long jarg1);
which is declared in C++ :
extern "C" {
JNIEXPORT void JNICALL Java_OnX_Test_nativeTestStatic(JNIEnv* aEnv,jclass jcls,jlong jarg1) {
printf("debug : %d\n",jarg1);
The printf shows always 0 !!!!
I have seen that in a big application in which some C++ code is wrapped for java by using SWIG. And C++ pointers being mapped to long, I let you imagine the disaster...
Is it a "well known problem" ????
Regards

Hello
Sure, I have verified that. I have done various System.print
before the calls and within the JNI functions.
Moreover, I have now a simple test environment (then a Test.java
and a TestJNI.c) in which I pass numbers explicitly.
I have tried to pass directly like nativeFunc(123456) or doing :
long i = 123456;
nativeFunc(l);
I tried to pass big long numbers to be sure that I am not in some
tricky byteswapping situation. (sizeof(jlong) says 8 bytes for me).
What is interesting is that it is related to static methods (then class methods).
I do not see that on object methods ; here the longs are passed correctly.
Cheers

Similar Messages

  • Here's a wierd one for ya' (JNI - JVM Maladies!)

    I'm at my wit's end, sorry for the abstract manner in which I'm going to describe this, I don't have time to write a novel about the intricacies of what the C code described herein does and I'm sure you won't have time to read it.
    I'm using JNI to wrap some C that's about a billion lines deep and at the very core of our product (it would take ten years to replace with an army of engineers).
    In the back end, we start a process that allows other processes to connect to its shared memory block (it was designed to be connected to by other C executables). I've wrapped the C client that connects to the server process in JNI. To find the hooks the connecting process uses, it (the C client) reads environment variables that list the locations of files and the address at which the shared memory starts. The connecting process also grabs a semaphore created by the server process.
    Okay, that said, the problem I'm having is less complicated. My JNI wrapper works perfectly every time I invoke it from the command line. The JVM comes up, loads the shared library, the C code talks to the already running process and does the work it needs to. THIS NEVER, EVER FAILS! However, when I take the very same java code and put it in a servlet, the C code I'm calling via JNI cannot find the hooks it needs (the error I'm getting has something to do with a semop()). The JNI side is working fine, I don't have a loadLibrary or class locator problem here. For some reason however, the webserver's JVM is hiding shared resources from the native code it is calling.
    My question is, what is the @#$!&%#!!! difference between the two JAVA processes calling the same code? Why doesn't a servlet running in Tomcat have access to the already running process when the command line process that does have access and Tomcat have been invoked from the same environment?
    I've got some theories about the webserver process having different access permissions or it's use of threads (the command line process that always works is single threaded) and child process spawning, but I don't know enough about the inner workings of the JVM to know where I should look. How do these types of permissions propagate? If the webserver process spawns a thread, does the thread have any knowledge of the environment in which its parent process was created? What about a child process? Any insights?
    I've been able to break this in the same way on Solaris and HP-UX (believe it or not, NT doesn't care, I think it might have something to do with using a mutex instead of a semaphore). By the way, I'm using root to spawn all of these processes.
    If you can give me a clue as to how to fix this, YOU ARE A GOD!
    Anyway, your help would be appreciated!

    When I'm running it from the command line, I'm usually logged in as root. I have attempted successfully to run it as other users from the command line. I'm also starting the webserver process as root.
    I'm not familiar with a way to set platform specific environment variables in Tomcat, I'm sure I could use the -D option in starting the JVM. However, I have written a native stub that uses putenv() to set all of the environment variables present at the command line when I'm able to successfully invoke my JNI wrapper. This doesn't seem to change anything.
    I've thought about this being a permissions propagation issue within the webserver. Any clues as to how I can confirm it?
    Thanks for your help!

  • I am trying to update CU3 on SQL Server 2008R2 SP2 on a cluster passive server by rollipatch upgrade i am getting the below said error

    2014-03-08 13:28:51 SQLEngine: : File versions : ['D:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Binn\SQSRVRES.DLL':2009.2009.4266.0], ['C:\Windows\system32\SQSRVRES.DLL':2009.2009.4266.0].
    2014-03-08 13:28:51 Slp: Sco: Attempting to create base registry key HKEY_LOCAL_MACHINE, machine 
    2014-03-08 13:28:51 Slp: Sco: Attempting to open registry subkey SOFTWARE\Microsoft\Windows\CurrentVersion\SharedDlls
    2014-03-08 13:28:51 Slp: Sco: Attempting to get registry value C:\Windows\system32\SQSRVRES.DLL
    2014-03-08 13:28:51 SQLEngine: : Incrementing value for DLL C:\Windows\system32\SQSRVRES.DLL, current value = 6
    2014-03-08 13:28:51 Slp: Sco: Attempting to get registry value C:\Windows\system32\SQSRVRES.DLL
    2014-03-08 13:28:51 Slp: Sco: Attempting to set value C:\Windows\system32\SQSRVRES.DLL
    2014-03-08 13:28:51 Slp: SetValue: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SharedDlls, Name = C:\Windows\system32\SQSRVRES.DLL
    2014-03-08 13:28:51 SQLEngine: : Leaving ConfigureSQLEngineResourceType
    2014-03-08 13:28:51 Slp: Sco: Attempting to create base registry key HKEY_LOCAL_MACHINE, machine 
    2014-03-08 13:28:51 Slp: Sco: Attempting to open registry subkey SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\Setup
    2014-03-08 13:28:51 Slp: Sco: Attempting to get registry value PatchLevel
    2014-03-08 13:28:51 SQLEngine: --PerfmonRegistration: Checking whether to patch performance counters for service 'MSSQLSERVER'
    2014-03-08 13:28:51 SQLEngine: --PerfmonRegistration: Getting perfmon DLL name from key at 'System\CurrentControlSet\Services\MSSQLSERVER\Performance'
    2014-03-08 13:28:51 Slp: Sco: Attempting to create base registry key HKEY_LOCAL_MACHINE, machine 
    2014-03-08 13:28:51 Slp: Sco: Attempting to open registry subkey System\CurrentControlSet\Services\MSSQLSERVER\Performance
    2014-03-08 13:28:51 Slp: Configuration action failed for feature SQL_Engine_Core_Inst during timing ConfigRC and scenario ConfigRC.
    2014-03-08 13:28:51 Slp: The registry key System\CurrentControlSet\Services\MSSQLSERVER\Performance is missing.
    2014-03-08 13:28:51 Slp: The configuration failure category of current exception is ConfigurationFailure
    2014-03-08 13:28:51 Slp: Configuration action failed for feature SQL_Engine_Core_Inst during timing ConfigRC and scenario ConfigRC.
    2014-03-08 13:28:51 Slp: Microsoft.SqlServer.Configuration.SqlEngine.MissingRegistryKeyException: The registry key System\CurrentControlSet\Services\MSSQLSERVER\Performance is missing.
    2014-03-08 13:28:51 Slp:    at Microsoft.SqlServer.Configuration.SqlEngine.Globals.GetSqlRegistryKeyHKLM(ServiceContainer context, String key, String machineName, Boolean createIfNotFound)
    2014-03-08 13:28:51 Slp:    at Microsoft.SqlServer.Configuration.SqlEngine.PerfmonRegistration.GetDLLNameFromRegistry()
    2014-03-08 13:28:51 Slp:    at Microsoft.SqlServer.Configuration.SqlEngine.PerfmonRegistration.NeedToPatch()
    2014-03-08 13:28:51 Slp:    at Microsoft.SqlServer.Configuration.SqlEngine.SqlEngineSetupPrivate.PatchPerfmonCounters(EffectiveProperties properties)
    2014-03-08 13:28:51 Slp:    at Microsoft.SqlServer.Configuration.SqlEngine.SqlEngineSetupPrivate.Patch(ConfigActionTiming timing, Dictionary`2 actionData, PublicConfigurationBase spcb)
    2014-03-08 13:28:51 Slp:    at Microsoft.SqlServer.Configuration.SqlConfigBase.SlpConfigAction.ExecuteAction(String actionId)
    2014-03-08 13:28:51 Slp:    at Microsoft.SqlServer.Configuration.SqlConfigBase.SlpConfigAction.Execute(String actionId, TextWriter errorStream)
    2014-03-08 13:28:51 Slp: Exception: Microsoft.SqlServer.Configuration.SqlEngine.MissingRegistryKeyException.
    2014-03-08 13:28:51 Slp: Source: Microsoft.SqlServer.Configuration.SqlServer_ConfigExtension.
    2014-03-08 13:28:51 Slp: Message: The registry key System\CurrentControlSet\Services\MSSQLSERVER\Performance is missing..
    2014-03-08 13:28:52 Slp: Watson Bucket 1 
     Original Parameter Values 
    2014-03-08 13:28:52 Slp: Parameter 0 : SQL2008@RTM@KB2754552 
    2014-03-08 13:28:52 Slp: Parameter 1 : Microsoft.SqlServer.Configuration.SqlEngine.Globals.GetSqlRegistryKeyHKLM 
    2014-03-08 13:28:52 Slp: Parameter 2 : Microsoft.SqlServer.Configuration.SqlEngine.Globals.GetSqlRegistryKeyHKLM 
    2014-03-08 13:28:52 Slp: Parameter 3 : Microsoft.SqlServer.Configuration.SqlEngine.MissingRegistryKeyException@1306@30 
    2014-03-08 13:28:52 Slp: Parameter 4 : Microsoft.SqlServer.Configuration.SqlEngine.MissingRegistryKeyException@1306@30 
    2014-03-08 13:28:52 Slp: Parameter 5 : SqlEngineConfigAction_patch_configrc 
    2014-03-08 13:28:52 Slp: Parameter 6 : PATCH@CONFIGRC@SQL_ENGINE_CORE_INST 
    2014-03-08 13:28:52 Slp: 
     Final Parameter Values 
    2014-03-08 13:28:52 Slp: Parameter 0 : SQL2008@RTM@KB2754552 
    2014-03-08 13:28:52 Slp: Parameter 1 : 0x4E0712AD 
    2014-03-08 13:28:52 Slp: Parameter 2 : 0x4E0712AD 
    2014-03-08 13:28:52 Slp: Parameter 3 : 0x2F2F19BE@1306@30 
    2014-03-08 13:28:52 Slp: Parameter 4 : 0x2F2F19BE@1306@30 
    2014-03-08 13:28:52 Slp: Parameter 5 : SqlEngineConfigAction_patch_configrc 
    2014-03-08 13:28:52 Slp: Parameter 6 : 0x94D05575 
    Sangamesh ms

    Hi,
    Backup system\CurrentControlSet\Services\MSSQLSERVER\ first.
    For loading the performance counter, we need a perf-<instancename>sqlctr.ini file, a sqlctr.h file matching the .ini file, and the
    registry key under System\CurrentControlSet\Services\MSSQLSERVER\Performance.
    According the description, I understand that it is missing the correct perf-<instancename>sqlctr.ini and the
    registry in your environment.
    I suggest you manually add the registry key values under the
    System\CurrentControlSet\Services\MSSQLSERVER\Performance with referring the value of registry on other working machine. Also I copy the perf-<instancename>sqlctr.ini file from other working
    machine as they are both SQL Server 2008 R2.  Then, restart the server.
    You can reload the system performance counter by lodctr /R and lodctr /T:MSSQLSERVER to set the SQL Server performance counter service as trusted.
    Lodctr
    http://technet.microsoft.com/en-us/library/hh875560.aspx
    Thanks.
    Tracy Cai
    TechNet Community Support

  • HT1338 when I turn on my macbook,macosx pops up and it won't log on my password.How do I get out of it?

                 When I turn on my MacBook,Mac osx pops up and asking for my password but it won't accept it.I need to get out of the page but how? Even when i insert the disk i' the same way.

    Hello,
    Do you have Firmware password protection in Mac OS X ...
    http://support.apple.com/kb/HT1352
    It would block usage of all the startup keys, like C, N, T, D, CMD+s, CMD+Option+p+r, CMD +v, Option, and Shift, as well as booting from anything but the Hard Drive.

  • How to specify for JVM the stack for ONE specific thread that invokes JNI

    Hello all!
    I'm 2 days now looking for a solution in several forums but even in Sun Java Forums nobody was able to come up with a solution. If you know a better forum to place it, please let me know.
    Description:
    I have an application that launches several threads of different types. One of them is quite specific and run a critical JNI C++ process. The remaining ones are just for controling of other stuff... When I call the application by the command line
    java -classpath ... -Xss20m -Djava.library.path ... pack.subpack.myApp
    the application usually crashes: My computer has 256MB RAM of memory that vanish in seconds and causes an OutOfMemoryException
    Sometimes the application works properly, but sometimes the memory usage goes up fast until a general crash.
    What I believe that is going on:
    When we declare -Xss20m, I undestand that for each thread the JVM will attemp to allocate more 20MB, and if I have 10 threads, it goes up to 200MB and so on; however I'd like to have 20MB just for my critical process (that is called in one specific thread) and not for any thread.
    If I try to reduce -Xss parameter to, let's say 10MB, my C++ process overflow the JVM stack for the thread.
    So, does any body have know how to solve it? Please... I need experts help!
    Thanks a lot,
    Calegari

    There we go...
    I have this class:
    package calegari.automata;
    * <p>Title: </p>
    * <p>Description: </p>
    * <p>Copyright: Copyright (c) 2003</p>
    * <p>Company: </p>
    * @author Aur�lio Calegari
    * @version 1.0
    public class Native {
    * Parameters:
    * individuals --> All binary individual (AC rule)
    * indivLength --> number of infividuals
    * numEval --> number of RIs
    * generateUniform --> Uniform distribution of density
    * seed --> seed for current generation
    public native double[] AutomataIterator(int[][] individuals,
    int indvLength,
    int numEval,
    boolean generateUniform,
    long seed
    static {
    System.loadLibrary("Native");
    public Native() {
    Then, running
    javah -classpath ... calegari.automata.Native
    I'll get the following .h
    /* DO NOT EDIT THIS FILE - it is machine generated */
    #include "jni.h"
    /* Header for class calegari_automata_Native */
    #ifndef Includedcalegari_automata_Native
    #define Includedcalegari_automata_Native
    #ifdef __cplusplus
    extern "C" {
    #endif
    * Class: calegari_automata_Native
    * Method: AutomataIterator
    * Signature: ([[IIIZJ)[D
    JNIEXPORT jdoubleArray JNICALL
    Java_calegari_automata_Native_AutomataIterator___3_3IIIZJ
    (JNIEnv *, jobject, jobjectArray, jint, jint, jboolean, jlong);
    #ifdef __cplusplus
    #endif
    #endif
    Next, I built my cpp file which is right bellow
    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.h>
    #include "jni.h"
    #include "calegari_automata_Native.h"
    #include "util.h"
    double IndividualEvaluator(long rule[], int automataCells[][149], int numInit1s[],
    int numOfACs, int numEvaluations);
    char getNext(char simb);
    JNIEXPORT jdoubleArray JNICALL
    Java_calegari_automata_Native_AutomataIterator___3_3IIIZJ
    (JNIEnv *env, jobject jobj, jobjectArray indiv, jint length, jint numEval,
         jboolean isUniform, jlong seed)
    printf("Native JVM call for C++ critical block: Started \a[-]");
    int ACs[10000][149]; //Will be filled with 100000 Initial states of a cellular automata
    int numIndiv = length;
    int numOfACs = numEval;
    //Dencity of each Initial state of cellular automata
    int num1sRIs[10000];
    //response
    double resp[1000];
    //set seed
    srand((unsigned int) seed);
    //generate Cellular automata states
    //Uniform generation
    if(isUniform)
    for(int i=0;i<numEval;i++)
    int num1s;
    num1s=0;
    for(int j=0;j<149;j++)
    ACs[i][j] = ((rand()%numEval)<i+1?0:1);
    if(ACs[i][j]==1) num1s++;
    num1sRIs[i] = num1s;
    printf(" %d ",num1s);
    else //not uniform generation
    for(int i=0;i<numEval;i++)
    int num1s;
    num1s=0;
    for(int j=0;j<149;j++)
    ACs[i][j] = rand()%2;
    if(ACs[i][j]==1) num1s++;
    num1sRIs[i] = num1s;
    //load individuals and start the critical method
    char simb = '-';
    for(int i=0;i<numIndiv;i++)
    jintArray oneDim = (jintArray) env->GetObjectArrayElement(indiv, i);
    jint *indiv=env->GetIntArrayElements(oneDim, 0);
    simb = getNext(simb);
    printf("\b\b%c]",simb);
    resp[i] = IndividualEvaluator(indiv,ACs,num1sRIs,numOfACs,300);
    jdoubleArray retApts;
    retApts = env->NewDoubleArray(numIndiv);
    env->SetDoubleArrayRegion((jdoubleArray)retApts,(jsize)0,numIndiv,(jdouble *)resp);
    printf("\nReturning to Java plataform: Completed\a\a\n");
    return retApts;
    char getNext(char simb)
    if(simb=='-') simb = '\\';
    else if(simb=='\\') simb = '|';
    else if(simb=='|') simb = '/';
    else if(simb=='/') simb = '-';
    return simb;
    Then it works fine since we declare the size of the stack to JVM, however, if we don't... We get a crash!
    Any idea?
    Thanks

  • Application crashes when using JNI with Jdk 1,2, 1.3 and 1.4

    Hi!
    I have this application that has a GUI written in Java and a file parser written in C. JNI is used to connect these parts together. The problem is that the application only works when I am using jdk 1.1.8 but not when using jdk1.2, jdk1.3 or jdk1.4. I am running the application on a Solaris 8 machine.
    I have not written the application myself but I am going to be working with it from now on. But I have today little knowledge with JNI and I have tried different approaches to solve the problem. For example I have tried to used DDD together with GDB to find out what the problem is but with no luck. When I run the application using jdk1.4 I get the following error when the JVM crashes:
    An unexpected exception has been detected in native code outside the VM.
    Unexpected Signal : 10 occurred at PC=0xFA023164
    Function=Java_Bitmap_setDebug+0x1C
    Library=/usr/u/lal/micview/micview2_1_0_beta1/libBitmapImpl.so
    Current Java thread:
    at Bitmap.setDebug(Native Method)
    at DisplayPanel.loadFile(DisplayPanel.java:396)
    at MicPlot.loadFile(MicPlot.java:1452)
    at MicPlot.loadFile(MicPlot.java:1441)
    at MicPlot.miOpen_Action(MicPlot.java:1267)
    at MicPlot$SymAction.actionPerformed(MicPlot.java:1184)
    at java.awt.MenuItem.processActionEvent(MenuItem.java:588)
    at java.awt.MenuItem.processEvent(MenuItem.java:548)
    at java.awt.MenuComponent.dispatchEventImpl(MenuComponent.java:285)
    at java.awt.MenuComponent.dispatchEvent(MenuComponent.java:273)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:452)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
    Dynamic libraries:
    0x10000 /opt/java/jdk1.4/bin/java
    0xff360000 /usr/lib/libthread.so.1
    0xff3a0000 /usr/lib/libdl.so.1
    0xff280000 /usr/lib/libc.so.1
    0xff270000 /usr/platform/SUNW,Ultra-4/lib/libc_psr.so.1
    0xfe000000 /opt/java/j2sdk1.4.1/jre/lib/sparc/client/libjvm.so
    0xff220000 /usr/lib/libCrun.so.1
    0xff200000 /usr/lib/libsocket.so.1
    0xff100000 /usr/lib/libnsl.so.1
    0xff1d0000 /usr/lib/libm.so.1
    0xff250000 /usr/lib/libw.so.1
    0xff0e0000 /usr/lib/libmp.so.2
    0xff0b0000 /opt/java/j2sdk1.4.1/jre/lib/sparc/native_threads/libhpi.so
    0xff080000 /opt/java/j2sdk1.4.1/jre/lib/sparc/libverify.so
    0xff030000 /opt/java/j2sdk1.4.1/jre/lib/sparc/libjava.so
    0xfe7e0000 /opt/java/j2sdk1.4.1/jre/lib/sparc/libzip.so
    0xfe4e0000 /usr/lib/locale/en_US.ISO8859-1/en_US.ISO8859-1.so.2
    0xedd00000 /opt/java/j2sdk1.4.1/jre/lib/sparc/libawt.so
    0xfc480000 /opt/java/j2sdk1.4.1/jre/lib/sparc/libmlib_image.so
    0xfc410000 /opt/java/j2sdk1.4.1/jre/lib/sparc/motif21/libmawt.so
    0xeda80000 /usr/dt/lib/libXm.so.4
    0xfa090000 /usr/openwin/lib/libXt.so.4
    0xfa3d0000 /usr/openwin/lib/libXext.so.0
    0xfc7e0000 /usr/openwin/lib/libXtst.so.1
    0xed980000 /usr/openwin/lib/libX11.so.4
    0xfa2a0000 /usr/openwin/lib/libdps.so.5
    0xfa3b0000 /usr/openwin/lib/libSM.so.6
    0xfa1d0000 /usr/openwin/lib/libICE.so.6
    0xed880000 /opt/java/j2sdk1.4.1/jre/lib/sparc/libfontmanager.so
    0xfa390000 /usr/openwin/lib/locale/common/xlibi18n.so.2
    0xfa1b0000 /usr/openwin/lib/locale/iso8859-1/xomEuro.so.2
    0xfa190000 /usr/lib//liblayout.so
    0xfa050000 /usr/openwin/lib/locale/common/ximlocal.so.2
    0xfa010000 /usr/u/lal/micview/micview2_1_0_beta1/libBitmapImpl.so
    Local Time = Thu Oct 3 13:32:47 2002
    Elapsed Time = 35
    # The exception above was detected in native code outside the VM
    # Java VM: Java HotSpot(TM) Client VM (1.4.1-beta-b14 mixed mode)
    # An error report file has been saved as hs_err_pid27692.log.
    # Please refer to the file for further information.
    Abort
    From this information I think that the problem should be in the native method setDebug. But I have tried to set a breakpoint at the beginning of that function in the C part but with no luck. The application crashes before it reaches that position in the C file.
    What could possibly go wrong between the setDebug function in the C part and the function call in the Java part?
    When using GDB, GDB cannot figure out what is wrong it just returns a hex address, no function name.
    I would really appreciate some help. I have tried everything that I can come up with!
    Best regards
    Lars

    I have figured out that the application fails on its first call to the native methods.
    So I have this Bitmap class that contains all the native calls and it is defined shortly as follow:
    public class Bitmap {
    static {
    System.loadLibrary("BitmapImpl");
    native void setDebug(int debuglevel, int statistics);
    There are many more native methods defined in Bitmap, but I only show the setDebug method because that is the first one that is executed and also the one that immediately fails.
    My setDebug C function is defined as follow in BitmapImpl.c
    #include <time.h>
    #include <stdio.h>
    #include <limits.h>
    #include <fcntl.h>
    #include <jni.h>
    #include <math.h>
    #include <errno.h>
    #include "Bitmap.h"
    #include "data.h"
    jint debug = 0;
    jint statistics = 1;
    JNIEXPORT void JNICALL Java_Bitmap_setDebug
    (JNIEnv *jenv, jobject jo, jint d, jint s)
    debug = d;
    statistics = s;
    My libBitmapImpl.so file is compiled using the following Makefile and using GNU gcc:
    JAVAPATH=$(JAVAINCLUDEPATH)
    LMACRO=-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DSOLARIS
    CSOURCE=BitmapImpl.c
    all:
    gcc -O3 -G $(LMACRO) -I$(JAVAPATH) -I$(JAVAPATH)/solaris \
    $(CSOURCE) -o libBitmapImpl.so
    It is still a total mystory why the application fails. I have tried it on a RedHat Linux machine and there it works fine. But not on Solaris. Only if I use the jdk1.1.8 but not a later one.
    Would really appreiciate some help!
    Best regards
    Lars

  • Exit handling in native function by JNI

    Hi everyone,
    We are developing a Java application using native function calls through JNI in Linux.
    The application starts and calls a native function and the native function attach a signal
    handler and an exit handler. In addition, in the native function, we fork another process
    and in the forked process, we calls a several java-side methods. It works in normal cases.
    However, when System.exit() is called in the java-side methods invoked by a native function,
    the application is stopped. Thus we add shutdown hook (Runtime.getRuntime().addShutdownHook())
    to treat this case. The shutdown hook just calls a native method, and the native method
    just calls exit(). We expect the calling exit() in the native method invoked in shutdown hook for JVM
    invokes our exit handler which is attached in advance. It looks working well.
    But, sometimes we find several garbage(?) jvm processes (we can see the process named as "java"
    in using Linux command "ps"). The parent process of these processes is init process (pid = 1).
    With the pid of these processes, we suspect the processes are created when we fork another process
    in native function invoked through JNI. However it is not happened every times in our application.
    Why the garbage java processes remain? Is there any problem in the calling exit() in the native
    method invoked during JVM Shutdown process?
    I hope any answers for this problem.
    Thanks in advance,
    Seung-Uk Oh

    Thus we add shutdown hook
    (Runtime.getRuntime().addShutdownHook())
    to treat this case. The shutdown hook just calls a
    native method, and the native method
    just calls exit(). We expect the calling exit() in the
    native method invoked in shutdown hook for JVM
    invokes our exit handler which is attached in advance.
    It looks working well.I wouldn't think that was a good idea.
    You are terminating the JVMs normal exit process. Why don't you just register the exit processes in your own stack and call them with the native method?

  • JVM Crashing in ParallelGC at AIX

    We use JNI_CreateJavaVM to start an JVM from C. And in this JVM we use "LocateRegistry.createRegistry(JMXPORT);" to create registry. But the JVM always crash at Solaris with JDK1.6 ( It works fine with JDK1.5). The crash happens at the process of ParallelGC. It works fine with SerialGC.
    I can work around the crashing by add -XX:+UseSerialGC to change the GC method. But i need to know the root cause. It will be very appreciated for any help. Thanks.
    # A fatal error has been detected by the Java Runtime Environment:
    # SIGFPE (0x8) at pc=0xfffffd7ff0f2b898, pid=28894, tid=4
    # JRE version: 6.0_37-b06
    # Java VM: Java HotSpot(TM) 64-Bit Server VM (20.12-b01 mixed mode solaris-amd64 compressed oops)
    # Problematic frame:
    # V [libjvm.so+0x46b898] JVM_GetCPClassNameUTF+0x94c8
    # 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 (0x000000000081b800): VMThread [stack: 0xfffffd7ffe6af000,0xfffffd7ffe7af000] [id=4]
    siginfo:si_signo=SIGFPE: si_errno=0, si_code=4 (FPE_FLTOVF), si_addr=0xfffffd7ff0f2b898
    Registers:
    RAX=0x0000000000469f60, RBX=0x0000000000000000, RCX=0x0000000000461a60, RDX=0x0000000000880000
    RSP=0xfffffd7ffe7ae6a0, RBP=0xfffffd7ffe7ae6d0, RSI=0x0000000003300000, RDI=0x0000000000475500
    R8 =0x000000000046c860, R9 =0xfffffd7ffee52490, R10=0x0000000000461b00, R11=0x00000000f9380000
    R12=0x0000000000475500, R13=0xfffffd7ff1272fd0, R14=0x0000000000475d30, R15=0x00000000000cc010
    RIP=0xfffffd7ff0f2b898, RFLAGS=0x0000000000010246
    Top of Stack: (sp=0xfffffd7ffe7ae6a0)
    0xfffffd7ffe7ae6a0: fffffd7ff199af30 000000000046c2e0
    0xfffffd7ffe7ae6b0: 0000000000475500 0000000000000000
    0xfffffd7ffe7ae6c0: fffffd7ffe7ae6f0 408f4000447a0000
    0xfffffd7ffe7ae6d0: fffffd7ffe7ae710 fffffd7ff0f2b8e7
    0xfffffd7ffe7ae6e0: fffffd7ff199af30 000000000046c2e0
    0xfffffd7ffe7ae6f0: 00000000004623c0 fffffd7ff0f37d99
    0xfffffd7ffe7ae700: 00000000000cc010 fffffd7ff199af30
    0xfffffd7ffe7ae710: fffffd7ffe7ae720 fffffd7ff0f2b5da
    0xfffffd7ffe7ae720: fffffd7ffe7ae9c0 fffffd7ff1680c44
    0xfffffd7ffe7ae730: 0000000000461970 000000000046c2e0
    0xfffffd7ffe7ae740: fffffd7ff1999388 fffffd7ff19a16e8
    0xfffffd7ffe7ae750: 0000000000000000 000000000081cb70
    0xfffffd7ffe7ae760: 0000000000000000 000000001ecf66a6
    0xfffffd7ffe7ae770: 000000001f257d23 0000000000000000
    0xfffffd7ffe7ae780: 0000000000000000 0000000000000000
    0xfffffd7ffe7ae790: 0000000000000000 0000000000000000
    0xfffffd7ffe7ae7a0: fffffd7ffe7ae878 00000000004a6530
    0xfffffd7ffe7ae7b0: 0000000000000001 0000000000000000
    0xfffffd7ffe7ae7c0: fffffd7ffe7ae7d0 fffffd7ff0e6fc92
    0xfffffd7ffe7ae7d0: 0000000000517da0 00000000004a6520
    0xfffffd7ffe7ae7e0: 00000000004a6530 00000000004a6908
    0xfffffd7ffe7ae7f0: 000000000081b800 000000000047b280
    0xfffffd7ffe7ae800: 000000000081bf10 000000000081bf20
    0xfffffd7ffe7ae810: 000000000081c2f8 fffffd7ffe7aebb8
    0xfffffd7ffe7ae820: fffffd7ff1990100 0000000000000000
    0xfffffd7ffe7ae830: 0000000000000000 0000000000000000
    0xfffffd7ffe7ae840: 000000000045e450 fffffd7ff9c77300
    0xfffffd7ffe7ae850: fffffd7ffe010100 0000000000000000
    0xfffffd7ffe7ae860: fffffd7ffe7ae8a0 fffffd7ff0f7cf00
    0xfffffd7ffe7ae870: 00000000004a6530 000000000045e450
    0xfffffd7ffe7ae880: 0000000000000000 000000001ed00a99
    0xfffffd7ffe7ae890: 0000000000000001 0000000000476c80
    Instructions: (pc=0xfffffd7ff0f2b898)
    0xfffffd7ff0f2b878: 2c c0 4d 8b 4e 28 4d 89 01 4d 8b b4 24 08 01 00
    0xfffffd7ff0f2b888: 00 49 8b fc 33 c0 41 ff d5 4c 8b 80 98 00 00 00
    0xfffffd7ff0f2b898: f2 41 0f 5a 40 28 f3 0f 59 45 f8 f3 4c 0f 2c c0
    0xfffffd7ff0f2b8a8: 4d 8b 4e 28 4d 89 01 41 5e 41 5d 41 5c c9 c3 00
    Register to memory mapping:
    RAX=0x0000000000469f60 is an unknown value
    RBX=0x0000000000000000 is an unknown value
    RCX=0x0000000000461a60 is an unknown value
    RDX=0x0000000000880000 is an unknown value
    RSP=0xfffffd7ffe7ae6a0 is an unknown value
    RBP=0xfffffd7ffe7ae6d0 is an unknown value
    RSI=0x0000000003300000 is an unknown value
    RDI=0x0000000000475500 is an unknown value
    R8 =0x000000000046c860 is an unknown value
    R9 =0xfffffd7ffee52490 is an unknown value
    R10=0x0000000000461b00 is an unknown value
    R11=0x00000000f9380000 is an unknown value
    R12=0x0000000000475500 is an unknown value
    R13=0xfffffd7ff1272fd0: JVM_SupportsCX8+0x219000 in /****/bin/jdk1.6.0_37/jre/lib/amd64/server/libjvm.so at 0xfffffd7ff0ac0000
    R14=0x0000000000475d30 is an unknown value
    R15=0x00000000000cc010 is an unknown value
    Stack: [0xfffffd7ffe6af000,0xfffffd7ffe7af000], sp=0xfffffd7ffe7ae6a0, free space=1021k
    Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
    V [libjvm.so+0x46b898] JVM_GetCPClassNameUTF+0x94c8
    V [libjvm.so+0x46b8e7] JVM_GetCPClassNameUTF+0x9517
    V [libjvm.so+0x46b5da] JVM_GetCPClassNameUTF+0x920a
    V [libjvm.so+0xbc0c44] sysThreadAvailableStackWithSlack+0x3a384
    V [libjvm.so+0xbb3986] sysThreadAvailableStackWithSlack+0x2d0c6
    V [libjvm.so+0x531398] JVM_IsSameClassPackage+0x2eb8
    V [libjvm.so+0x472384] JVM_GetCPClassNameUTF+0xffb4
    V [libjvm.so+0x4725fa] JVM_GetCPClassNameUTF+0x1022a
    V [libjvm.so+0x5ad0a0] JVM_SupportsCX8+0x130d0
    V [libjvm.so+0x5ac55f] JVM_SupportsCX8+0x1258f
    V [libjvm.so+0xb7f469] JVM_RaiseSignal+0x1c8509
    C [libc.so.1+0x1149d4] thrpsetup+0xbc
    C [libc.so.1+0x114ca0] lwpstart+0x0
    VM_Operation (0xfffffd7ffd58b7a0): ParallelGCSystemGC, mode: safepoint, requested by thread 0x0000000000bba800
    --------------- P R O C E S S ---------------
    Java Threads: ( => current thread )
    0x0000000000c4d800 JavaThread "RMI Scheduler(0)" daemon [_thread_blocked, id=23, stack(0xfffffd7ffd0ff000,0xfffffd7ffd1ff000)]
    0x0000000000b7d000 JavaThread "RMI RenewClean-[10.182.73.206:34213]" daemon [_thread_blocked, id=22, stack(0xfffffd7ffd28a000,0xfffffd7ffd38a000)]
    0x0000000000ccd000 JavaThread "RMI TCP Connection(1)-10.182.73.206" daemon [_thread_in_native, id=21, stack(0xfffffd7ffd38b000,0xfffffd7ffd48b000)]
    0x0000000000bba800 JavaThread "GC Daemon" daemon [_thread_blocked, id=20, stack(0xfffffd7ffd48c000,0xfffffd7ffd58c000)]
    0x0000000000bb9000 JavaThread "RMI Reaper" [_thread_blocked, id=19, stack(0xfffffd7ffd58d000,0xfffffd7ffd68d000)]
    0x0000000000bb6800 JavaThread "RMI TCP Accept-0" daemon [_thread_blocked, id=18, stack(0xfffffd7ffd68e000,0xfffffd7ffd78e000)]
    0x0000000000bb5800 JavaThread "Timer-0" [_thread_blocked, id=17, stack(0xfffffd7ffd78f000,0xfffffd7ffd88f000)]
    0x0000000000c0e000 JavaThread "RMI TCP Accept-26999" daemon [_thread_in_native, id=14, stack(0xfffffd7ffd96f000,0xfffffd7ffda6f000)]
    0x000000000086b800 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=12, stack(0xfffffd7ffdea7000,0xfffffd7ffdfa7000)]
    0x0000000000868800 JavaThread "C2 CompilerThread1" daemon [_thread_blocked, id=11, stack(0xfffffd7ffdfa8000,0xfffffd7ffe0a8000)]
    0x0000000000865800 JavaThread "C2 CompilerThread0" daemon [_thread_blocked, id=10, stack(0xfffffd7ffe0a9000,0xfffffd7ffe1a9000)]
    0x000000000085a000 JavaThread "JDWP Event Helper Thread" daemon [_thread_blocked, id=9, stack(0xfffffd7ffe1aa000,0xfffffd7ffe2aa000)]
    0x0000000000855000 JavaThread "JDWP Transport Listener: dt_socket" daemon [_thread_in_native, id=8, stack(0xfffffd7ffe2ab000,0xfffffd7ffe3ab000)]
    0x0000000000849000 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=7, stack(0xfffffd7ffe3ac000,0xfffffd7ffe4ac000)]
    0x0000000000823800 JavaThread "Finalizer" daemon [_thread_blocked, id=6, stack(0xfffffd7ffe4ad000,0xfffffd7ffe5ad000)]
    0x0000000000821800 JavaThread "Reference Handler" daemon [_thread_blocked, id=5, stack(0xfffffd7ffe5ae000,0xfffffd7ffe6ae000)]
    0x0000000000468800 JavaThread "main" [_thread_in_native, id=1, stack(0xfffffd7fff600000,0xfffffd7fffe00000)]
    Other Threads:
    =>0x000000000081b800 VMThread [stack: 0xfffffd7ffe6af000,0xfffffd7ffe7af000] [id=4]
    0x0000000000881000 WatcherThread [stack: 0xfffffd7ffdd3e000,0xfffffd7ffde3e000] [id=13]
    VM state:at safepoint (normal execution)
    VM Mutex/Monitor currently owned by a thread: ([mutex/lock_event])
    [0x0000000000467200] Threads_lock - owner thread: 0x000000000081b800
    [0x00000000004677a0] Heap_lock - owner thread: 0x0000000000bba800
    Heap
    PSYoungGen total 60928K, used 816K [0x00000000f5800000, 0x00000000f9c00000, 0x0000000100000000)
    eden space 52224K, 0% used [0x00000000f5800000,0x00000000f5800000,0x00000000f8b00000)
    from space 8704K, 9% used [0x00000000f8b00000,0x00000000f8bcc010,0x00000000f9380000)
    to space 8704K, 0% used [0x00000000f9380000,0x00000000f9380000,0x00000000f9c00000)
    PSOldGen total 137216K, used 0K [0x00000000e0a00000, 0x00000000e9000000, 0x00000000f5800000)
    object space 137216K, 0% used [0x00000000e0a00000,0x00000000e0a00000,0x00000000e9000000)
    PSPermGen total 22528K, used 9472K [0x00000000db800000, 0x00000000dce00000, 0x00000000e0a00000)
    object space 22528K, 42% used [0x00000000db800000,0x00000000dc1402f8,0x00000000dce00000)
    Code Cache [0xfffffd7ff9c00000, 0xfffffd7ffa000000, 0xfffffd7ffcc00000)
    total_blobs=280 nmethods=35 adapters=207 free_code_cache=49827264 largest_free_block=15680
    Dynamic libraries:
    0x0000000000400000 /****/bin/tlisten
    0xfffffd7fe8fc0000 /****/lib/libgpnet.so.71
    0xfffffd7fe8df0000 /****/lib/libtux.so.71
    0xfffffd7feae10000 /****/lib/libbuft.so.71
    0xfffffd7fe8db0000 /****/lib/libfml.so.71
    0xfffffd7fe8d70000 /****/lib/libfml32.so.71
    0xfffffd7fe9060000 /****/lib/libengine.so.71
    0xfffffd7ffe8cd000 /lib/64/libpthread.so.1
    0xfffffd7ffe8cb000 /lib/64/librt.so.1
    0xfffffd7ffe880000 /lib/64/libsocket.so.1
    0xfffffd7ffe7d0000 /lib/64/libnsl.so.1
    0xfffffd7ffeeb0000 /lib/64/libm.so.2
    0xfffffd7ffdcfc000 /lib/64/libthread.so.1
    0xfffffd7fff110000 /lib/64/libc.so.1
    0xfffffd7feadf0000 /****/lib/libutrace.so.71
    0xfffffd7feadb0000 /****/lib/libgiconv.so.71
    0xfffffd7ffd200000 /usr/lib/64/libCrun.so.1
    0xfffffd7fe8000000 /****/lib/libtmjmx.so
    0xfffffd7ffe8b0000 /lib/64/libmd.so.1
    0xfffffd7ffe7b0000 /lib/64/libmp.so.2
    0xfffffd7ff0ac0000 /****/bin/jdk1.6.0_37/jre/lib/amd64/server/libjvm.so
    0xfffffd7ffde3f000 /usr/lib/64/libsched.so.1
    0xfffffd7ffdcfb000 /lib/64/libdl.so.1
    0xfffffd7ffcdb0000 /lib/64/libm.so.1
    0xfffffd7ffceaf000 /lib/64/libdoor.so.1
    0xfffffd7ffcd70000 /usr/lib/64/libdemangle.so.1
    0xfffffd7fe9000000 /****/lib/registry.so
    0xfffffd7ff0a90000 /****/bin/jdk1.6.0_37/jre/lib/amd64/libverify.so
    0xfffffd7ff0a40000 /****/bin/jdk1.6.0_37/jre/lib/amd64/libjava.so
    0xfffffd7ff0950000 /****/bin/jdk1.6.0_37/jre/lib/amd64/libjdwp.so
    0xfffffd7ff0930000 /****/bin/jdk1.6.0_37/jre/lib/amd64/libnpt.so
    0xfffffd7ff0910000 /usr/lib/iconv/amd64/UTF-8%646.so
    0xfffffd7ff08f0000 /usr/lib/iconv/amd64/646%UTF-8.so
    0xfffffd7ff0a10000 /****/bin/jdk1.6.0_37/jre/lib/amd64/libzip.so
    0xfffffd7ff08d0000 /****/bin/jdk1.6.0_37/jre/lib/amd64/libdt_socket.so
    0xfffffd7fe6bc0000 /****/lib/libtuxjni.so
    0xfffffd7fe8ca0000 /****/lib/libtmib.so.71
    0xfffffd7fe8c10000 /****/lib/libqm.so.71
    0xfffffd7ff09f0000 /****/bin/jdk1.6.0_37/jre/lib/amd64/libj2pkcs11.so
    0xfffffd7ffde60000 /usr/lib/amd64/libpkcs11.so
    0xfffffd7ffdd10000 /lib/64/libcryptoutil.so.1
    0xfffffd7ffdbf0000 /usr/lib/security/64/pkcs11_softtoken.so
    0xfffffd7ffdbb0000 /usr/lib/64/libsoftcrypto.so.1
    0xfffffd7ffdb80000 /lib/64/libgen.so.1
    0xfffffd7ff09c0000 /****/bin/jdk1.6.0_37/jre/lib/amd64/libnet.so
    0xfffffd7fef430000 /****/bin/jdk1.6.0_37/jre/lib/amd64/librmi.so
    VM Arguments:
    jvm_args: -Djava.compiler=NONE -Dmyapp.jmx.auth=tux -Djava.security.policy= -Dmyapp.jmx.accessfile=/****/jmx/jmxaccess.properties -Dmyapp.jmx.addr=rmi://****:26999 -Xms200m -Xmx500m -Dmyapp.tlisten.nlsaddr=//****:27789 -XX:+HeapDumpOnCtrlBreak -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
    java_command: <unknown>
    Launcher Type: generic
    Environment Variables:
    JAVA_HOME=/****/bin/jdk1.6.0_37/jre
    PATH=/****/bin:/****/bin/jdk1.6.0_37/jre/bin/amd64:/****/bin:/****/bin/jdk1.6.0_37/jre/bin/amd64:/****/bin:/****/bin/jdk1.6.0_37/jre/bin/amd64:/****/bin:/****/bin/jdk1.6.0_37/jre/bin/amd64:/****/bin:/****/bin/jdk1.6.0_37/jre/bin/amd64:/****/bin:/****/bin/jdk1.6.0_37/jre/bin/amd64:/****/bin:/****/bin/jdk1.6.0_37/jre/bin/amd64:/****/bin/jdk1.6.0_37/bin/amd64/:/****/bin:/****/bin/jdk1.6.0_37/jre/bin/amd64:/****/bin:/****/bin/jdk1.6.0_37/jre/bin/amd64:/****/bin:/****/bin/jdk1.6.0_37/jre/bin/amd64:/****/bin:/****/bin/jdk1.6.0_37/jre/bin/amd64:/****/bin:/****/bin/jdk1.6.0_37/jre/bin/amd64:/****/bin:/****/bin/jdk1.6.0_37/jre/bin/amd64:/****/bin:/****/bin/jdk1.5.0_22/jre/bin:/****/bin:/****/bin/jdk1.6.0_37/jre/bin/amd64:/****/bin:/****/bin/jdk1.6.0_37/jre/bin/amd64:/****/bin:/****/bin/jdk1.6.0_37/jre/bin/amd64:/****/bin:/****/bin/jdk1.6.0_37/jre/bin:/****/bin:/****/bin/jdk1.6.0_37/jre/bin:/****/bin:/****/bin/jdk1.6.0_37/jre/bin:/usr/bin:/bin
    SHELL=/bin/ksh
    Signal Handlers:
    SIGSEGV: [libjvm.so+0xccfbb0], sa_mask[0]=0xffbffeff, sa_flags=0x0000000c
    SIGBUS: [libjvm.so+0xccfbb0], sa_mask[0]=0xffbffeff, sa_flags=0x0000000c
    SIGFPE: [libjvm.so+0x43f880], sa_mask[0]=0xffbffeff, sa_flags=0x0000000c
    SIGPIPE: [libjvm.so+0x43f880], sa_mask[0]=0xffbffeff, sa_flags=0x0000000c
    SIGXFSZ: [libjvm.so+0x43f880], sa_mask[0]=0xffbffeff, sa_flags=0x0000000c
    SIGILL: [libjvm.so+0x43f880], sa_mask[0]=0xffbffeff, sa_flags=0x0000000c
    SIGUSR1: SIG_IGN, sa_mask[0]=0x00000000, sa_flags=0x00000000
    SIGUSR2: SIG_IGN, sa_mask[0]=0x00000000, sa_flags=0x00000000
    SIGQUIT: [libjvm.so+0xb81a00], sa_mask[0]=0xffbffeff, sa_flags=0x00000004
    SIGHUP: SIG_IGN, sa_mask[0]=0x00000000, sa_flags=0x00000000
    SIGINT: SIG_IGN, sa_mask[0]=0x00000000, sa_flags=0x00000000
    SIGTERM: [libjvm.so+0xb81a00], sa_mask[0]=0xffbffeff, sa_flags=0x00000004
    SIG39: [libjvm.so+0xb84870], sa_mask[0]=0x00000000, sa_flags=0x00000008
    SIG40: [libjvm.so+0x43f880], sa_mask[0]=0xffbffeff, sa_flags=0x0000000c
    --------------- S Y S T E M ---------------
    OS: Oracle Solaris 11 Express snv_151a X86
    Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
    Assembled 04 November 2010
    uname:SunOS 5.11 snv_151a i86pc (T2 libthread)
    rlimit: STACK 10240k, CORE infinity, NOFILE 65536, AS infinity
    load average:1.16 1.15 0.84
    CPU:total 2 (32 cores per cpu, 2 threads per core) family 6 model 44 stepping 2, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3, sse4.1, sse4.2, ht
    Memory: 4k page, physical 8191612k(1152580k free)
    vm_info: Java HotSpot(TM) 64-Bit Server VM (20.12-b01) for solaris-amd64 JRE (1.6.0_37-b06), built on Sep 24 2012 11:42:33 by "" with Workshop 5.8
    time: Fri Oct 26 09:29:22 2012
    elapsed time: 0 seconds
    And following is the core dump stack trace
    Reading librmi.so
    t@4 (l@4) terminated by signal ABRT (Abort)
    0xfffffd7fff22dd1a: lwpkill+0x000a: jae lwpkill+0x18 [ 0xfffffd7fff22dd28, .+0xe ]
    (dbx) where
    current thread: t@4
    =>[1] lwpkill(0x4, 0x6, 0xffffff02cd0cbc00, 0xfffffd7fff22e54b, 0x0, 0xfffffd7ffe7addc0), at 0xfffffd7fff22dd1a
    [2] thr_kill(0x0, 0x0, 0x0, 0x0, 0x0, 0x0), at 0xfffffd7fff2224dd
    [3] raise(0x0, 0x0, 0x0, 0x0, 0x0, 0x0), at 0xfffffd7fff1ce9f1
    [4] abort(0x0, 0x0, 0x0, 0x0, 0x0, 0x0), at 0xfffffd7fff1a41a1
    [5] os::abort(0x0, 0x0, 0x0, 0x0, 0x0, 0x0), at 0xfffffd7ff16403e4
    [6] VMError::report_and_die(0x0, 0x0, 0x0, 0x0, 0x0, 0x0), at 0xfffffd7ff178f66a
    [7] JVM_handle_solaris_signal(0x0, 0x0, 0x0, 0x0, 0x0, 0x0), at 0xfffffd7ff0eff703
    [8] signalHandler(0x0, 0x0, 0x0, 0x0, 0x0, 0x0), at 0xfffffd7ff0eff88e
    [9] __sighndlr(0x0, 0x0, 0x0, 0x0, 0x0, 0x0), at 0xfffffd7fff224d66
    [10] call_user_handler(0x0, 0x0, 0x0, 0x0, 0x0, 0x0), at 0xfffffd7fff217a1c
    [11] sigacthandler(0x0, 0x0, 0x0, 0x0, 0x0, 0x0), at 0xfffffd7fff217c43
    ---- called from signal handler with signal 8 (SIGFPE) ------
    [12] GCAdaptivePolicyCounters::update_counters_from_policy(0x475500, 0x3300000, 0x880000, 0x461a60, 0x46c860, 0xfffffd7ffee52490), at 0xfffffd7ff0f2b898
    [13] PSGCAdaptivePolicyCounters::update_counters_from_policy(0x0, 0x0, 0x0, 0x0, 0x0, 0x0), at 0xfffffd7ff0f2b8e7
    [14] PSGCAdaptivePolicyCounters::update_counters(0x0, 0x0, 0x0, 0x0, 0x0, 0x0), at 0xfffffd7ff0f2b5da
    [15] PSScavenge::invoke_no_policy(0x0, 0x0, 0x0, 0x0, 0x0, 0x0), at 0xfffffd7ff1680c44
    [16] PSMarkSweep::invoke(0x0, 0x0, 0x0, 0x0, 0x0, 0x0), at 0xfffffd7ff1673986
    [17] VM_ParallelGCSystemGC::doit(0x0, 0x0, 0x0, 0x0, 0x0, 0x0), at 0xfffffd7ff0ff1398
    [18] VM_Operation::evaluate(0x0, 0x0, 0x0, 0x0, 0x0, 0x0), at 0xfffffd7ff0f32384
    [19] VMThread::evaluate_operation(0x0, 0x0, 0x0, 0x0, 0x0, 0x0), at 0xfffffd7ff0f325fa
    [20] VMThread::loop(0x0, 0x0, 0x0, 0x0, 0x0, 0x0), at 0xfffffd7ff106d0a0
    [21] VMThread::run(0x0, 0x0, 0x0, 0x0, 0x0, 0x0), at 0xfffffd7ff106c55f
    [22] java_start(0x0, 0x0, 0x0, 0x0, 0x0, 0x0), at 0xfffffd7ff163f469
    [23] thrpsetup(0x0, 0x0, 0x0, 0x0, 0x0, 0x0), at 0xfffffd7fff2249d4
    [24] lwpstart(0x0, 0x0, 0x0, 0x0, 0x0, 0x0), at 0xfffffd7fff224ca0
    Edited by: geting on Oct 29, 2012 8:16 PM
    Edited by: geting on Oct 29, 2012 8:17 PM
    Edited by: geting on Dec 17, 2012 2:30 PM
    Edited by: geting on Dec 17, 2012 3:57 PM

    Thanks for your reply.
    My native code is based on C.
    We use Sun Studio C Compiler. Also all the warning is fixed.
    And i remove the JNI operations which is wrote by me from JAVA code. But the core dump is still happen at the same place.
    Now, here is the case. One Java program is invoked by C using "JNI_CreateJavaVM". In the Java program a RMI server is created.
    Following is all the JNI operation printed by -verbose:jni. I really need your help.
    [Dynamic-linking native method java.lang.Object.registerNatives ... JNI]
    [Registering JNI native method java.lang.Object.hashCode]
    [Registering JNI native method java.lang.Object.wait]
    [Registering JNI native method java.lang.Object.notify]
    [Registering JNI native method java.lang.Object.notifyAll]
    [Registering JNI native method java.lang.Object.clone]
    [Dynamic-linking native method java.lang.System.registerNatives ... JNI]
    [Registering JNI native method java.lang.System.currentTimeMillis]
    [Registering JNI native method java.lang.System.nanoTime]
    [Registering JNI native method java.lang.System.arraycopy]
    [Dynamic-linking native method java.lang.Thread.registerNatives ... JNI]
    [Registering JNI native method java.lang.Thread.start0]
    [Registering JNI native method java.lang.Thread.stop0]
    [Registering JNI native method java.lang.Thread.isAlive]
    [Registering JNI native method java.lang.Thread.suspend0]
    [Registering JNI native method java.lang.Thread.resume0]
    [Registering JNI native method java.lang.Thread.setPriority0]
    [Registering JNI native method java.lang.Thread.yield]
    [Registering JNI native method java.lang.Thread.sleep]
    [Registering JNI native method java.lang.Thread.currentThread]
    [Registering JNI native method java.lang.Thread.countStackFrames]
    [Registering JNI native method java.lang.Thread.interrupt0]
    [Registering JNI native method java.lang.Thread.isInterrupted]
    [Registering JNI native method java.lang.Thread.holdsLock]
    [Registering JNI native method java.lang.Thread.getThreads]
    [Registering JNI native method java.lang.Thread.dumpThreads]
    [Dynamic-linking native method java.lang.Class.registerNatives ... JNI]
    [Registering JNI native method java.lang.Class.getName0]
    [Registering JNI native method java.lang.Class.getSuperclass]
    [Registering JNI native method java.lang.Class.getInterfaces]
    [Registering JNI native method java.lang.Class.getClassLoader0]
    [Registering JNI native method java.lang.Class.isInterface]
    [Registering JNI native method java.lang.Class.getSigners]
    [Registering JNI native method java.lang.Class.setSigners]
    [Registering JNI native method java.lang.Class.isArray]
    [Registering JNI native method java.lang.Class.isPrimitive]
    [Registering JNI native method java.lang.Class.getComponentType]
    [Registering JNI native method java.lang.Class.getModifiers]
    [Registering JNI native method java.lang.Class.getDeclaredFields0]
    [Registering JNI native method java.lang.Class.getDeclaredMethods0]
    [Registering JNI native method java.lang.Class.getDeclaredConstructors0]
    [Registering JNI native method java.lang.Class.getProtectionDomain0]
    [Registering JNI native method java.lang.Class.setProtectionDomain0]
    [Registering JNI native method java.lang.Class.getDeclaredClasses0]
    [Registering JNI native method java.lang.Class.getDeclaringClass]
    [Registering JNI native method java.lang.Class.getGenericSignature]
    [Registering JNI native method java.lang.Class.getRawAnnotations]
    [Registering JNI native method java.lang.Class.getConstantPool]
    [Registering JNI native method java.lang.Class.desiredAssertionStatus0]
    [Registering JNI native method java.lang.Class.getEnclosingMethod0]
    [Dynamic-linking native method java.lang.Class.getPrimitiveClass ... JNI]
    [Dynamic-linking native method java.security.AccessController.getStackAccessControlContext ... JNI]
    [Dynamic-linking native method sun.misc.Unsafe.registerNatives ... JNI]
    [Registering JNI native method sun.misc.Unsafe.getLoadAverage]
    [Dynamic-linking native method java.lang.Throwable.fillInStackTrace ... JNI]
    [Registering JNI native method sun.misc.Unsafe.copyMemory]
    [Registering JNI native method sun.misc.Unsafe.setMemory]
    [Registering JNI native method sun.misc.Unsafe.getObject]
    [Registering JNI native method sun.misc.Unsafe.putObject]
    [Registering JNI native method sun.misc.Unsafe.getObjectVolatile]
    [Registering JNI native method sun.misc.Unsafe.putObjectVolatile]
    [Registering JNI native method sun.misc.Unsafe.getBoolean]
    [Registering JNI native method sun.misc.Unsafe.putBoolean]
    [Registering JNI native method sun.misc.Unsafe.getBooleanVolatile]
    [Registering JNI native method sun.misc.Unsafe.putBooleanVolatile]
    [Registering JNI native method sun.misc.Unsafe.getByte]
    [Registering JNI native method sun.misc.Unsafe.putByte]
    [Registering JNI native method sun.misc.Unsafe.getByteVolatile]
    [Registering JNI native method sun.misc.Unsafe.putByteVolatile]
    [Registering JNI native method sun.misc.Unsafe.getShort]
    [Registering JNI native method sun.misc.Unsafe.putShort]
    [Registering JNI native method sun.misc.Unsafe.getShortVolatile]
    [Registering JNI native method sun.misc.Unsafe.putShortVolatile]
    [Registering JNI native method sun.misc.Unsafe.getChar]
    [Registering JNI native method sun.misc.Unsafe.putChar]
    [Registering JNI native method sun.misc.Unsafe.getCharVolatile]
    [Registering JNI native method sun.misc.Unsafe.putCharVolatile]
    [Registering JNI native method sun.misc.Unsafe.getInt]
    [Registering JNI native method sun.misc.Unsafe.putInt]
    [Registering JNI native method sun.misc.Unsafe.getIntVolatile]
    [Registering JNI native method sun.misc.Unsafe.putIntVolatile]
    [Registering JNI native method sun.misc.Unsafe.getLong]
    [Registering JNI native method sun.misc.Unsafe.putLong]
    [Registering JNI native method sun.misc.Unsafe.getLongVolatile]
    [Registering JNI native method sun.misc.Unsafe.putLongVolatile]
    [Registering JNI native method sun.misc.Unsafe.getFloat]
    [Registering JNI native method sun.misc.Unsafe.putFloat]
    [Registering JNI native method sun.misc.Unsafe.getFloatVolatile]
    [Registering JNI native method sun.misc.Unsafe.putFloatVolatile]
    [Registering JNI native method sun.misc.Unsafe.getDouble]
    [Registering JNI native method sun.misc.Unsafe.putDouble]
    [Registering JNI native method sun.misc.Unsafe.getDoubleVolatile]
    [Registering JNI native method sun.misc.Unsafe.putDoubleVolatile]
    [Registering JNI native method sun.misc.Unsafe.getByte]
    [Registering JNI native method sun.misc.Unsafe.putByte]
    [Registering JNI native method sun.misc.Unsafe.getShort]
    [Registering JNI native method sun.misc.Unsafe.putShort]
    [Registering JNI native method sun.misc.Unsafe.getChar]
    [Registering JNI native method sun.misc.Unsafe.putChar]
    [Registering JNI native method sun.misc.Unsafe.getInt]
    [Registering JNI native method sun.misc.Unsafe.putInt]
    [Registering JNI native method sun.misc.Unsafe.getLong]
    [Registering JNI native method sun.misc.Unsafe.putLong]
    [Registering JNI native method sun.misc.Unsafe.getFloat]
    [Registering JNI native method sun.misc.Unsafe.putFloat]
    [Registering JNI native method sun.misc.Unsafe.getDouble]
    [Registering JNI native method sun.misc.Unsafe.putDouble]
    [Registering JNI native method sun.misc.Unsafe.getAddress]
    [Registering JNI native method sun.misc.Unsafe.putAddress]
    [Registering JNI native method sun.misc.Unsafe.allocateMemory]
    [Registering JNI native method sun.misc.Unsafe.reallocateMemory]
    [Registering JNI native method sun.misc.Unsafe.freeMemory]
    [Registering JNI native method sun.misc.Unsafe.objectFieldOffset]
    [Registering JNI native method sun.misc.Unsafe.staticFieldOffset]
    [Registering JNI native method sun.misc.Unsafe.staticFieldBase]
    [Registering JNI native method sun.misc.Unsafe.ensureClassInitialized]
    [Registering JNI native method sun.misc.Unsafe.arrayBaseOffset]
    [Registering JNI native method sun.misc.Unsafe.arrayIndexScale]
    [Registering JNI native method sun.misc.Unsafe.addressSize]
    [Registering JNI native method sun.misc.Unsafe.pageSize]
    [Registering JNI native method sun.misc.Unsafe.defineClass]
    [Registering JNI native method sun.misc.Unsafe.defineClass]
    [Registering JNI native method sun.misc.Unsafe.allocateInstance]
    [Registering JNI native method sun.misc.Unsafe.monitorEnter]
    [Registering JNI native method sun.misc.Unsafe.monitorExit]
    [Registering JNI native method sun.misc.Unsafe.tryMonitorEnter]
    [Registering JNI native method sun.misc.Unsafe.throwException]
    [Registering JNI native method sun.misc.Unsafe.compareAndSwapObject]
    [Registering JNI native method sun.misc.Unsafe.compareAndSwapInt]
    [Registering JNI native method sun.misc.Unsafe.compareAndSwapLong]
    [Registering JNI native method sun.misc.Unsafe.putOrderedObject]
    [Registering JNI native method sun.misc.Unsafe.putOrderedInt]
    [Registering JNI native method sun.misc.Unsafe.putOrderedLong]
    [Registering JNI native method sun.misc.Unsafe.park]
    [Registering JNI native method sun.misc.Unsafe.unpark]
    [Dynamic-linking native method sun.reflect.Reflection.getCallerClass ... JNI]
    [Dynamic-linking native method java.security.AccessController.getInheritedAccessControlContext ... JNI]
    [Dynamic-linking native method java.lang.ClassLoader.registerNatives ... JNI]
    [Registering JNI native method java.lang.ClassLoader.retrieveDirectives]
    [Dynamic-linking native method java.security.AccessController.doPrivileged ... JNI]
    [Dynamic-linking native method java.lang.System.initProperties ... JNI]
    [Dynamic-linking native method sun.misc.VM.initialize ... JNI]
    [Dynamic-linking native method java.io.FileSystem.getFileSystem ... JNI]
    [Dynamic-linking native method java.io.UnixFileSystem.initIDs ... JNI]
    [Dynamic-linking native method java.lang.Float.floatToRawIntBits ... JNI]
    [Dynamic-linking native method java.lang.Double.doubleToRawLongBits ... JNI]
    [Dynamic-linking native method java.lang.String.intern ... JNI]
    [Dynamic-linking native method java.io.UnixFileSystem.getBooleanAttributes0 ... JNI]
    [Dynamic-linking native method java.lang.System.mapLibraryName ... JNI]
    [Dynamic-linking native method java.io.UnixFileSystem.canonicalize0 ... JNI]
    [Dynamic-linking native method java.lang.ClassLoader$NativeLibrary.load ... JNI]
    [Dynamic-linking native method java.io.FileInputStream.initIDs ... JNI]
    [Dynamic-linking native method java.io.FileDescriptor.initIDs ... JNI]
    [Dynamic-linking native method java.io.FileOutputStream.initIDs ... JNI]
    [Dynamic-linking native method java.lang.System.setIn0 ... JNI]
    [Dynamic-linking native method java.lang.Runtime.maxMemory ... JNI]
    [Dynamic-linking native method java.lang.System.setOut0 ... JNI]
    [Dynamic-linking native method java.lang.System.setErr0 ... JNI]
    [Dynamic-linking native method sun.misc.Signal.findSignal ... JNI]
    [Dynamic-linking native method sun.misc.Signal.handle0 ... JNI]
    [Dynamic-linking native method java.lang.Compiler.registerNatives ... JNI]
    [Registering JNI native method java.lang.Compiler.compileClass]
    [Registering JNI native method java.lang.Compiler.compileClasses]
    [Registering JNI native method java.lang.Compiler.command]
    [Registering JNI native method java.lang.Compiler.enable]
    [Registering JNI native method java.lang.Compiler.disable]
    [Dynamic-linking native method java.lang.ClassLoader$NativeLibrary.find ... JNI]
    [Dynamic-linking native method java.security.AccessController.doPrivileged ... JNI]
    [Dynamic-linking native method java.io.FileInputStream.open ... JNI]
    [Dynamic-linking native method java.io.FileInputStream.readBytes ... JNI]
    [Dynamic-linking native method java.io.FileInputStream.available ... JNI]
    [Dynamic-linking native method java.lang.Object.getClass ... JNI]
    [Dynamic-linking native method java.lang.reflect.Array.newArray ... JNI]
    [Dynamic-linking native method java.io.FileInputStream.close0 ... JNI]
    [Dynamic-linking native method java.io.UnixFileSystem.list ... JNI]
    [Dynamic-linking native method java.io.ObjectStreamClass.initNative ... JNI]
    [Dynamic-linking native method java.lang.Class.forName0 ... JNI]
    [Dynamic-linking native method sun.reflect.Reflection.getClassAccessFlags ... JNI]
    [Dynamic-linking native method sun.reflect.NativeConstructorAccessorImpl.newInstance0 ... JNI]
    [Dynamic-linking native method java.lang.ClassLoader.findLoadedClass0 ... JNI]
    [Dynamic-linking native method java.lang.ClassLoader.findBootstrapClass ... JNI]
    [Dynamic-linking native method sun.misc.VMSupport.initAgentProperties ... JNI]
    Listening for transport dt_socket at address: 8000
    [Dynamic-linking native method java.security.AccessController.doPrivileged ... JNI]
    [Dynamic-linking native method java.util.zip.ZipFile.initIDs ... JNI]
    [Dynamic-linking native method java.io.UnixFileSystem.getLastModifiedTime ... JNI]
    [Dynamic-linking native method java.util.zip.ZipFile.open ... JNI]
    [Dynamic-linking native method java.util.zip.ZipFile.getTotal ... JNI]
    [Dynamic-linking native method java.util.zip.ZipFile.getEntry ... JNI]
    [Dynamic-linking native method java.util.zip.ZipEntry.initIDs ... JNI]
    [Dynamic-linking native method java.util.zip.ZipEntry.initFields ... JNI]
    [Dynamic-linking native method java.util.zip.ZipFile.freeEntry ... JNI]
    [Dynamic-linking native method java.util.zip.ZipFile.getCSize ... JNI]
    [Dynamic-linking native method java.util.zip.ZipFile.getSize ... JNI]
    [Dynamic-linking native method java.util.zip.ZipFile.getMethod ... JNI]
    [Dynamic-linking native method java.util.zip.Inflater.initIDs ... JNI]
    [Dynamic-linking native method java.util.zip.Inflater.init ... JNI]
    [Dynamic-linking native method java.util.zip.Inflater.inflateBytes ... JNI]
    [Dynamic-linking native method java.util.zip.ZipFile.read ... JNI]
    [Dynamic-linking native method java.util.zip.Inflater.reset ... JNI]
    [Dynamic-linking native method java.lang.Package.getSystemPackage0 ... JNI]
    [Dynamic-linking native method java.util.jar.JarFile.getMetaInfEntryNames ... JNI]
    [Dynamic-linking native method java.lang.ClassLoader.defineClass1 ... JNI]
    [Dynamic-linking native method java.lang.ProcessEnvironment.environ ... JNI]
    [Dynamic-linking native method java.security.AccessController.doPrivileged ... JNI]
    [Dynamic-linking native method java.util.ResourceBundle.getClassContext ... JNI]
    [Dynamic-linking native method java.lang.Class.isAssignableFrom ... JNI]
    [Dynamic-linking native method java.lang.System.identityHashCode ... JNI]
    [Dynamic-linking native method java.util.concurrent.atomic.AtomicLong.VMSupportsCS8 ... JNI]
    [Dynamic-linking native method java.lang.Double.longBitsToDouble ... JNI]
    [Dynamic-linking native method sun.security.pkcs11.wrapper.PKCS11.initializeLibrary ... JNI]
    [Dynamic-linking native method sun.security.pkcs11.wrapper.PKCS11.connect ... JNI]
    [Dynamic-linking native method sun.security.pkcs11.wrapper.PKCS11.C_Initialize ... JNI]
    [Dynamic-linking native method sun.security.pkcs11.wrapper.PKCS11.C_GetInfo ... JNI]
    [Dynamic-linking native method sun.security.pkcs11.wrapper.PKCS11.C_GetSlotList ... JNI]
    [Dynamic-linking native method sun.security.pkcs11.wrapper.PKCS11.C_GetSlotInfo ... JNI]
    [Dynamic-linking native method sun.security.pkcs11.wrapper.PKCS11.C_GetTokenInfo ... JNI]
    [Dynamic-linking native method sun.security.pkcs11.wrapper.PKCS11.C_OpenSession ... JNI]
    [Dynamic-linking native method sun.security.pkcs11.wrapper.PKCS11.C_GetMechanismList ... JNI]
    [Dynamic-linking native method sun.security.pkcs11.wrapper.PKCS11.C_GenerateRandom ... JNI]
    [Dynamic-linking native method java.net.InetAddress.init ... JNI]
    [Dynamic-linking native method java.net.InetAddressImplFactory.isIPv6Supported ... JNI]
    [Dynamic-linking native method java.net.Inet6AddressImpl.getLocalHostName ... JNI]
    [Dynamic-linking native method java.net.Inet6AddressImpl.lookupAllHostAddr ... JNI]
    [Dynamic-linking native method java.net.Inet4Address.init ... JNI]
    [Dynamic-linking native method java.net.Inet6Address.init ... JNI]
    [Dynamic-linking native method java.lang.Runtime.availableProcessors ... JNI]
    [Dynamic-linking native method java.net.PlainSocketImpl.initProto ... JNI]
    [Dynamic-linking native method java.net.PlainSocketImpl.socketCreate ... JNI]
    [Dynamic-linking native method java.net.PlainSocketImpl.socketBind ... JNI]
    [Dynamic-linking native method java.net.PlainSocketImpl.socketListen ... JNI]
    [Dynamic-linking native method java.net.PlainSocketImpl.socketAccept ... JNI]
    [Dynamic-linking native method sun.reflect.ConstantPool.getUTF8At0 ... JNI]
    [Dynamic-linking native method sun.reflect.NativeMethodAccessorImpl.invoke0 ... JNI]
    [Dynamic-linking native method java.lang.reflect.Proxy.defineClass0 ... JNI]
    [Dynamic-linking native method java.lang.UNIXProcess.initIDs ... JNI]
    [Dynamic-linking native method java.lang.UNIXProcess.forkAndExec ... JNI]
    [Dynamic-linking native method java.lang.UNIXProcess.waitForProcessExit ... JNI]
    [Dynamic-linking native method java.lang.UNIXProcess.destroyProcess ... JNI]
    [Dynamic-linking native method java.io.FileOutputStream.close0 ... JNI]
    [Dynamic-linking native method java.net.PlainSocketImpl.socketConnect ... JNI]
    [Dynamic-linking native method java.net.PlainSocketImpl.socketSetOption ... JNI]
    [Dynamic-linking native method java.net.SocketOutputStream.init ... JNI]
    [Dynamic-linking native method java.net.SocketOutputStream.socketWrite0 ... JNI]
    [Dynamic-linking native method java.net.SocketInputStream.init ... JNI]
    [Dynamic-linking native method java.net.SocketInputStream.socketRead0 ... JNI]
    [Dynamic-linking native method sun.misc.GC.maxObjectInspectionAge ... JNI]
    [Dynamic-linking native method java.lang.Runtime.gc ... JNI]
    # A fatal error has been detected by the Java Runtime Environment:
    # SIGFPE (0x8) at pc=0xfffffd7ffccbb898, pid=1912, tid=4
    # JRE version: 6.0_37-b06
    # Java VM: Java HotSpot(TM) 64-Bit Server VM (20.12-b01 mixed mode solaris-amd64 compressed oops)
    # Problematic frame:
    # V [libjvm.so+0x46b898] JVM_GetCPClassNameUTF+0x94c8
    # An error report file with more information is saved as:
    # /testarea/gtt/test/jmx/servers/hs_err_pid1912.log
    # If you would like to submit a bug report, please visit:
    # http://java.sun.com/webapps/bugreport/crash.jsp
    Edited by: geting on Oct 30, 2012 6:43 PM
    Edited by: geting on Oct 30, 2012 6:43 PM

  • JNI 101

    While you people are connecting universes, I am having a problem running the first JNI program.
    invoking JVM from C++;
    Started just yesterday and this is very urgent.
    The following basic code returns error -3
    Also tried running code from sun website, they give me error -1
    Cannot create JVM.
    since its pretty urgent and I am really short on time, I dont have time to do my research so please give your suggestions and dont get mad!
    Appreciatively,
    Pranav
    #include "jni.h"
    #include <iostream.h>
    void main() {
    JavaVM jvm;       / denotes a Java VM */
    JNIEnv env;       / pointer to native method interface */
    JavaVMInitArgs vm_args; /* VM initialization arguments */
    JNI_GetDefaultJavaVMInitArgs(&vm_args);
    jint ret;
    ret = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
    if (ret < 0) {
    cout << "Can't create JVM! Error: " << ret << endl;
    jclass cls = env->FindClass("Prog");
    jmethodID mid = env->GetStaticMethodID(cls, "main", "(I)V");
    env->CallStaticVoidMethod(cls, mid, 100);
    jvm->DestroyJavaVM();

    try this one:
    //----------------------c-part----------------------------
    #include "jni.h" //jvm.lib
    #include <string>
    #include <iostream>
    #include <stdlib.h>
    int main()
         const int numberofargs=1;
    JavaVMInitArgs vm_args;
    JavaVMOption options[numberofargs];
    JNIEnv *env=NULL;
    JavaVM *jvm=NULL;
         std::string tmpstr="-Djava.class.path=.;";
         options[0].optionString=(char * )tmpstr.c_str();
         vm_args.version=JNI_VERSION_1_4;
    vm_args.options=options;
    vm_args.nOptions=numberofargs;
    vm_args.ignoreUnrecognized=JNI_TRUE;
         if((jint)JNI_CreateJavaVM(&jvm,(void**)&env,&vm_args)<0)
    std::cerr << "ERROR:Java Virtual Machine NOT initialized!" << std::endl;
              exit(-1);
         jclass cls;
         if((cls = (jclass)env->FindClass("Hello"))==NULL)
    std::cerr << "ERROR:class not found!" << std::endl;
              exit(-1);
         jmethodID mid;
         if((mid=(jmethodID)env->GetStaticMethodID(cls,"main","([Ljava/lang/String;)V"))==NULL)
    std::cerr << "ERROR:constructor-method not found!" << std::endl;
              exit(-1);
         jint length=100;
         jint i=0;
         jobject valueobj;
         jclass valuecls;
         jmethodID valuemid;
         jstring jstr;
         jobjectArray valuejoa;
         valuecls=(jclass)env->FindClass("Ljava/lang/String;");
         valuemid=env->GetMethodID(valuecls,"<init>","(Ljava/lang/String;)V");
         valuejoa= env->NewObjectArray(length,valuecls,NULL);
         char buffer[20];
         for(i=0;i<length;i++)
              _itoa( i, buffer, 10 );
              jstr=env->NewStringUTF(buffer);
              valueobj=env->NewObject(valuecls,valuemid,jstr);
              env->SetObjectArrayElement(valuejoa,i,valueobj);
         env->CallStaticVoidMethod(cls, mid, valuejoa);
         jvm->DestroyJavaVM();     
         return 0;
    //----------------------java-part--------------------------
    public class Hello
         public Hello()
         public static void main(String[] args)
              System.out.println("Hello World:");
              for(int i=0;i<args.length;i++)
                   System.out.println(args);
    the method "main" get strings, not integers.
    jens

  • JNI Invocation retry from JNI_ENOMEM leads to JNI_ERR

    We are using JNI Invocation from a C++ program to call from C++ to Java in a cross-platform Windows/Mac program. Usually this works great. Lately, though, we have been running into some issues on Windows XP (no problems so far on either Windows Vista or Mac OS X).
    In the problem cases, when we try to create the JVM, we get a JNI_ENOMEM error. This is odd since there appears to be plenty of memory available. We then try again, asking for less JVM memory. But that never seems to work - instead, we get a JNI_ERR message when retrying, at which point we are giving up. Asking for less memory does work when we do it the first time we try to create the JVM. But setting the maximum memory value that small would cause us to run out of JVM memory when handling larger data sets.
    Here's the basic code that we are using. Is there something obvious that we are doing wrong here when trying to create the JVM a second time?
    JavaVM *Jvm_mine;
    JNIEnv *Env_mine;
    JavaVMInitArgs vm_args;
    JavaVMOption options[3];
    char* classpathC;
    char* vmpathC;
    // Omitting classpathC and vmpathC assignment
    options[0].optionString = classpathC;
    options[1].optionString = "-Xms32m";
    options[2].optionString = "-Xmx512m"
    vm_args.version = JNI_VERSION_1_4;
    vm_args.options = options;
    vm_args.ignoreUnrecognized = JNI_TRUE;
    // JNU_FindCreateJavaVM taken from Liang's JNI book
    CreateJavaVM_t pCreateJVM = JNU_FindCreateJavaVM(vmpathC);
    result = pCreateJVM(&Jvm_mine, (void**)(&Env_mine), &vm_args);
    // Usually this works, but sometimes on XP we get JNI_ENOMEM
    if (result == JNI_ENOMEM) {
        options[2].optionString = "-Xmx256m";
        result = pCreateJVM(&Jvm_mine, (void**)(&Env_mine), &vm_args);
        // We nearly always get a JNI_ERR value in result here
    }Pointers to debugging tools we could use to figure out why we are getting either the first JNI_ENOMEM error or the second JNI_ERR error would also be appreciated.
    Thanks for any assistance!
    Michael

    I also need to destroy the jvm from w/in a dll but i havent been able to get it to work properly. So far, everything ive read in the forum says just dont use it. but i dont want to just leave it hanging around.
    if you hear anything different, please share. :)
    txjump

  • Help calling JNI function from a java thread

    I am using the following code to call a JNI fuction from a java thread:
    public class CMSMessageHandler extends MessageHandler{
    static{
    System.loadLibrary("jastb");
    public native int cmsReadIt(ByteBuffer buff);
    private ByteBuffer dirbuf = null;
    /** Creates a new instance of CMSMessageHandler */
    public CMSMessageHandler() {
    // allocate to max size datagram
    dirbuf = ByteBuffer.allocateDirect(65536);
    public void readMessages(){
    /*Thread worker = new Thread(){
    public void run(){*/
    int count;
    while (true){
    try{
    count = cmsReadIt(dirbuf);
    } catch (Exception e){
    e.printStackTrace();
    worker.start();*/
    public static void main(String[] args) {
    CMSMessageHandler handler = new CMSMessageHandler();
    handler.readMessages();
    When I run this main method with the thread commented out, it works great. When I run the main method with the thread, it works great for a while, and then funny things start happening with the native library I am using. My native library uses shared memory, signals, and semaphores. It feels a bit like my java program is stomping on the resources that my native library is using, when a run the java program with a thread.
    Is there something I don't know about calling native code from a thread? Should I be doing something explicitly to protect my native library's shared memory, signals, or semaphores?
    Thanks,
    Lisa.

    Does the library do any initialization when loaded? Does it make a dangerous assumption that the thead calling cmdReadIt will always be the same thread that initially loaded it? Try loading the library in the worker thread instead of in the main thread via the static initializer.Yes. There is a call to another native method cmsOpenIt that does CMS initialization. I put cmsOpenIt as well as the System.loadLibrary("jastb") in the worker thread and I'm still experiencing the same problems.
    Incidently, the mere presence of another Thread in this program does not seem to cause problems. It's only when I run calls to cmsReadIt in a thread that I get into trouble.
    For example, this works fine:
    public class CMSMessageHandler extends MessageHandler{
        public native int cmsReadIt(ByteBuffer buff);
        public ByteBuffer dirbuf = null;
        static {
            System.loadLibrary("jastb");
        public CMSMessageHandler() {
            // allocate to max size datagram
            dirbuf = ByteBuffer.allocateDirect(65536);
        public void readMessages(){
            try{
                int count = 0;
                while (true){
                    count = cmsReadIt(dirbuf);
            } catch (Exception e){
        public static void main(String[] args) {
            CMSMessageHandler handler = new CMSMessageHandler();
            Thread worker = new Thread(){
                public void run(){
                    while (true){
                        try{
                            Thread.currentThread().sleep(1000);
                            System.out.println("sleep thread.");
                        } catch (Exception e){
                            e.printStackTrace();
            worker.start();
            handler.readMessages();  
        }Are there JVM flags that I should experiment with that might help mitigate/diagnose this problem?

  • Create JVM from my own dll

    Hi all,
    I'm trying to create a JVM from within a windows dlln (vc++6) I'm writing. In the DllMain's DLL_PROCESS_ATTACH method of my dll I call a method called createJavaVM, this method creates the virtual machine.
    Using that method in a simple console application works ok, but using it in my dll it hangs and seems to wait forever. If I use -verbose:jni it shows 5 similar lines, all about [Dynamic linking native method java.lang.... JNI].
    I'm using jdk1.5.0_04.
    Can someone help me with this problem?
    TiA
    Alexander

    see here.    You will need the Pro version of LabVIEW or purchase tha application builder from NI
    Paul <--Always Learning!!!
    sense and simplicity.
    Browse my sample VIs?

  • Unable to create JVM

    Hi !
    In my project, i need to call a java method from C code using JNI.
    Here is the Java code:
    public class Prog{
         public static void main(String args[]){
              System.out.println("Hello Java Native"+args[0]);
    }And C code:
    #include <jni.h>
    void destroy (JNIEnv *env,JavaVM *jvm,char *str){.....}
    main(){
         JNIEnv *env;
         JavaVM *jvm;
         JavaVMInitArgs vm_args;
         JavaVMOption options[3];
         options[0].optionString = "-Djava.compiler=NONE";
         options[1].optionString = "-Djava.class.path=.";
         options[2].optionString = "-verbose:jni";
         memset (&vm_args,0,sizeof(vm_args));
                         vm_args.version = JNI_VERSION_1_4;
         vm_args.nOptions = 3;
                         vm_args.ignoreUnrecognized = JNI_TRUE;
         vm_args.options = options;
         /* Create Java VM */
         res = JNI_CreateJavaVM(&jvm,(void**)&env,&vm_args);
         if(res<0){
              fprintf(stderr,"Can't create Java VM\n");
              printf("%d",res);
              exit(1);
         (*env) -> CallStaticVoidMethod(env,cls,mid,args);
         (*jvm) -> DestroyJavaVM(jvm);
    }I think the code is alright.But when i run it , it tells me "Can't create Java VM".I guess there are some problems with Path or CLASSPATH? And i copy a (jre\bin\client)jvm.dll. Is there something wrong?
    Thank you for your help.�H

    Do NOT copy jvm.dll into your executable folder.
    instead simply set the Path environment variable appropriately before the execution
    set Path=C:\Program Files\Java\jre1.5.0_07\bin\client;%Path%
    yourExecutable.exeRegards

  • Calling JNI from a java sp.

    I read in 8.1.5 docs that JNI is not enabled in the Oracle JVM (for customers)
    Still the case in in 8.1.7?
    Has anyone (Brian?) had success when making RMI calls from the Oracle JVM?
    Thanks,
    Matt
    [email protected]

    Well, the problem with JNI, is a difficult issue. See, the C code would have to be linked with the Oracle executable itself and if not functionning properly (er, say core-dumping, or referencing random places in memory) could corrupt the quality of your precious data in the database. (For example, bogus code could overwrite data in the buffer caches). So JNI is indeed here and used in-house for most natives but is not available for customers. Sigh.
    Now, doing an RMI callout to a standalone RMI server that uses JNI is a GOOD IDEA. It's functional and recommended.
    The issues about RMI and scalability is when you want to use oracle itself as an RMI server. Not when you want to do RMI callouts.
    Hope this helps,
    matthieu

  • JNI + Timer, weird crash

    Hello people.
    First of all, I'd like to apologize beforehand for the long post. Also, I hope I'm posting on the right forum section.
    Here's the story:
    I'm working on an academic project, which involves a Java application calling C++ code, via JNI. I'm currently facing an issue, the exact cause of which I cannot track down, at least given my current grasp of Java, JNI, JVM etc.
    Before I get straight to the point, here's some background on the project, which I think may help in clarifying any possible subtleties of the problem. You can probably skip this paragraph safely though, and jump to the picture that is provided on the link below it, without missing too much. Basically, I'm working on implementing an AI (specifically Reinforcement Learning) experiment domain which is based on an open-source game, written in C++. A Java application (which can be thought of, as a platform for deploying AI experiments) is responsible for the control of the experiment execution, which is conducted on a step-by-step basis. The game is compiled as a dynamically loadable shared library, so that it can be loaded by a specific JNI component of the Java AI platform. Let me state at this point, that the Java application, as well as the JNI dynamic library loader that it features, were not implemented by myself. As a consequence, I'm not aware of the details concerning the JNI part of the implementation (I've peeked at the pure Java part though, and it seems pretty OK to me). My work lies on modifying the game code (C++), so that it can be integrated with the Java AI platform. The application features 2 modes of executing experiment steps. In the "manual" mode, a step is executed when a specific JButton is hit (I will henceforth refer to this execution mode, as JButton mode). On the other hand, there is a "batch" mode, where step execution is scheduled to happen on a fixed time interval, using the scheduleAtFixedRate method of the java.util.Timer class (Timer mode, henceforth). To make matters even more clear, here's a a sketch of the architecture of the system:
    [Sketch of the problem|http://users.auth.gr/~idaroglo/pub/fsitu.png]
    The problem is, that while the JButton mode works OK, the Timer mode doesn't. In that case, things crash on the native side (specifically on the OpenGL library, which is used to render the graphics of the game). This is quite weird I think, as the only difference between these 2 execution modes, is the way they call the native step function (I tried to illustrate in the picture linked above). So, a wild guess could be that something gets messed up, when the Timer gets involved in orchestrating the execution. I cannot put blame on the native shared library, as it functions properly in the case of the JButton mode. Having no other hint or indication of what causes this situation, I can only blame it on the Timer involvement (hence the thread title). I will post a sample JVM Hotspot crash log, as a reply to this one.
    Here are some things I've tried so far, to resolve this issue:
    1) Debugging with gdb. I tracked down which function of the OpenGL library causes the crash (btw, segmentation fault - SISEGV). I've been told by a fellow though, that this specific function cannot produce a segmentation fault and that the crash probably happens due to memory corruption. In case this speculation holds, a wild guess could be that the use of a timer, could be introducing memory corruption.
    2) I've skimmed through the JVM Troubleshooting guide, in the hope that I'll find some advice on how I should troubleshoot this situation. I'm bound to revisit this, hopefully after some feedback from the community.
    3) I've considered using valgrind to verify that memory corruption, but I'm not sure if that would make sense in the case of Java/JNI.
    4) I've tried setting the Timer's fixed time interval to a 20 seconds (20000ms), to make absolutely sure that the native method returns, before it is invoked by the timer for a consecutive time. Still things crash.
    5) I've tested the Java AI platform with a considerably simpler dynamic library (in terms of implementation), and both modes functioned OK. This probably indicates that I cannot blame it all, on the Timer alone.
    So, I would really appreciate some feedback on the following matters:
    1) Does any of the speculations above, concerning the cause of the problem, make sense to you?
    2) How should I proceed troubleshooting? Are there any recommended tools that might prove helpful in tracking down the cause of the problem?
    3) Should one employ extra care when using Timers in combination with JNI & native methods?
    4) How can one track down and troubleshoot memory corruption issues in the mixed mode scenario (JAVA+JNI)?
    That's all. Thanks for the time you spent reading this. Once more, I sincerely apologize for the long post.
    I really hope that collective experience and wisdom, will help me squash this issue.
    Thanks again.

    Hello again!
    Sorry to revive this thread after a long time, but this post might be helpful to anyone that might encounter a similar problem in the future.
    I am obliged to Paul Pluzhnikov, for identifying the cause of the problem. Wouldn't it be for his invaluable help, I would still have been stuck with this one.
    I quote part of his response, a while ago:
    Paul Pluzhnikov wrote:
    ....JVM log has register dump as well, and
    RAX=0x0000000000000000 in it. So your program tried to jump through a
    NULL pointer, and crashed with SIGSEGV since zero page of memory is
    not mapped into the process space on Linux.
    The more interesting question is "why is RAX NULL?"
    RAX was loaded in the previous instruction from the FS (thread-local
    storage on x86_64) segment register.
    Given all of the above, I will guess that the difference between the
    "JButton" and "Timer" execution is that in the "JButton" case you
    execute the call to JNI/game_step in the event dispatch thread, while
    in the "Timer" case you are not.
    The following (buggy) program demonstrates what I believe is
    essentially the same crash:
    // compile with "gcc -g main.c /usr/lib/libGL.so.1 -pthread"
    #include <pthread.h>
    #include <stdio.h>
    void *fn(void *p)
    printf("calling glHint on other thread\n");
    return glHint();
    int main(int argc, char *argv[])
    pthread_t tid;
    if (argc > 1) {
    printf("calling glHint on main thread\n");
    return glHint();
    pthread_create(&tid, 0, fn, 0);
    pthread_join(tid, 0);
    return 0;
    }Here is what I see on my system:
    gdb -q ./a.out
    (gdb) run
    [Thread debugging using libthread_db enabled]
    Using host libthread_db library "/lib/libthread_db.so.1".
    [New Thread 0x7ffff7ed4720 (LWP 19872)]
    [New Thread 0x40802950 (LWP 19875)]
    calling glHint on other thread
    Program received signal SIGSEGV, Segmentation fault.
    [Switching to Thread 0x40802950 (LWP 19875)]
    0x00007ffff7db62c9 in glHint () from /usr/lib/libGL.so.1
    (gdb) x/i $pc
    0x7ffff7db62c9 <glHint+9>:     jmpq *0x378(%rax)
    (gdb) p $rax
    $1 = 0 Notice the same instruction crash, and the same RAX == NULL (gdb) run 1
    [Thread debugging using libthread_db enabled]
    [New Thread 0x7ffff7ed4720 (LWP 19877)]
    calling glHint on main thread
    Program exited normally.
    (gdb) quitSo how do you fix this? The following may be helpful:
    [http://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.html] A few days later, I got some further input from Paul. I quote part of it as well, as I think it might also prove to be helpful for someone:
    Paul Pluzhnikov wrote:
    You probably don't actually have to jump through hoops to get the
    "game" executing on the event dispatch thread.
    What I think must happen is that the dlopen() of the "game" must
    be done in the same thread that the "step" will be done in.
    Alternatively, you may be able to force libGL to initialize its
    TLS storage for arbitrary thread, by using glXMakeCurrent.
    Here is some additional info which may be helpful:
    [http://www.equalizergraphics.com/documentation/parallelOpenGLFAQ.html]
    [http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/glx/xmakecurrent.html]
    I'd like to thank all of you, who provided any sort of input on this. Most of all, I'd like to thank Paul Pluzhnikov once more, for figuring the problem out.
    Hope this post will be helpful to someone in the future!
    Cheers!

Maybe you are looking for