Index: build/make/components/vm/port.xml =================================================================== --- build/make/components/vm/port.xml (revision 558796) +++ build/make/components/vm/port.xml (working copy) @@ -52,7 +52,6 @@ - Index: vm/include/open/hythread_ext.h =================================================================== --- vm/include/open/hythread_ext.h (revision 558796) +++ vm/include/open/hythread_ext.h (working copy) @@ -133,7 +133,6 @@ #include #include -#include "apr_thread_ext.h" //@{ /** Index: vm/port/include/apr_thread_ext.h =================================================================== --- vm/port/include/apr_thread_ext.h (revision 558796) +++ vm/port/include/apr_thread_ext.h (working copy) @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @author Andrey Chernyshev - * @version $Revision$ - */ - - -#ifndef APR_EXT_H -#define APR_EXT_H - -#include -#include -#include -#include - -APR_DECLARE(apr_status_t) apr_thread_set_priority(apr_thread_t *thread, apr_int32_t priority); - -APR_DECLARE(void) apr_memory_rw_barrier(); - -APR_DECLARE(apr_status_t) apr_thread_yield_other(apr_thread_t *thread); - -APR_DECLARE(apr_status_t) apr_thread_times(apr_thread_t *thread, - apr_time_t * kernel_time, apr_time_t * user_time); - -APR_DECLARE(apr_status_t) apr_thread_cancel(apr_thread_t *thread); - -APR_DECLARE(apr_status_t) apr_get_thread_time(apr_thread_t *thread, apr_int64_t* nanos_ptr); - -#endif /* APR_EXT_H */ Index: vm/port/src/thread/linux/apr_thread_ext.c =================================================================== --- vm/port/src/thread/linux/apr_thread_ext.c (revision 558796) +++ vm/port/src/thread/linux/apr_thread_ext.c (working copy) @@ -1,215 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @author Artem Aliev - * @version $Revision$ - */ - -#define _GNU_SOURCE 1 -#include "apr_thread_ext.h" -//#include "apr_arch_threadproc.h" -#include -#include - -int convert_priority(apr_int32_t priority); - -APR_DECLARE(apr_status_t) apr_thread_set_priority(apr_thread_t *thread, - apr_int32_t priority) -{ - /* HANDLE *os_thread; - apr_status_t status; - - if (status = apr_os_thread_get(&((apr_os_thread_t *)os_thread), thread)) { - return status; - } - - if (SetThreadPriority(os_thread, (int)convert_priority(priority))) { - return APR_SUCCESS; - } else { - return apr_get_os_error(); - } - */ - return APR_SUCCESS; -} - -int convert_priority(apr_int32_t priority) { - return (int)priority; -} - - - -pthread_mutex_t yield_other_mutex = PTHREAD_MUTEX_INITIALIZER; -sem_t yield_other_sem; -int yield_other_init_flag = 0; - -void yield_other_handler(int signum, siginfo_t* info, void* context) { - if (yield_other_init_flag) { - sem_post(&yield_other_sem); - } - -} - -static void init_thread_yield_other () { - struct sigaction sa; - //init notification semaphore - sem_init(&yield_other_sem,0,0); - //set signal handler - sigemptyset(&sa.sa_mask); - sa.sa_flags = SA_SIGINFO | SA_RESTART; - sa.sa_sigaction = yield_other_handler; - sigaction(SIGUSR2, &sa, NULL); - yield_other_init_flag = 1; - -} -// touch thread to flash memory -APR_DECLARE(apr_status_t) apr_thread_yield_other(apr_thread_t* thread) { - apr_status_t status; - pthread_t *os_thread; - struct timespec timeout; - timeout.tv_sec = 1; - timeout.tv_nsec = 0; - - pthread_mutex_lock(&yield_other_mutex); - if (!yield_other_init_flag) { - init_thread_yield_other (); - } - if (!thread - || (status = apr_os_thread_get((apr_os_thread_t**)&os_thread, thread)) !=APR_SUCCESS - || !*os_thread) { - pthread_mutex_unlock(&yield_other_mutex); - return status; - } - if((pthread_kill(*os_thread, SIGUSR2))) { - } else - { - // let's do timed wait to workaroud missed signals - // sem_wait(&yield_other_sem); - sem_timedwait(&yield_other_sem,&timeout); - } - pthread_mutex_unlock(&yield_other_mutex); - return APR_SUCCESS; -} - -APR_DECLARE(void) apr_memory_rw_barrier() { -#if defined(_EM64T_) - asm volatile ("mfence" : : : "memory"); -#elif defined(_IPF_) - asm volatile ("mf" : : : "memory"); -#else // General x86 case - /* - * This code must use a lock-prefixed assembly instruction, so that - * we can support P3 processors (SSE2 only). With P4 and SSE3, we - * could use 'mfence'. - * References: - * Java Memory Model cookbook - * - http://gee.cs.oswego.edu/dl/jmm/cookbook.html - * Linux Kernel, mb() function - * - http://lxr.linux.no/source/include/asm-i386/system.h - * This is a GCC inline assembly command. The final bit, "memory", will - * clobber all of the memory registers. - */ - asm volatile ("lock; addl $0,0(%%esp)" : : : "memory"); -#endif -} - -APR_DECLARE(apr_status_t) apr_thread_times(apr_thread_t *thread, - apr_time_t * kernel_time, apr_time_t * user_time){ -/* FILETIME creationTime; - FILETIME exitTime; - FILETIME kernelTime; - FILETIME userTime; - HANDLE hThread; - SYSTEMTIME sysTime; - int res; - __int64 xx; - __int32 * pp; - - res = GetThreadTimes( - thread->td, - &creationTime, - &exitTime, - &kernelTime, - &userTime - ); - - printf( "Creation time = %08x %08x\n", creationTime.dwHighDateTime, creationTime.dwLowDateTime); - printf( "Exit time = %08x %08x\n", exitTime.dwHighDateTime, exitTime.dwLowDateTime); - printf( "Kernrl time = %08x %08x %08d\n", kernelTime.dwHighDateTime - , kernelTime.dwLowDateTime, kernelTime.dwLowDateTime); - printf( "User time = %08x %08x %08d\n", userTime.dwHighDateTime - , userTime.dwLowDateTime, userTime.dwLowDateTime); - printf("%d\n", - ((unsigned)exitTime.dwLowDateTime - (unsigned)creationTime.dwLowDateTime)/10000000); - - FileTimeToSystemTime(&creationTime, &sysTime); - printf("%d %d %d %d %d %d \n", sysTime.wYear, sysTime.wMonth, - sysTime.wHour + 3, sysTime.wMinute, sysTime.wSecond, sysTime.wMilliseconds); - - pp = (int*)&xx; - *pp = kernelTime.dwLowDateTime; - *(pp + 1) = kernelTime.dwHighDateTime; - *kernel_time = xx; - pp = (int*)&xx; - *pp = userTime.dwLowDateTime; - *(pp + 1) = userTime.dwHighDateTime; - *user_time = xx;*/ - - return APR_SUCCESS; -} - -APR_DECLARE(apr_status_t) apr_get_thread_time(apr_thread_t *thread, apr_int64_t* nanos_ptr) -{ - clockid_t clock_id; - pthread_t *os_thread; - struct timespec tp; - apr_status_t status; - int res; - if (!thread) - return APR_DETACH; - status = apr_os_thread_get((apr_os_thread_t**)&os_thread, thread); - if(status!=APR_SUCCESS) - { - return status; - } - - res = pthread_getcpuclockid(*os_thread, &clock_id); - if (0 != res) - { - return APR_ENOTIME; - } - res = clock_gettime(clock_id, &tp); - - if (0 != res) - { - return APR_ENOTIME; - } - - *nanos_ptr = tp.tv_sec * 1000000000ULL + tp.tv_nsec; - return APR_SUCCESS; -} - - -APR_DECLARE(apr_status_t) apr_thread_cancel(apr_thread_t *thread) { - apr_os_thread_t *os_thread; - apr_status_t status = apr_os_thread_get(&os_thread, thread); - - if (status ) { - return status; - } - status = pthread_cancel(*(pthread_t *)os_thread); - return status; -} Index: vm/port/src/thread/win/apr_thread_ext.c =================================================================== --- vm/port/src/thread/win/apr_thread_ext.c (revision 558796) +++ vm/port/src/thread/win/apr_thread_ext.c (working copy) @@ -1,194 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * @author Artem Aliev - * @version $Revision:$ - */ - -#include -#include -#include "apr_thread_ext.h" -#include - -// MSVC barrier intrinsics setup -#if _MSC_VER < 1400 - // VC++ 2003 - extern void _ReadWriteBarrier(); - extern void _mm_mfence(void); -#else - // VC++ 2005 - #include - #include -#endif -#pragma intrinsic (_ReadWriteBarrier) - -APR_DECLARE(apr_status_t) apr_thread_set_priority(apr_thread_t *thread, - apr_int32_t priority) -{ - HANDLE *os_thread; - apr_status_t status; - - if (status = apr_os_thread_get(&((apr_os_thread_t *)os_thread), thread)) { - return status; - } - - if (SetThreadPriority(*os_thread, (int)priority)) { - return APR_SUCCESS; - } else { - return apr_get_os_error(); - } -} - -// touch thread to flash memory -APR_DECLARE(apr_status_t) apr_thread_yield_other(apr_thread_t* thread) { - HANDLE *os_thread = NULL; - apr_status_t status; - - static CRITICAL_SECTION *yield_other_mutex = NULL; - if (yield_other_mutex == NULL) { - CRITICAL_SECTION *cs = malloc(sizeof(CRITICAL_SECTION)); - InitializeCriticalSectionAndSpinCount(cs, 400); - // there should be the only one CS - // do nothing if some one else already init it. - if(apr_atomic_casptr ((volatile void**)&yield_other_mutex, (void*)cs, NULL)) { - DeleteCriticalSection(cs); - free(cs); - } - } - - if (status = apr_os_thread_get(&((apr_os_thread_t *)os_thread), thread)) { - return status; - } - if(!os_thread) { - return status; - } - - /* - * Synchronization is needed to avoid cyclic (mutual) suspension problem. - * Accordingly to MSDN, it is possible on multiprocessor box that - * 2 threads suspend each other and become deadlocked. - */ - EnterCriticalSection(yield_other_mutex); - if(-1 != SuspendThread(*os_thread)) { - /* suspended successfully, so resume it back. */ - ResumeThread(*os_thread); - } - LeaveCriticalSection(yield_other_mutex); - return APR_SUCCESS; -} - -APR_DECLARE(void) apr_memory_rw_barrier() { -#ifdef _EM64T_ - // if x86_64/x64/EM64T, then use an mfence to flush memory caches - _mm_mfence(); -#else - /* otherwise, we assume this is an x86, so insert an inline assembly - * macro to insert a lock instruction - * - * the lock is what's needed, so the 'add' is setup, essentially, as a no-op - */ - __asm {lock add [esp], 0 } -#endif - -#ifdef __INTEL_COMPILER - __memory_barrier(); -#else - _ReadWriteBarrier(); -#endif - -} - -APR_DECLARE(apr_status_t) apr_thread_times(apr_thread_t *thread, - apr_time_t * kernel_time, apr_time_t * user_time){ - FILETIME creationTime; - FILETIME exitTime; - FILETIME kernelTime; - FILETIME userTime; - HANDLE *hThread; - SYSTEMTIME sysTime; - int res; - __int64 xx; - __int32 * pp; - apr_status_t status; - - if (status = apr_os_thread_get(&((apr_os_thread_t *)hThread), thread)) { - return status; - } - - res = GetThreadTimes( - *hThread, - &creationTime, - &exitTime, - &kernelTime, - &userTime - ); - - printf( "Creation time = %08x %08x\n", creationTime.dwHighDateTime, creationTime.dwLowDateTime); - printf( "Exit time = %08x %08x\n", exitTime.dwHighDateTime, exitTime.dwLowDateTime); - printf( "Kernrl time = %08x %08x %08d\n", kernelTime.dwHighDateTime - , kernelTime.dwLowDateTime, kernelTime.dwLowDateTime); - printf( "User time = %08x %08x %08d\n", userTime.dwHighDateTime - , userTime.dwLowDateTime, userTime.dwLowDateTime); - printf("%d\n", - ((unsigned)exitTime.dwLowDateTime - (unsigned)creationTime.dwLowDateTime)/10000000); - - FileTimeToSystemTime(&creationTime, &sysTime); - printf("%d %d %d %d %d %d \n", sysTime.wYear, sysTime.wMonth, - sysTime.wHour + 3, sysTime.wMinute, sysTime.wSecond, sysTime.wMilliseconds); - - pp = (int*)&xx; - *pp = kernelTime.dwLowDateTime; - *(pp + 1) = kernelTime.dwHighDateTime; - *kernel_time = xx; - pp = (int*)&xx; - *pp = userTime.dwLowDateTime; - *(pp + 1) = userTime.dwHighDateTime; - *user_time = xx; - - return APR_SUCCESS; -} - -APR_DECLARE(apr_status_t) apr_get_thread_time(apr_thread_t *thread, apr_int64_t* nanos_ptr) -{ - HANDLE *os_thread; - apr_status_t status; - FILETIME creation_time, exit_time, kernel_time, user_time; - if (status = apr_os_thread_get(&((apr_os_thread_t *)os_thread), thread)!=APR_SUCCESS) { - return status; - } - GetThreadTimes(*os_thread, &creation_time, - &exit_time, &kernel_time, - &user_time); - - *nanos_ptr=(Int64ShllMod32((&user_time)->dwHighDateTime, 32)|(&user_time)->dwLowDateTime);//*100; - // *nanos_ptr = user_time * 100; // convert to nanos - return APR_SUCCESS; -} - -APR_DECLARE(apr_status_t) apr_thread_cancel(apr_thread_t *thread) { - HANDLE *os_thread; - apr_status_t status; - if (status = apr_os_thread_get(&((apr_os_thread_t *)os_thread), thread)) { - return status; - } - - if (TerminateThread(*os_thread, 0)) { - return APR_SUCCESS; - } else { - return apr_get_os_error(); - } -} Index: vm/vmcore/src/thread/thread_private.h =================================================================== --- vm/vmcore/src/thread/thread_private.h (revision 558796) +++ vm/vmcore/src/thread/thread_private.h (working copy) @@ -30,7 +30,6 @@ #include #include -#include "apr_thread_ext.h" #ifdef __linux__ #include Index: vm/vmcore/src/thread/thread_ti_timing.cpp =================================================================== --- vm/vmcore/src/thread/thread_ti_timing.cpp (revision 558796) +++ vm/vmcore/src/thread/thread_ti_timing.cpp (working copy) @@ -25,7 +25,6 @@ #include #include #include "vm_threads.h" -#include "apr_thread_ext.h" #define THREAD_CPU_TIME_SUPPORTED 1 Index: vm/doc/doc.properties =================================================================== --- vm/doc/doc.properties (revision 558796) +++ vm/doc/doc.properties (working copy) @@ -132,7 +132,6 @@ ${classlib.dir}/modules/luni/src/main/native/include/shared/vmi.h \ apr_extension.intf= \ -port/include/apr_thread_ext.h \ port/include/clog.h \ port/include/cxxlog.h \ port/include/lil.h \ Index: vm/thread/src/thread_private.h =================================================================== --- vm/thread/src/thread_private.h (revision 558796) +++ vm/thread/src/thread_private.h (working copy) @@ -30,7 +30,6 @@ #include #include -#include "apr_thread_ext.h" #ifdef __linux__ #include @@ -507,6 +506,7 @@ void os_thread_exit(IDATA status); void os_thread_yield_other(osthread_t); int os_get_thread_times(osthread_t os_thread, int64* pkernel, int64* puser); +void os_memory_rw_barrier(void); int os_cond_timedwait(hycond_t *cond, hymutex_t *mutex, I_64 ms, IDATA nano); UDATA os_get_foreign_thread_stack_size(); Index: vm/thread/src/thread_native_thin_monitor.c =================================================================== --- vm/thread/src/thread_native_thin_monitor.c (revision 558796) +++ vm/thread/src/thread_native_thin_monitor.c (working copy) @@ -90,7 +90,7 @@ lockword&=0x7FF; lockword|=(monitor_id << 11) | 0x80000000; *lockword_ptr=lockword; - apr_memory_rw_barrier(); + os_memory_rw_barrier(); } IDATA get_fat_lock_id(hythread_thin_monitor_t *lockword_ptr) { Index: vm/thread/src/win/os_thread.c =================================================================== --- vm/thread/src/win/os_thread.c (revision 558796) +++ vm/thread/src/win/os_thread.c (working copy) @@ -19,6 +19,19 @@ # #include "thread_private.h" +// MSVC barrier intrinsics setup +#if _MSC_VER < 1400 + // VC++ 2003 + extern void _ReadWriteBarrier(); + extern void _mm_mfence(void); +#else + // VC++ 2005 + #include + #include +#endif +#pragma intrinsic (_ReadWriteBarrier) + + /** * Creates new thread. * @@ -202,3 +215,24 @@ return (UDATA)stack_size; } + +void os_memory_rw_barrier() { +#ifdef _EM64T_ + // if x86_64/x64/EM64T, then use an mfence to flush memory caches + _mm_mfence(); +#else + /* otherwise, we assume this is an x86, so insert an inline assembly + * macro to insert a lock instruction + * + * the lock is what's needed, so the 'add' is setup, essentially, as a no-op + */ + __asm {lock add [esp], 0 } +#endif + +#ifdef __INTEL_COMPILER + __memory_barrier(); +#else + _ReadWriteBarrier(); +#endif + +} Index: vm/thread/src/thread_native_suspend.c =================================================================== --- vm/thread/src/thread_native_suspend.c (revision 558796) +++ vm/thread/src/thread_native_suspend.c (working copy) @@ -127,7 +127,7 @@ // set disable count to 0 (safe region value) gc_disable_count = thread->disable_count; thread->disable_count = 0; - apr_memory_rw_barrier(); + os_memory_rw_barrier(); do { TRACE(("safe point enter: thread: %p, suspend_count: %d, request: %d", Index: vm/thread/src/linux/os_thread.c =================================================================== --- vm/thread/src/linux/os_thread.c (revision 558796) +++ vm/thread/src/linux/os_thread.c (working copy) @@ -241,3 +241,25 @@ return common_stack_size; } + +void os_memory_rw_barrier() { +#if defined(_EM64T_) + asm volatile ("mfence" : : : "memory"); +#elif defined(_IPF_) + asm volatile ("mf" : : : "memory"); +#else // General x86 case + /* + * This code must use a lock-prefixed assembly instruction, so that + * we can support P3 processors (SSE2 only). With P4 and SSE3, we + * could use 'mfence'. + * References: + * Java Memory Model cookbook + * - http://gee.cs.oswego.edu/dl/jmm/cookbook.html + * Linux Kernel, mb() function + * - http://lxr.linux.no/source/include/asm-i386/system.h + * This is a GCC inline assembly command. The final bit, "memory", will + * clobber all of the memory registers. + */ + asm volatile ("lock; addl $0,0(%%esp)" : : : "memory"); +#endif +}