harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wjwashb...@apache.org
Subject svn commit: r510623 - in /harmony/enhanced/drlvm/trunk/vm: include/open/ tests/unit/thread/ thread/src/ vmcore/include/ vmcore/src/init/ vmcore/src/thread/
Date Thu, 22 Feb 2007 18:53:51 GMT
Author: wjwashburn
Date: Thu Feb 22 10:53:49 2007
New Revision: 510623

URL: http://svn.apache.org/viewvc?view=rev&rev=510623
Log:
Harmony-2963, moves child thread memory allocation to parent, moves non-daemon thread
count to wrapper_proc
build, build test pass on winxp and linux rhel 4.0 w/ gcc 4.0.2


Modified:
    harmony/enhanced/drlvm/trunk/vm/include/open/thread_externals.h
    harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_basic.c
    harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_basic.c
    harmony/enhanced/drlvm/trunk/vm/vmcore/include/thread_manager.h
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/finalizer_thread.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/ref_enqueue_thread.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/vm_init.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_generic.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_manager.cpp

Modified: harmony/enhanced/drlvm/trunk/vm/include/open/thread_externals.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/include/open/thread_externals.h?view=diff&rev=510623&r1=510622&r2=510623
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/include/open/thread_externals.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/include/open/thread_externals.h Thu Feb 22 10:53:49 2007
@@ -72,8 +72,10 @@
  *
  * @param[in] java_vm    - current thread will be attached to the specified VM
  * @param[out] p_jni_env - will point to JNI environment assocciated with the thread
+ * @param[in] vm_thread_dummies - memory preallocated for Java thread structures (if NULL,
memory will be allocated automatically)
  */
-VMEXPORT jint vm_attach(JavaVM * java_vm, JNIEnv ** p_jni_env);
+VMEXPORT jint vm_attach(JavaVM * java_vm, JNIEnv ** p_jni_env, 
+			void *vm_thread_dummies);
 
 /**
  * Frees java related resources before thread exit.
@@ -118,6 +120,14 @@
  * @return <code>int</code>
  */
 VMEXPORT int ti_is_enabled();
+
+/** 
+ * Allocates memory needed for creating new vm thread
+ *
+ * @param[in] java_vm    - current thread will be attached to the specified VM
+ */
+
+VMEXPORT void *vm_allocate_thread_dummies(JavaVM *java_vm);
 
 #ifdef __cplusplus
 }

Modified: harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_basic.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_basic.c?view=diff&rev=510623&r1=510622&r2=510623
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_basic.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/tests/unit/thread/test_java_basic.c Thu Feb 22 10:53:49
2007
@@ -47,7 +47,7 @@
         }
     }
 
-    status = vm_attach(GLOBAL_VM, &jni_env);
+    status = vm_attach(GLOBAL_VM, &jni_env, NULL);
     if (status != JNI_OK) {
         tts->phase = TT_PHASE_ERROR;
         return 0;

Modified: harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_basic.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_basic.c?view=diff&rev=510623&r1=510622&r2=510623
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_basic.c (original)
+++ harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_basic.c Thu Feb 22 10:53:49 2007
@@ -40,6 +40,7 @@
     jvmtiEnv *tiEnv;
     jvmtiStartFunction tiProc;
     void *tiProcArgs;
+    void *vm_thread_dummies;
 } wrapper_proc_data;
 
 
@@ -75,17 +76,22 @@
     assert(jvmti_thread);
     java_thread = jvmti_thread->thread_object;
 
-    status = vm_attach(data->java_vm, &jni_env);
-    if (status != JNI_OK) return TM_ERROR_INTERNAL;
+    status = vm_attach(data->java_vm, &jni_env, data->vm_thread_dummies);
+    assert (status == JNI_OK);
 
     jvmti_thread->jenv = jni_env;
     jvmti_thread->daemon = data->daemon;
 
     TRACE(("TM: Java thread started: id=%d OS_handle=%p", native_thread->thread_id, apr_os_thread_current()));
 
+    if (!jvmti_thread->daemon) {
+        increase_nondaemon_threads_count(native_thread);
+    }
+
     // Send Thread Start event.
     jvmti_send_thread_start_end_event(1);
 
+
     if (data->tiProc != NULL) {
         data->tiProc(data->tiEnv, jni_env, data->tiProcArgs);
     } else {
@@ -120,6 +126,8 @@
 {
     hythread_t tm_native_thread = NULL;
     jvmti_thread_t tm_java_thread;
+    void *vm_thread_dummies;
+    
     wrapper_proc_data * data;
     IDATA status;
     
@@ -145,20 +153,25 @@
     if (data == NULL) {
         return TM_ERROR_OUT_OF_MEMORY;
     }
-    
-    // Prepare arguments for wrapper proc
+
+    // Get JavaVM 
     status = (*jni_env) -> GetJavaVM(jni_env, &data->java_vm);
     if (status != JNI_OK) return TM_ERROR_INTERNAL;
 
+    // Allocate memory needed by soon to be born thread
+    vm_thread_dummies = vm_allocate_thread_dummies(data->java_vm);
+
+    if (vm_thread_dummies == NULL) {
+	return TM_ERROR_OUT_OF_MEMORY;
+    }
+
+    // prepare args for wrapper_proc
     data->daemon = attrs->daemon;
     data->tiEnv  = attrs->jvmti_env;
     data->tiProc = proc;
     data->tiProcArgs = (void *)arg;
+    data->vm_thread_dummies = vm_thread_dummies;
 
-    if (!data->daemon) {
-        increase_nondaemon_threads_count(hythread_self());
-    }
-    
     status = hythread_create(&tm_native_thread, (attrs->stacksize)?attrs->stacksize:1024000,
                                attrs->priority, 0, wrapper_proc, data);
 

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=510623&r1=510622&r2=510623
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/include/thread_manager.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/include/thread_manager.h Thu Feb 22 10:53:49 2007
@@ -32,7 +32,7 @@
 
 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;

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/finalizer_thread.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/finalizer_thread.cpp?view=diff&rev=510623&r1=510622&r2=510623
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/finalizer_thread.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/finalizer_thread.cpp Thu Feb 22 10:53:49
2007
@@ -151,7 +151,7 @@
     JavaVM *java_vm = (JavaVM *)args[0];
     JNIEnv *jni_env = (JNIEnv *)args[1];
     
-    IDATA status = vm_attach(java_vm, &jni_env);
+    IDATA status = vm_attach(java_vm, &jni_env, NULL);
     if(status != TM_ERROR_NONE)
         return status;
     

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/ref_enqueue_thread.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/ref_enqueue_thread.cpp?view=diff&rev=510623&r1=510622&r2=510623
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/ref_enqueue_thread.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/ref_enqueue_thread.cpp Thu Feb 22 10:53:49
2007
@@ -89,7 +89,7 @@
     JavaVM *java_vm = (JavaVM *)args[0];
     JNIEnv *jni_env = (JNIEnv *)args[1];
     
-    IDATA status = vm_attach(java_vm, &jni_env);
+    IDATA status = vm_attach(java_vm, &jni_env, NULL);
     if(status != TM_ERROR_NONE)
         return status;
     

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=510623&r1=510622&r2=510623
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/vm_init.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/init/vm_init.cpp Thu Feb 22 10:53:49 2007
@@ -592,7 +592,7 @@
     }
     assert(native_thread);
 
-    status = vm_attach(java_vm, &jni_env);
+    status = vm_attach(java_vm, &jni_env, NULL);
     if (status != JNI_OK) return status;
 
     *p_jni_env = jni_env;
@@ -698,7 +698,7 @@
     extern void initialize_signals();
     initialize_signals(); 
 
-    status = vm_attach(java_vm, &jni_env);
+    status = vm_attach(java_vm, &jni_env, NULL);
     if (status != JNI_OK) return status;
     
     finalizer_threads_init(java_vm, jni_env);   /* added for NATIVE FINALIZER THREAD */

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_generic.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_generic.cpp?view=diff&rev=510623&r1=510622&r2=510623
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_generic.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_generic.cpp Thu Feb 22 10:53:49
2007
@@ -91,6 +91,59 @@
 
 extern struct JNINativeInterface_ jni_vtable;
 
+struct vmthread_dummies {
+    VM_thread *p_vm_thread;
+    ObjectHandles *p_object_handles;
+    M2nFrame *p_m2n_frame;
+};
+
+
+void *vm_allocate_thread_dummies(JavaVM *java_vm) {
+    struct vmthread_dummies *p_vmt_dummies;
+    VM_thread *vmt = allocate_thread_block((JavaVM_Internal *)java_vm);
+    
+    if (vmt == NULL) 
+	goto err;
+    
+    p_vmt_dummies = 
+	(struct vmthread_dummies *)apr_palloc(vmt->pool, sizeof(vmthread_dummies));
+    
+    if (p_vmt_dummies == NULL)
+	goto err;
+    
+    // Create top level M2N frame.
+    p_vmt_dummies->p_m2n_frame = 
+	(M2nFrame*) apr_palloc(vmt->pool, sizeof(M2nFrame));
+    // Create local handles.
+    p_vmt_dummies->p_object_handles = 
+	(ObjectHandles*) apr_palloc(vmt->pool, sizeof(ObjectHandlesNew));
+    // allocate jni env internal structures
+    vmt->jni_env = (JNIEnv_Internal *) apr_palloc(vmt->pool, 
+						  sizeof(JNIEnv_Internal));
+
+    if (vmt->jni_env == NULL || p_vmt_dummies->p_object_handles == NULL ||
+	p_vmt_dummies->p_m2n_frame == NULL)
+	goto err;
+    
+    p_vmt_dummies->p_vm_thread = vmt;
+
+    return (void*)p_vmt_dummies;
+
+ err:
+    if (p_vmt_dummies->p_m2n_frame)
+      free (p_vmt_dummies->p_m2n_frame);
+    if (p_vmt_dummies->p_object_handles)
+      free(p_vmt_dummies->p_object_handles);
+    if (vmt->jni_env)
+      free(vmt->jni_env);
+    if (p_vmt_dummies) 
+      free(p_vmt_dummies);
+    if (vmt) 
+      free(vmt);
+
+    return NULL;
+}
+    
 /**
  * Runs java.lang.Thread.detach() method.
  */
@@ -140,48 +193,64 @@
 /**
  * Attaches thread current thread to VM.
  */
-jint vm_attach(JavaVM * java_vm, JNIEnv ** p_jni_env) {
+jint vm_attach(JavaVM * java_vm, JNIEnv ** p_jni_env,
+	       void *pv_vmt_dummies) {
     M2nFrame * p_m2n;
     VM_thread * p_vm_thread;
     ObjectHandles * p_handles;
-    
+    struct vmthread_dummies *p_vmt_dummies = 
+	(struct vmthread_dummies *)pv_vmt_dummies;
+
+    if (p_vmt_dummies != NULL) {
+	p_m2n = p_vmt_dummies->p_m2n_frame;
+	p_vm_thread = p_vmt_dummies->p_vm_thread;
+	p_handles = p_vmt_dummies->p_object_handles;
+    }
+
     // It seems to be reasonable to have suspend enabled state here.
     // It is unsafe to perform operations which require suspend disabled
     // mode until current thread is not attaced to VM.
     assert(hythread_is_suspend_enabled());
 
-    p_vm_thread = p_TLS_vmthread;
-    if (p_vm_thread != NULL) {
-        if (java_vm != p_vm_thread->jni_env->vm) {
-            return TM_ERROR_INTERNAL;
-        }
-        *p_jni_env = p_vm_thread->jni_env;
-        return JNI_OK;
-    }
+    hythread_t hythread = hythread_self();
 
-    p_vm_thread = get_a_thread_block((JavaVM_Internal *)java_vm);
-    if (p_vm_thread == NULL) {
-        TRACE2("thread", "can't get a thread block for a new thread");
-        return JNI_ENOMEM;
+    if (p_vmt_dummies != NULL) {
+	// VMThread structure is already allocated, we only need to set
+	// TLS
+	set_TLS_data (p_vm_thread);
+    } else {
+	p_vm_thread = get_vm_thread(hythread);
+	
+	if (p_vm_thread != NULL) {
+	    assert (java_vm == p_vm_thread->jni_env->vm); 
+	    *p_jni_env = p_vm_thread->jni_env;
+	    return JNI_OK;
+	}
+	
+	p_vm_thread = get_a_thread_block((JavaVM_Internal *)java_vm);
     }
+
+    // if the assertion is false we cannot notify the parent thread
+    // that we started and it would hang in waitloop
+    assert (p_vm_thread != NULL);
     
-    // Create JNI environment for current thread.
-    p_vm_thread->jni_env = (JNIEnv_Internal *) apr_palloc(p_vm_thread->pool, sizeof(JNIEnv_Internal));
-    
+    if (p_vmt_dummies == NULL) {
+	// Create top level M2N frame.
+	p_m2n = (M2nFrame*) apr_palloc(p_vm_thread->pool, sizeof(M2nFrame));
+	// Create local handles.
+	p_handles = (ObjectHandles*) apr_palloc(p_vm_thread->pool, sizeof(ObjectHandlesNew));
+	p_vm_thread->jni_env = (JNIEnv_Internal *) apr_palloc(p_vm_thread->pool, sizeof(JNIEnv_Internal));
+    }
+
+    assert (p_m2n != NULL && p_handles != NULL && p_vm_thread->jni_env
!= NULL);
+
     // Initialize JNI environment.
     p_vm_thread->jni_env->functions = &jni_vtable;
     p_vm_thread->jni_env->vm = (JavaVM_Internal *)java_vm;
     p_vm_thread->jni_env->reserved0 = (void *)0x1234abcd;
     *p_jni_env = p_vm_thread->jni_env;
-    
-    // Create top level M2N frame.
-    p_m2n = (M2nFrame*) apr_palloc(p_vm_thread->pool, sizeof(M2nFrame));
-    // Create local handles.
-    p_handles = (ObjectHandles*) apr_palloc(p_vm_thread->pool, sizeof(ObjectHandlesNew));
-    if (p_vm_thread->jni_env == NULL || p_m2n == NULL ||p_handles == NULL) {
-        TRACE2("thread", "can't get a thread block for a new thread");
-        return JNI_ENOMEM;
-    }
+
+
     
     init_stack_info();
 

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_manager.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_manager.cpp?view=diff&rev=510623&r1=510622&r2=510623
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_manager.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_manager.cpp Thu Feb 22 10:53:49
2007
@@ -89,20 +89,34 @@
 
 void init_TLS_data();
 
-VM_thread * get_a_thread_block(JavaVM_Internal * java_vm) {
+VM_thread * allocate_thread_block(JavaVM_Internal * java_vm) {
     VM_thread * p_vmthread;
     apr_pool_t * thread_pool;
+  
+    if (apr_pool_create(&thread_pool, java_vm->vm_env->mem_pool) != APR_SUCCESS)
{
+	return NULL;
+    }
+    p_vmthread = (VM_thread *) apr_pcalloc(thread_pool, sizeof(VM_thread));
+
+    if (!p_vmthread) return NULL;
+    
+    p_vmthread->pool = thread_pool;
+
+    return p_vmthread;
+}
+  
+
+
+VM_thread * get_a_thread_block(JavaVM_Internal * java_vm) {
+    VM_thread * p_vmthread;
 
     p_vmthread = p_TLS_vmthread;
     if (!p_vmthread) {
-        if (apr_pool_create(&thread_pool, java_vm->vm_env->mem_pool) != APR_SUCCESS)
{
-            return NULL;
-        }
-        p_vmthread = (VM_thread *) apr_pcalloc(thread_pool, sizeof(VM_thread));
-        if (!p_vmthread) return NULL;
+      p_vmthread = allocate_thread_block(java_vm);
+      
+      if (!p_vmthread) return NULL;
+      set_TLS_data(p_vmthread);
 
-        p_vmthread->pool = thread_pool;
-        set_TLS_data(p_vmthread);
     } else {
         memset(p_vmthread, 0, sizeof(VM_thread));
     }



Mime
View raw message