comparison graal/GraalCompiler/src/com/sun/c1x/ir/CompareAndSwap.java @ 2509:16b9a8b5ad39

Renamings Runtime=>GraalRuntime and Compiler=>GraalCompiler
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Wed, 27 Apr 2011 11:50:44 +0200
parents graal/Compiler/src/com/sun/c1x/ir/CompareAndSwap.java@9ec15d6914ca
children
comparison
equal deleted inserted replaced
2508:fea94949e0a2 2509:16b9a8b5ad39
1 /*
2 * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package com.sun.c1x.ir;
24
25 import com.sun.c1x.debug.*;
26 import com.sun.c1x.value.*;
27 import com.sun.cri.bytecode.*;
28
29 /**
30 * Atomic update of a value in memory. Implements the {@link Bytecodes#PCMPSWP} family of instructions.
31 *
32 * Compares a suspected value with the actual value in a memory location.
33 * Iff they are same, a new value is placed into the location and the expected value is returned.
34 * Otherwise, the actual value is returned.
35 *
36 * @author Doug Simon
37 */
38 public final class CompareAndSwap extends PointerOp {
39
40 /**
41 * The value to store.
42 */
43 Value expectedValue;
44
45 Value newValue;
46
47 /**
48 * Creates an instruction for a pointer store. If {@code displacement != null}, the effective of the address of the store is
49 * computed as the pointer plus a byte displacement plus a scaled index. Otherwise, the effective address is computed as the
50 * pointer plus a byte offset.
51 * @param pointer the value producing the pointer
52 * @param offset the value producing the byte offset
53 * @param expectedValue the value that must currently being in memory location for the swap to occur
54 * @param newValue the new value to store if the precondition is satisfied
55 * @param stateBefore the state before
56 * @param isVolatile {@code true} if the access is volatile
57 */
58 public CompareAndSwap(int opcode, Value pointer, Value offset, Value expectedValue, Value newValue, FrameState stateBefore, boolean isVolatile) {
59 super(expectedValue.kind, expectedValue.kind, opcode, pointer, null, offset, stateBefore, isVolatile);
60 assert offset != null;
61 this.expectedValue = expectedValue;
62 this.newValue = newValue;
63 setFlag(Flag.LiveStore);
64 }
65
66 @Override
67 public void accept(ValueVisitor v) {
68 v.visitCompareAndSwap(this);
69 }
70
71 public Value expectedValue() {
72 return expectedValue;
73 }
74
75 public Value newValue() {
76 return newValue;
77 }
78
79 @Override
80 public void inputValuesDo(ValueClosure closure) {
81 super.inputValuesDo(closure);
82 expectedValue = closure.apply(expectedValue);
83 newValue = closure.apply(newValue);
84 }
85
86 @Override
87 public void print(LogStream out) {
88 out.print(Bytecodes.nameOf(opcode)).print("(").print(pointer());
89 out.print(" + ").print(offset());
90 out.print(", ").print(expectedValue()).print(", ").print(newValue()).print(')');
91 }
92 }