48 private final boolean isJObject; 49 50 private HandleCleaner(Object wrapper, long handle, boolean isJObject) { 51 super(wrapper); 52 this.handle = handle; 53 this.isJObject = isJObject; 54 } 55 56 /** 57 * Releases the resource associated with {@code this.handle}. 58 */ 59 @Override 60 void doCleanup() { 61 if (isJObject) { 62 // The sentinel value used to denote a free handle is 63 // an object on the HotSpot heap so we call into the 64 // VM to set the target of an object handle to this value. 65 CompilerToVM.compilerToVM().deleteGlobalHandle(handle); 66 } else { 67 // Setting the target of a jmetadata handle to 0 enables 68 // the handle to be reused. See MetadataHandleBlock in 69 // jvmciRuntime.cpp for more info. 70 long value = UNSAFE.getLong(null, handle); 71 UNSAFE.compareAndSetLong(null, handle, value, 0); 72 } 73 } 74 75 /** 76 * Registers a cleaner for {@code handle}. The cleaner will release the handle some time after 77 * {@code wrapper} is detected as unreachable by the garbage collector. 78 */ 79 @SuppressWarnings("unused") 80 static void create(Object wrapper, long handle) { 81 assert wrapper instanceof IndirectHotSpotObjectConstantImpl || wrapper instanceof MetaspaceHandleObject; 82 new HandleCleaner(wrapper, handle, wrapper instanceof IndirectHotSpotObjectConstantImpl); 83 } 84 } | 48 private final boolean isJObject; 49 50 private HandleCleaner(Object wrapper, long handle, boolean isJObject) { 51 super(wrapper); 52 this.handle = handle; 53 this.isJObject = isJObject; 54 } 55 56 /** 57 * Releases the resource associated with {@code this.handle}. 58 */ 59 @Override 60 void doCleanup() { 61 if (isJObject) { 62 // The sentinel value used to denote a free handle is 63 // an object on the HotSpot heap so we call into the 64 // VM to set the target of an object handle to this value. 65 CompilerToVM.compilerToVM().deleteGlobalHandle(handle); 66 } else { 67 // Setting the target of a jmetadata handle to 0 enables 68 // the handle to be reused. See MetadataHandles in 69 // metadataHandles.hpp for more info. 70 long value = UNSAFE.getLong(null, handle); 71 UNSAFE.compareAndSetLong(null, handle, value, 0); 72 } 73 } 74 75 /** 76 * Registers a cleaner for {@code handle}. The cleaner will release the handle some time after 77 * {@code wrapper} is detected as unreachable by the garbage collector. 78 */ 79 @SuppressWarnings("unused") 80 static void create(Object wrapper, long handle) { 81 assert wrapper instanceof IndirectHotSpotObjectConstantImpl || wrapper instanceof MetaspaceHandleObject; 82 new HandleCleaner(wrapper, handle, wrapper instanceof IndirectHotSpotObjectConstantImpl); 83 } 84 } |