8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)

Fri, 08 Feb 2013 12:48:24 +0100

author
sla
date
Fri, 08 Feb 2013 12:48:24 +0100
changeset 4564
758935f7c23f
parent 4562
8d9fc28831cc
child 4565
7194f764221c

8006423: SA: NullPointerException in sun.jvm.hotspot.debugger.bsd.BsdThread.getContext(BsdThread.java:67)
Summary: Do not rely on mach thread port names to identify threads from SA
Reviewed-by: dholmes, minqi, rbackman

agent/src/os/bsd/MacosxDebuggerLocal.m file | annotate | diff | comparison | revisions
agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdDebugger.java file | annotate | diff | comparison | revisions
agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdDebuggerLocal.java file | annotate | diff | comparison | revisions
agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdThread.java file | annotate | diff | comparison | revisions
agent/src/share/classes/sun/jvm/hotspot/runtime/bsd_amd64/BsdAMD64JavaThreadPDAccess.java file | annotate | diff | comparison | revisions
src/os/bsd/vm/osThread_bsd.hpp file | annotate | diff | comparison | revisions
src/os/bsd/vm/os_bsd.cpp file | annotate | diff | comparison | revisions
src/os_cpu/bsd_x86/vm/vmStructs_bsd_x86.hpp file | annotate | diff | comparison | revisions
     1.1 --- a/agent/src/os/bsd/MacosxDebuggerLocal.m	Wed Feb 06 14:31:37 2013 -0800
     1.2 +++ b/agent/src/os/bsd/MacosxDebuggerLocal.m	Fri Feb 08 12:48:24 2013 +0100
     1.3 @@ -97,7 +97,8 @@
     1.4   * Method:    init0
     1.5   * Signature: ()V
     1.6   */
     1.7 -JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_init0(JNIEnv *env, jclass cls) {
     1.8 +JNIEXPORT void JNICALL 
     1.9 +Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_init0(JNIEnv *env, jclass cls) {
    1.10    symbolicatorID = (*env)->GetFieldID(env, cls, "symbolicator", "J");
    1.11    taskID = (*env)->GetFieldID(env, cls, "task", "J");
    1.12    CHECK_EXCEPTION;
    1.13 @@ -108,7 +109,11 @@
    1.14   * Method:    lookupByName0
    1.15   * Signature: (Ljava/lang/String;Ljava/lang/String;)J
    1.16   */
    1.17 -JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_lookupByName0(JNIEnv *env, jobject this_obj, jstring objectName, jstring symbolName) {
    1.18 +JNIEXPORT jlong JNICALL 
    1.19 +Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_lookupByName0(
    1.20 +  JNIEnv *env, jobject this_obj, 
    1.21 +  jstring objectName, jstring symbolName) 
    1.22 +{
    1.23    jlong address = 0;
    1.24  
    1.25  JNF_COCOA_ENTER(env);
    1.26 @@ -137,7 +142,11 @@
    1.27   * Method:    readBytesFromProcess0
    1.28   * Signature: (JJ)Lsun/jvm/hotspot/debugger/ReadResult;
    1.29   */
    1.30 -JNIEXPORT jbyteArray JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_readBytesFromProcess0(JNIEnv *env, jobject this_obj, jlong addr, jlong numBytes) {
    1.31 +JNIEXPORT jbyteArray JNICALL
    1.32 +Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_readBytesFromProcess0(
    1.33 +  JNIEnv *env, jobject this_obj, 
    1.34 +  jlong addr, jlong numBytes) 
    1.35 +{
    1.36    if (debug) printf("readBytesFromProcess called. addr = %llx numBytes = %lld\n", addr, numBytes);
    1.37  
    1.38    // must allocate storage instead of using former parameter buf
    1.39 @@ -209,12 +218,74 @@
    1.40    return array;
    1.41  }
    1.42  
    1.43 +
    1.44  /*
    1.45 - * Class:     sun_jvm_hotspot_debugger_macosx_MacOSXDebuggerLocal
    1.46 + * Lookup the thread_t that corresponds to the given thread_id.
    1.47 + * The thread_id should be the result from calling thread_info() with THREAD_IDENTIFIER_INFO
    1.48 + * and reading the m_ident_info.thread_id returned.
    1.49 + * The returned thread_t is the mach send right to the kernel port for the corresponding thread.
    1.50 + *
    1.51 + * We cannot simply use the OSThread._thread_id field in the JVM. This is set to ::mach_thread_self()
    1.52 + * in the VM, but that thread port is not valid for a remote debugger to access the thread.
    1.53 + */
    1.54 +thread_t
    1.55 +lookupThreadFromThreadId(task_t task, jlong thread_id) {
    1.56 +  if (debug) {
    1.57 +    printf("lookupThreadFromThreadId thread_id=0x%llx\n", thread_id);
    1.58 +  }
    1.59 +  
    1.60 +  thread_array_t thread_list = NULL;
    1.61 +  mach_msg_type_number_t thread_list_count = 0;
    1.62 +  thread_t result_thread = 0;
    1.63 +  int i;
    1.64 +  
    1.65 +  // get the list of all the send rights
    1.66 +  kern_return_t result = task_threads(task, &thread_list, &thread_list_count);
    1.67 +  if (result != KERN_SUCCESS) {
    1.68 +    if (debug) {
    1.69 +      printf("task_threads returned 0x%x\n", result);
    1.70 +    }
    1.71 +    return 0;
    1.72 +  }
    1.73 +  
    1.74 +  for(i = 0 ; i < thread_list_count; i++) {
    1.75 +    thread_identifier_info_data_t m_ident_info;
    1.76 +    mach_msg_type_number_t count = THREAD_IDENTIFIER_INFO_COUNT;
    1.77 +
    1.78 +    // get the THREAD_IDENTIFIER_INFO for the send right
    1.79 +    result = thread_info(thread_list[i], THREAD_IDENTIFIER_INFO, (thread_info_t) &m_ident_info, &count);
    1.80 +    if (result != KERN_SUCCESS) {
    1.81 +      if (debug) {
    1.82 +        printf("thread_info returned 0x%x\n", result);
    1.83 +      }
    1.84 +      break;
    1.85 +    }
    1.86 +    
    1.87 +    // if this is the one we're looking for, return the send right
    1.88 +    if (thread_id == m_ident_info.thread_id)
    1.89 +    {
    1.90 +      result_thread = thread_list[i];
    1.91 +      break;
    1.92 +    }
    1.93 +  }
    1.94 +  
    1.95 +  vm_size_t thread_list_size = (vm_size_t) (thread_list_count * sizeof (thread_t));
    1.96 +  vm_deallocate(mach_task_self(), (vm_address_t) thread_list, thread_list_count);
    1.97 +  
    1.98 +  return result_thread;
    1.99 +}
   1.100 +
   1.101 +
   1.102 +/*
   1.103 + * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
   1.104   * Method:    getThreadIntegerRegisterSet0
   1.105 - * Signature: (I)[J
   1.106 + * Signature: (J)[J
   1.107   */
   1.108 -JNIEXPORT jlongArray JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_getThreadIntegerRegisterSet0(JNIEnv *env, jobject this_obj, jint lwp_id) {
   1.109 +JNIEXPORT jlongArray JNICALL 
   1.110 +Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_getThreadIntegerRegisterSet0(
   1.111 +  JNIEnv *env, jobject this_obj, 
   1.112 +  jlong thread_id) 
   1.113 +{
   1.114    if (debug)
   1.115      printf("getThreadRegisterSet0 called\n");
   1.116  
   1.117 @@ -226,8 +297,9 @@
   1.118    int i;
   1.119    jlongArray registerArray;
   1.120    jlong *primitiveArray;
   1.121 +  task_t gTask = getTask(env, this_obj);
   1.122  
   1.123 -  tid = lwp_id;
   1.124 +  tid = lookupThreadFromThreadId(gTask, thread_id);
   1.125  
   1.126    result = thread_get_state(tid, HSDB_THREAD_STATE, (thread_state_t)&state, &count);
   1.127  
   1.128 @@ -328,19 +400,21 @@
   1.129  }
   1.130  
   1.131  /*
   1.132 - * Class:     sun_jvm_hotspot_debugger_macosx_MacOSXDebuggerLocal
   1.133 + * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
   1.134   * Method:    translateTID0
   1.135   * Signature: (I)I
   1.136   */
   1.137  JNIEXPORT jint JNICALL
   1.138 -Java_sun_jvm_hotspot_debugger_macosx_MacOSXDebuggerLocal_translateTID0(JNIEnv *env, jobject this_obj, jint tid) {
   1.139 +Java_sun_jvm_hotspot_debugger_macosx_MacOSXDebuggerLocal_translateTID0(
   1.140 +  JNIEnv *env, jobject this_obj, jint tid) 
   1.141 +{
   1.142    if (debug)
   1.143      printf("translateTID0 called on tid = 0x%x\n", (int)tid);
   1.144  
   1.145    kern_return_t result;
   1.146    thread_t foreign_tid, usable_tid;
   1.147    mach_msg_type_name_t type;
   1.148 -    
   1.149 +  
   1.150    foreign_tid = tid;
   1.151      
   1.152    task_t gTask = getTask(env, this_obj);
   1.153 @@ -361,7 +435,10 @@
   1.154   * Method:    attach0
   1.155   * Signature: (I)V
   1.156   */
   1.157 -JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_attach0__I(JNIEnv *env, jobject this_obj, jint jpid) {
   1.158 +JNIEXPORT void JNICALL 
   1.159 +Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_attach0__I(
   1.160 +  JNIEnv *env, jobject this_obj, jint jpid) 
   1.161 +{
   1.162  JNF_COCOA_ENTER(env);
   1.163    if (getenv("JAVA_SAPROC_DEBUG") != NULL)
   1.164      debug = JNI_TRUE;
   1.165 @@ -401,7 +478,10 @@
   1.166   * Method:    detach0
   1.167   * Signature: ()V
   1.168   */
   1.169 -JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_detach0(JNIEnv *env, jobject this_obj) {
   1.170 +JNIEXPORT void JNICALL 
   1.171 +Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_detach0(
   1.172 +  JNIEnv *env, jobject this_obj) 
   1.173 +{
   1.174  JNF_COCOA_ENTER(env);
   1.175    if (debug) printf("detach0 called\n");
   1.176  
   1.177 @@ -419,10 +499,13 @@
   1.178   * Method:    load_library
   1.179   * Signature: (Ljava/lang/String;)L
   1.180   */
   1.181 -JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_asm_Disassembler_load_1library(JNIEnv * env,
   1.182 -                                                                           jclass disclass,
   1.183 -                                                                           jstring jrepath_s,
   1.184 -                                                                           jstring libname_s) {
   1.185 +JNIEXPORT jlong JNICALL
   1.186 +Java_sun_jvm_hotspot_asm_Disassembler_load_1library(
   1.187 +  JNIEnv * env, 
   1.188 +  jclass disclass,
   1.189 +  jstring jrepath_s,
   1.190 +  jstring libname_s) 
   1.191 +{
   1.192    uintptr_t func = 0;
   1.193    const char* error_message = NULL;
   1.194    const char* java_home;
   1.195 @@ -533,13 +616,16 @@
   1.196   * Method:    decode
   1.197   * Signature: (Lsun/jvm/hotspot/asm/InstructionVisitor;J[BLjava/lang/String;J)V
   1.198   */
   1.199 -JNIEXPORT void JNICALL Java_sun_jvm_hotspot_asm_Disassembler_decode(JNIEnv * env,
   1.200 -                                                                    jobject dis,
   1.201 -                                                                    jobject visitor,
   1.202 -                                                                    jlong startPc,
   1.203 -                                                                    jbyteArray code,
   1.204 -                                                                    jstring options_s,
   1.205 -                                                                    jlong decode_instructions_virtual) {
   1.206 +JNIEXPORT void JNICALL
   1.207 +Java_sun_jvm_hotspot_asm_Disassembler_decode(
   1.208 +   JNIEnv * env,
   1.209 +   jobject dis,
   1.210 +   jobject visitor,
   1.211 +   jlong startPc,
   1.212 +   jbyteArray code,
   1.213 +   jstring options_s,
   1.214 +   jlong decode_instructions_virtual) 
   1.215 +{
   1.216    jboolean isCopy;
   1.217    jbyte* start = (*env)->GetByteArrayElements(env, code, &isCopy);
   1.218    jbyte* end = start + (*env)->GetArrayLength(env, code);
     2.1 --- a/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdDebugger.java	Wed Feb 06 14:31:37 2013 -0800
     2.2 +++ b/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdDebugger.java	Fri Feb 08 12:48:24 2013 +0100
     2.3 @@ -49,7 +49,7 @@
     2.4    public BsdAddress readCompKlassAddress(long address) throws DebuggerException;
     2.5    public BsdOopHandle readOopHandle(long address) throws DebuggerException;
     2.6    public BsdOopHandle readCompOopHandle(long address) throws DebuggerException;
     2.7 -  public long[]       getThreadIntegerRegisterSet(int lwp_id) throws DebuggerException;
     2.8 +  public long[]       getThreadIntegerRegisterSet(long unique_thread_id) throws DebuggerException;
     2.9    public long         getAddressValue(Address addr) throws DebuggerException;
    2.10    public Address      newAddress(long value) throws DebuggerException;
    2.11  
     3.1 --- a/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdDebuggerLocal.java	Wed Feb 06 14:31:37 2013 -0800
     3.2 +++ b/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdDebuggerLocal.java	Fri Feb 08 12:48:24 2013 +0100
     3.3 @@ -90,7 +90,7 @@
     3.4                                  throws DebuggerException;
     3.5      private native ClosestSymbol lookupByAddress0(long address)
     3.6                                  throws DebuggerException;
     3.7 -    private native long[] getThreadIntegerRegisterSet0(int lwp_id)
     3.8 +    private native long[] getThreadIntegerRegisterSet0(long unique_thread_id)
     3.9                                  throws DebuggerException;
    3.10      private native byte[] readBytesFromProcess0(long address, long numBytes)
    3.11                                  throws DebuggerException;
    3.12 @@ -400,10 +400,15 @@
    3.13      //
    3.14  
    3.15      /** From the ThreadAccess interface via Debugger and JVMDebugger */
    3.16 +    public ThreadProxy getThreadForIdentifierAddress(Address threadIdAddr, Address uniqueThreadIdAddr) {
    3.17 +        return new BsdThread(this, threadIdAddr, uniqueThreadIdAddr);
    3.18 +    }
    3.19 +    @Override
    3.20      public ThreadProxy getThreadForIdentifierAddress(Address addr) {
    3.21 -        return new BsdThread(this, addr);
    3.22 +        throw new RuntimeException("unimplemented");
    3.23      }
    3.24  
    3.25 +
    3.26      /** From the ThreadAccess interface via Debugger and JVMDebugger */
    3.27      public ThreadProxy getThreadForThreadId(long id) {
    3.28          return new BsdThread(this, id);
    3.29 @@ -455,22 +460,22 @@
    3.30      // Thread context access
    3.31      //
    3.32  
    3.33 -    public synchronized long[] getThreadIntegerRegisterSet(int lwp_id)
    3.34 +    public synchronized long[] getThreadIntegerRegisterSet(long unique_thread_id)
    3.35                                              throws DebuggerException {
    3.36          requireAttach();
    3.37          if (isCore) {
    3.38 -            return getThreadIntegerRegisterSet0(lwp_id);
    3.39 +            return getThreadIntegerRegisterSet0(unique_thread_id);
    3.40          } else {
    3.41              class GetThreadIntegerRegisterSetTask implements WorkerThreadTask {
    3.42 -                int lwp_id;
    3.43 +                long unique_thread_id;
    3.44                  long[] result;
    3.45                  public void doit(BsdDebuggerLocal debugger) {
    3.46 -                    result = debugger.getThreadIntegerRegisterSet0(lwp_id);
    3.47 +                    result = debugger.getThreadIntegerRegisterSet0(unique_thread_id);
    3.48                  }
    3.49              }
    3.50  
    3.51              GetThreadIntegerRegisterSetTask task = new GetThreadIntegerRegisterSetTask();
    3.52 -            task.lwp_id = lwp_id;
    3.53 +            task.unique_thread_id = unique_thread_id;
    3.54              workerThread.execute(task);
    3.55              return task.result;
    3.56          }
     4.1 --- a/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdThread.java	Wed Feb 06 14:31:37 2013 -0800
     4.2 +++ b/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdThread.java	Fri Feb 08 12:48:24 2013 +0100
     4.3 @@ -28,21 +28,23 @@
     4.4  
     4.5  class BsdThread implements ThreadProxy {
     4.6      private BsdDebugger debugger;
     4.7 -    private int           lwp_id;
     4.8 +    private int         thread_id;
     4.9 +    private long        unique_thread_id;
    4.10  
    4.11      /** The address argument must be the address of the _thread_id in the
    4.12          OSThread. It's value is result ::gettid() call. */
    4.13 -    BsdThread(BsdDebugger debugger, Address addr) {
    4.14 +    BsdThread(BsdDebugger debugger, Address threadIdAddr, Address uniqueThreadIdAddr) {
    4.15          this.debugger = debugger;
    4.16          // FIXME: size of data fetched here should be configurable.
    4.17          // However, making it so would produce a dependency on the "types"
    4.18          // package from the debugger package, which is not desired.
    4.19 -        this.lwp_id = (int) addr.getCIntegerAt(0, 4, true);
    4.20 +        this.thread_id = (int) threadIdAddr.getCIntegerAt(0, 4, true);
    4.21 +        this.unique_thread_id = uniqueThreadIdAddr.getCIntegerAt(0, 8, true);
    4.22      }
    4.23  
    4.24      BsdThread(BsdDebugger debugger, long id) {
    4.25          this.debugger = debugger;
    4.26 -        this.lwp_id = (int) id;
    4.27 +        this.thread_id = (int) id;
    4.28      }
    4.29  
    4.30      public boolean equals(Object obj) {
    4.31 @@ -50,19 +52,19 @@
    4.32              return false;
    4.33          }
    4.34  
    4.35 -        return (((BsdThread) obj).lwp_id == lwp_id);
    4.36 +        return (((BsdThread) obj).thread_id == thread_id);
    4.37      }
    4.38  
    4.39      public int hashCode() {
    4.40 -        return lwp_id;
    4.41 +        return thread_id;
    4.42      }
    4.43  
    4.44      public String toString() {
    4.45 -        return Integer.toString(lwp_id);
    4.46 +        return Integer.toString(thread_id);
    4.47      }
    4.48  
    4.49      public ThreadContext getContext() throws IllegalThreadStateException {
    4.50 -        long[] data = debugger.getThreadIntegerRegisterSet(lwp_id);
    4.51 +        long[] data = debugger.getThreadIntegerRegisterSet(unique_thread_id);
    4.52          ThreadContext context = BsdThreadContextFactory.createThreadContext(debugger);
    4.53          for (int i = 0; i < data.length; i++) {
    4.54              context.setRegister(i, data[i]);
     5.1 --- a/agent/src/share/classes/sun/jvm/hotspot/runtime/bsd_amd64/BsdAMD64JavaThreadPDAccess.java	Wed Feb 06 14:31:37 2013 -0800
     5.2 +++ b/agent/src/share/classes/sun/jvm/hotspot/runtime/bsd_amd64/BsdAMD64JavaThreadPDAccess.java	Fri Feb 08 12:48:24 2013 +0100
     5.3 @@ -28,6 +28,8 @@
     5.4  import java.util.*;
     5.5  import sun.jvm.hotspot.debugger.*;
     5.6  import sun.jvm.hotspot.debugger.amd64.*;
     5.7 +import sun.jvm.hotspot.debugger.bsd.BsdDebugger;
     5.8 +import sun.jvm.hotspot.debugger.bsd.BsdDebuggerLocal;
     5.9  import sun.jvm.hotspot.runtime.*;
    5.10  import sun.jvm.hotspot.runtime.amd64.*;
    5.11  import sun.jvm.hotspot.runtime.x86.*;
    5.12 @@ -38,8 +40,9 @@
    5.13    private static AddressField  lastJavaFPField;
    5.14    private static AddressField  osThreadField;
    5.15  
    5.16 -  // Field from OSThread
    5.17 +  // Fields from OSThread
    5.18    private static CIntegerField osThreadThreadIDField;
    5.19 +  private static CIntegerField osThreadUniqueThreadIDField;
    5.20  
    5.21    // This is currently unneeded but is being kept in case we change
    5.22    // the currentFrameGuess algorithm
    5.23 @@ -61,7 +64,8 @@
    5.24      lastJavaFPField         = anchorType.getAddressField("_last_Java_fp");
    5.25  
    5.26      Type osThreadType = db.lookupType("OSThread");
    5.27 -    osThreadThreadIDField   = osThreadType.getCIntegerField("_thread_id");
    5.28 +    osThreadThreadIDField = osThreadType.getCIntegerField("_thread_id");
    5.29 +    osThreadUniqueThreadIDField = osThreadType.getCIntegerField("_unique_thread_id");
    5.30    }
    5.31  
    5.32    public    Address getLastJavaFP(Address addr) {
    5.33 @@ -125,8 +129,9 @@
    5.34      Address osThreadAddr = osThreadField.getValue(addr);
    5.35      // Get the address of the _thread_id from the OSThread
    5.36      Address threadIdAddr = osThreadAddr.addOffsetTo(osThreadThreadIDField.getOffset());
    5.37 +    Address uniqueThreadIdAddr = osThreadAddr.addOffsetTo(osThreadUniqueThreadIDField.getOffset());
    5.38  
    5.39 -    JVMDebugger debugger = VM.getVM().getDebugger();
    5.40 -    return debugger.getThreadForIdentifierAddress(threadIdAddr);
    5.41 +    BsdDebuggerLocal debugger = (BsdDebuggerLocal) VM.getVM().getDebugger();
    5.42 +    return debugger.getThreadForIdentifierAddress(threadIdAddr, uniqueThreadIdAddr);
    5.43    }
    5.44  }
     6.1 --- a/src/os/bsd/vm/osThread_bsd.hpp	Wed Feb 06 14:31:37 2013 -0800
     6.2 +++ b/src/os/bsd/vm/osThread_bsd.hpp	Fri Feb 08 12:48:24 2013 +0100
     6.3 @@ -49,6 +49,11 @@
     6.4    // (e.g. pthread_kill).
     6.5    pthread_t _pthread_id;
     6.6  
     6.7 +  // This is the "thread_id" from struct thread_identifier_info. According to a
     6.8 +  // comment in thread_info.h, this is a "system-wide unique 64-bit thread id".
     6.9 +  // The value is used by SA to correlate threads.
    6.10 +  uint64_t _unique_thread_id;
    6.11 +
    6.12    sigset_t _caller_sigmask; // Caller's signal mask
    6.13  
    6.14   public:
    6.15 @@ -77,6 +82,10 @@
    6.16      _pthread_id = tid;
    6.17    }
    6.18  
    6.19 +  void set_unique_thread_id(uint64_t id) {
    6.20 +    _unique_thread_id = id;
    6.21 +  }
    6.22 +
    6.23    // ***************************************************************
    6.24    // suspension support.
    6.25    // ***************************************************************
     7.1 --- a/src/os/bsd/vm/os_bsd.cpp	Wed Feb 06 14:31:37 2013 -0800
     7.2 +++ b/src/os/bsd/vm/os_bsd.cpp	Fri Feb 08 12:48:24 2013 +0100
     7.3 @@ -657,6 +657,18 @@
     7.4  objc_registerThreadWithCollector_t objc_registerThreadWithCollectorFunction = NULL;
     7.5  #endif
     7.6  
     7.7 +#ifdef __APPLE__
     7.8 +static uint64_t locate_unique_thread_id() {
     7.9 +  // Additional thread_id used to correlate threads in SA
    7.10 +  thread_identifier_info_data_t     m_ident_info;
    7.11 +  mach_msg_type_number_t            count = THREAD_IDENTIFIER_INFO_COUNT;
    7.12 +
    7.13 +  thread_info(::mach_thread_self(), THREAD_IDENTIFIER_INFO,
    7.14 +              (thread_info_t) &m_ident_info, &count);
    7.15 +  return m_ident_info.thread_id;
    7.16 +}
    7.17 +#endif
    7.18 +
    7.19  // Thread start routine for all newly created threads
    7.20  static void *java_start(Thread *thread) {
    7.21    // Try to randomize the cache line index of hot stack frames.
    7.22 @@ -685,6 +697,7 @@
    7.23  #ifdef __APPLE__
    7.24    // thread_id is mach thread on macos
    7.25    osthread->set_thread_id(::mach_thread_self());
    7.26 +  osthread->set_unique_thread_id(locate_unique_thread_id());
    7.27  #else
    7.28    // thread_id is pthread_id on BSD
    7.29    osthread->set_thread_id(::pthread_self());
    7.30 @@ -847,6 +860,7 @@
    7.31    // Store pthread info into the OSThread
    7.32  #ifdef __APPLE__
    7.33    osthread->set_thread_id(::mach_thread_self());
    7.34 +  osthread->set_unique_thread_id(locate_unique_thread_id());
    7.35  #else
    7.36    osthread->set_thread_id(::pthread_self());
    7.37  #endif
     8.1 --- a/src/os_cpu/bsd_x86/vm/vmStructs_bsd_x86.hpp	Wed Feb 06 14:31:37 2013 -0800
     8.2 +++ b/src/os_cpu/bsd_x86/vm/vmStructs_bsd_x86.hpp	Fri Feb 08 12:48:24 2013 +0100
     8.3 @@ -35,17 +35,16 @@
     8.4    /* Threads (NOTE: incomplete) */                                                                                                   \
     8.5    /******************************/                                                                                                   \
     8.6    nonstatic_field(OSThread,                      _thread_id,                                      OSThread::thread_id_t)             \
     8.7 -  nonstatic_field(OSThread,                      _pthread_id,                                     pthread_t)
     8.8 +  nonstatic_field(OSThread,                      _unique_thread_id,                               uint64_t)
     8.9  
    8.10  
    8.11  #define VM_TYPES_OS_CPU(declare_type, declare_toplevel_type, declare_oop_type, declare_integer_type, declare_unsigned_integer_type, declare_c1_toplevel_type, declare_c2_type, declare_c2_toplevel_type) \
    8.12                                                                            \
    8.13    /**********************/                                                \
    8.14 -  /* Posix Thread IDs   */                                                \
    8.15 +  /* Thread IDs         */                                                \
    8.16    /**********************/                                                \
    8.17                                                                            \
    8.18 -  declare_unsigned_integer_type(OSThread::thread_id_t)                    \
    8.19 -  declare_unsigned_integer_type(pthread_t)
    8.20 +  declare_unsigned_integer_type(OSThread::thread_id_t)
    8.21  
    8.22  #define VM_INT_CONSTANTS_OS_CPU(declare_constant, declare_preprocessor_constant, declare_c1_constant, declare_c2_constant, declare_c2_preprocessor_constant)
    8.23  

mercurial