harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arc...@apache.org
Subject svn commit: r409254 - in /incubator/harmony/enhanced/jchevm/libjc: jni_invoke.c libjc.h native/java_lang_VMSystem.c native/java_lang_VMThread.c native_lib.c structures.h thread.c vm.c
Date Wed, 24 May 2006 21:22:36 GMT
Author: archie
Date: Wed May 24 14:22:35 2006
New Revision: 409254

URL: http://svn.apache.org/viewvc?rev=409254&view=rev
Log:
- Remove native methods in java.lang.VMSystem that are already implemented
  by Classpath.
- Create Thread objects lazily. This change is required for Classpath 0.91.

Modified:
    incubator/harmony/enhanced/jchevm/libjc/jni_invoke.c
    incubator/harmony/enhanced/jchevm/libjc/libjc.h
    incubator/harmony/enhanced/jchevm/libjc/native/java_lang_VMSystem.c
    incubator/harmony/enhanced/jchevm/libjc/native/java_lang_VMThread.c
    incubator/harmony/enhanced/jchevm/libjc/native_lib.c
    incubator/harmony/enhanced/jchevm/libjc/structures.h
    incubator/harmony/enhanced/jchevm/libjc/thread.c
    incubator/harmony/enhanced/jchevm/libjc/vm.c

Modified: incubator/harmony/enhanced/jchevm/libjc/jni_invoke.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/jchevm/libjc/jni_invoke.c?rev=409254&r1=409253&r2=409254&view=diff
==============================================================================
--- incubator/harmony/enhanced/jchevm/libjc/jni_invoke.c (original)
+++ incubator/harmony/enhanced/jchevm/libjc/jni_invoke.c Wed May 24 14:22:35 2006
@@ -241,7 +241,7 @@
 
 	/* Create and attach a new thread structure to the current thread */
 	_JC_MUTEX_LOCK(NULL, vm->mutex);
-	env = _jc_attach_thread(vm, &einfo, &cstack);
+	env = _jc_attach_thread(vm, NULL, JNI_FALSE, &einfo, &cstack);
 	_JC_MUTEX_UNLOCK(NULL, vm->mutex);
 	if (env == NULL) {
 		_jc_eprintf(vm, "%s: %s: %s\n", __FUNCTION__,
@@ -256,8 +256,7 @@
 
 	/* Create java.lang.Thread instance */
 	if (_jc_thread_create_instance(env,
-	    (args != NULL && args->group != NULL) ?
-	      *args->group : vm->boot.objects.systemThreadGroup,
+	    (args != NULL && args->group != NULL) ? *args->group : NULL,
 	    (args != NULL && args->name != NULL) ? args->name : NULL,
 	    vm->threads.java_prio_norm, daemon) != JNI_OK)
 		goto fail;

Modified: incubator/harmony/enhanced/jchevm/libjc/libjc.h
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/jchevm/libjc/libjc.h?rev=409254&r1=409253&r2=409254&view=diff
==============================================================================
--- incubator/harmony/enhanced/jchevm/libjc/libjc.h (original)
+++ incubator/harmony/enhanced/jchevm/libjc/libjc.h Wed May 24 14:22:35 2006
@@ -480,7 +480,8 @@
 extern void		_jc_free_thread(_jc_env **envp, int cachable);
 extern void		_jc_free_thread_stacks(_jc_jvm *vm);
 extern void		_jc_destroy_thread(_jc_env **envp);
-extern _jc_env		*_jc_attach_thread(_jc_jvm *vm, _jc_ex_info *ex,
+extern _jc_env		*_jc_attach_thread(_jc_jvm *vm, const char *name,
+				jboolean daemon, _jc_ex_info *ex,
 				_jc_c_stack *cstack);
 extern void		_jc_detach_thread(_jc_env **envp);
 extern jint		_jc_thread_create_instance(_jc_env *env,

Modified: incubator/harmony/enhanced/jchevm/libjc/native/java_lang_VMSystem.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/jchevm/libjc/native/java_lang_VMSystem.c?rev=409254&r1=409253&r2=409254&view=diff
==============================================================================
--- incubator/harmony/enhanced/jchevm/libjc/native/java_lang_VMSystem.c (original)
+++ incubator/harmony/enhanced/jchevm/libjc/native/java_lang_VMSystem.c Wed May 24 14:22:35
2006
@@ -15,7 +15,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  *
- * $Id: java_lang_VMSystem.c,v 1.6 2005/05/15 21:41:01 archiecobbs Exp $
+ * $Id$
  */
 
 #include "libjc.h"
@@ -150,91 +150,5 @@
 JCNI_java_lang_VMSystem_identityHashCode(_jc_env *env, _jc_object *obj)
 {
 	return (jint)obj;
-}
-
-/*
- * static final native void setIn(InputStream)
- */
-void _JC_JCNI_ATTR
-JCNI_java_lang_VMSystem_setIn(_jc_env *env, _jc_object *is)
-{
-	_jc_jvm *const vm = env->vm;
-
-	*_JC_VMSTATICFIELD(vm, System, in, _jc_object *) = is;
-}
-
-/*
- * static final native void setOut(PrintStream)
- */
-void _JC_JCNI_ATTR
-JCNI_java_lang_VMSystem_setOut(_jc_env *env, _jc_object *ps)
-{
-	_jc_jvm *const vm = env->vm;
-
-	*_JC_VMSTATICFIELD(vm, System, out, _jc_object *) = ps;
-}
-
-/*
- * static final native void setErr(PrintStream)
- */
-void _JC_JCNI_ATTR
-JCNI_java_lang_VMSystem_setErr(_jc_env *env, _jc_object *ps)
-{
-	_jc_jvm *const vm = env->vm;
-
-	*_JC_VMSTATICFIELD(vm, System, err, _jc_object *) = ps;
-}
-
-/*
- * public static final native long currentTimeMillis()
- */
-jlong _JC_JCNI_ATTR
-JCNI_java_lang_VMSystem_currentTimeMillis(_jc_env *env)
-{
-	struct timeval tv;
-
-	if (gettimeofday(&tv, NULL) == -1) {
-		_jc_post_exception_msg(env, _JC_InternalError,
-		    "%s: %s", "gettimeofday", strerror(errno));
-		_jc_throw_exception(env);
-	}
-	return ((jlong)tv.tv_sec * 1000) + ((jlong)tv.tv_usec / 1000);
-}
-
-/*
- * static native String getenv()
- */
-_jc_object * _JC_JCNI_ATTR
-JCNI_java_lang_VMSystem_getenv(_jc_env *env, _jc_object *name)
-{
-	_jc_object *string;
-	const char *value;
-	char *namebuf;
-	size_t len;
-
-	/* Check for null */
-	if (name == NULL) {
-		_jc_post_exception(env, _JC_NullPointerException);
-		_jc_throw_exception(env);
-	}
-
-	/* Convert String to UTF-8 */
-	len = _jc_decode_string_utf8(env, name, NULL);
-	if ((namebuf = _JC_STACK_ALLOC(env, len + 1)) == NULL) {
-		_jc_post_exception_info(env);
-		_jc_throw_exception(env);
-	}
-	_jc_decode_string_utf8(env, name, namebuf);
-
-	/* Get environment variable */
-	if ((value = getenv(namebuf)) == NULL)
-		return NULL;
-
-	/* Convert to string */
-	if ((string = _jc_new_string(env, value, strlen(value))) == NULL)
-		_jc_throw_exception(env);
-
-	/* Return result */
-	return string;
 }
 

Modified: incubator/harmony/enhanced/jchevm/libjc/native/java_lang_VMThread.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/jchevm/libjc/native/java_lang_VMThread.c?rev=409254&r1=409253&r2=409254&view=diff
==============================================================================
--- incubator/harmony/enhanced/jchevm/libjc/native/java_lang_VMThread.c (original)
+++ incubator/harmony/enhanced/jchevm/libjc/native/java_lang_VMThread.c Wed May 24 14:22:35
2006
@@ -69,7 +69,13 @@
 _jc_object * _JC_JCNI_ATTR
 JCNI_java_lang_VMThread_currentThread(_jc_env *env)
 {
-	_JC_ASSERT(env->instance != NULL);
+	/* Create instance if needed (native threads only) */
+	if (env->instance == NULL
+	    && _jc_thread_create_instance(env, NULL, env->name,
+	      java_lang_Thread_NORM_PRIORITY, env->daemon) != JNI_OK)
+		_jc_throw_exception(env);
+
+	/* Done */
 	return env->instance;
 }
 

Modified: incubator/harmony/enhanced/jchevm/libjc/native_lib.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/jchevm/libjc/native_lib.c?rev=409254&r1=409253&r2=409254&view=diff
==============================================================================
--- incubator/harmony/enhanced/jchevm/libjc/native_lib.c (original)
+++ incubator/harmony/enhanced/jchevm/libjc/native_lib.c Wed May 24 14:22:35 2006
@@ -94,12 +94,7 @@
 	_JC_ILIB_ENTRY(java_lang_VMRuntime_traceInstructions),
 	_JC_ILIB_ENTRY(java_lang_VMRuntime_traceMethodCalls),
 	_JC_ILIB_ENTRY(java_lang_VMSystem_arraycopy),
-	_JC_ILIB_ENTRY(java_lang_VMSystem_currentTimeMillis),
-	_JC_ILIB_ENTRY(java_lang_VMSystem_getenv),
 	_JC_ILIB_ENTRY(java_lang_VMSystem_identityHashCode),
-	_JC_ILIB_ENTRY(java_lang_VMSystem_setErr),
-	_JC_ILIB_ENTRY(java_lang_VMSystem_setIn),
-	_JC_ILIB_ENTRY(java_lang_VMSystem_setOut),
 	_JC_ILIB_ENTRY(java_lang_VMThread_countStackFrames),
 	_JC_ILIB_ENTRY(java_lang_VMThread_currentThread),
 	_JC_ILIB_ENTRY(java_lang_VMThread_interrupt),

Modified: incubator/harmony/enhanced/jchevm/libjc/structures.h
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/jchevm/libjc/structures.h?rev=409254&r1=409253&r2=409254&view=diff
==============================================================================
--- incubator/harmony/enhanced/jchevm/libjc/structures.h (original)
+++ incubator/harmony/enhanced/jchevm/libjc/structures.h Wed May 24 14:22:35 2006
@@ -250,6 +250,7 @@
 	jint				thread_id;	/* unique thread id */
 	_jc_object			*instance;	/* java.lang.Thread */
 	char				text_status[_JC_MAX_TEXT_STATUS];
+	const char			*name;		/* native threads */
 
 	/* Lock info */
 	_jc_word			thinlock_id;
@@ -288,6 +289,7 @@
 	/* Thread flags */
 	jboolean			out_of_memory;
 	jboolean			handling_signal;
+	jboolean			daemon;		/* native threads */
 #ifndef NDEBUG
 	jboolean			interpreting;
 #endif

Modified: incubator/harmony/enhanced/jchevm/libjc/thread.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/jchevm/libjc/thread.c?rev=409254&r1=409253&r2=409254&view=diff
==============================================================================
--- incubator/harmony/enhanced/jchevm/libjc/thread.c (original)
+++ incubator/harmony/enhanced/jchevm/libjc/thread.c Wed May 24 14:22:35 2006
@@ -577,19 +577,55 @@
 
 /*
  * Create the java.lang.Thread instance associated with a native thread.
+ * A native thread is one not created by an invocation of Thread.start().
  */
 jint
 _jc_thread_create_instance(_jc_env *env, _jc_object *group,
 	const char *name, jint priority, jboolean daemon)
 {
 	_jc_jvm *const vm = env->vm;
-	jobject sref = NULL;
 	jobject vtref = NULL;
+	jobject sref = NULL;
 
 	/* Sanity check */
-	_JC_ASSERT(group != NULL);
 	_JC_ASSERT(env->instance == NULL);
 
+	/* Default ThreadGroup is the system ThreadGroup */
+	if (group == NULL)
+		group = vm->boot.objects.systemThreadGroup;
+
+	/* Create system ThreadGroup if necessary */
+	if (group == NULL) {
+		_jc_object *root;
+		jobject gref;
+
+		/* Create system ThreadGroup, wrapped in a global native ref */
+		_JC_ASSERT(sref == NULL);
+		if ((sref = _jc_new_local_native_ref(env,
+		    _jc_new_string(env, _JC_SYSTEM_THREADGROUP_NAME,
+		      sizeof(_JC_SYSTEM_THREADGROUP_NAME) - 1))) == NULL)
+			goto fail;
+		if ((gref = _jc_new_global_native_ref(env, _jc_new_object(env,
+		    vm->boot.types.ThreadGroup), JNI_FALSE)) == NULL)
+			goto fail;
+		vm->boot.objects.systemThreadGroup = *gref;
+
+		/* Get root ThreadGroup */
+		root = *_JC_VMSTATICFIELD(vm, ThreadGroup, root, _jc_object *);
+		_JC_ASSERT(root != NULL);
+
+		/* Create system ThreadGroup with root ThreadGroup as parent */
+		if (_jc_invoke_nonvirtual(env, vm->boot.methods.ThreadGroup.init,
+		    *gref, root, *sref) != JNI_OK) {
+			_jc_free_global_native_ref(&gref);
+			goto fail;
+		}
+		_jc_free_local_native_ref(&sref);
+
+		/* Now use system ThreadGroup */
+		group = vm->boot.objects.systemThreadGroup;
+	}
+
 	/* Create String from supplied name, if any */
 	if (name != NULL
 	    && (sref = _jc_new_local_native_ref(env,
@@ -597,6 +633,7 @@
 		goto fail;
 
 	/* Create new Thread object for this thread */
+	_JC_ASSERT(env->instance == NULL);
 	if ((env->instance = _jc_new_object(env,
 	    vm->boot.types.Thread)) == NULL)
 		goto fail;
@@ -701,7 +738,8 @@
  * NOTE: This assumes the VM global mutex is held.
  */
 _jc_env *
-_jc_attach_thread(_jc_jvm *vm, _jc_ex_info *ex, _jc_c_stack *cstack)
+_jc_attach_thread(_jc_jvm *vm, const char *name, jboolean daemon,
+	_jc_ex_info *ex, _jc_c_stack *cstack)
 {
 	_jc_env temp_env;
 	_jc_env *env;
@@ -727,6 +765,8 @@
 	/* Get a new thread structure */
 	if ((env = _jc_allocate_thread(&temp_env)) == NULL)
 		goto fail;
+	env->name = name;
+	env->daemon = daemon;
 
 	/* Remember that this thread structure goes with the current thread */
 	_jc_set_current_env(vm, env);
@@ -875,7 +915,8 @@
 	}
 
 	/* Re-attach this thread */
-	if ((env = _jc_attach_thread(vm, NULL, &cstack)) == NULL)
+	if ((env = _jc_attach_thread(vm, "shutdown",
+	    JNI_FALSE, NULL, &cstack)) == NULL)
 		_jc_fatal_error(vm, "can't reattach shutdown thread");
 
 	/* Stop the world */

Modified: incubator/harmony/enhanced/jchevm/libjc/vm.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/jchevm/libjc/vm.c?rev=409254&r1=409253&r2=409254&view=diff
==============================================================================
--- incubator/harmony/enhanced/jchevm/libjc/vm.c (original)
+++ incubator/harmony/enhanced/jchevm/libjc/vm.c Wed May 24 14:22:35 2006
@@ -113,7 +113,8 @@
 
 	/* Create and attach a new thread structure to the current thread */
 	_JC_MUTEX_LOCK(NULL, vm->mutex);
-	if ((env = _jc_attach_thread(vm, &temp_env.ex, &cstack)) == NULL) {
+	if ((env = _jc_attach_thread(vm, "main",
+	    JNI_FALSE, &temp_env.ex, &cstack)) == NULL) {
 		_JC_MUTEX_UNLOCK(NULL, vm->mutex);
 		env = &temp_env;
 		goto fail_info;
@@ -156,10 +157,6 @@
 	    vm->boot.loader, _JC_INTERNAL_NATIVE_LIBRARY) != JNI_OK)
 		goto fail_info;
 
-	/* Load bootstrap Java classes, methods, etc. */
-	if (_jc_bootstrap_classes(env) != JNI_OK)
-		goto fail;
-
 	/* Get min and max scheduler scheduling priorities */
 	if ((vm->threads.prio_min = sched_get_priority_min(SCHED_RR)) == -1) {
 		_JC_EX_STORE(env, InternalError,
@@ -178,27 +175,8 @@
 	vm->threads.java_prio_max = java_lang_Thread_MAX_PRIORITY;
 	vm->threads.java_prio_norm = java_lang_Thread_NORM_PRIORITY;
 
-	/* Create system ThreadGroup */
-	if ((sref = _jc_new_local_native_ref(env,
-	    _jc_new_string(env, _JC_SYSTEM_THREADGROUP_NAME,
-	      sizeof(_JC_SYSTEM_THREADGROUP_NAME) - 1))) == NULL)
-		goto fail;
-	if ((vm->boot.objects.systemThreadGroup = _jc_new_object(env,
-	    vm->boot.types.ThreadGroup)) == NULL)
-		goto fail;
-	if (_jc_invoke_nonvirtual(env, vm->boot.methods.ThreadGroup.init,
-	    vm->boot.objects.systemThreadGroup, *_JC_VMSTATICFIELD(vm,
-	      ThreadGroup, root, _jc_object *), *sref) != JNI_OK)
-		goto fail;
-
-	/* Wrap it in a global native reference */
-	if (_jc_new_global_native_ref(env,
-	    vm->boot.objects.systemThreadGroup, JNI_FALSE) == NULL)
-		goto fail;
-
-	/* Create java.lang.Thread instance for this thread */
-	if (_jc_thread_create_instance(env, vm->boot.objects.systemThreadGroup,
-	    "main", vm->threads.java_prio_norm, JNI_FALSE) != JNI_OK)
+	/* Load bootstrap Java classes, methods, etc. */
+	if (_jc_bootstrap_classes(env) != JNI_OK)
 		goto fail;
 
 	/* Start debug thread */



Mime
View raw message