JDK 9 RFR of 6375303: Review use of caching in BigDecimal

Brian Burkhalter brian.burkhalter at oracle.com
Wed Mar 19 23:41:05 UTC 2014


Hi Peter,

On Mar 19, 2014, at 4:32 PM, Peter Levart <peter.levart at 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


More information about the core-libs-dev mailing list