< prev index next >
src/os/linux/vm/os_linux.cpp
Print this page
*** 636,646 ****
//////////////////////////////////////////////////////////////////////////////
// create new thread
// Thread start routine for all newly created threads
! static void *java_start(Thread *thread) {
// Try to randomize the cache line index of hot stack frames.
// This helps when threads of the same stack traces evict each other's
// cache lines. The threads can be either from the same JVM instance, or
// from different JVM instances. The benefit is especially true for
// processors with hyperthreading technology.
--- 636,646 ----
//////////////////////////////////////////////////////////////////////////////
// create new thread
// Thread start routine for all newly created threads
! static void *thread_native_entry(Thread *thread) {
// Try to randomize the cache line index of hot stack frames.
// This helps when threads of the same stack traces evict each other's
// cache lines. The threads can be either from the same JVM instance, or
// from different JVM instances. The benefit is especially true for
// processors with hyperthreading technology.
*** 688,697 ****
--- 688,706 ----
thread->run();
log_info(os, thread)("Thread finished (tid: " UINTX_FORMAT ", pthread id: " UINTX_FORMAT ").",
os::current_thread_id(), (uintx) pthread_self());
+ // If a thread has not deleted itself ("delete this") as part of its
+ // termination sequence, we have to ensure thread-local-storage is
+ // cleared before we actually terminate. No threads should ever be
+ // deleted asynchronously with respect to their termination.
+ if (Thread::current_or_null_safe() != NULL) {
+ assert(Thread::current_or_null_safe() == thread, "current thread is wrong");
+ thread->clear_thread_current();
+ }
+
return 0;
}
bool os::create_thread(Thread* thread, ThreadType thr_type,
size_t stack_size) {
*** 751,761 ****
ThreadState state;
{
pthread_t tid;
! int ret = pthread_create(&tid, &attr, (void* (*)(void*)) java_start, thread);
char buf[64];
if (ret == 0) {
log_info(os, thread)("Thread started (pthread id: " UINTX_FORMAT ", attributes: %s). ",
(uintx) tid, os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
--- 760,770 ----
ThreadState state;
{
pthread_t tid;
! int ret = pthread_create(&tid, &attr, (void* (*)(void*)) thread_native_entry, thread);
char buf[64];
if (ret == 0) {
log_info(os, thread)("Thread started (pthread id: " UINTX_FORMAT ", attributes: %s). ",
(uintx) tid, os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
*** 879,889 ****
// Free Linux resources related to the OSThread
void os::free_thread(OSThread* osthread) {
assert(osthread != NULL, "osthread not set");
! if (Thread::current()->osthread() == osthread) {
#ifdef ASSERT
sigset_t current;
sigemptyset(¤t);
pthread_sigmask(SIG_SETMASK, NULL, ¤t);
assert(!sigismember(¤t, SR_signum), "SR signal should not be blocked!");
--- 888,902 ----
// Free Linux resources related to the OSThread
void os::free_thread(OSThread* osthread) {
assert(osthread != NULL, "osthread not set");
! // We are told to free resources of the argument thread,
! // but we can only really operate on the current thread.
! assert(Thread::current()->osthread() == osthread,
! "os::free_thread but not current thread");
!
#ifdef ASSERT
sigset_t current;
sigemptyset(¤t);
pthread_sigmask(SIG_SETMASK, NULL, ¤t);
assert(!sigismember(¤t, SR_signum), "SR signal should not be blocked!");
*** 890,900 ****
#endif
// Restore caller's signal mask
sigset_t sigmask = osthread->caller_sigmask();
pthread_sigmask(SIG_SETMASK, &sigmask, NULL);
- }
delete osthread;
}
//////////////////////////////////////////////////////////////////////////////
--- 903,912 ----
< prev index next >