view jcstress-test-gen/src/main/resources/operationAtomic/byteBuffer/ @ 306:d05bb19014cd

7901712: VarHandles, Direct ByteBuffer tests probe the aligned offset in heap buffer, not in direct one
author shade
date Tue, 12 Jul 2016 00:19:01 +0300
parents 9dcd4ef5edf1
children ef7859c6197a
line wrap: on
line source
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
 * 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 if you need additional information or have any
 * questions.
package $package$;

import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.Random;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

import org.openjdk.jcstress.annotations.Actor;
import org.openjdk.jcstress.annotations.Arbiter;
import org.openjdk.jcstress.annotations.Expect;
import org.openjdk.jcstress.annotations.JCStressTest;
import org.openjdk.jcstress.annotations.Outcome;
import org.openjdk.jcstress.annotations.State;
import org.openjdk.jcstress.annotations.Description;
import org.openjdk.jcstress.infra.results.Bool2$Type$Result;

@Description("Tests weakCompareAndSet contend with strong compareAndSet.")
@Outcome(id = "true, false, $value1$", expect = Expect.ACCEPTABLE,  desc = "actor2 execute after actor1")
@Outcome(id = "false, true, $value2$", expect = Expect.ACCEPTABLE, desc = "actor2 execute before actor1 or win the contention with actor1")
@Outcome(id = "false, false, $value0$", expect = Expect.FORBIDDEN,  desc = "not both shall fail")
@Outcome(id = "true, true, $value1$", expect = Expect.FORBIDDEN,  desc = "not both shall succeed")
@Outcome(id = "true, true, $value2$", expect = Expect.FORBIDDEN, desc = "not both shall succeed")
public class $TestClassName$ {

    static final int OFF = $buffer_allocate$(128).alignmentOffset(0, 8);

    static final VarHandle vh;

    static {
        try {
            vh = MethodHandles.byteBufferViewVarHandle($type$[].class, ByteOrder.$byte_order$);
        } catch (Exception e) {
            throw new RuntimeException(e);

    ByteBuffer byteBuffer = $buffer_allocate$(OFF + 8);

    public void actor1(Bool2$Type$Result r) {
        r.r1 = %WeakCAS<$valueLiteral0$, $valueLiteral1$>%

    public void actor2(Bool2$Type$Result r) {
        r.r2 = %CompareAndSet<$valueLiteral0$, $valueLiteral2$>%

    public void arbiter1(Bool2$Type$Result r) {
        r.r3 = ($type$) vh.get(byteBuffer, OFF);