tree-ssa-alias.c: Fix intervals to use [) syntax.
[official-gcc.git] / libjava / jni-libjvm.cc
blob1833eb7f34509ce92bb5fe9acf0c830c69f2d909
1 // jni-libjvm.cc - an implementation of the JNI invocation API.
3 /* Copyright (C) 2006 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9 details. */
11 #include <gcj/cni.h>
12 #include <gcj/javaprims.h>
13 #include <java-assert.h>
14 #include <jvm.h>
15 #include <jni.h>
17 using namespace gcj;
19 // Forward declarations.
20 extern struct JNIInvokeInterface_ _Jv_JNI_InvokeFunctions;
21 extern jint JNICALL _Jv_JNI_AttachCurrentThread (JavaVM *vm,
22 void **penv, void *args);
23 extern JavaVM *_Jv_the_vm;
25 jint JNICALL
26 JNI_GetDefaultJavaVMInitArgs (void *args)
28 jint version = * (jint *) args;
29 // Here we only support 1.2 and 1.4.
30 if (version != JNI_VERSION_1_2 && version != JNI_VERSION_1_4)
31 return JNI_EVERSION;
33 JavaVMInitArgs *ia = reinterpret_cast<JavaVMInitArgs *> (args);
34 ia->version = JNI_VERSION_1_4;
35 ia->nOptions = 0;
36 ia->options = NULL;
37 ia->ignoreUnrecognized = true;
39 return 0;
42 jint JNICALL
43 JNI_CreateJavaVM (JavaVM **vm, void **penv, void *args)
45 JvAssert (! _Jv_the_vm);
47 jint version = * (jint *) args;
48 // We only support 1.2 and 1.4.
49 if (version != JNI_VERSION_1_2 && version != JNI_VERSION_1_4)
50 return JNI_EVERSION;
52 JvVMInitArgs* vm_args = reinterpret_cast<JvVMInitArgs *> (args);
54 jint result = _Jv_CreateJavaVM (vm_args);
55 if (result)
56 return result;
58 // FIXME: synchronize
59 JavaVM *nvm = (JavaVM *) _Jv_MallocUnchecked (sizeof (JavaVM));
60 if (nvm == NULL)
61 return JNI_ERR;
62 nvm->functions = &_Jv_JNI_InvokeFunctions;
64 jint r =_Jv_JNI_AttachCurrentThread (nvm, penv, NULL);
65 if (r < 0)
66 return r;
68 _Jv_the_vm = nvm;
69 *vm = _Jv_the_vm;
71 return 0;
74 jint JNICALL
75 JNI_GetCreatedJavaVMs (JavaVM **vm_buffer, jsize buf_len, jsize *n_vms)
77 if (buf_len <= 0)
78 return JNI_ERR;
80 // We only support a single VM.
81 if (_Jv_the_vm != NULL)
83 vm_buffer[0] = _Jv_the_vm;
84 *n_vms = 1;
86 else
87 *n_vms = 0;
88 return 0;