提交 4588eb6c 编写于 作者: R rbackman

7161732: Improve handling of thread_id in OSThread

Reviewed-by: dholmes, kamg
上级 35ff8cd8
......@@ -42,25 +42,18 @@
#ifdef _ALLBSD_SOURCE
#ifdef __APPLE__
thread_t _thread_id;
typedef thread_t thread_id_t;
#else
pthread_t _thread_id;
typedef pthread_t thread_id_t;
#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
// to access /proc.
pid_t _thread_id;
typedef pid_t thread_id_t;
#endif
// _pthread_id is the pthread id, which is used by library calls
// (e.g. pthread_kill).
pthread_t _pthread_id;
#endif
sigset_t _caller_sigmask; // Caller's signal mask
......@@ -70,28 +63,11 @@
sigset_t caller_sigmask() const { return _caller_sigmask; }
void set_caller_sigmask(sigset_t sigmask) { _caller_sigmask = sigmask; }
#ifdef _ALLBSD_SOURCE
#ifdef __APPLE__
static size_t thread_id_size() { return sizeof(thread_t); }
thread_t thread_id() const {
return _thread_id;
}
#else
static size_t thread_id_size() { return sizeof(pthread_t); }
pthread_t thread_id() const {
return _thread_id;
}
#endif
#else
static size_t thread_id_size() { return sizeof(pid_t); }
pid_t thread_id() const {
return _thread_id;
}
#endif
#ifndef PRODUCT
// Used for debugging, return a unique integer for each thread.
intptr_t thread_identifier() const { return (intptr_t)_pthread_id; }
#endif
#ifdef ASSERT
// We expect no reposition failures so kill vm if we get one.
//
......@@ -99,21 +75,7 @@
return false;
}
#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;
}
#endif
pthread_t pthread_id() const {
return _pthread_id;
}
......
......@@ -24,6 +24,8 @@
#ifndef OS_LINUX_VM_OSTHREAD_LINUX_HPP
#define OS_LINUX_VM_OSTHREAD_LINUX_HPP
public:
typedef pid_t thread_id_t;
private:
int _thread_type;
......@@ -37,13 +39,6 @@
_thread_type = type;
}
private:
// _thread_id is kernel thread id (similar to LWP id on Solaris). Each
// thread has a unique thread_id (LinuxThreads or NPTL). It can be used
// to access /proc.
pid_t _thread_id;
// _pthread_id is the pthread id, which is used by library calls
// (e.g. pthread_kill).
pthread_t _pthread_id;
......@@ -56,11 +51,6 @@
sigset_t caller_sigmask() const { return _caller_sigmask; }
void set_caller_sigmask(sigset_t sigmask) { _caller_sigmask = sigmask; }
static size_t thread_id_size() { return sizeof(pid_t); }
pid_t thread_id() const {
return _thread_id;
}
#ifndef PRODUCT
// Used for debugging, return a unique integer for each thread.
int thread_identifier() const { return _thread_id; }
......@@ -72,9 +62,6 @@
return false;
}
#endif // ASSERT
void set_thread_id(pid_t id) {
_thread_id = id;
}
pthread_t pthread_id() const {
return _pthread_id;
}
......
......@@ -26,9 +26,10 @@
#define OS_SOLARIS_VM_OSTHREAD_SOLARIS_HPP
// This is embedded via include into the class OSThread
public:
typedef thread_t thread_id_t;
private:
thread_t _thread_id; // Solaris thread id
uint _lwp_id; // lwp ID, only used with bound threads
int _native_priority; // Saved native priority when starting
// a bound thread
......@@ -36,8 +37,6 @@
bool _vm_created_thread; // true if the VM created this thread,
// false if primary thread or attached thread
public:
static size_t thread_id_size() { return sizeof(thread_t); }
thread_t thread_id() const { return _thread_id; }
uint lwp_id() const { return _lwp_id; }
int native_priority() const { return _native_priority; }
......@@ -63,7 +62,6 @@
return true;
}
#endif
void set_thread_id(thread_t id) { _thread_id = id; }
void set_lwp_id(uint id) { _lwp_id = id; }
void set_native_priority(int prio) { _native_priority = prio; }
......
......@@ -25,12 +25,13 @@
#ifndef OS_WINDOWS_VM_OSTHREAD_WINDOWS_HPP
#define OS_WINDOWS_VM_OSTHREAD_WINDOWS_HPP
typedef void* HANDLE;
typedef void* HANDLE;
public:
typedef unsigned long thread_id_t;
private:
// Win32-specific thread information
HANDLE _thread_handle; // Win32 thread handle
unsigned long _thread_id; // Win32 thread id
HANDLE _interrupt_event; // Event signalled on thread interrupt
ThreadState _last_state;
......@@ -42,9 +43,6 @@ typedef void* HANDLE;
HANDLE interrupt_event() const { return _interrupt_event; }
void set_interrupt_event(HANDLE interrupt_event) { _interrupt_event = interrupt_event; }
static size_t thread_id_size() { return sizeof(unsigned long); }
unsigned long thread_id() const { return _thread_id; }
#ifndef PRODUCT
// Used for debugging, return a unique integer for each thread.
int thread_identifier() const { return _thread_id; }
......@@ -56,8 +54,6 @@ typedef void* HANDLE;
return false;
}
#endif // ASSERT
void set_thread_id(unsigned long thread_id) { _thread_id = thread_id; }
bool is_try_mutex_enter() { return false; }
// This is a temporary fix for the thread states during
......
......@@ -29,18 +29,12 @@
// 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, OS_THREAD_ID_TYPE) \
nonstatic_field(OSThread, _thread_id, OSThread::thread_id_t) \
nonstatic_field(OSThread, _pthread_id, pthread_t) \
/* This must be the last entry, and must be present */ \
last_entry()
......@@ -52,7 +46,7 @@
/* Posix Thread IDs */ \
/**********************/ \
\
declare_unsigned_integer_type(thread_t) \
declare_unsigned_integer_type(OSThread::thread_id_t) \
declare_unsigned_integer_type(pthread_t) \
\
/* This must be the last entry, and must be present */ \
......
/*
* 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
......@@ -36,7 +36,7 @@
/******************************/ \
\
nonstatic_field(JavaThread, _base_of_stack_pointer, intptr_t*) \
nonstatic_field(OSThread, _thread_id, pid_t) \
nonstatic_field(OSThread, _thread_id, OSThread::thread_id_t) \
nonstatic_field(OSThread, _pthread_id, pthread_t) \
/* This must be the last entry, and must be present */ \
last_entry()
......@@ -48,7 +48,7 @@
/* POSIX Thread IDs */ \
/**********************/ \
\
declare_integer_type(pid_t) \
declare_integer_type(OSThread::thread_id_t) \
declare_unsigned_integer_type(pthread_t) \
\
/* This must be the last entry, and must be present */ \
......
/*
* 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
......@@ -34,7 +34,7 @@
/******************************/ \
/* Threads (NOTE: incomplete) */ \
/******************************/ \
nonstatic_field(OSThread, _thread_id, pid_t) \
nonstatic_field(OSThread, _thread_id, OSThread::thread_id_t) \
nonstatic_field(OSThread, _pthread_id, pthread_t) \
/* This must be the last entry, and must be present */ \
last_entry()
......@@ -46,7 +46,7 @@
/* Posix Thread IDs */ \
/**********************/ \
\
declare_integer_type(pid_t) \
declare_integer_type(OSThread::thread_id_t) \
declare_unsigned_integer_type(pthread_t) \
\
/* This must be the last entry, and must be present */ \
......
/*
* 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
......@@ -36,7 +36,7 @@
/******************************/ \
\
nonstatic_field(JavaThread, _base_of_stack_pointer, intptr_t*) \
nonstatic_field(OSThread, _thread_id, thread_t) \
nonstatic_field(OSThread, _thread_id, OSThread::thread_id_t) \
/* This must be the last entry, and must be present */ \
last_entry()
......@@ -47,7 +47,7 @@
/* Solaris Thread IDs */ \
/**********************/ \
\
declare_unsigned_integer_type(thread_t) \
declare_unsigned_integer_type(OSThread::thread_id_t) \
\
/* This must be the last entry, and must be present */ \
last_entry()
......
/*
* 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
......@@ -35,7 +35,7 @@
/* Threads (NOTE: incomplete) */ \
/******************************/ \
\
nonstatic_field(OSThread, _thread_id, thread_t) \
nonstatic_field(OSThread, _thread_id, OSThread::thread_id_t) \
\
/* This must be the last entry, and must be present */ \
last_entry()
......@@ -46,7 +46,7 @@
/* Solaris Thread IDs */ \
/**********************/ \
\
declare_unsigned_integer_type(thread_t) \
declare_unsigned_integer_type(OSThread::thread_id_t) \
\
/* This must be the last entry, and must be present */ \
last_entry()
......
/*
* 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
......@@ -35,7 +35,7 @@
/* Threads (NOTE: incomplete) */ \
/******************************/ \
\
nonstatic_field(OSThread, _thread_id, unsigned long) \
nonstatic_field(OSThread, _thread_id, OSThread::thread_id_t) \
unchecked_nonstatic_field(OSThread, _thread_handle, sizeof(HANDLE)) /* NOTE: no type */ \
\
/* This must be the last entry, and must be present */ \
......
......@@ -61,7 +61,6 @@ enum ThreadState {
class OSThread: public CHeapObj {
friend class VMStructs;
private:
//void* _start_proc; // Thread start routine
OSThreadStartFunc _start_proc; // Thread start routine
void* _start_parm; // Thread start routine parameter
volatile ThreadState _state; // Thread state *hint*
......@@ -77,10 +76,7 @@ class OSThread: public CHeapObj {
void set_state(ThreadState state) { _state = state; }
ThreadState get_state() { return _state; }
// Constructor
OSThread(OSThreadStartFunc start_proc, void* start_parm);
// Destructor
~OSThread();
// Accessors
......@@ -98,7 +94,6 @@ class OSThread: public CHeapObj {
// For java intrinsics:
static ByteSize interrupted_offset() { return byte_offset_of(OSThread, _interrupted); }
static ByteSize thread_id_offset() { return byte_offset_of(OSThread, _thread_id); }
// Platform dependent stuff
#ifdef TARGET_OS_FAMILY_linux
......@@ -114,6 +109,19 @@ class OSThread: public CHeapObj {
# include "osThread_bsd.hpp"
#endif
public:
static ByteSize thread_id_offset() { return byte_offset_of(OSThread, _thread_id); }
static size_t thread_id_size() { return sizeof(thread_id_t); }
thread_id_t thread_id() const { return _thread_id; }
void set_thread_id(thread_id_t id) { _thread_id = id; }
private:
// _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
// to access /proc.
thread_id_t _thread_id;
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册