harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r294974 [19/25] - in /incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm: ./ jchevm/ jchevm/doc/ jchevm/etc/ jchevm/include/ jchevm/java/ jchevm/java/org/ jchevm/java/org/dellroad/ jchevm/java/org/dellroad/jc/ jchevm/java/org/dellroad...
Date Wed, 05 Oct 2005 02:20:10 GMT
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_VMClass.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_VMClass.c?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_VMClass.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_VMClass.c Tue Oct  4 19:19:16 2005
@@ -0,0 +1,596 @@
+
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors,
+ * as applicable.
+ * 
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ * $Id: java_lang_VMClass.c,v 1.10 2005/05/15 21:41:01 archiecobbs Exp $
+ */
+
+#include "libjc.h"
+#include "java_lang_VMClass.h"
+
+/* Internal functions */
+static _jc_type		*_jc_get_type(_jc_env *env, _jc_object *this,
+				jboolean resolve);
+
+/*
+ * static final native Class forName(String)
+ *	throws java/lang/ClassNotFoundException
+ */
+_jc_object * _JC_JCNI_ATTR
+JCNI_java_lang_VMClass_forName(_jc_env *env, _jc_object *name)
+{
+	return NULL;
+}
+
+/*
+ * static final native ClassLoader getClassLoader(Class)
+ */
+_jc_object * _JC_JCNI_ATTR
+JCNI_java_lang_VMClass_getClassLoader(_jc_env *env, _jc_object *this)
+{
+	_jc_type *type;
+
+	/* Get type */
+	type = _jc_get_type(env, this, JNI_FALSE);
+
+	/* Return loader */
+	return type->loader->instance;
+}
+
+/*
+ * static final native Class getComponentType(Class)
+ */
+_jc_object * _JC_JCNI_ATTR
+JCNI_java_lang_VMClass_getComponentType(_jc_env *env, _jc_object *this)
+{
+	_jc_type *type;
+
+	/* Get type */
+	type = _jc_get_type(env, this, JNI_FALSE);
+
+	/* Return NULL for non-array types */
+	if (!_JC_FLG_TEST(type, ARRAY))
+		return NULL;
+
+	/* Return component type */
+	return type->u.array.element_type->instance;
+}
+
+/*
+ * static final native Class[] getDeclaredClasses(Class, boolean)
+ */
+_jc_object_array * _JC_JCNI_ATTR
+JCNI_java_lang_VMClass_getDeclaredClasses(_jc_env *env, _jc_object *this,
+	jboolean public_only)
+{
+	_jc_jvm *const vm = env->vm;
+	_jc_object_array *array;
+	_jc_type *type;
+	int num;
+	int i;
+
+	/* Get type */
+	type = _jc_get_type(env, this, JNI_TRUE);
+
+	/* Handle array types */
+	if (_JC_FLG_TEST(type, ARRAY)) {
+		if ((array = (_jc_object_array *)_jc_new_array(env,
+		    vm->boot.types.Class_array, 0)) == NULL)
+			_jc_throw_exception(env);
+		return array;
+	}
+
+	/* Count number of classes */
+	for (num = i = 0; i < type->u.nonarray.num_inner_classes; i++) {
+		_jc_inner_class *const ic = &type->u.nonarray.inner_classes[i];
+
+		if (!public_only || _JC_ACC_TEST(ic, PUBLIC))
+			num++;
+	}
+
+	/* Create array */
+	if ((array = (_jc_object_array *)_jc_new_array(env,
+	    vm->boot.types.Class_array, num)) == NULL)
+		_jc_throw_exception(env);
+
+	/* Fill in array */
+	for (num = i = 0; i < type->u.nonarray.num_inner_classes; i++) {
+		_jc_inner_class *const ic = &type->u.nonarray.inner_classes[i];
+
+		if (!public_only || _JC_ACC_TEST(ic, PUBLIC))
+			array->elems[~(num++)] = ic->type->instance;
+	}
+	_JC_ASSERT(num == array->length);
+
+	/* Done */
+	return array;
+}
+
+/*
+ * static final native Constructor[] getDeclaredConstructors(Class, boolean)
+ */
+_jc_object_array * _JC_JCNI_ATTR
+JCNI_java_lang_VMClass_getDeclaredConstructors(_jc_env *env,
+	_jc_object *this, jboolean public_only)
+{
+	_jc_jvm *const vm = env->vm;
+	_jc_object_array *array;
+	_jc_type *type;
+	jobject ref;
+	jint num;
+	int i;
+
+	/* Get type */
+	type = _jc_get_type(env, this, JNI_TRUE);
+
+	/* Handle array types */
+	if (_JC_FLG_TEST(type, ARRAY)) {
+		if ((array = (_jc_object_array *)_jc_new_array(env,
+		    vm->boot.types.Constructor_array, 0)) == NULL)
+			_jc_throw_exception(env);
+		return array;
+	}
+
+	/* Count constructors */
+	for (num = i = 0; i < type->u.nonarray.num_methods; i++) {
+		_jc_method *const method = type->u.nonarray.methods[i];
+
+		if (public_only && !_JC_ACC_TEST(method, PUBLIC))
+			continue;
+		if (_JC_ACC_TEST(method, STATIC) || *method->name != '<')
+			continue;
+		num++;
+	}
+
+	/* Create new array and wrap it temporarily */
+	if ((ref = _jc_new_local_native_ref(env,
+	    (_jc_object *)_jc_new_array(env,
+	      vm->boot.types.Constructor_array, num))) == NULL)
+		_jc_throw_exception(env);
+	array = (_jc_object_array *)*ref;
+
+	/* Add constructors */
+	for (num = i = 0; i < type->u.nonarray.num_methods; i++) {
+		_jc_method *const method = type->u.nonarray.methods[i];
+
+		if (public_only && !_JC_ACC_TEST(method, PUBLIC))
+			continue;
+		if (_JC_ACC_TEST(method, STATIC) || *method->name != '<')
+			continue;
+		if ((array->elems[~(num++)]
+		    = _jc_get_reflected_constructor(env, method)) == NULL) {
+			_jc_free_local_native_ref(&ref);
+			_jc_throw_exception(env);
+		}
+	}
+
+	/* Return result */
+	return (_jc_object_array *)_jc_free_local_native_ref(&ref);
+}
+
+/*
+ * static final native Field[] getDeclaredFields(Class, boolean)
+ */
+_jc_object_array * _JC_JCNI_ATTR
+JCNI_java_lang_VMClass_getDeclaredFields(_jc_env *env, _jc_object *this,
+	jboolean public_only)
+{
+	_jc_jvm *const vm = env->vm;
+	_jc_object_array *array;
+	_jc_type *type;
+	jobject ref;
+	jint num;
+	int i;
+
+	/* Get type */
+	type = _jc_get_type(env, this, JNI_TRUE);
+
+	/* Handle array types */
+	if (_JC_FLG_TEST(type, ARRAY)) {
+		if ((array = (_jc_object_array *)_jc_new_array(env,
+		    vm->boot.types.Field_array, 0)) == NULL)
+			_jc_throw_exception(env);
+		return array;
+	}
+
+	/* Count fields */
+	if (!public_only)
+		num = type->u.nonarray.num_fields;
+	else {
+		for (num = i = 0; i < type->u.nonarray.num_fields; i++) {
+			_jc_field *const field = type->u.nonarray.fields[i];
+
+			if (_JC_ACC_TEST(field, PUBLIC))
+				num++;
+		}
+	}
+
+	/* Create new array and wrap it temporarily */
+	if ((ref = _jc_new_local_native_ref(env,
+	    (_jc_object *)_jc_new_array(env,
+	      vm->boot.types.Field_array, num))) == NULL)
+		_jc_throw_exception(env);
+	array = (_jc_object_array *)*ref;
+
+	/* Add fields */
+	for (num = i = 0; i < type->u.nonarray.num_fields; i++) {
+		_jc_field *const field = type->u.nonarray.fields[i];
+
+		if (public_only && !_JC_ACC_TEST(field, PUBLIC))
+			continue;
+		if ((array->elems[~(num++)]
+		    = _jc_get_reflected_field(env, field)) == NULL) {
+			_jc_free_local_native_ref(&ref);
+			_jc_throw_exception(env);
+		}
+	}
+
+	/* Return result */
+	return (_jc_object_array *)_jc_free_local_native_ref(&ref);
+}
+
+/*
+ * static final native Method[] getDeclaredMethods(Class, boolean)
+ */
+_jc_object_array * _JC_JCNI_ATTR
+JCNI_java_lang_VMClass_getDeclaredMethods(_jc_env *env, _jc_object *this,
+	jboolean public_only)
+{
+	_jc_jvm *const vm = env->vm;
+	_jc_object_array *array;
+	_jc_type *type;
+	jobject ref;
+	jint num;
+	int i;
+
+	/* Get type */
+	type = _jc_get_type(env, this, JNI_TRUE);
+
+	/* Handle array types */
+	if (_JC_FLG_TEST(type, ARRAY)) {
+		if ((array = (_jc_object_array *)_jc_new_array(env,
+		    vm->boot.types.Method_array, 0)) == NULL)
+			_jc_throw_exception(env);
+		return array;
+	}
+
+	/* Count methods */
+	for (num = i = 0; i < type->u.nonarray.num_methods; i++) {
+		_jc_method *const method = type->u.nonarray.methods[i];
+
+		if (public_only && !_JC_ACC_TEST(method, PUBLIC))
+			continue;
+		if (*method->name == '<')
+			continue;
+		num++;
+	}
+
+	/* Create new array and wrap it temporarily */
+	if ((ref = _jc_new_local_native_ref(env,
+	    (_jc_object *)_jc_new_array(env,
+	      vm->boot.types.Method_array, num))) == NULL)
+		_jc_throw_exception(env);
+	array = (_jc_object_array *)*ref;
+
+	/* Add methods */
+	for (num = i = 0; i < type->u.nonarray.num_methods; i++) {
+		_jc_method *const method = type->u.nonarray.methods[i];
+
+		if (public_only && !_JC_ACC_TEST(method, PUBLIC))
+			continue;
+		if (*method->name == '<')
+			continue;
+		if ((array->elems[~(num++)]
+		    = _jc_get_reflected_method(env, method)) == NULL) {
+			_jc_free_local_native_ref(&ref);
+			_jc_throw_exception(env);
+		}
+	}
+
+	/* Return result */
+	return (_jc_object_array *)_jc_free_local_native_ref(&ref);
+}
+
+/*
+ * static final native Class getDeclaringClass(Class)
+ */
+_jc_object * _JC_JCNI_ATTR
+JCNI_java_lang_VMClass_getDeclaringClass(_jc_env *env, _jc_object *this)
+{
+	_jc_type *type;
+
+	/* Get type */
+	type = _jc_get_type(env, this, JNI_TRUE);
+
+	/* Return declaring class, if any */
+	if (!_JC_FLG_TEST(type, ARRAY)
+	    && type->u.nonarray.outer_class != NULL)
+	    	return type->u.nonarray.outer_class->instance;
+	return NULL;
+}
+
+/*
+ * static final native Class[] getInterfaces(Class)
+ */
+_jc_object_array * _JC_JCNI_ATTR
+JCNI_java_lang_VMClass_getInterfaces(_jc_env *env, _jc_object *this)
+{
+	_jc_jvm *const vm = env->vm;
+	_jc_object_array *array;
+	_jc_type *type;
+	jobject ref;
+	int i;
+
+	/* Get type */
+	type = _jc_get_type(env, this, JNI_TRUE);
+
+	/* Create new array and wrap it temporarily */
+	if ((ref = _jc_new_local_native_ref(env,
+	    (_jc_object *)_jc_new_array(env,
+	      vm->boot.types.Class_array, type->num_interfaces))) == NULL)
+		_jc_throw_exception(env);
+	array = (_jc_object_array *)*ref;
+
+	/* Add interfaces */
+	for (i = 0; i < type->num_interfaces; i++) {
+		_jc_type *const itype = type->interfaces[i];
+
+		array->elems[~i] = itype->instance;
+	}
+
+	/* Return result */
+	return (_jc_object_array *)_jc_free_local_native_ref(&ref);
+}
+
+/*
+ * static final native int getModifiers(Class, boolean)
+ */
+jint _JC_JCNI_ATTR
+JCNI_java_lang_VMClass_getModifiers(_jc_env *env,
+	_jc_object *this, jboolean notInner)
+{
+	_jc_type *type;
+	int flags;
+
+	/* Get type */
+	type = _jc_get_type(env, this, JNI_FALSE);
+	flags = type->access_flags;
+
+	/* Handle special case for inner classes */
+	if (!notInner
+	    && !_JC_FLG_TEST(type, ARRAY)
+	    && type->u.nonarray.outer_class != NULL) {
+	    	_jc_nonarray_type *const otype
+		    = &type->u.nonarray.outer_class->u.nonarray;
+		int i;
+
+		for (i = 0; i < otype->num_inner_classes; i++) {
+			_jc_inner_class *iclass = &otype->inner_classes[i];
+
+			if (iclass->type == type) {
+				flags = iclass->access_flags;
+				break;
+			}
+		}
+	}
+
+	/* Return modifiers */
+	return flags & _JC_ACC_MASK;
+}
+
+/*
+ * static final native String getName(Class)
+ */
+_jc_object * _JC_JCNI_ATTR
+JCNI_java_lang_VMClass_getName(_jc_env *env, _jc_object *this)
+{
+	_jc_object *string;
+	size_t name_len;
+	_jc_type *type;
+	char *name;
+	char *s;
+
+	/* Get type */
+	type = _jc_get_type(env, this, JNI_FALSE);
+
+	/* Convert from internal name format */
+	name_len = strlen(type->name);
+	if ((name = _JC_STACK_ALLOC(env, name_len + 1)) == NULL) {
+		_jc_post_exception_info(env);
+		_jc_throw_exception(env);
+	}
+	memcpy(name, type->name, name_len + 1);
+	for (s = name; *s != '\0'; s++) {
+		if (*s == '/')
+			*s = '.';
+	}
+
+	/* Get string */
+	if ((string = _jc_new_string(env, name, name_len)) == NULL)
+		_jc_throw_exception(env);
+
+	/* Return result */
+	return string;
+}
+
+/*
+ * static final native Class getSuperclass(Class)
+ */
+_jc_object * _JC_JCNI_ATTR
+JCNI_java_lang_VMClass_getSuperclass(_jc_env *env, _jc_object *this)
+{
+	_jc_type *type;
+
+	/* Get type */
+	type = _jc_get_type(env, this, JNI_FALSE);
+
+	/* Handle special cases */
+	if (type->superclass == NULL || _JC_ACC_TEST(type, INTERFACE))
+		return NULL;
+
+	/* Return result */
+	return type->superclass->instance;
+}
+
+/*
+ * static final native void initialize(Class)
+ */
+void _JC_JCNI_ATTR
+JCNI_java_lang_VMClass_initialize(_jc_env *env, _jc_object *this)
+{
+	_jc_type *type;
+
+	/* Get type */
+	type = _jc_get_type(env, this, JNI_FALSE);
+
+	/* Initialize type */
+	if (_jc_initialize_type(env, type) != JNI_OK)
+		_jc_throw_exception(env);
+}
+
+/*
+ * static final native boolean isArray(Class)
+ */
+jboolean _JC_JCNI_ATTR
+JCNI_java_lang_VMClass_isArray(_jc_env *env, _jc_object *this)
+{
+	_jc_type *type;
+
+	/* Get type */
+	type = _jc_get_type(env, this, JNI_FALSE);
+
+	/* Return arrayness */
+	return _JC_FLG_TEST(type, ARRAY);
+}
+
+/*
+ * static final native boolean isAssignableFrom(Class, Class)
+ */
+jboolean _JC_JCNI_ATTR
+JCNI_java_lang_VMClass_isAssignableFrom(_jc_env *env, _jc_object *this,
+	_jc_object *other)
+{
+	_jc_type *from_type;
+	_jc_type *to_type;
+
+	/* Get types */
+	from_type = _jc_get_type(env, other, JNI_FALSE);
+	to_type = _jc_get_type(env, this, JNI_FALSE);
+
+	/* Return assignable */
+	return _jc_assignable_from(env, from_type, to_type);
+}
+
+/*
+ * static final native boolean isInstance(Class, Object)
+ */
+jboolean _JC_JCNI_ATTR
+JCNI_java_lang_VMClass_isInstance(_jc_env *env,
+	_jc_object *this, _jc_object *obj)
+{
+	_jc_type *type;
+
+	/* Get type */
+	type = _jc_get_type(env, this, JNI_FALSE);
+
+	/* Return instanceof */
+	return _jc_instance_of(env, obj, type);
+}
+
+/*
+ * static final native boolean isInterface(Class)
+ */
+jboolean _JC_JCNI_ATTR
+JCNI_java_lang_VMClass_isInterface(_jc_env *env, _jc_object *this)
+{
+	_jc_type *type;
+
+	/* Get type */
+	type = _jc_get_type(env, this, JNI_FALSE);
+
+	/* Return interfaceness */
+	return _JC_ACC_TEST(type, INTERFACE);
+}
+
+/*
+ * static final native boolean isPrimitive(Class)
+ */
+jboolean _JC_JCNI_ATTR
+JCNI_java_lang_VMClass_isPrimitive(_jc_env *env, _jc_object *this)
+{
+	_jc_type *type;
+
+	/* Get type */
+	type = _jc_get_type(env, this, JNI_FALSE);
+
+	/* Return primitiveness */
+	return (type->flags & _JC_TYPE_MASK) != _JC_TYPE_REFERENCE;
+}
+
+/*
+ * static final native Class loadArrayClass(String, ClassLoader)
+ *	throws java/lang/ClassNotFoundException
+ */
+_jc_object * _JC_JCNI_ATTR
+JCNI_java_lang_VMClass_loadArrayClass(_jc_env *env,
+	_jc_object *name_string, _jc_object *loader_obj)
+{
+	return _jc_internal_load_class(env, name_string, loader_obj, JNI_FALSE);
+}
+
+/*
+ * static final native void throwException(Throwable)
+ */
+void _JC_JCNI_ATTR
+JCNI_java_lang_VMClass_throwException(_jc_env *env, _jc_object *throwable)
+{
+	/* Check for null */
+	if (throwable == NULL) {
+		_jc_post_exception(env, _JC_NullPointerException);
+		_jc_throw_exception(env);
+	}
+
+	/* Post and throw exception */
+	_jc_post_exception_object(env, throwable);
+	_jc_throw_exception(env);
+}
+
+/*
+ * Get (and resolve) the type corresponding to the Class object.
+ */
+static _jc_type *
+_jc_get_type(_jc_env *env, _jc_object *this, jboolean resolve)
+{
+	_jc_jvm *const vm = env->vm;
+	_jc_type *type;
+
+	/* Check for null */
+	if (this == NULL) {
+		_jc_post_exception(env, _JC_NullPointerException);
+		_jc_throw_exception(env);
+	}
+
+	/* Get type */
+	type = _jc_get_vm_pointer(this, vm->boot.fields.Class.vmdata);
+
+	/* Resolve type */
+	if (resolve && _jc_resolve_type(env, type) != JNI_OK)
+		_jc_throw_exception(env);
+
+	/* Done */
+	return type;
+}
+

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_VMClassLoader.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_VMClassLoader.c?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_VMClassLoader.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_VMClassLoader.c Tue Oct  4 19:19:16 2005
@@ -0,0 +1,268 @@
+
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors,
+ * as applicable.
+ * 
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ * $Id: java_lang_VMClassLoader.c,v 1.14 2005/05/15 21:41:01 archiecobbs Exp $
+ */
+
+#include "libjc.h"
+#include "java_lang_VMClassLoader.h"
+
+/*
+ * static final native Class defineClass(ClassLoader,
+ *	String, byte[], int, int, ProtectionDomain) throws ClassFormatError
+ */
+_jc_object * _JC_JCNI_ATTR
+JCNI_java_lang_VMClassLoader_defineClass(_jc_env *env, _jc_object *cl,
+	_jc_object *name_string, _jc_byte_array *data, jint offset,
+	jint len, _jc_object *pd)
+{
+	_jc_jvm *const vm = env->vm;
+	_jc_classbytes *cbytes = NULL;
+	_jc_class_loader *loader;
+	_jc_type *type = NULL;
+	char *name = NULL;
+
+	/* Check for null */
+	if (data == NULL) {
+		_jc_post_exception(env, _JC_NullPointerException);
+		goto done;
+	}
+	_JC_ASSERT(data->type == env->vm->boot.types.prim_array[_JC_TYPE_BYTE]);
+
+        /* Check byte[] array bounds */
+	if (!_JC_BOUNDS_CHECK(data, offset, len)) {
+		_jc_post_exception(env, _JC_ArrayIndexOutOfBoundsException);
+		goto done;
+	}
+
+	/* Get loader */
+	if (cl == NULL)
+		loader = vm->boot.loader;
+	else {
+		_JC_ASSERT(_jc_subclass_of(cl,
+		    env->vm->boot.types.ClassLoader));
+		if ((loader = _jc_get_loader(env, cl)) == NULL)
+			goto done;
+	}
+
+	/* Convert name string to UTF-8 and convert '.' chars to '/' */
+	if (name_string != NULL) {
+		size_t name_len;
+		char *s;
+
+		name_len = _jc_decode_string_utf8(env, name_string, NULL);
+		if ((name = _JC_STACK_ALLOC(env, name_len + 1)) == NULL) {
+			_jc_post_exception_info(env);
+			goto done;
+		}
+		_jc_decode_string_utf8(env, name_string, name);
+		for (s = name; *s != '\0'; s++) {
+			if (*s == '.')
+				*s = '/';
+		}
+	}
+
+	/* Create '_jc_classbytes' object from byte[] range */
+	if ((cbytes = _jc_copy_classbytes(env,
+	    data->elems + offset, len)) == NULL)
+		goto done;
+
+	/* Derive type */
+	if ((type = _jc_derive_type_from_classfile(env,
+	    loader, name, cbytes)) == NULL)
+		goto done;
+
+	/* Set protection domain */
+	*_JC_VMFIELD(vm, type->instance, Class, pd, _jc_object *) = pd;
+
+done:
+	/* Clean up */
+	_jc_free_classbytes(&cbytes);
+
+	/* Bail out if exception */
+	if (type == NULL)
+		_jc_throw_exception(env);
+
+	/* Return Class object */
+	return type->instance;
+}
+
+/*
+ * static final native Class getPrimitiveClass(char)
+ */
+_jc_object * _JC_JCNI_ATTR
+JCNI_java_lang_VMClassLoader_getPrimitiveClass(_jc_env *env, jchar pchar)
+{
+	_jc_jvm *const vm = env->vm;
+	int ptype;
+
+	/* Get primitive type */
+	ptype = _jc_sig_types[pchar];
+	if (ptype == _JC_TYPE_INVALID || ptype == _JC_TYPE_REFERENCE) {
+		_jc_post_exception_msg(env, _JC_InternalError,
+		    "invalid primitive class type `%c'", pchar);
+		_jc_throw_exception(env);
+	}
+
+	/* Return class instance */
+	return vm->boot.types.prim[ptype]->instance;
+}
+
+/*
+ * static final native Class loadClass(String, boolean)
+ *	throws java/lang/ClassNotFoundException
+ */
+_jc_object * _JC_JCNI_ATTR
+JCNI_java_lang_VMClassLoader_loadClass(_jc_env *env,
+	_jc_object *string, jboolean resolve)
+{
+	return _jc_internal_load_class(env, string, NULL, resolve);
+}
+
+/*
+ * static final native void resolveClass(Class)
+ */
+void _JC_JCNI_ATTR
+JCNI_java_lang_VMClassLoader_resolveClass(_jc_env *env, _jc_object *class)
+{
+	_jc_jvm *const vm = env->vm;
+	_jc_type *type;
+
+	/* Check for null and get type */
+	if (class == NULL) {
+		_jc_post_exception(env, _JC_NullPointerException);
+		_jc_throw_exception(env);
+	}
+	_JC_ASSERT(class->type == vm->boot.types.Class);
+	type = _jc_get_vm_pointer(class, vm->boot.fields.Class.vmdata);
+
+	/* Link type */
+	if (_jc_resolve_type(env, type) != JNI_OK)
+		_jc_throw_exception(env);
+}
+
+/*
+ * Load a class (array or non-array) using the class loader from the
+ * supplied ClassLoader object, or the boot loader if null.
+ */
+_jc_object *
+_jc_internal_load_class(_jc_env *env, _jc_object *name_string,
+	_jc_object *loader_obj, jboolean resolve)
+{
+	_jc_jvm *const vm = env->vm;
+	_jc_class_loader *loader;
+	_jc_type *type = NULL;
+	int status = JNI_ERR;
+	char *name = NULL;
+	size_t name_len;
+	_jc_object *e;
+	int i;
+
+	/* Check for null */
+	if (name_string == NULL) {
+		_jc_post_exception(env, _JC_NullPointerException);
+		goto done;
+	}
+
+	/* Get class loader */
+	if (loader_obj == NULL)
+		loader = vm->boot.loader;
+	else if ((loader = _jc_get_loader(env, loader_obj)) == NULL)
+		goto done;
+
+	/* Convert name string to UTF-8 */
+	name_len = _jc_decode_string_utf8(env, name_string, NULL);
+	if ((name = _JC_STACK_ALLOC(env, name_len + 1)) == NULL) {
+		_jc_post_exception_info(env);
+		goto done;
+	}
+	_jc_decode_string_utf8(env, name_string, name);
+
+	/* Disallow empty strings or embedded nul charcaters */
+	if (name_len == 0 || strlen(name) != name_len)
+		goto invalid;
+
+	/* Disallow '/' characters */
+	if (strchr(name, '/') != NULL)
+		goto invalid;
+
+	/*
+	 * Disallow duplicate, leading, or trailing '.' characters.
+	 * Replace '.' characters with '/' characters.
+	 */
+	if (name[0] == '.' || name[name_len - 1] == '.')
+		goto invalid;
+	for (i = 0; i < name_len - 1; i++) {
+		if (name[i] == '.' && name[i + 1] == '.') {
+			_jc_word params[2];
+invalid:		
+			params[0] = (_jc_word)name_string;
+			params[1] = (_jc_word)NULL;
+			_jc_post_exception_params(env,
+			    _JC_ClassNotFoundException, params);
+			goto done;
+		}
+		if (name[i] == '.')
+			name[i] = '/';
+	}
+
+	/* Load type using loader */
+	if ((type = _jc_load_type(env, loader, name)) == NULL)
+		goto done;
+
+	/* Link type if desired */
+	if (resolve && _jc_resolve_type(env, type) != JNI_OK)
+		goto done;
+
+	/* OK */
+	status = JNI_OK;
+
+done:
+	/* Convert any NoClassDefFoundError to ClassNotFoundException */
+	if (status != JNI_OK
+	    && (e = _jc_retrieve_exception(env,
+	      vm->boot.types.vmex[_JC_NoClassDefFoundError])) != NULL) {
+		jobject eref = NULL;
+		_jc_word params[2];
+
+		/* Wrap exception */
+		if ((eref = _jc_new_local_native_ref(env, e)) == NULL)
+			goto done2;
+
+		/* Extract message string from inner exception */
+		params[0] = (_jc_word)*_JC_VMFIELD(vm,
+		    e, Throwable, detailMessage, _jc_object *);
+		params[1] = (_jc_word)e;
+
+		/* Chain exception inside a new ClassNotFoundException */
+		_jc_post_exception_params(env,
+		    _JC_ClassNotFoundException, params);
+
+done2:
+		/* Clean up */
+		_jc_free_local_native_ref(&eref);
+	}
+
+	/* Bail out if exception */
+	if (status != JNI_OK)
+		_jc_throw_exception(env);
+
+	/* Return Class object */
+	_JC_ASSERT(type != NULL);
+	return type->instance;
+}
+

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_VMCompiler.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_VMCompiler.c?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_VMCompiler.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_VMCompiler.c Tue Oct  4 19:19:16 2005
@@ -0,0 +1,91 @@
+
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors,
+ * as applicable.
+ * 
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ * $Id: java_lang_VMCompiler.c,v 1.2 2005/05/15 21:41:01 archiecobbs Exp $
+ */
+
+#include "libjc.h"
+#include "java_lang_VMCompiler.h"
+
+/*
+ * public static final native boolean compileClass(Class)
+ */
+jboolean _JC_JCNI_ATTR
+JCNI_java_lang_VMCompiler_compileClass(_jc_env *env, _jc_object *cl)
+{
+	_jc_jvm *const vm = env->vm;
+	_jc_type *type;
+
+	/* Check for null */
+	if (cl == NULL) {
+		_jc_post_exception(env, _JC_NullPointerException);
+		_jc_throw_exception(env);
+	}
+
+	/* Get type */
+	type = _jc_get_vm_pointer(cl, vm->boot.fields.Class.vmdata);
+
+	/* Generate ELF object */
+	if (_jc_generate_object(env, type->loader, type->name) != JNI_OK)
+		_jc_throw_exception(env);
+	return JNI_TRUE;
+}
+
+/*
+ * public static final native boolean compileClasses(String)
+ */
+jboolean _JC_JCNI_ATTR
+JCNI_java_lang_VMCompiler_compileClasses(_jc_env *env, _jc_object *string)
+{
+	_jc_jvm *const vm = env->vm;
+	size_t slen;
+	char *name;
+
+	/* Decode string */
+	slen = _jc_decode_string_utf8(env, string, NULL);
+	if ((name = _JC_STACK_ALLOC(env, slen + 1)) == NULL) {
+		_jc_post_exception_info(env);
+		_jc_throw_exception(env);
+	}
+	_jc_decode_string_utf8(env, string, name);
+
+	/* XXX we are supposed to do some kind of pattern matching... */
+
+	/* Generate ELF object */
+	if (_jc_generate_object(env, vm->boot.loader, name) != JNI_OK)
+		_jc_throw_exception(env);
+	return JNI_TRUE;
+}
+
+/*
+ * public static final native void disable()
+ */
+void _JC_JCNI_ATTR
+JCNI_java_lang_VMCompiler_disable(_jc_env *env)
+{
+	env->vm->compiler_disabled = JNI_TRUE;
+}
+
+/*
+ * public static final native void enable()
+ */
+void _JC_JCNI_ATTR
+JCNI_java_lang_VMCompiler_enable(_jc_env *env)
+{
+	env->vm->compiler_disabled = JNI_FALSE;
+}
+

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_VMObject.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_VMObject.c?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_VMObject.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_VMObject.c Tue Oct  4 19:19:16 2005
@@ -0,0 +1,526 @@
+
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors,
+ * as applicable.
+ * 
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ * $Id: java_lang_VMObject.c,v 1.6 2005/05/15 21:41:01 archiecobbs Exp $
+ */
+
+#include "libjc.h"
+#include "java_lang_VMObject.h"
+
+/* Internal functions */
+static void	do_notify(_jc_env *env, _jc_object *this, jboolean broadcast);
+
+/*
+ * static final native Object clone(Cloneable)
+ */
+_jc_object * _JC_JCNI_ATTR
+JCNI_java_lang_VMObject_clone(_jc_env *env, _jc_object *this)
+{
+	_jc_jvm *const vm = env->vm;
+	_jc_object *clone;
+	_jc_type *type;
+
+	/* Check for null */
+	if (this == NULL) {
+		_jc_post_exception(env, _JC_NullPointerException);
+		_jc_throw_exception(env);
+	}
+
+	/* Check for Cloneable */
+	switch (_jc_instance_of(env, this, vm->boot.types.Cloneable)) {
+	case 1:
+		break;
+	case 0:
+		_jc_post_exception(env, _JC_CloneNotSupportedException);
+		/* FALLTHROUGH */
+	case -1:
+		_jc_throw_exception(env);
+	default:
+		_JC_ASSERT(JNI_FALSE);
+	}
+
+	/* Clone object */
+	type = this->type;
+	if (_JC_FLG_TEST(type, ARRAY)) {
+		_jc_type *const etype = type->u.array.element_type;
+		_jc_array *const array = (_jc_array *)this;
+		_jc_array *acopy;
+
+		/* Create a new array having the same length */
+		if ((acopy = _jc_new_array(env, type, array->length)) == NULL)
+			_jc_throw_exception(env);
+
+		/* Copy the array elements */
+		switch ((etype->flags & _JC_TYPE_MASK)) {
+		case _JC_TYPE_BOOLEAN:
+		    {
+			_jc_boolean_array *const src
+			    = (_jc_boolean_array *)array;
+			_jc_boolean_array *const dst
+			    = (_jc_boolean_array *)acopy;
+
+			memcpy(dst->elems, src->elems,
+			    src->length * sizeof(*src->elems));
+			break;
+		    }
+		case _JC_TYPE_BYTE:
+		    {
+			_jc_byte_array *const src = (_jc_byte_array *)array;
+			_jc_byte_array *const dst = (_jc_byte_array *)acopy;
+
+			memcpy(dst->elems, src->elems,
+			    src->length * sizeof(*src->elems));
+			break;
+		    }
+		case _JC_TYPE_CHAR:
+		    {
+			_jc_char_array *const src = (_jc_char_array *)array;
+			_jc_char_array *const dst = (_jc_char_array *)acopy;
+
+			memcpy(dst->elems, src->elems,
+			    src->length * sizeof(*src->elems));
+			break;
+		    }
+		case _JC_TYPE_SHORT:
+		    {
+			_jc_short_array *const src = (_jc_short_array *)array;
+			_jc_short_array *const dst = (_jc_short_array *)acopy;
+
+			memcpy(dst->elems, src->elems,
+			    src->length * sizeof(*src->elems));
+			break;
+		    }
+		case _JC_TYPE_INT:
+		    {
+			_jc_int_array *const src = (_jc_int_array *)array;
+			_jc_int_array *const dst = (_jc_int_array *)acopy;
+
+			memcpy(dst->elems, src->elems,
+			    src->length * sizeof(*src->elems));
+			break;
+		    }
+		case _JC_TYPE_LONG:
+		    {
+			_jc_long_array *const src = (_jc_long_array *)array;
+			_jc_long_array *const dst = (_jc_long_array *)acopy;
+
+			memcpy(dst->elems, src->elems,
+			    src->length * sizeof(*src->elems));
+			break;
+		    }
+		case _JC_TYPE_FLOAT:
+		    {
+			_jc_float_array *const src = (_jc_float_array *)array;
+			_jc_float_array *const dst = (_jc_float_array *)acopy;
+
+			memcpy(dst->elems, src->elems,
+			    src->length * sizeof(*src->elems));
+			break;
+		    }
+		case _JC_TYPE_DOUBLE:
+		    {
+			_jc_double_array *const src = (_jc_double_array *)array;
+			_jc_double_array *const dst = (_jc_double_array *)acopy;
+
+			memcpy(dst->elems, src->elems,
+			    src->length * sizeof(*src->elems));
+			break;
+		    }
+		case _JC_TYPE_REFERENCE:
+		    {
+			_jc_object_array *const src = (_jc_object_array *)array;
+			_jc_object_array *const dst = (_jc_object_array *)acopy;
+
+			memcpy(dst->elems - src->length,
+			    src->elems - dst->length,
+			    src->length * sizeof(*src->elems));
+			break;
+		    }
+		default:
+			_JC_ASSERT(JNI_FALSE);
+		}
+
+		/* Now we have our clone */
+		clone = (_jc_object *)acopy;
+	} else {
+		const int instance_offset
+		    = type->u.nonarray.num_virtual_refs * sizeof(void *);
+
+		/* Create a new object having the same type */
+		if ((clone = _jc_new_object(env, type)) == NULL)
+			_jc_throw_exception(env);
+
+		/* Copy type pointer and all reference and primitive fields */
+		memcpy((char *)clone - instance_offset,
+		    (char *)this - instance_offset,
+		    type->u.nonarray.instance_size);
+
+		/* Initialize lockword in the new object */
+		clone->lockword = type->initial_lockword;
+	}
+
+	/* Done */
+	return clone;
+}
+
+/*
+ * static final native Class getClass(Object)
+ */
+_jc_object * _JC_JCNI_ATTR
+JCNI_java_lang_VMObject_getClass(_jc_env *env, _jc_object *obj)
+{
+	/* Check for null */
+	if (obj == NULL) {
+		_jc_post_exception(env, _JC_NullPointerException);
+		_jc_throw_exception(env);
+	}
+
+	/* Return object type's Class instance */
+	return obj->type->instance;
+}
+
+/*
+ * static final native void wait(Object, long, int)
+ *	throws java/lang/IllegalMonitorStateException,
+ *		java/lang/InterruptedException
+ */
+void _JC_JCNI_ATTR
+JCNI_java_lang_VMObject_wait(_jc_env *env, _jc_object *this,
+	jlong millis, jint nanos)
+{
+	_jc_jvm *const vm = env->vm;
+	const jboolean timed_wait = (millis != 0 || nanos != 0);
+	jboolean clipped_stack_top;
+	jboolean interrupted;
+	struct timespec wakeup;
+	jint recursion_count;
+	_jc_word old_status;
+	_jc_fat_lock *lock;
+	_jc_word lockword;
+	jchar notify_count;
+	_jc_object *ex;
+
+	/* Check for invalid parameters */
+	if (millis < 0 || nanos < 0 || nanos >= 1000000) {
+		_jc_post_exception(env, _JC_IllegalArgumentException);
+		_jc_throw_exception(env);
+	}
+
+	/* Check for null */
+	if (this == NULL) {
+		_jc_post_exception(env, _JC_NullPointerException);
+		_jc_throw_exception(env);
+	}
+	lockword = this->lockword;
+
+	/* Compute our wakeup time (if any) */
+	if (timed_wait) {
+		struct timeval now;
+
+		/* Get current time */
+		gettimeofday(&now, NULL);
+
+		/* Add delay to get wakeup time */
+		wakeup.tv_sec = now.tv_sec + (millis / 1000);
+		wakeup.tv_nsec = (now.tv_usec * 1000)
+		    + ((millis % 1000) * 1000000) + nanos;
+
+		/* Handle nanosecond overflow */
+		if (wakeup.tv_nsec >= 1000000000L) {
+			wakeup.tv_sec += 1;
+			wakeup.tv_nsec -= 1000000000L;
+		}
+
+		/* Handle second overflow */
+		if (wakeup.tv_sec < now.tv_sec) {
+			wakeup.tv_sec = LONG_MAX;
+			wakeup.tv_nsec = 0;
+		}
+	}
+
+	/* Thinlocks must be inflated because we need a condition variable */
+	if (!_JC_LW_TEST(lockword, FAT)) {
+
+		/* Verify that this thread owns the lock */
+		if ((lockword & _JC_LW_THIN_TID_MASK) != env->thinlock_id) {
+			_jc_post_exception(env,
+			    _JC_IllegalMonitorStateException);
+			_jc_throw_exception(env);
+		}
+
+		/* Inflate the lock */
+		if (_jc_inflate_lock(env, this) != JNI_OK)
+			_jc_throw_exception(env);
+
+		/* Update object lockword */
+		lockword = this->lockword;
+		_JC_ASSERT(_JC_LW_TEST(lockword, FAT));
+
+		/* Handle any contention from the thinlock */
+		if (env->lock.owner.contention)
+			_jc_lock_contention(env, this);
+
+		/* Get the fat lock we just inflated */
+		lock = vm->fat_locks.by_id[_JC_LW_EXTRACT(lockword, FAT_ID)];
+		_JC_ASSERT(lock->u.owner == env);
+	} else {
+
+		/* Get the object's fat lock */
+		lock = vm->fat_locks.by_id[_JC_LW_EXTRACT(lockword, FAT_ID)];
+
+		/* Verify that this thread owns the lock */
+		if (lock->u.owner != env) {
+			_jc_post_exception(env,
+			    _JC_IllegalMonitorStateException);
+			_jc_throw_exception(env);
+		}
+	}
+
+	/* Clip the current top of the Java stack if not already */
+	clipped_stack_top = _jc_stack_clip(env);
+
+	/* Enter non-java mode */
+	_jc_stopping_java(env, "Object.wait() on %s@%p",
+	    this->type->name, this);
+
+	/* Acquire the fat lock mutex */
+	_JC_MUTEX_LOCK(env, lock->mutex);
+
+	/* Unlock the object lock and wake up other fat lock waiters */
+	recursion_count = lock->recursion_count;
+	_JC_ASSERT(recursion_count != 0);
+	lock->recursion_count = 0;
+	lock->u.owner = NULL;
+	_JC_COND_BROADCAST(lock->cond);
+
+	/* Check and update this thread's interrupt status */
+	while (JNI_TRUE) {
+		switch ((old_status = env->interrupt_status)) {
+		case _JC_INTERRUPT_CLEAR:
+			env->interruptible_lock = lock;
+			if (_jc_compare_and_swap(&env->interrupt_status,
+			    old_status, _JC_INTERRUPT_INTERRUPTIBLE))
+				goto sleep;
+			break;
+		case _JC_INTERRUPT_SET:
+			env->interrupt_status = _JC_INTERRUPT_INTERRUPTED;
+			goto finished;
+		default:
+			_JC_ASSERT(JNI_FALSE);
+		}
+	}
+
+sleep:
+	/* Record current notify counter */
+	notify_count = lock->notify_count;
+
+again:
+	/*
+	 * Sleep until woken up. According to SUSv2 spec, "sprious wakeups
+	 * from pthread_cond_wait() or pthread_cond_timedwait() functions
+	 * may occur". So just because we woke up it doesn't necessarily
+	 * mean notify() or notifyAll() was called. This is also the case
+	 * anyway, because Thread.interrupt() can wake us up also, even
+	 * if we're not the target thread.
+	 */
+	if (timed_wait)
+		_JC_COND_TIMEDWAIT(env, lock->notify, lock->mutex, &wakeup);
+	else
+		_JC_COND_WAIT(env, lock->notify, lock->mutex);
+
+	/* Sanity check */
+	_JC_ASSERT(env->interrupt_status == _JC_INTERRUPT_INTERRUPTIBLE
+	    || env->interrupt_status == _JC_INTERRUPT_INTERRUPTED);
+
+	/* If we got interrupted, we're free */
+	if (env->interrupt_status == _JC_INTERRUPT_INTERRUPTED)
+		goto finished;
+
+	/* If there is a cross-posted exception for us, handle it now */
+	if (env->cross_exception != NULL)
+		goto finished;
+
+	/*
+	 * See if we really should have woken up. The object must have
+	 * been notify()'d or the wakeup time reached. If the notify
+	 * count hasn't changed then we haven't really been notify()'d.
+	 */
+	if (lock->notify_count == notify_count) {
+		struct timespec tsnow;
+		struct timeval now;
+
+		/* If there is no timeout, go back to sleep */
+		if (!timed_wait)
+			goto again;
+
+		/* See if we've passed the wakeup time */
+		gettimeofday(&now, NULL);
+		tsnow.tv_sec = now.tv_sec;
+		tsnow.tv_nsec = now.tv_usec * 1000;
+		if (tsnow.tv_sec > wakeup.tv_sec
+		    || (tsnow.tv_sec == wakeup.tv_sec
+		      && tsnow.tv_nsec >= wakeup.tv_nsec))
+			goto finished;
+
+		/* Not time yet, go back to sleep */
+		goto again;
+	}
+
+	/* See if we are the lucky thread that gets to wake up */
+	switch (lock->notify_wakeup) {
+	case 1:				/* notify() called, we win */
+		lock->notify_wakeup = 0;
+		break;
+	case 0:				/* notify() called, we lose */
+		goto again;
+	case -1:			/* notifyAll() called, everyone wins */
+		break;
+	}
+
+finished:
+	/* Wait for the object lock to be released */
+	while (lock->recursion_count != 0)
+		_JC_COND_WAIT(env, lock->cond, lock->mutex);
+
+	/* OK, now we can grab the fat lock back */
+	lock->recursion_count = recursion_count;
+	lock->u.owner = env;
+
+	/* Release the fat lock mutex */
+	_JC_MUTEX_UNLOCK(env, lock->mutex);
+
+	/* Back to running normal Java */
+	_jc_resuming_java(env);
+
+	/* Check to see if we were interrupted */
+	interrupted = JNI_FALSE;
+	while (JNI_TRUE) {
+		switch ((old_status = env->interrupt_status)) {
+		case _JC_INTERRUPT_INTERRUPTED:
+			env->interrupt_status = _JC_INTERRUPT_CLEAR;
+			env->interruptible_lock = NULL;
+			interrupted = JNI_TRUE;
+			goto done;
+		case _JC_INTERRUPT_INTERRUPTIBLE:
+			if (_jc_compare_and_swap(&env->interrupt_status,
+			    old_status, _JC_INTERRUPT_CLEAR)) {
+				env->interruptible_lock = NULL;
+				goto done;
+			}
+			break;
+		default:
+			_JC_ASSERT(JNI_FALSE);
+		}
+	}
+
+done:
+	/* If there is a cross-posted exception waiting for us, throw it now */
+	if ((ex = _jc_retrieve_cross_exception(env)) != NULL) {
+		_jc_post_exception_object(env, ex);
+		_jc_throw_exception(env);
+	}
+
+	/* Throw an InterruptedException if we were interrupted */
+	if (interrupted) {
+		_jc_post_exception(env, _JC_InterruptedException);
+		_jc_throw_exception(env);
+	}
+
+	/* Unclip stack */
+	if (clipped_stack_top)
+		_jc_stack_unclip(env);
+}
+
+/*
+ * static final native void notify(Object)
+ *	throws java/lang/IllegalMonitorStateException
+ */
+void _JC_JCNI_ATTR
+JCNI_java_lang_VMObject_notify(_jc_env *env, _jc_object *this)
+{
+	do_notify(env, this, JNI_FALSE);
+}
+
+/*
+ * static final native void notifyAll(Object)
+ *	throws java/lang/IllegalMonitorStateException
+ */
+void _JC_JCNI_ATTR
+JCNI_java_lang_VMObject_notifyAll(_jc_env *env, _jc_object *this)
+{
+	do_notify(env, this, JNI_TRUE);
+}
+
+/* 
+ * Common function doing the work of notify() and notifyAll().
+ */
+static void
+do_notify(_jc_env *env, _jc_object *this, jboolean broadcast)
+{
+	_jc_jvm *const vm = env->vm;
+	_jc_fat_lock *lock;
+	_jc_word lockword;
+
+	/* Check for null */
+	if (this == NULL) {
+		_jc_post_exception(env, _JC_NullPointerException);
+		_jc_throw_exception(env);
+	}
+	lockword = this->lockword;
+
+	/*
+	 * If lock is thin, things are simpler because there can
+	 * be no contention so there's nobody to wake up.
+	 */
+	if (!_JC_LW_TEST(lockword, FAT)) {
+
+		/* Make sure this thread is the owner */
+		if ((lockword & _JC_LW_THIN_TID_MASK) != env->thinlock_id)
+			goto illegal;
+
+		/* Done */
+		return;
+	}
+
+	/*
+	 * Handle the fat lock case.
+	 */
+	lock = vm->fat_locks.by_id[_JC_LW_EXTRACT(lockword, FAT_ID)];
+	_JC_ASSERT(lock != NULL);
+	if (lock->u.owner != env)
+		goto illegal;
+	_JC_ASSERT(lock->recursion_count > 0);
+
+	/* Wake up waiters and return */
+	_JC_MUTEX_LOCK(env, lock->mutex);
+	lock->notify_count++;
+	if (broadcast) {
+		lock->notify_wakeup = -1;
+		_JC_COND_BROADCAST(lock->notify);
+	} else {
+		lock->notify_wakeup = 1;
+		_JC_COND_SIGNAL(lock->notify);
+	}
+	_JC_MUTEX_UNLOCK(env, lock->mutex);
+	return;
+
+illegal:
+	/* This thread is not the owner of the lock */
+	_jc_post_exception(env, _JC_IllegalMonitorStateException);
+	_jc_throw_exception(env);
+}
+

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_VMRuntime.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_VMRuntime.c?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_VMRuntime.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_VMRuntime.c Tue Oct  4 19:19:16 2005
@@ -0,0 +1,215 @@
+
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors,
+ * as applicable.
+ * 
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ * $Id: java_lang_VMRuntime.c,v 1.7 2005/05/15 21:41:01 archiecobbs Exp $
+ */
+
+#include "libjc.h"
+#include "java_lang_VMRuntime.h"
+
+/*
+ * static final native int availableProcessors()
+ */
+jint _JC_JCNI_ATTR
+JCNI_java_lang_VMRuntime_availableProcessors(_jc_env *env)
+{
+	return _jc_num_cpus(env);
+}
+
+/*
+ * static final native void exit(int)
+ */
+void _JC_JCNI_ATTR
+JCNI_java_lang_VMRuntime_exit(_jc_env *env, jint status)
+{
+	_jc_jvm *const vm = env->vm;
+
+	(*vm->exit)(status);
+	_jc_fatal_error(vm, "exit() returned!");
+}
+
+/*
+ * static final native long freeMemory()
+ */
+jlong _JC_JCNI_ATTR
+JCNI_java_lang_VMRuntime_freeMemory(_jc_env *env)
+{
+	_jc_jvm *const vm = env->vm;
+
+	return (jlong)(vm->heap.num_pages - vm->heap.next_page)
+	    * (jlong)_JC_PAGE_SIZE;
+}
+
+/*
+ * static final native void gc()
+ */
+void _JC_JCNI_ATTR
+JCNI_java_lang_VMRuntime_gc(_jc_env *env)
+{
+	if (_jc_gc(env, JNI_FALSE) != JNI_OK) {
+		_jc_post_exception_info(env);
+		_jc_throw_exception(env);
+	}
+}
+
+/*
+ * static final native String mapLibraryName(String)
+ */
+_jc_object * _JC_JCNI_ATTR
+JCNI_java_lang_VMRuntime_mapLibraryName(_jc_env *env, _jc_object *string)
+{
+	size_t name_len;
+	char *fname;
+	char *name;
+
+	/* Check for null */
+	if (string == NULL) {
+		_jc_post_exception(env, _JC_NullPointerException);
+		_jc_throw_exception(env);
+	}
+
+	/* Decode string */
+	name_len = _jc_decode_string_utf8(env, string, NULL);
+	if ((name = _JC_STACK_ALLOC(env, name_len + 1)) == NULL) {
+		_jc_post_exception_info(env);
+		_jc_throw_exception(env);
+	}
+	_jc_decode_string_utf8(env, string, name);
+
+	/* Format filename */
+	if ((fname = _JC_FORMAT_STRING(env, _JC_LIBRARY_FMT, name)) == NULL) {
+		_jc_post_exception_info(env);
+		_jc_throw_exception(env);
+	}
+
+	/* Create new String object */
+	if ((string = _jc_new_string(env, fname, strlen(fname))) == NULL)
+		_jc_throw_exception(env);
+
+	/* Done */
+	return string;
+}
+
+/*
+ * static final native long maxMemory()
+ */
+jlong _JC_JCNI_ATTR
+JCNI_java_lang_VMRuntime_maxMemory(_jc_env *env)
+{
+	return _JC_JLONG(0x7fffffffffffffff);
+}
+
+/*
+ * static final native int nativeLoad(String, ClassLoader)
+ */
+jint _JC_JCNI_ATTR
+JCNI_java_lang_VMRuntime_nativeLoad(_jc_env *env,
+	_jc_object *string, _jc_object *clobj)
+{
+	_jc_jvm *const vm = env->vm;
+	_jc_class_loader *loader;
+	char *filename;
+	size_t len;
+
+	/* Check for null */
+	if (string == NULL) {
+		_jc_post_exception(env, _JC_NullPointerException);
+		_jc_throw_exception(env);
+	}
+
+	/* Convert String to UTF-8 */
+	len = _jc_decode_string_utf8(env, string, NULL);
+	if ((filename = _JC_STACK_ALLOC(env, len + 1)) == NULL) {
+		_jc_post_exception_info(env);
+		_jc_throw_exception(env);
+	}
+	_jc_decode_string_utf8(env, string, filename);
+
+	/* Get class loader */
+	if (clobj == NULL)
+		loader = vm->boot.loader;
+	else if ((loader = _jc_get_loader(env, clobj)) == NULL)
+		_jc_throw_exception(env);
+
+	/* Open native library */
+	if (_jc_load_native_library(env, loader, filename) != JNI_OK) {
+		_jc_post_exception_info(env);
+		_jc_throw_exception(env);
+	}
+
+	/* OK */
+	return 1;
+}
+
+/*
+ * static final native void runFinalization()
+ */
+void _JC_JCNI_ATTR
+JCNI_java_lang_VMRuntime_runFinalization(_jc_env *env)
+{
+	_jc_jvm *const vm = env->vm;
+
+	_jc_thread_interrupt_instance(vm, *vm->finalizer_thread);
+}
+
+/*
+ * static final native void runFinalizationForExit()
+ */
+void _JC_JCNI_ATTR
+JCNI_java_lang_VMRuntime_runFinalizationForExit(_jc_env *env)
+{
+	/* we don't support doing this so just ignore the request */
+}
+
+/*
+ * static final native void runFinalizersOnExit(boolean)
+ */
+void _JC_JCNI_ATTR
+JCNI_java_lang_VMRuntime_runFinalizersOnExit(_jc_env *env, jboolean enable)
+{
+	/* we don't support doing this so just ignore the request */
+}
+
+/*
+ * static final native long totalMemory()
+ */
+jlong _JC_JCNI_ATTR
+JCNI_java_lang_VMRuntime_totalMemory(_jc_env *env)
+{
+	_jc_jvm *const vm = env->vm;
+
+	return (jlong)vm->heap.num_pages * (jlong)_JC_PAGE_SIZE;
+}
+
+/*
+ * static final native void traceInstructions(boolean)
+ */
+void _JC_JCNI_ATTR
+JCNI_java_lang_VMRuntime_traceInstructions(_jc_env *env, jboolean param1)
+{
+	/* we don't support doing this so just ignore the request */
+}
+
+/*
+ * static final native void traceMethodCalls(boolean)
+ */
+void _JC_JCNI_ATTR
+JCNI_java_lang_VMRuntime_traceMethodCalls(_jc_env *env, jboolean enable)
+{
+	/* we don't support doing this so just ignore the request */
+}
+

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_VMSystem.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_VMSystem.c?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_VMSystem.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_VMSystem.c Tue Oct  4 19:19:16 2005
@@ -0,0 +1,240 @@
+
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors,
+ * as applicable.
+ * 
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ * $Id: java_lang_VMSystem.c,v 1.6 2005/05/15 21:41:01 archiecobbs Exp $
+ */
+
+#include "libjc.h"
+#include "java_lang_VMSystem.h"
+
+/*
+ * static final native void arraycopy(Object, int, Object, int, int)
+ */
+void _JC_JCNI_ATTR
+JCNI_java_lang_VMSystem_arraycopy(_jc_env *env, _jc_object *src,
+	jint srcOff, _jc_object *dst, jint dstOff, jint len)
+{
+	_jc_type *setype;
+	_jc_type *detype;
+	int etype;
+
+	/* Check for null */
+	if (src == NULL || dst == NULL) {
+		_jc_post_exception(env, _JC_NullPointerException);
+		_jc_throw_exception(env);
+	}
+
+	/* Verify that objects are arrays with compatible element types */
+	if (!_JC_LW_TEST(src->lockword, ARRAY)
+	    || ((src->lockword ^ dst->lockword)
+	     & (_JC_LW_ARRAY_BIT | (_JC_LW_TYPE_MASK << _JC_LW_TYPE_SHIFT)))
+	    != 0) {
+		_jc_post_exception(env, _JC_ArrayStoreException);
+		_jc_throw_exception(env);
+	}
+
+	/* Check bounds */
+	if (!_JC_BOUNDS_CHECK((_jc_array *)src, srcOff, len)
+	    || !_JC_BOUNDS_CHECK((_jc_array *)dst, dstOff, len)) {
+		_jc_post_exception(env, _JC_ArrayIndexOutOfBoundsException);
+		_jc_throw_exception(env);
+	}
+
+	/* Minor optimization */
+	if (len == 0)
+		return;
+
+	/* For primitive type, just bulk copy */
+	if ((etype = _JC_LW_EXTRACT(src->lockword, TYPE))
+	    != _JC_TYPE_REFERENCE) {
+		_jc_array *const spary = (_jc_array *)src;
+		_jc_array *const dpary = (_jc_array *)dst;
+		const size_t esize = _jc_type_sizes[etype];
+		const size_t eoffs = _jc_array_head_sizes[etype];
+
+		if (src == dst) {
+			memmove((char *)dpary + eoffs + (dstOff * esize),
+				(char *)spary + eoffs + (srcOff * esize),
+				len * esize);
+		} else {
+			memcpy( (char *)dpary + eoffs + (dstOff * esize),
+				(char *)spary + eoffs + (srcOff * esize),
+				len * esize);
+		}
+		return;
+	}
+
+	/* Get array element types */
+	setype = src->type->u.array.element_type;
+	detype = dst->type->u.array.element_type;
+
+	/*
+	 * If array element types are assignable, just bulk copy. Otherwise,
+	 * copy one element at a time, checking each for assignability;
+	 * we know the two arrays are actually different because they are
+	 * not assignable, so there's no possibility of overlap.
+	 */
+	switch (_jc_assignable_from(env, setype, detype)) {
+	case -1:
+		_jc_throw_exception(env);
+
+	case 1:					/* assignable */
+	    {
+		_jc_object_array *const soary = (_jc_object_array *)src;
+		_jc_object_array *const doary = (_jc_object_array *)dst;
+
+		if (src == dst) {
+			memmove(doary->elems + ~(dstOff + len - 1),
+				soary->elems + ~(srcOff + len - 1),
+				len * sizeof(*soary->elems));
+		} else {
+			memcpy( doary->elems + ~(dstOff + len - 1),
+				soary->elems + ~(srcOff + len - 1),
+				len * sizeof(*soary->elems));
+		}
+		break;
+	    }
+
+	case 0:					/* not assignable */
+	    {
+		_jc_object_array *const soary = (_jc_object_array *)src;
+		_jc_object_array *const doary = (_jc_object_array *)dst;
+		int i;
+
+		for (i = 0; i < len; i++) {
+			_jc_object *const elem = soary->elems[~(srcOff + i)];
+
+			/* Check for type compatibility */
+			if (elem != NULL) {
+				switch (_jc_instance_of(env, elem, detype)) {
+				case 1:
+					break;
+				case 0:
+					_jc_post_exception(env,
+					    _JC_ArrayStoreException);
+					/* FALLTHROUGH */
+				case -1:
+					_jc_throw_exception(env);
+				default:
+					_JC_ASSERT(JNI_FALSE);
+				}
+			}
+			doary->elems[~(dstOff + i)] = elem;
+		}
+		break;
+	    }
+
+	default:
+		_JC_ASSERT(JNI_FALSE);
+	}
+}
+
+/*
+ * static final native int identityHashCode(Object)
+ */
+jint _JC_JCNI_ATTR
+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;
+}
+

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_VMThread.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_VMThread.c?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_VMThread.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_VMThread.c Tue Oct  4 19:19:16 2005
@@ -0,0 +1,525 @@
+
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors,
+ * as applicable.
+ * 
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ * $Id: java_lang_VMThread.c,v 1.6 2005/05/15 21:41:01 archiecobbs Exp $
+ */
+
+#include "libjc.h"
+#include "java_lang_Thread.h"
+#include "java_lang_VMThread.h"
+
+/* Linux pthread_create() with supplied attributes is completely broken! */
+#ifdef __linux__
+#define _JC_NO_THREAD_ATTRIBUTES	1
+#endif
+
+/* Internal functions */
+static int	_jc_convert_java_prio(_jc_jvm *vm, jint jprio);
+
+/*
+ * final native int countStackFrames()
+ */
+jint _JC_JCNI_ATTR
+JCNI_java_lang_VMThread_countStackFrames(_jc_env *env, _jc_object *this)
+{
+	_jc_jvm *const vm = env->vm;
+	_jc_env *thread;
+	jint num = 0;
+
+	/* Lock VM so thread doesn't disappear */
+	_JC_MUTEX_LOCK(env, vm->mutex);
+
+	/* Get internal thread structure */
+	thread = _jc_get_vm_pointer(this, vm->boot.fields.VMThread.vmdata);
+	if (thread == NULL)
+		goto done;
+
+	/* Thread must be suspended */
+	if (!thread->suspended)
+		goto done;
+
+	/* Count stack frames */
+	num = _jc_save_stack_frames(env, thread, 0, NULL);
+
+done:
+	/* Unlock VM */
+	_JC_MUTEX_UNLOCK(env, vm->mutex);
+
+	/* Done */
+	return num;
+}
+
+/*
+ * static final native Thread currentThread()
+ */
+_jc_object * _JC_JCNI_ATTR
+JCNI_java_lang_VMThread_currentThread(_jc_env *env)
+{
+	_JC_ASSERT(env->instance != NULL);
+	return env->instance;
+}
+
+/*
+ * final native void interrupt()
+ */
+void _JC_JCNI_ATTR
+JCNI_java_lang_VMThread_interrupt(_jc_env *env, _jc_object *vmthread)
+{
+	_jc_jvm *const vm = env->vm;
+	_jc_object *thisThread;
+
+	/* Get Thread object */
+	thisThread = *_JC_VMFIELD(vm, vmthread, VMThread, thread, _jc_object *);
+	_JC_ASSERT(thisThread != NULL);
+
+	/* Interrupt thread */
+	_jc_thread_interrupt_instance(vm, thisThread);
+}
+
+/*
+ * static final native boolean interrupted()
+ */
+jboolean _JC_JCNI_ATTR
+JCNI_java_lang_VMThread_interrupted(_jc_env *env)
+{
+	switch (env->interrupt_status) {
+	case _JC_INTERRUPT_CLEAR:
+		return JNI_FALSE;
+	case _JC_INTERRUPT_SET:
+		env->interrupt_status = _JC_INTERRUPT_CLEAR;    /* no race */
+		return JNI_TRUE;
+	default:
+		_JC_ASSERT(JNI_FALSE);
+		return JNI_FALSE;
+	}
+}
+
+/*
+ * final native boolean isInterrupted()
+ */
+jboolean _JC_JCNI_ATTR
+JCNI_java_lang_VMThread_isInterrupted(_jc_env *env, _jc_object *this)
+{
+	_jc_jvm *const vm = env->vm;
+	jboolean result = JNI_FALSE;
+	_jc_env *thread;
+
+	/* Lock VM so thread doesn't disappear */
+	_JC_MUTEX_LOCK(env, vm->mutex);
+
+	/* Get thread's thread structure */
+	thread = _jc_get_vm_pointer(this, vm->boot.fields.VMThread.vmdata);
+	if (thread == NULL)
+		goto done;
+
+	/* Return thread's current interrupt status */
+	switch (thread->interrupt_status) {
+	case _JC_INTERRUPT_CLEAR:
+	case _JC_INTERRUPT_INTERRUPTIBLE:
+		break;
+	case _JC_INTERRUPT_SET:
+	case _JC_INTERRUPT_INTERRUPTED:
+		result = JNI_TRUE;
+		break;
+	default:
+		_JC_ASSERT(JNI_FALSE);
+	}
+
+done:
+	/* Done */
+	_JC_MUTEX_UNLOCK(env, vm->mutex);
+	return result;
+}
+
+/*
+ * final native void nativeSetPriority(int)
+ */
+void _JC_JCNI_ATTR
+JCNI_java_lang_VMThread_nativeSetPriority(_jc_env *env, _jc_object *this,
+	jint jprio)
+{
+	_jc_jvm *const vm = env->vm;
+	_jc_env *thread;
+	int prio;
+
+	/* Check for null */
+	if (this == NULL) {
+		_jc_post_exception(env, _JC_NullPointerException);
+		_jc_throw_exception(env);
+	}
+
+	/* Get internal priority value */
+	prio = _jc_convert_java_prio(vm, jprio);
+
+	/* Lock VM */
+	_JC_MUTEX_LOCK(env, vm->mutex);
+
+	/* Get internal thread structure */
+	thread = _jc_get_vm_pointer(this, vm->boot.fields.VMThread.vmdata);
+	if (thread == NULL)
+		goto done;
+
+	/* Adjust thread's priority XXX how do we implement this?? */
+	//_jc_eprintf(vm, "%s: warning: unimplemented\n", __FUNCTION__);
+
+done:
+	/* Done */
+	_JC_MUTEX_UNLOCK(env, vm->mutex);
+}
+
+/*
+ * final native void nativeStop(Throwable)
+ */
+void _JC_JCNI_ATTR
+JCNI_java_lang_VMThread_nativeStop(_jc_env *env,
+	_jc_object *this, _jc_object *throwable)
+{
+	_jc_jvm *const vm = env->vm;
+	_jc_env *thread;
+
+	/* Check for null */
+	if (throwable == NULL) {
+		_jc_post_exception(env, _JC_NullPointerException);
+		_jc_throw_exception(env);
+	}
+
+	/* Sanity check */
+	_JC_ASSERT(_jc_subclass_of(throwable, vm->boot.types.Throwable));
+
+	/* Lock VM so thread doesn't disappear */
+	_JC_MUTEX_LOCK(env, vm->mutex);
+
+	/* Get internal thread structure */
+	thread = _jc_get_vm_pointer(this, vm->boot.fields.VMThread.vmdata);
+	if (thread == NULL)
+		goto done;
+
+	/* Handle case where target is this thread */
+	if (thread == env) {
+		_JC_MUTEX_UNLOCK(env, vm->mutex);
+		_jc_post_exception_object(env, throwable);
+		_jc_throw_exception(env);
+	}
+
+	/* Cross-post exception; race condition with other threads is OK */
+	thread->cross_exception = throwable;
+
+	/* Wake up thread if its sleeping */
+	_jc_thread_interrupt(vm, thread);
+
+done:
+	/* Unlock VM */
+	_JC_MUTEX_UNLOCK(env, vm->mutex);
+}
+
+/*
+ * final native void resume()
+ */
+void _JC_JCNI_ATTR
+JCNI_java_lang_VMThread_resume(_jc_env *env, _jc_object *this)
+{
+	_jc_jvm *const vm = env->vm;
+	_jc_env *thread;
+
+	/* Check for null */
+	if (this == NULL) {
+		_jc_post_exception(env, _JC_NullPointerException);
+		_jc_throw_exception(env);
+	}
+
+	/* Lock VM */
+	_JC_MUTEX_LOCK(env, vm->mutex);
+
+	/* Get internal thread structure */
+	thread = _jc_get_vm_pointer(this, vm->boot.fields.VMThread.vmdata);
+	if (thread == NULL)
+		goto done;
+
+	/* Not suspended? */
+	if (!thread->suspended)
+		goto done;
+
+	/* Resume thread */
+	thread->suspended = JNI_FALSE;
+	_JC_COND_SIGNAL(thread->resumption);
+
+done:
+	/* Unlock VM */
+	_JC_MUTEX_UNLOCK(env, vm->mutex);
+}
+
+/*
+ * final native void start(long)
+ */
+void _JC_JCNI_ATTR
+JCNI_java_lang_VMThread_start(_jc_env *env, _jc_object *this, jlong stack_size)
+{
+	_jc_jvm *const vm = env->vm;
+#if _JC_NO_THREAD_ATTRIBUTES
+	pthread_attr_t *const attrp = NULL;
+#else
+	pthread_attr_t attr;
+	pthread_attr_t *const attrp = &attr;
+	jboolean attr_initialized = JNI_FALSE;
+	struct sched_param sparam;
+	void *guard_page;
+	int prio;
+#endif
+	pthread_t pthread;
+	_jc_object *tobj;
+	_jc_env *thread;
+	int error;
+
+	/* Lock VM */
+	_JC_MUTEX_LOCK(env, vm->mutex);
+
+	/*
+	 * Create a new thread structure, but also first check if another
+	 * thread is trying to stop the world. This check is required to
+	 * avoid the new thread starting up while the world is stopped.
+	 */
+	snprintf(env->text_status, sizeof(env->text_status), "Thread.start()");
+	_jc_halt_if_requested(env);
+	thread = _jc_allocate_thread(env);
+
+	/* Unlock VM */
+	_JC_MUTEX_UNLOCK(env, vm->mutex);
+
+	/* Check result */
+	if (thread == NULL) {
+		_jc_post_exception_info(env);
+		goto fail;
+	}
+
+	/* Save Thread object associated with the VMThread */
+	tobj = *_JC_VMFIELD(vm, this, VMThread, thread, _jc_object *);
+	_JC_ASSERT(tobj != NULL);
+	thread->instance = tobj;
+
+	/* Thread must have a group */
+	if (*_JC_VMFIELD(vm, tobj, Thread, group, _jc_object *) == NULL) {
+		_jc_post_exception_msg(env, _JC_IllegalThreadStateException,
+		    "thread is not in any thread group");
+		goto fail;
+	}
+
+	/* Sanity check thread is not already started */
+	_JC_ASSERT(_jc_get_vm_pointer(this,
+	    vm->boot.fields.VMThread.vmdata) == NULL);
+
+	/* Get requested stack size; use default if zero */
+	thread->stack_size = stack_size;
+	if (thread->stack_size == 0)
+		thread->stack_size = vm->threads.stack_default;
+
+	/* Clip the stack size to be within limits */
+	if (vm->threads.stack_maximum > 0
+	    && thread->stack_size > vm->threads.stack_maximum)
+		thread->stack_size = vm->threads.stack_maximum;
+	if (thread->stack_size < vm->threads.stack_minimum)
+		thread->stack_size = vm->threads.stack_minimum;
+	if (thread->stack_size < PTHREAD_STACK_MIN)
+		thread->stack_size = PTHREAD_STACK_MIN;
+	if (thread->stack_size < _JC_STACK_OVERFLOW_MARGIN)
+		thread->stack_size = _JC_STACK_OVERFLOW_MARGIN;
+
+	/* Add an extra guard page and round up to a full page size */
+	thread->stack_size += _JC_PAGE_SIZE;
+	thread->stack_size = _JC_ROUNDUP2(thread->stack_size, _JC_PAGE_SIZE);
+
+#if !_JC_NO_THREAD_ATTRIBUTES
+	/* Get requested priority (converted to scheduler priority) */
+	prio = _jc_convert_java_prio(vm,
+	    *_JC_VMFIELD(vm, tobj, Thread, priority, jint));
+
+	/* Allocate stack */
+	if ((thread->stack = mmap(NULL, thread->stack_size,
+	    PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0)) == MAP_FAILED) {
+		_jc_post_exception_msg(env, _JC_InternalError,
+		    "%s: %s", "mmap", strerror(errno));
+		thread->stack_size = 0;
+		thread->stack = NULL;
+		goto fail;
+	}
+
+	/* Invalidate guard page */
+#if _JC_DOWNWARD_STACK
+	guard_page = thread->stack;
+#else
+	guard_page = (char *)thread->stack + thread->stack_size - _JC_PAGE_SIZE;
+#endif
+	if (mprotect(guard_page, _JC_PAGE_SIZE, PROT_NONE) == -1) {
+		_jc_post_exception_msg(env, _JC_InternalError,
+		    "%s: %s", "mprotect", strerror(errno));
+		goto fail;
+	}
+
+	/* Initialize pthread attributes */
+	if ((error = pthread_attr_init(&attr)) != 0) {
+		_jc_post_exception_msg(env, _JC_InternalError,
+		    "%s: %s", "pthread_attr_init", strerror(error));
+		goto fail;
+	}
+	attr_initialized = JNI_TRUE;
+
+	/* Set pthread stack address and size attributes */
+#if HAVE_PTHREAD_ATTR_SETSTACK
+	if ((error = pthread_attr_setstack(&attr,
+	    thread->stack, thread->stack_size)) != 0) {
+		_jc_post_exception_msg(env, _JC_InternalError,
+		    "%s: %s", "pthread_attr_setstack", strerror(error));
+		goto fail;
+	}
+#else
+	if ((error = pthread_attr_setstackaddr(&attr,
+#if _JC_DOWNWARD_STACK && defined(__linux__)
+		(char *)thread->stack + thread->stack_size
+#else
+		thread->stack
+#endif
+	)) != 0) {
+		_jc_post_exception_msg(env, _JC_InternalError,
+		    "%s: %s", "pthread_attr_setstackaddr", strerror(error));
+		goto fail;
+	}
+	if ((error = pthread_attr_setstacksize(&attr,
+	    thread->stack_size)) != 0) {
+		_jc_post_exception_msg(env, _JC_InternalError,
+		    "%s: %s", "pthread_attr_setstacksize", strerror(error));
+		goto fail;
+	}
+#endif
+
+#if 0
+	/* Set pthread scheduling policy */
+	if ((error = pthread_attr_setschedpolicy(&attr, SCHED_RR)) != 0) {
+		_jc_post_exception_msg(env, _JC_InternalError,
+		    "%s: %s", "pthread_attr_setschedpolicy", strerror(error));
+		goto fail;
+	}
+#endif
+
+	/* Set pthread and priority */
+	memset(&sparam, 0, sizeof(sparam));
+	sparam.sched_priority = prio;
+#if 0
+	if ((error = pthread_attr_setschedparam(&attr, &sparam)) != 0) {
+		_jc_post_exception_msg(env, _JC_InternalError,
+		    "%s: %s", "pthread_attr_setschedparam", strerror(error));
+		goto fail;
+	}
+#endif
+#endif	/* !_JC_NO_THREAD_ATTRIBUTES */
+
+	/* Set the VMThread's vmdata pointer */
+	_jc_set_vm_pointer(this, vm->boot.fields.VMThread.vmdata, thread);
+
+	/* Hack to pass the VMThread's Thread pointer without setting it */
+	thread->retval.l = this;
+
+	/* Spawn new pthread to execute this thread */
+	if ((error = pthread_create(&pthread,
+	    attrp, _jc_thread_start, thread)) != 0) {
+		_jc_set_vm_pointer(this, vm->boot.fields.VMThread.vmdata, NULL);
+		_jc_post_exception_msg(env, _JC_InternalError,
+		    "%s: %s", "pthread_create", strerror(error));
+		goto fail;
+	}
+
+	/* Detach thread */
+	error = pthread_detach(pthread);
+	_JC_ASSERT(error == 0);
+
+	/* Done */
+#if !_JC_NO_THREAD_ATTRIBUTES
+	pthread_attr_destroy(&attr);
+#endif
+	return;
+
+fail:
+	/* Clean up after failure */
+	_JC_MUTEX_LOCK(env, vm->mutex);
+	_jc_free_thread(&thread, JNI_FALSE);
+	_JC_MUTEX_UNLOCK(env, vm->mutex);
+#if !_JC_NO_THREAD_ATTRIBUTES
+	if (attr_initialized)
+		pthread_attr_destroy(&attr);
+#endif
+	_jc_throw_exception(env);
+}
+
+/*
+ * final native void suspend()
+ */
+void _JC_JCNI_ATTR
+JCNI_java_lang_VMThread_suspend(_jc_env *env, _jc_object *this)
+{
+	_jc_jvm *const vm = env->vm;
+	_jc_env *thread;
+
+	/* Lock VM so thread doesn't disappear */
+	_JC_MUTEX_LOCK(env, vm->mutex);
+
+	/* Get internal thread structure */
+	thread = _jc_get_vm_pointer(this, vm->boot.fields.VMThread.vmdata);
+	if (thread == NULL)
+		goto done;
+
+	/* Already suspended? */
+	if (thread->suspended)
+		goto done;
+
+	/* Stop the world; a way to force it to call _jc_thread_check() */
+	_jc_stop_the_world(env);
+
+	/* Mark thread as suspended */
+	thread->suspended = JNI_TRUE;
+
+	/* Resume the world; thread will stay suspended */
+	_jc_resume_the_world(env);
+
+done:
+	/* Unlock VM */
+	_JC_MUTEX_UNLOCK(env, vm->mutex);
+}
+
+/*
+ * static final native void yield()
+ */
+void _JC_JCNI_ATTR
+JCNI_java_lang_VMThread_yield(_jc_env *env)
+{
+	sched_yield();
+}
+
+/*
+ * Convert Java thread priority to scheduler thread priority.
+ */
+static int
+_jc_convert_java_prio(_jc_jvm *vm, jint jprio)
+{
+	int prio;
+
+	prio = (int)(jprio - vm->threads.java_prio_min);
+	prio *= vm->threads.prio_max + 1 - vm->threads.prio_min;
+	prio /= vm->threads.java_prio_max + 1 - vm->threads.java_prio_min;
+	prio += vm->threads.prio_min;
+	_JC_ASSERT(prio >= vm->threads.prio_min
+	    && prio <= vm->threads.prio_max);
+	return prio;
+}
+

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_VMThrowable.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_VMThrowable.c?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_VMThrowable.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_VMThrowable.c Tue Oct  4 19:19:16 2005
@@ -0,0 +1,212 @@
+
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors,
+ * as applicable.
+ * 
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ * $Id: java_lang_VMThrowable.c,v 1.3 2005/05/15 21:41:01 archiecobbs Exp $
+ */
+
+#include "libjc.h"
+#include "java_lang_VMThrowable.h"
+
+/* Used to align byte[] array bytes to _JC_FULL_ALIGNMENT */
+#define _JC_BYTE_ARRAY_PAD	(_JC_ROUNDUP2(_JC_OFFSETOF(		\
+				    _jc_byte_array, elems),		\
+				      _JC_FULL_ALIGNMENT)		\
+				    - _JC_OFFSETOF(_jc_byte_array, elems))
+
+/*
+ * static final native VMThrowable fillInStackTrace(Throwable)
+ */
+_jc_object * _JC_JCNI_ATTR
+JCNI_java_lang_VMThrowable_fillInStackTrace(_jc_env *env, _jc_object *throwable)
+{
+	_jc_jvm *const vm = env->vm;
+	_jc_byte_array *bytes = NULL;
+	jobject bytes_ref = NULL;
+	_jc_saved_frame *frames;
+	_jc_object *vmt;
+	int num_frames;
+
+	/* Count the number of frames to save */
+	num_frames = _jc_save_stack_frames(env, env, 0, NULL);
+
+	/* Create byte[] array big enough to hold aligned frame array */
+	if ((bytes_ref = _jc_new_local_native_ref(env,
+	    (_jc_object *)_jc_new_array(env,
+	      vm->boot.types.prim_array[_JC_TYPE_BYTE],
+	      num_frames * sizeof(*frames) + _JC_BYTE_ARRAY_PAD))) == NULL)
+		_jc_throw_exception(env);
+	bytes = (_jc_byte_array *)*bytes_ref;
+	frames = (_jc_saved_frame *)_JC_ROUNDUP2(
+	    (_jc_word)bytes->elems, _JC_FULL_ALIGNMENT);
+
+	/* Fill in trace */
+	_jc_save_stack_frames(env, env, num_frames, frames);
+
+	/* Create VMThrowable */
+	if ((vmt = _jc_new_object(env, vm->boot.types.VMThrowable)) == NULL) {
+		_jc_free_local_native_ref(&bytes_ref);
+		_jc_throw_exception(env);
+	}
+
+	/* Save byte[] array in 'vmdata' field of VMThrowable */
+	*_JC_VMFIELD(vm, vmt, VMThrowable, vmdata, _jc_byte_array *) = bytes;
+
+	/* Clean up */
+	_jc_free_local_native_ref(&bytes_ref);
+
+	/* Done */
+	return vmt;
+}
+
+/*
+ * final native StackTraceElement[] getStackTrace(Throwable)
+ */
+_jc_object_array * _JC_JCNI_ATTR
+JCNI_java_lang_VMThrowable_getStackTrace(_jc_env *env, _jc_object *this,
+	_jc_object *throwable)
+{
+	_jc_jvm *const vm = env->vm;
+	_jc_object_array *array = NULL;
+	_jc_saved_frame *frames;
+	jobject array_ref = NULL;
+	jboolean ok = JNI_FALSE;
+	_jc_byte_array *bytes;
+	int num_frames;
+	int i;
+
+	/* Get saved frames from 'vmdata' byte[] array */
+	bytes = *_JC_VMFIELD(vm, this, VMThrowable, vmdata, _jc_byte_array *);
+	if (bytes == NULL) {
+		num_frames = 0;
+		frames = NULL;
+	} else {
+		num_frames = bytes->length / sizeof(*frames);
+		frames = (_jc_saved_frame *)_JC_ROUNDUP2(
+		    (_jc_word)bytes->elems, _JC_FULL_ALIGNMENT);
+	}
+
+	/* Create array */
+	if ((array_ref = _jc_new_local_native_ref(env,
+	    (_jc_object *)_jc_new_array(env,
+	      vm->boot.types.StackTraceElement_array, num_frames))) == NULL)
+		goto done;
+	array = (_jc_object_array *)*array_ref;
+
+	/* Fill the array with StackTraceElement's */
+	for (i = 0; i < num_frames; i++) {
+		_jc_saved_frame *frame = &frames[i];
+		jboolean loop_ok = JNI_FALSE;
+		jobject file_ref;
+		jobject class_ref;
+		jobject method_ref;
+		jobject ste_ref;
+		char *cname = NULL;
+		_jc_method *method;
+		_jc_type *class;
+		int jline;
+		char *s;
+
+		/* Get method and class */
+		method = frame->method;
+		class = method->class;
+		_JC_ASSERT(class != NULL);
+
+		/* Initialize references */
+		file_ref = NULL;
+		class_ref = NULL;
+		method_ref = NULL;
+		ste_ref = NULL;
+
+		/* Create String for source file name */
+		if (class->u.nonarray.source_file != NULL
+		    && (file_ref = _jc_new_local_native_ref(env,
+		      _jc_new_string(env, class->u.nonarray.source_file,
+		       strlen(class->u.nonarray.source_file)))) == NULL)
+			goto fail;
+
+		/* Get Java line number, if known */
+		jline = _JC_ACC_TEST(method, INTERP) ?
+		    _jc_interp_pc_to_jline(method, frame->u.ipc) :
+		    _jc_exec_pc_to_jline(method, frame->u.pc);
+
+		/* Create String for Class name, converting '/' -> '.' */
+		if ((cname = _jc_vm_strdup(env, class->name)) == NULL) {
+			_jc_post_exception_info(env);
+			goto fail;
+		}
+		for (s = cname; *s != '\0'; s++) {
+			if (*s == '/')
+				*s = '.';
+		}
+		if ((class_ref = _jc_new_local_native_ref(env,
+		    _jc_new_string(env, cname, strlen(cname)))) == NULL)
+			goto fail;
+
+		/* Create String for Method name */
+		if ((method_ref = _jc_new_local_native_ref(env,
+		    _jc_new_string(env, method->name,
+		      strlen(method->name)))) == NULL)
+			goto fail;
+
+		/* Allocate new StackTraceElement */
+		if ((ste_ref = _jc_new_local_native_ref(env,
+		    _jc_new_object(env,
+		      vm->boot.types.StackTraceElement))) == NULL)
+			goto fail;
+
+		/* Invoke constructor */
+		if (_jc_invoke_nonvirtual(env,
+		    vm->boot.methods.StackTraceElement.init, *ste_ref,
+		    file_ref != NULL ? *file_ref : NULL,
+		    (jint)(jline != 0 ? jline : -1), *class_ref,
+		    *method_ref, _JC_ACC_TEST(method, NATIVE)) != JNI_OK)
+			goto fail;
+
+		/* Set array element */
+		array->elems[~i] = *ste_ref;
+
+		/* OK */
+		loop_ok = JNI_TRUE;
+
+	fail:
+		/* Free temporary stuff */
+		_jc_free_local_native_ref(&file_ref);
+		_jc_free_local_native_ref(&class_ref);
+		_jc_free_local_native_ref(&method_ref);
+		_jc_free_local_native_ref(&ste_ref);
+		_jc_vm_free(&cname);
+
+		/* Bail out if we got an exception */
+		if (!loop_ok)
+			goto done;
+	}
+
+	/* OK */
+	ok = JNI_TRUE;
+
+done:
+	/* Free local native reference */
+	_jc_free_local_native_ref(&array_ref);
+
+	/* Bail if we got an exception */
+	if (!ok)
+		_jc_throw_exception(env);
+
+	/* Done */
+	return array;
+}
+

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_reflect_Constructor.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_reflect_Constructor.c?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_reflect_Constructor.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native/java_lang_reflect_Constructor.c Tue Oct  4 19:19:16 2005
@@ -0,0 +1,147 @@
+
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors,
+ * as applicable.
+ * 
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ * $Id: java_lang_reflect_Constructor.c,v 1.7 2005/05/15 21:41:01 archiecobbs Exp $
+ */
+
+#include "libjc.h"
+#include "java_lang_reflect_Constructor.h"
+
+/* Internal functions */
+static _jc_method	*_jc_check_constructor(_jc_env *env, _jc_object *this);
+
+/*
+ * private final native Object constructNative(Object[], Class, int)
+ *      throws InstantiationException, IllegalAccessException,
+ *		InvocationTargetException
+ */
+_jc_object * _JC_JCNI_ATTR
+JCNI_java_lang_reflect_Constructor_constructNative(_jc_env *env,
+	_jc_object *this, _jc_object_array *params, _jc_object *cl, jint slot)
+{
+	_jc_jvm *const vm = env->vm;
+	_jc_type *calling_class;
+	_jc_method *method;
+
+	/* Get constructor */
+	method = _jc_check_constructor(env, this);
+
+	/* Check accessibility */
+	if (_jc_invoke_virtual(env,
+	    vm->boot.methods.AccessibleObject.isAccessible, this) != JNI_OK)
+		_jc_throw_exception(env);
+	if (env->retval.z)
+		goto accessible;
+
+	/* Check access */
+	switch (_jc_reflect_accessible(env, method->class,
+	    method->access_flags, &calling_class)) {
+	case -1:
+		_jc_throw_exception(env);
+	case 1:
+		break;
+	case 0:
+		_jc_post_exception_msg(env, _JC_IllegalAccessException,
+		    "`%s.%s%s' is not accessible from `%s'",
+		    method->class->name, method->name, method->signature,
+		    calling_class->name);
+		_jc_throw_exception(env);
+	}
+
+accessible:
+	/* Invoke constructor */
+	if (_jc_reflect_invoke(env, method, NULL, params) != JNI_OK)
+		_jc_throw_exception(env);
+	_JC_ASSERT(env->retval.l != NULL);
+
+	/* Return created object */
+	return env->retval.l;
+}
+
+/*
+ * public final native Class[] getExceptionTypes()
+ */
+_jc_object_array * _JC_JCNI_ATTR
+JCNI_java_lang_reflect_Constructor_getExceptionTypes(_jc_env *env,
+	_jc_object *this)
+{
+	_jc_object_array *array;
+	_jc_method *method;
+
+	/* Get constructor */
+	method = _jc_check_constructor(env, this);
+
+	/* Get exception types */
+	if ((array = _jc_get_exception_types(env, method)) == NULL)
+		_jc_throw_exception(env);
+
+	/* Return array */
+	return array;
+}
+
+/*
+ * public final native int getModifiers()
+ */
+jint _JC_JCNI_ATTR
+JCNI_java_lang_reflect_Constructor_getModifiers(_jc_env *env, _jc_object *this)
+{
+	_jc_method *method;
+
+	/* Get constructor */
+	method = _jc_check_constructor(env, this);
+
+	/* Return flags */
+	return method->access_flags & _JC_ACC_MASK;
+}
+
+/*
+ * public final native Class[] getParameterTypes()
+ */
+_jc_object_array * _JC_JCNI_ATTR
+JCNI_java_lang_reflect_Constructor_getParameterTypes(_jc_env *env,
+	_jc_object *this)
+{
+	_jc_object_array *array;
+	_jc_method *method;
+
+	/* Get constructor */
+	method = _jc_check_constructor(env, this);
+
+	/* Get parameter types */
+	if ((array = _jc_get_parameter_types(env, method)) == NULL)
+		_jc_throw_exception(env);
+
+	/* Return array */
+	return array;
+}
+
+/*
+ * Find the _jc_method structure corresponding to a Constructor object.
+ */
+static _jc_method *
+_jc_check_constructor(_jc_env *env, _jc_object *this)
+{
+	/* Check for null */
+	if (this == NULL) {
+		_jc_post_exception(env, _JC_NullPointerException);
+		_jc_throw_exception(env);
+	}
+
+	/* Return constructor */
+	return _jc_get_constructor(env, this);
+}
+



Mime
View raw message