view src/main/java/org/openjdk/gcbench/runtime/cmp/ACmpBarriersKnownNew.java @ 88:583fef4276f5

Update license and copyright headers.
author shade
date Wed, 22 Nov 2017 15:58:02 +0100
parents f8496889e1ac
children
line wrap: on
line source

/*
 * Copyright (c) 2017, Red Hat Inc. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Oracle designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Oracle in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */
package org.openjdk.gcbench.runtime.cmp;

import org.openjdk.jmh.annotations.*;

import java.util.concurrent.TimeUnit;

@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Fork(1)
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Threads(1)
@State(Scope.Thread)
public class ACmpBarriersKnownNew {

    Object target;

    @Setup
    public void setup() {
        target = new Object();
    }

    @Benchmark
    public void left() {
        doLeft(target);
    }

    @Benchmark
    public void right() {
        doRight(target);
    }

    @CompilerControl(CompilerControl.Mode.DONT_INLINE)
    private boolean doLeft(Object t1) {
        return t1 == new Object();
    }

    @CompilerControl(CompilerControl.Mode.DONT_INLINE)
    private boolean doRight(Object t2) {
        return new Object() == t2;
    }

    /*
        i7 4790K, 4.0 Ghz, Linux x86_64, JDK 9 (Shenandoah, 2016-09-05)

            Benchmark                   Mode  Cnt  Score   Error  Units

            # Shenandoah
            ACmpBarriersKnownNew.left   avgt    5  1.983 ± 0.100  ns/op
            ACmpBarriersKnownNew.right  avgt    5  1.977 ± 0.005  ns/op

            # G1
            ACmpBarriersKnownNew.left   avgt    5  2.057 ± 0.019  ns/op
            ACmpBarriersKnownNew.right  avgt    5  2.059 ± 0.022  ns/op

            # Parallel
            ACmpBarriersKnownNew.left   avgt    5  2.057 ± 0.030  ns/op
            ACmpBarriersKnownNew.right  avgt    5  2.060 ± 0.007  ns/op

        The difference is not caused by different compilation of doLeft/doRight methods,
        but rather the additional read barriers in the JMH loop itself. Note that
        additional barrier code *IMPROVES* performance.

            Benchmark                                        Mode  Cnt   Score    Error  Units

            # Shenandoah
            ACmpBarriersKnownNew.left                        avgt   25   1.970 ±  0.004  ns/op
            ACmpBarriersKnownNew.left:CPI                    avgt    5   0.330 ±  0.012   #/op
            ACmpBarriersKnownNew.left:L1-dcache-load-misses  avgt    5   0.010 ±  0.005   #/op
            ACmpBarriersKnownNew.left:L1-dcache-loads        avgt    5  11.095 ±  0.380   #/op  <--- more loads
            ACmpBarriersKnownNew.left:cycles                 avgt    5   7.820 ±  0.088   #/op  <--- yet, less cycles
            ACmpBarriersKnownNew.left:instructions           avgt    5  23.665 ±  0.833   #/op  <--- a few more instructions

            # G1
            ACmpBarriersKnownNew.left                        avgt   25   2.061 ±  0.008  ns/op
            ACmpBarriersKnownNew.left:CPI                    avgt    5   0.363 ±  0.010   #/op
            ACmpBarriersKnownNew.left:L1-dcache-load-misses  avgt    5   0.010 ±  0.012   #/op
            ACmpBarriersKnownNew.left:L1-dcache-loads        avgt    5   9.322 ±  0.153   #/op
            ACmpBarriersKnownNew.left:cycles                 avgt    5   8.115 ±  0.107   #/op
            ACmpBarriersKnownNew.left:instructions           avgt    5  22.331 ±  0.681   #/op

        The generated code for doLeft/doRight in Shenandoah/G1/Parallel is the same:

                          [Verified Entry Point]
         12.42%    7.23%    0x00007fbe6953f8c0: sub    $0x18,%rsp
          0.37%    0.40%    0x00007fbe6953f8c7: mov    %rbp,0x10(%rsp)
         11.19%   10.82%    0x00007fbe6953f8cc: xor    %eax,%eax           ; always false
          1.53%    1.76%    0x00007fbe6953f8ce: add    $0x10,%rsp
          0.22%    0.22%    0x00007fbe6953f8d2: pop    %rbp
          0.23%    0.12%    0x00007fbe6953f8d3: test   %eax,0x18b70727(%rip)
         10.71%   14.51%    0x00007fbe6953f8d9: retq

     */

}