harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r294974 [5/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/include/jni.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/include/jni.h?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/include/jni.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/include/jni.h Tue Oct  4 19:19:16 2005
@@ -0,0 +1,414 @@
+
+/*
+ * 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: jni.h,v 1.7 2005/02/27 04:52:59 archiecobbs Exp $
+ */
+
+#ifndef _JNI_H_
+#define _JNI_H_
+
+#include <stdarg.h>
+#include "jni_machdep.h"
+
+/************************************************************************
+ *			      Definitions				*
+ ************************************************************************/
+
+#define JNI_FALSE	((int)0)
+#define JNI_TRUE	1
+
+#define JNI_COMMIT	1
+#define JNI_ABORT	2
+
+#define JNI_VERSION_1_1	0x00010001
+#define JNI_VERSION_1_2	0x00010002
+#define JNI_VERSION_1_4	0x00010004
+
+#define JNI_OK		((int)0)
+#define JNI_ERR		(-1)
+#define JNI_EDETACHED	(-2)
+#define JNI_EVERSION	(-3)
+
+#define JNICALL
+#define JNIEXPORT
+
+/************************************************************************
+ *				Typedefs				*
+ ************************************************************************/
+
+#if _JC_VIRTUAL_MACHINE
+
+typedef struct _jc_object		**jobject;
+typedef struct _jc_object		**jstring;
+typedef struct _jc_object		**jthrowable;
+typedef struct _jc_object		**jweak;
+typedef struct _jc_object		**jclass;
+typedef struct _jc_array		**jarray;
+typedef struct _jc_boolean_array	**jbooleanArray;
+typedef struct _jc_byte_array		**jbyteArray;
+typedef struct _jc_char_array		**jcharArray;
+typedef struct _jc_short_array		**jshortArray;
+typedef struct _jc_int_array		**jintArray;
+typedef struct _jc_long_array		**jlongArray;
+typedef struct _jc_float_array		**jfloatArray;
+typedef struct _jc_double_array		**jdoubleArray;
+typedef struct _jc_object_array		**jobjectArray;
+typedef struct _jc_field		*jfieldID;
+typedef struct _jc_method		*jmethodID;
+
+typedef struct JNINativeInterface	*JNIEnv;
+typedef struct JNIInvokeInterface	*JavaVM;
+
+#else	/* !_JC_VIRTUAL_MACHINE */
+
+typedef const struct _jc_jni_object	*jobject;
+typedef jobject				jstring;
+typedef jobject				jthrowable;
+typedef jobject				jweak;
+typedef jobject				jclass;
+typedef jobject				jarray;
+typedef jobject				jbooleanArray;
+typedef jobject				jbyteArray;
+typedef jobject				jcharArray;
+typedef jobject				jshortArray;
+typedef jobject				jintArray;
+typedef jobject				jlongArray;
+typedef jobject				jfloatArray;
+typedef jobject				jdoubleArray;
+typedef jobject				jobjectArray;
+typedef const struct _jc_jni_field	*jfieldID;
+typedef const struct _jc_jni_method	*jmethodID;
+
+typedef const struct JNINativeInterface *JNIEnv;
+typedef const struct JNIInvokeInterface *JavaVM;
+
+#endif	/* !_JC_VIRTUAL_MACHINE */
+
+typedef jint jsize;
+
+union jvalue {
+	jboolean	z;
+	jbyte		b;
+	jchar		c;
+	jshort		s;
+	jint		i;
+	jlong		j;
+	jfloat		f;
+	jdouble		d;
+	jobject		l;
+};
+typedef union jvalue jvalue;
+
+struct JNINativeMethod {
+	char		*name;
+	char		*signature;
+	void		*fnPtr;
+};
+typedef struct JNINativeMethod JNINativeMethod;
+
+struct JavaVMOption {
+	char		*optionString;
+	void		*extraInfo;
+};
+typedef struct JavaVMOption JavaVMOption;
+
+struct JavaVMInitArgs {
+	jint		version;
+	jint		nOptions;
+	JavaVMOption	*options;
+	jboolean	ignoreUnrecognized;
+};
+typedef struct JavaVMInitArgs JavaVMInitArgs;
+
+struct JavaVMAttachArgs {
+	jint		version;
+	char		*name;
+	jobject		group;
+};
+typedef struct JavaVMAttachArgs JavaVMAttachArgs;
+
+/* JNINativeInterface type */
+struct JNINativeInterface {
+  void *null_0;
+  void *null_1;
+  void *null_2;
+  void *null_3;
+  jint (JNICALL *GetVersion)(JNIEnv *env);	/* 4 */
+  jclass (JNICALL *DefineClass)(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize bufLen);	/* 5 */
+  jclass (JNICALL *FindClass)(JNIEnv *env, const char *name);	/* 6 */
+  jmethodID (JNICALL *FromReflectedMethod)(JNIEnv *env, jobject method);	/* 7 */
+  jfieldID (JNICALL *FromReflectedField)(JNIEnv *env, jobject field);	/* 8 */
+  jobject (JNICALL *ToReflectedMethod)(JNIEnv *env, jclass cls, jmethodID methodID);	/* 9 */
+  jclass (JNICALL *GetSuperclass)(JNIEnv *env, jclass clazz);	/* 10 */
+  jboolean (JNICALL *IsAssignableFrom)(JNIEnv *env, jclass clazz1, jclass clazz2);	/* 11 */
+  jobject (JNICALL *ToReflectedField)(JNIEnv *env, jclass cls, jfieldID fieldID);	/* 12 */
+  jint (JNICALL *Throw)(JNIEnv *env, jthrowable obj);	/* 13 */
+  jint (JNICALL *ThrowNew)(JNIEnv *env, jclass clazz, const char *message);	/* 14 */
+  jthrowable (JNICALL *ExceptionOccurred)(JNIEnv *env);	/* 15 */
+  void (JNICALL *ExceptionDescribe)(JNIEnv *env);	/* 16 */
+  void (JNICALL *ExceptionClear)(JNIEnv *env);	/* 17 */
+  void (JNICALL *FatalError)(JNIEnv *env, const char *msg);	/* 18 */
+  jint (JNICALL *PushLocalFrame)(JNIEnv *env, jint capacity);	/* 19 */
+  jobject (JNICALL *PopLocalFrame)(JNIEnv *env, jobject result);	/* 20 */
+  jobject (JNICALL *NewGlobalRef)(JNIEnv *env, jobject obj);	/* 21 */
+  void (JNICALL *DeleteGlobalRef)(JNIEnv *env, jobject gref);	/* 22 */
+  void (JNICALL *DeleteLocalRef)(JNIEnv *env, jobject lref);	/* 23 */
+  jboolean (JNICALL *IsSameObject)(JNIEnv *env, jobject ref1, jobject ref2);	/* 24 */
+  jobject (JNICALL *NewLocalRef)(JNIEnv *env, jobject ref);	/* 25 */
+  jint (JNICALL *EnsureLocalCapacity)(JNIEnv *env, jint capacity);	/* 26 */
+  jobject (JNICALL *AllocObject)(JNIEnv *env, jclass clazz);	/* 27 */
+  jobject (JNICALL *NewObject)(JNIEnv *env, jclass clazz, jmethodID methodID, ...);	/* 28 */
+  jobject (JNICALL *NewObjectV)(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);	/* 29 */
+  jobject (JNICALL *NewObjectA)(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args);	/* 30 */
+  jclass (JNICALL *GetObjectClass)(JNIEnv *env, jobject obj);	/* 31 */
+  jboolean (JNICALL *IsInstanceOf)(JNIEnv *env, jobject obj, jclass clazz);	/* 32 */
+  jmethodID (JNICALL *GetMethodID)(JNIEnv *env, jclass clazz, const char *name, const char *sig);	/* 33 */
+  jobject (JNICALL *CallObjectMethod)(JNIEnv *env, jobject obj, jmethodID methodID, ...);	/* 34 */
+  jobject (JNICALL *CallObjectMethodV)(JNIEnv *env, jobject obj, jmethodID methodID, va_list args);	/* 35 */
+  jobject (JNICALL *CallObjectMethodA)(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args);	/* 36 */
+  jboolean (JNICALL *CallBooleanMethod)(JNIEnv *env, jobject obj, jmethodID methodID, ...);	/* 37 */
+  jboolean (JNICALL *CallBooleanMethodV)(JNIEnv *env, jobject obj, jmethodID methodID, va_list args);	/* 38 */
+  jboolean (JNICALL *CallBooleanMethodA)(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args);	/* 39 */
+  jbyte (JNICALL *CallByteMethod)(JNIEnv *env, jobject obj, jmethodID methodID, ...);	/* 40 */
+  jbyte (JNICALL *CallByteMethodV)(JNIEnv *env, jobject obj, jmethodID methodID, va_list args);	/* 41 */
+  jbyte (JNICALL *CallByteMethodA)(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args);	/* 42 */
+  jchar (JNICALL *CallCharMethod)(JNIEnv *env, jobject obj, jmethodID methodID, ...);	/* 43 */
+  jchar (JNICALL *CallCharMethodV)(JNIEnv *env, jobject obj, jmethodID methodID, va_list args);	/* 44 */
+  jchar (JNICALL *CallCharMethodA)(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args);	/* 45 */
+  jshort (JNICALL *CallShortMethod)(JNIEnv *env, jobject obj, jmethodID methodID, ...);	/* 46 */
+  jshort (JNICALL *CallShortMethodV)(JNIEnv *env, jobject obj, jmethodID methodID, va_list args);	/* 47 */
+  jshort (JNICALL *CallShortMethodA)(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args);	/* 48 */
+  jint (JNICALL *CallIntMethod)(JNIEnv *env, jobject obj, jmethodID methodID, ...);	/* 49 */
+  jint (JNICALL *CallIntMethodV)(JNIEnv *env, jobject obj, jmethodID methodID, va_list args);	/* 50 */
+  jint (JNICALL *CallIntMethodA)(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args);	/* 51 */
+  jlong (JNICALL *CallLongMethod)(JNIEnv *env, jobject obj, jmethodID methodID, ...);	/* 52 */
+  jlong (JNICALL *CallLongMethodV)(JNIEnv *env, jobject obj, jmethodID methodID, va_list args);	/* 53 */
+  jlong (JNICALL *CallLongMethodA)(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args);	/* 54 */
+  jfloat (JNICALL *CallFloatMethod)(JNIEnv *env, jobject obj, jmethodID methodID, ...);	/* 55 */
+  jfloat (JNICALL *CallFloatMethodV)(JNIEnv *env, jobject obj, jmethodID methodID, va_list args);	/* 56 */
+  jfloat (JNICALL *CallFloatMethodA)(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args);	/* 57 */
+  jdouble (JNICALL *CallDoubleMethod)(JNIEnv *env, jobject obj, jmethodID methodID, ...);	/* 58 */
+  jdouble (JNICALL *CallDoubleMethodV)(JNIEnv *env, jobject obj, jmethodID methodID, va_list args);	/* 59 */
+  jdouble (JNICALL *CallDoubleMethodA)(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args);	/* 60 */
+  void (JNICALL *CallVoidMethod)(JNIEnv *env, jobject obj, jmethodID methodID, ...);	/* 61 */
+  void (JNICALL *CallVoidMethodV)(JNIEnv *env, jobject obj, jmethodID methodID, va_list args);	/* 62 */
+  void (JNICALL *CallVoidMethodA)(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args);	/* 63 */
+  jobject (JNICALL *CallNonvirtualObjectMethod)(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);	/* 64 */
+  jobject (JNICALL *CallNonvirtualObjectMethodV)(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args);	/* 65 */
+  jobject (JNICALL *CallNonvirtualObjectMethodA)(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args);	/* 66 */
+  jboolean (JNICALL *CallNonvirtualBooleanMethod)(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);	/* 67 */
+  jboolean (JNICALL *CallNonvirtualBooleanMethodV)(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args);	/* 68 */
+  jboolean (JNICALL *CallNonvirtualBooleanMethodA)(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args);	/* 69 */
+  jbyte (JNICALL *CallNonvirtualByteMethod)(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);	/* 70 */
+  jbyte (JNICALL *CallNonvirtualByteMethodV)(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args);	/* 71 */
+  jbyte (JNICALL *CallNonvirtualByteMethodA)(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args);	/* 72 */
+  jchar (JNICALL *CallNonvirtualCharMethod)(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);	/* 73 */
+  jchar (JNICALL *CallNonvirtualCharMethodV)(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args);	/* 74 */
+  jchar (JNICALL *CallNonvirtualCharMethodA)(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args);	/* 75 */
+  jshort (JNICALL *CallNonvirtualShortMethod)(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);	/* 76 */
+  jshort (JNICALL *CallNonvirtualShortMethodV)(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args);	/* 77 */
+  jshort (JNICALL *CallNonvirtualShortMethodA)(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args);	/* 78 */
+  jint (JNICALL *CallNonvirtualIntMethod)(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);	/* 79 */
+  jint (JNICALL *CallNonvirtualIntMethodV)(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args);	/* 80 */
+  jint (JNICALL *CallNonvirtualIntMethodA)(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args);	/* 81 */
+  jlong (JNICALL *CallNonvirtualLongMethod)(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);	/* 82 */
+  jlong (JNICALL *CallNonvirtualLongMethodV)(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args);	/* 83 */
+  jlong (JNICALL *CallNonvirtualLongMethodA)(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args);	/* 84 */
+  jfloat (JNICALL *CallNonvirtualFloatMethod)(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);	/* 85 */
+  jfloat (JNICALL *CallNonvirtualFloatMethodV)(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args);	/* 86 */
+  jfloat (JNICALL *CallNonvirtualFloatMethodA)(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args);	/* 87 */
+  jdouble (JNICALL *CallNonvirtualDoubleMethod)(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);	/* 88 */
+  jdouble (JNICALL *CallNonvirtualDoubleMethodV)(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args);	/* 89 */
+  jdouble (JNICALL *CallNonvirtualDoubleMethodA)(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args);	/* 90 */
+  void (JNICALL *CallNonvirtualVoidMethod)(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);	/* 91 */
+  void (JNICALL *CallNonvirtualVoidMethodV)(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args);	/* 92 */
+  void (JNICALL *CallNonvirtualVoidMethodA)(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args);	/* 93 */
+  jfieldID (JNICALL *GetFieldID)(JNIEnv *env, jclass clazz, const char *name, const char *sig);	/* 94 */
+  jobject (JNICALL *GetObjectField)(JNIEnv *env, jobject obj, jfieldID fieldID);	/* 95 */
+  jboolean (JNICALL *GetBooleanField)(JNIEnv *env, jobject obj, jfieldID fieldID);	/* 96 */
+  jbyte (JNICALL *GetByteField)(JNIEnv *env, jobject obj, jfieldID fieldID);	/* 97 */
+  jchar (JNICALL *GetCharField)(JNIEnv *env, jobject obj, jfieldID fieldID);	/* 98 */
+  jshort (JNICALL *GetShortField)(JNIEnv *env, jobject obj, jfieldID fieldID);	/* 99 */
+  jint (JNICALL *GetIntField)(JNIEnv *env, jobject obj, jfieldID fieldID);	/* 100 */
+  jlong (JNICALL *GetLongField)(JNIEnv *env, jobject obj, jfieldID fieldID);	/* 101 */
+  jfloat (JNICALL *GetFloatField)(JNIEnv *env, jobject obj, jfieldID fieldID);	/* 102 */
+  jdouble (JNICALL *GetDoubleField)(JNIEnv *env, jobject obj, jfieldID fieldID);	/* 103 */
+  void (JNICALL *SetObjectField)(JNIEnv *env, jobject obj, jfieldID fieldID, jobject value);	/* 104 */
+  void (JNICALL *SetBooleanField)(JNIEnv *env, jobject obj, jfieldID fieldID, jboolean value);	/* 105 */
+  void (JNICALL *SetByteField)(JNIEnv *env, jobject obj, jfieldID fieldID, jbyte value);	/* 106 */
+  void (JNICALL *SetCharField)(JNIEnv *env, jobject obj, jfieldID fieldID, jchar value);	/* 107 */
+  void (JNICALL *SetShortField)(JNIEnv *env, jobject obj, jfieldID fieldID, jshort value);	/* 108 */
+  void (JNICALL *SetIntField)(JNIEnv *env, jobject obj, jfieldID fieldID, jint value);	/* 109 */
+  void (JNICALL *SetLongField)(JNIEnv *env, jobject obj, jfieldID fieldID, jlong value);	/* 110 */
+  void (JNICALL *SetFloatField)(JNIEnv *env, jobject obj, jfieldID fieldID, jfloat value);	/* 111 */
+  void (JNICALL *SetDoubleField)(JNIEnv *env, jobject obj, jfieldID fieldID, jdouble value);	/* 112 */
+  jmethodID (JNICALL *GetStaticMethodID)(JNIEnv *env, jclass clazz, const char *name, const char *sig);	/* 113 */
+  jobject (JNICALL *CallStaticObjectMethod)(JNIEnv *env, jclass clazz, jmethodID methodID, ...);	/* 114 */
+  jobject (JNICALL *CallStaticObjectMethodV)(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);	/* 115 */
+  jobject (JNICALL *CallStaticObjectMethodA)(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args);	/* 116 */
+  jboolean (JNICALL *CallStaticBooleanMethod)(JNIEnv *env, jclass clazz, jmethodID methodID, ...);	/* 117 */
+  jboolean (JNICALL *CallStaticBooleanMethodV)(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);	/* 118 */
+  jboolean (JNICALL *CallStaticBooleanMethodA)(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args);	/* 119 */
+  jbyte (JNICALL *CallStaticByteMethod)(JNIEnv *env, jclass clazz, jmethodID methodID, ...);	/* 120 */
+  jbyte (JNICALL *CallStaticByteMethodV)(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);	/* 121 */
+  jbyte (JNICALL *CallStaticByteMethodA)(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args);	/* 122 */
+  jchar (JNICALL *CallStaticCharMethod)(JNIEnv *env, jclass clazz, jmethodID methodID, ...);	/* 123 */
+  jchar (JNICALL *CallStaticCharMethodV)(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);	/* 124 */
+  jchar (JNICALL *CallStaticCharMethodA)(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args);	/* 125 */
+  jshort (JNICALL *CallStaticShortMethod)(JNIEnv *env, jclass clazz, jmethodID methodID, ...);	/* 126 */
+  jshort (JNICALL *CallStaticShortMethodV)(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);	/* 127 */
+  jshort (JNICALL *CallStaticShortMethodA)(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args);	/* 128 */
+  jint (JNICALL *CallStaticIntMethod)(JNIEnv *env, jclass clazz, jmethodID methodID, ...);	/* 129 */
+  jint (JNICALL *CallStaticIntMethodV)(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);	/* 130 */
+  jint (JNICALL *CallStaticIntMethodA)(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args);	/* 131 */
+  jlong (JNICALL *CallStaticLongMethod)(JNIEnv *env, jclass clazz, jmethodID methodID, ...);	/* 132 */
+  jlong (JNICALL *CallStaticLongMethodV)(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);	/* 133 */
+  jlong (JNICALL *CallStaticLongMethodA)(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args);	/* 134 */
+  jfloat (JNICALL *CallStaticFloatMethod)(JNIEnv *env, jclass clazz, jmethodID methodID, ...);	/* 135 */
+  jfloat (JNICALL *CallStaticFloatMethodV)(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);	/* 136 */
+  jfloat (JNICALL *CallStaticFloatMethodA)(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args);	/* 137 */
+  jdouble (JNICALL *CallStaticDoubleMethod)(JNIEnv *env, jclass clazz, jmethodID methodID, ...);	/* 138 */
+  jdouble (JNICALL *CallStaticDoubleMethodV)(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);	/* 139 */
+  jdouble (JNICALL *CallStaticDoubleMethodA)(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args);	/* 140 */
+  void (JNICALL *CallStaticVoidMethod)(JNIEnv *env, jclass clazz, jmethodID methodID, ...);	/* 141 */
+  void (JNICALL *CallStaticVoidMethodV)(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);	/* 142 */
+  void (JNICALL *CallStaticVoidMethodA)(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args);	/* 143 */
+  jfieldID (JNICALL *GetStaticFieldID)(JNIEnv *env, jclass clazz, const char *name, const char *sig);	/* 144 */
+  jobject (JNICALL *GetStaticObjectField)(JNIEnv *env, jclass clazz, jfieldID fieldID);	/* 145 */
+  jboolean (JNICALL *GetStaticBooleanField)(JNIEnv *env, jclass clazz, jfieldID fieldID);	/* 146 */
+  jbyte (JNICALL *GetStaticByteField)(JNIEnv *env, jclass clazz, jfieldID fieldID);	/* 147 */
+  jchar (JNICALL *GetStaticCharField)(JNIEnv *env, jclass clazz, jfieldID fieldID);	/* 148 */
+  jshort (JNICALL *GetStaticShortField)(JNIEnv *env, jclass clazz, jfieldID fieldID);	/* 149 */
+  jint (JNICALL *GetStaticIntField)(JNIEnv *env, jclass clazz, jfieldID fieldID);	/* 150 */
+  jlong (JNICALL *GetStaticLongField)(JNIEnv *env, jclass clazz, jfieldID fieldID);	/* 151 */
+  jfloat (JNICALL *GetStaticFloatField)(JNIEnv *env, jclass clazz, jfieldID fieldID);	/* 152 */
+  jdouble (JNICALL *GetStaticDoubleField)(JNIEnv *env, jclass clazz, jfieldID fieldID);	/* 153 */
+  void (JNICALL *SetStaticObjectField)(JNIEnv *env, jclass clazz, jfieldID fieldID, jobject value);	/* 154 */
+  void (JNICALL *SetStaticBooleanField)(JNIEnv *env, jclass clazz, jfieldID fieldID, jboolean value);	/* 155 */
+  void (JNICALL *SetStaticByteField)(JNIEnv *env, jclass clazz, jfieldID fieldID, jbyte value);	/* 156 */
+  void (JNICALL *SetStaticCharField)(JNIEnv *env, jclass clazz, jfieldID fieldID, jchar value);	/* 157 */
+  void (JNICALL *SetStaticShortField)(JNIEnv *env, jclass clazz, jfieldID fieldID, jshort value);	/* 158 */
+  void (JNICALL *SetStaticIntField)(JNIEnv *env, jclass clazz, jfieldID fieldID, jint value);	/* 159 */
+  void (JNICALL *SetStaticLongField)(JNIEnv *env, jclass clazz, jfieldID fieldID, jlong value);	/* 160 */
+  void (JNICALL *SetStaticFloatField)(JNIEnv *env, jclass clazz, jfieldID fieldID, jfloat value);	/* 161 */
+  void (JNICALL *SetStaticDoubleField)(JNIEnv *env, jclass clazz, jfieldID fieldID, jdouble value);	/* 162 */
+  jstring (JNICALL *NewString)(JNIEnv *env, const jchar *uChars, jsize len);	/* 163 */
+  jsize (JNICALL *GetStringLength)(JNIEnv *env, jstring string);	/* 164 */
+  const jchar *(JNICALL *GetStringChars)(JNIEnv *env, jstring string, jboolean *isCopy);	/* 165 */
+  void (JNICALL *ReleaseStringChars)(JNIEnv *env, jstring string, const jchar *chars);	/* 166 */
+  jstring (JNICALL *NewStringUTF)(JNIEnv *env, const char *bytes);	/* 167 */
+  jsize (JNICALL *GetStringUTFLength)(JNIEnv *env, jstring string);	/* 168 */
+  const char *(JNICALL *GetStringUTFChars)(JNIEnv *env, jstring string, jboolean *isCopy);	/* 169 */
+  void (JNICALL *ReleaseStringUTFChars)(JNIEnv *env, jstring string, const char *utf);	/* 170 */
+  jsize (JNICALL *GetArrayLength)(JNIEnv *env, jarray array);	/* 171 */
+  jobjectArray (JNICALL *NewObjectArray)(JNIEnv *env, jsize length, jclass elementType, jobject initialElement);	/* 172 */
+  jobject (JNICALL *GetObjectArrayElement)(JNIEnv *env, jobjectArray array, jsize indx);	/* 173 */
+  void (JNICALL *SetObjectArrayElement)(JNIEnv *env, jobjectArray array, jsize indx, jobject value);	/* 174 */
+  jbooleanArray (JNICALL *NewBooleanArray)(JNIEnv *env, jsize length);	/* 175 */
+  jbyteArray (JNICALL *NewByteArray)(JNIEnv *env, jsize length);	/* 176 */
+  jcharArray (JNICALL *NewCharArray)(JNIEnv *env, jsize length);	/* 177 */
+  jshortArray (JNICALL *NewShortArray)(JNIEnv *env, jsize length);	/* 178 */
+  jintArray (JNICALL *NewIntArray)(JNIEnv *env, jsize length);	/* 179 */
+  jlongArray (JNICALL *NewLongArray)(JNIEnv *env, jsize length);	/* 180 */
+  jfloatArray (JNICALL *NewFloatArray)(JNIEnv *env, jsize length);	/* 181 */
+  jdoubleArray (JNICALL *NewDoubleArray)(JNIEnv *env, jsize length);	/* 182 */
+  jboolean *(JNICALL *GetBooleanArrayElements)(JNIEnv *env, jbooleanArray array, jboolean *isCopy);	/* 183 */
+  jbyte *(JNICALL *GetByteArrayElements)(JNIEnv *env, jbyteArray array, jboolean *isCopy);	/* 184 */
+  jchar *(JNICALL *GetCharArrayElements)(JNIEnv *env, jcharArray array, jboolean *isCopy);	/* 185 */
+  jshort *(JNICALL *GetShortArrayElements)(JNIEnv *env, jshortArray array, jboolean *isCopy);	/* 186 */
+  jint *(JNICALL *GetIntArrayElements)(JNIEnv *env, jintArray array, jboolean *isCopy);	/* 187 */
+  jlong *(JNICALL *GetLongArrayElements)(JNIEnv *env, jlongArray array, jboolean *isCopy);	/* 188 */
+  jfloat *(JNICALL *GetFloatArrayElements)(JNIEnv *env, jfloatArray array, jboolean *isCopy);	/* 189 */
+  jdouble *(JNICALL *GetDoubleArrayElements)(JNIEnv *env, jdoubleArray array, jboolean *isCopy);	/* 190 */
+  void (JNICALL *ReleaseBooleanArrayElements)(JNIEnv *env, jbooleanArray array, jboolean *elems, jint mode);	/* 191 */
+  void (JNICALL *ReleaseByteArrayElements)(JNIEnv *env, jbyteArray array, jbyte *elems, jint mode);	/* 192 */
+  void (JNICALL *ReleaseCharArrayElements)(JNIEnv *env, jcharArray array, jchar *elems, jint mode);	/* 193 */
+  void (JNICALL *ReleaseShortArrayElements)(JNIEnv *env, jshortArray array, jshort *elems, jint mode);	/* 194 */
+  void (JNICALL *ReleaseIntArrayElements)(JNIEnv *env, jintArray array, jint *elems, jint mode);	/* 195 */
+  void (JNICALL *ReleaseLongArrayElements)(JNIEnv *env, jlongArray array, jlong *elems, jint mode);	/* 196 */
+  void (JNICALL *ReleaseFloatArrayElements)(JNIEnv *env, jfloatArray array, jfloat *elems, jint mode);	/* 197 */
+  void (JNICALL *ReleaseDoubleArrayElements)(JNIEnv *env, jdoubleArray array, jdouble *elems, jint mode);	/* 198 */
+  void (JNICALL *GetBooleanArrayRegion)(JNIEnv *env, jbooleanArray array, jsize start, jsize len, jboolean *buf);	/* 199 */
+  void (JNICALL *GetByteArrayRegion)(JNIEnv *env, jbyteArray array, jsize start, jsize len, jbyte *buf);	/* 200 */
+  void (JNICALL *GetCharArrayRegion)(JNIEnv *env, jcharArray array, jsize start, jsize len, jchar *buf);	/* 201 */
+  void (JNICALL *GetShortArrayRegion)(JNIEnv *env, jshortArray array, jsize start, jsize len, jshort *buf);	/* 202 */
+  void (JNICALL *GetIntArrayRegion)(JNIEnv *env, jintArray array, jsize start, jsize len, jint *buf);	/* 203 */
+  void (JNICALL *GetLongArrayRegion)(JNIEnv *env, jlongArray array, jsize start, jsize len, jlong *buf);	/* 204 */
+  void (JNICALL *GetFloatArrayRegion)(JNIEnv *env, jfloatArray array, jsize start, jsize len, jfloat *buf);	/* 205 */
+  void (JNICALL *GetDoubleArrayRegion)(JNIEnv *env, jdoubleArray array, jsize start, jsize len, jdouble *buf);	/* 206 */
+  void (JNICALL *SetBooleanArrayRegion)(JNIEnv *env, jbooleanArray array, jsize start, jsize len, const jboolean *buf);	/* 207 */
+  void (JNICALL *SetByteArrayRegion)(JNIEnv *env, jbyteArray array, jsize start, jsize len, const jbyte *buf);	/* 208 */
+  void (JNICALL *SetCharArrayRegion)(JNIEnv *env, jcharArray array, jsize start, jsize len, const jchar *buf);	/* 209 */
+  void (JNICALL *SetShortArrayRegion)(JNIEnv *env, jshortArray array, jsize start, jsize len, const jshort *buf);	/* 210 */
+  void (JNICALL *SetIntArrayRegion)(JNIEnv *env, jintArray array, jsize start, jsize len, const jint *buf);	/* 211 */
+  void (JNICALL *SetLongArrayRegion)(JNIEnv *env, jlongArray array, jsize start, jsize len, const jlong *buf);	/* 212 */
+  void (JNICALL *SetFloatArrayRegion)(JNIEnv *env, jfloatArray array, jsize start, jsize len, const jfloat *buf);	/* 213 */
+  void (JNICALL *SetDoubleArrayRegion)(JNIEnv *env, jdoubleArray array, jsize start, jsize len, const jdouble *buf);	/* 214 */
+  jint (JNICALL *RegisterNatives)(JNIEnv *env, jclass clazz, const JNINativeMethod *methods, jint nMethods);	/* 215 */
+  jint (JNICALL *UnregisterNatives)(JNIEnv *env, jclass clazz);	/* 216 */
+  jint (JNICALL *MonitorEnter)(JNIEnv *env, jobject obj);	/* 217 */
+  jint (JNICALL *MonitorExit)(JNIEnv *env, jobject obj);	/* 218 */
+  jint (JNICALL *GetJavaVM)(JNIEnv *env, JavaVM **vm);	/* 219 */
+  void (JNICALL *GetStringRegion)(JNIEnv *env, jstring str, jsize start, jsize len, jchar *buf);	/* 220 */
+  void (JNICALL *GetStringUTFRegion)(JNIEnv *env, jstring str, jsize start, jsize len, char *buf);	/* 221 */
+  void *(JNICALL *GetPrimitiveArrayCritical)(JNIEnv *env, jarray array, jboolean *isCopy);	/* 222 */
+  void (JNICALL *ReleasePrimitiveArrayCritical)(JNIEnv *env, jarray array, void *carray, jint mode);	/* 223 */
+  const jchar *(JNICALL *GetStringCritical)(JNIEnv *env, jstring string, jboolean *isCopy);	/* 224 */
+  void (JNICALL *ReleaseStringCritical)(JNIEnv *env, jstring string, const jchar *carray);	/* 225 */
+  jweak (JNICALL *NewWeakGlobalRef)(JNIEnv *env, jobject obj);	/* 226 */
+  void (JNICALL *DeleteWeakGlobalRef)(JNIEnv *env, jweak wref);	/* 227 */
+  jboolean (JNICALL *ExceptionCheck)(JNIEnv *env);	/* 228 */
+  jobject (JNICALL *NewDirectByteBuffer)(JNIEnv *env, void *address, jlong capacity);	/* 229 */
+  void *(JNICALL *GetDirectBufferAddress)(JNIEnv *env, jobject buf);	/* 230 */
+  jlong (JNICALL *GetDirectBufferCapacity)(JNIEnv *env, jobject buf);	/* 231 */
+};
+
+struct JNIInvokeInterface {
+  void *null_0;
+  void *null_1;
+  void *null_2;
+  jint (JNICALL *DestroyJavaVM)(JavaVM *vm);	/* 3 */
+  jint (JNICALL *AttachCurrentThread)(JavaVM *vm, void **penv, void *args);	/* 4 */
+  jint (JNICALL *DetachCurrentThread)(JavaVM *vm);	/* 5 */
+  jint (JNICALL *GetEnv)(JavaVM *vm, void **penv, jint interface_id);	/* 6 */
+  jint (JNICALL *AttachCurrentThreadAsDaemon)(JavaVM *vm, void **penv, void *args);	/* 7 */
+};
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/************************************************************************
+ *				Functions				*
+ ************************************************************************/
+
+/* JNI invocation API */
+JNIEXPORT jint JNICALL JNI_GetDefaultJavaVMInitArgs(void *vm_args);
+JNIEXPORT jint JNICALL JNI_GetCreatedJavaVMs(JavaVM **vmBuf,
+	jsize bufLen, jsize *nVMs);
+JNIEXPORT jint JNICALL JNI_CreateJavaVM(JavaVM **pvm,
+	void **penv, void *vm_args);
+
+/* Library and version management */
+JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved);
+JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif	/* _JNI_H_ */

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/include/jni_machdep.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/include/jni_machdep.h?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/include/jni_machdep.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/include/jni_machdep.h Tue Oct  4 19:19:16 2005
@@ -0,0 +1,43 @@
+
+/*
+ * 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: jni_machdep.h,v 1.1.1.1 2004/02/20 05:15:11 archiecobbs Exp $
+ */
+
+#ifndef _JNI_MACHDEP_H_
+#define _JNI_MACHDEP_H_
+
+/*
+ * Goal: define JNI C typedefs for Java primitive types.
+ */
+
+#if (defined (__ia64__) || defined (__alpha__) || defined (__i386__) || defined(__sparc__))
+
+typedef	unsigned char	jboolean;
+typedef	signed char	jbyte;
+typedef	unsigned short	jchar;
+typedef	signed short	jshort;
+typedef	signed int	jint;
+typedef	long long	jlong;
+typedef float		jfloat;
+typedef double		jdouble;
+
+#else
+#error "Unsupported architecture"
+#endif
+
+#endif	/* _JNI_MACHDEP_H_ */

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/Makefile.am
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/Makefile.am?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/Makefile.am (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/Makefile.am Tue Oct  4 19:19:16 2005
@@ -0,0 +1,44 @@
+## $Id: Makefile.am,v 1.9 2005/03/16 15:30:40 archiecobbs Exp $
+
+jcdir=		$(datadir)/jc
+apidir=		$(jcdir)/doc/api
+
+jc_DATA=	jc.zip
+
+sootdir=	$(top_srcdir)/soot
+
+CLASSPATH=	$(CLASSPATH_HOME)/share/classpath/glibj.zip:$(sootdir)/sootclasses-@SOOT_VERSION@.jar:$(sootdir)/jasminclasses-sable-@JASMIN_VERSION@.jar:$(sootdir)/polyglot-@POLYGLOT_VERSION@.jar
+
+JCOMPILE=	$(JIKES) -nowarn +F -bootclasspath '' -extdirs '' -sourcepath '' -classpath $(srcdir):$(CLASSPATH) -d classes
+
+SUBDIRS=	gnu java org
+
+EXTRA_DIST=	api.tgz jc.zip
+
+install-data-local:	api.tgz
+	$(mkinstalldirs) $(DESTDIR)$(apidir)
+	$(TAR) xzf $(srcdir)/api.tgz -C $(DESTDIR)$(apidir)
+
+uninstall-local:
+	rm -rf $(DESTDIR)$(apidir)
+
+jc.zip:
+	rm -rf classes
+	mkdir classes
+	$(JCOMPILE) `find $(srcdir) -name '*.java'`
+	( cd classes && $(ZIP) -qD -r ../jc.zip \
+	    `find $(SUBDIRS) -name '*.class'`)
+	rm -rf classes
+
+JDOC_TITLE=	"JC Virtual Machine"
+JDOC_FLAGS=	-classpath $(CLASSPATH) -sourcepath $(srcdir) -d api -doctitle $(JDOC_TITLE) -windowtitle $(JDOC_TITLE) -breakiterator -link http://java.sun.com/j2se/1.4.2/docs/api -link http://www.sable.mcgill.ca/soot/doc/
+
+api.tgz:
+	rm -rf api
+	mkdir api
+	$(JAVADOC) $(JDOC_FLAGS) org.dellroad.jc org.dellroad.jc.cgen \
+	    org.dellroad.jc.vm org.dellroad.jc.cgen.analysis \
+	    org.dellroad.jc.cgen.escape
+	( cd api && $(TAR) czf ../api.tgz * )
+	rm -rf api
+

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/Makefile.am
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/Makefile.am?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/Makefile.am (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/Makefile.am Tue Oct  4 19:19:16 2005
@@ -0,0 +1,4 @@
+## $Id: Makefile.am,v 1.1.1.1 2004/02/20 05:15:19 archiecobbs Exp $
+
+SUBDIRS=	dellroad
+

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/Makefile.am
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/Makefile.am?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/Makefile.am (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/Makefile.am Tue Oct  4 19:19:16 2005
@@ -0,0 +1,4 @@
+## $Id: Makefile.am,v 1.1.1.1 2004/02/20 05:15:19 archiecobbs Exp $
+
+SUBDIRS=	jc
+

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/BootstrapObjectGenerator.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/BootstrapObjectGenerator.java?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/BootstrapObjectGenerator.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/BootstrapObjectGenerator.java Tue Oct  4 19:19:16 2005
@@ -0,0 +1,453 @@
+
+//
+// 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: BootstrapObjectGenerator.java,v 1.8 2004/12/27 16:04:33 archiecobbs Exp $
+//
+
+package org.dellroad.jc;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipException;
+import java.util.zip.ZipFile;
+import org.dellroad.jc.cgen.JCObjectGenerator;
+import org.dellroad.jc.cgen.SootCodeGenerator;
+
+/**
+ * Used to pre-generate ELF object files for classes that JC itself uses
+ * to generate ELF object files. This class is meant to be executed
+ * as a separate process, typically using a JVM other than JC.
+ */
+public class BootstrapObjectGenerator {
+
+	private final ObjectGenerator generator;
+	private final SearchpathMatcher[] matchers;
+	private final SearchpathFinder finder;
+	private final HashSet generated = new HashSet();
+	private final boolean verbose;
+	private final boolean force;
+	private File objectDir;
+
+	static abstract class SearchpathMatcher {
+		private final String name;
+		public SearchpathMatcher(String name) {
+			this.name = name;
+		}
+		public String toString() {
+			return name;
+		}
+		public String[] getMatches(String pattern) {
+
+			// Parse pattern
+			pattern = pattern.replace('.', '/');
+			final int plen = pattern.length();
+			if (plen == 0)
+				return new String[0];
+			String prefix;
+			int looseness;
+			if (pattern.charAt(plen - 1) != '%') {
+				looseness = 0;
+				prefix = pattern;
+			} else if (plen < 2
+			    || pattern.charAt(plen - 2) != '%') {
+				looseness = 1;
+				prefix = pattern.substring(0, plen - 1);
+			} else {
+				looseness = 2;
+				prefix = pattern.substring(0, plen - 2);
+			}
+
+			// Return matches
+			while (prefix.endsWith("/")) {
+				prefix = prefix.substring(0,
+				    prefix.length() - 1);
+			}
+			Set matches = getMatches(prefix, looseness);
+			String[] array = (String[])matches.toArray(
+			    new String[matches.size()]);
+			Arrays.sort(array);
+			return array;
+		}
+		public boolean isMatch(String name,
+		    String prefix, int looseness) {
+			int plen = prefix.length();
+			switch (looseness) {
+			case 0:
+				if (!name.equals(prefix))
+					return false;
+				break;
+			case 1:
+				if (name.lastIndexOf('/') > plen)
+					return false;
+				// FALLTHROUGH
+			case 2:
+				if (name.length() < plen + 2
+				    || !name.startsWith(prefix))
+					return false;
+				if (name.charAt(plen) != '/')
+					return false;
+				break;
+			}
+			return true;
+		}
+
+		public abstract Set getMatches(String prefix, int looseness);
+	}
+
+	static class DirMatcher extends SearchpathMatcher {
+		private final File topDir;
+		public DirMatcher(File topDir) throws IOException {
+			super(topDir.toString());
+			if (!topDir.isDirectory()) {
+				throw new IOException("`" + topDir
+				    + "' is not a directory");
+			}
+			this.topDir = topDir;
+		}
+		public Set getMatches(String prefix, int looseness) {
+			if (looseness == 0) {
+				if (prefix.length() == 0)
+					return Collections.EMPTY_SET;
+				File file = new File(topDir, prefix + ".class");
+				if (file.isFile())
+					return Collections.singleton(prefix);
+				return Collections.EMPTY_SET;
+			}
+			File dir = prefix.length() == 0 ?
+			    topDir : new File(topDir, prefix);
+			if (!dir.isDirectory())
+				return Collections.EMPTY_SET;
+			HashSet set = new HashSet();
+			addFiles(dir, prefix, looseness == 2, set);
+			return set;
+		}
+		private void addFiles(File dir, String prefix,
+		    boolean subpackages, Set set) {
+			String[] files = dir.list();
+			if (files == null)
+				return;
+			for (int i = 0; i < files.length; i++) {
+				String name = files[i];
+				File file = new File(dir, name);
+				String prefixName = (prefix.length() == 0) ?
+				    name : prefix + "/" + name;
+				if (file.isFile()) {
+					if (!name.endsWith(".class"))
+						continue;
+					prefixName = prefixName.substring(
+					    0, prefixName.length() - 6);
+					set.add(prefixName);
+					continue;
+				}
+				if (file.isDirectory() && subpackages)
+					addFiles(file, prefixName, true, set);
+			}
+		}
+	}
+
+	static class ZipMatcher extends SearchpathMatcher {
+		private final ZipFile zfile;
+		public ZipMatcher(File zip) throws ZipException, IOException {
+			super(zip.toString());
+			this.zfile = new ZipFile(zip);
+		}
+		public Set getMatches(String prefix, int looseness) {
+			HashSet set = new HashSet();
+			final Enumeration e = zfile.entries();
+			if (e == null)		// Classpath bug workaround
+				return Collections.EMPTY_SET;
+			while (e.hasMoreElements()) {
+			    	ZipEntry entry = (ZipEntry)e.nextElement();
+				String name = entry.getName();
+				if (!name.endsWith(".class"))
+					continue;
+				name = name.substring(0, name.length() - 6);
+				if (isMatch(name, prefix, looseness))
+					set.add(name);
+			}
+			return set;
+		}
+		protected void finalize() throws Throwable {
+			try {
+				zfile.close();
+			} catch (IOException e) {
+			}
+			super.finalize();
+		}
+	}
+
+	private BootstrapObjectGenerator(String classpath, String srcpath,
+	    String objdir, boolean force, boolean verbose,
+	    boolean includeLineNumbers, boolean sourcesOnly) {
+
+		// Initialize instance fields
+		this.generator = new JCObjectGenerator(
+		    new SootCodeGenerator(null, null, includeLineNumbers),
+		    srcpath, verbose, includeLineNumbers, sourcesOnly, force);
+		this.objectDir = new File(
+		    SearchpathFinder.splitPath(objdir)[0]);
+		this.finder = new SearchpathFinder(classpath);
+		this.verbose = verbose;
+		this.force = force;
+
+		// Create matcher for each classpath component
+		String[] cpath = SearchpathFinder.splitPath(classpath);
+		ArrayList list = new ArrayList();
+		for (int i = 0; i < cpath.length; i++) {
+			String entry = cpath[i];
+			try {
+				File file = new File(entry);
+				list.add(file.isDirectory() ?
+				    (SearchpathMatcher)new DirMatcher(file) :
+				    (SearchpathMatcher)new ZipMatcher(file));
+			} catch (ZipException e) {
+			} catch (IOException e) {
+			}
+		}
+		matchers = (SearchpathMatcher[])list
+		    .toArray(new SearchpathMatcher[list.size()]);
+	}
+
+	private void generateMatches(String pattern) throws Exception {
+		boolean single = !pattern.endsWith("%");
+		boolean found = false;
+		for (int i = 0; i < matchers.length; i++) {
+			SearchpathMatcher matcher = matchers[i];
+			String[] matches = matcher.getMatches(pattern);
+			for (int j = 0; j < matches.length; j++) {
+				generate(matches[j]);
+				if (single) {
+					found = true;
+					break;
+				}
+			}
+		}
+		if (single && !found)
+			System.err.println("class `" + pattern + "' not found");
+	}
+
+	private void generate(String className) throws Exception {
+
+		// Get slashed name
+		className = className.replace('.', '/');
+		File ofile = Generate.objectFile(className, objectDir);
+
+		// Don't generate twice (e.g., if a class file appears
+		// twice in the class path)
+		if (generated.contains(className))
+			return;
+		generated.add(className);
+
+		// Check if object file is already there
+		if (!force
+		    && generator.objectIsValid(className, finder, ofile)) {
+			if (verbose) {
+				System.out.println("`" + className
+				    + "' is up to date");
+			}
+			return;
+		}
+
+		// Generate object
+		generator.generateObject(className, finder, ofile);
+	}
+
+	/**
+	 * Generate JC ELF object files for one or more classes. This class
+	 * is intended for use in two cases:
+	 *
+	 * <ul>
+	 * <li>When JC must generate ELF object files that are themselves
+	 *	used to generate ELF object files, it must bootstrap generate
+	 *	them by invoking this class in another Java virtual machine
+	 *	as a separate process.
+	 * <li>When it is desirable to pre-generate ELF objects (instead of
+	 *	having them created on demand during the execution of the JC
+	 *	virtual machine) to avoid runtime delays or to obviate then
+	 *	need for the GCC compiler.
+	 * </ul>
+	 *
+	 * <p>
+	 * Usage:
+	 * <blockquote>
+	 * <code>java org.dellroad.jc.BootstrapObjectGenerator [-classpath dir1:dir2:...]
+	 * [-srcpath dir1:dir2:...] [-objdir objdir] [-incdir dir] [-f] [-g] [-N] pattern ...</code>
+	 * </blockquote>
+	 * </p>
+	 *
+	 * <p>
+	 * ELF objects are (re)generated for all classes found in the
+	 * classpath specified by <code>-classpath</code> (or the
+	 * <code>java.class.path</code> system property if no
+	 * <code>-classpath</code> flag is given) that match any of the
+	 * given <code>pattern</code>s. A pattern is either a class name,
+	 * or a package name followed by a period and then one or two
+	 * asterisks.  One asterisk matches all classes in the package,
+	 * two matches all classes in the package and all subpackages. For
+	 * example, <code>java.util.List</code>, <code>java.util.*</code>,
+	 * and <code>java.util.**</code>. Slashes may be used instead of
+	 * periods and percent signs may be used instead of asterisks.
+	 * </p>
+	 * <p>
+	 * Objects stored in the directory hierarchy whose root is specified
+	 * by <code>-objdir</code> flag (default current working directory).
+	 * As a convenience feature, if <code>-objdir</code> specifies a
+	 * search path, the first directory in the path is used.
+	 * Intermediate C source and header files are searched for
+	 * in the search path specified by <code>-srcpath</code> and
+	 * those newly created (as necessary) are stored under the
+	 * first component directory of <code>-srcpath</code>. If no
+	 * <code>-srcpath</code> is given, &quot;.&quot; is assumed.
+	 * <code>-incdir</code> tells where the JC include files live.
+	 * </p>
+	 * <p>
+	 * If the <code>-f</code> flag is given, then all ELF object files
+	 * are regenerated even if a seemingly valid ELF file already exists.
+	 * </p>
+	 * <p>
+	 * If the <code>-g</code> flag is given, then support for Java
+	 * source code line numbers in stack traces is included.
+	 * </p>
+	 * <p>
+	 * If the <code>-N</code> flag is given, only the source files are
+	 * generated; C compilation is not done and no ELF objects are created.
+	 * </p>
+	 * <p>
+	 * The <code>jc.verbose.gen</code> system property, if equal to
+	 * <code>true</code>, enables progress reports to standard output.
+	 * Set via the <code>-Djc.verbose.gen=true</code> VM command line flag.
+	 * </p>
+	 * <p>
+	 * This class uses the {@link JCObjectGenerator JCObjectGenerator}
+	 * class to generate ELF objects.
+	 * </p>
+	 *
+	 * @see JCObjectGenerator JCObjectGenerator
+	 */
+	public static void main(String args[]) {
+		try {
+			doMain(args);
+		} catch (Throwable t) {
+			t.printStackTrace();
+			System.exit(1);
+		}
+	}
+
+	private static void doMain(String args[]) throws Exception {
+
+		String classpath = null;
+		String objdir = ".";
+		String srcpath = ".";
+		String incdir = "/usr/local/jc/include";
+		boolean badUsage = false;
+		boolean force = false;
+		boolean includeLineNumbers = Boolean.getBoolean(
+		    "jc.include.line.numbers");
+		boolean sourcesOnly = false;
+		int argi;
+
+		// Parse command line
+		for (argi = 0; argi < args.length; argi++) {
+			String arg = args[argi];
+			if (arg.length() < 1 || arg.charAt(0) != '-')
+				break;
+			if (arg.equals("-classpath")) {
+				if (++argi >= args.length) {
+					badUsage = true;
+					break;
+				}
+				classpath = args[argi];
+			} else if (arg.equals("-srcpath")) {
+				if (++argi >= args.length) {
+					badUsage = true;
+					break;
+				}
+				srcpath = args[argi];
+			} else if (arg.equals("-objdir")) {
+				if (++argi >= args.length) {
+					badUsage = true;
+					break;
+				}
+				objdir = args[argi];
+			} else if (arg.equals("-incdir")) {
+				if (++argi >= args.length) {
+					badUsage = true;
+					break;
+				}
+				incdir = args[argi];
+			} else if (arg.equals("-f")) {
+				force = true;
+			} else if (arg.equals("-g")) {
+				includeLineNumbers = true;
+			} else if (arg.equals("-N")) {
+				sourcesOnly = true;
+			} else {
+				System.err.println("unknown flag ``"
+				    + arg + "''");
+				badUsage = true;
+				break;
+			}
+		}
+		if (argi == args.length)
+			badUsage = true;
+		if (badUsage) {
+			String cname = BootstrapObjectGenerator.class.getName();
+			System.err.println("usage:\tjava " + cname
+			    + " [-classpat dir1:dir2:...]");
+			System.err.println("\t[-srcpath dir1:dir2:...]"
+			    + " [-objdir objdir] [-incdir dir] [-f] [-g] [-N]"
+			    + " pattern ...");
+			System.exit(1);
+		}
+
+		// Fall back to system class path
+		if (classpath == null)
+			classpath = System.getProperty("java.class.path");
+
+		// Set required JC properties if not already set
+		String[][] defaults = {
+		    { "jc.gnu.compiler",	"gcc" },
+		    { "jc.include.dir",		incdir },
+		};
+		for (int i = 0; i < defaults.length; i++) {
+			String name = defaults[i][0];
+			String value = defaults[i][1];
+			if (System.getProperty(name) == null)
+				System.setProperty(name, value);
+		}
+
+		// Create bootstrap generator
+		BootstrapObjectGenerator bgen = new BootstrapObjectGenerator(
+		    classpath, srcpath, objdir, force,
+		    Boolean.getBoolean("jc.verbose.gen"), includeLineNumbers,
+		    sourcesOnly);
+
+		// Generate objects
+		while (argi < args.length)
+			bgen.generateMatches(args[argi++].replace('*', '%'));
+	}
+}
+

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/ClassfileFinder.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/ClassfileFinder.java?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/ClassfileFinder.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/ClassfileFinder.java Tue Oct  4 19:19:16 2005
@@ -0,0 +1,50 @@
+
+//
+// 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: ClassfileFinder.java,v 1.1.1.1 2004/02/20 05:15:19 archiecobbs Exp $
+//
+
+package org.dellroad.jc;
+
+/**
+ * Represents objects capable of retrieving class files.
+ */
+public interface ClassfileFinder {
+
+	/**
+	 * Retrieve the class file that is used to define the named class.
+	 * This is a capability specific to the JC virtual machine.
+	 *
+	 * @param className Class name (with slashes, not dots)
+	 * @throws ClassNotFoundException if class is not found
+	 */
+	public byte[] getClassfile(String className)
+		throws ClassNotFoundException;
+
+	/**
+	 * Return the hash of the bytes that would be returned by
+	 * {@link #getClassfile getClassfile()} with the same arguments.
+	 * The hash of a class file is defined as the last 16 bytes
+	 * of the MD5 of the class file.
+	 *
+	 * @param className Class name (with slashes, not dots)
+	 * @throws ClassNotFoundException if class is not found
+	 */
+	public long getClassfileHash(String className)
+		throws ClassNotFoundException;
+}
+

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/Generate.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/Generate.java?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/Generate.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/Generate.java Tue Oct  4 19:19:16 2005
@@ -0,0 +1,258 @@
+
+//
+// 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: Generate.java,v 1.2 2005/07/04 19:56:16 archiecobbs Exp $
+//
+
+package org.dellroad.jc;
+
+import java.io.File;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.security.DigestInputStream;
+import java.security.MessageDigest;
+import org.dellroad.jc.cgen.Util;
+
+/**
+ * Singleton class used as the starting point for object file generation.
+ * The JC virtual machine will invoke {@link #generateObject generateObject()}
+ * on the singleton instance when it needs to create a new ELF object file.
+ *
+ * <p>
+ * The object file is actually generated by whatever {@link ObjectGenerator}
+ * is specified by the <code>jc.object.generator</code> system property.
+ * By default, a
+ * {@link org.dellroad.jc.cgen.JCObjectGenerator JCObjectGenerator} is used.
+ */
+public final class Generate {
+
+	// Singleton instance
+	private static Generate instance;
+
+	// Directory for newly created object files
+	private static final String objectDir = SearchpathFinder.splitPath(
+	    System.getProperty("jc.object.path", "."))[0];
+
+	/**
+	 * The system-dependent character used to separate directory
+	 * names in a path name.
+	 */
+	public static final char FILE_SEPARATOR
+	    = System.getProperty("file.separator").charAt(0);
+
+	/**
+	 * The system-dependent character used to separate individual
+	 * paths in a search path.
+	 */
+	public static final char PATH_SEPARATOR
+	    = System.getProperty("path.separator").charAt(0);
+
+	// Class that generates object files
+	private final ObjectGenerator generator;
+
+	private Generate() {
+
+		// Get object file generator
+		try {
+			this.generator = (ObjectGenerator)Class.forName(
+			    System.getProperty("jc.object.generator"))
+			      .newInstance();
+		} catch (Exception e) {
+			throw new RuntimeException(e);
+		}
+	}
+
+	/**
+	 * Retrieve the singleton instance of this class.
+	 */
+	public static synchronized Generate v() {
+		if (instance == null)
+			instance = new Generate();
+		return instance;
+	}
+
+	/**
+	 * Generate the ELF object file for the named class. The object
+	 * file is written into the first directory in the search path
+	 * specified by the <code>jc.object.path</code> system property.
+	 *
+	 * @param className	name of class (with slashes not dots).
+	 * @param loader	class loader used to acquire the class file
+	 * @see #objectFile objectFile()
+	 */
+	public void generateObject(String className, ClassLoader loader)
+	    throws Exception {
+		generator.generateObject(className,
+		    new JCFinder(loader), objectFile(className));
+	}
+
+	/**
+	 * Return the file that contains the ELF object for the class.
+	 * This will be a filename under the first directory in the search
+	 * path specified by the <code>jc.object.path</code> system property.
+	 */
+	public static File objectFile(String className) {
+		return objectFile(className, new File(objectDir));
+	}
+
+	/**
+	 * Return the file that contains the ELF object for the class,
+	 * given that <code>dir</code> is the root of the object directory
+	 * hierarchy.
+	 *
+	 * <p>
+	 * This method does not depend on the <code>jc.object.path</code>
+	 * and therefore may be used when running under other Java VM's.
+	 */
+	public static File objectFile(String className, File dir) {
+		return new File(dir,
+		    encode(className, true).replace('/', FILE_SEPARATOR)
+		    + ".o");
+	}
+
+	/**
+	 * Return the "JC hash" of some bytes. This is defined to be
+	 * the last 8 bytes of the MD5 of the input, interpreted as
+	 * a big-endian Java long value.
+	 */
+	public static long hash(InputStream s) {
+		try {
+			DigestInputStream dis = new DigestInputStream(
+			    s, MessageDigest.getInstance("MD5"));
+			byte[] buf = new byte[100];
+			while (dis.read(buf, 0, buf.length) != -1);
+			byte[] hash = dis.getMessageDigest().digest();
+			return ((long)(hash[hash.length - 8] & 0xff) << 56)
+			     | ((long)(hash[hash.length - 7] & 0xff) << 48)
+			     | ((long)(hash[hash.length - 6] & 0xff) << 40)
+			     | ((long)(hash[hash.length - 5] & 0xff) << 32)
+			     | ((long)(hash[hash.length - 4] & 0xff) << 24)
+			     | ((long)(hash[hash.length - 3] & 0xff) << 16)
+			     | ((long)(hash[hash.length - 2] & 0xff) <<  8)
+			     | ((long)(hash[hash.length - 1] & 0xff)      );
+		} catch (Exception e) {
+			throw new RuntimeException(e.toString());
+		}
+	}
+
+	/**
+	 * Equivalent to <code>encode(name, false)</code>.
+	 */
+	public static String encode(String name) {
+		return encode(name, false);
+	}
+
+	/**
+	 * Encode a name so that it uses only "safe" 7-bit characters
+	 * so that it's suitable for use as a file name. First the string
+	 * is UTF-8 encoded, then slashes become underscores and all other
+	 * non alphanumeric characters (UTF-8 bytes really) become two
+	 * underscores followed by two hex digits.
+	 *
+	 * @param name Class name
+	 * @param ignoreSlashes whether to pass slash characters through
+	 *	unencoded or convert them to underscores.
+	 */
+	public static String encode(String name, boolean ignoreSlashes) {
+		StringBuffer b = new StringBuffer(name.length() + 15);
+		byte[] utf = Util.utf8Encode(name);
+		for (int i = 0; i < utf.length; i++) {
+			int ch = utf[i] & 0xff;
+
+			// Should we pass through '/' characters?
+			if (ch == '/' && ignoreSlashes) {
+				b.append((char)ch);
+				continue;
+			}
+
+			// Alphanumerics pass through normally
+			if ((ch >= '0' && ch <= '9')
+			    || (ch >= 'A' && ch <= 'Z')
+			    || (ch >= 'a' && ch <= 'z')) {
+				b.append((char)ch);
+				continue;
+			}
+
+			// Dot converts to underscore
+			if (ch == '.') {
+				b.append('_');
+				continue;
+			}
+
+			// Escape everything else with two underscores + hex
+			b.append("__");
+			b.append(Integer.toHexString(ch >> 4));
+			b.append(Integer.toHexString(ch & 0x0f));
+		}
+		return b.toString();
+	}
+
+	/**
+	 * Reverse of {@link #encode}.
+	 *
+	 * @throws IllegalArgumentException
+	 *	if <code>s</code> is not validly encoded.
+	 */
+	public static String decode(String s) {
+
+		// Decode bytes
+		byte[] buf = new byte[s.length()];
+		int blen = 0;
+		for (int i = 0; i < s.length(); ) {
+			char ch = s.charAt(i++);
+			int val;
+			int j;
+
+			// Handle unescaped characters
+			if ((ch >= '0' && ch <= '9')
+			    || (ch >= 'A' && ch <= 'Z')
+			    || (ch >= 'a' && ch <= 'z')
+			    || ch == '/') {
+				buf[blen++] = (byte)ch;
+				continue;
+			}
+
+			// Must be an underscore
+			if (ch != '_')
+				throw new IllegalArgumentException(s);
+
+			// Look for two in a row, then two hex digits
+			int n1, n2;
+			if (i + 2 < s.length()
+			    && s.charAt(i) == '_'
+			    && (n1 = Character.digit(
+			      s.charAt(i + 1), 16)) != -1
+			    && (n2 = Character.digit(
+			      s.charAt(i + 2), 16)) != -1) {
+				i += 3;
+				buf[blen++] = (byte)((n1 << 4) | n2);
+				continue;
+			}
+
+			// Just a slash
+			buf[blen++] = (byte)'/';
+		}
+
+		// Convert bytes from UTF-8 back into a String
+		try {
+			return new String(buf, 0, blen, "UTF8");
+		} catch (UnsupportedEncodingException e) {
+			throw new IllegalArgumentException(e.toString());
+		}
+	}
+}
+

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/JCFinder.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/JCFinder.java?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/JCFinder.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/JCFinder.java Tue Oct  4 19:19:16 2005
@@ -0,0 +1,62 @@
+
+//
+// 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: JCFinder.java,v 1.1.1.1 2004/02/20 05:15:19 archiecobbs Exp $
+//
+
+package org.dellroad.jc;
+
+/**
+ * Gateway into the JC virtual machine for retrieving class files.
+ */
+public class JCFinder implements ClassfileFinder {
+
+	private final ClassLoader loader;
+
+	/**
+	 * Create a new finder that uses the given class loader
+	 * to pull in not-before-seen class files as necessary.
+	 */
+	public JCFinder(ClassLoader loader) {
+		this.loader = loader;
+	}
+
+	public byte[] getClassfile(String className)
+	    throws ClassNotFoundException {
+		try {
+			return getClassfile(className, loader);
+		} catch (NoClassDefFoundError e) {
+			throw new ClassNotFoundException(e.getMessage());
+		}
+	}
+
+	public long getClassfileHash(String className)
+	    throws ClassNotFoundException {
+		try {
+			return getClassfileHash(className, loader);
+		} catch (NoClassDefFoundError e) {
+			throw new ClassNotFoundException(e.getMessage());
+		}
+	}
+
+	private static native byte[] getClassfile(String className,
+	    ClassLoader loader);
+
+	private static native long getClassfileHash(String className,
+	    ClassLoader loader);
+}
+

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/Makefile.am
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/Makefile.am?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/Makefile.am (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/Makefile.am Tue Oct  4 19:19:16 2005
@@ -0,0 +1,12 @@
+## $Id: Makefile.am,v 1.1.1.1 2004/02/20 05:15:19 archiecobbs Exp $
+
+SUBDIRS=	cgen vm
+
+EXTRA_DIST=	BootstrapObjectGenerator.java \
+		ClassfileFinder.java \
+		Generate.java \
+		JCFinder.java \
+		ObjectGenerator.java \
+		SearchpathFinder.java \
+		package.html
+

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/ObjectGenerator.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/ObjectGenerator.java?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/ObjectGenerator.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/ObjectGenerator.java Tue Oct  4 19:19:16 2005
@@ -0,0 +1,54 @@
+
+//
+// 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: ObjectGenerator.java,v 1.1.1.1 2004/02/20 05:15:19 archiecobbs Exp $
+//
+
+package org.dellroad.jc;
+
+import java.io.File;
+
+/**
+ * Interface implemented by classes that generate JC ELF object
+ * files from raw class files.
+ */
+public interface ObjectGenerator {
+
+	/**
+	 * Generate the ELF object file for the named class
+	 * and write it into the file.
+	 *
+	 * @param className Class name (with slashes, not dots)
+	 * @param finder Object capable of retrieving class files
+	 * @param file Where to put resulting ELF object
+	 */
+	public void generateObject(String className,
+	    ClassfileFinder finder, File file) throws Exception;
+
+	/**
+	 * Determine if an ELF object file is valid for the named class
+	 * and all other classes (available through the provided
+	 * <code>finder</code>) on which the object file may depend.
+	 *
+	 * @param className Class name (with slashes, not dots)
+	 * @param finder Class finder capable of retrieving class files
+	 * @param file Where to put resulting ELF object
+	 */
+	public boolean objectIsValid(String className,
+	    ClassfileFinder finder, File file) throws Exception;
+}
+

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/SearchpathFinder.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/SearchpathFinder.java?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/SearchpathFinder.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/SearchpathFinder.java Tue Oct  4 19:19:16 2005
@@ -0,0 +1,203 @@
+
+//
+// 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: SearchpathFinder.java,v 1.1.1.1 2004/02/20 05:15:20 archiecobbs Exp $
+//
+
+package org.dellroad.jc;
+
+import java.util.ArrayList;
+import java.util.zip.ZipFile;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipException;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.ByteArrayInputStream;
+
+/** 
+ * Implementation of {@link ClassfileFinder} used by the
+ * {@link BootstrapObjectGenerator} class for object file generation
+ * when another virtual machine besides JC must be used. This class
+ * simply searches a standard ``classpath'' directory and ZIP/JAR file
+ * search path for class files.
+ */
+public class SearchpathFinder implements ClassfileFinder {
+
+	static final String fs = System.getProperty("file.separator");
+	static final char ps = System.getProperty("path.separator").charAt(0);
+
+	private final String path;
+	private final File[] files;
+	private Object[] cache;
+
+	/**
+	 * Create a finder using the supplied classpath.
+	 *
+	 * @param path Class search path containing directory names
+	 *		and ZIP/JAR file names, for example
+	 *		<code>/some/dir1:/some/dir2:/other/file.zip<code>.
+	 */
+	public SearchpathFinder(String path) {
+		this.path = path;
+		String[] dirs = splitPath(path);
+		files = new File[dirs.length];
+		for (int i = 0; i < dirs.length; i++)
+			files[i] = new File(dirs[i]);
+	}
+
+	/** 
+	 * Returns the constructor's argument.
+	 */
+	public String getPath() {
+		return path;
+	}
+
+	/** 
+	 * Returns the path split out into individual components.
+	 */
+	public File[] getPathArray() {
+		return (File[])files.clone();
+	}
+
+	public byte[] getClassfile(String className)
+	    throws ClassNotFoundException {
+
+		// Load cache
+		if (cache == null)
+			loadCache();
+
+		// Get classfile name
+		String cfile = className.replace('.', '/')
+		    .replace('/', fs.charAt(0)) + ".class";
+
+search:
+		// Search each directory and ZipFile
+		for (int i = 0; i < cache.length; i++) {
+			ZipFile zfile = null;
+			InputStream in = null;
+			byte[] rtn;
+
+			// Try to open and read the file
+			try {
+				if (cache[i] instanceof File) {
+					File dir = (File)cache[i];
+					File file = new File(dir, cfile);
+					if (!file.isFile())
+						continue;
+					rtn = new byte[(int)file.length()];
+					in = new FileInputStream(file);
+				} else if (cache[i] instanceof ZipFile) {
+					zfile = (ZipFile)cache[i];
+					ZipEntry zent = zfile.getEntry(cfile);
+					if (zent == null)
+						continue;
+					rtn = new byte[(int)zent.getSize()];
+					in = zfile.getInputStream(zent);
+				} else
+					continue;
+
+				// Read in data
+				int r;
+				for (int len = 0;
+				    len < rtn.length; len += r) {
+					if ((r = in.read(rtn, len,
+					    rtn.length - len)) == -1)
+						continue search;
+				}
+
+				// Done
+				return rtn;
+			} catch (ZipException e) {
+				continue;
+			} catch (IOException e) {
+				continue;
+			} finally {		// clean up before leaving
+				try {
+					if (in != null)
+						in.close();
+				} catch (IOException e) {
+				}
+			}
+		}
+
+		// Not found
+		throw new ClassNotFoundException("class `"
+		    + className + "' not found");
+	}
+
+	private synchronized void loadCache() {
+		if (cache != null)
+			return;
+		cache = new Object[files.length];
+		for (int i = 0; i < files.length; i++) {
+			if (files[i].isDirectory())
+				cache[i] = files[i];
+			else if (files[i].isFile()) {
+				try {
+					cache[i] = new ZipFile(files[i]);
+				} catch (ZipException e) {
+					continue;
+				} catch (IOException e) {
+					continue;
+				}
+			}
+		}
+	}
+
+	public long getClassfileHash(String className)
+	    throws ClassNotFoundException {
+		return Generate.hash(new ByteArrayInputStream(
+		    getClassfile(className)));
+	}
+
+	protected void finalize() {
+		if (cache == null)
+			return;
+		for (int i = 0; i < cache.length; i++) {
+			if (cache[i] instanceof ZipFile) {
+				try {
+					((ZipFile)cache[i]).close();
+				} catch (IOException e) {
+				}
+			}
+		}
+	}
+
+	/**
+	 * Split a search path into components. Splits on the platform
+	 * specific path separator.
+	 *
+	 * @param path Search path containing file/directory names, e.g.,
+	 *		<code>/some/dir1:/some/file2:/other/file.zip<code>.
+	 */
+	public static String[] splitPath(String path) {
+		ArrayList dlist = new ArrayList();
+		for (int i = 0; i < path.length(); ) {
+			while (i < path.length() && path.charAt(i) == ps)
+				i++;
+			int start = i;
+			while (i < path.length() && path.charAt(i) != ps)
+				i++;
+			if (i > start)
+				dlist.add(path.substring(start, i));
+		}
+		return (String[])dlist.toArray(new String[dlist.size()]);
+	}
+}
+

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/cgen/ActiveUseCheckStmt.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/cgen/ActiveUseCheckStmt.java?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/cgen/ActiveUseCheckStmt.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/cgen/ActiveUseCheckStmt.java Tue Oct  4 19:19:16 2005
@@ -0,0 +1,93 @@
+
+//
+// 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: ActiveUseCheckStmt.java,v 1.1 2004/12/24 21:55:56 archiecobbs Exp $
+//
+
+package org.dellroad.jc.cgen;
+
+import java.util.Random;
+import soot.*;
+import soot.jimple.*;
+import soot.jimple.internal.JInvokeStmt;
+
+/**
+ * Jimple statement that represents a class initialization check.
+ * This is a hack, as we have to look like a normal Jimple stmt.
+ */
+public class ActiveUseCheckStmt extends JInvokeStmt {
+
+	// Random prefix to avoid collisions
+	private static final String PREFIX
+	    = Long.toHexString(new Random().nextLong()
+		+ new Object().hashCode());
+
+	public ActiveUseCheckStmt(SootClass sc) {
+		super(Jimple.v().newStaticInvokeExpr(getCheckMethod(),
+		    StringConstant.v(PREFIX + "/" + sc.getName())));
+	}
+
+	public void toString(UnitPrinter up)
+	{
+	    up.literal(toString());
+	}
+
+	public String toString()
+	{
+	    return "activeusecheck " + getSootClass(this).getName();
+	}
+
+	public static SootClass getSootClass(Stmt stmt) {
+		return Scene.v().getSootClass(getClassName(stmt));
+	}
+
+	private static SootMethod getCheckMethod() {
+	    return Scene.v().getSootClass("java.lang.Class")
+		.getMethod("java.lang.Class forName(java.lang.String)");
+	}
+
+	public static void insertActiveUseCheck(PatchingChain units,
+	    Stmt stmt, SootClass cl) {
+		ActiveUseCheckStmt check = new ActiveUseCheckStmt(cl);
+		units.insertBefore(check, stmt);
+		stmt.redirectJumpsToThisTo(check);
+	}
+
+	public static boolean isActiveUseCheck(Stmt stmt) {
+		if (stmt instanceof ActiveUseCheckStmt)
+			return true;
+		return getClassName(stmt) != null;
+	}
+
+	private static String getClassName(Stmt stmt) {
+		if (!(stmt instanceof InvokeStmt))
+			return null;
+		InvokeExpr expr = ((InvokeStmt)stmt).getInvokeExpr();
+		if (!expr.getMethod().equals(getCheckMethod()))
+			return null;
+		Value arg = expr.getArg(0);
+		if (!(arg instanceof StringConstant))
+			return null;
+		String s = ((StringConstant)arg).value;
+		int i;
+		if ((i = s.indexOf('/')) != PREFIX.length()
+		    || !s.substring(0, i).equals(PREFIX))
+		    	return null;
+		return s.substring(PREFIX.length() + 1);
+	}
+}
+

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/cgen/C.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/cgen/C.java?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/cgen/C.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/java/org/dellroad/jc/cgen/C.java Tue Oct  4 19:19:16 2005
@@ -0,0 +1,465 @@
+
+//
+// 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: C.java,v 1.4 2005/01/25 23:12:00 archiecobbs Exp $
+//
+
+package org.dellroad.jc.cgen;
+
+import soot.*;
+import java.util.*;
+import java.io.*;
+import org.dellroad.jc.Generate;
+
+/**
+ * Utility routines for generating C code.
+ */
+public class C {
+
+	private static Set reservedWords;
+
+	private C() {
+	}
+
+	/**
+	 * Returns <code>string(s, true)</code>.
+	 */
+	public static String string(String s) {
+		return string(s, true);
+	}
+
+	/**
+	 * Returns a doubly-quoted C string containing the UTF-8 encoded
+	 * value of <code>s</code> with special characters suitably escaped.
+	 *
+	 * If <code>enquote</code> is true, then enclose the string
+	 * in double quotes.
+	 */
+	public static String string(String s, boolean enquote) {
+		StringBuffer b = new StringBuffer(s.length() + 8);
+		boolean justDidHexEscape = false;
+		int qmarkCount = 0;
+		if (enquote)
+			b.append('"');
+		byte[] bytes = Util.utf8Encode(s);
+		for (int i = 0; i < bytes.length; i++) {
+			char ch = (char)(bytes[i] & 0xff);
+
+			// Handle NUL byte
+			if (ch == 0x00) {
+				b.append("\\xc0\\x80");
+				justDidHexEscape = true;
+				qmarkCount = 0;
+				continue;
+			}
+
+			// Handle normal ASCII bytes
+			if (ch <= 0x7e) {
+				switch (ch) {
+				case '"':
+				case '\\':
+					b.append("\\");
+					b.append(ch);
+					justDidHexEscape = false;
+					qmarkCount = 0;
+					continue;
+				case '\t':
+					b.append("\\t");
+					justDidHexEscape = false;
+					qmarkCount = 0;
+					continue;
+				case '\r':
+					b.append("\\r");
+					justDidHexEscape = false;
+					qmarkCount = 0;
+					continue;
+				case '\n':
+					b.append("\\n");
+					justDidHexEscape = false;
+					qmarkCount = 0;
+					continue;
+				default:
+
+					// Don't follow hex escape with hex char
+					if ((justDidHexEscape
+					     && ((ch >= '0' && ch <= '9')
+					      || (ch >= 'A' && ch <= 'F')
+					      || (ch >= 'a' && ch <= 'f')))
+					    || ch < 0x20)
+						break;
+
+					// Avoid trigraphs
+					if (qmarkCount >= 2
+					    && "()<>=/'!-".indexOf(ch) != -1)
+					    	break;
+
+					// Append unescaped character
+					b.append(ch);
+					justDidHexEscape = false;
+					if (ch == '?')
+						qmarkCount++;
+					continue;
+				}
+			}
+
+			// Encode byte with hex escape
+			b.append('\\');
+			b.append('x');
+			b.append(Integer.toHexString((bytes[i] >> 4) & 0x0f));
+			b.append(Integer.toHexString(bytes[i] & 0x0f));
+			justDidHexEscape = true;
+			qmarkCount = 0;
+		}
+		if (enquote)
+			b.append('"');
+		return b.toString();
+	}
+
+	public static String name(SootClass c) {
+		return encode(c.getName());
+	}
+
+	public static String name(SootField f) {
+		String name = f.getName();
+		if (reserved(name))
+			name = "_" + name;
+		return encode(name);
+	}
+
+	public static String name(SootMethod m) {
+		String name = m.getName();
+		StringBuffer b = new StringBuffer();
+		if (name.equals("<init>"))
+			b.append("_init");
+		else if (name.equals("<clinit>"))
+			b.append("_clinit");
+		else
+			b.append(encode(name));
+		b.append('$');
+		b.append(Util.sigHashString(m));
+		return b.toString();
+	}
+
+	/**
+	 * Tells us whether the token is a reserved word that cannot
+	 * be used in C source. For example, we can't allow "jfloat"
+	 * as a static variable name because it conflicts with the
+	 * C typedef of the same name.
+	 */
+	public static boolean reserved(String s) {
+		return reservedWords.contains(s);
+	}
+
+	// Build reserved word set. We don't need to worry about any
+	// token that begins with a single underscore, as that is not
+	// a possible output of the encode() function given a Java
+	// identifier.
+	static {
+		reservedWords = new HashSet();
+
+		// JNI typedefs
+		reservedWords.add("jboolean");
+		reservedWords.add("jbyte");
+		reservedWords.add("jchar");
+		reservedWords.add("jshort");
+		reservedWords.add("jint");
+		reservedWords.add("jlong");
+		reservedWords.add("jfloat");
+		reservedWords.add("jdouble");
+
+		// Functions declared via #include <setjmp.h>
+		reservedWords.add("setjmp");
+		reservedWords.add("longjmp");
+		reservedWords.add("sigsetjmp");
+		reservedWords.add("siglongjmp");
+		reservedWords.add("longjmperror");
+
+		// C reserved tokens
+		reservedWords.add("auto");
+		reservedWords.add("break");
+		reservedWords.add("case");
+		reservedWords.add("char");
+		reservedWords.add("const");
+		reservedWords.add("continue");
+		reservedWords.add("default");
+		reservedWords.add("do");
+		reservedWords.add("double");
+		reservedWords.add("else");
+		reservedWords.add("enum");
+		reservedWords.add("extern");
+		reservedWords.add("float");
+		reservedWords.add("for");
+		reservedWords.add("if");
+		reservedWords.add("int");
+		reservedWords.add("long");
+		reservedWords.add("register");
+		reservedWords.add("restrict");
+		reservedWords.add("return");
+		reservedWords.add("short");
+		reservedWords.add("static");
+		reservedWords.add("struct");
+		reservedWords.add("switch");
+		reservedWords.add("typedef");
+		reservedWords.add("union");
+		reservedWords.add("volatile");
+		reservedWords.add("while");
+	}
+
+	public static String encode(String name) {
+		return Generate.encode(name, false);
+	}
+
+	public static String encode(String name, boolean ignoreSlashes) {
+		return Generate.encode(name, ignoreSlashes);
+	}
+
+	public static String type(SootClass sc) {
+		return type(sc.getType(), false);
+	}
+
+	public static String type(SootMethod m) {
+		return type(m.getReturnType(), false);
+	}
+
+	public static String type(SootField f) {
+		return type(f.getType(), false);
+	}
+
+	public static String type(Value v) {
+		return type(v.getType(), false);
+	}
+
+	public static String type(SootClass sc, boolean withStruct) {
+		return type(sc.getType(), withStruct);
+	}
+
+	public static String type(SootMethod m, boolean withStruct) {
+		return type(m.getReturnType(), withStruct);
+	}
+
+	public static String type(SootField f, boolean withStruct) {
+		return type(f.getType(), withStruct);
+	}
+
+	public static String type(Value v, boolean withStruct) {
+		return type(v.getType(), withStruct);
+	}
+
+	public static CExpr value(ValueBox vb) {
+		CValueSwitch cvs = new CValueSwitch(CMethod.current(), vb);
+		vb.getValue().apply(cvs);
+		return cvs.result;
+	}
+
+	/**
+	 * Equivalent to <code>type(t, false)</code>.
+	 */
+	public static String type(Type t) {
+		return type(t, false);
+	}
+
+	/**
+	 * Return the C type for an object of type <code>t</code>,
+	 * which must be a normal Java type, i.e., a type that can
+	 * be the type of a variable.
+	 *
+	 * Reference types have the <code>struct</code> code prefixed
+	 * if <code>withStruct</code> is true, but never have '*' appended.
+	 */
+	public static String type(Type t, boolean withStruct) {
+		final StringBuffer b = new StringBuffer();
+		if (Util.isPrimitive(t)) {
+			if (t instanceof VoidType)
+				b.append("void");
+			else {
+				t.apply(new Util.PrimTypeSwitch() {
+				    public void prim(String ptype) {
+					b.append('j');
+					b.append(ptype);
+				    }
+				});
+			}
+		} else if (t instanceof ArrayType) {
+			ArrayType at = (ArrayType)t;
+			if (Util.isPrimitive(at.getElementType())) {
+				at.getElementType().apply(
+				  new Util.PrimTypeSwitch() {
+				    public void prim(String ptype) {
+					b.append("_jc_");
+					b.append(ptype);
+					b.append("_array");
+				    }
+				});
+			} else
+				b.append("_jc_object_array");
+		} else if (t instanceof RefType) {
+			SootClass rc = ((RefType)t).getSootClass();
+
+			if (withStruct)
+				b.append("struct ");
+			b.append("_jc_");
+			if (!rc.isInterface()) {
+				b.append(encode(rc.getName()));
+				b.append('$');
+			}
+			b.append("object");
+		} else if (t instanceof VoidType)
+			b.append("void");
+		else if (t instanceof NullType)
+			b.append("_jc_object");
+		else
+			Util.panic("weird type " + t);
+		return b.toString();
+	}
+
+	public static String valueType(Type t) {
+		if (t instanceof VoidType)
+			return "void";
+		if (!Util.isPrimitive(t))
+			return "_jc_object *";
+		final StringBuffer b = new StringBuffer();
+		t.apply(new Util.PrimTypeSwitch() {
+		    public void prim(String ptype) {
+			b.append('j');
+			b.append(ptype);
+		    }
+		});
+		return b.toString();
+	}
+
+	public static String jc_type(Value v) {
+		return jc_type(v.getType());
+	}
+
+	public static String jc_type(Type t) {
+		StringBuffer b = new StringBuffer("_jc_");
+		if (Util.isPrimitive(t))
+			b.append(primName(t));
+		else if (t instanceof RefType)
+			b.append(name(((RefType)t).getSootClass()));
+		else {
+			ArrayType atype = (ArrayType)t;
+			t = atype.baseType;
+			if (Util.isPrimitive(t))
+				b.append(primName(t));
+			else
+				b.append(name(((RefType)t).getSootClass()));
+			b.append("$array");
+			if (atype.numDimensions > 1)
+				b.append(atype.numDimensions);
+		}
+		if (Util.isPrimitive(t))
+			b.append("$prim");
+		b.append("$type");
+		return b.toString();
+	}
+
+	public static String primName(Type t) {
+		final StringBuffer b = new StringBuffer(7);
+		t.apply(new Util.PrimTypeSwitch() {
+		    public void prim(String name) {
+			b.append(name);
+		    }
+		});
+		return b.toString();
+	}
+
+	public static String accessDefs(SootClass c) {
+		return accessDefs(c.getModifiers());
+	}
+
+	public static String accessDefs(SootField f) {
+		return accessDefs(f.getModifiers());
+	}
+
+	public static String accessDefs(SootMethod m) {
+		return accessDefs(m.getModifiers());
+	}
+
+	public static String accessDefs(int flags) {
+		StringBuffer b = new StringBuffer(120);
+		if ((flags & Modifier.PRIVATE) != 0)
+			b.append("|_JC_ACC_PRIVATE");
+		if ((flags & Modifier.PROTECTED) != 0)
+			b.append("|_JC_ACC_PROTECTED");
+		if ((flags & Modifier.PUBLIC) != 0)
+			b.append("|_JC_ACC_PUBLIC");
+		if ((flags & Modifier.STATIC) != 0)
+			b.append("|_JC_ACC_STATIC");
+		if ((flags & Modifier.FINAL) != 0)
+			b.append("|_JC_ACC_FINAL");
+		if ((flags & Modifier.NATIVE) != 0)
+			b.append("|_JC_ACC_NATIVE");
+		if ((flags & Modifier.SYNCHRONIZED) != 0)
+			b.append("|_JC_ACC_SYNCHRONIZED");
+		if ((flags & Modifier.TRANSIENT) != 0)
+			b.append("|_JC_ACC_TRANSIENT");
+		if ((flags & Modifier.VOLATILE) != 0)
+			b.append("|_JC_ACC_VOLATILE");
+		if ((flags & Modifier.ABSTRACT) != 0)
+			b.append("|_JC_ACC_ABSTRACT");
+		if ((flags & Modifier.INTERFACE) != 0)
+			b.append("|_JC_ACC_INTERFACE");
+		if (b.length() == 0)
+			return "0";
+		b.deleteCharAt(0);
+		return b.toString();
+	}
+
+	public static String paramsDecl(SootMethod m, boolean withNames) {
+		StringBuffer b = new StringBuffer(128);
+		b.append("(_jc_env *");
+		if (withNames)
+			b.append("const env");
+		if (!m.isStatic() || m.getName().equals("<init>")) {
+			b.append(", ");
+			SootClass dc = m.getDeclaringClass();
+			if (!withNames)
+				b.append("struct ");
+			b.append(C.type(dc));
+			b.append(" *");
+			if (withNames)
+				b.append("this");
+		}
+		for (int i = 0; i < m.getParameterCount(); i++) {
+			Type t = m.getParameterType(i);
+			b.append(", ");
+			if (Util.isReference(t) && !withNames)
+				b.append("struct ");
+			b.append(C.type(t));
+			if (Util.isReference(t) || withNames)
+				b.append(' ');
+			if (Util.isReference(t))
+				b.append('*');
+			if (withNames)
+				b.append("param" + i);
+		}
+		b.append(")");
+		return b.toString();
+	}
+
+	public static void include(String s) {
+		throw new RuntimeException("C.asm() invoked with a"
+		    + " non-constant string: " + s);
+	}
+
+	public static void main(String[] args) {
+		for (int i = 0; i < args.length; i++)
+			System.out.println(C.string(args[i]));
+	}
+}
+



Mime
View raw message