You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ar...@apache.org on 2005/12/14 18:54:43 UTC

svn commit: r356818 - in /incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm: configure.in include/jc_defs.h libjc/array.c libjc/interp.c libjc/libjc.h libjc/reflect.c libjc/resolve.c libjc/resolve2.c libjc/structures.h

Author: archie
Date: Wed Dec 14 09:54:36 2005
New Revision: 356818

URL: http://svn.apache.org/viewcvs?rev=356818&view=rev
Log:
- Hash signatures using normal string hashing rather than MD5 hashing
  to eliminate dependency on libcrypto and speed up class loading.
- Convert the quick interface method hash table to a table of method
  pointers (from a table of function pointers) so we can use it in
  interpreted code, to help avoid the now-slower bucket searches.

Modified:
    incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/configure.in
    incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/include/jc_defs.h
    incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/array.c
    incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/interp.c
    incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/libjc.h
    incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/reflect.c
    incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/resolve.c
    incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/resolve2.c
    incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/structures.h

Modified: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/configure.in
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/configure.in?rev=356818&r1=356817&r2=356818&view=diff
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/configure.in (original)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/configure.in Wed Dec 14 09:54:36 2005
@@ -76,8 +76,6 @@
 	[AC_MSG_ERROR([required library libm missing])])
 AC_CHECK_LIB(z, inflateInit_,,
 	[AC_MSG_ERROR([required library libz missing])])
-AC_CHECK_LIB(crypto, MD5_Init,,
-	[AC_MSG_ERROR([required library crypto missing])])
 AC_CHECK_LIB(popt, poptGetContext,,
 	[AC_MSG_ERROR([required library libpopt missing])])
 AC_CHECK_LIB(dl, dlopen,,,)
@@ -105,8 +103,7 @@
 # Check for required header files
 AC_HEADER_STDC
 AC_CHECK_HEADERS(sys/mman.h sys/wait.h pthread.h fcntl.h signal.h \
-	ctype.h errno.h dlfcn.h sched.h math.h pwd.h \
-	zlib.h openssl/md5.h, [],
+	ctype.h errno.h dlfcn.h sched.h math.h pwd.h zlib.h, [],
 	[AC_MSG_ERROR([required header file missing])])
 AC_CHECK_HEADERS([ucontext.h], [],
 	[AC_MSG_ERROR([required header file missing])],

Modified: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/include/jc_defs.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/include/jc_defs.h?rev=356818&r1=356817&r2=356818&view=diff
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/include/jc_defs.h (original)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/include/jc_defs.h Wed Dec 14 09:54:36 2005
@@ -302,13 +302,13 @@
 	_jc_type		**param_types;
 	_jc_type		*return_type;
 	unsigned char		*param_ptypes;
-	jlong			signature_hash;
 	_jc_type		**exceptions;
 	const void		*function;	/* code or interp trampoline */
 	_jc_word		vtable_index;	/* index in vtable, mtable */
 	_jc_uint16		access_flags;
 	_jc_uint16		num_parameters;
 	_jc_uint16		num_exceptions;
+	_jc_uint16		signature_hash_bucket;
 	const void		*native_function;
 	_jc_method_code		code;
 };
@@ -359,7 +359,7 @@
 	_jc_uint16		num_interfaces;
 	_jc_type		**interfaces;
 	_jc_method		***imethod_hash_table;
-	const void		**imethod_quick_table;
+	_jc_method		**imethod_quick_table;
 
 	/* Specific array/non-array info */
 	union {
@@ -552,7 +552,7 @@
 _JC_DECL_ARRAYS(double, prim$type);
 
 /* Empty interface method lookup tables */
-extern const		void *_jc_empty_quick_table[_JC_IMETHOD_HASHSIZE];
+extern _jc_method	*_jc_empty_quick_table[_JC_IMETHOD_HASHSIZE];
 extern _jc_method	**_jc_empty_imethod_table[_JC_IMETHOD_HASHSIZE];
 
 #endif	/* _JC_DEFS_H_ */

Modified: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/array.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/array.c?rev=356818&r1=356817&r2=356818&view=diff
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/array.c (original)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/array.c Wed Dec 14 09:54:36 2005
@@ -15,7 +15,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  *
- * $Id: array.c,v 1.6 2005/03/13 00:18:51 archiecobbs Exp $
+ * $Id$
  */
 
 #include "libjc.h"
@@ -85,7 +85,7 @@
 	    _JC_IMETHOD_HASHSIZE * sizeof(*array->imethod_hash_table))) == NULL)
 		goto fail;
 	if ((array->imethod_quick_table = _jc_cl_zalloc(env, vm->boot.loader,
-	      _JC_IMETHOD_HASHSIZE * sizeof(*array->imethod_quick_table)))
+	    _JC_IMETHOD_HASHSIZE * sizeof(*array->imethod_quick_table)))
 	      == NULL)
 		goto fail;
 
@@ -95,12 +95,12 @@
 		goto fail;
 
 	/* Get hash table index for clone() */
-	bucket = clone->signature_hash & (_JC_IMETHOD_HASHSIZE - 1);
+	bucket = clone->signature_hash_bucket;
 
 	/* Create hash table bucket */
 	if ((array->imethod_hash_table[bucket] = _jc_cl_zalloc(env,
 	    vm->boot.loader, 2 * sizeof(*array->imethod_hash_table[bucket])))
-	    == NULL)
+	      == NULL)
 		goto fail;
 
 	/* Put clone() in the bucket */
@@ -112,7 +112,7 @@
 	 * interface method implemented by arrays so we trivially know
 	 * there are no other methods in the same hash bucket.
 	 */
-	array->imethod_quick_table[bucket] = clone->function;
+	array->imethod_quick_table[bucket] = clone;
 
 	/* Unlock boot loader */
 	_JC_MUTEX_UNLOCK(env, vm->boot.loader->mutex);

Modified: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/interp.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/interp.c?rev=356818&r1=356817&r2=356818&view=diff
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/interp.c (original)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/interp.c Wed Dec 14 09:54:36 2005
@@ -955,9 +955,8 @@
 	switch (code->opcodes[pc]) {
 	case _JC_invokeinterface:
 	    {
-		const jlong sig_hash = imethod->signature_hash;
 		_jc_method *const *methodp;
-		int bucket;
+		_jc_method *quick;
 
 		/* Sanity check */
 		_JC_ASSERT(_JC_ACC_TEST(imethod->class, INTERFACE));
@@ -976,20 +975,34 @@
 			goto exception;
 		}
 
-		/* Lookup interface method entry point */
+		/* Sanity check */
 		_JC_ASSERT(obj->type->imethod_quick_table != NULL);
 		_JC_ASSERT(obj->type->imethod_hash_table != NULL);
-		bucket = (int)sig_hash & (_JC_IMETHOD_HASHSIZE - 1);
-		methodp = obj->type->imethod_hash_table[bucket];
-		if (methodp == NULL)
+		_JC_ASSERT(imethod->signature_hash_bucket
+		    < _JC_IMETHOD_HASHSIZE);
+
+		/* Try quick hash table lookup */
+		if ((quick = obj->type->imethod_quick_table[
+		    imethod->signature_hash_bucket]) != NULL) {
+		    	imethod = quick;
+			goto got_method;
+		}
+
+		/* Lookup interface method entry point in hash table */
+		if ((methodp = obj->type->imethod_hash_table[
+		    imethod->signature_hash_bucket]) == NULL)
 			goto not_found;
-		while (*methodp != NULL) {
-			if ((*methodp)->signature_hash == sig_hash) {
-				imethod = *methodp;
+		do {
+			_jc_method *const entry = *methodp;
+
+			if (strcmp(entry->name, imethod->name) == 0
+			    && strcmp(entry->signature,
+			      imethod->signature) == 0) {
+				imethod = entry;
 				break;
 			}
 			methodp++;
-		}
+		} while (*methodp != NULL);
 		if (*methodp == NULL) {
 not_found:		_jc_post_exception_msg(env, _JC_AbstractMethodError,
 			    "%s.%s%s invoked from %s.%s%s on a %s",
@@ -999,6 +1012,7 @@
 			goto exception;
 		}
 
+got_method:
 		/* Verify method is public */
 		if (!_JC_ACC_TEST(imethod, PUBLIC)) {
 			_jc_post_exception_msg(env, _JC_IllegalAccessError,

Modified: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/libjc.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/libjc.h?rev=356818&r1=356817&r2=356818&view=diff
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/libjc.h (original)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/libjc.h Wed Dec 14 09:54:36 2005
@@ -48,8 +48,6 @@
 
 #include <zlib.h>
 
-#include <openssl/md5.h>
-
 #define _JC_VIRTUAL_MACHINE		1	/* for jni.h */
 
 #include "queue.h"

Modified: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/reflect.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/reflect.c?rev=356818&r1=356817&r2=356818&view=diff
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/reflect.c (original)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/reflect.c Wed Dec 14 09:54:36 2005
@@ -15,7 +15,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  *
- * $Id: reflect.c,v 1.26 2005/11/09 18:14:22 archiecobbs Exp $
+ * $Id$
  */
 
 #include "libjc.h"
@@ -428,17 +428,19 @@
 	/* Resolve interface methods using hash table lookup */
 	if (!is_static && !is_constructor
 	    && _JC_ACC_TEST(method->class, INTERFACE)) {
-	      	const jlong sig_hash = method->signature_hash;
+	      	const int bucket = method->signature_hash_bucket;
 		_jc_type *const type = this->type;
-		const int bucket = (int)sig_hash & (_JC_IMETHOD_HASHSIZE - 1);
 		_jc_method *const *methodp;
 
 		_JC_ASSERT(type->imethod_hash_table != NULL);
 		for (methodp = type->imethod_hash_table[bucket];
 		    *methodp != NULL; methodp++) {
-			if ((*methodp)->signature_hash == sig_hash) {
+		    	_jc_method *const entry = *methodp;
+
+			if (strcmp(entry->name, method->name) == 0
+			    && strcmp(entry->signature, method->signature) == 0) {
 				imethod = method;
-				method = *methodp;
+				method = entry;
 				break;
 			}
 		}

Modified: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/resolve.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/resolve.c?rev=356818&r1=356817&r2=356818&view=diff
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/resolve.c (original)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/resolve.c Wed Dec 14 09:54:36 2005
@@ -24,7 +24,7 @@
 static void		_jc_resolve_vtable(_jc_jvm *vm, _jc_type *type);
 
 /* Empty interface method lookup tables */
-const void		*_jc_empty_quick_table[_JC_IMETHOD_HASHSIZE];
+_jc_method		*_jc_empty_quick_table[_JC_IMETHOD_HASHSIZE];
 _jc_method		**_jc_empty_imethod_table[_JC_IMETHOD_HASHSIZE];
 
 /*

Modified: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/resolve2.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/resolve2.c?rev=356818&r1=356817&r2=356818&view=diff
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/resolve2.c (original)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/resolve2.c Wed Dec 14 09:54:36 2005
@@ -295,20 +295,17 @@
 	for (i = 0; i < ntype->num_methods; i++) {
 		_jc_cf_method *const cmethod = &cfile->methods[i];
 		_jc_method *const method = ntype->methods[i];
-		u_char md5[MD5_DIGEST_LENGTH];
-		MD5_CTX ctx;
+		int signature_hash = 0;
+		const char *s;
 		int j;
 
 		/* Compute method's signature hash */
-		MD5_Init(&ctx);
-		MD5_Update(&ctx, method->name, strlen(method->name));
-		MD5_Update(&ctx, method->signature, strlen(method->signature));
-		MD5_Final(md5, &ctx);
-		method->signature_hash =
-		      ((jlong)md5[ 8] << 56) | ((jlong)md5[ 9] << 48)
-		    | ((jlong)md5[10] << 40) | ((jlong)md5[11] << 32)
-		    | ((jlong)md5[12] << 24) | ((jlong)md5[13] << 16)
-		    | ((jlong)md5[14] <<  8) | ((jlong)md5[15] <<  0);
+		for (s = method->name; *s != '\0'; s++)
+			signature_hash = (signature_hash * 31) + (u_char)*s;
+		for (s = method->signature; *s != '\0'; s++)
+			signature_hash = (signature_hash * 31) + (u_char)*s;
+		method->signature_hash_bucket = signature_hash
+		    & (_JC_IMETHOD_HASHSIZE - 1);
 
 		/* Compute the number of parameters */
 		if ((j = _jc_resolve_signature(env, method, NULL)) == -1) {
@@ -1057,7 +1054,6 @@
 	int max_methods;
 	int num_methods;
 	_jc_type *stype;
-	const void **qptr;
 	_jc_method **ptr;
 	int *follows;
 	int i;
@@ -1141,8 +1137,7 @@
 	memset(&heads, ~0, sizeof(heads));
 	for (i = 0; i < num_methods; i++) {
 		_jc_method *const method = methods[i];
-		const int bucket = (int)method->signature_hash
-		    & (_JC_IMETHOD_HASHSIZE - 1);
+		const int bucket = method->signature_hash_bucket;
 
 		/* Keep track of the number of nonempty and singleton buckets */
 		if (heads[bucket] == -1) {
@@ -1171,21 +1166,18 @@
 	_JC_MUTEX_UNLOCK(env, type->loader->mutex);
 
 	/* Fill in the "quick" hash table (if any) */
-	qptr = (const void **)(type->imethod_hash_table + _JC_IMETHOD_HASHSIZE);
+	ptr = (_jc_method **)(type->imethod_hash_table + _JC_IMETHOD_HASHSIZE);
 	if (num_singleton_buckets > 0) {
-		type->imethod_quick_table = qptr;
-		qptr += _JC_IMETHOD_HASHSIZE;
+		type->imethod_quick_table = ptr;
+		ptr += _JC_IMETHOD_HASHSIZE;
 		for (i = 0; i < _JC_IMETHOD_HASHSIZE; i++) {
-			if (heads[i] != -1 && follows[heads[i]] == -1) {
-				type->imethod_quick_table[i]
-				    = methods[heads[i]]->function;
-			}
+			if (heads[i] != -1 && follows[heads[i]] == -1)
+				type->imethod_quick_table[i] = methods[heads[i]];
 		}
 	} else
 		type->imethod_quick_table = _jc_empty_quick_table;
 
 	/* Fill in the hash table */
-	ptr = (_jc_method **)qptr;
 	for (i = 0; i < _JC_IMETHOD_HASHSIZE; i++) {
 		int next = heads[i];
 

Modified: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/structures.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/structures.h?rev=356818&r1=356817&r2=356818&view=diff
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/structures.h (original)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/structures.h Wed Dec 14 09:54:36 2005
@@ -574,7 +574,7 @@
 	int			num_interfaces;
 	_jc_type		**interfaces;
 	_jc_method		***imethod_hash_table;
-	const void		**imethod_quick_table;
+	_jc_method		**imethod_quick_table;
 };
 
 /* One entry in a classpath style search path */