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!

Why does using a static jclass variable within a method crash the JVM?

843829Sep 3 2009 — edited Sep 20 2009
I have some native code, that in a single thread, loops over a Java method. To improve performance, I tried this:
    static jclass clazz = env->FindClass("foo");
    /*FIXME: GetStaticMethodID crashes with "Bad global or local reference"*/
    jmethodID mid = env->GetStaticMethodID(clazz, "makeEvent", sig);
But with the static declaration of clazz, the JVM crashes on the second iteration. Why? Is this really any different then using a C++ member field ?

My loop is really a bit more complicated then this, in that it starts several calls up. I hate the idea of

A) actually calling FindClass every iteration.

B) passing the clazz pointer through 3 layers of calls, just to avoid calling FindClass

Is there a better way?
Thanks!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 18 2009
Added on Sep 3 2009
10 comments
351 views