You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by Mikael Ståldal <mi...@magine.com> on 2016/02/23 15:56:12 UTC

GC lean way to convert StringBuilder to byte[]

Do we have any way to convert a StringBuilder to a byte[], without any
intermediate String?

It seems like org.apache.logging.log4j.core.util.StringEncoder cannot do it.

-- 
[image: MagineTV]

*Mikael Ståldal*
Senior software developer

*Magine TV*
mikael.staldal@magine.com
Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com

Privileged and/or Confidential Information may be contained in this
message. If you are not the addressee indicated in this message
(or responsible for delivery of the message to such a person), you may not
copy or deliver this message to anyone. In such case,
you should destroy this message and kindly notify the sender by reply
email.

Re: GC lean way to convert StringBuilder to byte[]

Posted by Remko Popma <re...@gmail.com>.
Have you tried writing a JMH benchmark to compare your implementation to
the getBytes(String) method?

On Mon, Mar 14, 2016 at 9:03 PM, Mikael Ståldal <mi...@magine.com>
wrote:

> I am mostly unsure about the new method I added to AbstractStringLayout. I
> am quite sure that it works, but will it give at least as good performance
> as the current one in all cases?
>
> protected byte[] getBytes(final CharSequence cseq) {
>     if (useCustomEncoding) { // rely on branch prediction to eliminate this check if false
>         return StringEncoder.encodeSingleByteChars(cseq);
>     }
>     ByteBuffer byteBuffer = charset.encode(CharBuffer.wrap(cseq));
>     if (byteBuffer.hasArray()) {
>         return byteBuffer.array();
>     } else {
>         byte[] bytes = new byte[byteBuffer.remaining()];
>         byteBuffer.get(bytes);
>         return bytes;
>     }
> }
>
>
>
> On Fri, Mar 11, 2016 at 10:56 PM, Remko Popma <re...@gmail.com>
> wrote:
>
>> Mikael,
>> Your changes impact the GelfLayout class mostly, right? Any other class
>> impacted that you want me to take a look at? If not and all tests pass I'd
>> say just go ahead and merge into master.
>>
>> About testing whether it is allocation-free, there is this ticket
>> LOG4J2-1295 <https://issues.apache.org/jira/browse/LOG4J2-1295> that is
>> still open.
>> I'm thinking the Allocation Instrumenter (
>> https://github.com/google/allocation-instrumenter) would serve our
>> purposes quite well here.
>> I just haven't had the bandwidth to look at this in more depth. It
>> probably involves running a test in a separate VM with the -agent startup
>> option. Not sure if we can do that with a normal log4j junit test or
>> whether the test would need to start a separate VM with the proper startup
>> options and then get that the result of that process via a file or
>> something... It would actually be really good if you or someone else could
>> make progress on that Jira, because I currently don't have the bandwidth to
>> look at it yet.
>>
>>
>> On Sat, Mar 12, 2016 at 1:33 AM, Mikael Ståldal <
>> mikael.staldal@magine.com> wrote:
>>
>>> Is it OK to merge to master?
>>>
>>> Remko, can you help me to verify that it is properly allocation-free
>>> (when using
>>> <GelfLayout host="test" compressionType="OFF"/>)?
>>>
>>>
>>> On Tue, Mar 8, 2016 at 5:36 PM, Mikael Ståldal <
>>> mikael.staldal@magine.com> wrote:
>>>
>>>> I did it a bit differently, but now there are unit tests for
>>>> GelfLayout.encode().
>>>>
>>>> On Tue, Mar 8, 2016 at 3:51 PM, Remko Popma <re...@gmail.com>
>>>> wrote:
>>>>
>>>>> I added some tests to PatternLayoutTest, please take a look.
>>>>>
>>>>> On Tue, Mar 8, 2016 at 11:56 PM, Mikael Ståldal <
>>>>> mikael.staldal@magine.com> wrote:
>>>>>
>>>>>> I have done some work on this for GelfLayout. Please review branch
>>>>>> gelf-layout-gc-free
>>>>>>
>>>>>> Is there any convenient way to unit-test the encode method of a
>>>>>> layout? Do we do that for PatternLayout?
>>>>>>
>>>>>> On Wed, Feb 24, 2016 at 11:48 PM, Ralph Goers <
>>>>>> ralph.goers@dslextreme.com> wrote:
>>>>>>
>>>>>>> I haven’t had 5 minutes to spare in 3 days. I will try to look at
>>>>>>> this tonight.
>>>>>>>
>>>>>>> Ralph
>>>>>>>
>>>>>>> On Feb 24, 2016, at 3:46 PM, Gary Gregory <ga...@gmail.com>
>>>>>>> wrote:
>>>>>>>
>>>>>>> On Tue, Feb 23, 2016 at 8:23 AM, Gary Gregory <
>>>>>>> garydgregory@gmail.com> wrote:
>>>>>>>
>>>>>>>> I see we now have:
>>>>>>>>
>>>>>>>>
>>>>>>>> org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer2
>>>>>>>>
>>>>>>>> Should we
>>>>>>>> deprecate org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer
>>>>>>>> and reimplement everything in terms of Serializer2, even if objects are
>>>>>>>> allocated?
>>>>>>>>
>>>>>>>
>>>>>>> Thoughts on this?
>>>>>>>
>>>>>>> Gary
>>>>>>>
>>>>>>>
>>>>>>>>
>>>>>>>> Gary
>>>>>>>>
>>>>>>>> On Tue, Feb 23, 2016 at 7:59 AM, Remko Popma <remko.popma@gmail.com
>>>>>>>> > wrote:
>>>>>>>>
>>>>>>>>> Layout now extends Encoder so now it has this method:
>>>>>>>>>
>>>>>>>>> encode(LogEvent source, ByteBufferDestination destination)
>>>>>>>>>
>>>>>>>>> PatternLayout implements this method. It delegates the work of
>>>>>>>>> converting the StringBuilder to bytes and writing these bytes into the
>>>>>>>>> ByteBufferDestination to the TextEncoderHelper class. No objects are
>>>>>>>>> created during this conversion.
>>>>>>>>>
>>>>>>>>> The final piece is (Rolling)RandomAccessFileAppender, whose
>>>>>>>>> manager implements ByteBufferDestination. This appender calls the #encode()
>>>>>>>>> methos on the layout (other managers still call Layout#toByteArray).
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Wed, Feb 24, 2016 at 12:47 AM, Mikael Ståldal <
>>>>>>>>> mikael.staldal@magine.com> wrote:
>>>>>>>>>
>>>>>>>>>> I cannot really find it.
>>>>>>>>>>
>>>>>>>>>> On Tue, Feb 23, 2016 at 3:59 PM, Remko Popma <
>>>>>>>>>> remko.popma@gmail.com> wrote:
>>>>>>>>>>
>>>>>>>>>>> Yes, that was implemented in
>>>>>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1274.
>>>>>>>>>>>
>>>>>>>>>>> Please also see the description and discussion in the epic
>>>>>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1270.
>>>>>>>>>>>
>>>>>>>>>>> Sent from my iPhone
>>>>>>>>>>>
>>>>>>>>>>> On 2016/02/23, at 23:56, Mikael Ståldal <
>>>>>>>>>>> mikael.staldal@magine.com> wrote:
>>>>>>>>>>>
>>>>>>>>>>> Do we have any way to convert a StringBuilder to a byte[],
>>>>>>>>>>> without any intermediate String?
>>>>>>>>>>>
>>>>>>>>>>> It seems like org.apache.logging.log4j.core.util.StringEncoder cannot
>>>>>>>>>>> do it.
>>>>>>>>>>>
>>>>>>>>>>> --
>>>>>>>>>>> [image: MagineTV]
>>>>>>>>>>>
>>>>>>>>>>> *Mikael Ståldal*
>>>>>>>>>>> Senior software developer
>>>>>>>>>>>
>>>>>>>>>>> *Magine TV*
>>>>>>>>>>> mikael.staldal@magine.com
>>>>>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>>>>>>   <http://www.magine.com/>
>>>>>>>>>>>
>>>>>>>>>>> Privileged and/or Confidential Information may be contained in
>>>>>>>>>>> this message. If you are not the addressee indicated in this message
>>>>>>>>>>> (or responsible for delivery of the message to such a person),
>>>>>>>>>>> you may not copy or deliver this message to anyone. In such case,
>>>>>>>>>>> you should destroy this message and kindly notify the sender by
>>>>>>>>>>> reply email.
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> --
>>>>>>>>>> [image: MagineTV]
>>>>>>>>>>
>>>>>>>>>> *Mikael Ståldal*
>>>>>>>>>> Senior software developer
>>>>>>>>>>
>>>>>>>>>> *Magine TV*
>>>>>>>>>> mikael.staldal@magine.com
>>>>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>>>>> <http://www.magine.com/>
>>>>>>>>>>
>>>>>>>>>> Privileged and/or Confidential Information may be contained in
>>>>>>>>>> this message. If you are not the addressee indicated in this message
>>>>>>>>>> (or responsible for delivery of the message to such a person),
>>>>>>>>>> you may not copy or deliver this message to anyone. In such case,
>>>>>>>>>> you should destroy this message and kindly notify the sender by
>>>>>>>>>> reply email.
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>>>>> <gg...@apache.org>
>>>>>>>> Java Persistence with Hibernate, Second Edition
>>>>>>>> <http://www.manning.com/bauer3/>
>>>>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>>>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>>>>>> Blog: http://garygregory.wordpress.com
>>>>>>>> Home: http://garygregory.com/
>>>>>>>> Tweet! http://twitter.com/GaryGregory
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>>>> <gg...@apache.org>
>>>>>>> Java Persistence with Hibernate, Second Edition
>>>>>>> <http://www.manning.com/bauer3/>
>>>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>>>>> Blog: http://garygregory.wordpress.com
>>>>>>> Home: http://garygregory.com/
>>>>>>> Tweet! http://twitter.com/GaryGregory
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> [image: MagineTV]
>>>>>>
>>>>>> *Mikael Ståldal*
>>>>>> Senior software developer
>>>>>>
>>>>>> *Magine TV*
>>>>>> mikael.staldal@magine.com
>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>
>>>>>> Privileged and/or Confidential Information may be contained in this
>>>>>> message. If you are not the addressee indicated in this message
>>>>>> (or responsible for delivery of the message to such a person), you
>>>>>> may not copy or deliver this message to anyone. In such case,
>>>>>> you should destroy this message and kindly notify the sender by reply
>>>>>> email.
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> [image: MagineTV]
>>>>
>>>> *Mikael Ståldal*
>>>> Senior software developer
>>>>
>>>> *Magine TV*
>>>> mikael.staldal@magine.com
>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>
>>>> Privileged and/or Confidential Information may be contained in this
>>>> message. If you are not the addressee indicated in this message
>>>> (or responsible for delivery of the message to such a person), you may
>>>> not copy or deliver this message to anyone. In such case,
>>>> you should destroy this message and kindly notify the sender by reply
>>>> email.
>>>>
>>>
>>>
>>>
>>> --
>>> [image: MagineTV]
>>>
>>> *Mikael Ståldal*
>>> Senior software developer
>>>
>>> *Magine TV*
>>> mikael.staldal@magine.com
>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>
>>> Privileged and/or Confidential Information may be contained in this
>>> message. If you are not the addressee indicated in this message
>>> (or responsible for delivery of the message to such a person), you may
>>> not copy or deliver this message to anyone. In such case,
>>> you should destroy this message and kindly notify the sender by reply
>>> email.
>>>
>>
>>
>
>
> --
> [image: MagineTV]
>
> *Mikael Ståldal*
> Senior software developer
>
> *Magine TV*
> mikael.staldal@magine.com
> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>
> Privileged and/or Confidential Information may be contained in this
> message. If you are not the addressee indicated in this message
> (or responsible for delivery of the message to such a person), you may not
> copy or deliver this message to anyone. In such case,
> you should destroy this message and kindly notify the sender by reply
> email.
>

Re: GC lean way to convert StringBuilder to byte[]

Posted by Mikael Ståldal <mi...@magine.com>.
It is only used by GelfLayout now, but my intention is that other layouts
should use it as well.

On Mon, Mar 14, 2016 at 11:03 AM, Mikael Ståldal <mi...@magine.com>
wrote:

> I am mostly unsure about the new method I added to AbstractStringLayout. I
> am quite sure that it works, but will it give at least as good performance
> as the current one in all cases?
>
> protected byte[] getBytes(final CharSequence cseq) {
>     if (useCustomEncoding) { // rely on branch prediction to eliminate this check if false
>         return StringEncoder.encodeSingleByteChars(cseq);
>     }
>     ByteBuffer byteBuffer = charset.encode(CharBuffer.wrap(cseq));
>     if (byteBuffer.hasArray()) {
>         return byteBuffer.array();
>     } else {
>         byte[] bytes = new byte[byteBuffer.remaining()];
>         byteBuffer.get(bytes);
>         return bytes;
>     }
> }
>
>
>
> On Fri, Mar 11, 2016 at 10:56 PM, Remko Popma <re...@gmail.com>
> wrote:
>
>> Mikael,
>> Your changes impact the GelfLayout class mostly, right? Any other class
>> impacted that you want me to take a look at? If not and all tests pass I'd
>> say just go ahead and merge into master.
>>
>> About testing whether it is allocation-free, there is this ticket
>> LOG4J2-1295 <https://issues.apache.org/jira/browse/LOG4J2-1295> that is
>> still open.
>> I'm thinking the Allocation Instrumenter (
>> https://github.com/google/allocation-instrumenter) would serve our
>> purposes quite well here.
>> I just haven't had the bandwidth to look at this in more depth. It
>> probably involves running a test in a separate VM with the -agent startup
>> option. Not sure if we can do that with a normal log4j junit test or
>> whether the test would need to start a separate VM with the proper startup
>> options and then get that the result of that process via a file or
>> something... It would actually be really good if you or someone else could
>> make progress on that Jira, because I currently don't have the bandwidth to
>> look at it yet.
>>
>>
>> On Sat, Mar 12, 2016 at 1:33 AM, Mikael Ståldal <
>> mikael.staldal@magine.com> wrote:
>>
>>> Is it OK to merge to master?
>>>
>>> Remko, can you help me to verify that it is properly allocation-free
>>> (when using
>>> <GelfLayout host="test" compressionType="OFF"/>)?
>>>
>>>
>>> On Tue, Mar 8, 2016 at 5:36 PM, Mikael Ståldal <
>>> mikael.staldal@magine.com> wrote:
>>>
>>>> I did it a bit differently, but now there are unit tests for
>>>> GelfLayout.encode().
>>>>
>>>> On Tue, Mar 8, 2016 at 3:51 PM, Remko Popma <re...@gmail.com>
>>>> wrote:
>>>>
>>>>> I added some tests to PatternLayoutTest, please take a look.
>>>>>
>>>>> On Tue, Mar 8, 2016 at 11:56 PM, Mikael Ståldal <
>>>>> mikael.staldal@magine.com> wrote:
>>>>>
>>>>>> I have done some work on this for GelfLayout. Please review branch
>>>>>> gelf-layout-gc-free
>>>>>>
>>>>>> Is there any convenient way to unit-test the encode method of a
>>>>>> layout? Do we do that for PatternLayout?
>>>>>>
>>>>>> On Wed, Feb 24, 2016 at 11:48 PM, Ralph Goers <
>>>>>> ralph.goers@dslextreme.com> wrote:
>>>>>>
>>>>>>> I haven’t had 5 minutes to spare in 3 days. I will try to look at
>>>>>>> this tonight.
>>>>>>>
>>>>>>> Ralph
>>>>>>>
>>>>>>> On Feb 24, 2016, at 3:46 PM, Gary Gregory <ga...@gmail.com>
>>>>>>> wrote:
>>>>>>>
>>>>>>> On Tue, Feb 23, 2016 at 8:23 AM, Gary Gregory <
>>>>>>> garydgregory@gmail.com> wrote:
>>>>>>>
>>>>>>>> I see we now have:
>>>>>>>>
>>>>>>>>
>>>>>>>> org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer2
>>>>>>>>
>>>>>>>> Should we
>>>>>>>> deprecate org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer
>>>>>>>> and reimplement everything in terms of Serializer2, even if objects are
>>>>>>>> allocated?
>>>>>>>>
>>>>>>>
>>>>>>> Thoughts on this?
>>>>>>>
>>>>>>> Gary
>>>>>>>
>>>>>>>
>>>>>>>>
>>>>>>>> Gary
>>>>>>>>
>>>>>>>> On Tue, Feb 23, 2016 at 7:59 AM, Remko Popma <remko.popma@gmail.com
>>>>>>>> > wrote:
>>>>>>>>
>>>>>>>>> Layout now extends Encoder so now it has this method:
>>>>>>>>>
>>>>>>>>> encode(LogEvent source, ByteBufferDestination destination)
>>>>>>>>>
>>>>>>>>> PatternLayout implements this method. It delegates the work of
>>>>>>>>> converting the StringBuilder to bytes and writing these bytes into the
>>>>>>>>> ByteBufferDestination to the TextEncoderHelper class. No objects are
>>>>>>>>> created during this conversion.
>>>>>>>>>
>>>>>>>>> The final piece is (Rolling)RandomAccessFileAppender, whose
>>>>>>>>> manager implements ByteBufferDestination. This appender calls the #encode()
>>>>>>>>> methos on the layout (other managers still call Layout#toByteArray).
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Wed, Feb 24, 2016 at 12:47 AM, Mikael Ståldal <
>>>>>>>>> mikael.staldal@magine.com> wrote:
>>>>>>>>>
>>>>>>>>>> I cannot really find it.
>>>>>>>>>>
>>>>>>>>>> On Tue, Feb 23, 2016 at 3:59 PM, Remko Popma <
>>>>>>>>>> remko.popma@gmail.com> wrote:
>>>>>>>>>>
>>>>>>>>>>> Yes, that was implemented in
>>>>>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1274.
>>>>>>>>>>>
>>>>>>>>>>> Please also see the description and discussion in the epic
>>>>>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1270.
>>>>>>>>>>>
>>>>>>>>>>> Sent from my iPhone
>>>>>>>>>>>
>>>>>>>>>>> On 2016/02/23, at 23:56, Mikael Ståldal <
>>>>>>>>>>> mikael.staldal@magine.com> wrote:
>>>>>>>>>>>
>>>>>>>>>>> Do we have any way to convert a StringBuilder to a byte[],
>>>>>>>>>>> without any intermediate String?
>>>>>>>>>>>
>>>>>>>>>>> It seems like org.apache.logging.log4j.core.util.StringEncoder cannot
>>>>>>>>>>> do it.
>>>>>>>>>>>
>>>>>>>>>>> --
>>>>>>>>>>> [image: MagineTV]
>>>>>>>>>>>
>>>>>>>>>>> *Mikael Ståldal*
>>>>>>>>>>> Senior software developer
>>>>>>>>>>>
>>>>>>>>>>> *Magine TV*
>>>>>>>>>>> mikael.staldal@magine.com
>>>>>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>>>>>>   <http://www.magine.com/>
>>>>>>>>>>>
>>>>>>>>>>> Privileged and/or Confidential Information may be contained in
>>>>>>>>>>> this message. If you are not the addressee indicated in this message
>>>>>>>>>>> (or responsible for delivery of the message to such a person),
>>>>>>>>>>> you may not copy or deliver this message to anyone. In such case,
>>>>>>>>>>> you should destroy this message and kindly notify the sender by
>>>>>>>>>>> reply email.
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> --
>>>>>>>>>> [image: MagineTV]
>>>>>>>>>>
>>>>>>>>>> *Mikael Ståldal*
>>>>>>>>>> Senior software developer
>>>>>>>>>>
>>>>>>>>>> *Magine TV*
>>>>>>>>>> mikael.staldal@magine.com
>>>>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>>>>> <http://www.magine.com/>
>>>>>>>>>>
>>>>>>>>>> Privileged and/or Confidential Information may be contained in
>>>>>>>>>> this message. If you are not the addressee indicated in this message
>>>>>>>>>> (or responsible for delivery of the message to such a person),
>>>>>>>>>> you may not copy or deliver this message to anyone. In such case,
>>>>>>>>>> you should destroy this message and kindly notify the sender by
>>>>>>>>>> reply email.
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>>>>> <gg...@apache.org>
>>>>>>>> Java Persistence with Hibernate, Second Edition
>>>>>>>> <http://www.manning.com/bauer3/>
>>>>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>>>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>>>>>> Blog: http://garygregory.wordpress.com
>>>>>>>> Home: http://garygregory.com/
>>>>>>>> Tweet! http://twitter.com/GaryGregory
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>>>> <gg...@apache.org>
>>>>>>> Java Persistence with Hibernate, Second Edition
>>>>>>> <http://www.manning.com/bauer3/>
>>>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>>>>> Blog: http://garygregory.wordpress.com
>>>>>>> Home: http://garygregory.com/
>>>>>>> Tweet! http://twitter.com/GaryGregory
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> [image: MagineTV]
>>>>>>
>>>>>> *Mikael Ståldal*
>>>>>> Senior software developer
>>>>>>
>>>>>> *Magine TV*
>>>>>> mikael.staldal@magine.com
>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>
>>>>>> Privileged and/or Confidential Information may be contained in this
>>>>>> message. If you are not the addressee indicated in this message
>>>>>> (or responsible for delivery of the message to such a person), you
>>>>>> may not copy or deliver this message to anyone. In such case,
>>>>>> you should destroy this message and kindly notify the sender by reply
>>>>>> email.
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> [image: MagineTV]
>>>>
>>>> *Mikael Ståldal*
>>>> Senior software developer
>>>>
>>>> *Magine TV*
>>>> mikael.staldal@magine.com
>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>
>>>> Privileged and/or Confidential Information may be contained in this
>>>> message. If you are not the addressee indicated in this message
>>>> (or responsible for delivery of the message to such a person), you may
>>>> not copy or deliver this message to anyone. In such case,
>>>> you should destroy this message and kindly notify the sender by reply
>>>> email.
>>>>
>>>
>>>
>>>
>>> --
>>> [image: MagineTV]
>>>
>>> *Mikael Ståldal*
>>> Senior software developer
>>>
>>> *Magine TV*
>>> mikael.staldal@magine.com
>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>
>>> Privileged and/or Confidential Information may be contained in this
>>> message. If you are not the addressee indicated in this message
>>> (or responsible for delivery of the message to such a person), you may
>>> not copy or deliver this message to anyone. In such case,
>>> you should destroy this message and kindly notify the sender by reply
>>> email.
>>>
>>
>>
>
>
> --
> [image: MagineTV]
>
> *Mikael Ståldal*
> Senior software developer
>
> *Magine TV*
> mikael.staldal@magine.com
> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>
> Privileged and/or Confidential Information may be contained in this
> message. If you are not the addressee indicated in this message
> (or responsible for delivery of the message to such a person), you may not
> copy or deliver this message to anyone. In such case,
> you should destroy this message and kindly notify the sender by reply
> email.
>



-- 
[image: MagineTV]

*Mikael Ståldal*
Senior software developer

*Magine TV*
mikael.staldal@magine.com
Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com

Privileged and/or Confidential Information may be contained in this
message. If you are not the addressee indicated in this message
(or responsible for delivery of the message to such a person), you may not
copy or deliver this message to anyone. In such case,
you should destroy this message and kindly notify the sender by reply
email.

Re: GC lean way to convert StringBuilder to byte[]

Posted by Mikael Ståldal <mi...@magine.com>.
I am mostly unsure about the new method I added to AbstractStringLayout. I
am quite sure that it works, but will it give at least as good performance
as the current one in all cases?

protected byte[] getBytes(final CharSequence cseq) {
    if (useCustomEncoding) { // rely on branch prediction to eliminate
this check if false
        return StringEncoder.encodeSingleByteChars(cseq);
    }
    ByteBuffer byteBuffer = charset.encode(CharBuffer.wrap(cseq));
    if (byteBuffer.hasArray()) {
        return byteBuffer.array();
    } else {
        byte[] bytes = new byte[byteBuffer.remaining()];
        byteBuffer.get(bytes);
        return bytes;
    }
}



On Fri, Mar 11, 2016 at 10:56 PM, Remko Popma <re...@gmail.com> wrote:

> Mikael,
> Your changes impact the GelfLayout class mostly, right? Any other class
> impacted that you want me to take a look at? If not and all tests pass I'd
> say just go ahead and merge into master.
>
> About testing whether it is allocation-free, there is this ticket
> LOG4J2-1295 <https://issues.apache.org/jira/browse/LOG4J2-1295> that is
> still open.
> I'm thinking the Allocation Instrumenter (
> https://github.com/google/allocation-instrumenter) would serve our
> purposes quite well here.
> I just haven't had the bandwidth to look at this in more depth. It
> probably involves running a test in a separate VM with the -agent startup
> option. Not sure if we can do that with a normal log4j junit test or
> whether the test would need to start a separate VM with the proper startup
> options and then get that the result of that process via a file or
> something... It would actually be really good if you or someone else could
> make progress on that Jira, because I currently don't have the bandwidth to
> look at it yet.
>
>
> On Sat, Mar 12, 2016 at 1:33 AM, Mikael Ståldal <mikael.staldal@magine.com
> > wrote:
>
>> Is it OK to merge to master?
>>
>> Remko, can you help me to verify that it is properly allocation-free
>> (when using
>> <GelfLayout host="test" compressionType="OFF"/>)?
>>
>>
>> On Tue, Mar 8, 2016 at 5:36 PM, Mikael Ståldal <mikael.staldal@magine.com
>> > wrote:
>>
>>> I did it a bit differently, but now there are unit tests for
>>> GelfLayout.encode().
>>>
>>> On Tue, Mar 8, 2016 at 3:51 PM, Remko Popma <re...@gmail.com>
>>> wrote:
>>>
>>>> I added some tests to PatternLayoutTest, please take a look.
>>>>
>>>> On Tue, Mar 8, 2016 at 11:56 PM, Mikael Ståldal <
>>>> mikael.staldal@magine.com> wrote:
>>>>
>>>>> I have done some work on this for GelfLayout. Please review branch
>>>>> gelf-layout-gc-free
>>>>>
>>>>> Is there any convenient way to unit-test the encode method of a
>>>>> layout? Do we do that for PatternLayout?
>>>>>
>>>>> On Wed, Feb 24, 2016 at 11:48 PM, Ralph Goers <
>>>>> ralph.goers@dslextreme.com> wrote:
>>>>>
>>>>>> I haven’t had 5 minutes to spare in 3 days. I will try to look at
>>>>>> this tonight.
>>>>>>
>>>>>> Ralph
>>>>>>
>>>>>> On Feb 24, 2016, at 3:46 PM, Gary Gregory <ga...@gmail.com>
>>>>>> wrote:
>>>>>>
>>>>>> On Tue, Feb 23, 2016 at 8:23 AM, Gary Gregory <garydgregory@gmail.com
>>>>>> > wrote:
>>>>>>
>>>>>>> I see we now have:
>>>>>>>
>>>>>>> org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer2
>>>>>>>
>>>>>>> Should we
>>>>>>> deprecate org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer
>>>>>>> and reimplement everything in terms of Serializer2, even if objects are
>>>>>>> allocated?
>>>>>>>
>>>>>>
>>>>>> Thoughts on this?
>>>>>>
>>>>>> Gary
>>>>>>
>>>>>>
>>>>>>>
>>>>>>> Gary
>>>>>>>
>>>>>>> On Tue, Feb 23, 2016 at 7:59 AM, Remko Popma <re...@gmail.com>
>>>>>>>  wrote:
>>>>>>>
>>>>>>>> Layout now extends Encoder so now it has this method:
>>>>>>>>
>>>>>>>> encode(LogEvent source, ByteBufferDestination destination)
>>>>>>>>
>>>>>>>> PatternLayout implements this method. It delegates the work of
>>>>>>>> converting the StringBuilder to bytes and writing these bytes into the
>>>>>>>> ByteBufferDestination to the TextEncoderHelper class. No objects are
>>>>>>>> created during this conversion.
>>>>>>>>
>>>>>>>> The final piece is (Rolling)RandomAccessFileAppender, whose manager
>>>>>>>> implements ByteBufferDestination. This appender calls the #encode() methos
>>>>>>>> on the layout (other managers still call Layout#toByteArray).
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On Wed, Feb 24, 2016 at 12:47 AM, Mikael Ståldal <
>>>>>>>> mikael.staldal@magine.com> wrote:
>>>>>>>>
>>>>>>>>> I cannot really find it.
>>>>>>>>>
>>>>>>>>> On Tue, Feb 23, 2016 at 3:59 PM, Remko Popma <
>>>>>>>>> remko.popma@gmail.com> wrote:
>>>>>>>>>
>>>>>>>>>> Yes, that was implemented in
>>>>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1274.
>>>>>>>>>>
>>>>>>>>>> Please also see the description and discussion in the epic
>>>>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1270.
>>>>>>>>>>
>>>>>>>>>> Sent from my iPhone
>>>>>>>>>>
>>>>>>>>>> On 2016/02/23, at 23:56, Mikael Ståldal <
>>>>>>>>>> mikael.staldal@magine.com> wrote:
>>>>>>>>>>
>>>>>>>>>> Do we have any way to convert a StringBuilder to a byte[],
>>>>>>>>>> without any intermediate String?
>>>>>>>>>>
>>>>>>>>>> It seems like org.apache.logging.log4j.core.util.StringEncoder cannot
>>>>>>>>>> do it.
>>>>>>>>>>
>>>>>>>>>> --
>>>>>>>>>> [image: MagineTV]
>>>>>>>>>>
>>>>>>>>>> *Mikael Ståldal*
>>>>>>>>>> Senior software developer
>>>>>>>>>>
>>>>>>>>>> *Magine TV*
>>>>>>>>>> mikael.staldal@magine.com
>>>>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>>>>> <http://www.magine.com/>
>>>>>>>>>>
>>>>>>>>>> Privileged and/or Confidential Information may be contained in
>>>>>>>>>> this message. If you are not the addressee indicated in this message
>>>>>>>>>> (or responsible for delivery of the message to such a person),
>>>>>>>>>> you may not copy or deliver this message to anyone. In such case,
>>>>>>>>>> you should destroy this message and kindly notify the sender by
>>>>>>>>>> reply email.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> [image: MagineTV]
>>>>>>>>>
>>>>>>>>> *Mikael Ståldal*
>>>>>>>>> Senior software developer
>>>>>>>>>
>>>>>>>>> *Magine TV*
>>>>>>>>> mikael.staldal@magine.com
>>>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>>>> <http://www.magine.com/>
>>>>>>>>>
>>>>>>>>> Privileged and/or Confidential Information may be contained in
>>>>>>>>> this message. If you are not the addressee indicated in this message
>>>>>>>>> (or responsible for delivery of the message to such a person), you
>>>>>>>>> may not copy or deliver this message to anyone. In such case,
>>>>>>>>> you should destroy this message and kindly notify the sender by
>>>>>>>>> reply email.
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>>>> <gg...@apache.org>
>>>>>>> Java Persistence with Hibernate, Second Edition
>>>>>>> <http://www.manning.com/bauer3/>
>>>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>>>>> Blog: http://garygregory.wordpress.com
>>>>>>> Home: http://garygregory.com/
>>>>>>> Tweet! http://twitter.com/GaryGregory
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>>> <gg...@apache.org>
>>>>>> Java Persistence with Hibernate, Second Edition
>>>>>> <http://www.manning.com/bauer3/>
>>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>>>> Blog: http://garygregory.wordpress.com
>>>>>> Home: http://garygregory.com/
>>>>>> Tweet! http://twitter.com/GaryGregory
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> [image: MagineTV]
>>>>>
>>>>> *Mikael Ståldal*
>>>>> Senior software developer
>>>>>
>>>>> *Magine TV*
>>>>> mikael.staldal@magine.com
>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>
>>>>> Privileged and/or Confidential Information may be contained in this
>>>>> message. If you are not the addressee indicated in this message
>>>>> (or responsible for delivery of the message to such a person), you may
>>>>> not copy or deliver this message to anyone. In such case,
>>>>> you should destroy this message and kindly notify the sender by reply
>>>>> email.
>>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> [image: MagineTV]
>>>
>>> *Mikael Ståldal*
>>> Senior software developer
>>>
>>> *Magine TV*
>>> mikael.staldal@magine.com
>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>
>>> Privileged and/or Confidential Information may be contained in this
>>> message. If you are not the addressee indicated in this message
>>> (or responsible for delivery of the message to such a person), you may
>>> not copy or deliver this message to anyone. In such case,
>>> you should destroy this message and kindly notify the sender by reply
>>> email.
>>>
>>
>>
>>
>> --
>> [image: MagineTV]
>>
>> *Mikael Ståldal*
>> Senior software developer
>>
>> *Magine TV*
>> mikael.staldal@magine.com
>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>
>> Privileged and/or Confidential Information may be contained in this
>> message. If you are not the addressee indicated in this message
>> (or responsible for delivery of the message to such a person), you may
>> not copy or deliver this message to anyone. In such case,
>> you should destroy this message and kindly notify the sender by reply
>> email.
>>
>
>


-- 
[image: MagineTV]

*Mikael Ståldal*
Senior software developer

*Magine TV*
mikael.staldal@magine.com
Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com

Privileged and/or Confidential Information may be contained in this
message. If you are not the addressee indicated in this message
(or responsible for delivery of the message to such a person), you may not
copy or deliver this message to anyone. In such case,
you should destroy this message and kindly notify the sender by reply
email.

Re: GC lean way to convert StringBuilder to byte[]

Posted by Matt Sicker <bo...@gmail.com>.
Why won't this hyperlink? Try again:

https://www.jclarity.com/product/censum-free-trial/

On 11 March 2016 at 16:26, Matt Sicker <bo...@gmail.com> wrote:

> Also, I mentioned this before in another thread:
>
> https://www.jclarity.com/product/censum-free-trial/
>
> This company will also give us licenses. It looks super useful for this
> scenario.
>
> On 11 March 2016 at 16:25, Matt Sicker <bo...@gmail.com> wrote:
>
>> YourKit gives us all licenses. We even mention them here:
>> http://logging.apache.org/log4j/2.x/thanks.html
>>
>> On 11 March 2016 at 16:21, Gary Gregory <ga...@gmail.com> wrote:
>>
>>> I have YourKit at work. Let me know what it is exactly you want to look
>>> at. Or you can get a free eval for a while. I'm not sure if we have a
>>> special deal with them for Apache or FOSS. Worth asking tho.
>>>
>>> G
>>>
>>> On Fri, Mar 11, 2016 at 1:56 PM, Remko Popma <re...@gmail.com>
>>> wrote:
>>>
>>>> Mikael,
>>>> Your changes impact the GelfLayout class mostly, right? Any other class
>>>> impacted that you want me to take a look at? If not and all tests pass I'd
>>>> say just go ahead and merge into master.
>>>>
>>>> About testing whether it is allocation-free, there is this ticket
>>>> LOG4J2-1295 <https://issues.apache.org/jira/browse/LOG4J2-1295> that
>>>> is still open.
>>>> I'm thinking the Allocation Instrumenter (
>>>> https://github.com/google/allocation-instrumenter) would serve our
>>>> purposes quite well here.
>>>> I just haven't had the bandwidth to look at this in more depth. It
>>>> probably involves running a test in a separate VM with the -agent startup
>>>> option. Not sure if we can do that with a normal log4j junit test or
>>>> whether the test would need to start a separate VM with the proper startup
>>>> options and then get that the result of that process via a file or
>>>> something... It would actually be really good if you or someone else could
>>>> make progress on that Jira, because I currently don't have the bandwidth to
>>>> look at it yet.
>>>>
>>>>
>>>> On Sat, Mar 12, 2016 at 1:33 AM, Mikael Ståldal <
>>>> mikael.staldal@magine.com> wrote:
>>>>
>>>>> Is it OK to merge to master?
>>>>>
>>>>> Remko, can you help me to verify that it is properly allocation-free
>>>>> (when using
>>>>> <GelfLayout host="test" compressionType="OFF"/>)?
>>>>>
>>>>>
>>>>> On Tue, Mar 8, 2016 at 5:36 PM, Mikael Ståldal <
>>>>> mikael.staldal@magine.com> wrote:
>>>>>
>>>>>> I did it a bit differently, but now there are unit tests for
>>>>>> GelfLayout.encode().
>>>>>>
>>>>>> On Tue, Mar 8, 2016 at 3:51 PM, Remko Popma <re...@gmail.com>
>>>>>> wrote:
>>>>>>
>>>>>>> I added some tests to PatternLayoutTest, please take a look.
>>>>>>>
>>>>>>> On Tue, Mar 8, 2016 at 11:56 PM, Mikael Ståldal <
>>>>>>> mikael.staldal@magine.com> wrote:
>>>>>>>
>>>>>>>> I have done some work on this for GelfLayout. Please review branch
>>>>>>>> gelf-layout-gc-free
>>>>>>>>
>>>>>>>> Is there any convenient way to unit-test the encode method of a
>>>>>>>> layout? Do we do that for PatternLayout?
>>>>>>>>
>>>>>>>> On Wed, Feb 24, 2016 at 11:48 PM, Ralph Goers <
>>>>>>>> ralph.goers@dslextreme.com> wrote:
>>>>>>>>
>>>>>>>>> I haven’t had 5 minutes to spare in 3 days. I will try to look at
>>>>>>>>> this tonight.
>>>>>>>>>
>>>>>>>>> Ralph
>>>>>>>>>
>>>>>>>>> On Feb 24, 2016, at 3:46 PM, Gary Gregory <ga...@gmail.com>
>>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>> On Tue, Feb 23, 2016 at 8:23 AM, Gary Gregory <
>>>>>>>>> garydgregory@gmail.com> wrote:
>>>>>>>>>
>>>>>>>>>> I see we now have:
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer2
>>>>>>>>>>
>>>>>>>>>> Should we
>>>>>>>>>> deprecate org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer
>>>>>>>>>> and reimplement everything in terms of Serializer2, even if objects are
>>>>>>>>>> allocated?
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Thoughts on this?
>>>>>>>>>
>>>>>>>>> Gary
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Gary
>>>>>>>>>>
>>>>>>>>>> On Tue, Feb 23, 2016 at 7:59 AM, Remko Popma <
>>>>>>>>>> remko.popma@gmail.com> wrote:
>>>>>>>>>>
>>>>>>>>>>> Layout now extends Encoder so now it has this method:
>>>>>>>>>>>
>>>>>>>>>>> encode(LogEvent source, ByteBufferDestination destination)
>>>>>>>>>>>
>>>>>>>>>>> PatternLayout implements this method. It delegates the work of
>>>>>>>>>>> converting the StringBuilder to bytes and writing these bytes into the
>>>>>>>>>>> ByteBufferDestination to the TextEncoderHelper class. No objects are
>>>>>>>>>>> created during this conversion.
>>>>>>>>>>>
>>>>>>>>>>> The final piece is (Rolling)RandomAccessFileAppender, whose
>>>>>>>>>>> manager implements ByteBufferDestination. This appender calls the #encode()
>>>>>>>>>>> methos on the layout (other managers still call Layout#toByteArray).
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On Wed, Feb 24, 2016 at 12:47 AM, Mikael Ståldal <
>>>>>>>>>>> mikael.staldal@magine.com> wrote:
>>>>>>>>>>>
>>>>>>>>>>>> I cannot really find it.
>>>>>>>>>>>>
>>>>>>>>>>>> On Tue, Feb 23, 2016 at 3:59 PM, Remko Popma <
>>>>>>>>>>>> remko.popma@gmail.com> wrote:
>>>>>>>>>>>>
>>>>>>>>>>>>> Yes, that was implemented in
>>>>>>>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1274.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Please also see the description and discussion in the epic
>>>>>>>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1270.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Sent from my iPhone
>>>>>>>>>>>>>
>>>>>>>>>>>>> On 2016/02/23, at 23:56, Mikael Ståldal <
>>>>>>>>>>>>> mikael.staldal@magine.com> wrote:
>>>>>>>>>>>>>
>>>>>>>>>>>>> Do we have any way to convert a StringBuilder to a byte[],
>>>>>>>>>>>>> without any intermediate String?
>>>>>>>>>>>>>
>>>>>>>>>>>>> It seems like org.apache.logging.log4j.core.util.
>>>>>>>>>>>>> StringEncoder cannot do it.
>>>>>>>>>>>>>
>>>>>>>>>>>>> --
>>>>>>>>>>>>> [image: MagineTV]
>>>>>>>>>>>>>
>>>>>>>>>>>>> *Mikael Ståldal*
>>>>>>>>>>>>> Senior software developer
>>>>>>>>>>>>>
>>>>>>>>>>>>> *Magine TV*
>>>>>>>>>>>>> mikael.staldal@magine.com
>>>>>>>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |
>>>>>>>>>>>>> www.magine.com  <http://www.magine.com/>
>>>>>>>>>>>>>
>>>>>>>>>>>>> Privileged and/or Confidential Information may be contained in
>>>>>>>>>>>>> this message. If you are not the addressee indicated in this message
>>>>>>>>>>>>> (or responsible for delivery of the message to such a person),
>>>>>>>>>>>>> you may not copy or deliver this message to anyone. In such case,
>>>>>>>>>>>>> you should destroy this message and kindly notify the sender
>>>>>>>>>>>>> by reply email.
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> --
>>>>>>>>>>>> [image: MagineTV]
>>>>>>>>>>>>
>>>>>>>>>>>> *Mikael Ståldal*
>>>>>>>>>>>> Senior software developer
>>>>>>>>>>>>
>>>>>>>>>>>> *Magine TV*
>>>>>>>>>>>> mikael.staldal@magine.com
>>>>>>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |
>>>>>>>>>>>> www.magine.com  <http://www.magine.com/>
>>>>>>>>>>>>
>>>>>>>>>>>> Privileged and/or Confidential Information may be contained in
>>>>>>>>>>>> this message. If you are not the addressee indicated in this message
>>>>>>>>>>>> (or responsible for delivery of the message to such a person),
>>>>>>>>>>>> you may not copy or deliver this message to anyone. In such case,
>>>>>>>>>>>> you should destroy this message and kindly notify the sender by
>>>>>>>>>>>> reply email.
>>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> --
>>>>>>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>>>>>>> <gg...@apache.org>
>>>>>>>>>> Java Persistence with Hibernate, Second Edition
>>>>>>>>>> <http://www.manning.com/bauer3/>
>>>>>>>>>> JUnit in Action, Second Edition
>>>>>>>>>> <http://www.manning.com/tahchiev/>
>>>>>>>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>>>>>>>> Blog: http://garygregory.wordpress.com
>>>>>>>>>> Home: http://garygregory.com/
>>>>>>>>>> Tweet! http://twitter.com/GaryGregory
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>>>>>> <gg...@apache.org>
>>>>>>>>> Java Persistence with Hibernate, Second Edition
>>>>>>>>> <http://www.manning.com/bauer3/>
>>>>>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>>>>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>>>>>>> Blog: http://garygregory.wordpress.com
>>>>>>>>> Home: http://garygregory.com/
>>>>>>>>> Tweet! http://twitter.com/GaryGregory
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>> [image: MagineTV]
>>>>>>>>
>>>>>>>> *Mikael Ståldal*
>>>>>>>> Senior software developer
>>>>>>>>
>>>>>>>> *Magine TV*
>>>>>>>> mikael.staldal@magine.com
>>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>>>
>>>>>>>> Privileged and/or Confidential Information may be contained in this
>>>>>>>> message. If you are not the addressee indicated in this message
>>>>>>>> (or responsible for delivery of the message to such a person), you
>>>>>>>> may not copy or deliver this message to anyone. In such case,
>>>>>>>> you should destroy this message and kindly notify the sender by
>>>>>>>> reply email.
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> [image: MagineTV]
>>>>>>
>>>>>> *Mikael Ståldal*
>>>>>> Senior software developer
>>>>>>
>>>>>> *Magine TV*
>>>>>> mikael.staldal@magine.com
>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>
>>>>>> Privileged and/or Confidential Information may be contained in this
>>>>>> message. If you are not the addressee indicated in this message
>>>>>> (or responsible for delivery of the message to such a person), you
>>>>>> may not copy or deliver this message to anyone. In such case,
>>>>>> you should destroy this message and kindly notify the sender by reply
>>>>>> email.
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> [image: MagineTV]
>>>>>
>>>>> *Mikael Ståldal*
>>>>> Senior software developer
>>>>>
>>>>> *Magine TV*
>>>>> mikael.staldal@magine.com
>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>
>>>>> Privileged and/or Confidential Information may be contained in this
>>>>> message. If you are not the addressee indicated in this message
>>>>> (or responsible for delivery of the message to such a person), you may
>>>>> not copy or deliver this message to anyone. In such case,
>>>>> you should destroy this message and kindly notify the sender by reply
>>>>> email.
>>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>> Java Persistence with Hibernate, Second Edition
>>> <http://www.manning.com/bauer3/>
>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>> Spring Batch in Action <http://www.manning.com/templier/>
>>> Blog: http://garygregory.wordpress.com
>>> Home: http://garygregory.com/
>>> Tweet! http://twitter.com/GaryGregory
>>>
>>
>>
>>
>> --
>> Matt Sicker <bo...@gmail.com>
>>
>
>
>
> --
> Matt Sicker <bo...@gmail.com>
>



-- 
Matt Sicker <bo...@gmail.com>

Re: GC lean way to convert StringBuilder to byte[]

Posted by Matt Sicker <bo...@gmail.com>.
Also, I mentioned this before in another thread:

https://www.jclarity.com/product/censum-free-trial/

This company will also give us licenses. It looks super useful for this
scenario.

On 11 March 2016 at 16:25, Matt Sicker <bo...@gmail.com> wrote:

> YourKit gives us all licenses. We even mention them here:
> http://logging.apache.org/log4j/2.x/thanks.html
>
> On 11 March 2016 at 16:21, Gary Gregory <ga...@gmail.com> wrote:
>
>> I have YourKit at work. Let me know what it is exactly you want to look
>> at. Or you can get a free eval for a while. I'm not sure if we have a
>> special deal with them for Apache or FOSS. Worth asking tho.
>>
>> G
>>
>> On Fri, Mar 11, 2016 at 1:56 PM, Remko Popma <re...@gmail.com>
>> wrote:
>>
>>> Mikael,
>>> Your changes impact the GelfLayout class mostly, right? Any other class
>>> impacted that you want me to take a look at? If not and all tests pass I'd
>>> say just go ahead and merge into master.
>>>
>>> About testing whether it is allocation-free, there is this ticket
>>> LOG4J2-1295 <https://issues.apache.org/jira/browse/LOG4J2-1295> that is
>>> still open.
>>> I'm thinking the Allocation Instrumenter (
>>> https://github.com/google/allocation-instrumenter) would serve our
>>> purposes quite well here.
>>> I just haven't had the bandwidth to look at this in more depth. It
>>> probably involves running a test in a separate VM with the -agent startup
>>> option. Not sure if we can do that with a normal log4j junit test or
>>> whether the test would need to start a separate VM with the proper startup
>>> options and then get that the result of that process via a file or
>>> something... It would actually be really good if you or someone else could
>>> make progress on that Jira, because I currently don't have the bandwidth to
>>> look at it yet.
>>>
>>>
>>> On Sat, Mar 12, 2016 at 1:33 AM, Mikael Ståldal <
>>> mikael.staldal@magine.com> wrote:
>>>
>>>> Is it OK to merge to master?
>>>>
>>>> Remko, can you help me to verify that it is properly allocation-free
>>>> (when using
>>>> <GelfLayout host="test" compressionType="OFF"/>)?
>>>>
>>>>
>>>> On Tue, Mar 8, 2016 at 5:36 PM, Mikael Ståldal <
>>>> mikael.staldal@magine.com> wrote:
>>>>
>>>>> I did it a bit differently, but now there are unit tests for
>>>>> GelfLayout.encode().
>>>>>
>>>>> On Tue, Mar 8, 2016 at 3:51 PM, Remko Popma <re...@gmail.com>
>>>>> wrote:
>>>>>
>>>>>> I added some tests to PatternLayoutTest, please take a look.
>>>>>>
>>>>>> On Tue, Mar 8, 2016 at 11:56 PM, Mikael Ståldal <
>>>>>> mikael.staldal@magine.com> wrote:
>>>>>>
>>>>>>> I have done some work on this for GelfLayout. Please review branch
>>>>>>> gelf-layout-gc-free
>>>>>>>
>>>>>>> Is there any convenient way to unit-test the encode method of a
>>>>>>> layout? Do we do that for PatternLayout?
>>>>>>>
>>>>>>> On Wed, Feb 24, 2016 at 11:48 PM, Ralph Goers <
>>>>>>> ralph.goers@dslextreme.com> wrote:
>>>>>>>
>>>>>>>> I haven’t had 5 minutes to spare in 3 days. I will try to look at
>>>>>>>> this tonight.
>>>>>>>>
>>>>>>>> Ralph
>>>>>>>>
>>>>>>>> On Feb 24, 2016, at 3:46 PM, Gary Gregory <ga...@gmail.com>
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>> On Tue, Feb 23, 2016 at 8:23 AM, Gary Gregory <
>>>>>>>> garydgregory@gmail.com> wrote:
>>>>>>>>
>>>>>>>>> I see we now have:
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer2
>>>>>>>>>
>>>>>>>>> Should we
>>>>>>>>> deprecate org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer
>>>>>>>>> and reimplement everything in terms of Serializer2, even if objects are
>>>>>>>>> allocated?
>>>>>>>>>
>>>>>>>>
>>>>>>>> Thoughts on this?
>>>>>>>>
>>>>>>>> Gary
>>>>>>>>
>>>>>>>>
>>>>>>>>>
>>>>>>>>> Gary
>>>>>>>>>
>>>>>>>>> On Tue, Feb 23, 2016 at 7:59 AM, Remko Popma <
>>>>>>>>> remko.popma@gmail.com> wrote:
>>>>>>>>>
>>>>>>>>>> Layout now extends Encoder so now it has this method:
>>>>>>>>>>
>>>>>>>>>> encode(LogEvent source, ByteBufferDestination destination)
>>>>>>>>>>
>>>>>>>>>> PatternLayout implements this method. It delegates the work of
>>>>>>>>>> converting the StringBuilder to bytes and writing these bytes into the
>>>>>>>>>> ByteBufferDestination to the TextEncoderHelper class. No objects are
>>>>>>>>>> created during this conversion.
>>>>>>>>>>
>>>>>>>>>> The final piece is (Rolling)RandomAccessFileAppender, whose
>>>>>>>>>> manager implements ByteBufferDestination. This appender calls the #encode()
>>>>>>>>>> methos on the layout (other managers still call Layout#toByteArray).
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On Wed, Feb 24, 2016 at 12:47 AM, Mikael Ståldal <
>>>>>>>>>> mikael.staldal@magine.com> wrote:
>>>>>>>>>>
>>>>>>>>>>> I cannot really find it.
>>>>>>>>>>>
>>>>>>>>>>> On Tue, Feb 23, 2016 at 3:59 PM, Remko Popma <
>>>>>>>>>>> remko.popma@gmail.com> wrote:
>>>>>>>>>>>
>>>>>>>>>>>> Yes, that was implemented in
>>>>>>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1274.
>>>>>>>>>>>>
>>>>>>>>>>>> Please also see the description and discussion in the epic
>>>>>>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1270.
>>>>>>>>>>>>
>>>>>>>>>>>> Sent from my iPhone
>>>>>>>>>>>>
>>>>>>>>>>>> On 2016/02/23, at 23:56, Mikael Ståldal <
>>>>>>>>>>>> mikael.staldal@magine.com> wrote:
>>>>>>>>>>>>
>>>>>>>>>>>> Do we have any way to convert a StringBuilder to a byte[],
>>>>>>>>>>>> without any intermediate String?
>>>>>>>>>>>>
>>>>>>>>>>>> It seems like org.apache.logging.log4j.core.util.StringEncoder cannot
>>>>>>>>>>>> do it.
>>>>>>>>>>>>
>>>>>>>>>>>> --
>>>>>>>>>>>> [image: MagineTV]
>>>>>>>>>>>>
>>>>>>>>>>>> *Mikael Ståldal*
>>>>>>>>>>>> Senior software developer
>>>>>>>>>>>>
>>>>>>>>>>>> *Magine TV*
>>>>>>>>>>>> mikael.staldal@magine.com
>>>>>>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |
>>>>>>>>>>>> www.magine.com  <http://www.magine.com/>
>>>>>>>>>>>>
>>>>>>>>>>>> Privileged and/or Confidential Information may be contained in
>>>>>>>>>>>> this message. If you are not the addressee indicated in this message
>>>>>>>>>>>> (or responsible for delivery of the message to such a person),
>>>>>>>>>>>> you may not copy or deliver this message to anyone. In such case,
>>>>>>>>>>>> you should destroy this message and kindly notify the sender by
>>>>>>>>>>>> reply email.
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> --
>>>>>>>>>>> [image: MagineTV]
>>>>>>>>>>>
>>>>>>>>>>> *Mikael Ståldal*
>>>>>>>>>>> Senior software developer
>>>>>>>>>>>
>>>>>>>>>>> *Magine TV*
>>>>>>>>>>> mikael.staldal@magine.com
>>>>>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>>>>>>   <http://www.magine.com/>
>>>>>>>>>>>
>>>>>>>>>>> Privileged and/or Confidential Information may be contained in
>>>>>>>>>>> this message. If you are not the addressee indicated in this message
>>>>>>>>>>> (or responsible for delivery of the message to such a person),
>>>>>>>>>>> you may not copy or deliver this message to anyone. In such case,
>>>>>>>>>>> you should destroy this message and kindly notify the sender by
>>>>>>>>>>> reply email.
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>>>>>> <gg...@apache.org>
>>>>>>>>> Java Persistence with Hibernate, Second Edition
>>>>>>>>> <http://www.manning.com/bauer3/>
>>>>>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>>>>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>>>>>>> Blog: http://garygregory.wordpress.com
>>>>>>>>> Home: http://garygregory.com/
>>>>>>>>> Tweet! http://twitter.com/GaryGregory
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>>>>> <gg...@apache.org>
>>>>>>>> Java Persistence with Hibernate, Second Edition
>>>>>>>> <http://www.manning.com/bauer3/>
>>>>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>>>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>>>>>> Blog: http://garygregory.wordpress.com
>>>>>>>> Home: http://garygregory.com/
>>>>>>>> Tweet! http://twitter.com/GaryGregory
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> [image: MagineTV]
>>>>>>>
>>>>>>> *Mikael Ståldal*
>>>>>>> Senior software developer
>>>>>>>
>>>>>>> *Magine TV*
>>>>>>> mikael.staldal@magine.com
>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>>
>>>>>>> Privileged and/or Confidential Information may be contained in this
>>>>>>> message. If you are not the addressee indicated in this message
>>>>>>> (or responsible for delivery of the message to such a person), you
>>>>>>> may not copy or deliver this message to anyone. In such case,
>>>>>>> you should destroy this message and kindly notify the sender by
>>>>>>> reply email.
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> [image: MagineTV]
>>>>>
>>>>> *Mikael Ståldal*
>>>>> Senior software developer
>>>>>
>>>>> *Magine TV*
>>>>> mikael.staldal@magine.com
>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>
>>>>> Privileged and/or Confidential Information may be contained in this
>>>>> message. If you are not the addressee indicated in this message
>>>>> (or responsible for delivery of the message to such a person), you may
>>>>> not copy or deliver this message to anyone. In such case,
>>>>> you should destroy this message and kindly notify the sender by reply
>>>>> email.
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> [image: MagineTV]
>>>>
>>>> *Mikael Ståldal*
>>>> Senior software developer
>>>>
>>>> *Magine TV*
>>>> mikael.staldal@magine.com
>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>
>>>> Privileged and/or Confidential Information may be contained in this
>>>> message. If you are not the addressee indicated in this message
>>>> (or responsible for delivery of the message to such a person), you may
>>>> not copy or deliver this message to anyone. In such case,
>>>> you should destroy this message and kindly notify the sender by reply
>>>> email.
>>>>
>>>
>>>
>>
>>
>> --
>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>> Java Persistence with Hibernate, Second Edition
>> <http://www.manning.com/bauer3/>
>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>> Spring Batch in Action <http://www.manning.com/templier/>
>> Blog: http://garygregory.wordpress.com
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
>>
>
>
>
> --
> Matt Sicker <bo...@gmail.com>
>



-- 
Matt Sicker <bo...@gmail.com>

Re: GC lean way to convert StringBuilder to byte[]

Posted by Matt Sicker <bo...@gmail.com>.
YourKit gives us all licenses. We even mention them here:
http://logging.apache.org/log4j/2.x/thanks.html

On 11 March 2016 at 16:21, Gary Gregory <ga...@gmail.com> wrote:

> I have YourKit at work. Let me know what it is exactly you want to look
> at. Or you can get a free eval for a while. I'm not sure if we have a
> special deal with them for Apache or FOSS. Worth asking tho.
>
> G
>
> On Fri, Mar 11, 2016 at 1:56 PM, Remko Popma <re...@gmail.com>
> wrote:
>
>> Mikael,
>> Your changes impact the GelfLayout class mostly, right? Any other class
>> impacted that you want me to take a look at? If not and all tests pass I'd
>> say just go ahead and merge into master.
>>
>> About testing whether it is allocation-free, there is this ticket
>> LOG4J2-1295 <https://issues.apache.org/jira/browse/LOG4J2-1295> that is
>> still open.
>> I'm thinking the Allocation Instrumenter (
>> https://github.com/google/allocation-instrumenter) would serve our
>> purposes quite well here.
>> I just haven't had the bandwidth to look at this in more depth. It
>> probably involves running a test in a separate VM with the -agent startup
>> option. Not sure if we can do that with a normal log4j junit test or
>> whether the test would need to start a separate VM with the proper startup
>> options and then get that the result of that process via a file or
>> something... It would actually be really good if you or someone else could
>> make progress on that Jira, because I currently don't have the bandwidth to
>> look at it yet.
>>
>>
>> On Sat, Mar 12, 2016 at 1:33 AM, Mikael Ståldal <
>> mikael.staldal@magine.com> wrote:
>>
>>> Is it OK to merge to master?
>>>
>>> Remko, can you help me to verify that it is properly allocation-free
>>> (when using
>>> <GelfLayout host="test" compressionType="OFF"/>)?
>>>
>>>
>>> On Tue, Mar 8, 2016 at 5:36 PM, Mikael Ståldal <
>>> mikael.staldal@magine.com> wrote:
>>>
>>>> I did it a bit differently, but now there are unit tests for
>>>> GelfLayout.encode().
>>>>
>>>> On Tue, Mar 8, 2016 at 3:51 PM, Remko Popma <re...@gmail.com>
>>>> wrote:
>>>>
>>>>> I added some tests to PatternLayoutTest, please take a look.
>>>>>
>>>>> On Tue, Mar 8, 2016 at 11:56 PM, Mikael Ståldal <
>>>>> mikael.staldal@magine.com> wrote:
>>>>>
>>>>>> I have done some work on this for GelfLayout. Please review branch
>>>>>> gelf-layout-gc-free
>>>>>>
>>>>>> Is there any convenient way to unit-test the encode method of a
>>>>>> layout? Do we do that for PatternLayout?
>>>>>>
>>>>>> On Wed, Feb 24, 2016 at 11:48 PM, Ralph Goers <
>>>>>> ralph.goers@dslextreme.com> wrote:
>>>>>>
>>>>>>> I haven’t had 5 minutes to spare in 3 days. I will try to look at
>>>>>>> this tonight.
>>>>>>>
>>>>>>> Ralph
>>>>>>>
>>>>>>> On Feb 24, 2016, at 3:46 PM, Gary Gregory <ga...@gmail.com>
>>>>>>> wrote:
>>>>>>>
>>>>>>> On Tue, Feb 23, 2016 at 8:23 AM, Gary Gregory <
>>>>>>> garydgregory@gmail.com> wrote:
>>>>>>>
>>>>>>>> I see we now have:
>>>>>>>>
>>>>>>>>
>>>>>>>> org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer2
>>>>>>>>
>>>>>>>> Should we
>>>>>>>> deprecate org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer
>>>>>>>> and reimplement everything in terms of Serializer2, even if objects are
>>>>>>>> allocated?
>>>>>>>>
>>>>>>>
>>>>>>> Thoughts on this?
>>>>>>>
>>>>>>> Gary
>>>>>>>
>>>>>>>
>>>>>>>>
>>>>>>>> Gary
>>>>>>>>
>>>>>>>> On Tue, Feb 23, 2016 at 7:59 AM, Remko Popma <remko.popma@gmail.com
>>>>>>>> > wrote:
>>>>>>>>
>>>>>>>>> Layout now extends Encoder so now it has this method:
>>>>>>>>>
>>>>>>>>> encode(LogEvent source, ByteBufferDestination destination)
>>>>>>>>>
>>>>>>>>> PatternLayout implements this method. It delegates the work of
>>>>>>>>> converting the StringBuilder to bytes and writing these bytes into the
>>>>>>>>> ByteBufferDestination to the TextEncoderHelper class. No objects are
>>>>>>>>> created during this conversion.
>>>>>>>>>
>>>>>>>>> The final piece is (Rolling)RandomAccessFileAppender, whose
>>>>>>>>> manager implements ByteBufferDestination. This appender calls the #encode()
>>>>>>>>> methos on the layout (other managers still call Layout#toByteArray).
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Wed, Feb 24, 2016 at 12:47 AM, Mikael Ståldal <
>>>>>>>>> mikael.staldal@magine.com> wrote:
>>>>>>>>>
>>>>>>>>>> I cannot really find it.
>>>>>>>>>>
>>>>>>>>>> On Tue, Feb 23, 2016 at 3:59 PM, Remko Popma <
>>>>>>>>>> remko.popma@gmail.com> wrote:
>>>>>>>>>>
>>>>>>>>>>> Yes, that was implemented in
>>>>>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1274.
>>>>>>>>>>>
>>>>>>>>>>> Please also see the description and discussion in the epic
>>>>>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1270.
>>>>>>>>>>>
>>>>>>>>>>> Sent from my iPhone
>>>>>>>>>>>
>>>>>>>>>>> On 2016/02/23, at 23:56, Mikael Ståldal <
>>>>>>>>>>> mikael.staldal@magine.com> wrote:
>>>>>>>>>>>
>>>>>>>>>>> Do we have any way to convert a StringBuilder to a byte[],
>>>>>>>>>>> without any intermediate String?
>>>>>>>>>>>
>>>>>>>>>>> It seems like org.apache.logging.log4j.core.util.StringEncoder cannot
>>>>>>>>>>> do it.
>>>>>>>>>>>
>>>>>>>>>>> --
>>>>>>>>>>> [image: MagineTV]
>>>>>>>>>>>
>>>>>>>>>>> *Mikael Ståldal*
>>>>>>>>>>> Senior software developer
>>>>>>>>>>>
>>>>>>>>>>> *Magine TV*
>>>>>>>>>>> mikael.staldal@magine.com
>>>>>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>>>>>>   <http://www.magine.com/>
>>>>>>>>>>>
>>>>>>>>>>> Privileged and/or Confidential Information may be contained in
>>>>>>>>>>> this message. If you are not the addressee indicated in this message
>>>>>>>>>>> (or responsible for delivery of the message to such a person),
>>>>>>>>>>> you may not copy or deliver this message to anyone. In such case,
>>>>>>>>>>> you should destroy this message and kindly notify the sender by
>>>>>>>>>>> reply email.
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> --
>>>>>>>>>> [image: MagineTV]
>>>>>>>>>>
>>>>>>>>>> *Mikael Ståldal*
>>>>>>>>>> Senior software developer
>>>>>>>>>>
>>>>>>>>>> *Magine TV*
>>>>>>>>>> mikael.staldal@magine.com
>>>>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>>>>> <http://www.magine.com/>
>>>>>>>>>>
>>>>>>>>>> Privileged and/or Confidential Information may be contained in
>>>>>>>>>> this message. If you are not the addressee indicated in this message
>>>>>>>>>> (or responsible for delivery of the message to such a person),
>>>>>>>>>> you may not copy or deliver this message to anyone. In such case,
>>>>>>>>>> you should destroy this message and kindly notify the sender by
>>>>>>>>>> reply email.
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>>>>> <gg...@apache.org>
>>>>>>>> Java Persistence with Hibernate, Second Edition
>>>>>>>> <http://www.manning.com/bauer3/>
>>>>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>>>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>>>>>> Blog: http://garygregory.wordpress.com
>>>>>>>> Home: http://garygregory.com/
>>>>>>>> Tweet! http://twitter.com/GaryGregory
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>>>> <gg...@apache.org>
>>>>>>> Java Persistence with Hibernate, Second Edition
>>>>>>> <http://www.manning.com/bauer3/>
>>>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>>>>> Blog: http://garygregory.wordpress.com
>>>>>>> Home: http://garygregory.com/
>>>>>>> Tweet! http://twitter.com/GaryGregory
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> [image: MagineTV]
>>>>>>
>>>>>> *Mikael Ståldal*
>>>>>> Senior software developer
>>>>>>
>>>>>> *Magine TV*
>>>>>> mikael.staldal@magine.com
>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>
>>>>>> Privileged and/or Confidential Information may be contained in this
>>>>>> message. If you are not the addressee indicated in this message
>>>>>> (or responsible for delivery of the message to such a person), you
>>>>>> may not copy or deliver this message to anyone. In such case,
>>>>>> you should destroy this message and kindly notify the sender by reply
>>>>>> email.
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> [image: MagineTV]
>>>>
>>>> *Mikael Ståldal*
>>>> Senior software developer
>>>>
>>>> *Magine TV*
>>>> mikael.staldal@magine.com
>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>
>>>> Privileged and/or Confidential Information may be contained in this
>>>> message. If you are not the addressee indicated in this message
>>>> (or responsible for delivery of the message to such a person), you may
>>>> not copy or deliver this message to anyone. In such case,
>>>> you should destroy this message and kindly notify the sender by reply
>>>> email.
>>>>
>>>
>>>
>>>
>>> --
>>> [image: MagineTV]
>>>
>>> *Mikael Ståldal*
>>> Senior software developer
>>>
>>> *Magine TV*
>>> mikael.staldal@magine.com
>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>
>>> Privileged and/or Confidential Information may be contained in this
>>> message. If you are not the addressee indicated in this message
>>> (or responsible for delivery of the message to such a person), you may
>>> not copy or deliver this message to anyone. In such case,
>>> you should destroy this message and kindly notify the sender by reply
>>> email.
>>>
>>
>>
>
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition
> <http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>



-- 
Matt Sicker <bo...@gmail.com>

Re: GC lean way to convert StringBuilder to byte[]

Posted by Gary Gregory <ga...@gmail.com>.
I have YourKit at work. Let me know what it is exactly you want to look at.
Or you can get a free eval for a while. I'm not sure if we have a special
deal with them for Apache or FOSS. Worth asking tho.

G

On Fri, Mar 11, 2016 at 1:56 PM, Remko Popma <re...@gmail.com> wrote:

> Mikael,
> Your changes impact the GelfLayout class mostly, right? Any other class
> impacted that you want me to take a look at? If not and all tests pass I'd
> say just go ahead and merge into master.
>
> About testing whether it is allocation-free, there is this ticket
> LOG4J2-1295 <https://issues.apache.org/jira/browse/LOG4J2-1295> that is
> still open.
> I'm thinking the Allocation Instrumenter (
> https://github.com/google/allocation-instrumenter) would serve our
> purposes quite well here.
> I just haven't had the bandwidth to look at this in more depth. It
> probably involves running a test in a separate VM with the -agent startup
> option. Not sure if we can do that with a normal log4j junit test or
> whether the test would need to start a separate VM with the proper startup
> options and then get that the result of that process via a file or
> something... It would actually be really good if you or someone else could
> make progress on that Jira, because I currently don't have the bandwidth to
> look at it yet.
>
>
> On Sat, Mar 12, 2016 at 1:33 AM, Mikael Ståldal <mikael.staldal@magine.com
> > wrote:
>
>> Is it OK to merge to master?
>>
>> Remko, can you help me to verify that it is properly allocation-free
>> (when using
>> <GelfLayout host="test" compressionType="OFF"/>)?
>>
>>
>> On Tue, Mar 8, 2016 at 5:36 PM, Mikael Ståldal <mikael.staldal@magine.com
>> > wrote:
>>
>>> I did it a bit differently, but now there are unit tests for
>>> GelfLayout.encode().
>>>
>>> On Tue, Mar 8, 2016 at 3:51 PM, Remko Popma <re...@gmail.com>
>>> wrote:
>>>
>>>> I added some tests to PatternLayoutTest, please take a look.
>>>>
>>>> On Tue, Mar 8, 2016 at 11:56 PM, Mikael Ståldal <
>>>> mikael.staldal@magine.com> wrote:
>>>>
>>>>> I have done some work on this for GelfLayout. Please review branch
>>>>> gelf-layout-gc-free
>>>>>
>>>>> Is there any convenient way to unit-test the encode method of a
>>>>> layout? Do we do that for PatternLayout?
>>>>>
>>>>> On Wed, Feb 24, 2016 at 11:48 PM, Ralph Goers <
>>>>> ralph.goers@dslextreme.com> wrote:
>>>>>
>>>>>> I haven’t had 5 minutes to spare in 3 days. I will try to look at
>>>>>> this tonight.
>>>>>>
>>>>>> Ralph
>>>>>>
>>>>>> On Feb 24, 2016, at 3:46 PM, Gary Gregory <ga...@gmail.com>
>>>>>> wrote:
>>>>>>
>>>>>> On Tue, Feb 23, 2016 at 8:23 AM, Gary Gregory <garydgregory@gmail.com
>>>>>> > wrote:
>>>>>>
>>>>>>> I see we now have:
>>>>>>>
>>>>>>> org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer2
>>>>>>>
>>>>>>> Should we
>>>>>>> deprecate org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer
>>>>>>> and reimplement everything in terms of Serializer2, even if objects are
>>>>>>> allocated?
>>>>>>>
>>>>>>
>>>>>> Thoughts on this?
>>>>>>
>>>>>> Gary
>>>>>>
>>>>>>
>>>>>>>
>>>>>>> Gary
>>>>>>>
>>>>>>> On Tue, Feb 23, 2016 at 7:59 AM, Remko Popma <re...@gmail.com>
>>>>>>>  wrote:
>>>>>>>
>>>>>>>> Layout now extends Encoder so now it has this method:
>>>>>>>>
>>>>>>>> encode(LogEvent source, ByteBufferDestination destination)
>>>>>>>>
>>>>>>>> PatternLayout implements this method. It delegates the work of
>>>>>>>> converting the StringBuilder to bytes and writing these bytes into the
>>>>>>>> ByteBufferDestination to the TextEncoderHelper class. No objects are
>>>>>>>> created during this conversion.
>>>>>>>>
>>>>>>>> The final piece is (Rolling)RandomAccessFileAppender, whose manager
>>>>>>>> implements ByteBufferDestination. This appender calls the #encode() methos
>>>>>>>> on the layout (other managers still call Layout#toByteArray).
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On Wed, Feb 24, 2016 at 12:47 AM, Mikael Ståldal <
>>>>>>>> mikael.staldal@magine.com> wrote:
>>>>>>>>
>>>>>>>>> I cannot really find it.
>>>>>>>>>
>>>>>>>>> On Tue, Feb 23, 2016 at 3:59 PM, Remko Popma <
>>>>>>>>> remko.popma@gmail.com> wrote:
>>>>>>>>>
>>>>>>>>>> Yes, that was implemented in
>>>>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1274.
>>>>>>>>>>
>>>>>>>>>> Please also see the description and discussion in the epic
>>>>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1270.
>>>>>>>>>>
>>>>>>>>>> Sent from my iPhone
>>>>>>>>>>
>>>>>>>>>> On 2016/02/23, at 23:56, Mikael Ståldal <
>>>>>>>>>> mikael.staldal@magine.com> wrote:
>>>>>>>>>>
>>>>>>>>>> Do we have any way to convert a StringBuilder to a byte[],
>>>>>>>>>> without any intermediate String?
>>>>>>>>>>
>>>>>>>>>> It seems like org.apache.logging.log4j.core.util.StringEncoder cannot
>>>>>>>>>> do it.
>>>>>>>>>>
>>>>>>>>>> --
>>>>>>>>>> [image: MagineTV]
>>>>>>>>>>
>>>>>>>>>> *Mikael Ståldal*
>>>>>>>>>> Senior software developer
>>>>>>>>>>
>>>>>>>>>> *Magine TV*
>>>>>>>>>> mikael.staldal@magine.com
>>>>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>>>>> <http://www.magine.com/>
>>>>>>>>>>
>>>>>>>>>> Privileged and/or Confidential Information may be contained in
>>>>>>>>>> this message. If you are not the addressee indicated in this message
>>>>>>>>>> (or responsible for delivery of the message to such a person),
>>>>>>>>>> you may not copy or deliver this message to anyone. In such case,
>>>>>>>>>> you should destroy this message and kindly notify the sender by
>>>>>>>>>> reply email.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> [image: MagineTV]
>>>>>>>>>
>>>>>>>>> *Mikael Ståldal*
>>>>>>>>> Senior software developer
>>>>>>>>>
>>>>>>>>> *Magine TV*
>>>>>>>>> mikael.staldal@magine.com
>>>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>>>> <http://www.magine.com/>
>>>>>>>>>
>>>>>>>>> Privileged and/or Confidential Information may be contained in
>>>>>>>>> this message. If you are not the addressee indicated in this message
>>>>>>>>> (or responsible for delivery of the message to such a person), you
>>>>>>>>> may not copy or deliver this message to anyone. In such case,
>>>>>>>>> you should destroy this message and kindly notify the sender by
>>>>>>>>> reply email.
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>>>> <gg...@apache.org>
>>>>>>> Java Persistence with Hibernate, Second Edition
>>>>>>> <http://www.manning.com/bauer3/>
>>>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>>>>> Blog: http://garygregory.wordpress.com
>>>>>>> Home: http://garygregory.com/
>>>>>>> Tweet! http://twitter.com/GaryGregory
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>>> <gg...@apache.org>
>>>>>> Java Persistence with Hibernate, Second Edition
>>>>>> <http://www.manning.com/bauer3/>
>>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>>>> Blog: http://garygregory.wordpress.com
>>>>>> Home: http://garygregory.com/
>>>>>> Tweet! http://twitter.com/GaryGregory
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> [image: MagineTV]
>>>>>
>>>>> *Mikael Ståldal*
>>>>> Senior software developer
>>>>>
>>>>> *Magine TV*
>>>>> mikael.staldal@magine.com
>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>
>>>>> Privileged and/or Confidential Information may be contained in this
>>>>> message. If you are not the addressee indicated in this message
>>>>> (or responsible for delivery of the message to such a person), you may
>>>>> not copy or deliver this message to anyone. In such case,
>>>>> you should destroy this message and kindly notify the sender by reply
>>>>> email.
>>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> [image: MagineTV]
>>>
>>> *Mikael Ståldal*
>>> Senior software developer
>>>
>>> *Magine TV*
>>> mikael.staldal@magine.com
>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>
>>> Privileged and/or Confidential Information may be contained in this
>>> message. If you are not the addressee indicated in this message
>>> (or responsible for delivery of the message to such a person), you may
>>> not copy or deliver this message to anyone. In such case,
>>> you should destroy this message and kindly notify the sender by reply
>>> email.
>>>
>>
>>
>>
>> --
>> [image: MagineTV]
>>
>> *Mikael Ståldal*
>> Senior software developer
>>
>> *Magine TV*
>> mikael.staldal@magine.com
>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>
>> Privileged and/or Confidential Information may be contained in this
>> message. If you are not the addressee indicated in this message
>> (or responsible for delivery of the message to such a person), you may
>> not copy or deliver this message to anyone. In such case,
>> you should destroy this message and kindly notify the sender by reply
>> email.
>>
>
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: GC lean way to convert StringBuilder to byte[]

Posted by Remko Popma <re...@gmail.com>.
Mikael,
Your changes impact the GelfLayout class mostly, right? Any other class
impacted that you want me to take a look at? If not and all tests pass I'd
say just go ahead and merge into master.

About testing whether it is allocation-free, there is this ticket
LOG4J2-1295 <https://issues.apache.org/jira/browse/LOG4J2-1295> that is
still open.
I'm thinking the Allocation Instrumenter (
https://github.com/google/allocation-instrumenter) would serve our purposes
quite well here.
I just haven't had the bandwidth to look at this in more depth. It probably
involves running a test in a separate VM with the -agent startup option.
Not sure if we can do that with a normal log4j junit test or whether the
test would need to start a separate VM with the proper startup options and
then get that the result of that process via a file or something... It
would actually be really good if you or someone else could make progress on
that Jira, because I currently don't have the bandwidth to look at it yet.


On Sat, Mar 12, 2016 at 1:33 AM, Mikael Ståldal <mi...@magine.com>
wrote:

> Is it OK to merge to master?
>
> Remko, can you help me to verify that it is properly allocation-free (when
> using
> <GelfLayout host="test" compressionType="OFF"/>)?
>
>
> On Tue, Mar 8, 2016 at 5:36 PM, Mikael Ståldal <mi...@magine.com>
> wrote:
>
>> I did it a bit differently, but now there are unit tests for
>> GelfLayout.encode().
>>
>> On Tue, Mar 8, 2016 at 3:51 PM, Remko Popma <re...@gmail.com>
>> wrote:
>>
>>> I added some tests to PatternLayoutTest, please take a look.
>>>
>>> On Tue, Mar 8, 2016 at 11:56 PM, Mikael Ståldal <
>>> mikael.staldal@magine.com> wrote:
>>>
>>>> I have done some work on this for GelfLayout. Please review branch
>>>> gelf-layout-gc-free
>>>>
>>>> Is there any convenient way to unit-test the encode method of a layout?
>>>> Do we do that for PatternLayout?
>>>>
>>>> On Wed, Feb 24, 2016 at 11:48 PM, Ralph Goers <
>>>> ralph.goers@dslextreme.com> wrote:
>>>>
>>>>> I haven’t had 5 minutes to spare in 3 days. I will try to look at this
>>>>> tonight.
>>>>>
>>>>> Ralph
>>>>>
>>>>> On Feb 24, 2016, at 3:46 PM, Gary Gregory <ga...@gmail.com>
>>>>> wrote:
>>>>>
>>>>> On Tue, Feb 23, 2016 at 8:23 AM, Gary Gregory <ga...@gmail.com>
>>>>>  wrote:
>>>>>
>>>>>> I see we now have:
>>>>>>
>>>>>> org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer2
>>>>>>
>>>>>> Should we
>>>>>> deprecate org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer
>>>>>> and reimplement everything in terms of Serializer2, even if objects are
>>>>>> allocated?
>>>>>>
>>>>>
>>>>> Thoughts on this?
>>>>>
>>>>> Gary
>>>>>
>>>>>
>>>>>>
>>>>>> Gary
>>>>>>
>>>>>> On Tue, Feb 23, 2016 at 7:59 AM, Remko Popma <re...@gmail.com>
>>>>>> wrote:
>>>>>>
>>>>>>> Layout now extends Encoder so now it has this method:
>>>>>>>
>>>>>>> encode(LogEvent source, ByteBufferDestination destination)
>>>>>>>
>>>>>>> PatternLayout implements this method. It delegates the work of
>>>>>>> converting the StringBuilder to bytes and writing these bytes into the
>>>>>>> ByteBufferDestination to the TextEncoderHelper class. No objects are
>>>>>>> created during this conversion.
>>>>>>>
>>>>>>> The final piece is (Rolling)RandomAccessFileAppender, whose manager
>>>>>>> implements ByteBufferDestination. This appender calls the #encode() methos
>>>>>>> on the layout (other managers still call Layout#toByteArray).
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Wed, Feb 24, 2016 at 12:47 AM, Mikael Ståldal <
>>>>>>> mikael.staldal@magine.com> wrote:
>>>>>>>
>>>>>>>> I cannot really find it.
>>>>>>>>
>>>>>>>> On Tue, Feb 23, 2016 at 3:59 PM, Remko Popma <remko.popma@gmail.com
>>>>>>>> > wrote:
>>>>>>>>
>>>>>>>>> Yes, that was implemented in
>>>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1274.
>>>>>>>>>
>>>>>>>>> Please also see the description and discussion in the epic
>>>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1270.
>>>>>>>>>
>>>>>>>>> Sent from my iPhone
>>>>>>>>>
>>>>>>>>> On 2016/02/23, at 23:56, Mikael Ståldal <mi...@magine.com>
>>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>> Do we have any way to convert a StringBuilder to a byte[], without
>>>>>>>>> any intermediate String?
>>>>>>>>>
>>>>>>>>> It seems like org.apache.logging.log4j.core.util.StringEncoder cannot
>>>>>>>>> do it.
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> [image: MagineTV]
>>>>>>>>>
>>>>>>>>> *Mikael Ståldal*
>>>>>>>>> Senior software developer
>>>>>>>>>
>>>>>>>>> *Magine TV*
>>>>>>>>> mikael.staldal@magine.com
>>>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>>>> <http://www.magine.com/>
>>>>>>>>>
>>>>>>>>> Privileged and/or Confidential Information may be contained in
>>>>>>>>> this message. If you are not the addressee indicated in this message
>>>>>>>>> (or responsible for delivery of the message to such a person), you
>>>>>>>>> may not copy or deliver this message to anyone. In such case,
>>>>>>>>> you should destroy this message and kindly notify the sender by
>>>>>>>>> reply email.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>> [image: MagineTV]
>>>>>>>>
>>>>>>>> *Mikael Ståldal*
>>>>>>>> Senior software developer
>>>>>>>>
>>>>>>>> *Magine TV*
>>>>>>>> mikael.staldal@magine.com
>>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>>> <http://www.magine.com/>
>>>>>>>>
>>>>>>>> Privileged and/or Confidential Information may be contained in this
>>>>>>>> message. If you are not the addressee indicated in this message
>>>>>>>> (or responsible for delivery of the message to such a person), you
>>>>>>>> may not copy or deliver this message to anyone. In such case,
>>>>>>>> you should destroy this message and kindly notify the sender by
>>>>>>>> reply email.
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>>> <gg...@apache.org>
>>>>>> Java Persistence with Hibernate, Second Edition
>>>>>> <http://www.manning.com/bauer3/>
>>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>>>> Blog: http://garygregory.wordpress.com
>>>>>> Home: http://garygregory.com/
>>>>>> Tweet! http://twitter.com/GaryGregory
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>> <gg...@apache.org>
>>>>> Java Persistence with Hibernate, Second Edition
>>>>> <http://www.manning.com/bauer3/>
>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>>> Blog: http://garygregory.wordpress.com
>>>>> Home: http://garygregory.com/
>>>>> Tweet! http://twitter.com/GaryGregory
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> [image: MagineTV]
>>>>
>>>> *Mikael Ståldal*
>>>> Senior software developer
>>>>
>>>> *Magine TV*
>>>> mikael.staldal@magine.com
>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>
>>>> Privileged and/or Confidential Information may be contained in this
>>>> message. If you are not the addressee indicated in this message
>>>> (or responsible for delivery of the message to such a person), you may
>>>> not copy or deliver this message to anyone. In such case,
>>>> you should destroy this message and kindly notify the sender by reply
>>>> email.
>>>>
>>>
>>>
>>
>>
>> --
>> [image: MagineTV]
>>
>> *Mikael Ståldal*
>> Senior software developer
>>
>> *Magine TV*
>> mikael.staldal@magine.com
>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>
>> Privileged and/or Confidential Information may be contained in this
>> message. If you are not the addressee indicated in this message
>> (or responsible for delivery of the message to such a person), you may
>> not copy or deliver this message to anyone. In such case,
>> you should destroy this message and kindly notify the sender by reply
>> email.
>>
>
>
>
> --
> [image: MagineTV]
>
> *Mikael Ståldal*
> Senior software developer
>
> *Magine TV*
> mikael.staldal@magine.com
> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>
> Privileged and/or Confidential Information may be contained in this
> message. If you are not the addressee indicated in this message
> (or responsible for delivery of the message to such a person), you may not
> copy or deliver this message to anyone. In such case,
> you should destroy this message and kindly notify the sender by reply
> email.
>

Re: GC lean way to convert StringBuilder to byte[]

Posted by Mikael Ståldal <mi...@magine.com>.
Is it OK to merge to master?

Remko, can you help me to verify that it is properly allocation-free (when
using
<GelfLayout host="test" compressionType="OFF"/>)?


On Tue, Mar 8, 2016 at 5:36 PM, Mikael Ståldal <mi...@magine.com>
wrote:

> I did it a bit differently, but now there are unit tests for
> GelfLayout.encode().
>
> On Tue, Mar 8, 2016 at 3:51 PM, Remko Popma <re...@gmail.com> wrote:
>
>> I added some tests to PatternLayoutTest, please take a look.
>>
>> On Tue, Mar 8, 2016 at 11:56 PM, Mikael Ståldal <
>> mikael.staldal@magine.com> wrote:
>>
>>> I have done some work on this for GelfLayout. Please review branch
>>> gelf-layout-gc-free
>>>
>>> Is there any convenient way to unit-test the encode method of a layout?
>>> Do we do that for PatternLayout?
>>>
>>> On Wed, Feb 24, 2016 at 11:48 PM, Ralph Goers <
>>> ralph.goers@dslextreme.com> wrote:
>>>
>>>> I haven’t had 5 minutes to spare in 3 days. I will try to look at this
>>>> tonight.
>>>>
>>>> Ralph
>>>>
>>>> On Feb 24, 2016, at 3:46 PM, Gary Gregory <ga...@gmail.com>
>>>> wrote:
>>>>
>>>> On Tue, Feb 23, 2016 at 8:23 AM, Gary Gregory <ga...@gmail.com>
>>>> wrote:
>>>>
>>>>> I see we now have:
>>>>>
>>>>> org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer2
>>>>>
>>>>> Should we
>>>>> deprecate org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer
>>>>> and reimplement everything in terms of Serializer2, even if objects are
>>>>> allocated?
>>>>>
>>>>
>>>> Thoughts on this?
>>>>
>>>> Gary
>>>>
>>>>
>>>>>
>>>>> Gary
>>>>>
>>>>> On Tue, Feb 23, 2016 at 7:59 AM, Remko Popma <re...@gmail.com>
>>>>> wrote:
>>>>>
>>>>>> Layout now extends Encoder so now it has this method:
>>>>>>
>>>>>> encode(LogEvent source, ByteBufferDestination destination)
>>>>>>
>>>>>> PatternLayout implements this method. It delegates the work of
>>>>>> converting the StringBuilder to bytes and writing these bytes into the
>>>>>> ByteBufferDestination to the TextEncoderHelper class. No objects are
>>>>>> created during this conversion.
>>>>>>
>>>>>> The final piece is (Rolling)RandomAccessFileAppender, whose manager
>>>>>> implements ByteBufferDestination. This appender calls the #encode() methos
>>>>>> on the layout (other managers still call Layout#toByteArray).
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Wed, Feb 24, 2016 at 12:47 AM, Mikael Ståldal <
>>>>>> mikael.staldal@magine.com> wrote:
>>>>>>
>>>>>>> I cannot really find it.
>>>>>>>
>>>>>>> On Tue, Feb 23, 2016 at 3:59 PM, Remko Popma <re...@gmail.com>
>>>>>>>  wrote:
>>>>>>>
>>>>>>>> Yes, that was implemented in
>>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1274.
>>>>>>>>
>>>>>>>> Please also see the description and discussion in the epic
>>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1270.
>>>>>>>>
>>>>>>>> Sent from my iPhone
>>>>>>>>
>>>>>>>> On 2016/02/23, at 23:56, Mikael Ståldal <mi...@magine.com>
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>> Do we have any way to convert a StringBuilder to a byte[], without
>>>>>>>> any intermediate String?
>>>>>>>>
>>>>>>>> It seems like org.apache.logging.log4j.core.util.StringEncoder cannot
>>>>>>>> do it.
>>>>>>>>
>>>>>>>> --
>>>>>>>> [image: MagineTV]
>>>>>>>>
>>>>>>>> *Mikael Ståldal*
>>>>>>>> Senior software developer
>>>>>>>>
>>>>>>>> *Magine TV*
>>>>>>>> mikael.staldal@magine.com
>>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>>> <http://www.magine.com/>
>>>>>>>>
>>>>>>>> Privileged and/or Confidential Information may be contained in this
>>>>>>>> message. If you are not the addressee indicated in this message
>>>>>>>> (or responsible for delivery of the message to such a person), you
>>>>>>>> may not copy or deliver this message to anyone. In such case,
>>>>>>>> you should destroy this message and kindly notify the sender by
>>>>>>>> reply email.
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> [image: MagineTV]
>>>>>>>
>>>>>>> *Mikael Ståldal*
>>>>>>> Senior software developer
>>>>>>>
>>>>>>> *Magine TV*
>>>>>>> mikael.staldal@magine.com
>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>> <http://www.magine.com/>
>>>>>>>
>>>>>>> Privileged and/or Confidential Information may be contained in this
>>>>>>> message. If you are not the addressee indicated in this message
>>>>>>> (or responsible for delivery of the message to such a person), you
>>>>>>> may not copy or deliver this message to anyone. In such case,
>>>>>>> you should destroy this message and kindly notify the sender by
>>>>>>> reply email.
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>> <gg...@apache.org>
>>>>> Java Persistence with Hibernate, Second Edition
>>>>> <http://www.manning.com/bauer3/>
>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>>> Blog: http://garygregory.wordpress.com
>>>>> Home: http://garygregory.com/
>>>>> Tweet! http://twitter.com/GaryGregory
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>> <gg...@apache.org>
>>>> Java Persistence with Hibernate, Second Edition
>>>> <http://www.manning.com/bauer3/>
>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>> Blog: http://garygregory.wordpress.com
>>>> Home: http://garygregory.com/
>>>> Tweet! http://twitter.com/GaryGregory
>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> [image: MagineTV]
>>>
>>> *Mikael Ståldal*
>>> Senior software developer
>>>
>>> *Magine TV*
>>> mikael.staldal@magine.com
>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>
>>> Privileged and/or Confidential Information may be contained in this
>>> message. If you are not the addressee indicated in this message
>>> (or responsible for delivery of the message to such a person), you may
>>> not copy or deliver this message to anyone. In such case,
>>> you should destroy this message and kindly notify the sender by reply
>>> email.
>>>
>>
>>
>
>
> --
> [image: MagineTV]
>
> *Mikael Ståldal*
> Senior software developer
>
> *Magine TV*
> mikael.staldal@magine.com
> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>
> Privileged and/or Confidential Information may be contained in this
> message. If you are not the addressee indicated in this message
> (or responsible for delivery of the message to such a person), you may not
> copy or deliver this message to anyone. In such case,
> you should destroy this message and kindly notify the sender by reply
> email.
>



-- 
[image: MagineTV]

*Mikael Ståldal*
Senior software developer

*Magine TV*
mikael.staldal@magine.com
Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com

Privileged and/or Confidential Information may be contained in this
message. If you are not the addressee indicated in this message
(or responsible for delivery of the message to such a person), you may not
copy or deliver this message to anyone. In such case,
you should destroy this message and kindly notify the sender by reply
email.

Re: GC lean way to convert StringBuilder to byte[]

Posted by Mikael Ståldal <mi...@magine.com>.
I did it a bit differently, but now there are unit tests for
GelfLayout.encode().

On Tue, Mar 8, 2016 at 3:51 PM, Remko Popma <re...@gmail.com> wrote:

> I added some tests to PatternLayoutTest, please take a look.
>
> On Tue, Mar 8, 2016 at 11:56 PM, Mikael Ståldal <mikael.staldal@magine.com
> > wrote:
>
>> I have done some work on this for GelfLayout. Please review branch
>> gelf-layout-gc-free
>>
>> Is there any convenient way to unit-test the encode method of a layout?
>> Do we do that for PatternLayout?
>>
>> On Wed, Feb 24, 2016 at 11:48 PM, Ralph Goers <ralph.goers@dslextreme.com
>> > wrote:
>>
>>> I haven’t had 5 minutes to spare in 3 days. I will try to look at this
>>> tonight.
>>>
>>> Ralph
>>>
>>> On Feb 24, 2016, at 3:46 PM, Gary Gregory <ga...@gmail.com>
>>> wrote:
>>>
>>> On Tue, Feb 23, 2016 at 8:23 AM, Gary Gregory <ga...@gmail.com>
>>> wrote:
>>>
>>>> I see we now have:
>>>>
>>>> org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer2
>>>>
>>>> Should we
>>>> deprecate org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer
>>>> and reimplement everything in terms of Serializer2, even if objects are
>>>> allocated?
>>>>
>>>
>>> Thoughts on this?
>>>
>>> Gary
>>>
>>>
>>>>
>>>> Gary
>>>>
>>>> On Tue, Feb 23, 2016 at 7:59 AM, Remko Popma <re...@gmail.com>
>>>> wrote:
>>>>
>>>>> Layout now extends Encoder so now it has this method:
>>>>>
>>>>> encode(LogEvent source, ByteBufferDestination destination)
>>>>>
>>>>> PatternLayout implements this method. It delegates the work of
>>>>> converting the StringBuilder to bytes and writing these bytes into the
>>>>> ByteBufferDestination to the TextEncoderHelper class. No objects are
>>>>> created during this conversion.
>>>>>
>>>>> The final piece is (Rolling)RandomAccessFileAppender, whose manager
>>>>> implements ByteBufferDestination. This appender calls the #encode() methos
>>>>> on the layout (other managers still call Layout#toByteArray).
>>>>>
>>>>>
>>>>>
>>>>> On Wed, Feb 24, 2016 at 12:47 AM, Mikael Ståldal <
>>>>> mikael.staldal@magine.com> wrote:
>>>>>
>>>>>> I cannot really find it.
>>>>>>
>>>>>> On Tue, Feb 23, 2016 at 3:59 PM, Remko Popma <re...@gmail.com>
>>>>>> wrote:
>>>>>>
>>>>>>> Yes, that was implemented in
>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1274.
>>>>>>>
>>>>>>> Please also see the description and discussion in the epic
>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1270.
>>>>>>>
>>>>>>> Sent from my iPhone
>>>>>>>
>>>>>>> On 2016/02/23, at 23:56, Mikael Ståldal <mi...@magine.com>
>>>>>>> wrote:
>>>>>>>
>>>>>>> Do we have any way to convert a StringBuilder to a byte[], without
>>>>>>> any intermediate String?
>>>>>>>
>>>>>>> It seems like org.apache.logging.log4j.core.util.StringEncoder cannot
>>>>>>> do it.
>>>>>>>
>>>>>>> --
>>>>>>> [image: MagineTV]
>>>>>>>
>>>>>>> *Mikael Ståldal*
>>>>>>> Senior software developer
>>>>>>>
>>>>>>> *Magine TV*
>>>>>>> mikael.staldal@magine.com
>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>> <http://www.magine.com/>
>>>>>>>
>>>>>>> Privileged and/or Confidential Information may be contained in this
>>>>>>> message. If you are not the addressee indicated in this message
>>>>>>> (or responsible for delivery of the message to such a person), you
>>>>>>> may not copy or deliver this message to anyone. In such case,
>>>>>>> you should destroy this message and kindly notify the sender by
>>>>>>> reply email.
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> [image: MagineTV]
>>>>>>
>>>>>> *Mikael Ståldal*
>>>>>> Senior software developer
>>>>>>
>>>>>> *Magine TV*
>>>>>> mikael.staldal@magine.com
>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>> <http://www.magine.com/>
>>>>>>
>>>>>> Privileged and/or Confidential Information may be contained in this
>>>>>> message. If you are not the addressee indicated in this message
>>>>>> (or responsible for delivery of the message to such a person), you
>>>>>> may not copy or deliver this message to anyone. In such case,
>>>>>> you should destroy this message and kindly notify the sender by reply
>>>>>> email.
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>> <gg...@apache.org>
>>>> Java Persistence with Hibernate, Second Edition
>>>> <http://www.manning.com/bauer3/>
>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>> Blog: http://garygregory.wordpress.com
>>>> Home: http://garygregory.com/
>>>> Tweet! http://twitter.com/GaryGregory
>>>>
>>>
>>>
>>>
>>> --
>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>> <gg...@apache.org>
>>> Java Persistence with Hibernate, Second Edition
>>> <http://www.manning.com/bauer3/>
>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>> Spring Batch in Action <http://www.manning.com/templier/>
>>> Blog: http://garygregory.wordpress.com
>>> Home: http://garygregory.com/
>>> Tweet! http://twitter.com/GaryGregory
>>>
>>>
>>>
>>
>>
>> --
>> [image: MagineTV]
>>
>> *Mikael Ståldal*
>> Senior software developer
>>
>> *Magine TV*
>> mikael.staldal@magine.com
>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>
>> Privileged and/or Confidential Information may be contained in this
>> message. If you are not the addressee indicated in this message
>> (or responsible for delivery of the message to such a person), you may
>> not copy or deliver this message to anyone. In such case,
>> you should destroy this message and kindly notify the sender by reply
>> email.
>>
>
>


-- 
[image: MagineTV]

*Mikael Ståldal*
Senior software developer

*Magine TV*
mikael.staldal@magine.com
Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com

Privileged and/or Confidential Information may be contained in this
message. If you are not the addressee indicated in this message
(or responsible for delivery of the message to such a person), you may not
copy or deliver this message to anyone. In such case,
you should destroy this message and kindly notify the sender by reply
email.

Re: GC lean way to convert StringBuilder to byte[]

Posted by Remko Popma <re...@gmail.com>.
I added some tests to PatternLayoutTest, please take a look.

On Tue, Mar 8, 2016 at 11:56 PM, Mikael Ståldal <mi...@magine.com>
wrote:

> I have done some work on this for GelfLayout. Please review branch
> gelf-layout-gc-free
>
> Is there any convenient way to unit-test the encode method of a layout? Do
> we do that for PatternLayout?
>
> On Wed, Feb 24, 2016 at 11:48 PM, Ralph Goers <ra...@dslextreme.com>
> wrote:
>
>> I haven’t had 5 minutes to spare in 3 days. I will try to look at this
>> tonight.
>>
>> Ralph
>>
>> On Feb 24, 2016, at 3:46 PM, Gary Gregory <ga...@gmail.com> wrote:
>>
>> On Tue, Feb 23, 2016 at 8:23 AM, Gary Gregory <ga...@gmail.com>
>> wrote:
>>
>>> I see we now have:
>>>
>>> org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer2
>>>
>>> Should we
>>> deprecate org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer
>>> and reimplement everything in terms of Serializer2, even if objects are
>>> allocated?
>>>
>>
>> Thoughts on this?
>>
>> Gary
>>
>>
>>>
>>> Gary
>>>
>>> On Tue, Feb 23, 2016 at 7:59 AM, Remko Popma <re...@gmail.com>
>>> wrote:
>>>
>>>> Layout now extends Encoder so now it has this method:
>>>>
>>>> encode(LogEvent source, ByteBufferDestination destination)
>>>>
>>>> PatternLayout implements this method. It delegates the work of
>>>> converting the StringBuilder to bytes and writing these bytes into the
>>>> ByteBufferDestination to the TextEncoderHelper class. No objects are
>>>> created during this conversion.
>>>>
>>>> The final piece is (Rolling)RandomAccessFileAppender, whose manager
>>>> implements ByteBufferDestination. This appender calls the #encode() methos
>>>> on the layout (other managers still call Layout#toByteArray).
>>>>
>>>>
>>>>
>>>> On Wed, Feb 24, 2016 at 12:47 AM, Mikael Ståldal <
>>>> mikael.staldal@magine.com> wrote:
>>>>
>>>>> I cannot really find it.
>>>>>
>>>>> On Tue, Feb 23, 2016 at 3:59 PM, Remko Popma <re...@gmail.com>
>>>>> wrote:
>>>>>
>>>>>> Yes, that was implemented in
>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1274.
>>>>>>
>>>>>> Please also see the description and discussion in the epic
>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1270.
>>>>>>
>>>>>> Sent from my iPhone
>>>>>>
>>>>>> On 2016/02/23, at 23:56, Mikael Ståldal <mi...@magine.com>
>>>>>> wrote:
>>>>>>
>>>>>> Do we have any way to convert a StringBuilder to a byte[], without
>>>>>> any intermediate String?
>>>>>>
>>>>>> It seems like org.apache.logging.log4j.core.util.StringEncoder cannot
>>>>>> do it.
>>>>>>
>>>>>> --
>>>>>> [image: MagineTV]
>>>>>>
>>>>>> *Mikael Ståldal*
>>>>>> Senior software developer
>>>>>>
>>>>>> *Magine TV*
>>>>>> mikael.staldal@magine.com
>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>> <http://www.magine.com/>
>>>>>>
>>>>>> Privileged and/or Confidential Information may be contained in this
>>>>>> message. If you are not the addressee indicated in this message
>>>>>> (or responsible for delivery of the message to such a person), you
>>>>>> may not copy or deliver this message to anyone. In such case,
>>>>>> you should destroy this message and kindly notify the sender by reply
>>>>>> email.
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> [image: MagineTV]
>>>>>
>>>>> *Mikael Ståldal*
>>>>> Senior software developer
>>>>>
>>>>> *Magine TV*
>>>>> mikael.staldal@magine.com
>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>> <http://www.magine.com/>
>>>>>
>>>>> Privileged and/or Confidential Information may be contained in this
>>>>> message. If you are not the addressee indicated in this message
>>>>> (or responsible for delivery of the message to such a person), you may
>>>>> not copy or deliver this message to anyone. In such case,
>>>>> you should destroy this message and kindly notify the sender by reply
>>>>> email.
>>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>> <gg...@apache.org>
>>> Java Persistence with Hibernate, Second Edition
>>> <http://www.manning.com/bauer3/>
>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>> Spring Batch in Action <http://www.manning.com/templier/>
>>> Blog: http://garygregory.wordpress.com
>>> Home: http://garygregory.com/
>>> Tweet! http://twitter.com/GaryGregory
>>>
>>
>>
>>
>> --
>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>> <gg...@apache.org>
>> Java Persistence with Hibernate, Second Edition
>> <http://www.manning.com/bauer3/>
>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>> Spring Batch in Action <http://www.manning.com/templier/>
>> Blog: http://garygregory.wordpress.com
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
>>
>>
>>
>
>
> --
> [image: MagineTV]
>
> *Mikael Ståldal*
> Senior software developer
>
> *Magine TV*
> mikael.staldal@magine.com
> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>
> Privileged and/or Confidential Information may be contained in this
> message. If you are not the addressee indicated in this message
> (or responsible for delivery of the message to such a person), you may not
> copy or deliver this message to anyone. In such case,
> you should destroy this message and kindly notify the sender by reply
> email.
>

Re: GC lean way to convert StringBuilder to byte[]

Posted by Mikael Ståldal <mi...@magine.com>.
I have done some work on this for GelfLayout. Please review branch
gelf-layout-gc-free

Is there any convenient way to unit-test the encode method of a layout? Do
we do that for PatternLayout?

On Wed, Feb 24, 2016 at 11:48 PM, Ralph Goers <ra...@dslextreme.com>
wrote:

> I haven’t had 5 minutes to spare in 3 days. I will try to look at this
> tonight.
>
> Ralph
>
> On Feb 24, 2016, at 3:46 PM, Gary Gregory <ga...@gmail.com> wrote:
>
> On Tue, Feb 23, 2016 at 8:23 AM, Gary Gregory <ga...@gmail.com>
> wrote:
>
>> I see we now have:
>>
>> org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer2
>>
>> Should we
>> deprecate org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer
>> and reimplement everything in terms of Serializer2, even if objects are
>> allocated?
>>
>
> Thoughts on this?
>
> Gary
>
>
>>
>> Gary
>>
>> On Tue, Feb 23, 2016 at 7:59 AM, Remko Popma <re...@gmail.com>
>> wrote:
>>
>>> Layout now extends Encoder so now it has this method:
>>>
>>> encode(LogEvent source, ByteBufferDestination destination)
>>>
>>> PatternLayout implements this method. It delegates the work of
>>> converting the StringBuilder to bytes and writing these bytes into the
>>> ByteBufferDestination to the TextEncoderHelper class. No objects are
>>> created during this conversion.
>>>
>>> The final piece is (Rolling)RandomAccessFileAppender, whose manager
>>> implements ByteBufferDestination. This appender calls the #encode() methos
>>> on the layout (other managers still call Layout#toByteArray).
>>>
>>>
>>>
>>> On Wed, Feb 24, 2016 at 12:47 AM, Mikael Ståldal <
>>> mikael.staldal@magine.com> wrote:
>>>
>>>> I cannot really find it.
>>>>
>>>> On Tue, Feb 23, 2016 at 3:59 PM, Remko Popma <re...@gmail.com>
>>>> wrote:
>>>>
>>>>> Yes, that was implemented in
>>>>> https://issues.apache.org/jira/browse/LOG4J2-1274.
>>>>>
>>>>> Please also see the description and discussion in the epic
>>>>> https://issues.apache.org/jira/browse/LOG4J2-1270.
>>>>>
>>>>> Sent from my iPhone
>>>>>
>>>>> On 2016/02/23, at 23:56, Mikael Ståldal <mi...@magine.com>
>>>>> wrote:
>>>>>
>>>>> Do we have any way to convert a StringBuilder to a byte[], without any
>>>>> intermediate String?
>>>>>
>>>>> It seems like org.apache.logging.log4j.core.util.StringEncoder cannot
>>>>> do it.
>>>>>
>>>>> --
>>>>> [image: MagineTV]
>>>>>
>>>>> *Mikael Ståldal*
>>>>> Senior software developer
>>>>>
>>>>> *Magine TV*
>>>>> mikael.staldal@magine.com
>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>> <http://www.magine.com/>
>>>>>
>>>>> Privileged and/or Confidential Information may be contained in this
>>>>> message. If you are not the addressee indicated in this message
>>>>> (or responsible for delivery of the message to such a person), you may
>>>>> not copy or deliver this message to anyone. In such case,
>>>>> you should destroy this message and kindly notify the sender by reply
>>>>> email.
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> [image: MagineTV]
>>>>
>>>> *Mikael Ståldal*
>>>> Senior software developer
>>>>
>>>> *Magine TV*
>>>> mikael.staldal@magine.com
>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>> <http://www.magine.com/>
>>>>
>>>> Privileged and/or Confidential Information may be contained in this
>>>> message. If you are not the addressee indicated in this message
>>>> (or responsible for delivery of the message to such a person), you may
>>>> not copy or deliver this message to anyone. In such case,
>>>> you should destroy this message and kindly notify the sender by reply
>>>> email.
>>>>
>>>
>>>
>>
>>
>> --
>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>> <gg...@apache.org>
>> Java Persistence with Hibernate, Second Edition
>> <http://www.manning.com/bauer3/>
>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>> Spring Batch in Action <http://www.manning.com/templier/>
>> Blog: http://garygregory.wordpress.com
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
>>
>
>
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> <gg...@apache.org>
> Java Persistence with Hibernate, Second Edition
> <http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>
>
>


-- 
[image: MagineTV]

*Mikael Ståldal*
Senior software developer

*Magine TV*
mikael.staldal@magine.com
Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com

Privileged and/or Confidential Information may be contained in this
message. If you are not the addressee indicated in this message
(or responsible for delivery of the message to such a person), you may not
copy or deliver this message to anyone. In such case,
you should destroy this message and kindly notify the sender by reply
email.

Re: GC lean way to convert StringBuilder to byte[]

Posted by Ralph Goers <ra...@dslextreme.com>.
I haven’t had 5 minutes to spare in 3 days. I will try to look at this tonight.

Ralph

> On Feb 24, 2016, at 3:46 PM, Gary Gregory <ga...@gmail.com> wrote:
> 
> On Tue, Feb 23, 2016 at 8:23 AM, Gary Gregory <garydgregory@gmail.com <ma...@gmail.com>> wrote:
> I see we now have:
> 
> org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer2
> 
> Should we deprecate org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer and reimplement everything in terms of Serializer2, even if objects are allocated?
> 
> Thoughts on this?
> 
> Gary
>  
> 
> Gary
> 
> On Tue, Feb 23, 2016 at 7:59 AM, Remko Popma <remko.popma@gmail.com <ma...@gmail.com>> wrote:
> Layout now extends Encoder so now it has this method:
> encode(LogEvent source, ByteBufferDestination destination)
> PatternLayout implements this method. It delegates the work of converting the StringBuilder to bytes and writing these bytes into the ByteBufferDestination to the TextEncoderHelper class. No objects are created during this conversion.
> 
> The final piece is (Rolling)RandomAccessFileAppender, whose manager implements ByteBufferDestination. This appender calls the #encode() methos on the layout (other managers still call Layout#toByteArray).
> 
> 
> 
> On Wed, Feb 24, 2016 at 12:47 AM, Mikael Ståldal <mikael.staldal@magine.com <ma...@magine.com>> wrote:
> I cannot really find it.
> 
> On Tue, Feb 23, 2016 at 3:59 PM, Remko Popma <remko.popma@gmail.com <ma...@gmail.com>> wrote:
> Yes, that was implemented in https://issues.apache.org/jira/browse/LOG4J2-1274 <https://issues.apache.org/jira/browse/LOG4J2-1274>. 
> 
> Please also see the description and discussion in the epic https://issues.apache.org/jira/browse/LOG4J2-1270 <https://issues.apache.org/jira/browse/LOG4J2-1270>. 
> 
> Sent from my iPhone
> 
> On 2016/02/23, at 23:56, Mikael Ståldal <mikael.staldal@magine.com <ma...@magine.com>> wrote:
> 
>> Do we have any way to convert a StringBuilder to a byte[], without any intermediate String?
>> 
>> It seems like org.apache.logging.log4j.core.util.StringEncoder cannot do it.
>> 
>> -- 
>>  
>> 
>> Mikael Ståldal
>> Senior software developer 
>> 
>> Magine TV
>> mikael.staldal@magine.com <ma...@magine.com>    
>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com  <http://www.magine.com/>
>> 
>> Privileged and/or Confidential Information may be contained in this message. If you are not the addressee indicated in this message
>> (or responsible for delivery of the message to such a person), you may not copy or deliver this message to anyone. In such case, 
>> you should destroy this message and kindly notify the sender by reply email.   
> 
> 
> 
> -- 
>  
> 
> Mikael Ståldal
> Senior software developer 
> 
> Magine TV
> mikael.staldal@magine.com <ma...@magine.com>    
> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com  <http://www.magine.com/>
> 
> Privileged and/or Confidential Information may be contained in this message. If you are not the addressee indicated in this message
> (or responsible for delivery of the message to such a person), you may not copy or deliver this message to anyone. In such case, 
> you should destroy this message and kindly notify the sender by reply email.   
> 
> 
> 
> 
> -- 
> E-Mail: garydgregory@gmail.com <ma...@gmail.com> | ggregory@apache.org  <ma...@apache.org>
> Java Persistence with Hibernate, Second Edition <http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com <http://garygregory.wordpress.com/> 
> Home: http://garygregory.com/ <http://garygregory.com/>
> Tweet! http://twitter.com/GaryGregory <http://twitter.com/GaryGregory>
> 
> 
> -- 
> E-Mail: garydgregory@gmail.com <ma...@gmail.com> | ggregory@apache.org  <ma...@apache.org>
> Java Persistence with Hibernate, Second Edition <http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com <http://garygregory.wordpress.com/> 
> Home: http://garygregory.com/ <http://garygregory.com/>
> Tweet! http://twitter.com/GaryGregory <http://twitter.com/GaryGregory>

Re: GC lean way to convert StringBuilder to byte[]

Posted by Gary Gregory <ga...@gmail.com>.
On Tue, Feb 23, 2016 at 8:23 AM, Gary Gregory <ga...@gmail.com>
wrote:

> I see we now have:
>
> org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer2
>
> Should we
> deprecate org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer
> and reimplement everything in terms of Serializer2, even if objects are
> allocated?
>

Thoughts on this?

Gary


>
> Gary
>
> On Tue, Feb 23, 2016 at 7:59 AM, Remko Popma <re...@gmail.com>
> wrote:
>
>> Layout now extends Encoder so now it has this method:
>>
>> encode(LogEvent source, ByteBufferDestination destination)
>>
>> PatternLayout implements this method. It delegates the work of converting
>> the StringBuilder to bytes and writing these bytes into the
>> ByteBufferDestination to the TextEncoderHelper class. No objects are
>> created during this conversion.
>>
>> The final piece is (Rolling)RandomAccessFileAppender, whose manager
>> implements ByteBufferDestination. This appender calls the #encode() methos
>> on the layout (other managers still call Layout#toByteArray).
>>
>>
>>
>> On Wed, Feb 24, 2016 at 12:47 AM, Mikael Ståldal <
>> mikael.staldal@magine.com> wrote:
>>
>>> I cannot really find it.
>>>
>>> On Tue, Feb 23, 2016 at 3:59 PM, Remko Popma <re...@gmail.com>
>>> wrote:
>>>
>>>> Yes, that was implemented in
>>>> https://issues.apache.org/jira/browse/LOG4J2-1274.
>>>>
>>>> Please also see the description and discussion in the epic
>>>> https://issues.apache.org/jira/browse/LOG4J2-1270.
>>>>
>>>> Sent from my iPhone
>>>>
>>>> On 2016/02/23, at 23:56, Mikael Ståldal <mi...@magine.com>
>>>> wrote:
>>>>
>>>> Do we have any way to convert a StringBuilder to a byte[], without any
>>>> intermediate String?
>>>>
>>>> It seems like org.apache.logging.log4j.core.util.StringEncoder cannot
>>>> do it.
>>>>
>>>> --
>>>> [image: MagineTV]
>>>>
>>>> *Mikael Ståldal*
>>>> Senior software developer
>>>>
>>>> *Magine TV*
>>>> mikael.staldal@magine.com
>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>
>>>> Privileged and/or Confidential Information may be contained in this
>>>> message. If you are not the addressee indicated in this message
>>>> (or responsible for delivery of the message to such a person), you may
>>>> not copy or deliver this message to anyone. In such case,
>>>> you should destroy this message and kindly notify the sender by reply
>>>> email.
>>>>
>>>>
>>>
>>>
>>> --
>>> [image: MagineTV]
>>>
>>> *Mikael Ståldal*
>>> Senior software developer
>>>
>>> *Magine TV*
>>> mikael.staldal@magine.com
>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>
>>> Privileged and/or Confidential Information may be contained in this
>>> message. If you are not the addressee indicated in this message
>>> (or responsible for delivery of the message to such a person), you may
>>> not copy or deliver this message to anyone. In such case,
>>> you should destroy this message and kindly notify the sender by reply
>>> email.
>>>
>>
>>
>
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition
> <http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>



-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: GC lean way to convert StringBuilder to byte[]

Posted by Remko Popma <re...@gmail.com>.
You can always do StringBuilder.toString().getBytes().

Or you can create a byte[] array up front, call ByteBuffer.wrap(byte[]) on
it, and use TextEncoderHelper.encode().
When done you can access the wrapped byte[] array.



On Wednesday, 24 February 2016, Mikael Ståldal <mi...@magine.com>
wrote:

> But it would be useful to have a way to go from StringBuilder to byte[]
> (not ByteBuffer) as well, to be able to optimize a layout and still have it
> working together with all existing appenders.
>
> On Wed, Feb 24, 2016 at 11:19 AM, Remko Popma <remko.popma@gmail.com
> <javascript:_e(%7B%7D,'cvml','remko.popma@gmail.com');>> wrote:
>
>> StringBuilder implements CharSequence; the copy method takes a CharSequence
>> as its source of characters.
>>
>>
>> On Wednesday, 24 February 2016, Remko Popma <remko.popma@gmail.com
>> <javascript:_e(%7B%7D,'cvml','remko.popma@gmail.com');>> wrote:
>>
>>> See TextEncoderHelper's methods,
>>> copy: from StringBuilder to CharBuffer
>>> encodeText: from CharBuffer to ByteBufferDestination
>>>
>>> We don't want to create the byte[] array object so we write directly
>>> into the ByteBuffer.
>>>
>>> On Wednesday, 24 February 2016, Mikael Ståldal <
>>> mikael.staldal@magine.com> wrote:
>>>
>>>> I still cannot find a way to convert a StringBuilder to a byte[].
>>>>
>>>> On Tue, Feb 23, 2016 at 11:03 PM, Gary Gregory <ga...@gmail.com>
>>>> wrote:
>>>>
>>>>> How about /dropping/ Serializer1 altogether? Having both is mighty
>>>>> complicated.
>>>>>
>>>>> Gary
>>>>>
>>>>> On Tue, Feb 23, 2016 at 8:52 AM, Remko Popma <re...@gmail.com>
>>>>> wrote:
>>>>>
>>>>>> I wouldn't mind that (no strong opinion either way) but I won't have
>>>>>> time to do that work.
>>>>>>
>>>>>> On Wed, Feb 24, 2016 at 1:23 AM, Gary Gregory <garydgregory@gmail.com
>>>>>> > wrote:
>>>>>>
>>>>>>> I see we now have:
>>>>>>>
>>>>>>> org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer2
>>>>>>>
>>>>>>> Should we
>>>>>>> deprecate org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer
>>>>>>> and reimplement everything in terms of Serializer2, even if objects are
>>>>>>> allocated?
>>>>>>>
>>>>>>> Gary
>>>>>>>
>>>>>>> On Tue, Feb 23, 2016 at 7:59 AM, Remko Popma <re...@gmail.com>
>>>>>>> wrote:
>>>>>>>
>>>>>>>> Layout now extends Encoder so now it has this method:
>>>>>>>>
>>>>>>>> encode(LogEvent source, ByteBufferDestination destination)
>>>>>>>>
>>>>>>>> PatternLayout implements this method. It delegates the work of
>>>>>>>> converting the StringBuilder to bytes and writing these bytes into the
>>>>>>>> ByteBufferDestination to the TextEncoderHelper class. No objects are
>>>>>>>> created during this conversion.
>>>>>>>>
>>>>>>>> The final piece is (Rolling)RandomAccessFileAppender, whose manager
>>>>>>>> implements ByteBufferDestination. This appender calls the #encode() methos
>>>>>>>> on the layout (other managers still call Layout#toByteArray).
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On Wed, Feb 24, 2016 at 12:47 AM, Mikael Ståldal <
>>>>>>>> mikael.staldal@magine.com> wrote:
>>>>>>>>
>>>>>>>>> I cannot really find it.
>>>>>>>>>
>>>>>>>>> On Tue, Feb 23, 2016 at 3:59 PM, Remko Popma <
>>>>>>>>> remko.popma@gmail.com> wrote:
>>>>>>>>>
>>>>>>>>>> Yes, that was implemented in
>>>>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1274.
>>>>>>>>>>
>>>>>>>>>> Please also see the description and discussion in the epic
>>>>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1270.
>>>>>>>>>>
>>>>>>>>>> Sent from my iPhone
>>>>>>>>>>
>>>>>>>>>> On 2016/02/23, at 23:56, Mikael Ståldal <
>>>>>>>>>> mikael.staldal@magine.com> wrote:
>>>>>>>>>>
>>>>>>>>>> Do we have any way to convert a StringBuilder to a byte[],
>>>>>>>>>> without any intermediate String?
>>>>>>>>>>
>>>>>>>>>> It seems like org.apache.logging.log4j.core.util.StringEncoder cannot
>>>>>>>>>> do it.
>>>>>>>>>>
>>>>>>>>>> --
>>>>>>>>>> [image: MagineTV]
>>>>>>>>>>
>>>>>>>>>> *Mikael Ståldal*
>>>>>>>>>> Senior software developer
>>>>>>>>>>
>>>>>>>>>> *Magine TV*
>>>>>>>>>> mikael.staldal@magine.com
>>>>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>>>>>
>>>>>>>>>> Privileged and/or Confidential Information may be contained in
>>>>>>>>>> this message. If you are not the addressee indicated in this message
>>>>>>>>>> (or responsible for delivery of the message to such a person),
>>>>>>>>>> you may not copy or deliver this message to anyone. In such case,
>>>>>>>>>> you should destroy this message and kindly notify the sender by
>>>>>>>>>> reply email.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> [image: MagineTV]
>>>>>>>>>
>>>>>>>>> *Mikael Ståldal*
>>>>>>>>> Senior software developer
>>>>>>>>>
>>>>>>>>> *Magine TV*
>>>>>>>>> mikael.staldal@magine.com
>>>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>>>>
>>>>>>>>> Privileged and/or Confidential Information may be contained in
>>>>>>>>> this message. If you are not the addressee indicated in this message
>>>>>>>>> (or responsible for delivery of the message to such a person), you
>>>>>>>>> may not copy or deliver this message to anyone. In such case,
>>>>>>>>> you should destroy this message and kindly notify the sender by
>>>>>>>>> reply email.
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>>>> Java Persistence with Hibernate, Second Edition
>>>>>>> <http://www.manning.com/bauer3/>
>>>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>>>>> Blog: http://garygregory.wordpress.com
>>>>>>> Home: http://garygregory.com/
>>>>>>> Tweet! http://twitter.com/GaryGregory
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>> Java Persistence with Hibernate, Second Edition
>>>>> <http://www.manning.com/bauer3/>
>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>>> Blog: http://garygregory.wordpress.com
>>>>> Home: http://garygregory.com/
>>>>> Tweet! http://twitter.com/GaryGregory
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> [image: MagineTV]
>>>>
>>>> *Mikael Ståldal*
>>>> Senior software developer
>>>>
>>>> *Magine TV*
>>>> mikael.staldal@magine.com
>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>
>>>> Privileged and/or Confidential Information may be contained in this
>>>> message. If you are not the addressee indicated in this message
>>>> (or responsible for delivery of the message to such a person), you may
>>>> not copy or deliver this message to anyone. In such case,
>>>> you should destroy this message and kindly notify the sender by reply
>>>> email.
>>>>
>>>
>
>
> --
> [image: MagineTV]
>
> *Mikael Ståldal*
> Senior software developer
>
> *Magine TV*
> mikael.staldal@magine.com
> <javascript:_e(%7B%7D,'cvml','mikael.staldal@magine.com');>
> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>
> Privileged and/or Confidential Information may be contained in this
> message. If you are not the addressee indicated in this message
> (or responsible for delivery of the message to such a person), you may not
> copy or deliver this message to anyone. In such case,
> you should destroy this message and kindly notify the sender by reply
> email.
>

Re: GC lean way to convert StringBuilder to byte[]

Posted by Gary Gregory <ga...@gmail.com>.
Some folks call this "zero-copy".

Gary

On Wed, Feb 24, 2016 at 7:50 AM, Remko Popma <re...@gmail.com> wrote:

> Ah, now I finally get what you mean by optimize, you want to avoid making
> copies. That is certainly a good idea.
> One thing I considered at some point was to let the PatternConverters
> write to a ByteBuffer instead of to a StringBuilder.
> That may be an interesting thing to experiment with. I would recommend
> using a ByteBuffer for this. You can wrap a byte[] array in a ByteBuffer
> and when the PatternConverters are done writing to the ByteBuffer, use the
> underlying byte[] array to feed data to the legacy appenders.
>
> On Wed, Feb 24, 2016 at 9:16 PM, Mikael Ståldal <mikael.staldal@magine.com
> > wrote:
>
>> I want to optimize toByteArray() in an appender, and have all existing
>> appenders take advantage of it (without having to use encode).
>>
>> I don't want to use StringBuilder.toString(), I want to avoid the
>> intermediate String object.
>>
>> This is not only about avoiding GC, it is also about avoiding unnecessary
>> copying of data.
>>
>> On Wed, Feb 24, 2016 at 12:06 PM, Remko Popma <re...@gmail.com>
>> wrote:
>>
>>> I don't understand though:  appenders should only call encode() if they
>>> can offer the Layout a ByteBuffer to write into...
>>>
>>> Sent from my iPhone
>>>
>>> On 2016/02/24, at 19:36, Mikael Ståldal <mi...@magine.com>
>>> wrote:
>>>
>>> But it would be useful to have a way to go from StringBuilder to byte[]
>>> (not ByteBuffer) as well, to be able to optimize a layout and still have it
>>> working together with all existing appenders.
>>>
>>> On Wed, Feb 24, 2016 at 11:19 AM, Remko Popma <re...@gmail.com>
>>> wrote:
>>>
>>>> StringBuilder implements CharSequence; the copy method takes a CharSequence
>>>> as its source of characters.
>>>>
>>>>
>>>> On Wednesday, 24 February 2016, Remko Popma <re...@gmail.com>
>>>> wrote:
>>>>
>>>>> See TextEncoderHelper's methods,
>>>>> copy: from StringBuilder to CharBuffer
>>>>> encodeText: from CharBuffer to ByteBufferDestination
>>>>>
>>>>> We don't want to create the byte[] array object so we write directly
>>>>> into the ByteBuffer.
>>>>>
>>>>> On Wednesday, 24 February 2016, Mikael Ståldal <
>>>>> mikael.staldal@magine.com> wrote:
>>>>>
>>>>>> I still cannot find a way to convert a StringBuilder to a byte[].
>>>>>>
>>>>>> On Tue, Feb 23, 2016 at 11:03 PM, Gary Gregory <
>>>>>> garydgregory@gmail.com> wrote:
>>>>>>
>>>>>>> How about /dropping/ Serializer1 altogether? Having both is mighty
>>>>>>> complicated.
>>>>>>>
>>>>>>> Gary
>>>>>>>
>>>>>>> On Tue, Feb 23, 2016 at 8:52 AM, Remko Popma <re...@gmail.com>
>>>>>>> wrote:
>>>>>>>
>>>>>>>> I wouldn't mind that (no strong opinion either way) but I won't
>>>>>>>> have time to do that work.
>>>>>>>>
>>>>>>>> On Wed, Feb 24, 2016 at 1:23 AM, Gary Gregory <
>>>>>>>> garydgregory@gmail.com> wrote:
>>>>>>>>
>>>>>>>>> I see we now have:
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer2
>>>>>>>>>
>>>>>>>>> Should we
>>>>>>>>> deprecate org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer
>>>>>>>>> and reimplement everything in terms of Serializer2, even if objects are
>>>>>>>>> allocated?
>>>>>>>>>
>>>>>>>>> Gary
>>>>>>>>>
>>>>>>>>> On Tue, Feb 23, 2016 at 7:59 AM, Remko Popma <
>>>>>>>>> remko.popma@gmail.com> wrote:
>>>>>>>>>
>>>>>>>>>> Layout now extends Encoder so now it has this method:
>>>>>>>>>>
>>>>>>>>>> encode(LogEvent source, ByteBufferDestination destination)
>>>>>>>>>>
>>>>>>>>>> PatternLayout implements this method. It delegates the work of
>>>>>>>>>> converting the StringBuilder to bytes and writing these bytes into the
>>>>>>>>>> ByteBufferDestination to the TextEncoderHelper class. No objects are
>>>>>>>>>> created during this conversion.
>>>>>>>>>>
>>>>>>>>>> The final piece is (Rolling)RandomAccessFileAppender, whose
>>>>>>>>>> manager implements ByteBufferDestination. This appender calls the #encode()
>>>>>>>>>> methos on the layout (other managers still call Layout#toByteArray).
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On Wed, Feb 24, 2016 at 12:47 AM, Mikael Ståldal <
>>>>>>>>>> mikael.staldal@magine.com> wrote:
>>>>>>>>>>
>>>>>>>>>>> I cannot really find it.
>>>>>>>>>>>
>>>>>>>>>>> On Tue, Feb 23, 2016 at 3:59 PM, Remko Popma <
>>>>>>>>>>> remko.popma@gmail.com> wrote:
>>>>>>>>>>>
>>>>>>>>>>>> Yes, that was implemented in
>>>>>>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1274.
>>>>>>>>>>>>
>>>>>>>>>>>> Please also see the description and discussion in the epic
>>>>>>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1270.
>>>>>>>>>>>>
>>>>>>>>>>>> Sent from my iPhone
>>>>>>>>>>>>
>>>>>>>>>>>> On 2016/02/23, at 23:56, Mikael Ståldal <
>>>>>>>>>>>> mikael.staldal@magine.com> wrote:
>>>>>>>>>>>>
>>>>>>>>>>>> Do we have any way to convert a StringBuilder to a byte[],
>>>>>>>>>>>> without any intermediate String?
>>>>>>>>>>>>
>>>>>>>>>>>> It seems like org.apache.logging.log4j.core.util.StringEncoder cannot
>>>>>>>>>>>> do it.
>>>>>>>>>>>>
>>>>>>>>>>>> --
>>>>>>>>>>>> [image: MagineTV]
>>>>>>>>>>>>
>>>>>>>>>>>> *Mikael Ståldal*
>>>>>>>>>>>> Senior software developer
>>>>>>>>>>>>
>>>>>>>>>>>> *Magine TV*
>>>>>>>>>>>> mikael.staldal@magine.com
>>>>>>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |
>>>>>>>>>>>> www.magine.com
>>>>>>>>>>>>
>>>>>>>>>>>> Privileged and/or Confidential Information may be contained in
>>>>>>>>>>>> this message. If you are not the addressee indicated in this message
>>>>>>>>>>>> (or responsible for delivery of the message to such a person),
>>>>>>>>>>>> you may not copy or deliver this message to anyone. In such case,
>>>>>>>>>>>> you should destroy this message and kindly notify the sender by
>>>>>>>>>>>> reply email.
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> --
>>>>>>>>>>> [image: MagineTV]
>>>>>>>>>>>
>>>>>>>>>>> *Mikael Ståldal*
>>>>>>>>>>> Senior software developer
>>>>>>>>>>>
>>>>>>>>>>> *Magine TV*
>>>>>>>>>>> mikael.staldal@magine.com
>>>>>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>>>>>>
>>>>>>>>>>> Privileged and/or Confidential Information may be contained in
>>>>>>>>>>> this message. If you are not the addressee indicated in this message
>>>>>>>>>>> (or responsible for delivery of the message to such a person),
>>>>>>>>>>> you may not copy or deliver this message to anyone. In such case,
>>>>>>>>>>> you should destroy this message and kindly notify the sender by
>>>>>>>>>>> reply email.
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>>>>>> Java Persistence with Hibernate, Second Edition
>>>>>>>>> <http://www.manning.com/bauer3/>
>>>>>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>>>>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>>>>>>> Blog: http://garygregory.wordpress.com
>>>>>>>>> Home: http://garygregory.com/
>>>>>>>>> Tweet! http://twitter.com/GaryGregory
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>>>> Java Persistence with Hibernate, Second Edition
>>>>>>> <http://www.manning.com/bauer3/>
>>>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>>>>> Blog: http://garygregory.wordpress.com
>>>>>>> Home: http://garygregory.com/
>>>>>>> Tweet! http://twitter.com/GaryGregory
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> [image: MagineTV]
>>>>>>
>>>>>> *Mikael Ståldal*
>>>>>> Senior software developer
>>>>>>
>>>>>> *Magine TV*
>>>>>> mikael.staldal@magine.com
>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>
>>>>>> Privileged and/or Confidential Information may be contained in this
>>>>>> message. If you are not the addressee indicated in this message
>>>>>> (or responsible for delivery of the message to such a person), you
>>>>>> may not copy or deliver this message to anyone. In such case,
>>>>>> you should destroy this message and kindly notify the sender by reply
>>>>>> email.
>>>>>>
>>>>>
>>>
>>>
>>> --
>>> [image: MagineTV]
>>>
>>> *Mikael Ståldal*
>>> Senior software developer
>>>
>>> *Magine TV*
>>> mikael.staldal@magine.com
>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>
>>> Privileged and/or Confidential Information may be contained in this
>>> message. If you are not the addressee indicated in this message
>>> (or responsible for delivery of the message to such a person), you may
>>> not copy or deliver this message to anyone. In such case,
>>> you should destroy this message and kindly notify the sender by reply
>>> email.
>>>
>>>
>>
>>
>> --
>> [image: MagineTV]
>>
>> *Mikael Ståldal*
>> Senior software developer
>>
>> *Magine TV*
>> mikael.staldal@magine.com
>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>
>> Privileged and/or Confidential Information may be contained in this
>> message. If you are not the addressee indicated in this message
>> (or responsible for delivery of the message to such a person), you may
>> not copy or deliver this message to anyone. In such case,
>> you should destroy this message and kindly notify the sender by reply
>> email.
>>
>
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: GC lean way to convert StringBuilder to byte[]

Posted by Remko Popma <re...@gmail.com>.
Ah, now I finally get what you mean by optimize, you want to avoid making
copies. That is certainly a good idea.
One thing I considered at some point was to let the PatternConverters write
to a ByteBuffer instead of to a StringBuilder.
That may be an interesting thing to experiment with. I would recommend
using a ByteBuffer for this. You can wrap a byte[] array in a ByteBuffer
and when the PatternConverters are done writing to the ByteBuffer, use the
underlying byte[] array to feed data to the legacy appenders.

On Wed, Feb 24, 2016 at 9:16 PM, Mikael Ståldal <mi...@magine.com>
wrote:

> I want to optimize toByteArray() in an appender, and have all existing
> appenders take advantage of it (without having to use encode).
>
> I don't want to use StringBuilder.toString(), I want to avoid the
> intermediate String object.
>
> This is not only about avoiding GC, it is also about avoiding unnecessary
> copying of data.
>
> On Wed, Feb 24, 2016 at 12:06 PM, Remko Popma <re...@gmail.com>
> wrote:
>
>> I don't understand though:  appenders should only call encode() if they
>> can offer the Layout a ByteBuffer to write into...
>>
>> Sent from my iPhone
>>
>> On 2016/02/24, at 19:36, Mikael Ståldal <mi...@magine.com>
>> wrote:
>>
>> But it would be useful to have a way to go from StringBuilder to byte[]
>> (not ByteBuffer) as well, to be able to optimize a layout and still have it
>> working together with all existing appenders.
>>
>> On Wed, Feb 24, 2016 at 11:19 AM, Remko Popma <re...@gmail.com>
>> wrote:
>>
>>> StringBuilder implements CharSequence; the copy method takes a CharSequence
>>> as its source of characters.
>>>
>>>
>>> On Wednesday, 24 February 2016, Remko Popma <re...@gmail.com>
>>> wrote:
>>>
>>>> See TextEncoderHelper's methods,
>>>> copy: from StringBuilder to CharBuffer
>>>> encodeText: from CharBuffer to ByteBufferDestination
>>>>
>>>> We don't want to create the byte[] array object so we write directly
>>>> into the ByteBuffer.
>>>>
>>>> On Wednesday, 24 February 2016, Mikael Ståldal <
>>>> mikael.staldal@magine.com> wrote:
>>>>
>>>>> I still cannot find a way to convert a StringBuilder to a byte[].
>>>>>
>>>>> On Tue, Feb 23, 2016 at 11:03 PM, Gary Gregory <garydgregory@gmail.com
>>>>> > wrote:
>>>>>
>>>>>> How about /dropping/ Serializer1 altogether? Having both is mighty
>>>>>> complicated.
>>>>>>
>>>>>> Gary
>>>>>>
>>>>>> On Tue, Feb 23, 2016 at 8:52 AM, Remko Popma <re...@gmail.com>
>>>>>> wrote:
>>>>>>
>>>>>>> I wouldn't mind that (no strong opinion either way) but I won't have
>>>>>>> time to do that work.
>>>>>>>
>>>>>>> On Wed, Feb 24, 2016 at 1:23 AM, Gary Gregory <
>>>>>>> garydgregory@gmail.com> wrote:
>>>>>>>
>>>>>>>> I see we now have:
>>>>>>>>
>>>>>>>>
>>>>>>>> org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer2
>>>>>>>>
>>>>>>>> Should we
>>>>>>>> deprecate org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer
>>>>>>>> and reimplement everything in terms of Serializer2, even if objects are
>>>>>>>> allocated?
>>>>>>>>
>>>>>>>> Gary
>>>>>>>>
>>>>>>>> On Tue, Feb 23, 2016 at 7:59 AM, Remko Popma <remko.popma@gmail.com
>>>>>>>> > wrote:
>>>>>>>>
>>>>>>>>> Layout now extends Encoder so now it has this method:
>>>>>>>>>
>>>>>>>>> encode(LogEvent source, ByteBufferDestination destination)
>>>>>>>>>
>>>>>>>>> PatternLayout implements this method. It delegates the work of
>>>>>>>>> converting the StringBuilder to bytes and writing these bytes into the
>>>>>>>>> ByteBufferDestination to the TextEncoderHelper class. No objects are
>>>>>>>>> created during this conversion.
>>>>>>>>>
>>>>>>>>> The final piece is (Rolling)RandomAccessFileAppender, whose
>>>>>>>>> manager implements ByteBufferDestination. This appender calls the #encode()
>>>>>>>>> methos on the layout (other managers still call Layout#toByteArray).
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Wed, Feb 24, 2016 at 12:47 AM, Mikael Ståldal <
>>>>>>>>> mikael.staldal@magine.com> wrote:
>>>>>>>>>
>>>>>>>>>> I cannot really find it.
>>>>>>>>>>
>>>>>>>>>> On Tue, Feb 23, 2016 at 3:59 PM, Remko Popma <
>>>>>>>>>> remko.popma@gmail.com> wrote:
>>>>>>>>>>
>>>>>>>>>>> Yes, that was implemented in
>>>>>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1274.
>>>>>>>>>>>
>>>>>>>>>>> Please also see the description and discussion in the epic
>>>>>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1270.
>>>>>>>>>>>
>>>>>>>>>>> Sent from my iPhone
>>>>>>>>>>>
>>>>>>>>>>> On 2016/02/23, at 23:56, Mikael Ståldal <
>>>>>>>>>>> mikael.staldal@magine.com> wrote:
>>>>>>>>>>>
>>>>>>>>>>> Do we have any way to convert a StringBuilder to a byte[],
>>>>>>>>>>> without any intermediate String?
>>>>>>>>>>>
>>>>>>>>>>> It seems like org.apache.logging.log4j.core.util.StringEncoder cannot
>>>>>>>>>>> do it.
>>>>>>>>>>>
>>>>>>>>>>> --
>>>>>>>>>>> [image: MagineTV]
>>>>>>>>>>>
>>>>>>>>>>> *Mikael Ståldal*
>>>>>>>>>>> Senior software developer
>>>>>>>>>>>
>>>>>>>>>>> *Magine TV*
>>>>>>>>>>> mikael.staldal@magine.com
>>>>>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>>>>>>
>>>>>>>>>>> Privileged and/or Confidential Information may be contained in
>>>>>>>>>>> this message. If you are not the addressee indicated in this message
>>>>>>>>>>> (or responsible for delivery of the message to such a person),
>>>>>>>>>>> you may not copy or deliver this message to anyone. In such case,
>>>>>>>>>>> you should destroy this message and kindly notify the sender by
>>>>>>>>>>> reply email.
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> --
>>>>>>>>>> [image: MagineTV]
>>>>>>>>>>
>>>>>>>>>> *Mikael Ståldal*
>>>>>>>>>> Senior software developer
>>>>>>>>>>
>>>>>>>>>> *Magine TV*
>>>>>>>>>> mikael.staldal@magine.com
>>>>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>>>>>
>>>>>>>>>> Privileged and/or Confidential Information may be contained in
>>>>>>>>>> this message. If you are not the addressee indicated in this message
>>>>>>>>>> (or responsible for delivery of the message to such a person),
>>>>>>>>>> you may not copy or deliver this message to anyone. In such case,
>>>>>>>>>> you should destroy this message and kindly notify the sender by
>>>>>>>>>> reply email.
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>>>>> Java Persistence with Hibernate, Second Edition
>>>>>>>> <http://www.manning.com/bauer3/>
>>>>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>>>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>>>>>> Blog: http://garygregory.wordpress.com
>>>>>>>> Home: http://garygregory.com/
>>>>>>>> Tweet! http://twitter.com/GaryGregory
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>>> Java Persistence with Hibernate, Second Edition
>>>>>> <http://www.manning.com/bauer3/>
>>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>>>> Blog: http://garygregory.wordpress.com
>>>>>> Home: http://garygregory.com/
>>>>>> Tweet! http://twitter.com/GaryGregory
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> [image: MagineTV]
>>>>>
>>>>> *Mikael Ståldal*
>>>>> Senior software developer
>>>>>
>>>>> *Magine TV*
>>>>> mikael.staldal@magine.com
>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>
>>>>> Privileged and/or Confidential Information may be contained in this
>>>>> message. If you are not the addressee indicated in this message
>>>>> (or responsible for delivery of the message to such a person), you may
>>>>> not copy or deliver this message to anyone. In such case,
>>>>> you should destroy this message and kindly notify the sender by reply
>>>>> email.
>>>>>
>>>>
>>
>>
>> --
>> [image: MagineTV]
>>
>> *Mikael Ståldal*
>> Senior software developer
>>
>> *Magine TV*
>> mikael.staldal@magine.com
>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>
>> Privileged and/or Confidential Information may be contained in this
>> message. If you are not the addressee indicated in this message
>> (or responsible for delivery of the message to such a person), you may
>> not copy or deliver this message to anyone. In such case,
>> you should destroy this message and kindly notify the sender by reply
>> email.
>>
>>
>
>
> --
> [image: MagineTV]
>
> *Mikael Ståldal*
> Senior software developer
>
> *Magine TV*
> mikael.staldal@magine.com
> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>
> Privileged and/or Confidential Information may be contained in this
> message. If you are not the addressee indicated in this message
> (or responsible for delivery of the message to such a person), you may not
> copy or deliver this message to anyone. In such case,
> you should destroy this message and kindly notify the sender by reply
> email.
>

Re: GC lean way to convert StringBuilder to byte[]

Posted by Mikael Ståldal <mi...@magine.com>.
I want to optimize toByteArray() in an appender, and have all existing
appenders take advantage of it (without having to use encode).

I don't want to use StringBuilder.toString(), I want to avoid the
intermediate String object.

This is not only about avoiding GC, it is also about avoiding unnecessary
copying of data.

On Wed, Feb 24, 2016 at 12:06 PM, Remko Popma <re...@gmail.com> wrote:

> I don't understand though:  appenders should only call encode() if they
> can offer the Layout a ByteBuffer to write into...
>
> Sent from my iPhone
>
> On 2016/02/24, at 19:36, Mikael Ståldal <mi...@magine.com> wrote:
>
> But it would be useful to have a way to go from StringBuilder to byte[]
> (not ByteBuffer) as well, to be able to optimize a layout and still have it
> working together with all existing appenders.
>
> On Wed, Feb 24, 2016 at 11:19 AM, Remko Popma <re...@gmail.com>
> wrote:
>
>> StringBuilder implements CharSequence; the copy method takes a CharSequence
>> as its source of characters.
>>
>>
>> On Wednesday, 24 February 2016, Remko Popma <re...@gmail.com>
>> wrote:
>>
>>> See TextEncoderHelper's methods,
>>> copy: from StringBuilder to CharBuffer
>>> encodeText: from CharBuffer to ByteBufferDestination
>>>
>>> We don't want to create the byte[] array object so we write directly
>>> into the ByteBuffer.
>>>
>>> On Wednesday, 24 February 2016, Mikael Ståldal <
>>> mikael.staldal@magine.com> wrote:
>>>
>>>> I still cannot find a way to convert a StringBuilder to a byte[].
>>>>
>>>> On Tue, Feb 23, 2016 at 11:03 PM, Gary Gregory <ga...@gmail.com>
>>>> wrote:
>>>>
>>>>> How about /dropping/ Serializer1 altogether? Having both is mighty
>>>>> complicated.
>>>>>
>>>>> Gary
>>>>>
>>>>> On Tue, Feb 23, 2016 at 8:52 AM, Remko Popma <re...@gmail.com>
>>>>> wrote:
>>>>>
>>>>>> I wouldn't mind that (no strong opinion either way) but I won't have
>>>>>> time to do that work.
>>>>>>
>>>>>> On Wed, Feb 24, 2016 at 1:23 AM, Gary Gregory <garydgregory@gmail.com
>>>>>> > wrote:
>>>>>>
>>>>>>> I see we now have:
>>>>>>>
>>>>>>> org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer2
>>>>>>>
>>>>>>> Should we
>>>>>>> deprecate org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer
>>>>>>> and reimplement everything in terms of Serializer2, even if objects are
>>>>>>> allocated?
>>>>>>>
>>>>>>> Gary
>>>>>>>
>>>>>>> On Tue, Feb 23, 2016 at 7:59 AM, Remko Popma <re...@gmail.com>
>>>>>>> wrote:
>>>>>>>
>>>>>>>> Layout now extends Encoder so now it has this method:
>>>>>>>>
>>>>>>>> encode(LogEvent source, ByteBufferDestination destination)
>>>>>>>>
>>>>>>>> PatternLayout implements this method. It delegates the work of
>>>>>>>> converting the StringBuilder to bytes and writing these bytes into the
>>>>>>>> ByteBufferDestination to the TextEncoderHelper class. No objects are
>>>>>>>> created during this conversion.
>>>>>>>>
>>>>>>>> The final piece is (Rolling)RandomAccessFileAppender, whose manager
>>>>>>>> implements ByteBufferDestination. This appender calls the #encode() methos
>>>>>>>> on the layout (other managers still call Layout#toByteArray).
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On Wed, Feb 24, 2016 at 12:47 AM, Mikael Ståldal <
>>>>>>>> mikael.staldal@magine.com> wrote:
>>>>>>>>
>>>>>>>>> I cannot really find it.
>>>>>>>>>
>>>>>>>>> On Tue, Feb 23, 2016 at 3:59 PM, Remko Popma <
>>>>>>>>> remko.popma@gmail.com> wrote:
>>>>>>>>>
>>>>>>>>>> Yes, that was implemented in
>>>>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1274.
>>>>>>>>>>
>>>>>>>>>> Please also see the description and discussion in the epic
>>>>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1270.
>>>>>>>>>>
>>>>>>>>>> Sent from my iPhone
>>>>>>>>>>
>>>>>>>>>> On 2016/02/23, at 23:56, Mikael Ståldal <
>>>>>>>>>> mikael.staldal@magine.com> wrote:
>>>>>>>>>>
>>>>>>>>>> Do we have any way to convert a StringBuilder to a byte[],
>>>>>>>>>> without any intermediate String?
>>>>>>>>>>
>>>>>>>>>> It seems like org.apache.logging.log4j.core.util.StringEncoder cannot
>>>>>>>>>> do it.
>>>>>>>>>>
>>>>>>>>>> --
>>>>>>>>>> [image: MagineTV]
>>>>>>>>>>
>>>>>>>>>> *Mikael Ståldal*
>>>>>>>>>> Senior software developer
>>>>>>>>>>
>>>>>>>>>> *Magine TV*
>>>>>>>>>> mikael.staldal@magine.com
>>>>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>>>>>
>>>>>>>>>> Privileged and/or Confidential Information may be contained in
>>>>>>>>>> this message. If you are not the addressee indicated in this message
>>>>>>>>>> (or responsible for delivery of the message to such a person),
>>>>>>>>>> you may not copy or deliver this message to anyone. In such case,
>>>>>>>>>> you should destroy this message and kindly notify the sender by
>>>>>>>>>> reply email.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> [image: MagineTV]
>>>>>>>>>
>>>>>>>>> *Mikael Ståldal*
>>>>>>>>> Senior software developer
>>>>>>>>>
>>>>>>>>> *Magine TV*
>>>>>>>>> mikael.staldal@magine.com
>>>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>>>>
>>>>>>>>> Privileged and/or Confidential Information may be contained in
>>>>>>>>> this message. If you are not the addressee indicated in this message
>>>>>>>>> (or responsible for delivery of the message to such a person), you
>>>>>>>>> may not copy or deliver this message to anyone. In such case,
>>>>>>>>> you should destroy this message and kindly notify the sender by
>>>>>>>>> reply email.
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>>>> Java Persistence with Hibernate, Second Edition
>>>>>>> <http://www.manning.com/bauer3/>
>>>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>>>>> Blog: http://garygregory.wordpress.com
>>>>>>> Home: http://garygregory.com/
>>>>>>> Tweet! http://twitter.com/GaryGregory
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>> Java Persistence with Hibernate, Second Edition
>>>>> <http://www.manning.com/bauer3/>
>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>>> Blog: http://garygregory.wordpress.com
>>>>> Home: http://garygregory.com/
>>>>> Tweet! http://twitter.com/GaryGregory
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> [image: MagineTV]
>>>>
>>>> *Mikael Ståldal*
>>>> Senior software developer
>>>>
>>>> *Magine TV*
>>>> mikael.staldal@magine.com
>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>
>>>> Privileged and/or Confidential Information may be contained in this
>>>> message. If you are not the addressee indicated in this message
>>>> (or responsible for delivery of the message to such a person), you may
>>>> not copy or deliver this message to anyone. In such case,
>>>> you should destroy this message and kindly notify the sender by reply
>>>> email.
>>>>
>>>
>
>
> --
> [image: MagineTV]
>
> *Mikael Ståldal*
> Senior software developer
>
> *Magine TV*
> mikael.staldal@magine.com
> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>
> Privileged and/or Confidential Information may be contained in this
> message. If you are not the addressee indicated in this message
> (or responsible for delivery of the message to such a person), you may not
> copy or deliver this message to anyone. In such case,
> you should destroy this message and kindly notify the sender by reply
> email.
>
>


-- 
[image: MagineTV]

*Mikael Ståldal*
Senior software developer

*Magine TV*
mikael.staldal@magine.com
Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com

Privileged and/or Confidential Information may be contained in this
message. If you are not the addressee indicated in this message
(or responsible for delivery of the message to such a person), you may not
copy or deliver this message to anyone. In such case,
you should destroy this message and kindly notify the sender by reply
email.

Re: GC lean way to convert StringBuilder to byte[]

Posted by Remko Popma <re...@gmail.com>.
I don't understand though:  appenders should only call encode() if they can offer the Layout a ByteBuffer to write into...

Sent from my iPhone

> On 2016/02/24, at 19:36, Mikael Ståldal <mi...@magine.com> wrote:
> 
> But it would be useful to have a way to go from StringBuilder to byte[] (not ByteBuffer) as well, to be able to optimize a layout and still have it working together with all existing appenders.
> 
>> On Wed, Feb 24, 2016 at 11:19 AM, Remko Popma <re...@gmail.com> wrote:
>> StringBuilder implements CharSequence; the copy method takes a CharSequence as its source of characters. 
>> 
>> 
>>> On Wednesday, 24 February 2016, Remko Popma <re...@gmail.com> wrote:
>>> See TextEncoderHelper's methods,
>>> copy: from StringBuilder to CharBuffer
>>> encodeText: from CharBuffer to ByteBufferDestination
>>> 
>>> We don't want to create the byte[] array object so we write directly into the ByteBuffer. 
>>> 
>>>> On Wednesday, 24 February 2016, Mikael Ståldal <mi...@magine.com> wrote:
>>>> I still cannot find a way to convert a StringBuilder to a byte[].
>>>> 
>>>>> On Tue, Feb 23, 2016 at 11:03 PM, Gary Gregory <ga...@gmail.com> wrote:
>>>>> How about /dropping/ Serializer1 altogether? Having both is mighty complicated.
>>>>> 
>>>>> Gary
>>>>> 
>>>>>> On Tue, Feb 23, 2016 at 8:52 AM, Remko Popma <re...@gmail.com> wrote:
>>>>>> I wouldn't mind that (no strong opinion either way) but I won't have time to do that work.
>>>>>> 
>>>>>>> On Wed, Feb 24, 2016 at 1:23 AM, Gary Gregory <ga...@gmail.com> wrote:
>>>>>>> I see we now have:
>>>>>>> 
>>>>>>> org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer2
>>>>>>> 
>>>>>>> Should we deprecate org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer and reimplement everything in terms of Serializer2, even if objects are allocated?
>>>>>>> 
>>>>>>> Gary
>>>>>>> 
>>>>>>>> On Tue, Feb 23, 2016 at 7:59 AM, Remko Popma <re...@gmail.com> wrote:
>>>>>>>> Layout now extends Encoder so now it has this method:
>>>>>>>> encode(LogEvent source, ByteBufferDestination destination)
>>>>>>>> PatternLayout implements this method. It delegates the work of converting the StringBuilder to bytes and writing these bytes into the ByteBufferDestination to the TextEncoderHelper class. No objects are created during this conversion.
>>>>>>>> 
>>>>>>>> The final piece is (Rolling)RandomAccessFileAppender, whose manager implements ByteBufferDestination. This appender calls the #encode() methos on the layout (other managers still call Layout#toByteArray).
>>>>>>>> 
>>>>>>>> 
>>>>>>>> 
>>>>>>>>> On Wed, Feb 24, 2016 at 12:47 AM, Mikael Ståldal <mi...@magine.com> wrote:
>>>>>>>>> I cannot really find it.
>>>>>>>>> 
>>>>>>>>>> On Tue, Feb 23, 2016 at 3:59 PM, Remko Popma <re...@gmail.com> wrote:
>>>>>>>>>> Yes, that was implemented in https://issues.apache.org/jira/browse/LOG4J2-1274. 
>>>>>>>>>> 
>>>>>>>>>> Please also see the description and discussion in the epic https://issues.apache.org/jira/browse/LOG4J2-1270. 
>>>>>>>>>> 
>>>>>>>>>> Sent from my iPhone
>>>>>>>>>> 
>>>>>>>>>>> On 2016/02/23, at 23:56, Mikael Ståldal <mi...@magine.com> wrote:
>>>>>>>>>>> 
>>>>>>>>>>> Do we have any way to convert a StringBuilder to a byte[], without any intermediate String?
>>>>>>>>>>> 
>>>>>>>>>>> It seems like org.apache.logging.log4j.core.util.StringEncoder cannot do it.
>>>>>>>>>>> 
>>>>>>>>>>> -- 
>>>>>>>>>>>  
>>>>>>>>>>> 
>>>>>>>>>>> Mikael Ståldal
>>>>>>>>>>> Senior software developer 
>>>>>>>>>>> 
>>>>>>>>>>> Magine TV
>>>>>>>>>>> mikael.staldal@magine.com    
>>>>>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com 
>>>>>>>>>>> 
>>>>>>>>>>> Privileged and/or Confidential Information may be contained in this message. If you are not the addressee indicated in this message
>>>>>>>>>>> (or responsible for delivery of the message to such a person), you may not copy or deliver this message to anyone. In such case, 
>>>>>>>>>>> you should destroy this message and kindly notify the sender by reply email.   
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> -- 
>>>>>>>>>  
>>>>>>>>> 
>>>>>>>>> Mikael Ståldal
>>>>>>>>> Senior software developer 
>>>>>>>>> 
>>>>>>>>> Magine TV
>>>>>>>>> mikael.staldal@magine.com    
>>>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com 
>>>>>>>>> 
>>>>>>>>> Privileged and/or Confidential Information may be contained in this message. If you are not the addressee indicated in this message
>>>>>>>>> (or responsible for delivery of the message to such a person), you may not copy or deliver this message to anyone. In such case, 
>>>>>>>>> you should destroy this message and kindly notify the sender by reply email.   
>>>>>>> 
>>>>>>> 
>>>>>>> 
>>>>>>> -- 
>>>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org 
>>>>>>> Java Persistence with Hibernate, Second Edition
>>>>>>> JUnit in Action, Second Edition
>>>>>>> Spring Batch in Action
>>>>>>> Blog: http://garygregory.wordpress.com 
>>>>>>> Home: http://garygregory.com/
>>>>>>> Tweet! http://twitter.com/GaryGregory
>>>>> 
>>>>> 
>>>>> 
>>>>> -- 
>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org 
>>>>> Java Persistence with Hibernate, Second Edition
>>>>> JUnit in Action, Second Edition
>>>>> Spring Batch in Action
>>>>> Blog: http://garygregory.wordpress.com 
>>>>> Home: http://garygregory.com/
>>>>> Tweet! http://twitter.com/GaryGregory
>>>> 
>>>> 
>>>> 
>>>> -- 
>>>>  
>>>> 
>>>> Mikael Ståldal
>>>> Senior software developer 
>>>> 
>>>> Magine TV
>>>> mikael.staldal@magine.com    
>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com 
>>>> 
>>>> Privileged and/or Confidential Information may be contained in this message. If you are not the addressee indicated in this message
>>>> (or responsible for delivery of the message to such a person), you may not copy or deliver this message to anyone. In such case, 
>>>> you should destroy this message and kindly notify the sender by reply email.   
> 
> 
> 
> -- 
>  
> 
> Mikael Ståldal
> Senior software developer 
> 
> Magine TV
> mikael.staldal@magine.com    
> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com             
> 
> Privileged and/or Confidential Information may be contained in this message. If you are not the addressee indicated in this message
> (or responsible for delivery of the message to such a person), you may not copy or deliver this message to anyone. In such case, 
> you should destroy this message and kindly notify the sender by reply email.   

Re: GC lean way to convert StringBuilder to byte[]

Posted by Mikael Ståldal <mi...@magine.com>.
But it would be useful to have a way to go from StringBuilder to byte[]
(not ByteBuffer) as well, to be able to optimize a layout and still have it
working together with all existing appenders.

On Wed, Feb 24, 2016 at 11:19 AM, Remko Popma <re...@gmail.com> wrote:

> StringBuilder implements CharSequence; the copy method takes a CharSequence
> as its source of characters.
>
>
> On Wednesday, 24 February 2016, Remko Popma <re...@gmail.com> wrote:
>
>> See TextEncoderHelper's methods,
>> copy: from StringBuilder to CharBuffer
>> encodeText: from CharBuffer to ByteBufferDestination
>>
>> We don't want to create the byte[] array object so we write directly into
>> the ByteBuffer.
>>
>> On Wednesday, 24 February 2016, Mikael Ståldal <mi...@magine.com>
>> wrote:
>>
>>> I still cannot find a way to convert a StringBuilder to a byte[].
>>>
>>> On Tue, Feb 23, 2016 at 11:03 PM, Gary Gregory <ga...@gmail.com>
>>> wrote:
>>>
>>>> How about /dropping/ Serializer1 altogether? Having both is mighty
>>>> complicated.
>>>>
>>>> Gary
>>>>
>>>> On Tue, Feb 23, 2016 at 8:52 AM, Remko Popma <re...@gmail.com>
>>>> wrote:
>>>>
>>>>> I wouldn't mind that (no strong opinion either way) but I won't have
>>>>> time to do that work.
>>>>>
>>>>> On Wed, Feb 24, 2016 at 1:23 AM, Gary Gregory <ga...@gmail.com>
>>>>> wrote:
>>>>>
>>>>>> I see we now have:
>>>>>>
>>>>>> org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer2
>>>>>>
>>>>>> Should we
>>>>>> deprecate org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer
>>>>>> and reimplement everything in terms of Serializer2, even if objects are
>>>>>> allocated?
>>>>>>
>>>>>> Gary
>>>>>>
>>>>>> On Tue, Feb 23, 2016 at 7:59 AM, Remko Popma <re...@gmail.com>
>>>>>> wrote:
>>>>>>
>>>>>>> Layout now extends Encoder so now it has this method:
>>>>>>>
>>>>>>> encode(LogEvent source, ByteBufferDestination destination)
>>>>>>>
>>>>>>> PatternLayout implements this method. It delegates the work of
>>>>>>> converting the StringBuilder to bytes and writing these bytes into the
>>>>>>> ByteBufferDestination to the TextEncoderHelper class. No objects are
>>>>>>> created during this conversion.
>>>>>>>
>>>>>>> The final piece is (Rolling)RandomAccessFileAppender, whose manager
>>>>>>> implements ByteBufferDestination. This appender calls the #encode() methos
>>>>>>> on the layout (other managers still call Layout#toByteArray).
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Wed, Feb 24, 2016 at 12:47 AM, Mikael Ståldal <
>>>>>>> mikael.staldal@magine.com> wrote:
>>>>>>>
>>>>>>>> I cannot really find it.
>>>>>>>>
>>>>>>>> On Tue, Feb 23, 2016 at 3:59 PM, Remko Popma <remko.popma@gmail.com
>>>>>>>> > wrote:
>>>>>>>>
>>>>>>>>> Yes, that was implemented in
>>>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1274.
>>>>>>>>>
>>>>>>>>> Please also see the description and discussion in the epic
>>>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1270.
>>>>>>>>>
>>>>>>>>> Sent from my iPhone
>>>>>>>>>
>>>>>>>>> On 2016/02/23, at 23:56, Mikael Ståldal <mi...@magine.com>
>>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>> Do we have any way to convert a StringBuilder to a byte[], without
>>>>>>>>> any intermediate String?
>>>>>>>>>
>>>>>>>>> It seems like org.apache.logging.log4j.core.util.StringEncoder cannot
>>>>>>>>> do it.
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> [image: MagineTV]
>>>>>>>>>
>>>>>>>>> *Mikael Ståldal*
>>>>>>>>> Senior software developer
>>>>>>>>>
>>>>>>>>> *Magine TV*
>>>>>>>>> mikael.staldal@magine.com
>>>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>>>>
>>>>>>>>> Privileged and/or Confidential Information may be contained in
>>>>>>>>> this message. If you are not the addressee indicated in this message
>>>>>>>>> (or responsible for delivery of the message to such a person), you
>>>>>>>>> may not copy or deliver this message to anyone. In such case,
>>>>>>>>> you should destroy this message and kindly notify the sender by
>>>>>>>>> reply email.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>> [image: MagineTV]
>>>>>>>>
>>>>>>>> *Mikael Ståldal*
>>>>>>>> Senior software developer
>>>>>>>>
>>>>>>>> *Magine TV*
>>>>>>>> mikael.staldal@magine.com
>>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>>>
>>>>>>>> Privileged and/or Confidential Information may be contained in this
>>>>>>>> message. If you are not the addressee indicated in this message
>>>>>>>> (or responsible for delivery of the message to such a person), you
>>>>>>>> may not copy or deliver this message to anyone. In such case,
>>>>>>>> you should destroy this message and kindly notify the sender by
>>>>>>>> reply email.
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>>> Java Persistence with Hibernate, Second Edition
>>>>>> <http://www.manning.com/bauer3/>
>>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>>>> Blog: http://garygregory.wordpress.com
>>>>>> Home: http://garygregory.com/
>>>>>> Tweet! http://twitter.com/GaryGregory
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>> Java Persistence with Hibernate, Second Edition
>>>> <http://www.manning.com/bauer3/>
>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>> Blog: http://garygregory.wordpress.com
>>>> Home: http://garygregory.com/
>>>> Tweet! http://twitter.com/GaryGregory
>>>>
>>>
>>>
>>>
>>> --
>>> [image: MagineTV]
>>>
>>> *Mikael Ståldal*
>>> Senior software developer
>>>
>>> *Magine TV*
>>> mikael.staldal@magine.com
>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>
>>> Privileged and/or Confidential Information may be contained in this
>>> message. If you are not the addressee indicated in this message
>>> (or responsible for delivery of the message to such a person), you may
>>> not copy or deliver this message to anyone. In such case,
>>> you should destroy this message and kindly notify the sender by reply
>>> email.
>>>
>>


-- 
[image: MagineTV]

*Mikael Ståldal*
Senior software developer

*Magine TV*
mikael.staldal@magine.com
Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com

Privileged and/or Confidential Information may be contained in this
message. If you are not the addressee indicated in this message
(or responsible for delivery of the message to such a person), you may not
copy or deliver this message to anyone. In such case,
you should destroy this message and kindly notify the sender by reply
email.

Re: GC lean way to convert StringBuilder to byte[]

Posted by Remko Popma <re...@gmail.com>.
StringBuilder implements CharSequence; the copy method takes a CharSequence
as its source of characters.

On Wednesday, 24 February 2016, Remko Popma <re...@gmail.com> wrote:

> See TextEncoderHelper's methods,
> copy: from StringBuilder to CharBuffer
> encodeText: from CharBuffer to ByteBufferDestination
>
> We don't want to create the byte[] array object so we write directly into
> the ByteBuffer.
>
> On Wednesday, 24 February 2016, Mikael Ståldal <mikael.staldal@magine.com
> <javascript:_e(%7B%7D,'cvml','mikael.staldal@magine.com');>> wrote:
>
>> I still cannot find a way to convert a StringBuilder to a byte[].
>>
>> On Tue, Feb 23, 2016 at 11:03 PM, Gary Gregory <ga...@gmail.com>
>> wrote:
>>
>>> How about /dropping/ Serializer1 altogether? Having both is mighty
>>> complicated.
>>>
>>> Gary
>>>
>>> On Tue, Feb 23, 2016 at 8:52 AM, Remko Popma <re...@gmail.com>
>>> wrote:
>>>
>>>> I wouldn't mind that (no strong opinion either way) but I won't have
>>>> time to do that work.
>>>>
>>>> On Wed, Feb 24, 2016 at 1:23 AM, Gary Gregory <ga...@gmail.com>
>>>> wrote:
>>>>
>>>>> I see we now have:
>>>>>
>>>>> org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer2
>>>>>
>>>>> Should we
>>>>> deprecate org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer
>>>>> and reimplement everything in terms of Serializer2, even if objects are
>>>>> allocated?
>>>>>
>>>>> Gary
>>>>>
>>>>> On Tue, Feb 23, 2016 at 7:59 AM, Remko Popma <re...@gmail.com>
>>>>> wrote:
>>>>>
>>>>>> Layout now extends Encoder so now it has this method:
>>>>>>
>>>>>> encode(LogEvent source, ByteBufferDestination destination)
>>>>>>
>>>>>> PatternLayout implements this method. It delegates the work of
>>>>>> converting the StringBuilder to bytes and writing these bytes into the
>>>>>> ByteBufferDestination to the TextEncoderHelper class. No objects are
>>>>>> created during this conversion.
>>>>>>
>>>>>> The final piece is (Rolling)RandomAccessFileAppender, whose manager
>>>>>> implements ByteBufferDestination. This appender calls the #encode() methos
>>>>>> on the layout (other managers still call Layout#toByteArray).
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Wed, Feb 24, 2016 at 12:47 AM, Mikael Ståldal <
>>>>>> mikael.staldal@magine.com> wrote:
>>>>>>
>>>>>>> I cannot really find it.
>>>>>>>
>>>>>>> On Tue, Feb 23, 2016 at 3:59 PM, Remko Popma <re...@gmail.com>
>>>>>>> wrote:
>>>>>>>
>>>>>>>> Yes, that was implemented in
>>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1274.
>>>>>>>>
>>>>>>>> Please also see the description and discussion in the epic
>>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1270.
>>>>>>>>
>>>>>>>> Sent from my iPhone
>>>>>>>>
>>>>>>>> On 2016/02/23, at 23:56, Mikael Ståldal <mi...@magine.com>
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>> Do we have any way to convert a StringBuilder to a byte[], without
>>>>>>>> any intermediate String?
>>>>>>>>
>>>>>>>> It seems like org.apache.logging.log4j.core.util.StringEncoder cannot
>>>>>>>> do it.
>>>>>>>>
>>>>>>>> --
>>>>>>>> [image: MagineTV]
>>>>>>>>
>>>>>>>> *Mikael Ståldal*
>>>>>>>> Senior software developer
>>>>>>>>
>>>>>>>> *Magine TV*
>>>>>>>> mikael.staldal@magine.com
>>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>>>
>>>>>>>> Privileged and/or Confidential Information may be contained in this
>>>>>>>> message. If you are not the addressee indicated in this message
>>>>>>>> (or responsible for delivery of the message to such a person), you
>>>>>>>> may not copy or deliver this message to anyone. In such case,
>>>>>>>> you should destroy this message and kindly notify the sender by
>>>>>>>> reply email.
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> [image: MagineTV]
>>>>>>>
>>>>>>> *Mikael Ståldal*
>>>>>>> Senior software developer
>>>>>>>
>>>>>>> *Magine TV*
>>>>>>> mikael.staldal@magine.com
>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>>
>>>>>>> Privileged and/or Confidential Information may be contained in this
>>>>>>> message. If you are not the addressee indicated in this message
>>>>>>> (or responsible for delivery of the message to such a person), you
>>>>>>> may not copy or deliver this message to anyone. In such case,
>>>>>>> you should destroy this message and kindly notify the sender by
>>>>>>> reply email.
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>> Java Persistence with Hibernate, Second Edition
>>>>> <http://www.manning.com/bauer3/>
>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>>> Blog: http://garygregory.wordpress.com
>>>>> Home: http://garygregory.com/
>>>>> Tweet! http://twitter.com/GaryGregory
>>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>> Java Persistence with Hibernate, Second Edition
>>> <http://www.manning.com/bauer3/>
>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>> Spring Batch in Action <http://www.manning.com/templier/>
>>> Blog: http://garygregory.wordpress.com
>>> Home: http://garygregory.com/
>>> Tweet! http://twitter.com/GaryGregory
>>>
>>
>>
>>
>> --
>> [image: MagineTV]
>>
>> *Mikael Ståldal*
>> Senior software developer
>>
>> *Magine TV*
>> mikael.staldal@magine.com
>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>
>> Privileged and/or Confidential Information may be contained in this
>> message. If you are not the addressee indicated in this message
>> (or responsible for delivery of the message to such a person), you may
>> not copy or deliver this message to anyone. In such case,
>> you should destroy this message and kindly notify the sender by reply
>> email.
>>
>

Re: GC lean way to convert StringBuilder to byte[]

Posted by Remko Popma <re...@gmail.com>.
See TextEncoderHelper's methods,
copy: from StringBuilder to CharBuffer
encodeText: from CharBuffer to ByteBufferDestination

We don't want to create the byte[] array object so we write directly into
the ByteBuffer.

On Wednesday, 24 February 2016, Mikael Ståldal <mi...@magine.com>
wrote:

> I still cannot find a way to convert a StringBuilder to a byte[].
>
> On Tue, Feb 23, 2016 at 11:03 PM, Gary Gregory <garydgregory@gmail.com
> <javascript:_e(%7B%7D,'cvml','garydgregory@gmail.com');>> wrote:
>
>> How about /dropping/ Serializer1 altogether? Having both is mighty
>> complicated.
>>
>> Gary
>>
>> On Tue, Feb 23, 2016 at 8:52 AM, Remko Popma <remko.popma@gmail.com
>> <javascript:_e(%7B%7D,'cvml','remko.popma@gmail.com');>> wrote:
>>
>>> I wouldn't mind that (no strong opinion either way) but I won't have
>>> time to do that work.
>>>
>>> On Wed, Feb 24, 2016 at 1:23 AM, Gary Gregory <garydgregory@gmail.com
>>> <javascript:_e(%7B%7D,'cvml','garydgregory@gmail.com');>> wrote:
>>>
>>>> I see we now have:
>>>>
>>>> org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer2
>>>>
>>>> Should we
>>>> deprecate org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer
>>>> and reimplement everything in terms of Serializer2, even if objects are
>>>> allocated?
>>>>
>>>> Gary
>>>>
>>>> On Tue, Feb 23, 2016 at 7:59 AM, Remko Popma <remko.popma@gmail.com
>>>> <javascript:_e(%7B%7D,'cvml','remko.popma@gmail.com');>> wrote:
>>>>
>>>>> Layout now extends Encoder so now it has this method:
>>>>>
>>>>> encode(LogEvent source, ByteBufferDestination destination)
>>>>>
>>>>> PatternLayout implements this method. It delegates the work of
>>>>> converting the StringBuilder to bytes and writing these bytes into the
>>>>> ByteBufferDestination to the TextEncoderHelper class. No objects are
>>>>> created during this conversion.
>>>>>
>>>>> The final piece is (Rolling)RandomAccessFileAppender, whose manager
>>>>> implements ByteBufferDestination. This appender calls the #encode() methos
>>>>> on the layout (other managers still call Layout#toByteArray).
>>>>>
>>>>>
>>>>>
>>>>> On Wed, Feb 24, 2016 at 12:47 AM, Mikael Ståldal <
>>>>> mikael.staldal@magine.com
>>>>> <javascript:_e(%7B%7D,'cvml','mikael.staldal@magine.com');>> wrote:
>>>>>
>>>>>> I cannot really find it.
>>>>>>
>>>>>> On Tue, Feb 23, 2016 at 3:59 PM, Remko Popma <remko.popma@gmail.com
>>>>>> <javascript:_e(%7B%7D,'cvml','remko.popma@gmail.com');>> wrote:
>>>>>>
>>>>>>> Yes, that was implemented in
>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1274.
>>>>>>>
>>>>>>> Please also see the description and discussion in the epic
>>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1270.
>>>>>>>
>>>>>>> Sent from my iPhone
>>>>>>>
>>>>>>> On 2016/02/23, at 23:56, Mikael Ståldal <mikael.staldal@magine.com
>>>>>>> <javascript:_e(%7B%7D,'cvml','mikael.staldal@magine.com');>> wrote:
>>>>>>>
>>>>>>> Do we have any way to convert a StringBuilder to a byte[], without
>>>>>>> any intermediate String?
>>>>>>>
>>>>>>> It seems like org.apache.logging.log4j.core.util.StringEncoder cannot
>>>>>>> do it.
>>>>>>>
>>>>>>> --
>>>>>>> [image: MagineTV]
>>>>>>>
>>>>>>> *Mikael Ståldal*
>>>>>>> Senior software developer
>>>>>>>
>>>>>>> *Magine TV*
>>>>>>> mikael.staldal@magine.com
>>>>>>> <javascript:_e(%7B%7D,'cvml','mikael.staldal@magine.com');>
>>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>>
>>>>>>> Privileged and/or Confidential Information may be contained in this
>>>>>>> message. If you are not the addressee indicated in this message
>>>>>>> (or responsible for delivery of the message to such a person), you
>>>>>>> may not copy or deliver this message to anyone. In such case,
>>>>>>> you should destroy this message and kindly notify the sender by
>>>>>>> reply email.
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> [image: MagineTV]
>>>>>>
>>>>>> *Mikael Ståldal*
>>>>>> Senior software developer
>>>>>>
>>>>>> *Magine TV*
>>>>>> mikael.staldal@magine.com
>>>>>> <javascript:_e(%7B%7D,'cvml','mikael.staldal@magine.com');>
>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>
>>>>>> Privileged and/or Confidential Information may be contained in this
>>>>>> message. If you are not the addressee indicated in this message
>>>>>> (or responsible for delivery of the message to such a person), you
>>>>>> may not copy or deliver this message to anyone. In such case,
>>>>>> you should destroy this message and kindly notify the sender by reply
>>>>>> email.
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> E-Mail: garydgregory@gmail.com
>>>> <javascript:_e(%7B%7D,'cvml','garydgregory@gmail.com');> | ggregory@apache.org
>>>> <javascript:_e(%7B%7D,'cvml','ggregory@apache.org');>
>>>> Java Persistence with Hibernate, Second Edition
>>>> <http://www.manning.com/bauer3/>
>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>> Blog: http://garygregory.wordpress.com
>>>> Home: http://garygregory.com/
>>>> Tweet! http://twitter.com/GaryGregory
>>>>
>>>
>>>
>>
>>
>> --
>> E-Mail: garydgregory@gmail.com
>> <javascript:_e(%7B%7D,'cvml','garydgregory@gmail.com');> | ggregory@apache.org
>> <javascript:_e(%7B%7D,'cvml','ggregory@apache.org');>
>> Java Persistence with Hibernate, Second Edition
>> <http://www.manning.com/bauer3/>
>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>> Spring Batch in Action <http://www.manning.com/templier/>
>> Blog: http://garygregory.wordpress.com
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
>>
>
>
>
> --
> [image: MagineTV]
>
> *Mikael Ståldal*
> Senior software developer
>
> *Magine TV*
> mikael.staldal@magine.com
> <javascript:_e(%7B%7D,'cvml','mikael.staldal@magine.com');>
> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>
> Privileged and/or Confidential Information may be contained in this
> message. If you are not the addressee indicated in this message
> (or responsible for delivery of the message to such a person), you may not
> copy or deliver this message to anyone. In such case,
> you should destroy this message and kindly notify the sender by reply
> email.
>

Re: GC lean way to convert StringBuilder to byte[]

Posted by Mikael Ståldal <mi...@magine.com>.
I still cannot find a way to convert a StringBuilder to a byte[].

On Tue, Feb 23, 2016 at 11:03 PM, Gary Gregory <ga...@gmail.com>
wrote:

> How about /dropping/ Serializer1 altogether? Having both is mighty
> complicated.
>
> Gary
>
> On Tue, Feb 23, 2016 at 8:52 AM, Remko Popma <re...@gmail.com>
> wrote:
>
>> I wouldn't mind that (no strong opinion either way) but I won't have time
>> to do that work.
>>
>> On Wed, Feb 24, 2016 at 1:23 AM, Gary Gregory <ga...@gmail.com>
>> wrote:
>>
>>> I see we now have:
>>>
>>> org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer2
>>>
>>> Should we
>>> deprecate org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer
>>> and reimplement everything in terms of Serializer2, even if objects are
>>> allocated?
>>>
>>> Gary
>>>
>>> On Tue, Feb 23, 2016 at 7:59 AM, Remko Popma <re...@gmail.com>
>>> wrote:
>>>
>>>> Layout now extends Encoder so now it has this method:
>>>>
>>>> encode(LogEvent source, ByteBufferDestination destination)
>>>>
>>>> PatternLayout implements this method. It delegates the work of
>>>> converting the StringBuilder to bytes and writing these bytes into the
>>>> ByteBufferDestination to the TextEncoderHelper class. No objects are
>>>> created during this conversion.
>>>>
>>>> The final piece is (Rolling)RandomAccessFileAppender, whose manager
>>>> implements ByteBufferDestination. This appender calls the #encode() methos
>>>> on the layout (other managers still call Layout#toByteArray).
>>>>
>>>>
>>>>
>>>> On Wed, Feb 24, 2016 at 12:47 AM, Mikael Ståldal <
>>>> mikael.staldal@magine.com> wrote:
>>>>
>>>>> I cannot really find it.
>>>>>
>>>>> On Tue, Feb 23, 2016 at 3:59 PM, Remko Popma <re...@gmail.com>
>>>>> wrote:
>>>>>
>>>>>> Yes, that was implemented in
>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1274.
>>>>>>
>>>>>> Please also see the description and discussion in the epic
>>>>>> https://issues.apache.org/jira/browse/LOG4J2-1270.
>>>>>>
>>>>>> Sent from my iPhone
>>>>>>
>>>>>> On 2016/02/23, at 23:56, Mikael Ståldal <mi...@magine.com>
>>>>>> wrote:
>>>>>>
>>>>>> Do we have any way to convert a StringBuilder to a byte[], without
>>>>>> any intermediate String?
>>>>>>
>>>>>> It seems like org.apache.logging.log4j.core.util.StringEncoder cannot
>>>>>> do it.
>>>>>>
>>>>>> --
>>>>>> [image: MagineTV]
>>>>>>
>>>>>> *Mikael Ståldal*
>>>>>> Senior software developer
>>>>>>
>>>>>> *Magine TV*
>>>>>> mikael.staldal@magine.com
>>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>>
>>>>>> Privileged and/or Confidential Information may be contained in this
>>>>>> message. If you are not the addressee indicated in this message
>>>>>> (or responsible for delivery of the message to such a person), you
>>>>>> may not copy or deliver this message to anyone. In such case,
>>>>>> you should destroy this message and kindly notify the sender by reply
>>>>>> email.
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> [image: MagineTV]
>>>>>
>>>>> *Mikael Ståldal*
>>>>> Senior software developer
>>>>>
>>>>> *Magine TV*
>>>>> mikael.staldal@magine.com
>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>
>>>>> Privileged and/or Confidential Information may be contained in this
>>>>> message. If you are not the addressee indicated in this message
>>>>> (or responsible for delivery of the message to such a person), you may
>>>>> not copy or deliver this message to anyone. In such case,
>>>>> you should destroy this message and kindly notify the sender by reply
>>>>> email.
>>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>> Java Persistence with Hibernate, Second Edition
>>> <http://www.manning.com/bauer3/>
>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>> Spring Batch in Action <http://www.manning.com/templier/>
>>> Blog: http://garygregory.wordpress.com
>>> Home: http://garygregory.com/
>>> Tweet! http://twitter.com/GaryGregory
>>>
>>
>>
>
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition
> <http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>



-- 
[image: MagineTV]

*Mikael Ståldal*
Senior software developer

*Magine TV*
mikael.staldal@magine.com
Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com

Privileged and/or Confidential Information may be contained in this
message. If you are not the addressee indicated in this message
(or responsible for delivery of the message to such a person), you may not
copy or deliver this message to anyone. In such case,
you should destroy this message and kindly notify the sender by reply
email.

Re: GC lean way to convert StringBuilder to byte[]

Posted by Gary Gregory <ga...@gmail.com>.
How about /dropping/ Serializer1 altogether? Having both is mighty
complicated.

Gary

On Tue, Feb 23, 2016 at 8:52 AM, Remko Popma <re...@gmail.com> wrote:

> I wouldn't mind that (no strong opinion either way) but I won't have time
> to do that work.
>
> On Wed, Feb 24, 2016 at 1:23 AM, Gary Gregory <ga...@gmail.com>
> wrote:
>
>> I see we now have:
>>
>> org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer2
>>
>> Should we
>> deprecate org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer
>> and reimplement everything in terms of Serializer2, even if objects are
>> allocated?
>>
>> Gary
>>
>> On Tue, Feb 23, 2016 at 7:59 AM, Remko Popma <re...@gmail.com>
>> wrote:
>>
>>> Layout now extends Encoder so now it has this method:
>>>
>>> encode(LogEvent source, ByteBufferDestination destination)
>>>
>>> PatternLayout implements this method. It delegates the work of
>>> converting the StringBuilder to bytes and writing these bytes into the
>>> ByteBufferDestination to the TextEncoderHelper class. No objects are
>>> created during this conversion.
>>>
>>> The final piece is (Rolling)RandomAccessFileAppender, whose manager
>>> implements ByteBufferDestination. This appender calls the #encode() methos
>>> on the layout (other managers still call Layout#toByteArray).
>>>
>>>
>>>
>>> On Wed, Feb 24, 2016 at 12:47 AM, Mikael Ståldal <
>>> mikael.staldal@magine.com> wrote:
>>>
>>>> I cannot really find it.
>>>>
>>>> On Tue, Feb 23, 2016 at 3:59 PM, Remko Popma <re...@gmail.com>
>>>> wrote:
>>>>
>>>>> Yes, that was implemented in
>>>>> https://issues.apache.org/jira/browse/LOG4J2-1274.
>>>>>
>>>>> Please also see the description and discussion in the epic
>>>>> https://issues.apache.org/jira/browse/LOG4J2-1270.
>>>>>
>>>>> Sent from my iPhone
>>>>>
>>>>> On 2016/02/23, at 23:56, Mikael Ståldal <mi...@magine.com>
>>>>> wrote:
>>>>>
>>>>> Do we have any way to convert a StringBuilder to a byte[], without any
>>>>> intermediate String?
>>>>>
>>>>> It seems like org.apache.logging.log4j.core.util.StringEncoder cannot
>>>>> do it.
>>>>>
>>>>> --
>>>>> [image: MagineTV]
>>>>>
>>>>> *Mikael Ståldal*
>>>>> Senior software developer
>>>>>
>>>>> *Magine TV*
>>>>> mikael.staldal@magine.com
>>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>>
>>>>> Privileged and/or Confidential Information may be contained in this
>>>>> message. If you are not the addressee indicated in this message
>>>>> (or responsible for delivery of the message to such a person), you may
>>>>> not copy or deliver this message to anyone. In such case,
>>>>> you should destroy this message and kindly notify the sender by reply
>>>>> email.
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> [image: MagineTV]
>>>>
>>>> *Mikael Ståldal*
>>>> Senior software developer
>>>>
>>>> *Magine TV*
>>>> mikael.staldal@magine.com
>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>
>>>> Privileged and/or Confidential Information may be contained in this
>>>> message. If you are not the addressee indicated in this message
>>>> (or responsible for delivery of the message to such a person), you may
>>>> not copy or deliver this message to anyone. In such case,
>>>> you should destroy this message and kindly notify the sender by reply
>>>> email.
>>>>
>>>
>>>
>>
>>
>> --
>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>> Java Persistence with Hibernate, Second Edition
>> <http://www.manning.com/bauer3/>
>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>> Spring Batch in Action <http://www.manning.com/templier/>
>> Blog: http://garygregory.wordpress.com
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
>>
>
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: GC lean way to convert StringBuilder to byte[]

Posted by Remko Popma <re...@gmail.com>.
I wouldn't mind that (no strong opinion either way) but I won't have time
to do that work.

On Wed, Feb 24, 2016 at 1:23 AM, Gary Gregory <ga...@gmail.com>
wrote:

> I see we now have:
>
> org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer2
>
> Should we
> deprecate org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer
> and reimplement everything in terms of Serializer2, even if objects are
> allocated?
>
> Gary
>
> On Tue, Feb 23, 2016 at 7:59 AM, Remko Popma <re...@gmail.com>
> wrote:
>
>> Layout now extends Encoder so now it has this method:
>>
>> encode(LogEvent source, ByteBufferDestination destination)
>>
>> PatternLayout implements this method. It delegates the work of converting
>> the StringBuilder to bytes and writing these bytes into the
>> ByteBufferDestination to the TextEncoderHelper class. No objects are
>> created during this conversion.
>>
>> The final piece is (Rolling)RandomAccessFileAppender, whose manager
>> implements ByteBufferDestination. This appender calls the #encode() methos
>> on the layout (other managers still call Layout#toByteArray).
>>
>>
>>
>> On Wed, Feb 24, 2016 at 12:47 AM, Mikael Ståldal <
>> mikael.staldal@magine.com> wrote:
>>
>>> I cannot really find it.
>>>
>>> On Tue, Feb 23, 2016 at 3:59 PM, Remko Popma <re...@gmail.com>
>>> wrote:
>>>
>>>> Yes, that was implemented in
>>>> https://issues.apache.org/jira/browse/LOG4J2-1274.
>>>>
>>>> Please also see the description and discussion in the epic
>>>> https://issues.apache.org/jira/browse/LOG4J2-1270.
>>>>
>>>> Sent from my iPhone
>>>>
>>>> On 2016/02/23, at 23:56, Mikael Ståldal <mi...@magine.com>
>>>> wrote:
>>>>
>>>> Do we have any way to convert a StringBuilder to a byte[], without any
>>>> intermediate String?
>>>>
>>>> It seems like org.apache.logging.log4j.core.util.StringEncoder cannot
>>>> do it.
>>>>
>>>> --
>>>> [image: MagineTV]
>>>>
>>>> *Mikael Ståldal*
>>>> Senior software developer
>>>>
>>>> *Magine TV*
>>>> mikael.staldal@magine.com
>>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>>
>>>> Privileged and/or Confidential Information may be contained in this
>>>> message. If you are not the addressee indicated in this message
>>>> (or responsible for delivery of the message to such a person), you may
>>>> not copy or deliver this message to anyone. In such case,
>>>> you should destroy this message and kindly notify the sender by reply
>>>> email.
>>>>
>>>>
>>>
>>>
>>> --
>>> [image: MagineTV]
>>>
>>> *Mikael Ståldal*
>>> Senior software developer
>>>
>>> *Magine TV*
>>> mikael.staldal@magine.com
>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>
>>> Privileged and/or Confidential Information may be contained in this
>>> message. If you are not the addressee indicated in this message
>>> (or responsible for delivery of the message to such a person), you may
>>> not copy or deliver this message to anyone. In such case,
>>> you should destroy this message and kindly notify the sender by reply
>>> email.
>>>
>>
>>
>
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition
> <http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>

Re: GC lean way to convert StringBuilder to byte[]

Posted by Gary Gregory <ga...@gmail.com>.
I see we now have:

org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer2

Should we
deprecate org.apache.logging.log4j.core.layout.AbstractStringLayout.Serializer
and reimplement everything in terms of Serializer2, even if objects are
allocated?

Gary

On Tue, Feb 23, 2016 at 7:59 AM, Remko Popma <re...@gmail.com> wrote:

> Layout now extends Encoder so now it has this method:
>
> encode(LogEvent source, ByteBufferDestination destination)
>
> PatternLayout implements this method. It delegates the work of converting
> the StringBuilder to bytes and writing these bytes into the
> ByteBufferDestination to the TextEncoderHelper class. No objects are
> created during this conversion.
>
> The final piece is (Rolling)RandomAccessFileAppender, whose manager
> implements ByteBufferDestination. This appender calls the #encode() methos
> on the layout (other managers still call Layout#toByteArray).
>
>
>
> On Wed, Feb 24, 2016 at 12:47 AM, Mikael Ståldal <
> mikael.staldal@magine.com> wrote:
>
>> I cannot really find it.
>>
>> On Tue, Feb 23, 2016 at 3:59 PM, Remko Popma <re...@gmail.com>
>> wrote:
>>
>>> Yes, that was implemented in
>>> https://issues.apache.org/jira/browse/LOG4J2-1274.
>>>
>>> Please also see the description and discussion in the epic
>>> https://issues.apache.org/jira/browse/LOG4J2-1270.
>>>
>>> Sent from my iPhone
>>>
>>> On 2016/02/23, at 23:56, Mikael Ståldal <mi...@magine.com>
>>> wrote:
>>>
>>> Do we have any way to convert a StringBuilder to a byte[], without any
>>> intermediate String?
>>>
>>> It seems like org.apache.logging.log4j.core.util.StringEncoder cannot
>>> do it.
>>>
>>> --
>>> [image: MagineTV]
>>>
>>> *Mikael Ståldal*
>>> Senior software developer
>>>
>>> *Magine TV*
>>> mikael.staldal@magine.com
>>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>>
>>> Privileged and/or Confidential Information may be contained in this
>>> message. If you are not the addressee indicated in this message
>>> (or responsible for delivery of the message to such a person), you may
>>> not copy or deliver this message to anyone. In such case,
>>> you should destroy this message and kindly notify the sender by reply
>>> email.
>>>
>>>
>>
>>
>> --
>> [image: MagineTV]
>>
>> *Mikael Ståldal*
>> Senior software developer
>>
>> *Magine TV*
>> mikael.staldal@magine.com
>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>
>> Privileged and/or Confidential Information may be contained in this
>> message. If you are not the addressee indicated in this message
>> (or responsible for delivery of the message to such a person), you may
>> not copy or deliver this message to anyone. In such case,
>> you should destroy this message and kindly notify the sender by reply
>> email.
>>
>
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: GC lean way to convert StringBuilder to byte[]

Posted by Remko Popma <re...@gmail.com>.
Layout now extends Encoder so now it has this method:

encode(LogEvent source, ByteBufferDestination destination)

PatternLayout implements this method. It delegates the work of converting
the StringBuilder to bytes and writing these bytes into the
ByteBufferDestination to the TextEncoderHelper class. No objects are
created during this conversion.

The final piece is (Rolling)RandomAccessFileAppender, whose manager
implements ByteBufferDestination. This appender calls the #encode() methos
on the layout (other managers still call Layout#toByteArray).



On Wed, Feb 24, 2016 at 12:47 AM, Mikael Ståldal <mi...@magine.com>
wrote:

> I cannot really find it.
>
> On Tue, Feb 23, 2016 at 3:59 PM, Remko Popma <re...@gmail.com>
> wrote:
>
>> Yes, that was implemented in
>> https://issues.apache.org/jira/browse/LOG4J2-1274.
>>
>> Please also see the description and discussion in the epic
>> https://issues.apache.org/jira/browse/LOG4J2-1270.
>>
>> Sent from my iPhone
>>
>> On 2016/02/23, at 23:56, Mikael Ståldal <mi...@magine.com>
>> wrote:
>>
>> Do we have any way to convert a StringBuilder to a byte[], without any
>> intermediate String?
>>
>> It seems like org.apache.logging.log4j.core.util.StringEncoder cannot do
>> it.
>>
>> --
>> [image: MagineTV]
>>
>> *Mikael Ståldal*
>> Senior software developer
>>
>> *Magine TV*
>> mikael.staldal@magine.com
>> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>>
>> Privileged and/or Confidential Information may be contained in this
>> message. If you are not the addressee indicated in this message
>> (or responsible for delivery of the message to such a person), you may
>> not copy or deliver this message to anyone. In such case,
>> you should destroy this message and kindly notify the sender by reply
>> email.
>>
>>
>
>
> --
> [image: MagineTV]
>
> *Mikael Ståldal*
> Senior software developer
>
> *Magine TV*
> mikael.staldal@magine.com
> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>
> Privileged and/or Confidential Information may be contained in this
> message. If you are not the addressee indicated in this message
> (or responsible for delivery of the message to such a person), you may not
> copy or deliver this message to anyone. In such case,
> you should destroy this message and kindly notify the sender by reply
> email.
>

Re: GC lean way to convert StringBuilder to byte[]

Posted by Mikael Ståldal <mi...@magine.com>.
I cannot really find it.

On Tue, Feb 23, 2016 at 3:59 PM, Remko Popma <re...@gmail.com> wrote:

> Yes, that was implemented in
> https://issues.apache.org/jira/browse/LOG4J2-1274.
>
> Please also see the description and discussion in the epic
> https://issues.apache.org/jira/browse/LOG4J2-1270.
>
> Sent from my iPhone
>
> On 2016/02/23, at 23:56, Mikael Ståldal <mi...@magine.com> wrote:
>
> Do we have any way to convert a StringBuilder to a byte[], without any
> intermediate String?
>
> It seems like org.apache.logging.log4j.core.util.StringEncoder cannot do
> it.
>
> --
> [image: MagineTV]
>
> *Mikael Ståldal*
> Senior software developer
>
> *Magine TV*
> mikael.staldal@magine.com
> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>
> Privileged and/or Confidential Information may be contained in this
> message. If you are not the addressee indicated in this message
> (or responsible for delivery of the message to such a person), you may not
> copy or deliver this message to anyone. In such case,
> you should destroy this message and kindly notify the sender by reply
> email.
>
>


-- 
[image: MagineTV]

*Mikael Ståldal*
Senior software developer

*Magine TV*
mikael.staldal@magine.com
Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com

Privileged and/or Confidential Information may be contained in this
message. If you are not the addressee indicated in this message
(or responsible for delivery of the message to such a person), you may not
copy or deliver this message to anyone. In such case,
you should destroy this message and kindly notify the sender by reply
email.

Re: GC lean way to convert StringBuilder to byte[]

Posted by Remko Popma <re...@gmail.com>.
Yes, that was implemented in https://issues.apache.org/jira/browse/LOG4J2-1274. 

Please also see the description and discussion in the epic https://issues.apache.org/jira/browse/LOG4J2-1270. 

Sent from my iPhone

> On 2016/02/23, at 23:56, Mikael Ståldal <mi...@magine.com> wrote:
> 
> Do we have any way to convert a StringBuilder to a byte[], without any intermediate String?
> 
> It seems like org.apache.logging.log4j.core.util.StringEncoder cannot do it.
> 
> -- 
>  
> 
> Mikael Ståldal
> Senior software developer 
> 
> Magine TV
> mikael.staldal@magine.com    
> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com             
> 
> Privileged and/or Confidential Information may be contained in this message. If you are not the addressee indicated in this message
> (or responsible for delivery of the message to such a person), you may not copy or deliver this message to anyone. In such case, 
> you should destroy this message and kindly notify the sender by reply email.