On Tuesday 03 Apr 2012 02:26:03 Zlatin Balevsky wrote: > On Mon, Apr 2, 2012 at 6:04 PM, Matthew Toseland > <toad at amphibian.dyndns.org> wrote: > > On Saturday 31 Mar 2012 04:03:10 Zlatin Balevsky wrote: > >> >> > >> >> In 'log.info("Random message: %s", obj.toString())' evaluating > >> >> 'obj.toString()' was what caused issues, not recycling it, or so I > >> >> believe to remember. > >> > > >> > You don't need to call obj.toString() before calling log() - just pass > >> > the object itself. Then the only overheads are: > >> > 1) Calling the function, including passing the arguments - which > >> > hopefully will be optimised to be on some stack (but the code might not > >> > have been JITted yet). > >> > 2) Looking up whether it needs to be logged. > >> > > >> > >> 3) Autoboxing because you cannot pass a primitive if the argument is > >> Object without creating a <? extends Number>. Small ranges of > >> Char/Short/Integer/Long values are cached, anything outside those will > >> end up creating garbage if the shouldLog predicate evaluate true even > >> once. > > > > Will it still autobox them if they are on the stack, and never used? > > If the isDebuggable predicate never evaluates true, then it's not a > problem. But if it evaluates true even once for the lifetime of the > loaded class it will create these objects. It's a quirk of current > hotspot jvm which will not affect production deployments but will > affect the developer: turning on debug logging for one class will > cause all primitives in all log statements to be instantiated. I had > some sample code earlier in the thread.
It means we need separate checks in each method, rather than having them all wrap the same generic logger method? -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part. URL: <https://emu.freenetproject.org/pipermail/devl/attachments/20120403/2ce6b476/attachment.pgp>