[kaffe] JNI Memory leak

Fernando Silveira fsilveira at provectus.com.br
Wed Mar 15 05:50:57 PST 2006


Hi,

I'm developing a JNI library to work with Kaffe and I'm having a kind of
memory leak issue.

Sometimes my lib needs to instantiate Java objects and call some
methods. If the objects are created and the methods are called with
success (without exceptions or errors) everything works fine. Sometimes
the JNI library needs to try to call an inexistant method and if the
method does not exist, it must not return to the JVM and must retry to
call other methods.

The issue occurs when it calls many times the GetMethodID() function and
it returns exceptions: Kaffe shows the following error:

FATAL ERROR: No more room for local references

I know this happens when I don't DeleteLocalRef() everything I have
created, but this situation seems to be different. The following code
proves what I'm trying to say:

jmethodID
test_GetMethodID(JNIEnv *jenv, jclass jcls, const char *name,
    const char *sig)
{
	jmethodID jmid;

	/* Force java.lang.NoSuchMethodError error. */
	name = "NoSuchMethod";

	do {
		jmid = (*jenv)->GetMethodID(jenv, jcls, name, sig);

		if ((*jenv)->ExceptionOccurred(jenv)) {
			(*jenv)->ExceptionDescribe(jenv);
			(*jenv)->ExceptionClear(jenv);
		}
	} while (jmid == 0);

	return jmid;
}

This function causes many exceptions and a final "FATAL ERROR: No more
room for local references" message.

I'm not sure but I think SUN JVM and SableVM also behaves this way,
because I can see the JVM memory growing up slowly when I call this
function but they don't limit the "reference room" size.

I tried Google and all the JNI documentation I have but I could not find
anything related to this. Am I missing something or doing something
wrong? Can't I call a lot of GetMethodID() with invalid method names? I
hope you can give me a hint or solution for my problem.

Thanks a lot.

-- 
Fernando Silveira <fsilveira at provectus.com.br>





More information about the kaffe mailing list