001/* 002 * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. 008 * 009 * This code is distributed in the hope that it will be useful, but WITHOUT 010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 011 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 012 * version 2 for more details (a copy is included in the LICENSE file that 013 * accompanied this code). 014 * 015 * You should have received a copy of the GNU General Public License version 016 * 2 along with this work; if not, write to the Free Software Foundation, 017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 018 * 019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 020 * or visit www.oracle.com if you need additional information or have any 021 * questions. 022 */ 023package com.oracle.graal.nodes.java; 024 025import jdk.internal.jvmci.meta.*; 026 027import com.oracle.graal.compiler.common.type.*; 028import com.oracle.graal.graph.*; 029import com.oracle.graal.nodeinfo.*; 030import com.oracle.graal.nodes.*; 031import com.oracle.graal.nodes.spi.*; 032import com.oracle.graal.nodes.virtual.*; 033 034/** 035 * The {@code StoreFieldNode} represents a write to a static or instance field. 036 */ 037@NodeInfo(nameTemplate = "StoreField#{p#field/s}") 038public final class StoreFieldNode extends AccessFieldNode implements StateSplit, Virtualizable { 039 public static final NodeClass<StoreFieldNode> TYPE = NodeClass.create(StoreFieldNode.class); 040 041 @Input ValueNode value; 042 @OptionalInput(InputType.State) FrameState stateAfter; 043 044 public FrameState stateAfter() { 045 return stateAfter; 046 } 047 048 public void setStateAfter(FrameState x) { 049 assert x == null || x.isAlive() : "frame state must be in a graph"; 050 updateUsages(stateAfter, x); 051 stateAfter = x; 052 } 053 054 public boolean hasSideEffect() { 055 return true; 056 } 057 058 public ValueNode value() { 059 return value; 060 } 061 062 public StoreFieldNode(ValueNode object, ResolvedJavaField field, ValueNode value) { 063 super(TYPE, StampFactory.forVoid(), object, field); 064 this.value = value; 065 } 066 067 public StoreFieldNode(ValueNode object, ResolvedJavaField field, ValueNode value, FrameState stateAfter) { 068 super(TYPE, StampFactory.forVoid(), object, field); 069 this.value = value; 070 this.stateAfter = stateAfter; 071 } 072 073 @Override 074 public void virtualize(VirtualizerTool tool) { 075 ValueNode alias = tool.getAlias(object()); 076 if (alias instanceof VirtualObjectNode) { 077 VirtualInstanceNode virtual = (VirtualInstanceNode) alias; 078 int fieldIndex = virtual.fieldIndex(field()); 079 if (fieldIndex != -1) { 080 tool.setVirtualEntry(virtual, fieldIndex, value(), false); 081 tool.delete(); 082 } 083 } 084 } 085 086 public FrameState getState() { 087 return stateAfter; 088 } 089}