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 org.graalvm.compiler.virtual.phases.ea; 24 25 import java.util.Arrays; 26 import java.util.List; 27 28 import org.graalvm.compiler.debug.Debug; 29 import org.graalvm.compiler.debug.DebugCounter; 30 import org.graalvm.compiler.nodes.ValueNode; 31 import org.graalvm.compiler.nodes.java.MonitorIdNode; 32 import org.graalvm.compiler.nodes.virtual.EscapeObjectState; 33 import org.graalvm.compiler.nodes.virtual.LockState; 34 import org.graalvm.compiler.nodes.virtual.VirtualObjectNode; 35 import org.graalvm.compiler.virtual.nodes.MaterializedObjectState; 36 import org.graalvm.compiler.virtual.nodes.VirtualObjectState; 37 38 import jdk.vm.ci.meta.JavaConstant; 39 40 /** 41 * This class describes the state of a virtual object while iterating over the graph. It describes 42 * the fields or array elements (called "entries") and the lock count if the object is still 43 * virtual. If the object was materialized, it contains the current materialized value. 44 */ 45 public class ObjectState { 46 47 public static final DebugCounter CREATE_ESCAPED_OBJECT_STATE = Debug.counter("CreateEscapeObjectState"); 48 public static final DebugCounter GET_ESCAPED_OBJECT_STATE = Debug.counter("GetEscapeObjectState"); 49 50 private ValueNode[] entries; 51 private ValueNode materializedValue; 52 private LockState locks; 53 private boolean ensureVirtualized; 54 55 private EscapeObjectState cachedState; 56 57 /** 58 * ObjectStates are duplicated lazily, if this field is true then the state needs to be copied 59 * before it is modified. 60 */ 61 boolean copyOnWrite; 62 63 public ObjectState(ValueNode[] entries, List<MonitorIdNode> locks, boolean ensureVirtualized) { 64 this(entries, (LockState) null, ensureVirtualized); 65 for (int i = locks.size() - 1; i >= 0; i--) { 66 this.locks = new LockState(locks.get(i), this.locks); 67 } 68 } 75 76 public ObjectState(ValueNode materializedValue, LockState locks, boolean ensureVirtualized) { 77 assert materializedValue != null; 78 this.materializedValue = materializedValue; 79 this.locks = locks; 80 this.ensureVirtualized = ensureVirtualized; 81 } 82 83 private ObjectState(ObjectState other) { 84 entries = other.entries == null ? null : other.entries.clone(); 85 materializedValue = other.materializedValue; 86 locks = other.locks; 87 cachedState = other.cachedState; 88 ensureVirtualized = other.ensureVirtualized; 89 } 90 91 public ObjectState cloneState() { 92 return new ObjectState(this); 93 } 94 95 public EscapeObjectState createEscapeObjectState(VirtualObjectNode virtual) { 96 GET_ESCAPED_OBJECT_STATE.increment(); 97 if (cachedState == null) { 98 CREATE_ESCAPED_OBJECT_STATE.increment(); 99 if (isVirtual()) { 100 /* 101 * Clear out entries that are default values anyway. 102 * 103 * TODO: this should be propagated into ObjectState.entries, but that will take some 104 * more refactoring. 105 */ 106 ValueNode[] newEntries = entries.clone(); 107 for (int i = 0; i < newEntries.length; i++) { 108 if (newEntries[i].asJavaConstant() == JavaConstant.defaultForKind(virtual.entryKind(i).getStackKind())) { 109 newEntries[i] = null; 110 } 111 } 112 cachedState = new VirtualObjectState(virtual, newEntries); 113 } else { 114 cachedState = new MaterializedObjectState(virtual, materializedValue); 115 } 116 } 117 return cachedState; 118 | 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 org.graalvm.compiler.virtual.phases.ea; 24 25 import java.util.Arrays; 26 import java.util.List; 27 28 import org.graalvm.compiler.debug.CounterKey; 29 import org.graalvm.compiler.debug.DebugContext; 30 import org.graalvm.compiler.nodes.ValueNode; 31 import org.graalvm.compiler.nodes.java.MonitorIdNode; 32 import org.graalvm.compiler.nodes.virtual.EscapeObjectState; 33 import org.graalvm.compiler.nodes.virtual.LockState; 34 import org.graalvm.compiler.nodes.virtual.VirtualObjectNode; 35 import org.graalvm.compiler.virtual.nodes.MaterializedObjectState; 36 import org.graalvm.compiler.virtual.nodes.VirtualObjectState; 37 38 import jdk.vm.ci.meta.JavaConstant; 39 40 /** 41 * This class describes the state of a virtual object while iterating over the graph. It describes 42 * the fields or array elements (called "entries") and the lock count if the object is still 43 * virtual. If the object was materialized, it contains the current materialized value. 44 */ 45 public class ObjectState { 46 47 public static final CounterKey CREATE_ESCAPED_OBJECT_STATE = DebugContext.counter("CreateEscapeObjectState"); 48 public static final CounterKey GET_ESCAPED_OBJECT_STATE = DebugContext.counter("GetEscapeObjectState"); 49 50 private ValueNode[] entries; 51 private ValueNode materializedValue; 52 private LockState locks; 53 private boolean ensureVirtualized; 54 55 private EscapeObjectState cachedState; 56 57 /** 58 * ObjectStates are duplicated lazily, if this field is true then the state needs to be copied 59 * before it is modified. 60 */ 61 boolean copyOnWrite; 62 63 public ObjectState(ValueNode[] entries, List<MonitorIdNode> locks, boolean ensureVirtualized) { 64 this(entries, (LockState) null, ensureVirtualized); 65 for (int i = locks.size() - 1; i >= 0; i--) { 66 this.locks = new LockState(locks.get(i), this.locks); 67 } 68 } 75 76 public ObjectState(ValueNode materializedValue, LockState locks, boolean ensureVirtualized) { 77 assert materializedValue != null; 78 this.materializedValue = materializedValue; 79 this.locks = locks; 80 this.ensureVirtualized = ensureVirtualized; 81 } 82 83 private ObjectState(ObjectState other) { 84 entries = other.entries == null ? null : other.entries.clone(); 85 materializedValue = other.materializedValue; 86 locks = other.locks; 87 cachedState = other.cachedState; 88 ensureVirtualized = other.ensureVirtualized; 89 } 90 91 public ObjectState cloneState() { 92 return new ObjectState(this); 93 } 94 95 public EscapeObjectState createEscapeObjectState(DebugContext debug, VirtualObjectNode virtual) { 96 GET_ESCAPED_OBJECT_STATE.increment(debug); 97 if (cachedState == null) { 98 CREATE_ESCAPED_OBJECT_STATE.increment(debug); 99 if (isVirtual()) { 100 /* 101 * Clear out entries that are default values anyway. 102 * 103 * TODO: this should be propagated into ObjectState.entries, but that will take some 104 * more refactoring. 105 */ 106 ValueNode[] newEntries = entries.clone(); 107 for (int i = 0; i < newEntries.length; i++) { 108 if (newEntries[i].asJavaConstant() == JavaConstant.defaultForKind(virtual.entryKind(i).getStackKind())) { 109 newEntries[i] = null; 110 } 111 } 112 cachedState = new VirtualObjectState(virtual, newEntries); 113 } else { 114 cachedState = new MaterializedObjectState(virtual, materializedValue); 115 } 116 } 117 return cachedState; 118 |