Hi Andrew, > Why not just use a straightforward static assignment to a final > variable as before?
A simple AWT app creates 79 loggers on solaris-i586 and 34 loggers on windows-i586. SwingSet2 creates a total of 85 loggers on solaris-i586 and 35 on windows-i586.
Improvement on client startup performance and memory footprint has always been one of our top features in the past releases.
As I noted in CR 6880089 (Revisit the number of AWT loggers to reduce the memory usage), there is no strong reason why we need such fine-grained loggers.
I fixed AWTEvent since it's one obvious candidate for lazy initialization. With my fix, I reduced the number of loggers by 4. Alex Potochkin also brought up a consistency issue that will be addressed by 6880089 or a new CR.
> Is it really that unlikely that fine() will be > called that we need not initialise this early? AWT team, can you confirm? > At the very least consider using the lazy holder idiom over volatile. Good point. Mandy Andrew John Hughes wrote:
2009/9/14 Mandy Chung <mandy.ch...@sun.com>: I'm curious as to why some of the initialisations are lazy and some are eager. Notably AWTEvent is changed from eager to lazy: public abstract class AWTEvent extends EventObject { - private static final Logger log = Logger.getLogger("java.awt.AWTEvent"); + private static volatile PlatformLogger log; + ... + + // log fine message to the java.awt.AWTEvent logger + private static void fine(String msg, Throwable t) { + if (log == null) { + log = PlatformLogger.getLogger("java.awt.AWTEvent"); + } + if (log.isLoggable(PlatformLogger.FINE)) { + log.fine(msg, t); + } + } + Although the use of volatile should ensure the correct ordering of operations, there is still the possibility of a minor race here as the if condition and its body are not atomic; thus there could be multiple calls to PlatformLogger.getLogger should a thread be interrupted between the check and the assignment. Why not just use a straightforward static assignment to a final variable as before? Is it really that unlikely that fine() will be called that we need not initialise this early?. At the very least consider using the lazy holder idiom over volatile.