/* Latency-target value indicating that there's no active target
*/ privatestaticfinallong NO_TARGET = Long.MAX_VALUE;
/* The current latency target, or NO_TARGET if there is no target
*/ privatestaticlong latencyTarget = NO_TARGET;
/* The daemon thread that implements the latency-target mechanism, *ornullifthereispresentlynodaemonthread
*/ privatestaticThread daemon = null;
/* The lock object for the latencyTarget and daemon fields. The daemon *thread,ifitexists,waitsonthislockfornotificationthatthe *latencytargethaschanged.
*/ privatestaticclass LatencyLock extends Object { }; privatestatic Object lock = new LatencyLock();
@Override publicvoid run() { for (;;) { long l; synchronized (lock) {
l = latencyTarget; if (l == NO_TARGET) { /* No latency target, so exit */
GC.daemon = null; return;
}
long d = maxObjectInspectionAge(); if (d >= l) { /* Do a full collection. There is a remote possibility *thatafullcollectionwilloccurbetweenthetime *wesampletheinspectionageandthetimetheGC *actuallystarts,butthisissufficientlyunlikely *thatitdoesn'tseemworththemoreexpensiveJVM *interfacethatwouldberequired.
*/
System.gc();
d = 0;
}
/* Wait for the latency period to expire, *orfornotificationthattheperiodhaschanged
*/ try {
lock.wait(l - d);
} catch (InterruptedException x) { continue;
}
}
}
}
/* Create a new daemon thread */ publicstaticvoid create() {
PrivilegedAction<Void> pa = new PrivilegedAction<Void>() { publicVoid run() { Thread t = InnocuousThread.newSystemThread("RMI GC Daemon", new Daemon()); assert t.getContextClassLoader() == null;
t.setDaemon(true);
t.setPriority(Thread.MIN_PRIORITY + 1);
t.start();
GC.daemon = t; returnnull;
}};
AccessController.doPrivileged(pa);
}
}
/* Sets the latency target to the given value. *Mustbeinvokedwhileholdingthelock.
*/ privatestaticvoid setLatencyTarget(long ms) {
latencyTarget = ms; if (daemon == null) { /* Create a new daemon thread */
Daemon.create();
} else { /* Notify the existing daemon thread *thatthelateencytargethaschanged
*/
lock.notify();
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.