You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ge...@apache.org on 2005/10/05 04:20:10 UTC
svn commit: r294974 [24/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...
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/vm.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/vm.c?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/vm.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/vm.c Tue Oct 4 19:19:16 2005
@@ -0,0 +1,561 @@
+
+/*
+ * 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: vm.c,v 1.17 2005/05/15 02:05:07 archiecobbs Exp $
+ */
+
+#include "libjc.h"
+#include "java_lang_Thread.h"
+
+/* Internal functions */
+static void _jc_length_detect(_jc_env *env) _JC_JCNI_ATTR;
+static int _jc_parse_vm_options(_jc_env *env, const JavaVMInitArgs *args);
+
+/*
+ * Create a new Java VM and attach the currently running thread
+ * to it as its first and only thread.
+ */
+jint
+_jc_create_vm(void *args, _jc_jvm **vmp, _jc_env **envp)
+{
+ _jc_initialization initialization;
+ _jc_env temp_env;
+ _jc_env *env = &temp_env;
+ _jc_jvm temp_vm;
+ _jc_jvm *vm = &temp_vm;
+ _jc_method method;
+ jobject sref = NULL;
+ u_char rtype;
+ int i;
+
+ /* Static checks */
+ _JC_ASSERT(_JC_VMEXCEPTION_MAX <= 64); /* must fit in jlong */
+ _JC_ASSERT(_JC_VERBOSE_MAX <= 32); /* must fit in jint */
+ _JC_ASSERT(_JC_FULL_ALIGNMENT <= sizeof(_jc_word));
+ _JC_ASSERT(sizeof(void *) <= sizeof(jlong));
+ _JC_ASSERT(sizeof(_jc_word) == sizeof(void *));
+
+ /* Initialize initialization structure */
+ memset(&initialization, 0, sizeof(initialization));
+ initialization.ex.num = -1;
+
+ /* Initialize temporary dummy thread and VM structures */
+ memset(&temp_env, 0, sizeof(temp_env));
+ memset(&temp_vm, 0, sizeof(temp_vm));
+ temp_env.ex.num = -1;
+ temp_env.vm = &temp_vm;
+ temp_vm.initialization = &initialization;
+ temp_vm.vfprintf = vfprintf;
+ temp_vm.abort = abort;
+ temp_vm.exit = exit;
+
+ /* Allocate vm struct */
+ if ((vm = _jc_vm_zalloc(env, sizeof(*vm))) == NULL) {
+ vm = &temp_vm;
+ goto fail_info;
+ }
+ env->vm = vm;
+ vm->initialization = &initialization;
+
+ /* Initialize the easy stuff */
+ vm->jni_interface = &_jc_invoke_interface;
+ vm->vfprintf = vfprintf;
+ vm->abort = abort;
+ vm->exit = exit;
+ SLIST_INIT(&vm->native_globals);
+ LIST_INIT(&vm->class_loaders);
+ LIST_INIT(&vm->threads.alive_list);
+ LIST_INIT(&vm->threads.free_list);
+ SLIST_INIT(&vm->fat_locks.free_list);
+
+ /* Initialize mutexes and condition variables */
+ if (_jc_mutex_init(env, &vm->mutex) != JNI_OK)
+ goto pfail1;
+ if (_jc_cond_init(env, &vm->all_halted) != JNI_OK)
+ goto pfail2;
+ if (_jc_cond_init(env, &vm->world_restarted) != JNI_OK) {
+ _jc_cond_destroy(&vm->all_halted);
+pfail2: _jc_mutex_destroy(&vm->mutex);
+pfail1: _jc_vm_free(&vm);
+ vm = &temp_vm;
+ goto fail_info;
+ }
+
+ /* Map in thread check page */
+ if ((vm->check_address = mmap(NULL, _JC_PAGE_SIZE,
+ PROT_READ, MAP_PRIVATE|MAP_ANON, -1, 0)) == MAP_FAILED) {
+ vm->check_address = NULL;
+ _JC_EX_STORE(env, InternalError, "%s: %s",
+ "mmap", strerror(errno));
+ goto fail;
+ }
+
+ /* Allocate threads.by_id array */
+ if ((vm->threads.by_id = _jc_vm_alloc(env,
+ _JC_MAX_THREADS * sizeof(*vm->threads.by_id))) == NULL)
+ goto fail_info;
+
+ /* Allocate fat_locks.by_id array */
+ if ((vm->fat_locks.by_id = _jc_vm_alloc(env,
+ _JC_MAX_FATLOCKS * sizeof(*vm->fat_locks.by_id))) == NULL)
+ goto fail_info;
+
+ /* Initialize list of free thread ID's (we never use ID zero) */
+ vm->threads.next_free_id = 1;
+ for (i = 1; i < _JC_MAX_THREADS - 1; i++)
+ vm->threads.by_id[i] = (_jc_env *)(i + 1);
+ vm->threads.by_id[i] = (_jc_env *)0;
+
+ /* Create and attach a new thread structure to the current thread */
+ _JC_MUTEX_LOCK(NULL, vm->mutex);
+ if ((env = _jc_attach_thread(vm, &temp_env.ex)) == NULL) {
+ _JC_MUTEX_UNLOCK(NULL, vm->mutex);
+ env = &temp_env;
+ goto fail_info;
+ }
+ _JC_MUTEX_UNLOCK(env, vm->mutex);
+
+ /* Initialize classfiles tree */
+ _jc_splay_init(&vm->classfiles, _jc_classfile_tree_compare,
+ _JC_OFFSETOF(_jc_class_node, node));
+
+ /* Initialize PC -> method tree */
+ _jc_splay_init(&vm->method_tree, _jc_method_tree_compare,
+ _JC_OFFSETOF(_jc_method, u.exec.node));
+
+ /* Initialize default system properties */
+ if (_jc_set_system_properties(env) != JNI_OK)
+ goto fail_info;
+
+ /* Parse options */
+ if (_jc_parse_vm_options(env, args) != JNI_OK)
+ goto fail_info;
+
+ /* Digest properties */
+ if (_jc_digest_properties(env) != JNI_OK)
+ goto fail_info;
+
+ /* Initialize the heap */
+ if (_jc_heap_init(env, vm) != JNI_OK)
+ goto fail_info;
+
+ /* Create the bootstrap class loader */
+ _JC_MUTEX_LOCK(env, vm->mutex);
+ if ((vm->boot.loader = _jc_create_loader(env)) == NULL) {
+ _JC_MUTEX_UNLOCK(env, vm->mutex);
+ goto fail_info;
+ }
+ _JC_MUTEX_UNLOCK(env, vm->mutex);
+
+ /* Initialize boot loader's loading types tree */
+ _jc_splay_init(&vm->boot.loading_types,
+ _jc_node_cmp, _JC_OFFSETOF(_jc_type_node, node));
+
+ /* Open myself as a native library */
+ if (_jc_load_native_library(env,
+ vm->boot.loader, _JC_INTERNAL_NATIVE_LIBRARY) != JNI_OK)
+ goto fail_info;
+
+ /* Copy _jc_invoke_jcni_a() method descriptor */
+ vm->invoke_method = _jc_invoke_jcni_a$method_info;
+
+ /* Compute high/low PC limits of _jc_invoke_jcni_a() function */
+ memset(&method, 0, sizeof(method));
+ method.access_flags |= _JC_ACC_STATIC;
+ method.num_parameters = 0;
+ method.param_ptypes = &rtype;
+ for (rtype = _JC_TYPE_BOOLEAN; rtype < _JC_TYPE_MAX; rtype++)
+ _jc_invoke_jcni_a(env, &method, _jc_length_detect, NULL, NULL);
+
+ /* Sanity check _jc_invoke_jcni_a() length */
+ _JC_ASSERT((char *)vm->invoke_method.u.exec.function_end
+ - (char *)vm->invoke_method.function < 8192);
+#if 0
+ printf("_jc_invoke_jcni_a(): %p - %p length=%d\n",
+ vm->invoke_method.function, vm->invoke_method.u.exec.function_end,
+ (char *)vm->invoke_method.u.exec.function_end
+ - (char *)vm->invoke_method.function);
+#endif
+
+ /* Add _jc_invoke_jcni_a() to PC -> method tree */
+ _jc_splay_insert(&vm->method_tree, &vm->invoke_method);
+
+ /* Load bootstrap Java classes, methods, etc. */
+ if (_jc_bootstrap_classes(env) != JNI_OK)
+ goto fail;
+
+ /* Get min and max scheduler scheduling priorities */
+ if ((vm->threads.prio_min = sched_get_priority_min(SCHED_RR)) == -1) {
+ _JC_EX_STORE(env, InternalError,
+ "%s: %s", "sched_get_priority_min", strerror(errno));
+ goto fail;
+ }
+ if ((vm->threads.prio_max = sched_get_priority_max(SCHED_RR)) == -1) {
+ _JC_EX_STORE(env, InternalError,
+ "%s: %s", "sched_get_priority_max", strerror(errno));
+ goto fail;
+ }
+ _JC_ASSERT(vm->threads.prio_min <= vm->threads.prio_max);
+
+ /* Get minimum, maximum, and default Java priority values */
+ vm->threads.java_prio_min = java_lang_Thread_MIN_PRIORITY;
+ vm->threads.java_prio_max = java_lang_Thread_MAX_PRIORITY;
+ vm->threads.java_prio_norm = java_lang_Thread_NORM_PRIORITY;
+
+ /* Create system ThreadGroup */
+ if ((sref = _jc_new_local_native_ref(env,
+ _jc_new_string(env, _JC_SYSTEM_THREADGROUP_NAME,
+ sizeof(_JC_SYSTEM_THREADGROUP_NAME) - 1))) == NULL)
+ goto fail;
+ if ((vm->boot.objects.systemThreadGroup = _jc_new_object(env,
+ vm->boot.types.ThreadGroup)) == NULL)
+ goto fail;
+ if (_jc_invoke_nonvirtual(env, vm->boot.methods.ThreadGroup.init,
+ vm->boot.objects.systemThreadGroup, *_JC_VMSTATICFIELD(vm,
+ ThreadGroup, root, _jc_object *), *sref) != JNI_OK)
+ goto fail;
+
+ /* Wrap it in a global native reference */
+ if (_jc_new_global_native_ref(env,
+ vm->boot.objects.systemThreadGroup) == NULL)
+ goto fail;
+
+ /* Create java.lang.Thread instance for this thread */
+ if (_jc_thread_create_instance(env, vm->boot.objects.systemThreadGroup,
+ "main", vm->threads.java_prio_norm, JNI_FALSE) != JNI_OK)
+ goto fail;
+
+ /* Start debug thread */
+ if ((vm->debug_thread = _jc_internal_thread(env,
+ "org/dellroad/jc/vm/DebugThread")) == NULL)
+ goto fail;
+
+ /* Start finalizer thread */
+ if ((vm->finalizer_thread = _jc_internal_thread(env,
+ "org/dellroad/jc/vm/FinalizerThread")) == NULL)
+ goto fail;
+
+ /* Initialization complete */
+ _JC_ASSERT(vm->initialization->ex.num == -1);
+ _JC_ASSERT(vm->initialization->frames == NULL);
+ vm->initialization = NULL;
+
+ /* Done */
+ *vmp = vm;
+ *envp = env;
+ return JNI_OK;
+
+fail_info:
+ _jc_post_exception_info(env);
+
+fail:
+ /* Sanity check */
+ _JC_ASSERT(vm->initialization != NULL);
+
+ /*
+ * Exception may have been "posted" during bootstrap but
+ * with no actual object created. If so, print out the info
+ * saved in the initialization structure.
+ */
+ if (env->head.pending == NULL && vm->initialization->ex.num != -1) {
+ _jc_initialization *const init = vm->initialization;
+
+ /* Print out the exception */
+ _jc_eprintf(vm, "jc: exception during initialization\n");
+ _jc_eprintf(vm, "%s", _jc_vmex_names[init->ex.num]);
+ if (*init->ex.msg != '\0')
+ _jc_eprintf(vm, ": %s", init->ex.msg);
+ _jc_eprintf(vm, "\n");
+
+ /* Print stack trace (if any) */
+ _jc_print_stack_frames(env, stderr,
+ init->num_frames, init->frames);
+ goto done;
+ }
+
+ /* Otherwise, exception must have been posted normally */
+ _JC_ASSERT(env->head.pending != NULL);
+ _jc_print_stack_trace(env, stderr);
+
+done:
+ /* Cleanup and return failure */
+ _jc_free_local_native_ref(&sref);
+ if (env != &temp_env)
+ _jc_thread_shutdown(&env);
+ if (vm != &temp_vm)
+ _jc_free_vm(&vm);
+ return JNI_ERR;
+}
+
+/*
+ * Part of the hack to compute the length of _jc_invoke_jcni_a().
+ */
+static void _JC_JCNI_ATTR
+_jc_length_detect(_jc_env *env)
+{
+ _jc_jvm *const vm = env->vm;
+ _jc_stack_frame frame;
+ const void *pc;
+
+ /* Get PC return address */
+ _jc_stack_frame_current(&frame);
+ _jc_stack_frame_next(&frame, &pc);
+
+ /* Update high/low bound of _jc_invoke_jcni_a() */
+ if (vm->invoke_method.function == NULL
+ || pc < vm->invoke_method.function)
+ vm->invoke_method.function = (const char *)pc - 1;
+ if (vm->invoke_method.u.exec.function_end == NULL
+ || pc >= vm->invoke_method.u.exec.function_end)
+ vm->invoke_method.u.exec.function_end = (const char *)pc + 1;
+}
+
+/*
+ * Free a Java VM structure.
+ *
+ * This assumes there are no threads remaining alive.
+ */
+void
+_jc_free_vm(_jc_jvm **vmp)
+{
+ _jc_jvm *vm = *vmp;
+ int i;
+
+ /* Sanity check */
+ if (vm == NULL)
+ return;
+ *vmp = NULL;
+
+ /* There should be no alive threads! */
+ _JC_ASSERT(LIST_EMPTY(&vm->threads.alive_list));
+
+ /* Free system properties */
+ _jc_destroy_properties(vm);
+
+ /* Free other stuff */
+ if (vm->boot.class_path != NULL) {
+ for (i = 0; i < vm->boot.class_path_len; i++) {
+ _jc_cpath_entry *const ent = &vm->boot.class_path[i];
+
+ _jc_vm_free(&ent->pathname);
+ _jc_zip_close(&ent->zip);
+ }
+ _jc_vm_free(&vm->boot.class_path);
+ }
+ if (vm->object_path != NULL) {
+ for (i = 0; i < vm->object_path_len; i++) {
+ _jc_objpath_entry *const ent = &vm->object_path[i];
+
+ _jc_vm_free(&ent->pathname);
+ }
+ _jc_vm_free(&vm->object_path);
+ }
+ if (vm->source_path != NULL) {
+ for (i = 0; vm->source_path[i] != NULL; i++)
+ _jc_vm_free(&vm->source_path[i]);
+ _jc_vm_free(&vm->source_path);
+ }
+ if (vm->object_path != NULL) {
+ for (i = 0; i < vm->object_path_len; i++) {
+ _jc_objpath_entry *const ent = &vm->object_path[i];
+
+ _jc_vm_free(&ent->pathname);
+ }
+ _jc_vm_free(&vm->object_path);
+ }
+
+ /* Free fat locks XXX need to recover fat locks alive in the heap */
+ while (!SLIST_EMPTY(&vm->fat_locks.free_list)) {
+ _jc_fat_lock *lock = SLIST_FIRST(&vm->fat_locks.free_list);
+
+ SLIST_REMOVE_HEAD(&vm->fat_locks.free_list, u.link);
+ _jc_destroy_lock(&lock);
+ }
+ _jc_vm_free(&vm->fat_locks.by_id);
+
+ /* Destroy threads on the free list */
+ _jc_free_thread_stacks(vm);
+ while (!LIST_EMPTY(&vm->threads.free_list)) {
+ _jc_env *env = LIST_FIRST(&vm->threads.free_list);
+
+ LIST_REMOVE(env, link);
+ vm->threads.num_free--;
+ _jc_destroy_thread(&env);
+ }
+ _jc_vm_free(&vm->threads.by_id);
+
+ /* Free class loaders */
+ while (!LIST_EMPTY(&vm->class_loaders)) {
+ _jc_class_loader *loader = LIST_FIRST(&vm->class_loaders);
+
+ _jc_destroy_loader(vm, &loader);
+ }
+ _JC_ASSERT(vm->method_tree.size <= 1); /* vm->invoke_method ok */
+ _JC_ASSERT(vm->avail_loader_pages == vm->max_loader_pages);
+
+ /* Free native globals */
+ _jc_free_all_native_global_refs(vm);
+
+ /* Destroy mutexes and condition vars */
+ _jc_mutex_destroy(&vm->mutex);
+ _jc_cond_destroy(&vm->all_halted);
+ _jc_cond_destroy(&vm->world_restarted);
+
+ /* Free thread check page */
+ if (vm->check_address != NULL)
+ munmap(vm->check_address, _JC_PAGE_SIZE);
+
+ /* Free the heap */
+ _jc_heap_destroy(vm);
+
+ /* Free VM struct */
+ memset(vm, 0, sizeof(*vm)); /* for good measure */
+ _jc_vm_free(&vm);
+}
+
+/*
+ * Parse VM options.
+ *
+ * If unsuccessful an exception is stored.
+ */
+static jint
+_jc_parse_vm_options(_jc_env *env, const JavaVMInitArgs *args)
+{
+ _jc_jvm *const vm = env->vm;
+ int i;
+
+ /* We only communicate using the 1.2 interface version */
+ if (args->version != JNI_VERSION_1_2)
+ return JNI_EVERSION;
+
+ /* Parse options */
+ for (i = 0; i < args->nOptions; i++) {
+ JavaVMOption *const opt = &args->options[i];
+
+ /* Function hooks */
+ if (strcmp(opt->optionString, "vfprintf") == 0) {
+ vm->vfprintf = opt->extraInfo;
+ continue;
+ }
+ if (strcmp(opt->optionString, "exit") == 0) {
+ vm->exit = opt->extraInfo;
+ continue;
+ }
+ if (strcmp(opt->optionString, "abort") == 0) {
+ vm->abort = opt->extraInfo;
+ continue;
+ }
+
+ /* Properties */
+ if (strncmp(opt->optionString, "-D", 2) == 0) {
+ const char *const pname = opt->optionString + 2;
+ const char *eq = strchr(pname, '=');
+ const char *pvalue;
+ size_t pname_len;
+
+ /* Parse propery name and value */
+ if (eq == NULL)
+ goto option_fail;
+ pname_len = eq - pname;
+ pvalue = eq + 1;
+ if (pname_len == 0)
+ goto option_fail;
+
+ /* Add property to list */
+ if (_jc_set_property2(env,
+ pname, pname_len, pvalue) != JNI_OK)
+ goto fail;
+ continue;
+ }
+
+ /* Verbosity */
+ if (strncmp(opt->optionString, "-verbose", 8) == 0) {
+ const char *s = opt->optionString + 8;
+
+ /* Verbose all standard stuff? */
+ if (*s == '\0') {
+ vm->verbose_flags |= (1 << _JC_VERBOSE_CLASS);
+ vm->verbose_flags |= (1 << _JC_VERBOSE_GC);
+ vm->verbose_flags |= (1 << _JC_VERBOSE_JNI);
+ continue;
+ }
+
+ /* An explicitly specified list? */
+ if (*s++ != ':')
+ goto option_fail;
+
+ /* Parse the list */
+ while (*s != '\0') {
+ size_t n = 0;
+ int j;
+
+ /* Match verbose options; 'X' is optional */
+ for (j = 0; j < _JC_VERBOSE_MAX; j++) {
+ const char *const vn
+ = _jc_verbose_names[j];
+
+ n = strlen(vn);
+ if ((strncmp(s, vn, n) == 0
+ && (s[n] == ',' || s[n] == '\0'))
+ || (*s == 'X'
+ && strncmp(s + 1, vn, n) == 0
+ && (s[n + 1] == ','
+ || s[n + 1] == '\0')
+ && ++n /* ugh */)) {
+ vm->verbose_flags |= (1 << j);
+ break;
+ }
+ }
+ if (j == _JC_VERBOSE_MAX) {
+ if (*s != 'X'
+ || !args->ignoreUnrecognized)
+ goto option_fail;
+ }
+ s += n;
+ if (*s != '\0' && *s++ != ',')
+ goto option_fail;
+ }
+ continue;
+ }
+
+ /* FILE * for outputting list of loaded object files */
+ if (strcmp(opt->optionString, "-Xloadlist") == 0) {
+ vm->object_list = opt->extraInfo;
+ continue;
+ }
+
+ /* Ignore unrecognized but ignorable options */
+ if (args->ignoreUnrecognized
+ && (*opt->optionString == '_'
+ || strncmp(opt->optionString, "-X", 2) == 0))
+ continue;
+
+option_fail:
+ /* Unrecognized option */
+ _JC_EX_STORE(env, InternalError,
+ "invalid option `%s'\n", opt->optionString);
+ goto fail;
+ }
+
+ /* Done */
+ return JNI_OK;
+
+fail:
+ /* Failed */
+ return JNI_ERR;
+}
+
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/vm_alloc.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/vm_alloc.c?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/vm_alloc.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/vm_alloc.c Tue Oct 4 19:19:16 2005
@@ -0,0 +1,103 @@
+
+/*
+ * 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: vm_alloc.c,v 1.3 2005/02/27 23:29:45 archiecobbs Exp $
+ */
+
+#include "libjc.h"
+
+/************************************************************************
+ * VM memory pool allocation *
+ ************************************************************************/
+
+char *
+_jc_vm_strndup(_jc_env *env, const char *s, size_t len)
+{
+ char *result;
+
+ if ((result = malloc(len + 1)) == NULL) {
+ _JC_EX_STORE(env, OutOfMemoryError, "system heap");
+ return NULL;
+ }
+ memcpy(result, s, len);
+ result[len] = '\0';
+ return result;
+}
+
+char *
+_jc_vm_strdup(_jc_env *env, const char *s)
+{
+ char *result;
+
+ if ((result = strdup(s)) == NULL) {
+ _JC_EX_STORE(env, OutOfMemoryError, "system heap");
+ return NULL;
+ }
+ return result;
+}
+
+void *
+_jc_vm_zalloc(_jc_env *env, size_t size)
+{
+ void *mem;
+
+ if ((mem = malloc(size)) == NULL) {
+ _JC_EX_STORE(env, OutOfMemoryError, "system heap");
+ return NULL;
+ }
+ memset(mem, 0, size);
+ return mem;
+}
+
+void *
+_jc_vm_alloc(_jc_env *env, size_t size)
+{
+ void *mem;
+
+ if ((mem = malloc(size)) == NULL) {
+ _JC_EX_STORE(env, OutOfMemoryError, "system heap");
+ return NULL;
+ }
+ return mem;
+}
+
+void *
+_jc_vm_realloc(_jc_env *env, void *mem, size_t size)
+{
+ void *new_mem;
+
+ if ((new_mem = realloc(mem, size)) == NULL) {
+ _JC_EX_STORE(env, OutOfMemoryError, "system heap");
+ return NULL;
+ }
+ return new_mem;
+}
+
+/*
+ * This function must not allow this thread to be blocked & GC'd.
+ */
+void
+_jc_vm_free(void *pointerp)
+{
+ void **const ptrp = pointerp;
+
+ if (*ptrp != NULL) {
+ free(*ptrp);
+ *ptrp = NULL;
+ }
+}
+
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/zip.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/zip.c?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/zip.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/zip.c Tue Oct 4 19:19:16 2005
@@ -0,0 +1,545 @@
+
+/*
+ * 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: zip.c,v 1.2 2004/07/05 21:03:28 archiecobbs Exp $
+ */
+
+#include "libjc.h"
+
+/* Internal functions */
+static int _jc_zip_scan(_jc_zip *zip, ...);
+static jint _jc_zip_unstore(_jc_env *env, _jc_zip *zip,
+ _jc_zip_entry *zent, void *data);
+static jint _jc_zip_inflate(_jc_env *env, _jc_zip *zip,
+ _jc_zip_entry *zent, void *data);
+static void *_jc_zip_alloc(void *cookie, unsigned int num,
+ unsigned int size);
+static void _jc_zip_free(void *cookie, void *mem);
+static int _jc_zip_entry_cmp(const void *v1, const void *v2);
+
+/*
+ * Open a ZIP file.
+ *
+ * If there is an error, an exception is stored and NULL is returned.
+ */
+_jc_zip *
+_jc_zip_open(_jc_env *env, const char *path)
+{
+ jshort num_entries;
+ jint signature;
+ jint offset;
+ _jc_zip *zip;
+ int i;
+
+ /* Create new zip structure */
+ if ((zip = _jc_vm_zalloc(env, sizeof(*zip))) == NULL)
+ goto fail;
+ zip->fd = -1;
+ if ((zip->path = _jc_vm_strdup(env, path)) == NULL)
+ goto fail;
+
+ /* Open file */
+ if ((zip->fd = open(path, O_RDONLY)) == -1) {
+ _JC_EX_STORE(env, IOException, "can't open ZIP file `%s': %s",
+ zip->path, strerror(errno));
+ goto fail;
+ }
+ (void)fcntl(zip->fd, F_SETFD, 1);
+
+ /* Seek to start of central directory meta-info at end of file */
+ if (lseek(zip->fd, (off_t)-ZIP_DIRECTORY_INFO_LEN, SEEK_END) == -1) {
+ _JC_EX_STORE(env, IOException, "can't seek to directory meta-"
+ "info in ZIP file `%s': %s", zip->path, strerror(errno));
+ goto fail;
+ }
+
+ /* Read central directory meta-info */
+ if (_jc_zip_scan(zip, -4, &signature, 6, NULL,
+ -2, &num_entries, 4, NULL, -4, &offset, 0) != JNI_OK) {
+ _JC_EX_STORE(env, IOException, "can't read directory meta-info"
+ " in ZIP file `%s': %s", zip->path, strerror(errno));
+ goto fail;
+ }
+
+ /* Check signature */
+ if (signature != ZIP_DIRECTORY_SIGNATURE) {
+ _JC_EX_STORE(env, IOException, "invalid directory signature"
+ " 0x%08x != 0x%08x in ZIP file `%s'", signature,
+ ZIP_DIRECTORY_SIGNATURE, zip->path);
+ goto fail;
+ }
+
+ /* Seek to start of central directory */
+ if (lseek(zip->fd, (off_t)offset, SEEK_SET) == -1) {
+ _JC_EX_STORE(env, IOException, "can't seek to directory in ZIP"
+ " file `%s': %s", zip->path, strerror(errno));
+ goto fail;
+ }
+
+ /* Allocate directory entries */
+ if ((zip->entries = _jc_vm_zalloc(env,
+ num_entries * sizeof(*zip->entries))) == NULL)
+ goto fail;
+ zip->num_entries = num_entries;
+
+ /* Read directory entries */
+ for (i = 0; i < num_entries; i++) {
+ _jc_zip_entry *const zent = &zip->entries[i];
+ jshort comment_len;
+ jshort extra_len;
+ jshort name_len;
+ off_t pos;
+
+ /* Read directory entry */
+ if (_jc_zip_scan(zip, -4, &signature, 6, NULL,
+ -2, &zent->method, 4, NULL, -4, &zent->crc,
+ -4, &zent->comp_len, -4, &zent->uncomp_len,
+ -2, &name_len, -2, &extra_len, -2, &comment_len,
+ 8, NULL, -4, &offset, 0) != JNI_OK) {
+ _JC_EX_STORE(env, IOException, "can't read entry"
+ " directory #%d in ZIP file `%s': %s", i + 1,
+ zip->path, strerror(errno));
+ goto fail;
+ }
+
+ /* Check signature */
+ if (signature != ZIP_DIRENTRY_SIGNATURE) {
+ _JC_EX_STORE(env, IOException, "invalid signature"
+ " 0x%08x != 0x%08x for directory entry #%d in ZIP"
+ " file `%s'", signature, ZIP_DIRENTRY_SIGNATURE,
+ i + 1, zip->path);
+ goto fail;
+ }
+
+ /* Allocate buffer for file name */
+ if ((zent->name = _jc_vm_alloc(env, name_len + 1)) == NULL)
+ goto fail;
+
+ /* Read entry file name */
+ if (_jc_zip_scan(zip, name_len, zent->name, 0) != JNI_OK) {
+ _JC_EX_STORE(env, IOException, "can't read directory"
+ " entry #%d in ZIP file `%s': %s", i + 1,
+ zip->path, strerror(errno));
+ goto fail;
+ }
+ zent->name[name_len] = '\0';
+
+ /* Skip over extra and comment fields */
+ if (_jc_zip_scan(zip,
+ extra_len + comment_len, NULL, 0) != JNI_OK) {
+ _JC_EX_STORE(env, IOException, "can't read entry `%s'"
+ " in ZIP file `%s': %s", zent->name, zip->path,
+ strerror(errno));
+ goto fail;
+ }
+
+ /* Save current position */
+ if ((pos = lseek(zip->fd, 0, SEEK_CUR)) == (off_t)-1) {
+ _JC_EX_STORE(env, IOException, "can't seek entry `%s'"
+ " in ZIP file `%s': %s", zent->name, zip->path,
+ strerror(errno));
+ goto fail;
+ }
+
+ /* Jump to entry local header extra data length field */
+ if (lseek(zip->fd,
+ (off_t)(offset + ZIP_LOCAL_HEADER_EXTRA_OFFSET),
+ SEEK_SET) == (off_t)-1) {
+ _JC_EX_STORE(env, IOException, "can't seek entry `%s'"
+ " in ZIP file `%s': %s", zent->name, zip->path,
+ strerror(errno));
+ goto fail;
+ }
+
+ /* Read length of local extra data */
+ if (_jc_zip_scan(zip, -2, &extra_len, 0) != JNI_OK) {
+ _JC_EX_STORE(env, IOException, "can't read entry `%s'"
+ " in ZIP file `%s': %s", zent->name, zip->path,
+ strerror(errno));
+ goto fail;
+ }
+
+ /* Compute offset of actual file data */
+ zent->offset = offset
+ + ZIP_LOCAL_HEADER_LEN + name_len + extra_len;
+
+ /* Jump back to previous position in directory */
+ if (lseek(zip->fd, pos, SEEK_SET) == (off_t)-1) {
+ _JC_EX_STORE(env, IOException, "can't seek entry `%s'"
+ " in ZIP file `%s': %s", zent->name, zip->path,
+ strerror(errno));
+ goto fail;
+ }
+ }
+
+ /* Sort the entries by name for faster searching */
+ qsort(zip->entries, zip->num_entries,
+ sizeof(*zip->entries), _jc_zip_entry_cmp);
+
+ /* Done */
+ return zip;
+
+fail:
+ /* Clean up after failure */
+ _jc_zip_close(&zip);
+ return NULL;
+}
+
+/*
+ * Close a ZIP file.
+ */
+void
+_jc_zip_close(_jc_zip **zipp)
+{
+ _jc_zip *zip = *zipp;
+
+ /* Sanity check */
+ if (zip == NULL)
+ return;
+ *zipp = NULL;
+
+ /* Free resources */
+ while (zip->num_entries > 0) {
+ _jc_zip_entry *const zent = &zip->entries[--zip->num_entries];
+
+ _jc_vm_free(&zent->name);
+ }
+ _jc_vm_free(&zip->entries);
+ _jc_vm_free(&zip->path);
+ if (zip->fd != -1)
+ close(zip->fd);
+ _jc_vm_free(&zip);
+}
+
+/*
+ * Search for an entry in a ZIP file.
+ *
+ * Returns the entry index, or -1 if unsuccessful.
+ * No exceptions stored or posted.
+ */
+int
+_jc_zip_search(_jc_zip *zip, const char *name)
+{
+ int base;
+ int lim;
+
+ /* Search for entry using binary search */
+ for (base = 0, lim = zip->num_entries; lim != 0; lim >>= 1) {
+ const int target = base + (lim >> 1);
+ const _jc_zip_entry *const zent = &zip->entries[target];
+ int diff;
+
+ if ((diff = strcmp(name, zent->name)) == 0)
+ return target;
+ if (diff > 0) {
+ base = target + 1;
+ lim--;
+ }
+ }
+ return -1;
+}
+
+/*
+ * Extract an entry from a ZIP file and return its length.
+ *
+ * Stores an exception and returns -1 if unsuccessful.
+ */
+jint
+_jc_zip_read(_jc_env *env, _jc_zip *zip, int indx, u_char *data)
+{
+ _jc_zip_entry *const zent = &zip->entries[indx];
+
+ /* Sanity check */
+ _JC_ASSERT(indx >= 0 && indx < zip->num_entries);
+
+ /* Decompress data */
+ switch (zent->method) {
+ case ZIP_METHOD_STORED:
+ if (_jc_zip_unstore(env, zip, zent, data) != JNI_OK)
+ return JNI_ERR;
+ break;
+ case ZIP_METHOD_DEFLATED:
+ if (_jc_zip_inflate(env, zip, zent, data) != JNI_OK)
+ return JNI_ERR;
+ break;
+ default:
+ _JC_EX_STORE(env, IOException, "unsupported compression method"
+ " %d for entry `%s' in ZIP file `%s'", zent->method,
+ zent->name, zip->path);
+ return JNI_ERR;
+ }
+
+ /* Done */
+ return JNI_OK;
+}
+
+/*
+ * Extract a stored entry.
+ *
+ * Stores an exception and returns JNI_ERR if unsuccessful.
+ */
+static jint
+_jc_zip_unstore(_jc_env *env, _jc_zip *zip, _jc_zip_entry *zent, void *data)
+{
+ int i;
+ int r;
+
+ /* Sanity check */
+ if (zent->comp_len != zent->uncomp_len) {
+ _JC_EX_STORE(env, IOException, "inconsistent lengths %d != %d"
+ " for entry `%s' in ZIP file `%s'", zent->comp_len,
+ zent->uncomp_len, zent->name, zip->path);
+ return JNI_ERR;
+ }
+
+ /* Read data */
+ for (i = 0; i < zent->comp_len; i += r) {
+ if ((r = pread(zip->fd, (char *)data + i,
+ zent->comp_len - i, zent->offset + i)) == -1) {
+ _JC_EX_STORE(env, IOException, "can't read entry `%s'"
+ " in ZIP file `%s': %s", zent->name, zip->path,
+ strerror(errno));
+ return JNI_ERR;
+ }
+ if (r == 0) {
+ _JC_EX_STORE(env, IOException, "premature EOF reading"
+ " entry `%s' in ZIP file `%s'", zent->name,
+ zip->path);
+ return JNI_ERR;
+ }
+ }
+
+ /* Done */
+ return JNI_OK;
+}
+
+/*
+ * Extract a deflated entry.
+ *
+ * Stores an exception and returns JNI_ERR if unsuccessful.
+ */
+static jint
+_jc_zip_inflate(_jc_env *env, _jc_zip *zip, _jc_zip_entry *zent, void *data)
+{
+ z_stream zs;
+ int i;
+ int r;
+
+ /* Initialize decompression state */
+ memset(&zs, 0, sizeof(zs));
+ zs.zalloc = _jc_zip_alloc;
+ zs.zfree = _jc_zip_free;
+ zs.opaque = env;
+ zs.next_out = data;
+ zs.avail_out = zent->uncomp_len;
+ switch (inflateInit2(&zs, -MAX_WBITS)) {
+ case Z_OK:
+ break;
+ case Z_MEM_ERROR:
+ return JNI_ERR;
+ case Z_VERSION_ERROR:
+ _JC_EX_STORE(env, IOException, "error reading entry `%s' in"
+ " ZIP file `%s': %s", zent->name, zip->path,
+ "incompatible zlib version");
+ return JNI_ERR;
+ default:
+ _JC_ASSERT(JNI_FALSE);
+ }
+
+ /* Read and inflate data */
+ for (i = 0; i < zent->comp_len; i += r) {
+ char buf[512];
+ int to_read;
+ int flush;
+
+ /* Read the next chunk of data */
+ to_read = zent->comp_len - i;
+ if (to_read > sizeof(buf))
+ to_read = sizeof(buf);
+ if ((r = pread(zip->fd, buf,
+ to_read, zent->offset + i)) == -1) {
+ _JC_EX_STORE(env, IOException, "error reading entry"
+ " `%s' in ZIP file `%s': %s", zent->name,
+ zip->path, strerror(errno));
+ goto fail;
+ }
+ if (r == 0) {
+ _JC_EX_STORE(env, IOException, "error reading entry"
+ " `%s' in ZIP file `%s': %s", zent->name,
+ zip->path, "premature EOF");
+ goto fail;
+ }
+
+ /*
+ * Check for uncompressed data appearing to be too big.
+ * A bug in zlib somewhere causes this to happen sometimes.
+ */
+ if (zs.avail_out == 0) {
+ r = inflateEnd(&zs);
+ _JC_ASSERT(r == Z_OK);
+ return JNI_OK;
+ }
+
+ /* Decompress the chunk we just read */
+ zs.next_in = buf;
+ zs.avail_in = r;
+ flush = (i + r == zent->comp_len) ? Z_FINISH : Z_SYNC_FLUSH;
+ switch (inflate(&zs, flush)) {
+ case Z_OK:
+ _JC_ASSERT(zs.avail_in == 0);
+ continue;
+ case Z_BUF_ERROR: /* bug in zlib causes this */
+ case Z_STREAM_END:
+ if (zs.avail_out != 0 || i + r != zent->comp_len)
+ goto bad_length;
+ r = inflateEnd(&zs);
+ _JC_ASSERT(r == Z_OK);
+ return JNI_OK;
+ case Z_NEED_DICT:
+ _JC_EX_STORE(env, IOException, "error reading entry'"
+ " `%s in ZIP file `%s': %s", zent->name, zip->path,
+ "dictionary required");
+ goto fail;
+ case Z_DATA_ERROR:
+ _JC_EX_STORE(env, IOException, "error reading entry"
+ " `%s' in ZIP file `%s': %s", zent->name,
+ zip->path, "corrupted entry");
+ goto fail;
+ case Z_MEM_ERROR:
+ goto fail;
+ default:
+ _JC_ASSERT(JNI_FALSE);
+ }
+ }
+
+bad_length:
+ /* Uncompressed data had the wrong length */
+ _JC_EX_STORE(env, IOException, "error reading entry `%s' in ZIP file"
+ " `%s': %s", zent->name, zip->path, "incorrect length");
+
+fail:
+ /* Clean up after failure */
+ inflateEnd(&zs);
+ return JNI_ERR;
+}
+
+/*
+ * Function to read consecutive data bytes from the ZIP file and perform
+ * optional conversion from little endian. A negative count means 16 or
+ * 32 bit conversion is performed.
+ *
+ * NOTE: Does not post or store an exception in the error case.
+ */
+static int
+_jc_zip_scan(_jc_zip *zip, ...)
+{
+ jint rtn = JNI_OK;
+ va_list args;
+
+ va_start(args, zip);
+ while (JNI_TRUE) {
+ const int count = va_arg(args, int);
+ const int num_bytes = (count < 0 ? -count : count);
+ void *const data = va_arg(args, void *);
+ u_char buf[16];
+ u_char *dest;
+ int i;
+ int r;
+
+ /* A zero count terminates the list */
+ if (count == 0)
+ break;
+
+ /* Read bytes into provided buffer or byte-swap buffer */
+ if (data == NULL || count < 0) {
+ _JC_ASSERT(num_bytes <= sizeof(buf));
+ dest = buf;
+ } else
+ dest = data;
+ for (i = 0; i < num_bytes; i += r) {
+ if ((r = read(zip->fd,
+ dest + i, num_bytes - i)) == -1) {
+ rtn = JNI_ERR;
+ goto done;
+ }
+ if (r == 0) {
+ errno = ESPIPE; /* XXX */
+ rtn = JNI_ERR;
+ goto done;
+ }
+ }
+
+ /* If no conversion needed, just continue */
+ if (data == NULL || count >= 0)
+ continue;
+
+ /* Do byte-swapping */
+ switch (num_bytes) {
+ case 1:
+ *((u_char *)data) = buf[0];
+ break;
+ case 2:
+ *((jshort *)data) = buf[0] | (buf[1] << 8);
+ break;
+ case 4:
+ *((jint *)data) = buf[0] | (buf[1] << 8)
+ | (buf[2] << 16) | (buf[3] << 24);
+ break;
+ default:
+ _JC_ASSERT(JNI_FALSE);
+ }
+ }
+
+done:
+ /* Clean up and return */
+ va_end(args);
+ return rtn;
+}
+
+/*
+ * Function to sort ZIP entries by name.
+ */
+static int
+_jc_zip_entry_cmp(const void *v1, const void *v2)
+{
+ const _jc_zip_entry *const zent1 = v1;
+ const _jc_zip_entry *const zent2 = v2;
+
+ return strcmp(zent1->name, zent2->name);
+}
+
+/*
+ * Memory allocation callback for zlib.
+ */
+static void *
+_jc_zip_alloc(void *cookie, unsigned int num, unsigned int size)
+{
+ _jc_env *const env = cookie;
+
+ return _jc_vm_alloc(env, num * size);
+}
+
+/*
+ * Memory free callback for zlib.
+ */
+static void
+_jc_zip_free(void *cookie, void *mem)
+{
+ _jc_vm_free(&mem);
+}
+
+
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/zip.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/zip.h?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/zip.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/zip.h Tue Oct 4 19:19:16 2005
@@ -0,0 +1,59 @@
+
+/*
+ * 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: zip.h,v 1.1 2005/05/24 01:09:38 archiecobbs Exp $
+ */
+
+#ifndef _ZIP_H_
+#define _ZIP_H_
+
+/*
+ * ZIP file constants.
+ */
+#define ZIP_DIRECTORY_SIGNATURE 0x06054b50
+#define ZIP_DIRENTRY_SIGNATURE 0x02014b50
+#define ZIP_ENTRY_SIGNATURE 0x03044b50
+#define ZIP_DIRECTORY_INFO_LEN 22
+#define ZIP_LOCAL_HEADER_EXTRA_OFFSET 28
+#define ZIP_LOCAL_HEADER_LEN 30
+
+#define ZIP_METHOD_STORED 0
+#define ZIP_METHOD_DEFLATED 8
+
+/*
+ * ZIP structures.
+ */
+typedef struct _jc_zip _jc_zip;
+typedef struct _jc_zip_entry _jc_zip_entry;
+
+struct _jc_zip_entry {
+ char *name;
+ jshort method;
+ jint comp_len;
+ jint uncomp_len;
+ jint crc;
+ off_t offset;
+};
+
+struct _jc_zip {
+ int fd;
+ char *path;
+ int num_entries;
+ _jc_zip_entry *entries;
+};
+
+#endif /* _ZIP_H_ */
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/Makefile.am
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/Makefile.am?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/Makefile.am (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/Makefile.am Tue Oct 4 19:19:16 2005
@@ -0,0 +1,4 @@
+## $Id: Makefile.am,v 1.3 2005/01/08 23:23:07 archiecobbs Exp $
+
+SUBDIRS= cfdump jcgen jcjavah
+
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/cfdump/Makefile.am
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/cfdump/Makefile.am?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/cfdump/Makefile.am (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/cfdump/Makefile.am Tue Oct 4 19:19:16 2005
@@ -0,0 +1,31 @@
+## $Id: Makefile.am,v 1.5 2005/02/27 21:50:04 archiecobbs Exp $
+
+jcbindir= $(bindir)
+
+jcbin_PROGRAMS= cfdump
+
+cfdump_SOURCES= dep.c deps.c main.c support.c cfdump.h
+
+nodist_cfdump_SOURCES= $(top_srcdir)/libjc/cf_parse.c \
+ $(top_srcdir)/libjc/class_bytes.c \
+ $(top_srcdir)/libjc/cl_alloc.c \
+ $(top_srcdir)/libjc/mutex.c \
+ $(top_srcdir)/libjc/splay.c \
+ $(top_srcdir)/libjc/tables.c \
+ $(top_srcdir)/libjc/misc.c \
+ $(top_srcdir)/libjc/utf.c \
+ $(top_srcdir)/libjc/vm_alloc.c \
+ $(top_srcdir)/libjc/zip.c
+
+AM_CFLAGS= $(CFLAGS) @JC_CFLAGS@
+AM_CFLAGS+= -D_AC_INCLUDEDIR=\"$(includedir)\"
+AM_CFLAGS+= -D_AC_DATADIR=\"$(datadir)\"
+AM_CFLAGS+= -D_AC_LIBDIR=\"$(libdir)\"
+AM_CFLAGS+= -D_JC_CLASSPATH_HOME=\"@CLASSPATH_HOME@\"
+AM_CFLAGS+= -DSOOT_VERSION=\"@SOOT_VERSION@\"
+AM_CFLAGS+= -DJASMIN_VERSION=\"@JASMIN_VERSION@\"
+AM_CFLAGS+= -DPOLYGLOT_VERSION=\"@POLYGLOT_VERSION@\"
+
+AM_CPPFLAGS= -I$(top_srcdir)/libjc
+AM_CPPFLAGS+= -I$(top_srcdir)/libjc/arch
+
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/cfdump/cfdump.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/cfdump/cfdump.h?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/cfdump/cfdump.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/cfdump/cfdump.h Tue Oct 4 19:19:16 2005
@@ -0,0 +1,36 @@
+
+/*
+ * 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: cfdump.h,v 1.2 2004/07/05 21:03:29 archiecobbs Exp $
+ */
+
+#ifndef _CFDUMP_H_
+#define _CFDUMP_H_
+
+#include "libjc.h"
+#include <err.h>
+#include <assert.h>
+
+/* Flags */
+#define DUMP_ENCODE_NAMES 0x0001
+#define DUMP_TRANS_CLOSURE 0x0002
+#define DUMP_SUPERS_ONLY 0x0004
+
+extern void do_deps(_jc_env *env, _jc_classfile *cf, int flags);
+extern _jc_env *_jc_support_init(void);
+
+#endif /* _CFDUMP_H_ */
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/cfdump/dep.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/cfdump/dep.c?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/cfdump/dep.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/cfdump/dep.c Tue Oct 4 19:19:16 2005
@@ -0,0 +1,223 @@
+
+/*
+ * 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: dep.c,v 1.3 2005/03/18 22:24:33 archiecobbs Exp $
+ */
+
+#include "cfdump.h"
+
+/* A node in a tree of class references */
+struct _jc_dep {
+ _jc_class_ref ref;
+ _jc_splay_node node;
+};
+typedef struct _jc_dep _jc_dep;
+
+static void add_deps(_jc_env *env, _jc_splay_tree *tree,
+ _jc_classfile *cf, int flags);
+static _jc_dep *add_dep(_jc_splay_tree *tree, const char *name,
+ size_t name_len);
+static void dump_deps(_jc_splay_tree *tree,
+ _jc_splay_node *node, int flags);
+static int _jc_dep_cmp(const void *v1, const void *v2);
+static const char *encode_name(const char *name);
+
+void
+do_deps(_jc_env *env, _jc_classfile *cf, int flags)
+{
+ _jc_splay_tree tree;
+
+ /* Build tree */
+ _jc_splay_init(&tree, _jc_dep_cmp, _JC_OFFSETOF(_jc_dep, node));
+ add_deps(env, &tree, cf, flags);
+
+ /* Dump tree */
+ dump_deps(&tree, tree.root, flags);
+
+ /* Free tree */
+ while (tree.root != NULL) {
+ _jc_dep *const dep = _JC_NODE2ITEM(&tree, tree.root);
+
+ _jc_splay_remove(&tree, dep);
+ free(dep);
+ }
+}
+
+static void
+add_deps(_jc_env *env, _jc_splay_tree *tree, _jc_classfile *cf, int flags)
+{
+ _jc_classbytes *cb = NULL;
+ _jc_classfile *scf;
+ _jc_class_ref *deps;
+ _jc_class_ref ref;
+ int num_deps;
+ int i;
+
+ /* Already doing this class? */
+ ref.name = cf->name;
+ ref.len = strlen(cf->name);
+ if (_jc_splay_find(tree, &ref) != NULL)
+ return;
+
+ /* Add this class */
+ add_dep(tree, cf->name, strlen(cf->name));
+
+ /* Dump superclasses' dependencies */
+ if (cf->superclass == NULL)
+ goto no_superclass;
+
+ if ((cb = _jc_bootcl_find_classbytes(env, cf->superclass, NULL)) == NULL
+ || (scf = _jc_parse_classfile(env, cb, 2)) == NULL) {
+ errx(1, "failed to load classfile: %s: %s",
+ _jc_vmex_names[env->ex.num], env->ex.msg);
+ }
+ _jc_free_classbytes(&cb);
+ add_deps(env, tree, scf, flags);
+ _jc_destroy_classfile(&scf);
+
+no_superclass:
+ /* Dump superinterfaces' dependencies */
+ for (i = 0; i < cf->num_interfaces; i++) {
+ if ((cb = _jc_bootcl_find_classbytes(env,
+ cf->interfaces[i], NULL)) == NULL
+ || (scf = _jc_parse_classfile(env, cb, 2)) == NULL) {
+ errx(1, "failed to load classfile: %s: %s",
+ _jc_vmex_names[env->ex.num], env->ex.msg);
+ }
+ _jc_free_classbytes(&cb);
+ add_deps(env, tree, scf, flags);
+ _jc_destroy_classfile(&scf);
+ }
+
+ /* If 'supers_only', we're done */
+ if ((flags & DUMP_SUPERS_ONLY) != 0)
+ return;
+
+ /* Update flags */
+ if ((flags & DUMP_TRANS_CLOSURE) == 0)
+ flags |= DUMP_SUPERS_ONLY;
+
+ /* Dump this class's direct dependencies and their supers */
+ if ((num_deps = _jc_gen_deplist(env, cf, &deps)) == -1)
+ errx(1, "failed to generate dependency list: %s: %s",
+ _jc_vmex_names[env->ex.num], env->ex.msg);
+ for (i = 0; i < num_deps; i++) {
+ _jc_class_ref *const dep = &deps[i];
+ char *name;
+
+ if ((name = malloc(dep->len + 1)) == NULL)
+ err(1, "malloc");
+ memcpy(name, dep->name, dep->len);
+ name[dep->len] = '\0';
+ if ((cb = _jc_bootcl_find_classbytes(env, name, NULL)) == NULL
+ || (scf = _jc_parse_classfile(env, cb, 2)) == NULL) {
+ errx(1, "failed to load classfile: %s: %s",
+ _jc_vmex_names[env->ex.num], env->ex.msg);
+ }
+ _jc_free_classbytes(&cb);
+ add_deps(env, tree, scf, flags);
+ _jc_destroy_classfile(&scf);
+ free(name);
+ }
+ _jc_vm_free(&deps);
+}
+
+static _jc_dep *
+add_dep(_jc_splay_tree *tree, const char *name, size_t name_len)
+{
+ _jc_class_ref ref;
+ _jc_dep *dep;
+
+ /* See if name is already in the tree */
+ ref.name = name;
+ ref.len = name_len;
+ if ((dep = _jc_splay_find(tree, &ref)) != NULL)
+ return dep;
+
+ /* Add name to the tree */
+ if ((dep = malloc(sizeof(*dep) + name_len + 1)) == NULL)
+ err(1, "malloc");
+ memset(dep, 0, sizeof(*dep));
+ dep->ref.name = (char *)(dep + 1);
+ dep->ref.len = name_len;
+ memcpy(dep + 1, name, name_len);
+ ((char *)(dep + 1))[name_len] = '\0';
+ _jc_splay_insert(tree, dep);
+ return dep;
+}
+
+static void
+dump_deps(_jc_splay_tree *tree, _jc_splay_node *node, int flags)
+{
+ _jc_dep *const dep = _JC_NODE2ITEM(tree, node);
+
+ /* Sanity check */
+ if (node == NULL)
+ return;
+
+ /* Do left subtree */
+ dump_deps(tree, node->left, flags);
+
+ /* Print this class */
+ printf("%s\n", (flags & DUMP_ENCODE_NAMES) != 0 ?
+ encode_name(dep->ref.name) : dep->ref.name);
+
+ /* Do right subtree */
+ dump_deps(tree, node->right, flags);
+}
+
+static const char *
+encode_name(const char *name)
+{
+ static const char hexdig[] = "0123456789abcdef";
+ static char *buf;
+ const char *s;
+ char *t;
+ int len;
+
+ for (len = 0, s = name; *s != '\0'; s++) {
+ if (isalnum(*s) || *s == '/')
+ len++;
+ len += 4;
+ }
+ free(buf);
+ if ((buf = malloc(len + 1)) == NULL)
+ err(1, "malloc");
+ for (s = name, t = buf; *s != '\0'; s++) {
+ if (isalnum(*s) || *s == '/') {
+ *t++ = *s;
+ continue;
+ }
+ assert(*s != '.');
+ *t++ = '_';
+ *t++ = '_';
+ *t++ = hexdig[(*s >> 4) & 0x0f];
+ *t++ = hexdig[*s & 0x0f];
+ }
+ *t = '\0';
+ return buf;
+}
+
+static int
+_jc_dep_cmp(const void *v1, const void *v2)
+{
+ const _jc_dep *const dep1 = v1;
+ const _jc_dep *const dep2 = v2;
+
+ return _jc_class_ref_compare(&dep1->ref, &dep2->ref);
+}
+
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/cfdump/deps.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/cfdump/deps.c?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/cfdump/deps.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/cfdump/deps.c Tue Oct 4 19:19:16 2005
@@ -0,0 +1,136 @@
+
+/*
+ * 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: deps.c,v 1.1 2004/07/06 00:33:34 archiecobbs Exp $
+ */
+
+#include "libjc.h"
+
+/*
+ * Generate a list of all other classes directly referenced by this classfile.
+ * We do this by parsing CONSTANT_Class constant pool entries, and
+ * field and method signatures.
+ *
+ * This list tells us which other classfiles we need to acquire to be
+ * able to generate the C code for this class. Note that in the process
+ * of acquiring any classfile, we automatically acquire the classfiles for
+ * that class' superclasses and superinterfaces, so we don't need to
+ * explicitly add them to the list.
+ *
+ * Similarly, this list tells us which other classes must remain loaded
+ * as long as this class is loaded (i.e., this class has implicit references
+ * to the dependent classes).
+ *
+ * Returns the number of entries, or -1 if there was an error.
+ * If unsuccessful an exception is stored.
+ *
+ * NOTE: The caller is responsible for freeing the returned array
+ * of _jc_class_ref structures.
+ *
+ * NOTE: The names in the array point into the 'cfile' data structure
+ * and therefore become invalid when it does.
+ */
+int
+_jc_gen_deplist(_jc_env *env, _jc_classfile *cfile, _jc_class_ref **arrayp)
+{
+ const size_t name_len = strlen(cfile->name);
+ _jc_class_ref *array = NULL;
+ _jc_class_ref dummy;
+ u_char ptype;
+ int num;
+ int i;
+
+pass2:
+ /* Reset counter */
+ num = 0;
+
+ /* Parse out referenced class names */
+ for (i = 0; i < cfile->num_constants; i++) {
+ _jc_cf_constant *const cp = &cfile->constants[i];
+ _jc_class_ref *const cref = array != NULL ?
+ &array[num] : &dummy;
+
+ if (cp->type != CONSTANT_Class)
+ continue;
+ _jc_parse_class_ref(cp->u.Class, cref, JNI_TRUE, &ptype);
+ if (ptype == _JC_TYPE_REFERENCE)
+ num++;
+ }
+ for (i = 0; i < cfile->num_fields; i++) {
+ _jc_cf_field *const field = &cfile->fields[i];
+ _jc_class_ref *const cref = array != NULL ?
+ &array[num] : &dummy;
+
+ _jc_parse_class_ref(field->descriptor, cref, JNI_FALSE, &ptype);
+ if (ptype == _JC_TYPE_REFERENCE)
+ num++;
+ }
+ for (i = 0; i < cfile->num_methods; i++) {
+ _jc_cf_method *const method = &cfile->methods[i];
+ const char *s;
+
+ for (s = method->descriptor; *s != '\0'; ) {
+ _jc_class_ref *const cref = array != NULL ?
+ &array[num] : &dummy;
+
+ s =_jc_parse_class_ref(s, cref, JNI_FALSE, &ptype);
+ if (ptype == _JC_TYPE_REFERENCE)
+ num++;
+ }
+ }
+
+ /* After first pass, allocate array and re-parse */
+ if (array == NULL) {
+ if ((array = _jc_vm_alloc(env,
+ (num + 1) * sizeof(*array))) == NULL)
+ return -1;
+ goto pass2;
+ }
+
+ /* Sort and uniqify the list, and remove self-references */
+ qsort(array, num, sizeof(*array), _jc_class_ref_compare);
+ for (i = 0; i < num; i++) {
+ _jc_class_ref *const first = &array[i];
+ int repeat;
+
+ /* Count how many copies of the same entry */
+ for (repeat = 0; i + repeat < num - 1; repeat++) {
+ _jc_class_ref *const next = &array[i + 1 + repeat];
+
+ if (_jc_class_ref_compare(first, next) != 0)
+ break;
+ }
+
+ /* Compress out repeats */
+ if (repeat > 0) {
+ memmove(&array[i + 1], &array[i + 1 + repeat],
+ ((num -= repeat) - (i + 1)) * sizeof(*array));
+ }
+
+ /* Remove self-references */
+ if (first->len == name_len
+ && strncmp(first->name, cfile->name, name_len) == 0) {
+ memmove(&array[i], &array[i + 1],
+ (--num - i) * sizeof(*array));
+ }
+ }
+
+ /* Done */
+ *arrayp = array;
+ return num;
+}
+
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/cfdump/main.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/cfdump/main.c?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/cfdump/main.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/cfdump/main.c Tue Oct 4 19:19:16 2005
@@ -0,0 +1,470 @@
+
+/*
+ * 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: main.c,v 1.10 2005/03/28 15:12:58 archiecobbs Exp $
+ */
+
+#include "cfdump.h"
+
+#define DEFAULT_CLASSPATH ".:" _JC_BOOT_CLASS_PATH
+
+static void dump_attr(_jc_env *env, int indent, _jc_classfile *cf,
+ _jc_cf_attr *attrs, int num);
+static void dump_const(_jc_cf_constant *cp);
+static void dump_string(const char *s);
+static void dump_code(_jc_env *env, _jc_classfile *cfile,
+ _jc_cf_bytecode *bytecode);
+static void usage(void) __attribute__ ((noreturn));
+
+int
+main(int ac, char **av)
+{
+ const char *classpath = DEFAULT_CLASSPATH;
+ char *classname;
+ _jc_classbytes *cb;
+ _jc_classfile *cf;
+ jboolean deps = JNI_FALSE;
+ int flags = 0;
+ _jc_env *env;
+ _jc_jvm *vm;
+ int i;
+
+ /* Initialize */
+ env = _jc_support_init();
+ vm = env->vm;
+
+ /* Parse command line */
+ for (av++, ac--; ac > 0 && **av == '-'; av++, ac--) {
+ if (strcmp(av[0], "-d") == 0)
+ deps = JNI_TRUE;
+ else if (strcmp(*av, "-e") == 0)
+ flags |= DUMP_ENCODE_NAMES;
+ else if (strcmp(*av, "-c") == 0)
+ flags |= DUMP_TRANS_CLOSURE;
+ else if (strcmp(*av, "-cp") == 0
+ || strcmp(*av, "-classpath") == 0) {
+ av++, ac--;
+ if (ac == 0)
+ usage();
+ classpath = *av;
+ } else
+ usage();
+ }
+ if (ac != 1)
+ usage();
+
+ /* Parse classpath */
+ if (_jc_parse_classpath(env, classpath,
+ &vm->boot.class_path, &vm->boot.class_path_len) != JNI_OK)
+ errx(1, "%s: %s", _jc_vmex_names[env->ex.num], env->ex.msg);
+
+ /* Get class name */
+ classname = av[0];
+ for (i = 0; classname[i] != '\0'; i++) {
+ if (classname[i] == '.')
+ classname[i] = '/';
+ }
+
+ /* Read in classfile */
+ if ((cb = _jc_bootcl_find_classbytes(env, classname, NULL)) == NULL) {
+ errx(1, "can't load class `%s': %s: %s", classname,
+ _jc_vmex_names[env->ex.num], env->ex.msg);
+ }
+
+ /* Parse classfile */
+ if ((cf = _jc_parse_classfile(env, cb, 2)) == NULL) {
+ errx(1, "can't parse class `%s': %s: %s", classname,
+ _jc_vmex_names[env->ex.num], env->ex.msg);
+ }
+ _jc_free_classbytes(&cb);
+
+ /* Just dump dependencies? */
+ if (deps) {
+ do_deps(env, cf, flags);
+ goto done;
+ }
+
+ /* Dump parsed classfile */
+ printf("version=\t%d.%d\n", cf->major_version, cf->minor_version);
+ printf("num_constants=\t%d\n", cf->num_constants);
+ for (i = 1; i < cf->num_constants; i++) {
+ _jc_cf_constant *const cp = &cf->constants[i - 1];
+
+ if (cp->type == 0)
+ continue;
+ printf("[%2d]\t", i);
+ dump_const(cp);
+ printf("\n");
+ }
+ printf("access_flags=\t0x%04x\n", cf->access_flags);
+ printf("name=\t\t%s\n", cf->name);
+ printf("superclass=\t%s\n", cf->superclass ? cf->superclass : "<NONE>");
+ printf("num_interfaces=\t%d\n", cf->num_interfaces);
+ for (i = 0; i < cf->num_interfaces; i++)
+ printf("[%2d]\t%s\n", i, cf->interfaces[i]);
+ printf("num_fields=\t%d\n", cf->num_fields);
+ for (i = 0; i < cf->num_fields; i++) {
+ _jc_cf_field *const field = &cf->fields[i];
+
+ printf("[%2d]\tname=\t\t%s\n", i, field->name);
+ printf("\tdescriptor=\t%s\n", field->descriptor);
+ printf("\taccess_flags=\t0x%04x\n", field->access_flags);
+ printf("\tnum_attributes=\t%d\n", field->num_attributes);
+ dump_attr(env, 1, cf, field->attributes, field->num_attributes);
+ }
+ printf("num_methods=\t%d\n", cf->num_methods);
+ for (i = 0; i < cf->num_methods; i++) {
+ _jc_cf_method *const method = &cf->methods[i];
+
+ printf("[%2d]\tname=\t\t%s\n", i, method->name);
+ printf("\tdescriptor=\t%s\n", method->descriptor);
+ printf("\taccess_flags=\t0x%04x\n", method->access_flags);
+ printf("\tnum_attributes=\t%d\n", method->num_attributes);
+ dump_attr(env, 1, cf, method->attributes,
+ method->num_attributes);
+ }
+ printf("num_attributes=\t%d\n", cf->num_attributes);
+ dump_attr(env, 0, cf, cf->attributes, cf->num_attributes);
+
+done:
+ /* Clean up and exit */
+ _jc_destroy_classfile(&cf);
+ return 0;
+}
+
+static void
+dump_attr(_jc_env *env, int indent, _jc_classfile *cf,
+ _jc_cf_attr *attrs, int num)
+{
+ int i;
+
+ for (i = 0; i < num; i++) {
+ _jc_cf_attr *const attr = &attrs[i];
+
+ if (indent)
+ printf("\t");
+ printf("[%2d]\t\%s: ", i, attr->name);
+ if (strcmp(attr->name, "ConstantValue") == 0) {
+ dump_const(attr->u.ConstantValue);
+ printf("\n");
+ } else if (strcmp(attr->name, "SourceFile") == 0)
+ printf("\"%s\"\n", attr->u.SourceFile);
+ else if (strcmp(attr->name, "Exceptions") == 0) {
+ const int num = attr->u.Exceptions.num_exceptions;
+ int j;
+
+ for (j = 0; j < num; j++) {
+ printf("%s%s", attr->u.Exceptions.exceptions[j],
+ j == num - 1 ? "\n" : ", ");
+ }
+ } else if (strcmp(attr->name, "InnerClasses") == 0) {
+ const int num = attr->u.InnerClasses.num_classes;
+ int j;
+
+ printf("%d classes\n", num);
+ for (j = 0; j < num; j++) {
+ _jc_cf_inner_class *const inner
+ = &attr->u.InnerClasses.classes[j];
+
+ printf("\t[%2d]\tInner: %s\n", j,
+ inner->inner != NULL ?
+ inner->inner : "none");
+ printf("\t\tOuter: %s\n",
+ inner->outer != NULL ?
+ inner->outer : "none");
+ printf("\t\t Name: %s\n",
+ inner->name != NULL ? inner->name : "none");
+ printf("\t\tFlags: 0x%04x\n",
+ inner->access_flags);
+ }
+ } else if (strcmp(attr->name, "Code") == 0)
+ dump_code(env, cf, &attr->u.Code);
+ else
+ printf("length %d\n", attr->length);
+ }
+}
+
+static void
+dump_const(_jc_cf_constant *cp)
+{
+ switch (cp->type) {
+ case CONSTANT_Long:
+ printf("0x%016llx", cp->u.Long);
+ break;
+ case CONSTANT_Float:
+ printf("%g (0x%08x)", cp->u.Float, cp->u.Integer);
+ break;
+ case CONSTANT_Double:
+ printf("%g (0x%016llx)", cp->u.Double, cp->u.Long);
+ break;
+ case CONSTANT_Integer:
+ printf("0x%08x", cp->u.Integer);
+ break;
+ case CONSTANT_String:
+ dump_string(cp->u.String);
+ break;
+ case CONSTANT_Class:
+ printf("class \"%s\"", cp->u.Class);
+ break;
+ case CONSTANT_Fieldref:
+ printf("class \"%s\" field \"%s\" descriptor \"%s\"",
+ cp->u.Ref.class, cp->u.Ref.name, cp->u.Ref.descriptor);
+ break;
+ case CONSTANT_Methodref:
+ printf("class \"%s\" method \"%s\" descriptor \"%s\"",
+ cp->u.Ref.class, cp->u.Ref.name, cp->u.Ref.descriptor);
+ break;
+ case CONSTANT_InterfaceMethodref:
+ printf("interface \"%s\" method \"%s\" descriptor \"%s\"",
+ cp->u.Ref.class, cp->u.Ref.name, cp->u.Ref.descriptor);
+ break;
+ case CONSTANT_NameAndType:
+ printf("name \"%s\" descriptor \"%s\"",
+ cp->u.NameAndType.name, cp->u.NameAndType.descriptor);
+ break;
+ case CONSTANT_Utf8:
+ dump_string(cp->u.Utf8);
+ break;
+ default:
+ assert(0);
+ break;
+ }
+}
+
+static void
+dump_string(const char *s)
+{
+ printf("\"");
+ while (*s != '\0') {
+ switch (*s) {
+ case '"':
+ case '\\':
+ printf("\\%c", *s);
+ break;
+ case '\v':
+ printf("\\v");
+ break;
+ case '\f':
+ printf("\\f");
+ break;
+ case '\t':
+ printf("\\t");
+ break;
+ case '\r':
+ printf("\\r");
+ break;
+ case '\n':
+ printf("\\n");
+ break;
+ default:
+ if (isprint(*s)) {
+ putchar(*s);
+ break;
+ }
+ printf("\\x%02x", *s & 0xff);
+ break;
+ }
+ s++;
+ }
+ printf("\"");
+}
+
+static void
+dump_code(_jc_env *env, _jc_classfile *cf, _jc_cf_bytecode *bytecode)
+{
+ _jc_cf_code codemem;
+ _jc_cf_code *const code = &codemem;
+ int i;
+
+ /* Parse bytecode */
+ if (_jc_parse_code(env, cf, bytecode, code) != JNI_OK) {
+ errx(1, "can't parse bytecode: %s: %s",
+ _jc_vmex_names[env->ex.num], env->ex.msg);
+ }
+
+ /* Dump parsed code */
+ printf("\t\tmax_stack=%d max_locals=%d #instructions=%d\n",
+ code->max_stack, code->max_locals, code->num_insns);
+ for (i = 0; i < code->num_insns; i++) {
+ _jc_cf_insn *const insn = &code->insns[i];
+ char nbuf[32];
+
+ snprintf(nbuf, sizeof(nbuf), "[%d]", i);
+ printf("\t%6s: %s", nbuf, _jc_bytecode_names[insn->opcode]);
+ switch (insn->opcode) {
+ case _JC_aload:
+ case _JC_astore:
+ case _JC_dload:
+ case _JC_dstore:
+ case _JC_fload:
+ case _JC_fstore:
+ case _JC_iload:
+ case _JC_istore:
+ case _JC_lload:
+ case _JC_lstore:
+ case _JC_ret:
+ printf(" local%d", insn->u.local.index);
+ break;
+ case _JC_anewarray:
+ case _JC_checkcast:
+ case _JC_instanceof:
+ case _JC_new:
+ printf(" %s", insn->u.type.name);
+ break;
+ case _JC_bipush:
+ printf(" %d", insn->u.immediate.value);
+ break;
+ case _JC_getfield:
+ case _JC_getstatic:
+ case _JC_putfield:
+ case _JC_putstatic:
+ printf(" %s.%s (%s)", insn->u.fieldref.field->class,
+ insn->u.fieldref.field->name,
+ insn->u.fieldref.field->descriptor);
+ break;
+ case _JC_goto:
+ case _JC_if_acmpeq:
+ case _JC_if_acmpne:
+ case _JC_if_icmpeq:
+ case _JC_if_icmpne:
+ case _JC_if_icmplt:
+ case _JC_if_icmpge:
+ case _JC_if_icmpgt:
+ case _JC_if_icmple:
+ case _JC_ifeq:
+ case _JC_ifne:
+ case _JC_iflt:
+ case _JC_ifge:
+ case _JC_ifgt:
+ case _JC_ifle:
+ case _JC_ifnonnull:
+ case _JC_ifnull:
+ case _JC_jsr:
+ printf(" [%d]", insn->u.branch.target);
+ break;
+ case _JC_iinc:
+ printf(" local%d %d", insn->u.iinc.index,
+ insn->u.iinc.value);
+ break;
+ case _JC_invokeinterface:
+ case _JC_invokespecial:
+ case _JC_invokestatic:
+ case _JC_invokevirtual:
+ printf(" %s.%s%s", insn->u.invoke.method->class,
+ insn->u.invoke.method->name,
+ insn->u.invoke.method->descriptor);
+ break;
+ case _JC_ldc:
+ printf(" ");
+ dump_const(insn->u.constant);
+ break;
+ case _JC_ldc2_w:
+ printf(" ");
+ dump_const(insn->u.constant);
+ break;
+ case _JC_lookupswitch:
+ {
+ _jc_cf_lookupswitch *const lsw = insn->u.lookupswitch;
+ int j;
+
+ printf(" default [%d]", lsw->default_target);
+ for (j = 0; j < lsw->num_pairs; j++) {
+ _jc_cf_lookup *const lookup = &lsw->pairs[j];
+
+ printf("\n\t\t%11d [%d]",
+ lookup->match, lookup->target);
+ }
+ break;
+ }
+ case _JC_tableswitch:
+ {
+ _jc_cf_tableswitch *const tsw = insn->u.tableswitch;
+ int j;
+
+ printf(" default [%d]", tsw->default_target);
+ for (j = 0; j < tsw->high - tsw->low + 1; j++) {
+ printf("\n\t\t%11d [%d]",
+ tsw->low + j, tsw->targets[j]);
+ }
+ break;
+ }
+ case _JC_multianewarray:
+ printf(" %d dims %s", insn->u.multianewarray.dims,
+ insn->u.multianewarray.type);
+ break;
+ case _JC_newarray:
+ printf(" %s[]", _jc_prim_names[insn->u.newarray.type]);
+ break;
+ case _JC_sipush:
+ printf(" %d", insn->u.immediate.value);
+ break;
+ default:
+ _JC_ASSERT(_jc_bytecode_names[insn->opcode] != NULL);
+ break;
+ }
+ printf("\n");
+ }
+
+ /* Dump traps */
+ if (code->num_traps > 0) {
+ printf("\t%d traps:\n", code->num_traps);
+ for (i = 0; i < code->num_traps; i++) {
+ _jc_cf_trap *const trap = &code->traps[i];
+ char bufs[3][32];
+
+ snprintf(bufs[0], sizeof(bufs[0]),
+ "[%d]", trap->start);
+ snprintf(bufs[1], sizeof(bufs[1]),
+ "[%d]", trap->end - 1);
+ snprintf(bufs[2], sizeof(bufs[2]),
+ "[%d]", trap->target);
+ printf("\t\t%-6s.. %-6s -> %-6s %s\n",
+ bufs[0], bufs[1], bufs[2],
+ trap->type != NULL ? trap->type : "");
+ }
+ }
+
+ /* Dump line number table */
+ if (code->num_linemaps > 0) {
+ printf("\t%d line number entries:\n", code->num_linemaps);
+ for (i = 0; i < code->num_linemaps; i++) {
+ _jc_cf_linemap *const linemap = &code->linemaps[i];
+ char buf[32];
+
+ snprintf(buf, sizeof(buf), "[%d]", linemap->index);
+ printf("\t\t%-6s line %d\n", buf, linemap->line);
+ }
+ }
+
+ /* Free parsed code */
+ _jc_destroy_code(code);
+}
+
+static void
+usage(void)
+{
+ fprintf(stderr, "Usage: cfdump [-d] [-e] [-c]"
+ " [-classpath path] class-name\n");
+ fprintf(stderr, "Options:\n"
+ " -classpath\tSpecify search path for class files\n"
+ " -cp\t\tSame as -classpath\n"
+ " -d\t\tDump class, superclass & superinterface dependencies\n"
+ " -c\t\tDo transitive closure of ``-d'' dependencies\n"
+ " -e\t\tEncode class names suitable for filenames\n");
+ exit(1);
+}
+
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/cfdump/support.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/cfdump/support.c?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/cfdump/support.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/cfdump/support.c Tue Oct 4 19:19:16 2005
@@ -0,0 +1,214 @@
+
+/*
+ * 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: support.c,v 1.4 2005/03/12 04:24:54 archiecobbs Exp $
+ */
+
+#include "cfdump.h"
+
+static _jc_class_loader phoney_loader;
+static _jc_env phoney_env;
+static _jc_jvm phoney_jvm;
+
+jboolean
+_jc_interp_z(_jc_env *env, ...)
+{
+ return 0;
+}
+
+jbyte
+_jc_interp_b(_jc_env *env, ...)
+{
+ return 0;
+}
+
+jchar
+_jc_interp_c(_jc_env *env, ...)
+{
+ return 0;
+}
+
+jshort
+_jc_interp_s(_jc_env *env, ...)
+{
+ return 0;
+}
+
+jint
+_jc_interp_i(_jc_env *env, ...)
+{
+ return 0;
+}
+
+jlong
+_jc_interp_j(_jc_env *env, ...)
+{
+ return 0;
+}
+
+jfloat
+_jc_interp_f(_jc_env *env, ...)
+{
+ return 0;
+}
+
+jdouble
+_jc_interp_d(_jc_env *env, ...)
+{
+ return 0;
+}
+
+_jc_object *
+_jc_interp_l(_jc_env *env, ...)
+{
+ return NULL;
+}
+
+void
+_jc_interp_v(_jc_env *env, ...)
+{
+}
+
+jboolean
+_jc_interp_native_z(_jc_env *env, ...)
+{
+ return 0;
+}
+
+jbyte
+_jc_interp_native_b(_jc_env *env, ...)
+{
+ return 0;
+}
+
+jchar
+_jc_interp_native_c(_jc_env *env, ...)
+{
+ return 0;
+}
+
+jshort
+_jc_interp_native_s(_jc_env *env, ...)
+{
+ return 0;
+}
+
+jint
+_jc_interp_native_i(_jc_env *env, ...)
+{
+ return 0;
+}
+
+jlong
+_jc_interp_native_j(_jc_env *env, ...)
+{
+ return 0;
+}
+
+jfloat
+_jc_interp_native_f(_jc_env *env, ...)
+{
+ return 0;
+}
+
+jdouble
+_jc_interp_native_d(_jc_env *env, ...)
+{
+ return 0;
+}
+
+_jc_object *
+_jc_interp_native_l(_jc_env *env, ...)
+{
+ return NULL;
+}
+
+void
+_jc_interp_native_v(_jc_env *env, ...)
+{
+}
+
+jint
+_jc_gc(_jc_env *env, jboolean urgent)
+{
+ return JNI_OK;
+}
+
+_jc_env *
+_jc_get_current_env()
+{
+ return &phoney_env;
+}
+
+_jc_env *
+_jc_support_init()
+{
+ _jc_mutex_init(&phoney_env, &phoney_loader.mutex);
+ _jc_uni_alloc_init(&phoney_loader.uni, 0, NULL);
+ phoney_jvm.boot.loader = &phoney_loader;
+ phoney_env.vm = &phoney_jvm;
+ return &phoney_env;
+}
+
+void
+_jc_fatal_error(_jc_jvm *vm __attribute__ ((unused)), const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ vwarnx(fmt, args);
+ va_end(args);
+ abort();
+}
+
+void
+_jc_post_exception(_jc_env *env, int num)
+{
+ _jc_post_exception_msg(env, num, NULL);
+}
+
+void
+_jc_post_exception_info(_jc_env *env)
+{
+ _jc_post_exception_msg(env, env->ex.num,
+ *env->ex.msg != '\0' ? env->ex.msg : NULL);
+}
+
+_jc_object *
+_jc_retrieve_exception(_jc_env *env, _jc_type *type)
+{
+ return NULL;
+}
+
+jboolean
+_jc_unpost_exception(_jc_env *env, int num)
+{
+ return JNI_TRUE;
+}
+
+void
+_jc_post_exception_msg(_jc_env *env __attribute__ ((unused)),
+ int num, const char *fmt, ...)
+{
+ assert(0);
+}
+
+void
+_jc_loader_wait(_jc_env *env, _jc_class_loader *loader)
+{
+}
+
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/jcgen/Makefile.am
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/jcgen/Makefile.am?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/jcgen/Makefile.am (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/jcgen/Makefile.am Tue Oct 4 19:19:16 2005
@@ -0,0 +1,8 @@
+## $Id: Makefile.am,v 1.2 2005/01/09 02:06:56 archiecobbs Exp $
+
+jcbindir= $(bindir)
+
+jcbin_SCRIPTS= jcgen
+
+EXTRA_DIST= jcgen.in
+
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/jcgen/jcgen.in
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/jcgen/jcgen.in?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/jcgen/jcgen.in (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/jcgen/jcgen.in Tue Oct 4 19:19:16 2005
@@ -0,0 +1,280 @@
+#!/bin/sh
+# $Id: jcgen.in,v 1.10 2005/05/15 20:38:55 archiecobbs Exp $
+
+# Constants
+prefix="@prefix@"
+exec_prefix="@exec_prefix@"
+JAVA="@JAVA@"
+CLASSPATH_HOME="@CLASSPATH_HOME@"
+JC_CFILES="@datadir@/jc/jc.zip"
+CP_CFILES="${CLASSPATH_HOME}/share/classpath/glibj.zip"
+SOOTDIR="@datadir@/jc"
+SOOT_CFILES="${SOOTDIR}/sootclasses-@SOOT_VERSION@.jar:${SOOTDIR}/jasminclasses-sable-@JASMIN_VERSION@.jar:${SOOTDIR}/polyglot-@POLYGLOT_VERSION@.jar"
+JC_CFLAGS="@JC_CFLAGS@"
+HOSTGCC="@HOSTGCC@"
+LIBDIR="@libdir@"
+LDFLAGS="@LDFLAGS@"
+INCLUDEDIR="@includedir@/jc"
+
+GENCLASS="org.dellroad.jc.BootstrapObjectGenerator"
+
+# Defaults
+USERCPATH="."
+VMCPATH="${JC_CFILES}:${SOOT_CFILES}"
+JCCPATH="${JC_CFILES}:${CP_CFILES}:${SOOT_CFILES}"
+BASE_SRCPATH="@datadir@/jc/src"
+USER_SRCPATH="${HOME}/.jc_src"
+OBJDIR="${HOME}/.jc_obj"
+INCDIR="${INCLUDEDIR}"
+VMFLAGS=""
+EXTRA_VERBOSE="false"
+VERBOSE="true"
+FORCE="false"
+DEBUG="true"
+EXECFILE=""
+
+# Check for which java to use
+[ -x "${JAVA}" ] || JAVA="@bindir@/jc"
+
+#
+# Output usage message
+#
+usage()
+{
+ echo 'Usage:' >&2
+ echo ' jcgen [options] pattern ...' >&2
+ echo ' jcgen -o filename [options] classname' >&2
+ echo ''
+ echo 'Options:' >&2
+ echo ' -srcpath path Prepend path to the search path for generated C source' >&2
+ echo ' files. The first component of the resulting path is also'
+ echo ' the destination for newly generated sources. This option' >&2
+ echo ' is cumulative and may be repeated multiple times.' >&2
+ echo ' -newsrcpath path Same as -srcpath but replaces the current search path' >&2
+ echo ' instead of prepending to it.' >&2
+ echo ' -objdir dir Specify destination for generated ELF objects.' >&2
+ echo ' -incdir dir Specify include directory for JC headers.' >&2
+ echo ' -classpath path Specify search path for user class files.' >&2
+# echo ' -vmclasspath path Specify JVM classpath.' >&2
+# echo ' -jcclasspath path Specify JC base classpath.' >&2
+ echo ' -vmopt opt Pass opt through to the Java VM command line.' >&2
+ echo ' -o filename Generate an executable invoking classname' >&2
+ echo ' -f Force regeneration even if not needed' >&2
+ echo ' -q Quiet mode (omit verbose output).' >&2
+ echo ' -v Increase verbosity.' >&2
+ echo " -s Don't include support for Java line numbers." >&2
+ echo ' -N Only generate source files, no ELF objects.' >&2
+ echo ''
+ echo 'Example patterns:' >&2
+ echo ' jan.foo.Bar Class jan.foo.Bar' >&2
+ echo ' jan.foo.* All classes in the jan.foo package' >&2
+ echo ' jan.foo.% Same' >&2
+ echo ' jan.foo.** All classes in jan.foo and all its subpackages' >&2
+ echo ' jan.foo.%% Same' >&2
+ echo ''
+ echo "Default -srcpath: ${USER_SRCPATH}:${BASE_SRCPATH}"
+ echo "Default -objdir: ${OBJDIR}"
+ echo "Default -incdir: ${INCDIR}"
+ echo "Default -classpath: ${USERCPATH}"
+# echo "Default -jcclasspath: ${JCCPATH}"
+# echo "Default -vmclasspath: ${VMCPATH}"
+ echo ''
+ exit 1
+}
+
+#
+# Parse command line
+#
+while :
+ do case "$1" in
+ -srcpath)
+ USER_SRCPATH="${2}:${USER_SRCPATH}"
+ shift
+ shift
+ ;;
+ -newsrcpath)
+ BASE_SRCPATH=""
+ USER_SRCPATH="${2}"
+ shift
+ shift
+ ;;
+ -objdir)
+ OBJDIR="${2}"
+ shift
+ shift
+ ;;
+ -classpath|-cp)
+ USERCPATH="$2"
+ shift
+ shift
+ ;;
+ -jcclasspath)
+ JCCPATH="$2"
+ shift
+ shift
+ ;;
+ -vmclasspath)
+ VMCPATH="$2"
+ shift
+ shift
+ ;;
+ -incdir)
+ INCDIR="$2"
+ shift
+ shift
+ ;;
+ -vmopt)
+ VMFLAGS="$2 ${VMFLAGS}"
+ shift
+ shift
+ ;;
+ -o)
+ EXECFILE="$2"
+ shift
+ shift
+ ;;
+ -f)
+ FORCE="true"
+ shift
+ ;;
+ -q)
+ VERBOSE="false"
+ shift
+ ;;
+ -N)
+ SOURCES_ONLY="true"
+ shift
+ ;;
+ -s)
+ DEBUG="false"
+ shift
+ ;;
+ -v)
+ EXTRA_VERBOSE="true"
+ shift
+ ;;
+ --)
+ shift
+ break
+ ;;
+ -*)
+ usage
+ ;;
+ *)
+ break
+ ;;
+ esac
+done
+
+case $# in
+ 0)
+ usage
+ ;;
+ *)
+ ;;
+esac
+
+# Handle '-o' flag
+if [ "${EXECFILE}" != "" ]; then
+
+ # Sanity check
+ if [ "$#" -ne 1 ] || echo "${@}" | grep -q '[%*]'; then
+ echo 'jcgen: only one class name allowed with "-o" flag' 1>&2
+ exit 1
+ fi
+
+ # Create flags to pass to JC itself
+ VMFLAGS="${VMFLAGS} -classpath ${USERCPATH}"
+
+ # Create temporary file and ensure we clean it up
+ CFILE="/tmp/jcgen$$.c"
+ trap cleanup TERM INT
+ cleanup()
+ {
+ rm -f ${CFILE}
+ }
+
+ # Construct main C file
+ cat > ${CFILE} <<- xxEOFxx
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <stdarg.h>
+ #include <string.h>
+ #include <errno.h>
+ #include <jc_invoke.h>
+
+ #define MAIN_CLASS "${@}"
+
+ static const char *const vmflags[] = {
+ "jc",
+xxEOFxx
+ for FLAG in ${VMFLAGS}; do
+ echo ${FLAG} | sed \
+ -e 's/\\/\\\\/g' -e 's/"/\\"/g' \
+ -e 's/^/ "/g' -e 's/$/",/g' >> ${CFILE}
+ done
+ echo '};' >> ${CFILE}
+ echo '#define NVMFLAGS (sizeof(vmflags) / sizeof(*vmflags))' >> ${CFILE}
+ cat >> ${CFILE} <<- xxEOFxx
+
+ int main(int ac, char **av)
+ {
+ const int jc_ac = NVMFLAGS + 1 + ac;
+ const char **jc_av;
+ int r;
+
+ if ((jc_av = malloc(jc_ac * sizeof(*jc_av))) == (void *)0) {
+ fprintf(stderr, "malloc: %s\n", strerror(errno));
+ exit(1);
+ }
+ memcpy(jc_av, vmflags, NVMFLAGS * sizeof(*jc_av));
+ jc_av[NVMFLAGS] = MAIN_CLASS;
+ memcpy(jc_av + NVMFLAGS + 1, av, ac * sizeof(jc_av));
+ r = _jc_invoke(jc_ac, jc_av, 1, vfprintf);
+ free(jc_av);
+ return r == _JC_RETURN_NORMAL ? 0 : 1;
+ }
+xxEOFxx
+
+ # Compile C file
+ CMD="${HOSTGCC} ${JC_CFLAGS} -I${INCLUDEDIR} \
+ -L${LIBDIR} ${LDFLAGS} -ljc -o ${EXECFILE} ${CFILE}"
+ if [ "${EXTRA_VERBOSE}" = "true" ]; then
+ echo ${CMD}
+ fi
+ ${CMD}
+ RTN=$?
+ rm -f ${CFILE}
+ exit ${RTN}
+fi
+
+# Set up various flags
+VMFLAGS="${VMFLAGS} -Djc.verbose.gen=${VERBOSE}"
+VMFLAGS="${VMFLAGS} -Djc.include.line.numbers=${DEBUG}"
+VMFLAGS="${VMFLAGS} -Djc.gen.force=${FORCE}"
+
+SRCPATH="${USER_SRCPATH}:${BASE_SRCPATH}"
+
+GENFLAGS=""
+
+if [ "${SOURCES_ONLY}" = "true" ]; then
+ GENFLAGS="${GENFLAGS} -N"
+fi
+
+if [ "${FORCE}" = "true" ]; then
+ GENFLAGS="${GENFLAGS} -f"
+fi
+
+# Run the command
+if [ "${EXTRA_VERBOSE}" = "true" ]; then
+ echo ${JAVA} ${VMFLAGS} -classpath "${VMCPATH}" \
+ "${GENCLASS}"${GENFLAGS} \
+ -classpath "${USERCPATH}:${JCCPATH}" \
+ -srcpath "${SRCPATH}" -objdir "${OBJDIR}" -incdir "${INCDIR}" "${@}"
+fi
+${JAVA} ${VMFLAGS} -classpath "${VMCPATH}" \
+ "${GENCLASS}"${GENFLAGS} \
+ -classpath "${USERCPATH}:${JCCPATH}" \
+ -srcpath "${SRCPATH}" -objdir "${OBJDIR}" -incdir "${INCDIR}" "${@}"
+exit $?
+
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/jcjavah/Makefile.am
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/jcjavah/Makefile.am?rev=294974&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/jcjavah/Makefile.am (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/tools/jcjavah/Makefile.am Tue Oct 4 19:19:16 2005
@@ -0,0 +1,30 @@
+## $Id: Makefile.am,v 1.2 2005/01/09 02:06:56 archiecobbs Exp $
+
+jcbindir= $(bindir)
+
+jcbin_PROGRAMS= jcjavah
+
+jcjavah_SOURCES= gen.c main.c javah.h
+
+nodist_jcjavah_SOURCES= $(top_srcdir)/tools/cfdump/support.c
+
+nodist_jcjavah_SOURCES+=$(top_srcdir)/libjc/cf_parse.c \
+ $(top_srcdir)/libjc/class_bytes.c \
+ $(top_srcdir)/libjc/cl_alloc.c \
+ $(top_srcdir)/libjc/misc.c \
+ $(top_srcdir)/libjc/mutex.c \
+ $(top_srcdir)/libjc/printf.c \
+ $(top_srcdir)/libjc/splay.c \
+ $(top_srcdir)/libjc/tables.c \
+ $(top_srcdir)/libjc/utf.c \
+ $(top_srcdir)/libjc/vm_alloc.c \
+ $(top_srcdir)/libjc/zip.c
+
+AM_CFLAGS= $(CFLAGS) @JC_CFLAGS@
+AM_CFLAGS+= -D_AC_INCLUDEDIR=\"$(includedir)\"
+AM_CFLAGS+= -D_AC_DATADIR=\"$(datadir)\"
+AM_CFLAGS+= -D_AC_LIBDIR=\"$(libdir)\"
+
+AM_CPPFLAGS= -I$(top_srcdir)/libjc
+AM_CPPFLAGS+= -I$(top_srcdir)/libjc/arch
+