NewMultiArrayNode.java revision 12651:6ef01bd40ce2
1/*
2 * Copyright (c) 2009, 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.java;
24
25import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_50;
26import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_50;
27
28import org.graalvm.compiler.core.common.type.StampFactory;
29import org.graalvm.compiler.core.common.type.TypeReference;
30import org.graalvm.compiler.graph.NodeClass;
31import org.graalvm.compiler.graph.NodeInputList;
32import org.graalvm.compiler.graph.NodeList;
33import org.graalvm.compiler.nodeinfo.NodeInfo;
34import org.graalvm.compiler.nodes.DeoptimizingFixedWithNextNode;
35import org.graalvm.compiler.nodes.ValueNode;
36import org.graalvm.compiler.nodes.spi.ArrayLengthProvider;
37import org.graalvm.compiler.nodes.spi.Lowerable;
38import org.graalvm.compiler.nodes.spi.LoweringTool;
39
40import jdk.vm.ci.meta.ResolvedJavaType;
41
42/**
43 * The {@code NewMultiArrayNode} represents an allocation of a multi-dimensional object array.
44 */
45@NodeInfo(cycles = CYCLES_50, size = SIZE_50)
46public class NewMultiArrayNode extends DeoptimizingFixedWithNextNode implements Lowerable, ArrayLengthProvider {
47
48    public static final NodeClass<NewMultiArrayNode> TYPE = NodeClass.create(NewMultiArrayNode.class);
49    @Input protected NodeInputList<ValueNode> dimensions;
50    protected final ResolvedJavaType type;
51
52    public ValueNode dimension(int index) {
53        return dimensions.get(index);
54    }
55
56    public int dimensionCount() {
57        return dimensions.size();
58    }
59
60    public NodeList<ValueNode> dimensions() {
61        return dimensions;
62    }
63
64    public NewMultiArrayNode(ResolvedJavaType type, ValueNode[] dimensions) {
65        this(TYPE, type, dimensions);
66    }
67
68    protected NewMultiArrayNode(NodeClass<? extends NewMultiArrayNode> c, ResolvedJavaType type, ValueNode[] dimensions) {
69        super(c, StampFactory.objectNonNull(TypeReference.createExactTrusted(type)));
70        this.type = type;
71        this.dimensions = new NodeInputList<>(this, dimensions);
72        assert dimensions.length > 0 && type.isArray();
73    }
74
75    @Override
76    public void lower(LoweringTool tool) {
77        tool.getLowerer().lower(this, tool);
78    }
79
80    public ResolvedJavaType type() {
81        return type;
82    }
83
84    @Override
85    public boolean canDeoptimize() {
86        return true;
87    }
88
89    @Override
90    public ValueNode length() {
91        return dimension(0);
92    }
93}
94