_JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_CreateJavaVM(JavaVM **vm, void **penv, void *args) {
// At the moment it's only possible to have one Java VM,
// since some of the runtime state is in global variables.
// We cannot use our mutex locks here, since they only work on
// Threads. We do an atomic compare and exchange to ensure only
// one thread can call this method at a time
if (Atomic::add(1, &num_vm_created) > 1) {
return JNI_ERR;
}
if (Atomic::xchg(1, &vm_created) == 1) {
Atomic::dec(&num_vm_created);
return JNI_ERR;
}
assert(vm_created == 1, "vm_created is true during the creation");
……