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 */ 23 package org.graalvm.compiler.nodes.java; 24 25 import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_50; 26 import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_50; 27 28 import org.graalvm.compiler.core.common.type.StampFactory; 29 import org.graalvm.compiler.core.common.type.TypeReference; 30 import org.graalvm.compiler.graph.NodeClass; 31 import org.graalvm.compiler.graph.NodeInputList; 32 import org.graalvm.compiler.graph.NodeList; 33 import org.graalvm.compiler.nodeinfo.NodeInfo; 34 import org.graalvm.compiler.nodes.DeoptimizingFixedWithNextNode; 35 import org.graalvm.compiler.nodes.ValueNode; 36 import org.graalvm.compiler.nodes.spi.ArrayLengthProvider; 37 import org.graalvm.compiler.nodes.spi.Lowerable; 38 import org.graalvm.compiler.nodes.spi.LoweringTool; 39 40 import 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) 46 public 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 }