提交 e21db581 编写于 作者: S sla

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
上级 9a33f214
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -65,8 +65,8 @@ class VM_Version_StubGenerator: public StubCodeGenerator { ...@@ -65,8 +65,8 @@ class VM_Version_StubGenerator: public StubCodeGenerator {
address generate_getPsrInfo() { address generate_getPsrInfo() {
// Flags to test CPU type. // Flags to test CPU type.
const uint32_t EFL_AC = 0x40000; const uint32_t HS_EFL_AC = 0x40000;
const uint32_t EFL_ID = 0x200000; const uint32_t HS_EFL_ID = 0x200000;
// Values for when we don't have a CPUID instruction. // Values for when we don't have a CPUID instruction.
const int CPU_FAMILY_SHIFT = 8; const int CPU_FAMILY_SHIFT = 8;
const uint32_t CPU_FAMILY_386 = (3 << CPU_FAMILY_SHIFT); const uint32_t CPU_FAMILY_386 = (3 << CPU_FAMILY_SHIFT);
...@@ -100,7 +100,7 @@ class VM_Version_StubGenerator: public StubCodeGenerator { ...@@ -100,7 +100,7 @@ class VM_Version_StubGenerator: public StubCodeGenerator {
// //
// if we are unable to change the AC flag, we have a 386 // if we are unable to change the AC flag, we have a 386
// //
__ xorl(rax, EFL_AC); __ xorl(rax, HS_EFL_AC);
__ push(rax); __ push(rax);
__ popf(); __ popf();
__ pushf(); __ pushf();
...@@ -118,7 +118,7 @@ class VM_Version_StubGenerator: public StubCodeGenerator { ...@@ -118,7 +118,7 @@ class VM_Version_StubGenerator: public StubCodeGenerator {
// //
__ bind(detect_486); __ bind(detect_486);
__ mov(rax, rcx); __ mov(rax, rcx);
__ xorl(rax, EFL_ID); __ xorl(rax, HS_EFL_ID);
__ push(rax); __ push(rax);
__ popf(); __ popf();
__ pushf(); __ pushf();
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -49,7 +49,11 @@ ...@@ -49,7 +49,11 @@
void OSThread::pd_initialize() { void OSThread::pd_initialize() {
assert(this != NULL, "check"); assert(this != NULL, "check");
#ifdef __APPLE__
_thread_id = 0;
#else
_thread_id = NULL; _thread_id = NULL;
#endif
_pthread_id = NULL; _pthread_id = NULL;
_siginfo = NULL; _siginfo = NULL;
_ucontext = NULL; _ucontext = NULL;
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -40,10 +40,17 @@ ...@@ -40,10 +40,17 @@
private: private:
#ifdef _ALLBSD_SOURCE #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; 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; pthread_t _pthread_id;
#else #else
// _thread_id is kernel thread id (similar to LWP id on Solaris). Each // _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 // thread has a unique thread_id (BsdThreads or NPTL). It can be used
...@@ -64,9 +71,15 @@ ...@@ -64,9 +71,15 @@
void set_caller_sigmask(sigset_t sigmask) { _caller_sigmask = sigmask; } void set_caller_sigmask(sigset_t sigmask) { _caller_sigmask = sigmask; }
#ifdef _ALLBSD_SOURCE #ifdef _ALLBSD_SOURCE
#ifdef __APPLE__
thread_t thread_id() const {
return _thread_id;
}
#else
pthread_t thread_id() const { pthread_t thread_id() const {
return _thread_id; return _thread_id;
} }
#endif
#else #else
pid_t thread_id() const { pid_t thread_id() const {
return _thread_id; return _thread_id;
...@@ -84,9 +97,15 @@ ...@@ -84,9 +97,15 @@
} }
#endif // ASSERT #endif // ASSERT
#ifdef _ALLBSD_SOURCE #ifdef _ALLBSD_SOURCE
#ifdef __APPLE__
void set_thread_id(thread_t id) {
_thread_id = id;
}
#else
void set_thread_id(pthread_t id) { void set_thread_id(pthread_t id) {
_thread_id = id; _thread_id = id;
} }
#endif
#else #else
void set_thread_id(pid_t id) { void set_thread_id(pid_t id) {
_thread_id = id; _thread_id = id;
......
...@@ -998,8 +998,13 @@ static void *java_start(Thread *thread) { ...@@ -998,8 +998,13 @@ static void *java_start(Thread *thread) {
} }
#ifdef _ALLBSD_SOURCE #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 // thread_id is pthread_id on BSD
osthread->set_thread_id(::pthread_self()); osthread->set_thread_id(::pthread_self());
#endif
#else #else
// thread_id is kernel thread id (similar to Solaris LWP id) // thread_id is kernel thread id (similar to Solaris LWP id)
osthread->set_thread_id(os::Bsd::gettid()); osthread->set_thread_id(os::Bsd::gettid());
...@@ -1190,7 +1195,11 @@ bool os::create_attached_thread(JavaThread* thread) { ...@@ -1190,7 +1195,11 @@ bool os::create_attached_thread(JavaThread* thread) {
// Store pthread info into the OSThread // Store pthread info into the OSThread
#ifdef _ALLBSD_SOURCE #ifdef _ALLBSD_SOURCE
#ifdef __APPLE__
osthread->set_thread_id(::mach_thread_self());
#else
osthread->set_thread_id(::pthread_self()); osthread->set_thread_id(::pthread_self());
#endif
#else #else
osthread->set_thread_id(os::Bsd::gettid()); osthread->set_thread_id(os::Bsd::gettid());
#endif #endif
...@@ -1807,7 +1816,13 @@ size_t os::lasterror(char *buf, size_t len) { ...@@ -1807,7 +1816,13 @@ size_t os::lasterror(char *buf, size_t len) {
return n; 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() { int os::current_process_id() {
// Under the old bsd thread library, bsd gives each thread // Under the old bsd thread library, bsd gives each thread
...@@ -5152,9 +5167,9 @@ jlong os::thread_cpu_time(Thread *thread, bool user_sys_cpu_time) { ...@@ -5152,9 +5167,9 @@ jlong os::thread_cpu_time(Thread *thread, bool user_sys_cpu_time) {
struct thread_basic_info tinfo; struct thread_basic_info tinfo;
mach_msg_type_number_t tcount = THREAD_INFO_MAX; mach_msg_type_number_t tcount = THREAD_INFO_MAX;
kern_return_t kr; kern_return_t kr;
mach_port_t mach_thread; thread_t mach_thread;
mach_thread = pthread_mach_thread_np(thread->osthread()->thread_id()); mach_thread = thread->osthread()->thread_id();
kr = thread_info(mach_thread, THREAD_BASIC_INFO, (thread_info_t)&tinfo, &tcount); kr = thread_info(mach_thread, THREAD_BASIC_INFO, (thread_info_t)&tinfo, &tcount);
if (kr != KERN_SUCCESS) if (kr != KERN_SUCCESS)
return -1; return -1;
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -29,12 +29,18 @@ ...@@ -29,12 +29,18 @@
// constants required by the Serviceability Agent. This file is // constants required by the Serviceability Agent. This file is
// referenced by vmStructs.cpp. // 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) \ #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) */ \ /* 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) \ nonstatic_field(OSThread, _pthread_id, pthread_t) \
/* This must be the last entry, and must be present */ \ /* This must be the last entry, and must be present */ \
last_entry() last_entry()
...@@ -46,7 +52,7 @@ ...@@ -46,7 +52,7 @@
/* Posix Thread IDs */ \ /* Posix Thread IDs */ \
/**********************/ \ /**********************/ \
\ \
declare_integer_type(pid_t) \ declare_unsigned_integer_type(thread_t) \
declare_unsigned_integer_type(pthread_t) \ declare_unsigned_integer_type(pthread_t) \
\ \
/* This must be the last entry, and must be present */ \ /* This must be the last entry, and must be present */ \
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -87,14 +87,7 @@ ...@@ -87,14 +87,7 @@
#endif #endif
#ifdef __APPLE__ #ifdef __APPLE__
#include <AvailabilityMacros.h> #include <AvailabilityMacros.h>
#if (MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4) #include <mach/mach.h>
// 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
#endif #endif
#include <sys/time.h> #include <sys/time.h>
#endif // LINUX || _ALLBSD_SOURCE #endif // LINUX || _ALLBSD_SOURCE
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册