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!

JNI AttachCurrentThread causes core dump

843829Apr 9 2009 — edited Apr 17 2009
Hi Folks,
I have a case where i am calling AttachCurrentThread out of a native app on 64 bit sol sparc causes a core dump... specifically i am calling out of a dtor of thread specific data as below
void
tsd_dtor(
    void*
)
{
    //    fprintf(stderr, "tsd_dtor()\n");

    JNIEnv* 	     jni_env = 0;
    JavaVMAttachArgs args = {JNI_VERSION_1_4, 0, 0};

    jint ret = 0;
    if ((ret = gsd_jvm->AttachCurrentThread((void**)&jni_env, &args)) != 0)
    {
        fprintf(stderr, "FATAL: tsd_dtor(), AttachCurrentThread() failed, returned %d\n", ret);
        exit(1);
    }
    if ((ret = gsd_jvm->DetachCurrentThread()) != 0)
    {
        fprintf(stderr, "FATAL: tsd_dtor(), DetachCurrentThread() failed, returned %d\n", ret);
        exit(1);
    }
}
The ctor create_tsd creates the TSD. This native code lives in a .so which is loaded by a simple Java class which invokes the native create_tsd method in a thread..... as below
class JVMTest implements Runnable {
    public static void main(String args[]) throws Exception {
        final int num_threads = 10;
        while (true) {
            for(int i = 0; i < num_threads; ++i) {
                new Thread(new JVMTest()).start();
            }
            try {
                Thread.currentThread().sleep(50);
            }
            catch (InterruptedException e) {
            }
        }
    }
    public void run() {
        create_tsd();
    }
    native static void create_tsd();
    static {
        System.loadLibrary("jvm_test");
    }
when the thread finishes it then invokes the dtor which in turn calls the AttachCurrentThread. Here is some info from dbx..
dbx: warning: Some symbolic information might be incorrect.
t@12943829 (l@12943829) terminated by signal SEGV (access to address exceeded protections)
0xffffffffffffffff:     <bad address 0xffffffffffffffff>
Current function is JavaVM_::AttachCurrentThread
Here is the stack trace from the aforementioned thread
-----------------  lwp# 12943829 / thread# 12943829  --------------------
 7fffffff7806b970 * *java/lang/AbstractStringBuilder.<init>(I)V [compiled] 
 7fffffff7806d024 * *java/lang/StringBuilder.<init>()V [compiled] +4 (line 136)
 7fffffff7806d024 * *java/lang/Thread.<init>(Ljava/lang/ThreadGroup;Ljava/lang/Runnable;)V+48 (line 1510)
 7fffffff78000240 * StubRoutines (1)
 7fffffff7e97ad40 void JavaCalls::call_helper(JavaValue*,methodHandle*,JavaCallArguments*,Thread*) (7fffffff76cffa30, a, 7fffffff76cff720, 186aedc0
0, 1, 7ffffff970043c88) + 1c0
 7fffffff7ea01ba0 void JavaCalls::call_special(JavaValue*,Handle,KlassHandle,symbolHandle,symbolHandle,Handle,Handle,Thread*) (7fffffff76cffa30, 18
6a1c9d8, 186a1c9c8, 0, 0, 186a1c9c0) + d0
 7fffffff7eef7c74 void JavaThread::allocate_threadObj(Handle,char*,bool,Thread*) (186aedc00, 186a1c9c8, 0, 186a1c9d8, 186aedc00, 7fffffff7f22e5e8) 
+ 1b4
 7fffffff7ec750fc jni_AttachCurrentThread (10012a6d0, 7fffffff76cffcf8, 186aedc00, 186aedc00, 59000, 7fffffff7f1b6000) + 25c
 7fffffff76e00e18 int JavaVM_::AttachCurrentThread(void**,void*) (7fffffff7f205d80, 7fffffff76cffcf8, 7fffffff76cffce0, fb, 7fffffff7e201908, fffc0
0) + 30
 7fffffff76e00a3c tsd_dtor (deadbeef, 1cc4, 7fffffff7f7480c0, 7fffffff76cff95c, 7fffffff7f7480c0, 1c00) + 6c
 7fffffff7f5d5c00 tsd_exit (7fffffff7c903200, 1c00, 7fffffff7f7480c0, 1d00, 7fffffff76e009d0, deadbeef) + 80
 7fffffff7f5d2120 _thrp_exit (0, 1c00, 7fffffff7ff36420, 7fffffff7f73c000, 7fffffff7f7480c0, 7fffffff7c903200) + 128
 7fffffff7f5d9024 _t_cancel (0, 0, 20f8, 10760c, 7fffffff7e207888, 7fffffff7f73c000) + a0
 7fffffff7f5d5fe0 _lwp_start (0, 0, 0, 0, 0, 0)
I was using java 1.6 update 12 for this test. Is there something obviously wrong with this test or should i just open a bug?

thanks
arkle
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 15 2009
Added on Apr 9 2009
11 comments
842 views