diff --git a/build/make/components/vm/port.xml b/build/make/components/vm/port.xml index 30208ae..9bc0440 100644 --- a/build/make/components/vm/port.xml +++ b/build/make/components/vm/port.xml @@ -52,7 +52,6 @@ Version: $Revision: 1.3.2.2 $ - diff --git a/vm/port/include/apr_thread_ext.h b/vm/port/include/apr_thread_ext.h deleted file mode 100644 index c431eec..0000000 --- a/vm/port/include/apr_thread_ext.h +++ /dev/null @@ -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 */ diff --git a/vm/port/src/thread/linux/apr_thread_ext.c b/vm/port/src/thread/linux/apr_thread_ext.c deleted file mode 100644 index a09dbff..0000000 --- a/vm/port/src/thread/linux/apr_thread_ext.c +++ /dev/null @@ -1,201 +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() { - #ifdef _IPF_ - asm volatile ("mf" ::: "memory"); - #else - __asm__("mfence"); - #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; -} diff --git a/vm/port/src/thread/win/apr_thread_ext.c b/vm/port/src/thread/win/apr_thread_ext.c deleted file mode 100644 index e72ceb2..0000000 --- a/vm/port/src/thread/win/apr_thread_ext.c +++ /dev/null @@ -1,174 +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 - -#if defined(_EM64T_) && defined(_WIN64) -#include -#pragma intrinsic (_ReadWriteBarrier) -#endif - -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() { -#if defined(_EM64T_) && defined(_WIN64) - _ReadWriteBarrier(); -#else - __asm mfence; -#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(); - } -} diff --git a/vm/thread/src/linux/os_thread.c b/vm/thread/src/linux/os_thread.c index cea68f7..ca2e60f 100644 --- a/vm/thread/src/linux/os_thread.c +++ b/vm/thread/src/linux/os_thread.c @@ -216,3 +216,11 @@ int os_get_thread_times(osthread_t os_th *puser = tp.tv_sec * 1000000000ULL + tp.tv_nsec; return 0; } + +void os_memory_rw_barrier(void) { + #ifdef _IPF_ + asm volatile ("mf" ::: "memory"); + #else + __asm__("mfence"); + #endif +} diff --git a/vm/thread/src/thread_native_suspend.c b/vm/thread/src/thread_native_suspend.c index 1b61c78..b94ec84 100644 --- a/vm/thread/src/thread_native_suspend.c +++ b/vm/thread/src/thread_native_suspend.c @@ -167,7 +167,7 @@ static void thread_safe_point_impl(hythr thread->suspend_disable_count = 0; - apr_memory_rw_barrier(); + os_memory_rw_barrier(); // code for Ipf that support StackIterator and immediate suspend // notify suspender // hylatch_count_down(thread->safe_region_event); @@ -177,7 +177,7 @@ static void thread_safe_point_impl(hythr TRACE(("TM: safe point resume: thread: %p count: %d", thread, thread->suspend_request)); thread->suspend_disable_count = old_status; - apr_memory_rw_barrier(); + os_memory_rw_barrier(); } while (thread->suspend_request >0); } } // thread_safe_point_impl diff --git a/vm/thread/src/thread_native_thin_monitor.c b/vm/thread/src/thread_native_thin_monitor.c index 2ce12aa..dbb8fc5 100644 --- a/vm/thread/src/thread_native_thin_monitor.c +++ b/vm/thread/src/thread_native_thin_monitor.c @@ -76,7 +76,7 @@ #endif lockword&=0x7FF; lockword|=(monitor_id << 11) | 0x80000000; *lockword_ptr=lockword; - apr_memory_rw_barrier(); + os_memory_rw_barrier(); } IDATA is_fat_lock(hythread_thin_monitor_t lockword) { @@ -668,7 +668,7 @@ IDATA locktable_put_fat_monitor(hythread table_size = table_size*2; lock_table = (hythread_monitor_t *)realloc(lock_table, sizeof(hythread_monitor_t)*table_size); assert(lock_table); - apr_memory_rw_barrier(); + os_memory_rw_barrier(); hythread_resume_all(NULL); } diff --git a/vm/thread/src/thread_private.h b/vm/thread/src/thread_private.h index d1313a4..1e6ee4a 100644 --- a/vm/thread/src/thread_private.h +++ b/vm/thread/src/thread_private.h @@ -31,7 +31,6 @@ #include #include #include -#include "apr_thread_ext.h" #ifdef __linux__ #include @@ -629,6 +628,7 @@ int os_thread_join(osthread_t); void os_thread_exit(int 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); diff --git a/vm/thread/src/thread_ti_timing.c b/vm/thread/src/thread_ti_timing.c index a99f9a3..58a8741 100644 --- a/vm/thread/src/thread_ti_timing.c +++ b/vm/thread/src/thread_ti_timing.c @@ -24,7 +24,6 @@ #include #include #include #include "thread_private.h" -#include "apr_thread_ext.h" #define THREAD_CPU_TIME_SUPPORTED 1 diff --git a/vm/thread/src/win/os_thread.c b/vm/thread/src/win/os_thread.c index c042e31..044c84b 100644 --- a/vm/thread/src/win/os_thread.c +++ b/vm/thread/src/win/os_thread.c @@ -19,6 +19,11 @@ #include #include "thread_private.h" +#if defined(_EM64T_) && defined(_WIN64) +#include +#pragma intrinsic (_ReadWriteBarrier) +#endif + /** * Creates new thread. * @@ -187,3 +192,11 @@ int os_get_thread_times(osthread_t os_th } else return GetLastError(); } + +void os_memory_rw_barrier(void) { +#if defined(_EM64T_) && defined(_WIN64) + _ReadWriteBarrier(); +#else + __asm mfence; +#endif +}