= LogManager.getLogger(HelloLog.class); public static void main(String[] args) { LOGGER.debug("should not be printed !"); } } Log4J2: Performance of a disabled logger ??
= LogManager.getLogger(HelloLog.class); public static void main(String[] args) { LOGGER.debug(() -> "should not be printed !"); } } Performance of a disabled logger ?? (v2)
= LogManager.getLogger(HelloLog.class); public static void main(String[] args) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("should not be printed !"); } } } Performance of a disabled logger ?? (v3)
public enum Level { WARNING, DEBUG } final Level level; public SimpleLogger(Level level) { this.level = level; } public boolean isDebugEnabled() { return level.ordinal() - Level.DEBUG.ordinal() <= 0; } public void debug(String message) { if (isDebugEnabled()) { System.err.println(message); } } } class Enum { final int ordinal; public int ordinal() { return ordinal; } }
check once ! Do not box by default ! Richer API bindTo(), guardWithTest(), asType(), loop(), … Introduced in 7, used by Java for Lambda creation in 8+ String concatenation in 9+
trust_final_non_static_fields(ciInstanceKlass* holder) { // Never trust strangely unstable finals: System.out, etc. if (holder->name() == ciSymbol::java_lang_System()) return false; // Even if general trusting is disabled, trust system-built closures if (holder->is_in_package("java/lang/invoke") || holder->is_in_package("sun/invoke")) return true; // Trust VM anonymous classes, can't be serialized so no field hacking if (holder->is_anonymous()) return true; // Trust final fields in all boxed classes if (holder->is_box_klass()) return true; // Trust final fields in String if (holder->name() == ciSymbol::java_lang_String()) return true; return TrustFinalNonStaticFields; }
public int log4j2_sum() { int sum = 0; for(int i = 0; i < array.length; i++) { sum += array[i]; LOG4J2_LOGGER.debug("should not be printed !"); } return sum; } @Benchmark public int log4j2_foreach_sum() { int sum = 0; for(int value: array) { sum += value; LOG4J2_LOGGER.debug("should not be printed !"); } return sum; }
Can create guards from it Switch off with SP.invalidateAll(new SP[] { sp }) Implemented by recording invalidation dependencies between a SP and all JITed codes that depend on it => look Ma, no volatile !
– 3 levels of configuration module/package/class • A SwitchPoint at each level Output to SLF4J, LOG4J, JUL, System.Logger API https://github.com/forax/beautiful_logger
https://github.com/forax/exotic MostlyConstant A constant value that can be changed StableField A field that acts as a constant when initialized ConstantMemoizer A function that returns a constant if the argument is a constant StructuralCall To do structural call