private void runFinalizer(JavaLangAccess jla) { synchronized (this) { if (hasBeenFinalized()) return; remove(); } try { Object finalizee = this.get(); if (finalizee != null && !(finalizee instanceof java.lang.Enum)) { jla.invokeFinalize(finalizee); /* Clear stack slot containing this variable, to decrease the chances of false retention with a conservative GC */ finalizee = null; } } catch (Throwable x) { } super.clear(); }
static void runFinalization() { if (!VM.isBooted()) { return; } forkSecondaryFinalizer(new Runnable() { private volatile boolean running; public void run() { if (running) return; final JavaLangAccess jla = SharedSecrets.getJavaLangAccess(); running = true; for (;;) { Finalizer f = (Finalizer)queue.poll(); if (f == null) break; f.runFinalizer(jla); } } }); }
static void runAllFinalizers() { if (!VM.isBooted()) { return; } forkSecondaryFinalizer(new Runnable() { private volatile boolean running; public void run() { if (running) return; final JavaLangAccess jla = SharedSecrets.getJavaLangAccess(); running = true; for (;;) { Finalizer f; synchronized (lock) { f = unfinalized; if (f == null) break; unfinalized = f.next; } f.runFinalizer(jla); }}}); }
static TypeAnnotation[] parseAllTypeAnnotations(AnnotatedElement decl) { Class<?> container; byte[] rawBytes; JavaLangAccess javaLangAccess = sun.misc.SharedSecrets.getJavaLangAccess(); if (decl instanceof Class) { container = (Class<?>)decl; rawBytes = javaLangAccess.getRawClassTypeAnnotations(container); } else if (decl instanceof Executable) { container = ((Executable)decl).getDeclaringClass(); rawBytes = javaLangAccess.getRawExecutableTypeAnnotations((Executable)decl); } else { // Should not reach here. Assert? return EMPTY_TYPE_ANNOTATION_ARRAY; } return parseTypeAnnotations(rawBytes, javaLangAccess.getConstantPool(container), decl, container); }
private void inferCaller() { needToInferCaller = false; JavaLangAccess access = SharedSecrets.getJavaLangAccess(); Throwable throwable = new Throwable(); int depth = access.getStackTraceDepth(throwable); boolean lookingForLogger = true; for (int ix = 0; ix < depth; ix++) { // Calling getStackTraceElement directly prevents the VM // from paying the cost of building the entire stack frame. StackTraceElement frame = access.getStackTraceElement(throwable, ix); String cname = frame.getClassName(); boolean isLoggerImpl = isLoggerImplFrame(cname); if (lookingForLogger) { // Skip all frames until we have found the first logger frame. if (isLoggerImpl) { lookingForLogger = false; } } else { if (!isLoggerImpl) { // skip reflection call if (!cname.startsWith("java.lang.reflect.") && !cname.startsWith("sun.reflect.")) { // We've found the relevant frame. setSourceClassName(cname); setSourceMethodName(frame.getMethodName()); return; } } } } // We haven't found a suitable frame, so just punt. This is // OK as we are only committed to making a "best effort" here. }
private String getCallerInfo() { String sourceClassName = null; String sourceMethodName = null; JavaLangAccess access = SharedSecrets.getJavaLangAccess(); Throwable throwable = new Throwable(); int depth = access.getStackTraceDepth(throwable); String logClassName = "sun.util.logging.PlatformLogger"; boolean lookingForLogger = true; for (int ix = 0; ix < depth; ix++) { // Calling getStackTraceElement directly prevents the VM // from paying the cost of building the entire stack frame. StackTraceElement frame = access.getStackTraceElement(throwable, ix); String cname = frame.getClassName(); if (lookingForLogger) { // Skip all frames until we have found the first logger frame. if (cname.equals(logClassName)) { lookingForLogger = false; } } else { if (!cname.equals(logClassName)) { // We've found the relevant frame. sourceClassName = cname; sourceMethodName = frame.getMethodName(); break; } } } if (sourceClassName != null) { return sourceClassName + " " + sourceMethodName; } else { return name; } }