annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/NewArrayNode.java @ 21931:40aff2bb1880

Preserve stateBefore when creating newInstanceNode and newArrayNode during canonicalization
author Christian Wimmer <christian.wimmer@oracle.com>
date Thu, 11 Jun 2015 20:40:11 -0700
parents 48c1ebd24120
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
19396
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
2 * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
23 package com.oracle.graal.nodes.java;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
13554
83fd2094ff66 rework of monitorenter/exit (use MonitorIdNode)
Lukas Stadler <lukas.stadler@jku.at>
parents: 13122
diff changeset
25 import java.util.*;
83fd2094ff66 rework of monitorenter/exit (use MonitorIdNode)
Lukas Stadler <lukas.stadler@jku.at>
parents: 13122
diff changeset
26
15261
882f4cb7cfcf Move Stamps to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents: 15260
diff changeset
27 import com.oracle.graal.compiler.common.type.*;
19396
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
28 import com.oracle.graal.graph.*;
16841
cbd42807a31f moved NodeInfo and friends into separate com.oracle.graal.nodeinfo project so that annotation processor can be applied to the base Node class
Doug Simon <doug.simon@oracle.com>
parents: 16822
diff changeset
29 import com.oracle.graal.nodeinfo.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
30 import com.oracle.graal.nodes.*;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
31 import com.oracle.graal.nodes.spi.*;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
32 import com.oracle.graal.nodes.type.*;
6393
adf0879a41c1 more escape analysis infrastructure: change EscapeOp behavior, make MaterializeObjectNodes roots for escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents: 6356
diff changeset
33 import com.oracle.graal.nodes.virtual.*;
21556
48c1ebd24120 renamed com.oracle.graal.api[meta|code] modules to com.oracle.jvmci.[meta|code] (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 20155
diff changeset
34 import com.oracle.jvmci.meta.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
35
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
36 /**
10589
17c5cc84560b Factor out common code of NewArrayNode and DynamicNewArrayNode.
Roland Schatz <roland.schatz@oracle.com>
parents: 9880
diff changeset
37 * The {@code NewArrayNode} is used for all array allocations where the element type is know at
17c5cc84560b Factor out common code of NewArrayNode and DynamicNewArrayNode.
Roland Schatz <roland.schatz@oracle.com>
parents: 9880
diff changeset
38 * compile time.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
39 */
17363
4f9633b83a24 mx: reduce size of exculde command line argument and fold it into package-star expressions
Bernhard Urban <bernhard.urban@jku.at>
parents: 17133
diff changeset
40 // JaCoCo Exclude
16822
5d468add216f added @NodeInfo annotations to all Node classes
Doug Simon <doug.simon@oracle.com>
parents: 16028
diff changeset
41 @NodeInfo
10589
17c5cc84560b Factor out common code of NewArrayNode and DynamicNewArrayNode.
Roland Schatz <roland.schatz@oracle.com>
parents: 9880
diff changeset
42 public class NewArrayNode extends AbstractNewArrayNode implements VirtualizableAllocation {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
43
19526
8fc336a04d77 Create TYPE fields for LIRInstruction and CompositeValue. Renaming NodeClass#get to NodeClass#create.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19471
diff changeset
44 public static final NodeClass<NewArrayNode> TYPE = NodeClass.create(NewArrayNode.class);
19396
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
45
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18487
diff changeset
46 public NewArrayNode(ResolvedJavaType elementType, ValueNode length, boolean fillContents) {
21931
40aff2bb1880 Preserve stateBefore when creating newInstanceNode and newArrayNode during canonicalization
Christian Wimmer <christian.wimmer@oracle.com>
parents: 21556
diff changeset
47 this(elementType, length, fillContents, null);
19396
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
48 }
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18845
diff changeset
49
21931
40aff2bb1880 Preserve stateBefore when creating newInstanceNode and newArrayNode during canonicalization
Christian Wimmer <christian.wimmer@oracle.com>
parents: 21556
diff changeset
50 public NewArrayNode(ResolvedJavaType elementType, ValueNode length, boolean fillContents, FrameState stateBefore) {
40aff2bb1880 Preserve stateBefore when creating newInstanceNode and newArrayNode during canonicalization
Christian Wimmer <christian.wimmer@oracle.com>
parents: 21556
diff changeset
51 this(TYPE, elementType, length, fillContents, stateBefore);
40aff2bb1880 Preserve stateBefore when creating newInstanceNode and newArrayNode during canonicalization
Christian Wimmer <christian.wimmer@oracle.com>
parents: 21556
diff changeset
52 }
40aff2bb1880 Preserve stateBefore when creating newInstanceNode and newArrayNode during canonicalization
Christian Wimmer <christian.wimmer@oracle.com>
parents: 21556
diff changeset
53
40aff2bb1880 Preserve stateBefore when creating newInstanceNode and newArrayNode during canonicalization
Christian Wimmer <christian.wimmer@oracle.com>
parents: 21556
diff changeset
54 protected NewArrayNode(NodeClass<? extends NewArrayNode> c, ResolvedJavaType elementType, ValueNode length, boolean fillContents, FrameState stateBefore) {
40aff2bb1880 Preserve stateBefore when creating newInstanceNode and newArrayNode during canonicalization
Christian Wimmer <christian.wimmer@oracle.com>
parents: 21556
diff changeset
55 super(c, StampFactory.exactNonNull(elementType.getArrayClass()), length, fillContents, stateBefore);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
56 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
57
16028
bca2ed3b97fd skip initialization and use arraycopy for cloning arrays
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15261
diff changeset
58 @NodeIntrinsic
18163
c88ab4f1f04a re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
Doug Simon <doug.simon@oracle.com>
parents: 17450
diff changeset
59 private static native Object newArray(@ConstantNodeParameter Class<?> elementType, int length, @ConstantNodeParameter boolean fillContents);
16028
bca2ed3b97fd skip initialization and use arraycopy for cloning arrays
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15261
diff changeset
60
bca2ed3b97fd skip initialization and use arraycopy for cloning arrays
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15261
diff changeset
61 public static Object newUninitializedArray(Class<?> elementType, int length) {
bca2ed3b97fd skip initialization and use arraycopy for cloning arrays
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15261
diff changeset
62 return newArray(elementType, length, false);
bca2ed3b97fd skip initialization and use arraycopy for cloning arrays
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15261
diff changeset
63 }
bca2ed3b97fd skip initialization and use arraycopy for cloning arrays
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15261
diff changeset
64
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
65 /**
5814
d241f8b2e6f9 Adapt the coloring filter for binary dumped graphs
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5811
diff changeset
66 * Gets the element type of the array.
16028
bca2ed3b97fd skip initialization and use arraycopy for cloning arrays
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15261
diff changeset
67 *
5814
d241f8b2e6f9 Adapt the coloring filter for binary dumped graphs
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5811
diff changeset
68 * @return the element type of the array
d241f8b2e6f9 Adapt the coloring filter for binary dumped graphs
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5811
diff changeset
69 */
d241f8b2e6f9 Adapt the coloring filter for binary dumped graphs
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5811
diff changeset
70 public ResolvedJavaType elementType() {
15260
61363577a184 Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents: 13554
diff changeset
71 return StampTool.typeOrNull(this).getComponentType();
5814
d241f8b2e6f9 Adapt the coloring filter for binary dumped graphs
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5811
diff changeset
72 }
d241f8b2e6f9 Adapt the coloring filter for binary dumped graphs
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 5811
diff changeset
73
6393
adf0879a41c1 more escape analysis infrastructure: change EscapeOp behavior, make MaterializeObjectNodes roots for escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents: 6356
diff changeset
74 @Override
7394
94f032472c28 changed PEA interface:
Lukas Stadler <lukas.stadler@jku.at>
parents: 7007
diff changeset
75 public void virtualize(VirtualizerTool tool) {
20155
6a84da35bc84 take replacements into account in NewArrayNode.virtualize
Lukas Stadler <lukas.stadler@oracle.com>
parents: 19526
diff changeset
76 ValueNode replacedLength = tool.getReplacedValue(length());
6a84da35bc84 take replacements into account in NewArrayNode.virtualize
Lukas Stadler <lukas.stadler@oracle.com>
parents: 19526
diff changeset
77 if (replacedLength.asConstant() != null) {
6a84da35bc84 take replacements into account in NewArrayNode.virtualize
Lukas Stadler <lukas.stadler@oracle.com>
parents: 19526
diff changeset
78 final int constantLength = replacedLength.asJavaConstant().asInt();
7394
94f032472c28 changed PEA interface:
Lukas Stadler <lukas.stadler@jku.at>
parents: 7007
diff changeset
79 if (constantLength >= 0 && constantLength < tool.getMaximumEntryCount()) {
7006
51b6e594b0cd refactor EscapeAnalyzeable (remove EscapeOp)
Lukas Stadler <lukas.stadler@jku.at>
parents: 6666
diff changeset
80 ValueNode[] state = new ValueNode[constantLength];
13122
c6ab6ae1b360 Allow subclasses of NewInstanceNode and NewArrayNode to provide the default values used by escape analysis
Christian Wimmer <christian.wimmer@oracle.com>
parents: 10589
diff changeset
81 ConstantNode defaultForKind = constantLength == 0 ? null : defaultElementValue();
7006
51b6e594b0cd refactor EscapeAnalyzeable (remove EscapeOp)
Lukas Stadler <lukas.stadler@jku.at>
parents: 6666
diff changeset
82 for (int i = 0; i < constantLength; i++) {
51b6e594b0cd refactor EscapeAnalyzeable (remove EscapeOp)
Lukas Stadler <lukas.stadler@jku.at>
parents: 6666
diff changeset
83 state[i] = defaultForKind;
51b6e594b0cd refactor EscapeAnalyzeable (remove EscapeOp)
Lukas Stadler <lukas.stadler@jku.at>
parents: 6666
diff changeset
84 }
17133
1a02fc45776f Allow customization by subclasses
Christian Wimmer <christian.wimmer@oracle.com>
parents: 16957
diff changeset
85 VirtualObjectNode virtualObject = createVirtualArrayNode(constantLength);
13554
83fd2094ff66 rework of monitorenter/exit (use MonitorIdNode)
Lukas Stadler <lukas.stadler@jku.at>
parents: 13122
diff changeset
86 tool.createVirtualObject(virtualObject, state, Collections.<MonitorIdNode> emptyList());
7394
94f032472c28 changed PEA interface:
Lukas Stadler <lukas.stadler@jku.at>
parents: 7007
diff changeset
87 tool.replaceWithVirtual(virtualObject);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
88 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
89 }
6393
adf0879a41c1 more escape analysis infrastructure: change EscapeOp behavior, make MaterializeObjectNodes roots for escape analysis
Lukas Stadler <lukas.stadler@jku.at>
parents: 6356
diff changeset
90 }
13122
c6ab6ae1b360 Allow subclasses of NewInstanceNode and NewArrayNode to provide the default values used by escape analysis
Christian Wimmer <christian.wimmer@oracle.com>
parents: 10589
diff changeset
91
17133
1a02fc45776f Allow customization by subclasses
Christian Wimmer <christian.wimmer@oracle.com>
parents: 16957
diff changeset
92 protected VirtualArrayNode createVirtualArrayNode(int constantLength) {
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18487
diff changeset
93 return new VirtualArrayNode(elementType(), constantLength);
17133
1a02fc45776f Allow customization by subclasses
Christian Wimmer <christian.wimmer@oracle.com>
parents: 16957
diff changeset
94 }
1a02fc45776f Allow customization by subclasses
Christian Wimmer <christian.wimmer@oracle.com>
parents: 16957
diff changeset
95
13122
c6ab6ae1b360 Allow subclasses of NewInstanceNode and NewArrayNode to provide the default values used by escape analysis
Christian Wimmer <christian.wimmer@oracle.com>
parents: 10589
diff changeset
96 /* Factored out in a separate method so that subclasses can override it. */
c6ab6ae1b360 Allow subclasses of NewInstanceNode and NewArrayNode to provide the default values used by escape analysis
Christian Wimmer <christian.wimmer@oracle.com>
parents: 10589
diff changeset
97 protected ConstantNode defaultElementValue() {
c6ab6ae1b360 Allow subclasses of NewInstanceNode and NewArrayNode to provide the default values used by escape analysis
Christian Wimmer <christian.wimmer@oracle.com>
parents: 10589
diff changeset
98 return ConstantNode.defaultForKind(elementType().getKind(), graph());
c6ab6ae1b360 Allow subclasses of NewInstanceNode and NewArrayNode to provide the default values used by escape analysis
Christian Wimmer <christian.wimmer@oracle.com>
parents: 10589
diff changeset
99 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
100 }