Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Debugging C++/JNI code

800358Sep 3 2008 — edited Sep 6 2008
Ok, "JNI izing" a C++ dll built in VC7. Am working in Eclipse using a dual nature project (first Java then convert to C/C++). Am using an Ant build.xml to compile the Java code run javah and finally compile and link the C++ code into a dll. All this goes great.
I viewed the generated dll with Anywhere PE Viewer and the functions I have implemented are in the export table.
At runtime I get a fatal error. Using the Java print statement, I am able to verify that my generated dll is loaded. The main function calls the constructor of the Java class which in turn calls one native method which in turn calls one JNI C++ function. That function is as follows:
JNIEXPORT jlong JNICALL Java_com_sra_pipeline_servers_summarizer_JSummarizer_createSummarizer
  (JNIEnv *env, jobject object, jstring resource_dir, jstring license, jstring key) {
	jlong summPtr;
	const char *rdir;
	rdir = env->GetStringUTFChars(resource_dir, NULL);
	printf("rdir %s \n", rdir);
	if(rdir == NULL) {
		return 0; /*exception occurred*/
	}
	const char *lic;
	lic = env->GetStringUTFChars(license, NULL);
	printf("lic %s \n", lic);
	if(lic == NULL) {
		return 0; /*exception ocurred*/
	}
	const char *ckey;
	ckey = env->GetStringUTFChars(key, NULL);
	if(ckey == NULL) {
		return 0; /* exception occurred */
	}
	printf("ckey %s \n", ckey);
	DebugBreak();
	summarizer summarizer(rdir, lic, ckey);
	DebugBreak();
	env->ReleaseStringUTFChars(resource_dir, rdir);
	env->ReleaseStringUTFChars(license, lic);
	env->ReleaseStringUTFChars(key, ckey);
	summPtr = (jlong)((long)&summarizer);
	return(summPtr);
}
Used "DebugBreak()" to move down line by line and find the problem area.
The problem line is summarizer summarizer(rdir, lic, ckey);
In the header file this function is defined as:
 summarizer(const char* resource_dir, const char* license_file, const char* key) 
In the JNI C++ file I am using the namespace inxight in which all these functions reside.
In the function above, the printf yeilds:
rdir lang
lic license/license.dat
ckey 686978757870
this agrees with the input.
However, when in VSC++ debug mode the variables are displayed as:
ckey 0x003ffce0 "pɘ"Xý?" const char *
lic 0x003ffcfc "å" const char *
rdir 0x00000000 <Bad Ptr> const char * CXX0030: Error: expression cannot be evaluated const char

This value "lang" is a dir in the root of my project, just license which it finds, so what other reason might there for "lang" generating a bad pointer?
Jim
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 4 2008
Added on Sep 3 2008
3 comments
414 views