static int newGlobalRef(Object referent) { if (VM.VerifyAssertions) VM._assert(MemoryManager.validRef(ObjectReference.fromObject(referent))); if (free >= JNIGlobalRefs.length()) { AddressArray newGlobalRefs = AddressArray.create(JNIGlobalRefs.length() * 2); copyAndReplaceGlobalRefs(newGlobalRefs); } JNIGlobalRefs.set(free, Magic.objectAsAddress(referent)); return -free++; }
@Uninterruptible private static void copyAndReplaceGlobalRefs(AddressArray newGlobalRefs) { for (int i = 0; i < JNIGlobalRefs.length(); i++) { newGlobalRefs.set(i, JNIGlobalRefs.get(i)); } JNIGlobalRefs = newGlobalRefs; }