On Mon, Apr 2, 2012 at 6:04 PM, Matthew Toseland <t...@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. _______________________________________________ Devl mailing list Devl@freenetproject.org https://emu.freenetproject.org/cgi-bin/mailman/listinfo/devl