src/hotspot/share/prims/jni.cpp
changeset 59251 4cbfa5077d68
parent 59248 e92153ed8bdc
child 59252 623722a6aeb9
equal deleted inserted replaced
59250:a6deb69743d4 59251:4cbfa5077d68
  3809   // but __sync_lock_test_and_set is not guaranteed to do what we want
  3809   // but __sync_lock_test_and_set is not guaranteed to do what we want
  3810   // on all architectures.  So we check it works before relying on it.
  3810   // on all architectures.  So we check it works before relying on it.
  3811 #if defined(ZERO) && defined(ASSERT)
  3811 #if defined(ZERO) && defined(ASSERT)
  3812   {
  3812   {
  3813     jint a = 0xcafebabe;
  3813     jint a = 0xcafebabe;
  3814     jint b = Atomic::xchg((jint) 0xdeadbeef, &a);
  3814     jint b = Atomic::xchg(&a, (jint) 0xdeadbeef);
  3815     void *c = &a;
  3815     void *c = &a;
  3816     void *d = Atomic::xchg(&b, &c);
  3816     void *d = Atomic::xchg(&c, &b);
  3817     assert(a == (jint) 0xdeadbeef && b == (jint) 0xcafebabe, "Atomic::xchg() works");
  3817     assert(a == (jint) 0xdeadbeef && b == (jint) 0xcafebabe, "Atomic::xchg() works");
  3818     assert(c == &b && d == &a, "Atomic::xchg() works");
  3818     assert(c == &b && d == &a, "Atomic::xchg() works");
  3819   }
  3819   }
  3820 #endif // ZERO && ASSERT
  3820 #endif // ZERO && ASSERT
  3821 
  3821 
  3827   // one thread can call this method at a time
  3827   // one thread can call this method at a time
  3828 
  3828 
  3829   // We use Atomic::xchg rather than Atomic::add/dec since on some platforms
  3829   // We use Atomic::xchg rather than Atomic::add/dec since on some platforms
  3830   // the add/dec implementations are dependent on whether we are running
  3830   // the add/dec implementations are dependent on whether we are running
  3831   // on a multiprocessor Atomic::xchg does not have this problem.
  3831   // on a multiprocessor Atomic::xchg does not have this problem.
  3832   if (Atomic::xchg(1, &vm_created) == 1) {
  3832   if (Atomic::xchg(&vm_created, 1) == 1) {
  3833     return JNI_EEXIST;   // already created, or create attempt in progress
  3833     return JNI_EEXIST;   // already created, or create attempt in progress
  3834   }
  3834   }
  3835   if (Atomic::xchg(0, &safe_to_recreate_vm) == 0) {
  3835   if (Atomic::xchg(&safe_to_recreate_vm, 0) == 0) {
  3836     return JNI_ERR;  // someone tried and failed and retry not allowed.
  3836     return JNI_ERR;  // someone tried and failed and retry not allowed.
  3837   }
  3837   }
  3838 
  3838 
  3839   assert(vm_created == 1, "vm_created is true during the creation");
  3839   assert(vm_created == 1, "vm_created is true during the creation");
  3840 
  3840