7132070: Use a mach_port_t as the OSThread thread_id rather than pthread_t on BSD/OSX
Summary: Change OSThread to use mach thread_t
Reviewed-by: phh, dcubed
--- a/hotspot/src/cpu/x86/vm/vm_version_x86.cpp Fri Feb 17 15:55:27 2012 -0800
+++ b/hotspot/src/cpu/x86/vm/vm_version_x86.cpp Sun Feb 19 13:11:39 2012 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -65,8 +65,8 @@
address generate_getPsrInfo() {
// Flags to test CPU type.
- const uint32_t EFL_AC = 0x40000;
- const uint32_t EFL_ID = 0x200000;
+ const uint32_t HS_EFL_AC = 0x40000;
+ const uint32_t HS_EFL_ID = 0x200000;
// Values for when we don't have a CPUID instruction.
const int CPU_FAMILY_SHIFT = 8;
const uint32_t CPU_FAMILY_386 = (3 << CPU_FAMILY_SHIFT);
@@ -100,7 +100,7 @@
//
// if we are unable to change the AC flag, we have a 386
//
- __ xorl(rax, EFL_AC);
+ __ xorl(rax, HS_EFL_AC);
__ push(rax);
__ popf();
__ pushf();
@@ -118,7 +118,7 @@
//
__ bind(detect_486);
__ mov(rax, rcx);
- __ xorl(rax, EFL_ID);
+ __ xorl(rax, HS_EFL_ID);
__ push(rax);
__ popf();
__ pushf();
--- a/hotspot/src/os/bsd/vm/osThread_bsd.cpp Fri Feb 17 15:55:27 2012 -0800
+++ b/hotspot/src/os/bsd/vm/osThread_bsd.cpp Sun Feb 19 13:11:39 2012 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -49,7 +49,11 @@
void OSThread::pd_initialize() {
assert(this != NULL, "check");
+#ifdef __APPLE__
+ _thread_id = 0;
+#else
_thread_id = NULL;
+#endif
_pthread_id = NULL;
_siginfo = NULL;
_ucontext = NULL;
--- a/hotspot/src/os/bsd/vm/osThread_bsd.hpp Fri Feb 17 15:55:27 2012 -0800
+++ b/hotspot/src/os/bsd/vm/osThread_bsd.hpp Sun Feb 19 13:11:39 2012 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -40,10 +40,17 @@
private:
#ifdef _ALLBSD_SOURCE
- // _thread_id and _pthread_id are the same on BSD
- // keep both to minimize code divergence in os_bsd.cpp
+
+#ifdef __APPLE__
+ thread_t _thread_id;
+#else
pthread_t _thread_id;
+#endif
+
+ // _pthread_id is the pthread id, which is used by library calls
+ // (e.g. pthread_kill).
pthread_t _pthread_id;
+
#else
// _thread_id is kernel thread id (similar to LWP id on Solaris). Each
// thread has a unique thread_id (BsdThreads or NPTL). It can be used
@@ -64,9 +71,15 @@
void set_caller_sigmask(sigset_t sigmask) { _caller_sigmask = sigmask; }
#ifdef _ALLBSD_SOURCE
+#ifdef __APPLE__
+ thread_t thread_id() const {
+ return _thread_id;
+ }
+#else
pthread_t thread_id() const {
return _thread_id;
}
+#endif
#else
pid_t thread_id() const {
return _thread_id;
@@ -84,9 +97,15 @@
}
#endif // ASSERT
#ifdef _ALLBSD_SOURCE
+#ifdef __APPLE__
+ void set_thread_id(thread_t id) {
+ _thread_id = id;
+ }
+#else
void set_thread_id(pthread_t id) {
_thread_id = id;
}
+#endif
#else
void set_thread_id(pid_t id) {
_thread_id = id;
--- a/hotspot/src/os/bsd/vm/os_bsd.cpp Fri Feb 17 15:55:27 2012 -0800
+++ b/hotspot/src/os/bsd/vm/os_bsd.cpp Sun Feb 19 13:11:39 2012 +0100
@@ -998,8 +998,13 @@
}
#ifdef _ALLBSD_SOURCE
+#ifdef __APPLE__
+ // thread_id is mach thread on macos
+ osthread->set_thread_id(::mach_thread_self());
+#else
// thread_id is pthread_id on BSD
osthread->set_thread_id(::pthread_self());
+#endif
#else
// thread_id is kernel thread id (similar to Solaris LWP id)
osthread->set_thread_id(os::Bsd::gettid());
@@ -1190,7 +1195,11 @@
// Store pthread info into the OSThread
#ifdef _ALLBSD_SOURCE
+#ifdef __APPLE__
+ osthread->set_thread_id(::mach_thread_self());
+#else
osthread->set_thread_id(::pthread_self());
+#endif
#else
osthread->set_thread_id(os::Bsd::gettid());
#endif
@@ -1807,7 +1816,13 @@
return n;
}
-intx os::current_thread_id() { return (intx)pthread_self(); }
+intx os::current_thread_id() {
+#ifdef __APPLE__
+ return (intx)::mach_thread_self();
+#else
+ return (intx)::pthread_self();
+#endif
+}
int os::current_process_id() {
// Under the old bsd thread library, bsd gives each thread
@@ -5152,9 +5167,9 @@
struct thread_basic_info tinfo;
mach_msg_type_number_t tcount = THREAD_INFO_MAX;
kern_return_t kr;
- mach_port_t mach_thread;
-
- mach_thread = pthread_mach_thread_np(thread->osthread()->thread_id());
+ thread_t mach_thread;
+
+ mach_thread = thread->osthread()->thread_id();
kr = thread_info(mach_thread, THREAD_BASIC_INFO, (thread_info_t)&tinfo, &tcount);
if (kr != KERN_SUCCESS)
return -1;
--- a/hotspot/src/os_cpu/bsd_x86/vm/vmStructs_bsd_x86.hpp Fri Feb 17 15:55:27 2012 -0800
+++ b/hotspot/src/os_cpu/bsd_x86/vm/vmStructs_bsd_x86.hpp Sun Feb 19 13:11:39 2012 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -29,12 +29,18 @@
// constants required by the Serviceability Agent. This file is
// referenced by vmStructs.cpp.
+#ifdef __APPLE__
+#define OS_THREAD_ID_TYPE thread_t
+#else
+#define OS_THREAD_ID_TYPE pthread_t
+#endif
+
#define VM_STRUCTS_OS_CPU(nonstatic_field, static_field, unchecked_nonstatic_field, volatile_nonstatic_field, nonproduct_nonstatic_field, c2_nonstatic_field, unchecked_c1_static_field, unchecked_c2_static_field, last_entry) \
\
/******************************/ \
/* Threads (NOTE: incomplete) */ \
/******************************/ \
- nonstatic_field(OSThread, _thread_id, pthread_t) \
+ nonstatic_field(OSThread, _thread_id, OS_THREAD_ID_TYPE) \
nonstatic_field(OSThread, _pthread_id, pthread_t) \
/* This must be the last entry, and must be present */ \
last_entry()
@@ -46,7 +52,7 @@
/* Posix Thread IDs */ \
/**********************/ \
\
- declare_integer_type(pid_t) \
+ declare_unsigned_integer_type(thread_t) \
declare_unsigned_integer_type(pthread_t) \
\
/* This must be the last entry, and must be present */ \
--- a/hotspot/src/share/vm/utilities/globalDefinitions_gcc.hpp Fri Feb 17 15:55:27 2012 -0800
+++ b/hotspot/src/share/vm/utilities/globalDefinitions_gcc.hpp Sun Feb 19 13:11:39 2012 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -87,14 +87,7 @@
#endif
#ifdef __APPLE__
#include <AvailabilityMacros.h>
- #if (MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4)
- // Mac OS X 10.4 defines EFL_AC and EFL_ID,
- // which conflict with hotspot variable names.
- //
- // This has been fixed in Mac OS X 10.5.
- #undef EFL_AC
- #undef EFL_ID
- #endif
+ #include <mach/mach.h>
#endif
#include <sys/time.h>
#endif // LINUX || _ALLBSD_SOURCE