< prev index next >

src/hotspot/os/bsd/os_bsd.cpp

Print this page




3247 }
3248 
3249 uint os::processor_id() {
3250   volatile int* mapping = get_apic_to_processor_mapping();
3251 
3252   uint eax = 0xb;
3253   uint ebx;
3254   uint ecx = 0;
3255   uint edx;
3256 
3257   __asm__ ("cpuid\n\t" : "+a" (eax), "+b" (ebx), "+c" (ecx), "+d" (edx) : );
3258 
3259   // Map from APIC id to a unique logical processor ID in the expected
3260   // [0, num_processors) range.
3261 
3262   uint apic_id = edx;
3263   int processor_id = Atomic::load(&mapping[apic_id]);
3264 
3265   while (processor_id < 0) {
3266     if (Atomic::cmpxchg(-2, &mapping[apic_id], -1)) {
3267       Atomic::store(Atomic::add(1, &next_processor_id) - 1, &mapping[apic_id]);
3268     }
3269     processor_id = Atomic::load(&mapping[apic_id]);
3270   }
3271 
3272   return (uint)processor_id;
3273 }
3274 #endif
3275 
3276 void os::set_native_thread_name(const char *name) {
3277 #if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
3278   // This is only supported in Snow Leopard and beyond
3279   if (name != NULL) {
3280     // Add a "Java: " prefix to the name
3281     char buf[MAXTHREADNAMESIZE];
3282     snprintf(buf, sizeof(buf), "Java: %s", name);
3283     pthread_setname_np(buf);
3284   }
3285 #endif
3286 }
3287 




3247 }
3248 
3249 uint os::processor_id() {
3250   volatile int* mapping = get_apic_to_processor_mapping();
3251 
3252   uint eax = 0xb;
3253   uint ebx;
3254   uint ecx = 0;
3255   uint edx;
3256 
3257   __asm__ ("cpuid\n\t" : "+a" (eax), "+b" (ebx), "+c" (ecx), "+d" (edx) : );
3258 
3259   // Map from APIC id to a unique logical processor ID in the expected
3260   // [0, num_processors) range.
3261 
3262   uint apic_id = edx;
3263   int processor_id = Atomic::load(&mapping[apic_id]);
3264 
3265   while (processor_id < 0) {
3266     if (Atomic::cmpxchg(-2, &mapping[apic_id], -1)) {
3267       Atomic::store(&mapping[apic_id], Atomic::add(1, &next_processor_id) - 1);
3268     }
3269     processor_id = Atomic::load(&mapping[apic_id]);
3270   }
3271 
3272   return (uint)processor_id;
3273 }
3274 #endif
3275 
3276 void os::set_native_thread_name(const char *name) {
3277 #if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
3278   // This is only supported in Snow Leopard and beyond
3279   if (name != NULL) {
3280     // Add a "Java: " prefix to the name
3281     char buf[MAXTHREADNAMESIZE];
3282     snprintf(buf, sizeof(buf), "Java: %s", name);
3283     pthread_setname_np(buf);
3284   }
3285 #endif
3286 }
3287 


< prev index next >