@PerformanceSensitive("allocation") private static boolean contains(final Marker parent, final Marker... localParents) { // performance tests showed a normal for loop is slightly faster than a for-each loop on some platforms // noinspection ForLoopReplaceableByForEach for (int i = 0, localParentsLength = localParents.length; i < localParentsLength; i++) { final Marker marker = localParents[i]; if (marker == parent) { return true; } } return false; }
@PerformanceSensitive public Class<?> getCallerClass(final int depth) { if (depth < 0) { throw new IndexOutOfBoundsException(Integer.toString(depth)); } // note that we need to add 1 to the depth value to compensate for this method, but not for the Method.invoke // since Reflection.getCallerClass ignores the call to Method.invoke() try { return (Class<?>) GET_CALLER_CLASS.invoke(null, depth + 1 + JDK_7u25_OFFSET); } catch (final Exception e) { // theoretically this could happen if the caller class were native code // TODO: return Object.class return null; } }
/** * Returns a {@code StringBuilder} containing the text representation of the specified primitive value. * This method will not allocate temporary objects. * * @param value the value whose text representation to return * @return a {@code StringBuilder} containing the text representation of the specified primitive value */ @PerformanceSensitive("allocation") public static StringBuilder box(final long value) { return getSB().append(value); }
/** * Returns a {@code StringBuilder} containing the text representation of the specified primitive value. * This method will not allocate temporary objects. * * @param value the value whose text representation to return * @return a {@code StringBuilder} containing the text representation of the specified primitive value */ @PerformanceSensitive("allocation") public static StringBuilder box(final float value) { return getSB().append(value); }
/** * Returns a {@code StringBuilder} containing the text representation of the specified primitive value. * This method will not allocate temporary objects. * * @param value the value whose text representation to return * @return a {@code StringBuilder} containing the text representation of the specified primitive value */ @PerformanceSensitive("allocation") public static StringBuilder box(final int value) { return getSB().append(value); }
/** * Returns a {@code StringBuilder} containing the text representation of the specified primitive value. * This method will not allocate temporary objects. * * @param value the value whose text representation to return * @return a {@code StringBuilder} containing the text representation of the specified primitive value */ @PerformanceSensitive("allocation") public static StringBuilder box(final char value) { return getSB().append(value); }
/** * Returns a {@code StringBuilder} containing the text representation of the specified primitive value. * This method will not allocate temporary objects. * * @param value the value whose text representation to return * @return a {@code StringBuilder} containing the text representation of the specified primitive value */ @PerformanceSensitive("allocation") public static StringBuilder box(final byte value) { return getSB().append(value); }
/** * Returns a {@code StringBuilder} containing the text representation of the specified primitive value. * This method will not allocate temporary objects. * * @param value the value whose text representation to return * @return a {@code StringBuilder} containing the text representation of the specified primitive value */ @PerformanceSensitive("allocation") public static StringBuilder box(final double value) { return getSB().append(value); }
@PerformanceSensitive public static Class<?> getCallerClass(final String fqcn) { return getCallerClass(fqcn, Strings.EMPTY); }
@PerformanceSensitive public static Class<?> getCallerClass(final Class<?> anchor) { return stackLocator.getCallerClass(anchor); }
@PerformanceSensitive public static Class<?> getCallerClass(final int depth) { return stackLocator.getCallerClass(depth + 1); }
@PerformanceSensitive public static Class<?> getCallerClass(final String fqcn, final String pkg) { return stackLocator.getCallerClass(fqcn, pkg); }
@PerformanceSensitive public static Stack<Class<?>> getCurrentStackTrace() { return stackLocator.getCurrentStackTrace(); }
/** * Returns a {@code StringBuilder} containing the text representation of the specified primitive value. * This method will not allocate temporary objects. * * @param value the value whose text representation to return * @return a {@code StringBuilder} containing the text representation of the specified primitive value */ @PerformanceSensitive("allocation") public static StringBuilder box(final short value) { return getSB().append(value); }
/** * Returns a {@code StringBuilder} containing the text representation of the specified primitive value. * This method will not allocate temporary objects. * * @param value the value whose text representation to return * @return a {@code StringBuilder} containing the text representation of the specified primitive value */ @PerformanceSensitive("allocation") public static StringBuilder box(final boolean value) { return getSB().append(value); }
@PerformanceSensitive public Class<?> getCallerClass(final Class<?> anchor) { boolean next = false; Class<?> clazz; for (int i = 2; null != (clazz = getCallerClass(i)); i++) { if (anchor.equals(clazz)) { next = true; continue; } if (next) { return clazz; } } return Object.class; }
@PerformanceSensitive public Class<?> getCallerClass(final String fqcn, final String pkg) { boolean next = false; Class<?> clazz; for (int i = 2; null != (clazz = getCallerClass(i)); i++) { if (fqcn.equals(clazz.getName())) { next = true; continue; } if (next && clazz.getName().startsWith(pkg)) { return clazz; } } // TODO: return Object.class return null; }
@PerformanceSensitive // NOTE: This is a hot method. Current implementation compiles to 30 bytes of byte code. // This is within the 35 byte MaxInlineSize threshold. Modify with care! private void logMessageSafely(final String fqcn, final Level level, final Marker marker, final Message msg, final Throwable throwable) { try { logMessageTrackRecursion(fqcn, level, marker, msg, throwable); } finally { // LOG4J2-1583 prevent scrambled logs when logging calls are nested (logging in toString()) ReusableMessageFactory.release(msg); } }
@PerformanceSensitive // NOTE: This is a hot method. Current implementation compiles to 26 bytes of byte code. // This is within the 35 byte MaxInlineSize threshold. Modify with care! private void tryLogMessage(final String fqcn, final Level level, final Marker marker, final Message msg, final Throwable throwable) { try { logMessage(fqcn, level, marker, msg, throwable); } catch (final Exception e) { // LOG4J2-1990 Log4j2 suppresses all exceptions that occur once application called the logger handleLogMessageException(e, fqcn, msg); } }
@PerformanceSensitive // NOTE: This is a hot method. Current implementation compiles to 29 bytes of byte code. // This is within the 35 byte MaxInlineSize threshold. Modify with care! private void logMessageTrackRecursion(final String fqcn, final Level level, final Marker marker, final Message msg, final Throwable throwable) { try { incrementRecursionDepth(); // LOG4J2-1518, LOG4J2-2031 tryLogMessage(fqcn, level, marker, msg, throwable); } finally { decrementRecursionDepth(); } }