Help with JDPA failure on JVM Startup from C++ using JNI_CreateJavaVM

The short version:

When I try to start a jvm with the -Xrunjdwp from C++ using JNI_CreateJavaVM and the following settings, it simply crashes. I can run my program just fine when this option is not present.

JavaVMOption aoOptions[5];

aoOptions[0].optionString = m_ustrClassPath.GetStringA();

aoOptions[1].optionString = "-Xdebug";

aoOptions[2].optionString = "-Xnoagent";

aoOptions[3].optionString = "-Djava.compiler=NONE";

aoOptions[4].optionString = "-Xrunjdwp:transport=dt_socket,address=localhost:8000,server=y,suspend=n";

I have all the appropriate jar files on the classpath and the DLL's are on the path. I am running 1.4.2. I have also tried dt_shmem and a combination of most of the adjustable paramaters being on/off or not present. Any help would be greatly appreciated!!!

Thanks,

Chris

The long version (or why I want to do this crazy thing):

I am migrating a product line from Visual Basic/C++/COM to Java. I recently purchased JBuilder 9 with the hope that I could use the attach to running JVM process to debug fully. When I attempted to add the neccessary options, my jvm create dies. I can't get to a point to attach from JBuilder.

[1229 byte] By [foxxlf23a] at [2007-9-29 6:44:38]
# 1

Is there any information available from the crash?

Do you get an error traceback, or a SIGSEGV, or some

other message?

I just tried a simple run based on your command line

and got this error:

% java -Xdebug \

-Xrunjdwp:transport=dt_socket,address=localhost:8000,server=y,suspend=n HelloWorld

Invalid listen port number: localhost:8000

Transport dt_socket failed to initialize, rc = -1.

FATAL ERROR in native method: No transports initialized

Since you have "server=y", this VM will be listening for

an attach and the hostname is not needed (it is implicitly

going to be the machine you are running on). Try this:

% java -Xdebug \

-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n HelloWorld

Hello, world!

As a side note, the options -Xnoagent and -Djava.compiler=NONE

are obsolete in any HotSpot Virtual Machine. They will be ignored. For

more information:

http://java.sun.com/j2se/1.4.2/docs/guide/jpda/conninv.html

debugging_teama at 2007-7-14 20:45:50 > top of Java-index,Archived Forums,Debugging Tools and Techniques...
# 2
Hi,I'm having the exact problem. Have you found a solution yet?-Anqing
anx2a at 2007-7-14 20:45:50 > top of Java-index,Archived Forums,Debugging Tools and Techniques...
# 3

I have not found a solution to this problem. I am going to renew efforts to solve this issue. It would be nice if someone involved in this portion of the system at SUN would pay attention to this. I would think that my company is not the only entity that needs to start a JVM from within C++ and then debug the java code by attaching to the process.

foxxlf23a at 2007-7-14 20:45:50 > top of Java-index,Archived Forums,Debugging Tools and Techniques...
# 4

I have finally found a solution...

Please see this bug: http://developer.java.sun.com/developer/bugParade/bugs/4335526.html

The bug has not been fixed but a workaround exists. Please see the bug for full information, the short answer is this.

When using the below settings, the -Xrun option is causing an Access Exception crash within jvm.dll. This seems to be because the -Xrun string is modified within jvm.dll.

JavaVMOption aoOptions[5];

aoOptions[0].optionString = m_ustrClassPath.GetStringA();

aoOptions[1].optionString = "-Xdebug";

aoOptions[2].optionString = "-Xnoagent";

aoOptions[3].optionString = "-Djava.compiler=NONE";

aoOptions[4].optionString = "-Xrunjdwp:transport=dt_socket,address=localhost:8000,server=y,suspend=n";

The solution that worked for me was to use strdup as indicated in the workaround for the bug.

JavaVMOption aoOptions[5];

pTempStrOption = m_ustrClassPath.GetStringA();

aoOptions[0].optionString = strdup(pTempStrOption);

aoOptions[1].optionString = strdup("-Xdebug");

aoOptions[2].optionString = strdup("-Xnoagent");

aoOptions[3].optionString = strdup("-Djava.compiler=NONE");

aoOptions[4].optionString = strdup("-Xrunjdwp:transport=dt_socket,address=3333,server=y");

This has caused me grief for months. It was not easy to locate in the bug database. It existed in 1.3 and still exists as of 1.4.2. I am not sure about the 1.5 beta.

foxxlf23a at 2007-7-14 20:45:50 > top of Java-index,Archived Forums,Debugging Tools and Techniques...