Name: rlT66838 Date: 05/03/2000
java version "1.3.0rc3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc3-Z)
Java HotSpot(TM) Client VM (build 1.3.0rc3-Z, mixed mode)
I am working on an application that uses an embedded jvm, instantiated using
the JNI. For the most part, this works great. But, I am having difficulty when
I try to enable the remote debugging interface. I'm using the "JPDA Connection
and Invocation" doc as a reference.
I can start up a java program with the "java.exe" executable and the appropriate
debug options and then attach the jdb debugger later from another shell. That
works fine. But, when I try to pass the same debug arguments to a JVM that I
create through the JNI, I get a crash every time in the JNI_CreateJavaVM
function. If I remove the -Xrunjdwp argument, then the crash goes away.
I've included a simple test program that I wrote in Dev Studio to demonstrate
the problem.
I'm guessing that this should work. Any help would be greatly appriciated! It
would make my life much easier if I had a debugger. I'm going to experiment
with jdk1.2.2 and see if I can get any further.
------
// TestJVM.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <jni.h>
#define OPTION_COUNT 5
int main(int argc, char* argv[])
{
JavaVMInitArgs vm_args;
JavaVMOption options[OPTION_COUNT];
// Enable remote debugging
//
options[0].optionString = "-verbose:jni";
options[1].optionString = "-Xdebug";
options[2].optionString = "-Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=n";
/* for use with classic VM
options[3].optionString = "-Djava.compiler=NONE";
options[4].optionString = "-Xnoagent";
*/
// Set up options to be passed to the virtual machine when it is
// created.
//
vm_args.version = JNI_VERSION_1_2;
vm_args.options = options;
vm_args.nOptions = OPTION_COUNT;
vm_args.ignoreUnrecognized = 1;
// Create the virtual Machine
//
JNIEnv * jvmEnv = NULL;
JavaVM * vm = NULL;
jint ret = JNI_CreateJavaVM(&vm, (void **)&jvmEnv, &vm_args);
return 0;
}
(Review ID: 104417)
======================================================================
Name: tb29552 Date: 04/30/2001
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
Java HotSpot(TM) Server VM (build 1.3.0, mixed mode)
Invoke JNI_CreateJavaVM with an option set to "-Xrunjdwp:help", this will cause
a SEG_FAULT in arguments.cpp, line 475, due to trying to write to a const char
*. You need to copy the option to a separate buffer or store the length of
"name" in a variable so you don't need to use strlen() to get it.
(Review ID: 123351)
======================================================================
Response from the submitter:
I just read the update in the bug. I tried doing strdup's on my strings that I'm
passing as options so that I'm not using static strings anymore. That did indeed
fix the crash.
I'm a little curious as to why the JVM would be writing over my option strings. I
didn't do anything different than was suggested in the JNI docs that came with the
JDK 1.3.
I have not double checked to make sure that I can attach a debugger yet. But if that
works, then I'm in business.
You may, at the very least, consider updating the docs.
My work flow for recreating the bug is that I compile the attached program, ran it, and it crashed (NT 4.0 and JDK 1.3). I have an embedded JVM that I need to attach a debugger to.
The crash was preventing that. The tip in the bug update seems to make it possible.
// jnicrash.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <string.h>
#include <jni.h>
#define OPTION_COUNT 3
int main(int argc, char* argv[])
{
JavaVMInitArgs vm_args;
JavaVMOption options[OPTION_COUNT];
/*
// This version works
// Enable remote debugging
//
options[0].optionString = strdup( "-verbose:jni" );
options[1].optionString = strdup( "-Xdebug" );
options[2].optionString = strdup( "-Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=n" );
*/
// This version does not
// Enable remote debugging
//
options[0].optionString = "-verbose:jni";
options[1].optionString = "-Xdebug";
options[2].optionString = "-Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=n";
// Set up options to be passed to the virtual machine when it is
// created.
//
vm_args.version = JNI_VERSION_1_2;
vm_args.options = options;
vm_args.nOptions = OPTION_COUNT;
vm_args.ignoreUnrecognized = 1;
// Create the virtual Machine
//
JNIEnv * jvmEnv = NULL;
JavaVM * vm = NULL;
jint ret = JNI_CreateJavaVM(&vm, (void **)&jvmEnv, &vm_args);
return 0;
}
ranjith.mandala@Eng 2001-07-25