25using System.Collections.Generic;
28using IKVM.ByteCode.Text;
34#if FIRST_PASS == false && IMPORTER == false && EXPORTER == false
38 sealed unsafe
partial class JNIVM
41 static readonly MUTF8Encoding MUTF8 = MUTF8Encoding.GetMUTF8(52);
43 internal static volatile bool jvmCreated;
44 internal static volatile bool jvmDestroyed;
47 static readonly Encoding platformEncoding = Encoding.Default;
49 static readonly Encoding platformEncoding = CodePagesEncodingProvider.Instance.GetEncoding(0);
52 internal static bool IsSupportedJNIVersion(
int version)
54 return version == JNIEnv.JNI_VERSION_1_1
55 || version == JNIEnv.JNI_VERSION_1_2
56 || version == JNIEnv.JNI_VERSION_1_4
57 || version == JNIEnv.JNI_VERSION_1_6
58 || version == JNIEnv.JNI_VERSION_1_8
67 static string DecodePlatformString(
byte* psz)
70 return p < 0 ? null : platformEncoding.GetString(psz, p);
85 if (!IsSupportedJNIVersion(pInitArgs->version) || pInitArgs->version ==
JNIEnv.JNI_VERSION_1_1)
86 return JNIEnv.JNI_EVERSION;
92 var properties =
new Dictionary<string, string>();
93 for (
int i = 0; i < pInitArgs->nOptions; i++)
95 var option = DecodePlatformString(pInitArgs->options[i].optionString);
99 if (option.StartsWith(
"-D"))
101 var idx = option.IndexOf(
'=', 2);
102 properties[option.Substring(2, idx - 2)] = option.Substring(idx + 1);
104 else if (option.StartsWith(
"-verbose"))
108 else if (option ==
"vfprintf" || option ==
"exit" || option ==
"abort")
112 else if (pInitArgs->ignoreUnrecognized ==
JNIEnv.JNI_FALSE)
119 foreach (var kvp
in properties)
125 return JavaVM.AttachCurrentThread(
JavaVM.pJavaVM, p_env,
null);
151 *ppvmBuf =
JavaVM.pJavaVM;
156 else if (nVMs !=
null)
static unsafe int GetIndexOfNull(byte *ptr, int max=int.MaxValue)
Gets the length of a pointer to a C string.
static int GetCreatedJavaVMs(JavaVM **ppvmBuf, jsize bufLen, jsize *nVMs)
Implements the JNI_GetCreatedJavaVMs native function.
static int CreateJavaVM(JavaVM **p_vm, void **p_env, void *vm_args)
Implements the JNI_CreateJavaVM native method.
static int GetDefaultJavaVMInitArgs(void *vm_args)
Implements the JNI_GetDefaultJavaVMInitArgs native function.
Property values loaded into the JVM from various sources.
static IDictionary< string, string > User
Gets the set of properties that are set by the user before initialization. Modification of values in ...
Main state of the running JVM.