view jcstress-test-gen/src/main/resources/copy/X-ObjectCloneCopyingTest.java.template @ 398:2357daa047b7

Chapter 2.a: Copying (manual, clone, arraycopy, copyOf) tests.
author shade
date Tue, 28 Mar 2017 16:28:36 +0200
parents
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 $package$;

import java.util.Arrays;
import org.openjdk.jcstress.annotations.*;
import org.openjdk.jcstress.infra.results.*;

#warn

/**
 * Tests if arrays experience coherence failures.
 */
@JCStressTest
#if[safe]
@Outcome(id = "$default$", expect = Expect.FORBIDDEN, desc = "Seeing object, but not its contents.")
#else[safe]
@Outcome(id = "$default$", expect = Expect.ACCEPTABLE, desc = "Seeing object, but not its contents.")
#end[safe]
#if[alwaysAtomic]
@Outcome(id = "$set$", expect = Expect.ACCEPTABLE, desc = "Seeing the complete update.")
#else[alwaysAtomic]
@Outcome(id = ".*", expect = Expect.ACCEPTABLE, desc = "Observing non-atomic write/read.")
#end[alwaysAtomic]
@State
public class $name$ {

    static class Data implements Cloneable {
        $type$ f;

        @Override
        public Data clone() throws CloneNotSupportedException {
            return (Data)super.clone();
        }
    }

    static final Data src;

    static {
        src = new Data();
        src.f = $setLiteral$;
    }

    $modifier$ Data copy;

    @Actor
    public void actor1() {
        try {
            copy = src.clone();
        } catch (Exception e) {
            // okay
        }
    }

    @Actor
    public void actor2($T$_Result r) {
        Data d = copy;
        if (d != null) {
          r.r1 = d.f;
        } else {
          r.r1 = $setLiteral$;
        }
    }

}