JDK-4335526 : Crash when enabling remote debugging in jvm created using jni
  • Type: Bug
  • Component: hotspot
  • Sub-Component: svc
  • Affected Version: 1.3.0,1.4.1
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS:
    generic,solaris_8,windows_nt,windows_2000 generic,solaris_8,windows_nt,windows_2000
  • CPU: generic,x86,sparc
  • Submitted: 2000-05-03
  • Updated: 2023-12-13
  • Resolved: 2013-08-20
Description

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

Comments
We don't support JDK 1.3. Closing.
20-08-2013

EVALUATION can't reproduce it david.wallman@Eng 2001-06-22 ===================================================================== I had sent a mail to the submitter asking for the necessary information needed and the exact steps to be followed in order to reproduce the problem. ranjith.mandala@Eng 2001-07-18 I received the response from the submitter which i have put in the description. Please also see the comments section. ranjith.mandala@Eng 2001-07-25 ###@###.### 2002-05-30 The example in the description is faulty in that vm_args.nOptions is set to 5, yet vm_args.options[3] and [4] are not initialized. When this is fixed, and we link against libjvm_g, then we get an assert, because the user property list has no elements. This is legal, so the assert is bogus. In order to catch cases of the argument processing code writing into the user's strings, I have inserted "const" qualifiers in many places, and have found a few potential problems, however none of these appear relevent to the test, and the test appears to work (although I have not atteched to it with a bebugger yet either.
17-09-2004

WORK AROUND Name: tb29552 Date: 04/30/2001 An -Xrun option with a ':' needs to be stored in a temporary buffer before being passed to JNI_CreateJavaVM. (Review ID: 123351) ======================================================================
17-09-2004

PUBLIC COMMENTS .
17-09-2004