Path: blob/master/test/micro/org/openjdk/bench/vm/compiler/BitSetAndReset.java
41161 views
/*1* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22package org.openjdk.bench.vm.compiler;2324import org.openjdk.jmh.annotations.*;25import org.openjdk.jmh.infra.*;2627import java.util.concurrent.TimeUnit;2829@BenchmarkMode(Mode.AverageTime)30@OutputTimeUnit(TimeUnit.NANOSECONDS)31@State(Scope.Thread)32public class BitSetAndReset {33private static final int COUNT = 10_000;3435private static final long MASK63 = 0x8000_0000_0000_0000L;36private static final long MASK31 = 0x0000_0000_8000_0000L;37private static final long MASK15 = 0x0000_0000_0000_8000L;38private static final long MASK00 = 0x0000_0000_0000_0001L;3940private long andq, orq;41private boolean success = true;4243@TearDown(Level.Iteration)44public void finish() {45if (!success)46throw new AssertionError("Failure while setting or clearing long vector bits!");47}4849@Benchmark50public void bitSet(Blackhole bh) {51for (int i=0; i<COUNT; i++) {52andq = MASK63 | MASK31 | MASK15 | MASK00;53orq = 0;54bh.consume(test63());55bh.consume(test31());56bh.consume(test15());57bh.consume(test00());58success &= andq == 0 && orq == (MASK63 | MASK31 | MASK15 | MASK00);59}60}6162private long test63() {63andq &= ~MASK63;64orq |= MASK63;65return 0L;66}67private long test31() {68andq &= ~MASK31;69orq |= MASK31;70return 0L;71}72private long test15() {73andq &= ~MASK15;74orq |= MASK15;75return 0L;76}77private long test00() {78andq &= ~MASK00;79orq |= MASK00;80return 0L;81}8283private static final long MASK62 = 0x4000_0000_0000_0000L;84private static final long MASK61 = 0x2000_0000_0000_0000L;85private static final long MASK60 = 0x1000_0000_0000_0000L;8687private long orq63, orq62, orq61, orq60;8889@Benchmark90public void throughput(Blackhole bh) {91for (int i=0; i<COUNT; i++) {92orq63 = orq62 = orq61 = orq60 = 0;93bh.consume(testTp());94}95}9697private long testTp() {98orq63 |= MASK63;99orq62 |= MASK62;100orq61 |= MASK61;101orq60 |= MASK60;102return 0L;103}104}105106107