Index: vm/include/jni.h =================================================================== --- vm/include/jni.h (revision 420746) +++ vm/include/jni.h (working copy) @@ -1727,4 +1727,17 @@ #endif }; + +#ifdef __cplusplus +extern "C" { +#endif + +JNIEXPORT jint JNICALL JNI_CreateJavaVM(JavaVM **p_vm, JNIEnv **p_env, void *vm_args); + +#ifdef __cplusplus +} +#endif + + + #endif /* _JNI_H_ */ Index: vm/vmcore/include/init.h =================================================================== --- vm/vmcore/include/init.h (revision 0) +++ vm/vmcore/include/init.h (revision 0) @@ -0,0 +1,45 @@ +/* + * Copyright 2005-2006 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. + */ +/** + * @author Euguene Ostrovsky + * @version $Revision: 1.1.2.1.4.6 $ + */ + + +#ifndef _INIT_H +#define _INIT_H + +#include "environment.h" + +bool vm_init(Global_Env *env); +int run_java_main(char *classname, char **j_argv, int j_argc, Global_Env *p_env); +int run_main_platform_specific(char *classname, char **j_argv, int j_argc, Global_Env *p_env); + +JavaVMInitArgs* parse_cmd_arguments(int argc, char *argv[], char **class_name, char **jar_file, int *p_java_arg_num); +void clear_vm_arguments(JavaVMInitArgs* vm_args); +void initialize_vm_cmd_state(Global_Env *p_env, JavaVMInitArgs* arguments); +void set_log_levels_from_cmd(JavaVMInitArgs* vm_arguments); +void parse_vm_arguments(Global_Env *p_env); +void parse_jit_arguments(JavaVMInitArgs* vm_arguments); +void print_generic_help(); + + +void create_vm(Global_Env *p_env, JavaVMInitArgs* vm_arguments); +void destroy_vm(Global_Env *p_env); +extern Global_Env env; + + +#endif //_INIT_H Index: vm/vmcore/src/init/init.h =================================================================== --- vm/vmcore/src/init/init.h (revision 420746) +++ vm/vmcore/src/init/init.h (working copy) @@ -1,39 +0,0 @@ -/* - * Copyright 2005-2006 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. - */ -/** - * @author Euguene Ostrovsky - * @version $Revision: 1.1.2.1.4.6 $ - */ - - -#ifndef _INIT_H -#define _INIT_H - -#include "environment.h" - -bool vm_init(Global_Env *env); -int run_java_main(char *classname, char **j_argv, int j_argc, Global_Env *p_env); -int run_main_platform_specific(char *classname, char **j_argv, int j_argc, Global_Env *p_env); - -JavaVMInitArgs* parse_cmd_arguments(int argc, char *argv[], char **class_name, char **jar_file, int *p_java_arg_num); -void clear_vm_arguments(JavaVMInitArgs* vm_args); -void initialize_vm_cmd_state(Global_Env *p_env, JavaVMInitArgs* arguments); -void set_log_levels_from_cmd(JavaVMInitArgs* vm_arguments); -void parse_vm_arguments(Global_Env *p_env); -void parse_jit_arguments(JavaVMInitArgs* vm_arguments); -void print_generic_help(); - -#endif //_INIT_H Index: vm/vmcore/src/init/parse_arguments.cpp =================================================================== --- vm/vmcore/src/init/parse_arguments.cpp (revision 420746) +++ vm/vmcore/src/init/parse_arguments.cpp (working copy) @@ -277,6 +277,9 @@ else if (strcmp(option, "-XcleanupOnExit") == 0) { add_pair_to_properties(p_env->properties, "vm.cleanupOnExit", "true"); } + else if (strcmp(option, "_org.apache.harmony.vmi.portlib") == 0) { + // Ignore _org.apache.harmony.vmi.portlib for now; + } else { ECHO("Unknown option " << option << USE_JAVA_HELP); LOGGER_EXIT(1); Index: vm/vmcore/src/init/vm_main.cpp =================================================================== --- vm/vmcore/src/init/vm_main.cpp (revision 420746) +++ vm/vmcore/src/init/vm_main.cpp (working copy) @@ -281,7 +281,7 @@ return 0; } //run_java_shutdown -static void create_vm(Global_Env *p_env, JavaVMInitArgs* vm_arguments) +void create_vm(Global_Env *p_env, JavaVMInitArgs* vm_arguments) { #ifdef PLATFORM_POSIX init_linux_thread_system(); @@ -541,7 +541,7 @@ return result; } //run_main -static void destroy_vm(Global_Env *p_env) +void destroy_vm(Global_Env *p_env) { assert(p_TLS_vmthread->app_status == thread_is_running); Index: vm/vmcore/src/jni/jni.cpp =================================================================== --- vm/vmcore/src/jni/jni.cpp (revision 420746) +++ vm/vmcore/src/jni/jni.cpp (working copy) @@ -42,6 +42,7 @@ #include "stack_trace.h" #include "m2n.h" #include "nogc.h" +#include "init.h" #include "Verifier_stub.h" @@ -1216,11 +1217,30 @@ return (jlong)CallStaticIntMethod(env, bbcl, id, buf); } + +VMEXPORT jint JNICALL JNI_CreateJavaVM(JavaVM **p_vm, JNIEnv **p_env, void *vm_args) { + static int called = 0; // this function can only be called once for now; + + init_log_system(); + TRACE2("jni", "CreateJavaVM called"); + if (called) { + WARN("Java Invoke :: multiple VM instances are not implemented"); + ASSERT(0, "Not implemented"); + return JNI_ERR; + } else { + create_vm(&env, (JavaVMInitArgs *)vm_args); + *p_env = &jni_env; + *p_vm = jni_env.vm; + return JNI_OK; + } +} + + VMEXPORT jint JNICALL DestroyVM(JavaVM*) { - WARN("Java Invoke :: DestroyVM not implemented"); - ASSERT(0, "Not implemented"); - return JNI_ERR; + TRACE2("jni", "DestroyVM called"); + destroy_vm(&env); + return JNI_OK; } VMEXPORT jint JNICALL AttachCurrentThread(JavaVM* vm, void** penv, void* UNREF args)