LOG4J2-1274 update no-gc perf test now that TextEncoderHelper lives in 
o.a.l.l.core.layout


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

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 35a76e9a75410a6b2bea18f2883c641934c29114
Parents: 27619e0
Author: rpopma <[email protected]>
Authored: Sun Feb 21 20:52:58 2016 +0900
Committer: rpopma <[email protected]>
Committed: Sun Feb 21 20:52:58 2016 +0900

----------------------------------------------------------------------
 .../log4j/core/layout/TextEncoderHelper.java    |   2 +-
 .../logging/log4j/perf/nogc/NoGcLayout.java     |   3 +-
 .../log4j/perf/nogc/TextEncoderHelper.java      | 110 -------------------
 3 files changed, 3 insertions(+), 112 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/35a76e9a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/TextEncoderHelper.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/TextEncoderHelper.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/TextEncoderHelper.java
index 79f0123..3b81dd8 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/TextEncoderHelper.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/TextEncoderHelper.java
@@ -30,7 +30,7 @@ import java.util.Objects;
  *
  * @since 2.6
  */
-class TextEncoderHelper {
+public class TextEncoderHelper {
     private static final int DEFAULT_BUFFER_SIZE = 2048;
 
     private final Charset charset;

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/35a76e9a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/nogc/NoGcLayout.java
----------------------------------------------------------------------
diff --git 
a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/nogc/NoGcLayout.java 
b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/nogc/NoGcLayout.java
index 45ad87b..e49dc0f 100644
--- 
a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/nogc/NoGcLayout.java
+++ 
b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/nogc/NoGcLayout.java
@@ -20,6 +20,7 @@ import org.apache.logging.log4j.core.Layout;
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.layout.ByteBufferDestination;
 import org.apache.logging.log4j.core.layout.Encoder;
+import org.apache.logging.log4j.core.layout.TextEncoderHelper;
 import org.apache.logging.log4j.core.pattern.FormattingInfo;
 import org.apache.logging.log4j.core.pattern.PatternFormatter;
 
@@ -48,7 +49,7 @@ public class NoGcLayout implements Layout<Serializable>, 
Encoder<LogEvent> {
         StringBuilder text = toText(event, getCachedStringBuilder());
 
         TextEncoderHelper helper = getCachedHelper();
-        helper.encodeWithoutAllocation(text, destination);
+        helper.encodeText(text, destination);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/35a76e9a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/nogc/TextEncoderHelper.java
----------------------------------------------------------------------
diff --git 
a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/nogc/TextEncoderHelper.java
 
b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/nogc/TextEncoderHelper.java
deleted file mode 100644
index b7b813c..0000000
--- 
a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/nogc/TextEncoderHelper.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.perf.nogc;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CoderResult;
-import java.nio.charset.StandardCharsets;
-
-import org.apache.logging.log4j.core.layout.ByteBufferDestination;
-
-/**
- * TextEncoderHelper class proposed in LOG4J2-1274.
- */
-public class TextEncoderHelper {
-    private Charset charset;
-    private CharBuffer cachedCharBuffer = CharBuffer.wrap(new char[2048]);
-    private CharsetEncoder charsetEncoder;
-
-    public TextEncoderHelper(Charset charset) {
-        this.charset = charset;
-        charsetEncoder = charset.newEncoder();
-    }
-
-    public void encodeWithoutAllocation(StringBuilder text, 
ByteBufferDestination destination) {
-        charsetEncoder.reset();
-        ByteBuffer byteBuf = destination.getByteBuffer();
-        CharBuffer charBuf = getCachedCharBuffer();
-        charBuf.clear();
-        int start = 0;
-        int todoChars = text.length();
-        boolean endOfInput = true;
-        do {
-            int copied = copy(text, start, charBuf);
-            start += copied;
-            todoChars -= copied;
-            endOfInput = todoChars <= 0;
-
-            charBuf.flip();
-            CoderResult result;
-            do {
-                result = charsetEncoder.encode(charBuf, byteBuf, endOfInput);
-                if (result == CoderResult.OVERFLOW) { // byteBuf full
-                    // destination consumes contents
-                    // and returns byte buffer with more capacity
-                    byteBuf = destination.drain(byteBuf);
-                }
-            } while (result == CoderResult.OVERFLOW);
-        } while (!endOfInput);
-    }
-
-    /**
-     * Copies characters from the StringBuilder into the CharBuffer,
-     * starting at the specified offset and ending when either all
-     * characters have been copied or when the CharBuffer is full.
-     *
-     * @return the number of characters that were copied
-     */
-    int copy(StringBuilder source, int offset, CharBuffer destination) {
-        int length = Math.min(source.length() - offset, 
destination.capacity());
-        for (int i = offset; i < offset + length; i++) {
-            destination.put(source.charAt(i));
-        }
-        return length;
-    }
-
-    public CharBuffer getCachedCharBuffer() {
-        return cachedCharBuffer;
-    }
-
-    public static void main(String[] args) {
-        StringBuilder sb = new StringBuilder("AAA bbb ccc dddd eee fff ggg hhh 
iii");
-        ByteBufferDestination dest = new ByteBufferDestination() {
-            ByteBuffer buffer = ByteBuffer.wrap(new byte[4096]);
-
-            @Override
-            public ByteBuffer getByteBuffer() {
-                return buffer;
-            }
-
-            @Override
-            public ByteBuffer drain(ByteBuffer buf) {
-                buf.flip();
-                buf.clear();
-                return buf;
-            }
-        };
-        TextEncoderHelper helper = new 
TextEncoderHelper(StandardCharsets.UTF_8);
-        for (int i = 0; i < 100; i++) {
-            helper.encodeWithoutAllocation(sb, dest);
-            dest.drain(dest.getByteBuffer());
-        }
-    }
-}

Reply via email to