Hi Peter,

On Mar 19, 2014, at 4:32 PM, Peter Levart <peter.lev...@gmail.com> wrote:

> So the solution is to "reduce number of bytecodes in toString()". For 
> example, the following:
> 
> 
>     public String toString() {
>         String sc = stringCache;
>         if (sc == null) {
>             sc = toStringSlow();
>         }
>         return sc;
>     }
> 
>     private String toStringSlow() {
>         String sc = (String) U.getObjectVolatile(this, STRING_CACHE_OFFSET);
>         if (sc == null) {
>             sc = layoutChars(true);
>             if (!U.compareAndSwapObject(this, STRING_CACHE_OFFSET, null, sc)) 
> {
>                 sc = (String) U.getObjectVolatile(this, STRING_CACHE_OFFSET);
>             }
>         }
>         return sc;
>     }
> 
> 
> ...gives the good results even without special JVM options:
> 
> Benchmark                         Mode   Samples         Mean   Mean error    
> Units
> o.s.Bench6375303.testToString     avgt        10       80.925        0.313    
> ns/op

That’s great! I can re-try that version on my system for comparison.

Thanks,

Brian

Reply via email to