1/*
2 * Copyright (c) 2013, 2015, 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.virtual;
24
25import org.graalvm.compiler.graph.NodeClass;
26import org.graalvm.compiler.nodeinfo.NodeInfo;
27import org.graalvm.compiler.nodes.FixedNode;
28import org.graalvm.compiler.nodes.ValueNode;
29import org.graalvm.compiler.nodes.extended.BoxNode;
30
31import org.graalvm.compiler.nodes.spi.VirtualizerTool;
32import jdk.vm.ci.meta.JavaKind;
33import jdk.vm.ci.meta.ResolvedJavaType;
34
35@NodeInfo
36public class VirtualBoxingNode extends VirtualInstanceNode {
37
38    public static final NodeClass<VirtualBoxingNode> TYPE = NodeClass.create(VirtualBoxingNode.class);
39    protected final JavaKind boxingKind;
40
41    public VirtualBoxingNode(ResolvedJavaType type, JavaKind boxingKind) {
42        this(TYPE, type, boxingKind);
43    }
44
45    public VirtualBoxingNode(NodeClass<? extends VirtualBoxingNode> c, ResolvedJavaType type, JavaKind boxingKind) {
46        super(c, type, false);
47        this.boxingKind = boxingKind;
48    }
49
50    public JavaKind getBoxingKind() {
51        return boxingKind;
52    }
53
54    @Override
55    public VirtualBoxingNode duplicate() {
56        return new VirtualBoxingNode(type(), boxingKind);
57    }
58
59    @Override
60    public ValueNode getMaterializedRepresentation(FixedNode fixed, ValueNode[] entries, LockState locks) {
61        assert entries.length == 1;
62        assert locks == null;
63        return new BoxNode(entries[0], type(), boxingKind);
64    }
65
66    public ValueNode getBoxedValue(VirtualizerTool tool) {
67        return tool.getEntry(this, 0);
68    }
69}
70