You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2016/08/31 16:27:06 UTC

[1/4] logging-log4j2 git commit: reset Unbox buffer to default size after configurable test

Repository: logging-log4j2
Updated Branches:
  refs/heads/LOG4J2-1349-gcfree-threadcontext b4c029593 -> 1e4f0ffbe


reset Unbox buffer to default size after configurable test


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/12ea0e2c
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/12ea0e2c
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/12ea0e2c

Branch: refs/heads/LOG4J2-1349-gcfree-threadcontext
Commit: 12ea0e2cfa4602bf6f4833fe404ff56998d2d833
Parents: b4c0295
Author: rpopma <rp...@apache.org>
Authored: Wed Aug 31 23:06:44 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Wed Aug 31 23:06:44 2016 +0900

----------------------------------------------------------------------
 .../logging/log4j/util/UnboxConfigurableTest.java    | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/12ea0e2c/log4j-api/src/test/java/org/apache/logging/log4j/util/UnboxConfigurableTest.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/util/UnboxConfigurableTest.java b/log4j-api/src/test/java/org/apache/logging/log4j/util/UnboxConfigurableTest.java
index 30d6ddc..ff72716 100644
--- a/log4j-api/src/test/java/org/apache/logging/log4j/util/UnboxConfigurableTest.java
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/util/UnboxConfigurableTest.java
@@ -16,6 +16,9 @@
  */
 package org.apache.logging.log4j.util;
 
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -33,8 +36,18 @@ public class UnboxConfigurableTest {
     }
 
     @AfterClass
-    public static void afterClass() {
+    public static void afterClass() throws Exception {
         System.clearProperty("log4j.unbox.ringbuffer.size");
+
+        // ensure subsequent tests (which assume 32 slots) pass
+        final Field field = Unbox.class.getDeclaredField("RINGBUFFER_SIZE");
+        field.setAccessible(true); // make non-private
+
+        final Field modifierField = Field.class.getDeclaredField("modifiers");
+        modifierField.setAccessible(true);
+        modifierField.setInt(field, field.getModifiers() &~ Modifier.FINAL); // make non-final
+
+        field.set(null, 32); // reset to default
     }
 
     @Test


[3/4] logging-log4j2 git commit: LOG4J2-1349 MutableContextDataSupplier::getMutableContextData must not return null

Posted by rp...@apache.org.
LOG4J2-1349 MutableContextDataSupplier::getMutableContextData must not return null


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/22ef566e
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/22ef566e
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/22ef566e

Branch: refs/heads/LOG4J2-1349-gcfree-threadcontext
Commit: 22ef566e6f3524a13b2d1a3ff238908f81b2326a
Parents: c0368da
Author: rpopma <rp...@apache.org>
Authored: Thu Sep 1 00:21:43 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Thu Sep 1 00:21:43 2016 +0900

----------------------------------------------------------------------
 .../spi/CopyOnWriteSortedArrayThreadContextMap.java     |  3 ++-
 .../spi/GarbageFreeSortedArrayThreadContextMap.java     | 12 ++++++++++--
 2 files changed, 12 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/22ef566e/log4j-api/src/main/java/org/apache/logging/log4j/spi/CopyOnWriteSortedArrayThreadContextMap.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/spi/CopyOnWriteSortedArrayThreadContextMap.java b/log4j-api/src/main/java/org/apache/logging/log4j/spi/CopyOnWriteSortedArrayThreadContextMap.java
index 1ccb81b..08bac8e 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/spi/CopyOnWriteSortedArrayThreadContextMap.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/spi/CopyOnWriteSortedArrayThreadContextMap.java
@@ -157,7 +157,8 @@ public class CopyOnWriteSortedArrayThreadContextMap implements ThreadContextMap,
      */
     @Override
     public MutableContextData getMutableContextData() {
-        return localMap.get();
+        final MutableContextData map = localMap.get();
+        return map == null ? createMutableContextData() : map;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/22ef566e/log4j-api/src/main/java/org/apache/logging/log4j/spi/GarbageFreeSortedArrayThreadContextMap.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/spi/GarbageFreeSortedArrayThreadContextMap.java b/log4j-api/src/main/java/org/apache/logging/log4j/spi/GarbageFreeSortedArrayThreadContextMap.java
index da04829..1fe2f65 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/spi/GarbageFreeSortedArrayThreadContextMap.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/spi/GarbageFreeSortedArrayThreadContextMap.java
@@ -139,7 +139,10 @@ public class GarbageFreeSortedArrayThreadContextMap implements ThreadContextMap,
 
     @Override
     public void clear() {
-        localMap.remove();
+        final MutableContextData map = localMap.get();
+        if (map != null) {
+            map.clear();
+        }
     }
 
     @Override
@@ -159,7 +162,12 @@ public class GarbageFreeSortedArrayThreadContextMap implements ThreadContextMap,
      */
     @Override
     public MutableContextData getMutableContextData() {
-        return localMap.get();
+        MutableContextData map = localMap.get();
+        if (map == null) {
+            map = createMutableContextData();
+            localMap.set(map);
+        }
+        return map;
     }
 
     @Override


[4/4] logging-log4j2 git commit: LOG4J2-1349 (work in progress) update tests to prove garbage-free context map does not allocate

Posted by rp...@apache.org.
LOG4J2-1349 (work in progress) update tests to prove garbage-free context map does not allocate


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/1e4f0ffb
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/1e4f0ffb
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/1e4f0ffb

Branch: refs/heads/LOG4J2-1349-gcfree-threadcontext
Commit: 1e4f0ffbe9ac4611ea11b0c23f0b2d0918760a3e
Parents: 22ef566
Author: rpopma <rp...@apache.org>
Authored: Thu Sep 1 01:26:54 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Thu Sep 1 01:26:54 2016 +0900

----------------------------------------------------------------------
 .../logging/log4j/core/GcFreeAsynchronousLoggingTest.java    | 2 ++
 .../org/apache/logging/log4j/core/GcFreeLoggingTestUtil.java | 8 ++++++--
 .../logging/log4j/core/GcFreeMixedSyncAyncLoggingTest.java   | 1 +
 .../logging/log4j/core/GcFreeSynchronousLoggingTest.java     | 1 +
 log4j-core/src/test/resources/gcFreeLogging.xml              | 2 +-
 .../src/test/resources/gcFreeMixedSyncAsyncLogging.xml       | 2 +-
 6 files changed, 12 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1e4f0ffb/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeAsynchronousLoggingTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeAsynchronousLoggingTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeAsynchronousLoggingTest.java
index 0e22b3e..188605a 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeAsynchronousLoggingTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeAsynchronousLoggingTest.java
@@ -35,6 +35,8 @@ public class GcFreeAsynchronousLoggingTest {
      * This code runs in a separate process, instrumented with the Google Allocation Instrumenter.
      */
     public static void main(final String[] args) throws Exception {
+        System.setProperty("log4j2.garbagefree.threadContextMap", "true");
+        System.setProperty("AsyncLogger.RingBufferSize", "128"); // minimum ringbuffer size
         System.setProperty("Log4jContextSelector", AsyncLoggerContextSelector.class.getName());
         GcFreeLoggingTestUtil.executeLogging("gcFreeLogging.xml", GcFreeAsynchronousLoggingTest.class);
     }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1e4f0ffb/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTestUtil.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTestUtil.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTestUtil.java
index 1394b9f..9cf4164 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTestUtil.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTestUtil.java
@@ -53,12 +53,16 @@ public class GcFreeLoggingTestUtil {
 
         // initialize LoggerContext etc.
         // This is not steady-state logging and will allocate objects.
+
+        ThreadContext.put("aKey", "value1");
+        ThreadContext.put("key2", "value2");
+
         final org.apache.logging.log4j.Logger logger = LogManager.getLogger(testClass.getName());
         logger.debug("debug not set");
         logger.fatal("This message is logged to the console");
         logger.error("Sample error message");
         logger.error("Test parameterized message {}", "param");
-        for (int i = 0; i < 128; i++) {
+        for (int i = 0; i < 256; i++) {
             logger.debug("ensure all ringbuffer slots have been used once"); // allocate MutableLogEvent.messageText
         }
 
@@ -128,7 +132,7 @@ public class GcFreeLoggingTestUtil {
         final String text = new String(Files.readAllBytes(tempFile.toPath()));
         final List<String> lines = Files.readAllLines(tempFile.toPath(), Charset.defaultCharset());
         final String className = cls.getSimpleName();
-        assertEquals(text, "FATAL o.a.l.l.c." + className + " [main]  This message is logged to the console",
+        assertEquals(text, "FATAL o.a.l.l.c." + className + " [main] value1 {aKey=value1, key2=value2} This message is logged to the console",
                 lines.get(0));
 
         final String LINESEP = System.getProperty("line.separator");

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1e4f0ffb/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeMixedSyncAyncLoggingTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeMixedSyncAyncLoggingTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeMixedSyncAyncLoggingTest.java
index 8ed4d1b..93ddc2c 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeMixedSyncAyncLoggingTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeMixedSyncAyncLoggingTest.java
@@ -34,6 +34,7 @@ public class GcFreeMixedSyncAyncLoggingTest {
      * This code runs in a separate process, instrumented with the Google Allocation Instrumenter.
      */
     public static void main(final String[] args) throws Exception {
+        System.setProperty("log4j2.garbagefree.threadContextMap", "true");
         System.setProperty("AsyncLoggerConfig.RingBufferSize", "128"); // minimum ringbuffer size
         GcFreeLoggingTestUtil.executeLogging("gcFreeMixedSyncAsyncLogging.xml", GcFreeMixedSyncAyncLoggingTest.class);
     }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1e4f0ffb/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeSynchronousLoggingTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeSynchronousLoggingTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeSynchronousLoggingTest.java
index 2d0ecc6..8ab6e8b 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeSynchronousLoggingTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeSynchronousLoggingTest.java
@@ -34,6 +34,7 @@ public class GcFreeSynchronousLoggingTest {
      * This code runs in a separate process, instrumented with the Google Allocation Instrumenter.
      */
     public static void main(final String[] args) throws Exception {
+        System.setProperty("log4j2.garbagefree.threadContextMap", "true");
         GcFreeLoggingTestUtil.executeLogging("gcFreeLogging.xml", GcFreeSynchronousLoggingTest.class);
     }
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1e4f0ffb/log4j-core/src/test/resources/gcFreeLogging.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/gcFreeLogging.xml b/log4j-core/src/test/resources/gcFreeLogging.xml
index d4b597f..81a8055 100644
--- a/log4j-core/src/test/resources/gcFreeLogging.xml
+++ b/log4j-core/src/test/resources/gcFreeLogging.xml
@@ -2,7 +2,7 @@
 <Configuration status="OFF">
   <Appenders>
     <Console name="Console" target="SYSTEM_OUT">
-      <PatternLayout pattern="%p %c{1.} [%t] %X{aKey} %m%ex%n" />
+      <PatternLayout pattern="%p %c{1.} [%t] %X{aKey} %X %m%ex%n" />
     </Console>
     <File name="File" fileName="target/gcfreefile.log" bufferedIO="false">
       <PatternLayout>

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1e4f0ffb/log4j-core/src/test/resources/gcFreeMixedSyncAsyncLogging.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/gcFreeMixedSyncAsyncLogging.xml b/log4j-core/src/test/resources/gcFreeMixedSyncAsyncLogging.xml
index f1937be..714ea9f 100644
--- a/log4j-core/src/test/resources/gcFreeMixedSyncAsyncLogging.xml
+++ b/log4j-core/src/test/resources/gcFreeMixedSyncAsyncLogging.xml
@@ -2,7 +2,7 @@
 <Configuration status="OFF">
   <Appenders>
     <Console name="Console" target="SYSTEM_OUT">
-      <PatternLayout pattern="%p %c{1.} [%t] %X{aKey} %m%ex%n" />
+      <PatternLayout pattern="%p %c{1.} [%t] %X{aKey} %X %m%ex%n" />
     </Console>
     <File name="File" fileName="target/gcfreefileMixed.log" bufferedIO="false">
       <PatternLayout>


[2/4] logging-log4j2 git commit: reset Unbox buffer to default size after configurable test

Posted by rp...@apache.org.
reset Unbox buffer to default size after configurable test


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/c0368dac
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/c0368dac
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/c0368dac

Branch: refs/heads/LOG4J2-1349-gcfree-threadcontext
Commit: c0368dac6a3f7749203e308a73a7b2d2429785a4
Parents: 12ea0e2
Author: rpopma <rp...@apache.org>
Authored: Thu Sep 1 00:20:23 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Thu Sep 1 00:20:23 2016 +0900

----------------------------------------------------------------------
 .../org/apache/logging/log4j/util/UnboxConfigurableTest.java   | 6 ++++++
 1 file changed, 6 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c0368dac/log4j-api/src/test/java/org/apache/logging/log4j/util/UnboxConfigurableTest.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/util/UnboxConfigurableTest.java b/log4j-api/src/test/java/org/apache/logging/log4j/util/UnboxConfigurableTest.java
index ff72716..01fb6a1 100644
--- a/log4j-api/src/test/java/org/apache/logging/log4j/util/UnboxConfigurableTest.java
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/util/UnboxConfigurableTest.java
@@ -48,6 +48,12 @@ public class UnboxConfigurableTest {
         modifierField.setInt(field, field.getModifiers() &~ Modifier.FINAL); // make non-final
 
         field.set(null, 32); // reset to default
+
+        final Field threadLocalField = Unbox.class.getDeclaredField("threadLocalState");
+        threadLocalField.setAccessible(true);
+        final ThreadLocal<?> threadLocal = (ThreadLocal<?>) threadLocalField.get(null);
+        threadLocal.remove();
+        threadLocalField.set(null, new ThreadLocal<>());
     }
 
     @Test