changeset 2610:39aa89baa165

cleanup: FrameState copy methods, ImmutableFrameState
author Lukas Stadler <lukas.stadler@jku.at>
date Fri, 06 May 2011 13:03:33 +0200
parents 01c5c0443158
children bd235cb4375a
files graal/GraalCompiler/src/com/sun/c1x/ir/BlockBegin.java graal/GraalCompiler/src/com/sun/c1x/ir/StateSplit.java graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java graal/GraalCompiler/src/com/sun/c1x/value/ImmutableFrameState.java graal/GraalCompiler/src/com/sun/c1x/value/MutableFrameState.java
diffstat 5 files changed, 60 insertions(+), 74 deletions(-) [+]
line wrap: on
line diff
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/BlockBegin.java	Fri May 06 11:18:15 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/BlockBegin.java	Fri May 06 13:03:33 2011 +0200
@@ -410,7 +410,7 @@
             }
 
             // copy state because it is modified
-            newState = newState.copy();
+            newState = newState.immutableCopy();
 
             if (C1XOptions.UseStackMapTableLiveness) {
                 // if a liveness map is available, use it to invalidate dead locals
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/StateSplit.java	Fri May 06 11:18:15 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/StateSplit.java	Fri May 06 13:03:33 2011 +0200
@@ -35,11 +35,6 @@
     private static final int INPUT_COUNT = 0;
     private static final int SUCCESSOR_COUNT = 0;
 
-    /**
-     * Sentinel denoting an explicitly cleared state.
-     */
-    private static final FrameState CLEARED_STATE = new MutableFrameState(-5, 0, 0);
-
     private FrameState stateBefore;
 
     /**
--- a/graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java	Fri May 06 11:18:15 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java	Fri May 06 13:03:33 2011 +0200
@@ -28,6 +28,7 @@
 import com.sun.c1x.*;
 import com.sun.c1x.graph.*;
 import com.sun.c1x.ir.*;
+import com.sun.c1x.util.*;
 import com.sun.cri.ci.*;
 
 /**
@@ -105,22 +106,25 @@
      *
      * @return a new frame state with the specified components
      */
-    public MutableFrameState copy(int bci, boolean withLocals, boolean withStack, boolean withLocks) {
-        final MutableFrameState other = new MutableFrameState(bci, localsSize(), maxStackSize());
+    public FrameState immutableCopy(int bci, boolean withLocals, boolean withStack, boolean withLocks) {
+        final ImmutableFrameState other = new ImmutableFrameState(bci, localsSize(), maxStackSize());
         if (withLocals && withStack) {
             // fast path: use array copy
             System.arraycopy(values, 0, other.values, 0, valuesSize());
             other.stackIndex = stackIndex;
         } else {
             if (withLocals) {
-                other.replaceLocals(this);
+                System.arraycopy(values, 0, other.values, 0, maxLocals);
             }
             if (withStack) {
-                other.replaceStack(this);
+                System.arraycopy(values, maxLocals, other.values, other.maxLocals, stackIndex);
+                other.stackIndex = stackIndex;
             }
         }
         if (withLocks) {
-            other.replaceLocks(this);
+            if (locks != null) {
+                other.locks = new ArrayList<Value>(locks);
+            }
         }
         return other;
     }
@@ -129,21 +133,34 @@
      * Gets a mutable copy ({@link MutableFrameState}) of this frame state.
      */
     public MutableFrameState copy() {
-        return copy(bci, true, true, true);
+        final MutableFrameState other = new MutableFrameState(bci, localsSize(), maxStackSize());
+        System.arraycopy(values, 0, other.values, 0, valuesSize());
+        other.stackIndex = stackIndex;
+        if (locks != null) {
+            other.locks = new ArrayList<Value>(locks);
+        }
+        return other;
+    }
+
+    /**
+     * Gets a immutable copy ({@link MutableFrameState}) of this frame state.
+     */
+    public FrameState immutableCopy() {
+        return immutableCopy(bci, true, true, true);
     }
 
     /**
      * Gets an immutable copy of this frame state but without the stack.
      */
     public FrameState immutableCopyWithEmptyStack() {
-        return copy(bci, true, false, true);
+        return immutableCopy(bci, true, false, true);
     }
 
     /**
      * Gets an immutable copy of this frame state but without the frame info.
      */
     public FrameState immutableCopyCodePosOnly() {
-        return copy(bci, false, false, false);
+        return immutableCopy(bci, false, false, false);
     }
 
     public boolean isCompatibleWith(FrameState other) {
@@ -431,28 +448,6 @@
     }
 
     /**
-     * Traverses all {@linkplain Phi phis} of a given block in this frame state.
-     *
-     * @param block only phis {@linkplain Phi#block() associated} with this block are traversed
-     * @param proc the call back invoked for each live phi traversed
-     */
-    public boolean forEachPhi(BlockBegin block, PhiProcedure proc) {
-        int max = this.valuesSize();
-        for (int i = 0; i < max; i++) {
-            Value instr = values[i];
-            if (instr instanceof Phi && !instr.isDeadPhi()) {
-                Phi phi = (Phi) instr;
-                if (block == null || phi.block() == block) {
-                    if (!proc.doPhi(phi)) {
-                        return false;
-                    }
-                }
-            }
-        }
-        return true;
-    }
-
-    /**
      * Traverses all live {@linkplain Phi phis} of a given block in this frame state.
      *
      * @param block only phis {@linkplain Phi#block() associated} with this block are traversed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/GraalCompiler/src/com/sun/c1x/value/ImmutableFrameState.java	Fri May 06 13:03:33 2011 +0200
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. 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.
+ *
+ * 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 com.sun.c1x.value;
+
+
+public class ImmutableFrameState extends FrameState {
+
+    public ImmutableFrameState(int bci, int maxLocals, int maxStack) {
+        super(bci, maxLocals, maxStack);
+    }
+
+
+}
--- a/graal/GraalCompiler/src/com/sun/c1x/value/MutableFrameState.java	Fri May 06 11:18:15 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/value/MutableFrameState.java	Fri May 06 13:03:33 2011 +0200
@@ -39,8 +39,6 @@
  * Contrariwise and as an optimization, an instance referenced as {@code MutableFrameState} can be assigned to
  * a variable, field, or method parameter of type {@link FrameState} without creating an immutable copy before
  * (using {@link #immutableCopy(int)}) if the state is not mutated after the assignment.
- *
- * @author Michael Duller
  */
 public final class MutableFrameState extends FrameState {
 
@@ -49,41 +47,6 @@
     }
 
     /**
-     * Replace the local variables in this frame state with the local variables from the specified frame state. This is
-     * used in inlining.
-     *
-     * @param with the frame state containing the new local variables
-     */
-    public void replaceLocals(FrameState with) {
-        assert with.maxLocals == maxLocals;
-        System.arraycopy(with.values, 0, values, 0, maxLocals);
-    }
-
-    /**
-     * Replace the stack in this frame state with the stack from the specified frame state. This is used in inlining.
-     *
-     * @param with the frame state containing the new local variables
-     */
-    public void replaceStack(FrameState with) {
-        System.arraycopy(with.values, with.maxLocals, values, maxLocals, with.stackIndex);
-        stackIndex = with.stackIndex;
-        assert stackIndex >= 0;
-    }
-
-    /**
-     * Replace the locks in this frame state with the locks from the specified frame state. This is used in inlining.
-     *
-     * @param with the frame state containing the new local variables
-     */
-    public void replaceLocks(FrameState with) {
-        if (with.locks == null) {
-            locks = null;
-        } else {
-            locks = Util.uncheckedCast(with.locks.clone());
-        }
-    }
-
-    /**
      * Clears all values on this stack.
      */
     public void clearStack() {
@@ -349,7 +312,7 @@
      * @param bci the bytecode index of the new frame state
      */
     public FrameState immutableCopy(int bci) {
-        return copy(bci, true, true, true);
+        return immutableCopy(bci, true, true, true);
     }
 
     private static void assertHigh(Value x) {