Mercurial > hg > truffle
annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/NewArrayNode.java @ 18187:9619ba4daf4c
Rename Constant to JavaConstant.
author | Roland Schatz <roland.schatz@oracle.com> |
---|---|
date | Thu, 30 Oct 2014 12:21:07 +0100 |
parents | c88ab4f1f04a |
children | 0f4813e0b4a9 |
rev | line source |
---|---|
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
1 /* |
18187
9619ba4daf4c
Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents:
18163
diff
changeset
|
2 * Copyright (c) 2009, 2014, 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 |
5507
dc71b06d09f8
Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5504
diff
changeset
|
27 import com.oracle.graal.api.meta.*; |
15261
882f4cb7cfcf
Move Stamps to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents:
15260
diff
changeset
|
28 import com.oracle.graal.compiler.common.type.*; |
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.*; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
34 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
35 /** |
10589
17c5cc84560b
Factor out common code of NewArrayNode and DynamicNewArrayNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
9880
diff
changeset
|
36 * 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
|
37 * compile time. |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
38 */ |
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
|
39 // JaCoCo Exclude |
16822
5d468add216f
added @NodeInfo annotations to all Node classes
Doug Simon <doug.simon@oracle.com>
parents:
16028
diff
changeset
|
40 @NodeInfo |
10589
17c5cc84560b
Factor out common code of NewArrayNode and DynamicNewArrayNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
9880
diff
changeset
|
41 public class NewArrayNode extends AbstractNewArrayNode implements VirtualizableAllocation { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
42 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
43 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
44 * Constructs a new NewArrayNode. |
16028
bca2ed3b97fd
skip initialization and use arraycopy for cloning arrays
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15261
diff
changeset
|
45 * |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7394
diff
changeset
|
46 * @param elementType the the type of the elements of the newly created array (not the type of |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7394
diff
changeset
|
47 * the array itself). |
6511
0b62a9d44c21
add infrastructure for creating locked objects
Lukas Stadler <lukas.stadler@jku.at>
parents:
6399
diff
changeset
|
48 * @param length the node that produces the length for this allocation. |
0b62a9d44c21
add infrastructure for creating locked objects
Lukas Stadler <lukas.stadler@jku.at>
parents:
6399
diff
changeset
|
49 * @param fillContents determines whether the array elements should be initialized to zero/null. |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
50 */ |
16895
06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents:
16841
diff
changeset
|
51 public static NewArrayNode create(ResolvedJavaType elementType, ValueNode length, boolean fillContents) { |
17450
45b45f902bed
removed Node generation (GRAAL-857)
Doug Simon <doug.simon@oracle.com>
parents:
17363
diff
changeset
|
52 return new NewArrayNode(elementType, length, fillContents); |
16895
06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents:
16841
diff
changeset
|
53 } |
06c15e88d383
added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents:
16841
diff
changeset
|
54 |
16957
27b40d2f8f8a
relaxed access control from package to protected for elements that need to be accessed in generated subclasses in disjoint packages
Doug Simon <doug.simon@oracle.com>
parents:
16919
diff
changeset
|
55 protected NewArrayNode(ResolvedJavaType elementType, ValueNode length, boolean fillContents) { |
10589
17c5cc84560b
Factor out common code of NewArrayNode and DynamicNewArrayNode.
Roland Schatz <roland.schatz@oracle.com>
parents:
9880
diff
changeset
|
56 super(StampFactory.exactNonNull(elementType.getArrayClass()), length, fillContents); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
57 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
58 |
16028
bca2ed3b97fd
skip initialization and use arraycopy for cloning arrays
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15261
diff
changeset
|
59 @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
|
60 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
|
61 |
bca2ed3b97fd
skip initialization and use arraycopy for cloning arrays
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15261
diff
changeset
|
62 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
|
63 return newArray(elementType, length, false); |
bca2ed3b97fd
skip initialization and use arraycopy for cloning arrays
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15261
diff
changeset
|
64 } |
bca2ed3b97fd
skip initialization and use arraycopy for cloning arrays
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15261
diff
changeset
|
65 |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
66 /** |
5814
d241f8b2e6f9
Adapt the coloring filter for binary dumped graphs
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5811
diff
changeset
|
67 * 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
|
68 * |
5814
d241f8b2e6f9
Adapt the coloring filter for binary dumped graphs
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5811
diff
changeset
|
69 * @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
|
70 */ |
d241f8b2e6f9
Adapt the coloring filter for binary dumped graphs
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5811
diff
changeset
|
71 public ResolvedJavaType elementType() { |
15260
61363577a184
Move static helpers from ObjectStamp to StampTool.
Josef Eisl <josef.eisl@jku.at>
parents:
13554
diff
changeset
|
72 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
|
73 } |
d241f8b2e6f9
Adapt the coloring filter for binary dumped graphs
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
5811
diff
changeset
|
74 |
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
|
75 @Override |
7394
94f032472c28
changed PEA interface:
Lukas Stadler <lukas.stadler@jku.at>
parents:
7007
diff
changeset
|
76 public void virtualize(VirtualizerTool tool) { |
18187
9619ba4daf4c
Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents:
18163
diff
changeset
|
77 if (length().asJavaConstant() != null) { |
9619ba4daf4c
Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents:
18163
diff
changeset
|
78 final int constantLength = length().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) { |
1a02fc45776f
Allow customization by subclasses
Christian Wimmer <christian.wimmer@oracle.com>
parents:
16957
diff
changeset
|
93 return VirtualArrayNode.create(elementType(), constantLength); |
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 } |