Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 45460 invoked from network); 16 Jul 2007 19:34:23 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 16 Jul 2007 19:34:23 -0000 Received: (qmail 34106 invoked by uid 500); 16 Jul 2007 19:34:24 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 34073 invoked by uid 500); 16 Jul 2007 19:34:24 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 33996 invoked by uid 99); 16 Jul 2007 19:34:24 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 16 Jul 2007 12:34:24 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 16 Jul 2007 12:34:16 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 23A1A1A9819; Mon, 16 Jul 2007 12:33:56 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r556704 [2/5] - in /harmony/enhanced/drlvm/trunk: build/make/ build/make/components/vm/ build/make/targets/ vm/include/ vm/include/open/ vm/interpreter/src/ vm/port/src/lil/em64t/pim/ vm/port/src/lil/ia32/pim/ vm/port/src/lil/ipf/pim/ vm/te... Date: Mon, 16 Jul 2007 19:32:52 -0000 To: commits@harmony.apache.org From: wjwashburn@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070716193356.23A1A1A9819@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: harmony/enhanced/drlvm/trunk/vm/thread/src/thread_init.c URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_init.c?view=diff&rev=556704&r1=556703&r2=556704 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/thread/src/thread_init.c (original) +++ harmony/enhanced/drlvm/trunk/vm/thread/src/thread_init.c Mon Jul 16 12:32:35 2007 @@ -231,7 +231,7 @@ // suspend_disable_count must be 0 on potentially // blocking operation to prevent suspension deadlocks, // meaning that the thread is safe for suspension - saved_count = reset_suspend_disable(); + saved_count = hythread_reset_suspend_disable(); r = hymutex_lock(&TM_LIBRARY->TM_LOCK); if (r) return r; @@ -247,7 +247,7 @@ if (r) return r; } - // do not use set_suspend_disable() as we do not + // do not use hythread_set_suspend_disable() as we do not // want safe points happening under global lock self->disable_count = saved_count; return 0; @@ -423,74 +423,4 @@ //hythread_monitor_exit(*p_global_monitor); return data+index; } - - -/* - * Resizable array implementation - */ - -IDATA array_create(array_t *array) { - array_t ptr; - ptr = (array_t)malloc(sizeof(ResizableArrayType)); - if (!ptr) return -1; - ptr->capacity = 1024; - ptr->size =0; - ptr->next_index = 0; - ptr->entries = (array_entry_t)malloc(sizeof(ResizableArrayEntry)*ptr->capacity); - if (!ptr->entries) return -1; - - *array = ptr; - return 0; -} - -IDATA array_destroy(array_t array) { - if (!array) return -1; - free(array->entries); - free(array); - - return 0; -} - -UDATA array_add(array_t array, void *value) { - UDATA index; - if (!array) return 0; - if (array->next_index) { - index = array->next_index; - } else { - index = array->size + 1; - if (index >= array->capacity) { - array->entries = realloc(array->entries, sizeof(void*)*array->capacity*2); - if (!array->entries) return 0; - array->capacity*=2; - } - - array->entries[index].next_free=0; - } - - array->next_index = array->entries[index].next_free; - array->entries[index].entry = value; - array->size++; - - return index; -} - -void *array_delete(array_t array, UDATA index) { - void *return_value; - if (!array || index > array->size || index==0) return NULL; - return_value = array->entries[index].entry; - - array->entries[index].entry = NULL; - array->entries[index].next_free = array->next_index; - array->next_index = index; - - return return_value; -} - -void *array_get(array_t array, UDATA index) { - if (!array || index > array->size || index==0) return NULL; - return array->entries[index].entry; -} - - - Modified: harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_basic.c URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_basic.c?view=diff&rev=556704&r1=556703&r2=556704 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_basic.c (original) +++ harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_basic.c Mon Jul 16 12:32:35 2007 @@ -33,6 +33,7 @@ # define hy_inline #endif //PLATFORM_POSIX +#include #include #include "thread_private.h" @@ -115,7 +116,7 @@ new_thread->library = hythread_self()->library; new_thread->priority = priority ? priority : HYTHREAD_PRIORITY_NORMAL; - new_thread->stacksize = stacksize ? stacksize : HY_DEFAULT_STACKSIZE; + new_thread->stacksize = stacksize ? stacksize : TM_DEFAULT_STACKSIZE; //new_thread->suspend_request = suspend ? 1 : 0; start_proc_data = @@ -483,28 +484,6 @@ } /** - * Returns thread private data. - * - * @param[in] t thread those private data to get - * @return pointer to thread private data - */ -void* VMCALL hythread_get_private_data(hythread_t t) { - assert(t); - return t->private_data; -} -/** - * Sets the thread private data. - * - * @param t thread - * @param data pointer to private data - */ -IDATA VMCALL hythread_set_private_data(hythread_t t, void* data) { - assert(t); - t->private_data = data; - return TM_ERROR_NONE; -} - -/** * Get thread group. * * @param[out] group hythread_group_t* pointer to group @@ -562,6 +541,7 @@ * */ IDATA VMCALL hythread_struct_init(hythread_t *ret_thread) { + assert(ret_thread); if (*ret_thread) { reset_thread(*ret_thread); return TM_ERROR_NONE; @@ -642,9 +622,6 @@ ptr->os_handle = (osthread_t)NULL; ptr->priority = HYTHREAD_PRIORITY_NORMAL; ptr->stacksize = os_get_foreign_thread_stack_size(); - ptr->name = strdup("NONAME"); - // not implemented - //ptr->big_thread_local_storage = (void **)calloc(1, sizeof(void*)*tm_tls_capacity); // Suspension ptr->request = 0; @@ -664,19 +641,16 @@ } static void reset_thread(hythread_t thread) { - int r; - IDATA status; + IDATA UNREF status; if (thread->os_handle) { - r = os_thread_join(thread->os_handle); - assert(!r); + int UNREF res = os_thread_join(thread->os_handle); + assert(!res); } hymutex_lock(&thread->mutex); thread->os_handle = (osthread_t)NULL; thread->priority = HYTHREAD_PRIORITY_NORMAL; - // not implemented - //ptr->big_thread_local_storage = (void **)calloc(1, sizeof(void*)*tm_tls_capacity); // Suspension thread->request = 0; @@ -716,8 +690,7 @@ status = register_to_group(thread, group); if (status != TM_ERROR_NONE) { - thread->exit_value = status; - return thread->exit_value; + return status; } // Also, should it be executed under TM global lock? @@ -733,7 +706,6 @@ assert(status == TM_ERROR_NONE); assert(hythread_is_suspend_enabled()); thread->state = TM_THREAD_STATE_TERMINATED | (TM_THREAD_STATE_INTERRUPTED & thread->state); - thread->exit_value = 0; hythread_detach(thread); // Send join event to those threads who called join on this thread. @@ -775,3 +747,139 @@ UDATA hythread_get_thread_stacksize(hythread_t thread) { return thread->stacksize; } + +IDATA VMCALL hythread_thread_lock(hythread_t thread) { + assert(thread); + return hymutex_lock(&thread->mutex); +} // hythread_thread_lock + +IDATA VMCALL hythread_thread_unlock(hythread_t thread) { + assert(thread); + return hymutex_unlock(&thread->mutex); +} // hythread_thread_unlock + +IDATA VMCALL hythread_get_state(hythread_t thread) { + IDATA state; + assert(thread); + hymutex_lock(&thread->mutex); + state = thread->state; + hymutex_unlock(&thread->mutex); + return state; +} // hythread_get_state + +IDATA VMCALL hythread_set_state(hythread_t thread, IDATA state) { + assert(thread); + hymutex_lock(&thread->mutex); + thread->state = state; + hymutex_unlock(&thread->mutex); + return TM_ERROR_NONE; +} // hythread_set_state + +IDATA VMCALL hythread_get_thread_id_offset() { + return (uint32)&((HyThread *)0)->thread_id; +} // hythread_get_thread_id_offset + +IDATA VMCALL hythread_set_thread_stop_callback(hythread_t thread, + tm_thread_event_callback_proc stop_callback) +{ + IDATA status = hythread_set_safepoint_callback(thread, stop_callback); + + while (thread->suspend_count > 0) { + apr_atomic_dec32((volatile apr_uint32_t *) + &thread->suspend_count); + apr_atomic_dec32((volatile apr_uint32_t *) + &thread->request); + } + + // if there is no competition, it would be 1, but if someone else is + // suspending the same thread simultaneously, it could be greater than 1 + // if safepoint callback isn't set it could be equal to 0. + // + // The following assertion may be false because at each time + // one of the conditions is true, and the other is false, but + // when checking the whole condition it may be failse in the result. + // assert(thread->request > 0 || thread->safepoint_callback == NULL); + + // notify the thread that it may wake up now, + // so that it would eventually reach exception safepoint + // and execute callback + hysem_post(thread->resume_event); + return status; +} // hythread_set_thread_stop_callback + +IDATA VMCALL hythread_wait_for_nondaemon_threads(hythread_t thread, IDATA threads_to_keep) +{ + IDATA status; + hythread_library_t lib; + + assert(thread); + lib = thread->library; + + status = hymutex_lock(&lib->TM_LOCK); + if (status != TM_ERROR_NONE) { + return status; + } + + while (lib->nondaemon_thread_count - threads_to_keep > 0) + { + // check interruption and other problems + status = hycond_wait(&lib->nondaemon_thread_cond, &lib->TM_LOCK); + + TRACE(("TM wait for nondaemons notified, count: %d", + lib->nondaemon_thread_count)); + + if (status != TM_ERROR_NONE) { + hymutex_unlock(&lib->TM_LOCK); + return status; + } + } + + status = hymutex_unlock(&lib->TM_LOCK); + return status; +} // hythread_wait_for_nondaemon_threads + +IDATA VMCALL hythread_increase_nondaemon_threads_count(hythread_t thread) +{ + hythread_library_t lib = thread->library; + IDATA status = hymutex_lock(&lib->TM_LOCK); + if (status != TM_ERROR_NONE) { + return status; + } + lib->nondaemon_thread_count++; + status = hymutex_unlock(&lib->TM_LOCK); + return status; +} // hythread_increase_nondaemon_threads_count_in_library + +IDATA VMCALL hythread_decrease_nondaemon_threads_count(hythread_t thread, IDATA threads_to_keep) +{ + hythread_library_t lib = thread->library; + IDATA status = hymutex_lock(&lib->TM_LOCK); + if (status != TM_ERROR_NONE) { + return status; + } + + if (lib->nondaemon_thread_count <= 0) { + status = hymutex_unlock(&lib->TM_LOCK); + if (status != TM_ERROR_NONE) { + return status; + } + return TM_ERROR_ILLEGAL_STATE; + } + + TRACE(("TM: nondaemons decreased, thread: %p count: %d\n", thread, + lib->nondaemon_thread_count)); + + lib->nondaemon_thread_count--; + if (lib->nondaemon_thread_count - threads_to_keep <= 0) { + status = hycond_notify_all(&lib->nondaemon_thread_cond); + TRACE(("TM: nondaemons all dead, thread: %p count: %d\n", thread, + lib->nondaemon_thread_count)); + if (status != TM_ERROR_NONE) { + hymutex_unlock(&lib->TM_LOCK); + return status; + } + } + + status = hymutex_unlock(&lib->TM_LOCK); + return status; +} // hythread_countdown_nondaemon_threads Modified: harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_condvar.c URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_condvar.c?view=diff&rev=556704&r1=556703&r2=556704 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_condvar.c (original) +++ harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_condvar.c Mon Jul 16 12:32:35 2007 @@ -50,11 +50,11 @@ return TM_ERROR_INTERRUPT; } - disable_count = reset_suspend_disable(); + disable_count = hythread_reset_suspend_disable(); r = os_cond_timedwait(cond, mutex, ms, nano); - set_suspend_disable(disable_count); + hythread_set_suspend_disable(disable_count); self->current_condition = NULL; // check interrupted flag Modified: harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_fat_monitor.c URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_fat_monitor.c?view=diff&rev=556704&r1=556703&r2=556704 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_fat_monitor.c (original) +++ harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_fat_monitor.c Mon Jul 16 12:32:35 2007 @@ -223,9 +223,9 @@ hymutex_unlock(&mon_ptr->mutex); hythread_safe_point(); hythread_exception_safe_point(); - save_count = reset_suspend_disable(); + save_count = hythread_reset_suspend_disable(); hymutex_lock(&mon_ptr->mutex); - set_suspend_disable(save_count); + hythread_set_suspend_disable(save_count); } mon_ptr->recursion_count = saved_recursion; Modified: harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_interrupt.c URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_interrupt.c?view=diff&rev=556704&r1=556703&r2=556704 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_interrupt.c (original) +++ harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_interrupt.c Mon Jul 16 12:32:35 2007 @@ -23,7 +23,7 @@ #include "thread_private.h" #include -static int interrupter_thread_function(void *args); +static IDATA HYTHREAD_PROC interrupter_thread_function(void *args); /** * Interrupt a thread. @@ -65,7 +65,7 @@ hymutex_unlock(&thread->mutex); } -static int interrupter_thread_function(void *args) { +static IDATA HYTHREAD_PROC interrupter_thread_function(void *args) { hythread_t thread = (hythread_t)args; hythread_monitor_t monitor = NULL; hymutex_lock(&thread->mutex); Modified: harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_suspend.c URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_suspend.c?view=diff&rev=556704&r1=556703&r2=556704 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_suspend.c (original) +++ harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_suspend.c Mon Jul 16 12:32:35 2007 @@ -429,9 +429,9 @@ /** * Reset disable_count for currect thread. * The method begins suspension safe region. - * Field disable_count is restored in set_suspend_disable() function. + * Field disable_count is restored in hythread_set_suspend_disable() function. */ -int reset_suspend_disable() +int VMCALL hythread_reset_suspend_disable() { hythread_t self = tm_self_tls; int disable_count = self->disable_count; @@ -442,12 +442,12 @@ /** * Restores disable_count for current thread, - * which was reset in reset_suspend_disable() function + * which was reset in hythread_reset_suspend_disable() function * If restored value ends suspension safe region * and there was a suspension request set for this thread, * the method invokes hythread_safe_point() function. */ -void set_suspend_disable(int count) +void VMCALL hythread_set_suspend_disable(int count) { hythread_t self = tm_self_tls; Modified: harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_thin_monitor.c URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_thin_monitor.c?view=diff&rev=556704&r1=556703&r2=556704 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_thin_monitor.c (original) +++ harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_thin_monitor.c Mon Jul 16 12:32:35 2007 @@ -34,6 +34,11 @@ */ //@{ +#if !defined (_IPF_) +// spin with try_lock SPIN_COUNT times +#define SPIN_COUNT 5 +#endif // !defined (_IPF_) + /* * 32bit lock word * |0|------15bit-------|--5bit--|1bit|--10bit------| @@ -65,7 +70,7 @@ HyFatLockTable *lock_table = NULL; -IDATA owns_thin_lock(hythread_t thread, I_32 lockword) { +IDATA VMCALL hythread_owns_thin_lock(hythread_t thread, hythread_thin_monitor_t lockword) { IDATA this_id = thread->thread_id; assert(!IS_FAT_LOCK(lockword)); #ifdef LOCK_RESERVATION @@ -100,15 +105,14 @@ return lockword; } -IDATA is_fat_lock(hythread_thin_monitor_t lockword) { - return IS_FAT_LOCK(lockword); +int VMCALL hythread_is_fat_lock(hythread_thin_monitor_t lockword) { + return (int)IS_FAT_LOCK(lockword); } //forward declaration hythread_monitor_t locktable_get_fat_monitor(IDATA lock_id); IDATA locktable_put_fat_monitor(hythread_monitor_t fat_monitor); hythread_monitor_t locktable_delete_entry(int lock_id); -hythread_monitor_t inflate_lock(hythread_thin_monitor_t *lockword_ptr); //DEBUG INFO BLOCK //char *vm_get_object_class_name(void* ptr); @@ -131,8 +135,8 @@ void unreserve_self_lock(hythread_thin_monitor_t *lockword_ptr) { U_32 lockword = *lockword_ptr; U_32 lockword_new; - TRACE(("unreserve self_id %d lock owner %d", hythread_get_id(hythread_self()), THREAD_ID(lockword))); - assert(hythread_get_id(hythread_self()) == THREAD_ID(lockword)); + TRACE(("unreserve self_id %d lock owner %d", hythread_get_self_id(), THREAD_ID(lockword))); + assert(hythread_get_self_id() == THREAD_ID(lockword)); assert (!IS_FAT_LOCK(*lockword_ptr)); assert (IS_RESERVED(lockword)); TRACE(("Unreserved self %d \n", ++unreserve_count_self/*, vm_get_object_class_name(lockword_ptr-1)*/)); @@ -150,10 +154,11 @@ } -/* +/** * Used lockword + * Thin monitor functions used java monitor. */ -IDATA unreserve_lock(hythread_thin_monitor_t *lockword_ptr) { +IDATA VMCALL hythread_unreserve_lock(hythread_thin_monitor_t *lockword_ptr) { U_32 lockword = *lockword_ptr; U_32 lockword_new; uint16 lock_id; @@ -251,7 +256,7 @@ return TM_ERROR_NONE; } #else -IDATA unreserve_lock(I_32* lockword_ptr) { +IDATA VMCALL hythread_unreserve_lock(hythread_thin_monitor_t* lockword_ptr) { return TM_ERROR_NONE; } #endif @@ -304,7 +309,7 @@ if (lock_id == this_id) { if (RECURSION(lockword) == MAX_RECURSION) { //inflate lock in case of recursion overflow - fat_monitor =inflate_lock(lockword_ptr); + fat_monitor = hythread_inflate_lock(lockword_ptr); return hythread_monitor_try_enter(fat_monitor); //break FAT_LOCK; } else { @@ -366,7 +371,7 @@ #ifdef LOCK_RESERVATION // unreserved busy lock else if (IS_RESERVED(lockword)) { - status = unreserve_lock(lockword_ptr); + status = hythread_unreserve_lock(lockword_ptr); if (status != TM_ERROR_NONE) { #ifdef SPIN_COUNT if (status == TM_ERROR_EBUSY) { @@ -407,9 +412,9 @@ if (IS_FAT_LOCK(*lockword_ptr)) { fat_monitor = locktable_get_fat_monitor(FAT_LOCK_ID(*lockword_ptr)); // find fat_monitor in lock table TRACE((" lock %d\n", FAT_LOCK_ID(*lockword_ptr))); - saved_disable_count=reset_suspend_disable(); + saved_disable_count = hythread_reset_suspend_disable(); status = hythread_monitor_enter(fat_monitor); - set_suspend_disable(saved_disable_count); + hythread_set_suspend_disable(saved_disable_count); return status; // lock fat_monitor } //hythread_safe_point(); @@ -420,7 +425,7 @@ return TM_ERROR_NONE; } TRACE(("inflate_contended thin_lcok%d\n", ++inflate_contended)); - inflate_lock(lockword_ptr); + hythread_inflate_lock(lockword_ptr); return TM_ERROR_NONE; } @@ -470,13 +475,13 @@ if (!IS_FAT_LOCK(lockword)) { // check if the current thread owns lock - if (!owns_thin_lock(this_thread, lockword)) { + if (!hythread_owns_thin_lock(this_thread, lockword)) { TRACE(("ILLEGAL_STATE %wait d\n", FAT_LOCK_ID(lockword))); return TM_ERROR_ILLEGAL_STATE; } TRACE(("inflate_wait%d\n", ++inflate_waited)); // if it is not a thin lock, inflate it - fat_monitor = inflate_lock(lockword_ptr); + fat_monitor = hythread_inflate_lock(lockword_ptr); } else { // otherwise, get the appropriate fat lock fat_monitor = locktable_get_fat_monitor(FAT_LOCK_ID(lockword)); @@ -552,7 +557,7 @@ return hythread_monitor_notify(fat_monitor); } // check if the current thread owns lock - if (!owns_thin_lock(tm_self_tls, lockword)) { + if (!hythread_owns_thin_lock(tm_self_tls, lockword)) { return TM_ERROR_ILLEGAL_STATE; } @@ -573,7 +578,7 @@ return hythread_monitor_notify_all(fat_monitor); } // check if the current thread owns lock - if (!owns_thin_lock(tm_self_tls, lockword)) { + if (!hythread_owns_thin_lock(tm_self_tls, lockword)) { return TM_ERROR_ILLEGAL_STATE; } return TM_ERROR_NONE; @@ -599,7 +604,7 @@ /* * Inflates the compressed lockword into fat fat_monitor */ -hythread_monitor_t VMCALL inflate_lock(hythread_thin_monitor_t *lockword_ptr) { +hythread_monitor_t VMCALL hythread_inflate_lock(hythread_thin_monitor_t *lockword_ptr) { hythread_monitor_t fat_monitor; IDATA status; IDATA fat_monitor_id; @@ -626,7 +631,7 @@ assert(!IS_RESERVED(lockword)); #endif - assert(owns_thin_lock(tm_self_tls, lockword)); + assert(hythread_owns_thin_lock(tm_self_tls, lockword)); assert(!hythread_is_suspend_enabled()); TRACE (("inflation begin for %x thread: %d", lockword, tm_self_tls->thread_id)); @@ -644,7 +649,7 @@ } fat_monitor_id = locktable_put_fat_monitor(fat_monitor); // put fat_monitor into lock table set_fat_lock_id(lockword_ptr, fat_monitor_id); - TRACE(("inflate_lock %d thread: %d\n", FAT_LOCK_ID(*lockword_ptr), tm_self_tls->thread_id)); + TRACE(("hythread_inflate_lock %d thread: %d\n", FAT_LOCK_ID(*lockword_ptr), tm_self_tls->thread_id)); //assert(FAT_LOCK_ID(*lockword_ptr) != 2); TRACE(("FAT ID : 0x%x", *lockword_ptr)); fat_monitor->inflate_count++; Modified: harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_tls.c URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_tls.c?view=diff&rev=556704&r1=556703&r2=556704 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_tls.c (original) +++ harmony/enhanced/drlvm/trunk/vm/thread/src/thread_native_tls.c Mon Jul 16 12:32:35 2007 @@ -191,15 +191,4 @@ return ((UDATA)&((hythread_t)0)->thread_local_storage) + (key * sizeof(void*)); } - -/* - * Class: org_apache_harmony_drlvm_thread_ThreadHelper - * Method: getThreadIdOffset - * Signature: ()I - */ -jint JNICALL Java_org_apache_harmony_drlvm_thread_ThreadHelper_getThreadIdOffset(JNIEnv *e, jclass c) { - return (uint32)&((HyThread *)0)->thread_id; -} - - //@} Modified: harmony/enhanced/drlvm/trunk/vm/thread/src/thread_private.h URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_private.h?view=diff&rev=556704&r1=556703&r2=556704 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/thread/src/thread_private.h (original) +++ harmony/enhanced/drlvm/trunk/vm/thread/src/thread_private.h Mon Jul 16 12:32:35 2007 @@ -50,27 +50,10 @@ #define RET_ON_ERROR(stat) if (stat) { return -1; } #define CONVERT_ERROR(stat) (stat) -#define MAX_OWNED_MONITOR_NUMBER 200 //FIXME: switch to dynamic resize #define FAST_LOCAL_STORAGE_SIZE 10 #define INITIAL_FAT_TABLE_ENTRIES 16*1024 //make this table exapandible if workloads show it is necessary -#define HY_DEFAULT_STACKSIZE 512 * 1024 // if default stack size is not through -Xss parameter, it is 256kb - - -#if !defined (_IPF_) -//use lock reservation -#define LOCK_RESERVATION -// spin with try_lock SPIN_COUNT times -#define SPIN_COUNT 5 - -#endif // !defined (_IPF_) - -#if defined(_WIN32) && !defined (_EM64T_) -//use optimized asm monitor enter and exit helpers -#define ASM_MONITOR_HELPER -#endif - #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ @@ -136,7 +119,7 @@ * 2. hythread_exception_safe_point() * - removes safe point callback request for current thread */ - int32 request; + uint32 request; /** * Field indicating that thread can safely be suspended. @@ -147,7 +130,7 @@ * for current thread only. * * Also disable_count could be reset to value 0 and restored in - * reset_suspend_disable()/set_suspend_disable() function + * hythread_set_suspend_disable()/hythread_set_suspend_disable() function * for current thread only. * * Function hythread_exception_safe_point() sets disable_count to @@ -160,7 +143,6 @@ */ int16 disable_count; - /** * Group for this thread. Different groups are needed in order * to be able to quickly iterate over the specific group. @@ -191,8 +173,7 @@ * After increment/decrement of suspend_count, request field * should be incremented/decremented too. */ - int32 suspend_count; - + uint32 suspend_count; /** * Function to be executed at safepoint upon thread resume. @@ -226,23 +207,7 @@ * Handle to OS thread. */ osthread_t os_handle; - - /** - * Placeholder for any data to be associated with this thread. - * Java layer is using it to keep java-specific context. - */ - void *private_data; - - /** - * Flag indicating there was request to exit - */ - Boolean exit_request; - /** - * Exit value of this thread - */ - IDATA exit_value; - // Synchronization stuff @@ -278,11 +243,6 @@ // Attributes - /** - * name of the thread (useful for debugging purposes) - */ - char* name; - /** * Hint for scheduler about thread priority */ @@ -298,7 +258,7 @@ /** * Monitor this thread is waiting on now. - **/ + */ hythread_monitor_t waited_monitor; /** @@ -306,108 +266,8 @@ */ IDATA thread_id; - /** - * APR thread attributes - */ - apr_threadattr_t *apr_attrs; - - /** - * Extension to the standard local storage slot. - */ - void **big_local_storage; - } HyThread; - -/** - * Java-specific context that is attached to tm_thread control structure by Java layer - */ -typedef struct JVMTIThread { - - /** - * JNI env associated with this Java thread - */ - JNIEnv *jenv; - - /** - * jthread object which is associated with tm_thread - */ - jthread thread_object; - - /** - * Conditional variable which is used to wait/notify on java monitors. - */ - hycond_t monitor_condition; - - /** - * Exception that has to be thrown in stopped thread - */ - jthrowable stop_exception; - - /** - * Blocked on monitor times count - */ - jlong blocked_count; - - /** - * Blocked on monitor time in nanoseconds - */ - jlong blocked_time; - - /** - * Waited on monitor times count - */ - jlong waited_count; - - /** - * Waited on monitor time in nanoseconds - */ - jlong waited_time; - - /** - * JVM TI local storage - */ - JVMTILocalStorage jvmti_local_storage; - - /** - * Monitor this thread is blocked on. - */ - jobject contended_monitor; - - /** - * Monitor this thread waits on. - */ - jobject wait_monitor; - - /** - * Monitors for which this thread is owner. - */ - jobject *owned_monitors; - - /** - * owned monitors count. - */ - int owned_monitors_nmb; - - /** - * APR pool for this structure - */ - apr_pool_t *pool; - - /** - * weak reference to corresponding java.lang.Thread instance - */ - jobject thread_ref; - - /** - * Is this thread daemon? - */ - IDATA daemon; - -} JVMTIThread; - - - /** * hythread_group_t pointer to the first element in the thread group */ @@ -599,8 +459,6 @@ extern int max_group_index; // max number of groups -extern int total_started_thread_count; // Total started thread counter. - extern HyFatLockTable *lock_table; #define THREAD_ID_SIZE 16 //size of thread ID in bits. Also defines max number of threads @@ -610,23 +468,6 @@ /** * Internal TM functions */ - -/** -* tm_reset_suspend_disable() reset suspend_disable to 0, and return old value. -* It should be used with tm_set_suspend_disable() to implement safe points -* Will be used in tm_safe_point(), tm_mutex_lock(), tm_cond_wait(). -*/ - -int reset_suspend_disable(); -void set_suspend_disable(int count); - -/* thin monitor functions used java monitor - */ -IDATA is_fat_lock(hythread_thin_monitor_t lockword); -IDATA owns_thin_lock(hythread_t thread, I_32 lockword); -hythread_monitor_t inflate_lock(hythread_thin_monitor_t *lockword_ptr); -IDATA unreserve_lock(hythread_thin_monitor_t *lockword_ptr); - IDATA VMCALL hythread_get_group(hythread_group_t *group, hythread_t thread); /** * Auxiliary function to throw java.lang.InterruptedException @@ -654,34 +495,6 @@ IDATA thin_monitor_wait_impl(hythread_thin_monitor_t *lockword_ptr, I_64 ms, IDATA nano, IDATA interruptable); IDATA sem_wait_impl(hysem_t sem, I_64 ms, IDATA nano, IDATA interruptable); -typedef struct ResizableArrayEntry { - void *entry; - UDATA next_free; -} ResizableArrayEntry; - -typedef struct ResizableArrayEntry *array_entry_t; - -typedef struct ResizableArrayType { - UDATA size; - UDATA capacity; - UDATA next_index; - array_entry_t entries; -} ResizableArrayType; -typedef struct ResizableArrayType *array_t; - - -IDATA array_create(array_t *array); -IDATA array_destroy(array_t array); -UDATA array_add(array_t array, void *value); -void *array_delete(array_t array, UDATA index); -void *array_get(array_t array, UDATA index); - -/** - * Auxiliary function to update thread count - */ -void thread_start_count(); -void thread_end_count(); - /* * portability functions, private for thread module */ @@ -691,7 +504,7 @@ osthread_t os_thread_current(); int os_thread_cancel(osthread_t); int os_thread_join(osthread_t); -void os_thread_exit(int status); +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); Modified: harmony/enhanced/drlvm/trunk/vm/thread/src/win/os_thread.c URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/thread/src/win/os_thread.c?view=diff&rev=556704&r1=556703&r2=556704 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/thread/src/win/os_thread.c (original) +++ harmony/enhanced/drlvm/trunk/vm/thread/src/win/os_thread.c Mon Jul 16 12:32:35 2007 @@ -119,7 +119,7 @@ * * @param status returns status of a thread */ -void os_thread_exit(int status) +void os_thread_exit(IDATA status) { ExitThread(status); } Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/include/Class.h URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/include/Class.h?view=diff&rev=556704&r1=556703&r2=556704 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/vmcore/include/Class.h (original) +++ harmony/enhanced/drlvm/trunk/vm/vmcore/include/Class.h Mon Jul 16 12:32:35 2007 @@ -50,7 +50,7 @@ class JIT; struct Global_Env; class Package; -class VM_thread; +struct VM_thread; struct AnnotationTable; Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/include/exceptions_type.h URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/include/exceptions_type.h?view=diff&rev=556704&r1=556703&r2=556704 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/vmcore/include/exceptions_type.h (original) +++ harmony/enhanced/drlvm/trunk/vm/vmcore/include/exceptions_type.h Mon Jul 16 12:32:35 2007 @@ -30,11 +30,12 @@ #ifdef __cplusplus extern "C" { #endif + struct Exception { - ManagedObject* exc_object; - Class* exc_class; + struct ManagedObject* exc_object; + struct Class* exc_class; const char* exc_message; - ManagedObject* exc_cause; + struct ManagedObject* exc_cause; }; #ifdef __cplusplus Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/include/jvmti_internal.h URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/include/jvmti_internal.h?view=diff&rev=556704&r1=556703&r2=556704 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/vmcore/include/jvmti_internal.h (original) +++ harmony/enhanced/drlvm/trunk/vm/vmcore/include/jvmti_internal.h Mon Jul 16 12:32:35 2007 @@ -372,11 +372,11 @@ jvmtiError jvmti_get_next_bytecodes_from_native(VM_thread *thread, jvmti_StepLocation **next_step, unsigned *count, bool invoked_frame); void jvmti_set_single_step_breakpoints(DebugUtilsTI *ti, - VM_thread *vm_thread, jvmti_StepLocation *locations, + jvmti_thread_t jvmti_thread, jvmti_StepLocation *locations, unsigned locations_number); void jvmti_set_single_step_breakpoints_for_method(DebugUtilsTI *ti, - VM_thread *vm_thread, Method* method); -void jvmti_remove_single_step_breakpoints(DebugUtilsTI *ti, VM_thread *vm_thread); + jvmti_thread_t jvmti_thread, Method* method); +void jvmti_remove_single_step_breakpoints(DebugUtilsTI *ti, jvmti_thread_t jvmti_thread); // Object check functions Boolean is_valid_thread_object(jthread thread); Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/include/native_stack.h URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/include/native_stack.h?view=diff&rev=556704&r1=556703&r2=556704 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/vmcore/include/native_stack.h (original) +++ harmony/enhanced/drlvm/trunk/vm/vmcore/include/native_stack.h Mon Jul 16 12:32:35 2007 @@ -54,7 +54,7 @@ int native_test_unwind_special(native_module_t* modules, void* sp); bool native_unwind_special(native_module_t* modules, void* stack, void** ip, void** sp, void** bp, bool is_last); -void native_unwind_interrupted_frame(VM_thread* pthread, void** p_ip, void** p_bp, void** p_sp); +void native_unwind_interrupted_frame(jvmti_thread_t thread, void** p_ip, void** p_bp, void** p_sp); bool native_is_ip_in_modules(native_module_t* modules, void* ip); bool native_is_ip_stub(void* ip); Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/include/thread_manager.h URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/include/thread_manager.h?view=diff&rev=556704&r1=556703&r2=556704 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/vmcore/include/thread_manager.h (original) +++ harmony/enhanced/drlvm/trunk/vm/vmcore/include/thread_manager.h Mon Jul 16 12:32:35 2007 @@ -14,29 +14,256 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/** - * @author Andrey Chernyshev - * @version $Revision: 1.1.2.1.4.4 $ - */ - #ifndef THREAD_MANAGER_HEADER #define THREAD_MANAGER_HEADER -#include "vm_threads.h" - +#include "open/jthread.h" +#include "open/thread_externals.h" +#include "exceptions_type.h" + +#define GC_BYTES_IN_THREAD_LOCAL (20 * sizeof(void *)) +#define CONVERT_ERROR(stat) (stat) +#define TM_JVMTI_MAX_BUFFER_SIZE 50 #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif -void free_this_thread_block(VM_thread *); -VM_thread * get_a_thread_block(JavaVM_Internal * java_vm); -VM_thread * allocate_thread_block(JavaVM_Internal * java_vm); - -extern volatile VM_thread *p_the_safepoint_control_thread; // only set when a gc is happening -extern volatile safepoint_state global_safepoint_status; +struct jvmti_frame_pop_listener; +struct JVMTISingleStepState; +struct ClassLoader; + +/** + * These are thread level gc states. + */ +enum gc_state { + zero = 0, + gc_moving_to_safepoint, + gc_at_safepoint, + gc_enumeration_done +}; + +/** + * Java-specific context that is attached to tm_thread control structure by Java layer + */ +struct JVMTIThread +{ + /** + * Blocked on monitor times count + */ + jlong blocked_count; + + /** + * Blocked on monitor time in nanoseconds + */ + jlong blocked_time; + + /** + * Waited on monitor times count + */ + jlong waited_count; + + /** + * Waited on monitor time in nanoseconds + */ + jlong waited_time; + + /** + * JVM TI local storage + */ + JVMTILocalStorage jvmti_local_storage; + + /** + * Monitor this thread is blocked on. + */ + jobject contended_monitor; + + /** + * Monitor this thread waits on. + */ + jobject wait_monitor; + + /** + * Monitors for which this thread is owner. + */ + jobject *owned_monitors; + + /** + * owned monitors count. + */ + int owned_monitors_nmb; + + /** + * For support of JVMTI events: EXCEPTION, EXCEPTION_CATCH + * If p_exception_object is set and p_exception_object_ti is not + * - EXCEPTION event should be generated + * If p_exception_object_ti is set and p_exception_object is not + * - EXCEPTION_CATCH even should be generated + */ + volatile struct ManagedObject *p_exception_object_ti; + + /** + * Buffer used to create instructions instead of original instruction + * to transfer execution control back to the code after breakpoint + * has been processed + */ + jbyte *jvmti_jit_breakpoints_handling_buffer; + + struct jvmti_frame_pop_listener *frame_pop_listener; + struct JVMTISingleStepState *ss_state; + void *jvmti_saved_exception_registers; +}; + +struct VM_thread +{ + /** + * Native thread which is associated with VM_thread + */ + hythread_t native_thread; + + /** + * Java thread object to corresponding java.lang.Thread instance + */ + jobject java_thread; + + /** + * Thread reference object to corresponding java.lang.ThreadWeakRef instance + */ + jobject weak_ref; + + /** + * Exception that has to be thrown in stopped thread + */ + jthrowable stop_exception; + + /** + * Memory pool where this structure is allocated. + * This pool should be used by current thread for memory allocations. + */ + apr_pool_t *pool; + + /** + * JNI environment associated with this thread. + */ + JNIEnv *jni_env; + + /** + * Class loader which loads native library and calls to its JNI_OnLoad + */ + struct ClassLoader *onload_caller; + + /** + * Flag to detect if a class is not found on bootclasspath, + * as opposed to linkage errors. + * Used for implementing default delegation model. + */ + unsigned char class_not_found; + + // In case exception is thrown, Exception object is put here + volatile struct Exception thread_exception; + + // flag which indicate that guard page on the stak should be restored + unsigned char restore_guard_page; + + // thread stack address + void *stack_addr; + + // thread stack size + UDATA stack_size; + + // ?? + enum gc_state gc_status; + int finalize_thread_flags; + + // CPU registers. + void *regs; + + // This field is private the to M2nFrame module, init code should set it to NULL + // Informational frame - created when native is called from Java, + // used to store local handles (jobjects) + registers. + // =0 if there is no m2n frame. + void *last_m2n_frame; + + // GC Information + unsigned char _gc_private_information[GC_BYTES_IN_THREAD_LOCAL]; + void *native_handles; + void *gc_frames; + +#if defined(PLATFORM_POSIX) && defined(_IPF_) + // Linux/IPF + hysem_t suspend_self; // To suspend current thread for signal handler + uint64 suspended_state; // Flag to indicate how the one thread is suspended + // Possible values: + // NOT_SUSPENDED, + // SUSPENDED_IN_SIGNAL_HANDLER, + // SUSPENDED_IN_DISABLE_GC_FOR_THREAD + uint64 t[2]; // t[0] <= rnat, t[1] <= bspstore for current thread context + // t[0] <= rnat, t[1] <= bsp for other thread context +#endif + void *lastFrame; + void *firstFrame; + int interpreter_state; + + /** + * The upper boundary of the stack to scan when verifying stack enumeration + */ + void **stack_end; + + /** + * Is this thread daemon? + */ + IDATA daemon; + + /** + * JVMTI support in thread structure + */ + struct JVMTIThread jvmti_thread; +}; + +/** + * Java thread creation attributes. + */ +struct jthread_thread_attr +{ + /** + * Pointer to Java VM. + */ + JavaVM *java_vm; + + /** + * Thread scheduling priority. + */ + jint priority; + + /** + * Thread stack size. + */ + UDATA stacksize; + + /** + * Denotes whether Java thread is daemon. + * JVM exits when the only threads running are daemon threads. + */ + jboolean daemon; + + /** + * JVMTI environment. + */ + jvmtiEnv *jvmti_env; + + /** + * JVMTI start function to be executed in this thread. + */ + jvmtiStartFunction proc; + + /** + * Start function argument to the start function. Is passed as an array. + */ + const void *arg; +}; #ifdef __cplusplus } Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/include/vm_core_types.h URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/include/vm_core_types.h?view=diff&rev=556704&r1=556703&r2=556704 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/vmcore/include/vm_core_types.h (original) +++ harmony/enhanced/drlvm/trunk/vm/vmcore/include/vm_core_types.h Mon Jul 16 12:32:35 2007 @@ -44,7 +44,7 @@ struct M2nFrame; struct ManagedObject; class NativeObjectHandles; -class VM_thread; +struct VM_thread; class Package; class Package_Table; class Properties; Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/include/vm_threads.h URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/include/vm_threads.h?view=diff&rev=556704&r1=556703&r2=556704 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/vmcore/include/vm_threads.h (original) +++ harmony/enhanced/drlvm/trunk/vm/vmcore/include/vm_threads.h Mon Jul 16 12:32:35 2007 @@ -14,16 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/** - * @author Andrey Chernyshev - * @version $Revision: 1.1.2.2.4.4 $ - */ - #ifndef _VM_THREADS_H_ #define _VM_THREADS_H_ - #ifdef PLATFORM_POSIX #include #include "platform_lowlevel.h" @@ -34,175 +28,110 @@ #include #include "open/types.h" -//#include "open/hythread.h" -#include +#include "open/hythread.h" +#include "open/hythread_ext.h" #include "open/ti_thread.h" - -#include "vm_core_types.h" -#include "object_layout.h" +#include "open/jthread.h" #include "open/vm_gc.h" -#include "exceptions_type.h" + #include "jvmti.h" #include "jni_direct.h" +#include "thread_manager.h" +#include "vm_core_types.h" +#include "object_layout.h" - -// #define tmn_suspend_disable assert(hythread_is_suspend_enabled());hythread_suspend_disable #define tmn_suspend_enable assert(!hythread_is_suspend_enabled());hythread_suspend_enable #define tmn_suspend_disable_recursive hythread_suspend_disable #define tmn_suspend_enable_recursive hythread_suspend_enable -#define GC_BYTES_IN_THREAD_LOCAL (20 * sizeof(void *)) - -// These are thread level gc states. -enum gc_state { - zero = 0, - gc_moving_to_safepoint, - gc_at_safepoint, - gc_enumeration_done -}; - - -struct jvmti_frame_pop_listener; -struct JVMTISingleStepState; - -class VmRegisterContext; - -class VM_thread { - -public: - /** - * Memory pool where this structure is allocated. - * This pool should be used by current thread for memory allocations. - */ - apr_pool_t * pool; - - /** - * JNI environment associated with this thread. - */ - JNIEnv_Internal * jni_env; - - /** - * Class loader which loads native library and calls to its JNI_OnLoad - */ - ClassLoader* onload_caller; - - /** - * Flag to detect if a class is not found on bootclasspath, - * as opposed to linkage errors. - * Used for implementing default delegation model. - */ - bool class_not_found; - - // In case exception is thrown, Exception object is put here - // TODO: Needs to be replaced with jobject! - //volatile ManagedObject* p_exception_object; - volatile Exception thread_exception; - - // For support of JVMTI events: EXCEPTION, EXCEPTION_CATCH - // If p_exception_object is set and p_exception_object_ti is not - // - EXCEPTION event should be generated - // If p_exception_object_ti is set and p_exception_object is not - // - EXCEPTION_CATCH even should be generated - volatile ManagedObject* p_exception_object_ti; - - // flag which indicate that guard page on the stak should be restored - bool restore_guard_page; - - // thread stack address - void* stack_addr; - - // thread stack size - unsigned int stack_size; - - // Should JVMTI code be notified about exception in p_exception_object - bool ti_exception_callback_pending; - - // ?? - gc_state gc_status; - int finalize_thread_flags; - // Flag indicating whether thread stopped. Duplicate of thread_state? - bool is_stoped; - - JVMTILocalStorage jvmti_local_storage; - // Buffer used to create instructions instead of original instruction - // to transfer execution control back to the code after breakpoint - // has been processed - jbyte jvmti_jit_breakpoints_handling_buffer[50]; - jvmti_frame_pop_listener *frame_pop_listener; - JVMTISingleStepState *ss_state; - Registers jvmti_saved_exception_registers; - - // CPU registers. - Registers regs; - - // This field is private the to M2nFrame module, init code should set it to NULL - // Informational frame - created when native is called from Java, - // used to store local handles (jobjects) + registers. - // =0 if there is no m2n frame. - M2nFrame* last_m2n_frame; - - // GC Information - Byte _gc_private_information[GC_BYTES_IN_THREAD_LOCAL]; - NativeObjectHandles* native_handles; - GcFrame* gc_frames; - //gc_enable_disable_state gc_enabled_status; - bool gc_wait_for_enumeration; - bool restore_context_after_gc_and_resume; - -#if defined(PLATFORM_POSIX) && defined(_IPF_) - // Linux/IPF - sem_t suspend_sem; // To suspend thread in signal handler - sem_t suspend_self; // To suspend current thread for signal handler - uint64 suspended_state; // Flag to indicate how the one thread is suspended - // Possible values: - // NOT_SUSPENDED, - // SUSPENDED_IN_SIGNAL_HANDLER, - // SUSPENDED_IN_DISABLE_GC_FOR_THREAD - uint64 t[2]; // t[0] <= rnat, t[1] <= bspstore for current thread context - // t[0] <= rnat, t[1] <= bsp for other thread context -#endif - - void *lastFrame; - void *firstFrame; - int interpreter_state; - void** stack_end; /// The upper boundary of the stack to scan when verifying stack enumeration +typedef VM_thread *vm_thread_accessor(); +VMEXPORT extern vm_thread_accessor *get_thread_ptr; - void* get_ip_from_regs() { return regs.get_ip(); } - void reset_regs_ip() { return regs.reset_ip(); } +inline void vm_set_exception_registers(VM_thread * thread, Registers & regs) +{ + if (!thread->regs) { + thread->regs = malloc(sizeof(Registers)); + assert(thread->regs); + } + *(Registers *) thread->regs = regs; +} +inline void *vm_get_ip_from_regs(VM_thread * thread) +{ + return ((Registers *) thread->regs)->get_ip(); +} -}; +inline void vm_reset_ip_from_regs(VM_thread * thread) +{ + ((Registers *) thread->regs)->reset_ip(); +} -typedef VM_thread *vm_thread_accessor(); -VMEXPORT extern vm_thread_accessor *get_thread_ptr; +inline jvmti_thread_t jthread_get_jvmti_thread(hythread_t native_thread) +{ + assert(native_thread); + vm_thread_t vm_thread = + (vm_thread_t)hythread_tls_get(native_thread, TM_THREAD_VM_TLS_KEY); + if (!vm_thread) { + return NULL; + } + return &(vm_thread->jvmti_thread); +} -//VMEXPORT VM_thread *get_vm_thread(hythread_t thr); -//VMEXPORT VM_thread *get_vm_thread_self(); +inline jvmti_thread_t jthread_self_jvmti() +{ + return jthread_get_jvmti_thread(hythread_self()); +} -inline VM_thread *get_vm_thread_fast_self() { - register hythread_t thr = hythread_self(); +inline void vm_set_jvmti_saved_exception_registers(VM_thread * thread, + Registers & regs) +{ + assert(thread); + assert(&thread->jvmti_thread); + jvmti_thread_t jvmti_thread = &thread->jvmti_thread; + if (!jvmti_thread->jvmti_saved_exception_registers) { + jvmti_thread->jvmti_saved_exception_registers = malloc(sizeof(Registers)); + assert(jvmti_thread->jvmti_saved_exception_registers); + } + *(Registers *) jvmti_thread->jvmti_saved_exception_registers = regs; +} - return thr ? ((VM_thread *)hythread_tls_get(thr, TM_THREAD_VM_TLS_KEY)) : NULL; +inline VM_thread *get_vm_thread_fast_self() +{ + register hythread_t thr = hythread_self(); + return thr ? ((VM_thread *) hythread_tls_get(thr, TM_THREAD_VM_TLS_KEY)) : + NULL; } -inline VM_thread *get_vm_thread(hythread_t thr) { +inline VM_thread *get_vm_thread(hythread_t thr) +{ if (thr == NULL) { return NULL; } - return (VM_thread *)hythread_tls_get(thr, TM_THREAD_VM_TLS_KEY); + return (VM_thread *) hythread_tls_get(thr, TM_THREAD_VM_TLS_KEY); } VMEXPORT void init_TLS_data(); -VMEXPORT void set_TLS_data(VM_thread *thread) ; +VMEXPORT void set_TLS_data(VM_thread * thread); uint16 get_self_stack_key(); #define p_TLS_vmthread (get_vm_thread_fast_self()) -Registers *thread_gc_get_context(VM_thread *, VmRegisterContext &); +//Registers *thread_gc_get_context(VM_thread *, VmRegisterContext &); void thread_gc_set_context(VM_thread *); -struct Global_Env; +/** + * Auxiliary function to update thread count + */ +void jthread_start_count(); +void jthread_end_count(); + +vm_thread_t jthread_allocate_vm_thread(hythread_t native_thread); +jint jthread_allocate_vm_thread_pool(JavaVM * java_vm, vm_thread_t vm_thread); +void jthread_deallocate_vm_thread_pool(vm_thread_t vm_thread); + +extern volatile VM_thread *p_the_safepoint_control_thread; // only set when a gc is happening +extern volatile safepoint_state global_safepoint_status; #endif //!_VM_THREADS_H_ Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/exception/exceptions_jit.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/exception/exceptions_jit.cpp?view=diff&rev=556704&r1=556703&r2=556704 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/vmcore/src/exception/exceptions_jit.cpp (original) +++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/exception/exceptions_jit.cpp Mon Jul 16 12:32:35 2007 @@ -252,11 +252,11 @@ DebugUtilsTI *ti = VM_Global_State::loader_env->TI; if (ti->isEnabled() && ti->is_single_step_enabled()) { - VM_thread *vm_thread = p_TLS_vmthread; + jvmti_thread_t jvmti_thread = jthread_self_jvmti(); ti->vm_brpt->lock(); - if (NULL != vm_thread->ss_state) + if (NULL != jvmti_thread->ss_state) { - jvmti_remove_single_step_breakpoints(ti, vm_thread); + jvmti_remove_single_step_breakpoints(ti, jvmti_thread); } ti->vm_brpt->unlock(); } @@ -318,9 +318,9 @@ // Start single step in exception handler if (ti->isEnabled() && ti->is_single_step_enabled()) { - VM_thread *vm_thread = p_TLS_vmthread; + jvmti_thread_t jvmti_thread = jthread_self_jvmti(); ti->vm_brpt->lock(); - if (NULL != vm_thread->ss_state) + if (NULL != jvmti_thread->ss_state) { uint16 bc; NativeCodePtr ip = handler->get_handler_ip(); @@ -330,7 +330,7 @@ jvmti_StepLocation method_start = {(Method *)method, ip, bc, false}; - jvmti_set_single_step_breakpoints(ti, vm_thread, + jvmti_set_single_step_breakpoints(ti, jvmti_thread, &method_start, 1); } ti->vm_brpt->unlock(); Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/gc/root_set_enum_common.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/gc/root_set_enum_common.cpp?view=diff&rev=556704&r1=556703&r2=556704 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/vmcore/src/gc/root_set_enum_common.cpp (original) +++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/gc/root_set_enum_common.cpp Mon Jul 16 12:32:35 2007 @@ -266,14 +266,14 @@ if (thread->thread_exception.exc_cause != NULL) { vm_enumerate_root_reference((void **)&(thread->thread_exception.exc_cause), FALSE); } - if (thread->p_exception_object_ti != NULL) { - vm_enumerate_root_reference((void **)&(thread->p_exception_object_ti), FALSE); + if (thread->jvmti_thread.p_exception_object_ti != NULL) { + vm_enumerate_root_reference((void **)&(thread->jvmti_thread.p_exception_object_ti), FALSE); } if (thread->native_handles) - thread->native_handles->enumerate(); + ((NativeObjectHandles*)(thread->native_handles))->enumerate(); if (thread->gc_frames) { - thread->gc_frames->enumerate(); + ((GcFrame*)(thread->gc_frames))->enumerate(); } } //vm_enumerate_root_set_single_thread_not_on_stack Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/vm_init.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/vm_init.cpp?view=diff&rev=556704&r1=556703&r2=556704 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/vm_init.cpp (original) +++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/vm_init.cpp Mon Jul 16 12:32:35 2007 @@ -604,7 +604,7 @@ } assert(native_thread); - status = vm_attach(java_vm, &jni_env, NULL); + status = vm_attach(java_vm, &jni_env); if (status != JNI_OK) return status; *p_jni_env = jni_env; @@ -723,7 +723,7 @@ extern void initialize_signals(); initialize_signals(); - status = vm_attach(java_vm, &jni_env, NULL); + status = vm_attach(java_vm, &jni_env); if (status != JNI_OK) return status; // "Tool Interface" initialization Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/jit/compile.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jit/compile.cpp?view=diff&rev=556704&r1=556703&r2=556704 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/vmcore/src/jit/compile.cpp (original) +++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/jit/compile.cpp Mon Jul 16 12:32:35 2007 @@ -812,7 +812,9 @@ if(ti->isEnabled() && ti->is_single_step_enabled() && !method->is_native()) { - jvmti_set_single_step_breakpoints_for_method(ti, p_TLS_vmthread, method); + jvmti_thread_t jvmti_thread = jthread_self_jvmti(); + assert(jvmti_thread); + jvmti_set_single_step_breakpoints_for_method(ti, jvmti_thread, method); } return entry_point; Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/jit/ini.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jit/ini.cpp?view=diff&rev=556704&r1=556703&r2=556704 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/vmcore/src/jit/ini.cpp (original) +++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/jit/ini.cpp Mon Jul 16 12:32:35 2007 @@ -54,7 +54,9 @@ DebugUtilsTI *ti = VM_Global_State::loader_env->TI; if(ti->isEnabled() && ti->is_single_step_enabled()) { // Start single stepping a new Java method - jvmti_set_single_step_breakpoints_for_method(ti, p_TLS_vmthread, (Method*)method); + jvmti_thread_t jvmti_thread = jthread_self_jvmti(); + assert(jvmti_thread); + jvmti_set_single_step_breakpoints_for_method(ti, jvmti_thread, (Method*)method); } VM_Global_State::loader_env->em_interface->ExecuteMethod(method, result, args); @@ -65,19 +67,20 @@ if (ti->isEnabled() && ti->is_single_step_enabled()) { VM_thread *vm_thread = p_TLS_vmthread; + jvmti_thread_t jvmti_thread = &vm_thread->jvmti_thread; LMAutoUnlock lock(ti->vm_brpt->get_lock()); - if (NULL != vm_thread->ss_state) + if (NULL != jvmti_thread->ss_state) { // Start single stepping a new Java method - jvmti_remove_single_step_breakpoints(ti, vm_thread); + jvmti_remove_single_step_breakpoints(ti, jvmti_thread); jvmti_StepLocation *method_return; unsigned locations_number; jvmtiError errorCode = jvmti_get_next_bytecodes_from_native( - vm_thread, &method_return, &locations_number, is_in_jni_method()); + vm_thread, &method_return, &locations_number, is_in_jni_method()); assert (JVMTI_ERROR_NONE == errorCode); - jvmti_set_single_step_breakpoints(ti , vm_thread, method_return, locations_number); + jvmti_set_single_step_breakpoints(ti, jvmti_thread, method_return, locations_number); } } } Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti.cpp?view=diff&rev=556704&r1=556703&r2=556704 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti.cpp (original) +++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti.cpp Mon Jul 16 12:32:35 2007 @@ -305,6 +305,9 @@ break; } } + if (TRUE == get_boolean_property("vm.jvmti.enabled", FALSE, VM_PROPERTIES)) { + p_env->TI->setEnabled(); + } } DebugUtilsTI::DebugUtilsTI() : Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_break_intf.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_break_intf.cpp?view=diff&rev=556704&r1=556703&r2=556704 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_break_intf.cpp (original) +++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_break_intf.cpp Mon Jul 16 12:32:35 2007 @@ -593,7 +593,8 @@ // JVMTI handles it, and registers context is saved for us in TLS VM_thread *vm_thread = p_TLS_vmthread; lock(); - Registers regs = vm_thread->jvmti_saved_exception_registers; + Registers regs = + *(Registers*)vm_thread->jvmti_thread.jvmti_saved_exception_registers; NativeCodePtr addr = (NativeCodePtr)regs.get_ip(); TRACE2("jvmti.break", "Native breakpoint occured: " << addr); @@ -703,7 +704,7 @@ // Registers in TLS can be changed in user callbacks // It should be restored to keep original address of instrumented instruction // Exception/signal handlers use it when HWE occurs in instruction buffer - vm_thread->jvmti_saved_exception_registers = regs; + vm_set_jvmti_saved_exception_registers(vm_thread, regs); unlock(); // Now we need to return back to normal code execution, it is @@ -714,7 +715,8 @@ // special handling. InstructionDisassembler::Type type = idisasm.get_type(); - instruction_buffer = vm_thread->jvmti_jit_breakpoints_handling_buffer; + instruction_buffer = + vm_thread->jvmti_thread.jvmti_jit_breakpoints_handling_buffer; jbyte *interrupted_instruction = (jbyte *)addr; jint instruction_length = idisasm.get_length_with_prefix(); @@ -1367,7 +1369,7 @@ // Store possibly corrected location regs->set_ip((void*)native_location); // Copy original registers to TLS - vm_thread->jvmti_saved_exception_registers = *regs; + vm_set_jvmti_saved_exception_registers(vm_thread, *regs); // Set return address for exception handler #if defined (PLATFORM_POSIX) || defined(_EM64T_) regs->set_ip((void*)process_native_breakpoint_event); Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_event.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_event.cpp?view=diff&rev=556704&r1=556703&r2=556704 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_event.cpp (original) +++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_event.cpp Mon Jul 16 12:32:35 2007 @@ -247,7 +247,7 @@ return JVMTI_ERROR_INVALID_THREAD; jint thread_state; - IDATA UNUSED status = jthread_get_state(event_thread, &thread_state); + IDATA UNUSED status = jthread_get_jvmti_state(event_thread, &thread_state); assert(status == TM_ERROR_NONE); if (!(thread_state & JVMTI_THREAD_STATE_ALIVE)) @@ -876,7 +876,7 @@ jint depth = get_thread_stack_depth(curr_thread); #ifndef NDEBUG - if( curr_thread->frame_pop_listener ) { + if( curr_thread->jvmti_thread.frame_pop_listener ) { TRACE2("jvmti.stack", "Prepare to PopFrame callback for thread: " << curr_thread << ", method: " << class_get_name(method_get_class((Method*)method)) << "." << method_get_name((Method*)method) @@ -887,9 +887,9 @@ #endif // NDEBUG jvmti_frame_pop_listener *last = NULL; - for( jvmti_frame_pop_listener *fpl = curr_thread->frame_pop_listener; + for( jvmti_frame_pop_listener *fpl = curr_thread->jvmti_thread.frame_pop_listener; fpl; - last = fpl, (fpl = fpl ? fpl->next : curr_thread->frame_pop_listener) ) + last = fpl, (fpl = fpl ? fpl->next : curr_thread->jvmti_thread.frame_pop_listener) ) { TRACE2("jvmti.stack", "-> Look through listener: " << fpl << ", env: " << fpl->env << ", depth: " << fpl->depth); @@ -900,7 +900,7 @@ if(last) { last->next = fpl->next; } else { - curr_thread->frame_pop_listener = fpl->next; + curr_thread->jvmti_thread.frame_pop_listener = fpl->next; } fpl = last; @@ -1376,7 +1376,6 @@ VM_thread *curr_thread = p_TLS_vmthread; hythread_t curr_native_thread=hythread_self(); - curr_thread->ti_exception_callback_pending = false; DebugUtilsTI *ti = VM_Global_State::loader_env->TI; assert(ti->isEnabled()); @@ -2025,17 +2024,17 @@ if (!ti->is_single_step_enabled()) return; + jvmti_thread_t jvmti_thread = jthread_self_jvmti(); if (is_start) { // Init single step state for the thread - VM_thread *vm_thread = p_TLS_vmthread; LMAutoUnlock lock(ti->vm_brpt->get_lock()); jvmtiError UNREF errorCode = _allocate(sizeof(JVMTISingleStepState), - (unsigned char **)&vm_thread->ss_state); + (unsigned char **)&jvmti_thread->ss_state); assert(JVMTI_ERROR_NONE == errorCode); - vm_thread->ss_state->predicted_breakpoints = NULL; + jvmti_thread->ss_state->predicted_breakpoints = NULL; // There is no need to set a breakpoint in a thread which // is started inside of jvmti_send_thread_start_end_event() function. @@ -2047,16 +2046,15 @@ else { // Shut down single step state for the thread - VM_thread *vm_thread = p_TLS_vmthread; LMAutoUnlock lock(ti->vm_brpt->get_lock()); - jvmti_remove_single_step_breakpoints(ti, vm_thread); - if( vm_thread->ss_state ) { - if( vm_thread->ss_state->predicted_breakpoints ) { - ti->vm_brpt->release_intf(vm_thread->ss_state->predicted_breakpoints); + jvmti_remove_single_step_breakpoints(ti, jvmti_thread); + if( jvmti_thread->ss_state ) { + if( jvmti_thread->ss_state->predicted_breakpoints ) { + ti->vm_brpt->release_intf(jvmti_thread->ss_state->predicted_breakpoints); } - _deallocate((unsigned char *)vm_thread->ss_state); - vm_thread->ss_state = NULL; + _deallocate((unsigned char *)jvmti_thread->ss_state); + jvmti_thread->ss_state = NULL; } } } Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_pop_frame.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_pop_frame.cpp?view=diff&rev=556704&r1=556703&r2=556704 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_pop_frame.cpp (original) +++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_pop_frame.cpp Mon Jul 16 12:32:35 2007 @@ -38,7 +38,8 @@ static void jvmti_pop_frame_callback() { TRACE(("JVMTI PopFrame callback is called")); - frame_type type = m2n_get_frame_type(p_TLS_vmthread->last_m2n_frame); + frame_type type = + m2n_get_frame_type((M2nFrame*)(p_TLS_vmthread->last_m2n_frame)); // frame wasn't requested to be popped if (FRAME_POP_NOW != (FRAME_POP_NOW & type)) { @@ -307,11 +308,11 @@ DebugUtilsTI *ti = VM_Global_State::loader_env->TI; if (ti->isEnabled() && ti->is_single_step_enabled()) { - VM_thread *vm_thread = p_TLS_vmthread; + jvmti_thread_t jvmti_thread = jthread_self_jvmti(); LMAutoUnlock lock(ti->vm_brpt->get_lock()); - if (NULL != vm_thread->ss_state) { + if (NULL != jvmti_thread->ss_state) { // remove old single step breakpoints - jvmti_remove_single_step_breakpoints(ti, vm_thread); + jvmti_remove_single_step_breakpoints(ti, jvmti_thread); // set new single step breakpoints CodeChunkInfo *cci = si_get_code_chunk_info(si); @@ -324,7 +325,7 @@ assert(EXE_ERROR_NONE == result); jvmti_StepLocation locations = {method, ip, bc, false}; - jvmti_set_single_step_breakpoints(ti, vm_thread, &locations, 1); + jvmti_set_single_step_breakpoints(ti, jvmti_thread, &locations, 1); } } return; Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_roots.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_roots.cpp?view=diff&rev=556704&r1=556703&r2=556704 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_roots.cpp (original) +++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_roots.cpp Mon Jul 16 12:32:35 2007 @@ -268,14 +268,14 @@ if (thread->thread_exception.exc_cause != NULL) { vm_enumerate_root_reference((void **)&(thread->thread_exception.exc_cause), FALSE); } - if (thread->p_exception_object_ti != NULL) { - vm_enumerate_root_reference((void **)&(thread->p_exception_object_ti), FALSE); + if (thread->jvmti_thread.p_exception_object_ti != NULL) { + vm_enumerate_root_reference((void **)&(thread->jvmti_thread.p_exception_object_ti), FALSE); } if (thread->native_handles) - thread->native_handles->enumerate(); + ((NativeObjectHandles*)(thread->native_handles))->enumerate(); if (thread->gc_frames) { - thread->gc_frames->enumerate(); + ((GcFrame*)(thread->gc_frames))->enumerate(); } } Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_stack.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_stack.cpp?view=diff&rev=556704&r1=556703&r2=556704 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_stack.cpp (original) +++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_stack.cpp Mon Jul 16 12:32:35 2007 @@ -872,8 +872,8 @@ new_listener->depth = jsi.get_depth() - depth; new_listener->env = reinterpret_cast(env); - new_listener->next = vm_thread->frame_pop_listener; - vm_thread->frame_pop_listener = new_listener; + new_listener->next = vm_thread->jvmti_thread.frame_pop_listener; + vm_thread->jvmti_thread.frame_pop_listener = new_listener; TRACE("Pop listener is created: thread: " << vm_thread << ", listener: " << new_listener Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_step.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_step.cpp?view=diff&rev=556704&r1=556703&r2=556704 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_step.cpp (original) +++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_step.cpp Mon Jul 16 12:32:35 2007 @@ -443,25 +443,25 @@ static void jvmti_setup_jit_single_step(DebugUtilsTI *ti, Method* m, jlocation location) { - VM_thread* vm_thread = p_TLS_vmthread; + jvmti_thread_t jvmti_thread = jthread_self_jvmti(); jvmti_StepLocation *locations; unsigned locations_count; - jvmti_SingleStepLocation(vm_thread, m, (unsigned)location, + jvmti_SingleStepLocation(p_TLS_vmthread, m, (unsigned)location, &locations, &locations_count); // lock breakpoints VMBreakPoints* vm_brpt = VM_Global_State::loader_env->TI->vm_brpt; LMAutoUnlock lock(vm_brpt->get_lock()); - jvmti_remove_single_step_breakpoints(ti, vm_thread); + jvmti_remove_single_step_breakpoints(ti, jvmti_thread); - jvmti_set_single_step_breakpoints(ti, vm_thread, locations, locations_count); + jvmti_set_single_step_breakpoints(ti, jvmti_thread, locations, locations_count); } void jvmti_set_single_step_breakpoints_for_method(DebugUtilsTI *ti, - VM_thread *vm_thread, + jvmti_thread_t jvmti_thread, Method *method) { if (ti->isEnabled() && ti->is_single_step_enabled()) @@ -470,12 +470,12 @@ return; LMAutoUnlock lock(ti->vm_brpt->get_lock()); - if (NULL != vm_thread->ss_state) + if (NULL != jvmti_thread->ss_state) { - jvmti_remove_single_step_breakpoints(ti, vm_thread); + jvmti_remove_single_step_breakpoints(ti, jvmti_thread); jvmti_StepLocation method_start = {method, NULL, 0, false}; - jvmti_set_single_step_breakpoints(ti, vm_thread, &method_start, 1); + jvmti_set_single_step_breakpoints(ti, jvmti_thread, &method_start, 1); } } } @@ -485,7 +485,10 @@ { #if (defined _IA32_) || (defined _EM64T_) VM_thread *vm_thread = p_TLS_vmthread; - Registers *regs = &vm_thread->jvmti_saved_exception_registers; + assert(vm_thread); + jvmti_thread_t jvmti_thread = &vm_thread->jvmti_thread; + assert(jvmti_thread); + Registers regs = *(Registers*)(jvmti_thread->jvmti_saved_exception_registers); // This is a virtual breakpoint set exactly on the call // instruction for the virtual method. In this place it is // possible to determine the target method in runtime @@ -500,11 +503,11 @@ // Invokevirtual uses indirect call from VTable. The base // address is in the register, offset is in displacement * // scale. This method is much faster than - VTable* vtable = (VTable*)disasm->get_reg_value(op.base, regs); + VTable* vtable = (VTable*)disasm->get_reg_value(op.base, ®s); assert(vtable); // For x86 based architectures offset cannot be longer than 32 // bits, so unsigned is ok here - unsigned offset = (unsigned)((POINTER_SIZE_INT)disasm->get_reg_value(op.index, regs) * + unsigned offset = (unsigned)((POINTER_SIZE_INT)disasm->get_reg_value(op.index, ®s) * op.scale + op.disp); method = class_get_method_from_vt_offset(vtable, offset); } @@ -513,7 +516,7 @@ // This is invokeinterface bytecode which uses register // call so we need to search through all methods for this // one to find it, no way to get vtable and offset in it - NativeCodePtr ip = disasm->get_target_address_from_context(regs); + NativeCodePtr ip = disasm->get_target_address_from_context(®s); Global_Env * vm_env = jni_get_vm_env(vm_thread->jni_env); CodeChunkInfo *cci = vm_env->vm_methods->find(ip); if (cci) @@ -547,7 +550,7 @@ // The determined method is the one which is called by // invokevirtual or invokeinterface bytecodes. It should be // started to be single stepped from the beginning - jvmti_set_single_step_breakpoints_for_method(ti, vm_thread, method); + jvmti_set_single_step_breakpoints_for_method(ti, jvmti_thread, method); #else NOT_IMPLEMENTED; #endif @@ -570,7 +573,9 @@ return false; ti->vm_brpt->lock(); - JVMTISingleStepState* sss = p_TLS_vmthread->ss_state; + jvmti_thread_t jvmti_thread = jthread_self_jvmti(); + assert(jvmti_thread); + JVMTISingleStepState* sss = jvmti_thread->ss_state; if (!sss || !ti->is_single_step_enabled()) { ti->vm_brpt->unlock(); @@ -677,13 +682,13 @@ return true; } -void jvmti_set_single_step_breakpoints(DebugUtilsTI *ti, VM_thread *vm_thread, +void jvmti_set_single_step_breakpoints(DebugUtilsTI *ti, jvmti_thread_t jvmti_thread, jvmti_StepLocation *locations, unsigned locations_number) { // Function is always executed under global TI breakpoints lock ASSERT_NO_INTERPRETER; - JVMTISingleStepState *ss_state = vm_thread->ss_state; + JVMTISingleStepState *ss_state = jvmti_thread->ss_state; if( NULL == ss_state ) { // no need predict next step due to single step is off return; @@ -730,10 +735,10 @@ } } -void jvmti_remove_single_step_breakpoints(DebugUtilsTI *ti, VM_thread *vm_thread) +void jvmti_remove_single_step_breakpoints(DebugUtilsTI *ti, jvmti_thread_t jvmti_thread) { // Function is always executed under global TI breakpoints lock - JVMTISingleStepState *ss_state = vm_thread->ss_state; + JVMTISingleStepState *ss_state = jvmti_thread->ss_state; TRACE2("jvmti.break.ss", "Remove single step breakpoints, intf: " << (ss_state ? ss_state->predicted_breakpoints : NULL) ); @@ -937,17 +942,25 @@ // Set single step in all threads while ((ht = hythread_iterator_next(&threads_iterator)) != NULL) { - VM_thread *vm_thread = get_vm_thread(ht); + vm_thread_t vm_thread = + (vm_thread_t)hythread_tls_get(ht, TM_THREAD_VM_TLS_KEY); if( !vm_thread ) { - // Skip thread that isn't started yet. SingleStep state - // will be enabled for it in + // Skip thread that isn't started yet. + // SingleStep state will be enabled for it in + // jvmti_send_thread_start_end_event() + continue; + } + jvmti_thread_t jvmti_thread = &vm_thread->jvmti_thread; + if( !jvmti_thread ) { + // Skip thread that isn't started yet. + // SingleStep state will be enabled for it in // jvmti_send_thread_start_end_event continue; } // Init single step state for the thread jvmtiError errorCode = _allocate(sizeof(JVMTISingleStepState), - (unsigned char **)&vm_thread->ss_state); + (unsigned char **)&jvmti_thread->ss_state); if (JVMTI_ERROR_NONE != errorCode) { @@ -955,7 +968,7 @@ return errorCode; } - vm_thread->ss_state->predicted_breakpoints = NULL; + jvmti_thread->ss_state->predicted_breakpoints = NULL; jvmti_StepLocation *locations; unsigned locations_number; @@ -969,7 +982,7 @@ return errorCode; } - jvmti_set_single_step_breakpoints(this, vm_thread, locations, locations_number); + jvmti_set_single_step_breakpoints(this, jvmti_thread, locations, locations_number); } single_step_enabled = true; @@ -1014,20 +1027,20 @@ // Clear single step in all threads while ((ht = hythread_iterator_next(&threads_iterator)) != NULL) { - VM_thread *vm_thread = get_vm_thread(ht); - if( !vm_thread ) { + jvmti_thread_t jvmti_thread = jthread_get_jvmti_thread(ht); + if( !jvmti_thread ) { // Skip thread that isn't started yet. No need to disable // SingleStep state for it continue; } - if( vm_thread->ss_state ) { - jvmti_remove_single_step_breakpoints(this, vm_thread); - if( vm_thread->ss_state->predicted_breakpoints ) { - vm_brpt->release_intf(vm_thread->ss_state->predicted_breakpoints); + if( jvmti_thread->ss_state ) { + jvmti_remove_single_step_breakpoints(this, jvmti_thread); + if( jvmti_thread->ss_state->predicted_breakpoints ) { + vm_brpt->release_intf(jvmti_thread->ss_state->predicted_breakpoints); } - _deallocate((unsigned char *)vm_thread->ss_state); - vm_thread->ss_state = NULL; + _deallocate((unsigned char *)jvmti_thread->ss_state); + jvmti_thread->ss_state = NULL; } } Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_thread.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_thread.cpp?view=diff&rev=556704&r1=556703&r2=556704 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_thread.cpp (original) +++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_thread.cpp Mon Jul 16 12:32:35 2007 @@ -81,7 +81,7 @@ if (thread_state_ptr == NULL){ return JVMTI_ERROR_NULL_POINTER; } - IDATA UNUSED status = jthread_get_state(thread, thread_state_ptr); + IDATA UNUSED status = jthread_get_jvmti_state(thread, thread_state_ptr); assert(status == TM_ERROR_NONE); return JVMTI_ERROR_NONE; @@ -469,7 +469,7 @@ } jint thread_state; - IDATA UNUSED status = jthread_get_state(thread, &thread_state); + IDATA UNUSED status = jthread_get_jvmti_state(thread, &thread_state); assert(status == TM_ERROR_NONE); if (! (JVMTI_THREAD_STATE_ALIVE & thread_state)) @@ -697,15 +697,16 @@ CallVoidMethod(jvmti_test_jenv, thread, set_daemon, JNI_TRUE); jni_env = jthread_get_JNI_env(jthread_self()); + // Run new thread - // FIXME TM integration, pass arguments correctly - //Java_java_lang_Thread_start_generic(jvmti_test_jenv, thread, env, proc, arg, priority); - jthread_threadattr_t attrs; + jthread_threadattr_t attrs = {0}; attrs.priority = priority; - attrs.stacksize = 0; attrs.daemon = JNI_TRUE; attrs.jvmti_env = env; - jthread_create_with_function(jni_env, thread, &attrs, proc, arg); + attrs.proc = proc; + attrs.arg = arg; + + jthread_create_with_function(jni_env, thread, &attrs); ti->setLocallyEnabled();//-----------------------------------^ Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMThreadManager.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMThreadManager.cpp?view=diff&rev=556704&r1=556703&r2=556704 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMThreadManager.cpp (original) +++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMThreadManager.cpp Mon Jul 16 12:32:35 2007 @@ -29,6 +29,7 @@ #include "open/ti_thread.h" #include "open/thread_externals.h" #include "jni_utils.h" +#include "thread_manager.h" /* * Class: java_lang_VMThreadManager @@ -148,7 +149,7 @@ JNIEXPORT jlong JNICALL Java_java_lang_VMThreadManager_init (JNIEnv *jenv, jclass clazz, jobject thread, jobject ref, jlong oldThread) { - return jthread_thread_init(NULL, jenv, thread, ref, oldThread); + return jthread_thread_init(jenv, thread, ref, (hythread_t)oldThread); } /* @@ -159,11 +160,13 @@ JNIEXPORT jint JNICALL Java_java_lang_VMThreadManager_start (JNIEnv *jenv, jclass clazz, jobject thread, jlong stackSize, jboolean daemon, jint priority) { - jthread_threadattr_t attrs; + jthread_threadattr_t attrs = {0}; attrs.daemon = daemon; attrs.priority = priority; - attrs.stacksize = stackSize > 40000000? 0:(jint)stackSize; + // FIXME - may be define value 40000000 + attrs.stacksize = stackSize > 40000000 ? 0:(jint)stackSize; + return (jint)jthread_create(jenv, thread, &attrs); } @@ -225,13 +228,7 @@ tm_native_thread = (hythread_t )vm_jthread_get_tm_data((jthread)thread); assert(tm_native_thread); - if (hythread_is_alive(tm_native_thread)) - { - printf("isAlive\n"); - return true; - } - printf ("isnot\n"); - return false; + return hythread_is_alive(tm_native_thread) ? 1 : 0; } /* @@ -256,7 +253,7 @@ jint state; IDATA stat; - stat = jthread_get_state(jthread, &state); + stat = jthread_get_jvmti_state(jthread, &state); assert(stat == TM_ERROR_NONE); return state; } Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_lang_management_ThreadMXBeanImpl.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_lang_management_ThreadMXBeanImpl.cpp?view=diff&rev=556704&r1=556703&r2=556704 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_lang_management_ThreadMXBeanImpl.cpp (original) +++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/org_apache_harmony_lang_management_ThreadMXBeanImpl.cpp Mon Jul 16 12:32:35 2007 @@ -356,7 +356,7 @@ { jint thread_state; TRACE2("management", "ThreadMXBeanImpl_isSuspendedImpl invocation"); - IDATA UNUSED status = jthread_get_state(thread, &thread_state); + IDATA UNUSED status = jthread_get_jvmti_state(thread, &thread_state); assert(status == TM_ERROR_NONE); return thread_state & TM_THREAD_STATE_SUSPENDED; }; Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/object/object_handles.cpp URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/object/object_handles.cpp?view=diff&rev=556704&r1=556703&r2=556704 ============================================================================== --- harmony/enhanced/drlvm/trunk/vm/vmcore/src/object/object_handles.cpp (original) +++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/object/object_handles.cpp Mon Jul 16 12:32:35 2007 @@ -81,7 +81,7 @@ nodes = gc_frame_node_new(size_hint); else nodes = NULL; - next = p_TLS_vmthread->gc_frames; + next = (GcFrame*)p_TLS_vmthread->gc_frames; p_TLS_vmthread->gc_frames = this; } @@ -89,7 +89,7 @@ { assert(!hythread_is_suspend_enabled()); - assert(p_TLS_vmthread->gc_frames==this); + assert(((GcFrame*)p_TLS_vmthread->gc_frames) == this); p_TLS_vmthread->gc_frames = next; next = NULL; GcFrameNode* c; @@ -331,14 +331,14 @@ NativeObjectHandles::NativeObjectHandles() : handles(NULL) { - next = p_TLS_vmthread->native_handles; + next = (NativeObjectHandles*)p_TLS_vmthread->native_handles; p_TLS_vmthread->native_handles = this; } VMEXPORT // temporary solution for interpreter unplug NativeObjectHandles::~NativeObjectHandles() { - assert(p_TLS_vmthread->native_handles==this); + assert(((NativeObjectHandles*)p_TLS_vmthread->native_handles) == this); p_TLS_vmthread->native_handles = next; next = NULL; oh_free_handles(handles); @@ -386,7 +386,7 @@ m2n_set_local_handles(lm2nf, hs); } else { assert(p_TLS_vmthread->native_handles); - res = p_TLS_vmthread->native_handles->allocate(); + res = ((NativeObjectHandles*)p_TLS_vmthread->native_handles)->allocate(); } return res; }