JDK-6354345 : JDWP: Loading twice is not properly handled. Misleading error message.
  • Type: Bug
  • Component: core-svc
  • Sub-Component: debugger
  • Affected Version: 5.0u4,6
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2005-11-22
  • Updated: 2012-10-01
  • Resolved: 2005-12-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b65Fixed
Related Reports
Duplicate :  
Relates :  
Description
FULL JDK VERSION(S)
java version "1.5.0_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)
Java HotSpot(TM) Client VM (build 1.5.0_04-b05, mixed mode)
DESCRIPTION:
launching java with -Xrunjdwp (or agentlib:jdwp) specified twice (as can happen
easily through script errors in an invocation script) results in the unhelpful 
error message:
   ERROR: JDWP unable to get necessary JVMTI capabilities. ["debugInit.c",L279]
...and the JVM terminates.  This does not give the user any useful information on
the cause of the failure.
JDWP was clearly never coded to be loaded multiple times, its onload routine sets
various static variables and memsets to zeroes a global static area "gdata".  
That is not the issue here.
  
The issue is that it does not protect itself against such user error.  It does not 
check that it has not already been loaded and will blithely overwrite any previous 
settings and continue executing.  However it then hits an error it cannot handle 
and terminates with a misleading error message.
example command to produce the problem:
java -Xrunjdwp:transport=dt_socket,address=8000 
     -Xrunjdwp:transport=dt_socket,address=8000 HelloWorld
ERROR: JDWP unable to get necessary JVMTI capabilities. ["debugInit.c",L279]
[This bug is being submitted as a courtesy, in order to maintain uniformity between Sun & IBM JDKs.  It has been fixed in IBM JDKs.  
Please contact ###@###.### if you have questions.]

Comments
EVALUATION Detect JDWP agent being loaded twice, print out reasonable error message.
06-12-2005

SUGGESTED FIX ######### File: ./debugInit.c ######### (cd . && sccs diffs -C -w -s -b debugInit.c) ------- debugInit.c ------- *** /tmp/sccs.ZkaGqN Tue Dec 6 15:43:54 2005 --- debugInit.c Tue Dec 6 15:43:44 2005 *************** *** 151,156 **** --- 151,162 ---- jint jvmtiCompileTimeMinorVersion; jint jvmtiCompileTimeMicroVersion; + /* See if it's already loaded */ + if ( gdata!=NULL && gdata->isLoaded==JNI_TRUE ) { + ERROR_MESSAGE(("Cannot load this JVM TI agent twice, check your java command line for duplicate jdwp options.")); + return JNI_ERR; + } + /* If gdata is defined and the VM died, why are we here? */ if ( gdata!=NULL && gdata->vmDead ) { ERROR_MESSAGE(("JDWP unable to load, VM died")); *************** *** 163,168 **** --- 169,175 ---- ERROR_MESSAGE(("JDWP unable to allocate memory")); return JNI_ERR; } + gdata->isLoaded = JNI_TRUE; /* Start filling in gdata */ gdata->jvm = vm; *************** *** 335,340 **** --- 342,350 ---- JNIEXPORT void JNICALL Agent_OnUnload(JavaVM *vm) { + + gdata->isLoaded = JNI_FALSE; + /* Cleanup, but make sure VM is alive before using JNI, and * make sure JVMTI environment is ok before deallocating * memory allocated through JVMTI, which all of it is. ######### File: ./util.h ######### (cd . && sccs diffs -C -w -s -b util.h) ------- util.h ------- *** /tmp/sccs.HnairN Tue Dec 6 15:43:54 2005 --- util.h Tue Dec 6 15:36:31 2005 *************** *** 114,119 **** --- 114,122 ---- int objectsByIDsize; int objectsByIDcount; + /* Indication that the agent has been loaded */ + jboolean isLoaded; + } BackendGlobalData; extern BackendGlobalData * gdata;
06-12-2005

WORK AROUND Don't get the arguments wrong. But how to enforce that?
22-11-2005