RawMonitorEnterNode.java revision 13175:3df8ef613001
1/*
2 * Copyright (c) 2009, 2016, 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 */
23package org.graalvm.compiler.nodes.java;
24
25import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_64;
26import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_64;
27
28import org.graalvm.compiler.core.common.type.ObjectStamp;
29import org.graalvm.compiler.graph.IterableNodeType;
30import org.graalvm.compiler.graph.NodeClass;
31import org.graalvm.compiler.nodeinfo.NodeInfo;
32import org.graalvm.compiler.nodes.ValueNode;
33import org.graalvm.compiler.nodes.extended.MonitorEnter;
34import org.graalvm.compiler.nodes.memory.MemoryCheckpoint;
35import org.graalvm.compiler.nodes.spi.Lowerable;
36import org.graalvm.compiler.nodes.spi.LoweringTool;
37import org.graalvm.compiler.nodes.spi.Virtualizable;
38import org.graalvm.compiler.nodes.spi.VirtualizerTool;
39import org.graalvm.compiler.nodes.virtual.VirtualObjectNode;
40import org.graalvm.word.LocationIdentity;
41
42/**
43 * The {@code RawMonitorEnterNode} represents the acquisition of a monitor. The object needs to
44 * already be non-null and the hub is an additional parameter to the node.
45 */
46// @formatter:off
47@NodeInfo(cycles = CYCLES_64,
48          cyclesRationale = "Rough estimation of the enter operation",
49          size = SIZE_64)
50// @formatter:on
51public final class RawMonitorEnterNode extends AccessMonitorNode implements Virtualizable, Lowerable, IterableNodeType, MonitorEnter, MemoryCheckpoint.Single {
52
53    public static final NodeClass<RawMonitorEnterNode> TYPE = NodeClass.create(RawMonitorEnterNode.class);
54
55    @Input ValueNode hub;
56
57    public RawMonitorEnterNode(ValueNode object, ValueNode hub, MonitorIdNode monitorId) {
58        super(TYPE, object, monitorId);
59        assert ((ObjectStamp) object.stamp()).nonNull();
60        this.hub = hub;
61    }
62
63    @Override
64    public LocationIdentity getLocationIdentity() {
65        return LocationIdentity.any();
66    }
67
68    @Override
69    public void lower(LoweringTool tool) {
70        tool.getLowerer().lower(this, tool);
71    }
72
73    @Override
74    public void virtualize(VirtualizerTool tool) {
75        ValueNode alias = tool.getAlias(object());
76        if (alias instanceof VirtualObjectNode) {
77            VirtualObjectNode virtual = (VirtualObjectNode) alias;
78            if (virtual.hasIdentity()) {
79                tool.addLock(virtual, getMonitorId());
80                tool.delete();
81            }
82        }
83    }
84
85    public ValueNode getHub() {
86        return hub;
87    }
88}
89