annotate graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/NewObjectSnippets.java @ 11770:7c4595b7ef3a

NewInstanceNode: use INIT_LOCATION; NewArrayNode: use INIT_LOCATION and ARRAY_LENGTH_LOCATION
author Bernhard Urban <bernhard.urban@jku.at>
date Tue, 24 Sep 2013 14:11:35 +0200
parents 7e7edb86fb43
children 4e2be0ab31a9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5563
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1 /*
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
4 *
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
8 *
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
13 * accompanied this code).
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
14 *
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
18 *
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
21 * questions.
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
22 */
8415
2361bf148c06 rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents: 8413
diff changeset
23 package com.oracle.graal.hotspot.replacements;
5563
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
24
6501
55c54c4bdcfc moved UnsignedMath to com.oracle.graal.api.code
Doug Simon <doug.simon@oracle.com>
parents: 6431
diff changeset
25 import static com.oracle.graal.api.code.UnsignedMath.*;
9513
659bb6cf930c rename: HotSpotSnippetUtils -> HotSpotReplacementsUtil
Doug Simon <doug.simon@oracle.com>
parents: 9423
diff changeset
26 import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*;
11752
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11732
diff changeset
27 import static com.oracle.graal.nodes.PiArrayNode.*;
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11732
diff changeset
28 import static com.oracle.graal.nodes.PiNode.*;
10787
388fbd0dd4a4 moved BranchNodeProbabilities to graal.nodes project
Doug Simon <doug.simon@oracle.com>
parents: 10760
diff changeset
29 import static com.oracle.graal.nodes.extended.BranchProbabilityNode.*;
9864
063a712fe8d8 converted remaining options in GraalOptions to new system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 9793
diff changeset
30 import static com.oracle.graal.phases.GraalOptions.*;
8415
2361bf148c06 rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents: 8413
diff changeset
31 import static com.oracle.graal.replacements.SnippetTemplate.*;
2361bf148c06 rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents: 8413
diff changeset
32 import static com.oracle.graal.replacements.nodes.ExplodeLoopNode.*;
5563
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
33
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
34 import com.oracle.graal.api.code.*;
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
35 import com.oracle.graal.api.meta.*;
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
36 import com.oracle.graal.debug.*;
11752
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11732
diff changeset
37 import com.oracle.graal.graph.Node.ConstantNodeParameter;
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11732
diff changeset
38 import com.oracle.graal.graph.Node.NodeIntrinsic;
5563
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
39 import com.oracle.graal.hotspot.meta.*;
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
40 import com.oracle.graal.hotspot.nodes.*;
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
41 import com.oracle.graal.nodes.*;
10586
110434bc2913 Remove unnecessary class.
Roland Schatz <roland.schatz@oracle.com>
parents: 10542
diff changeset
42 import com.oracle.graal.nodes.extended.*;
5563
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
43 import com.oracle.graal.nodes.java.*;
5720
46ad94a0574a moved everything from com.oracle.graal.nodes.cri into com.oracle.graal.nodes.spi
Doug Simon <doug.simon@oracle.com>
parents: 5718
diff changeset
44 import com.oracle.graal.nodes.spi.*;
6950
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6568
diff changeset
45 import com.oracle.graal.nodes.type.*;
8415
2361bf148c06 rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents: 8413
diff changeset
46 import com.oracle.graal.replacements.*;
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
47 import com.oracle.graal.replacements.Snippet.ConstantParameter;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
48 import com.oracle.graal.replacements.Snippet.VarargsParameter;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
49 import com.oracle.graal.replacements.SnippetTemplate.AbstractTemplates;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
50 import com.oracle.graal.replacements.SnippetTemplate.Arguments;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
51 import com.oracle.graal.replacements.SnippetTemplate.SnippetInfo;
8415
2361bf148c06 rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents: 8413
diff changeset
52 import com.oracle.graal.replacements.nodes.*;
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7275
diff changeset
53 import com.oracle.graal.word.*;
5563
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
54
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
55 /**
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
56 * Snippets used for implementing NEW, ANEWARRAY and NEWARRAY.
5563
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
57 */
8413
d9347ee39fbe rename: SnippetsInterface -> Snippets
Doug Simon <doug.simon@oracle.com>
parents: 7868
diff changeset
58 public class NewObjectSnippets implements Snippets {
5563
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
59
11770
7c4595b7ef3a NewInstanceNode: use INIT_LOCATION; NewArrayNode: use INIT_LOCATION and ARRAY_LENGTH_LOCATION
Bernhard Urban <bernhard.urban@jku.at>
parents: 11752
diff changeset
60 public static final LocationIdentity INIT_LOCATION = new NamedLocationIdentity("Initialization");
7c4595b7ef3a NewInstanceNode: use INIT_LOCATION; NewArrayNode: use INIT_LOCATION and ARRAY_LENGTH_LOCATION
Bernhard Urban <bernhard.urban@jku.at>
parents: 11752
diff changeset
61 public static final LocationIdentity ARRAY_LENGTH_LOCATION = new NamedLocationIdentity("ArrayLength");
7c4595b7ef3a NewInstanceNode: use INIT_LOCATION; NewArrayNode: use INIT_LOCATION and ARRAY_LENGTH_LOCATION
Bernhard Urban <bernhard.urban@jku.at>
parents: 11752
diff changeset
62
5663
77069a28a983 split lowering of NEW into two separate nodes - one for doing the allocation and one for doing the object formatting. Both of these nodes are in turn lowered via snippets.
Doug Simon <doug.simon@oracle.com>
parents: 5648
diff changeset
63 @Snippet
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
64 public static Word allocate(int size) {
6419
b74402a7079b fixed oopmap bug caused by unsafe mixing of word and object values
Doug Simon <doug.simon@oracle.com>
parents: 6375
diff changeset
65 Word thread = thread();
7868
7a5bbcc36bb2 add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7701
diff changeset
66 Word top = readTlabTop(thread);
7a5bbcc36bb2 add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7701
diff changeset
67 Word end = readTlabEnd(thread);
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7275
diff changeset
68 Word newTop = top.add(size);
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
69 /*
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
70 * this check might lead to problems if the TLAB is within 16GB of the address space end
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
71 * (checked in c++ code)
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
72 */
9316
5e1465ec46d6 Change the way branch probabilities are injected. Update all snippets.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9015
diff changeset
73 if (probability(FAST_PATH_PROBABILITY, newTop.belowOrEqual(end))) {
7868
7a5bbcc36bb2 add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7701
diff changeset
74 writeTlabTop(thread, newTop);
5666
48a2505efb54 added verification phase for snippets to ensure word types are not incorrectly mixed with Object types
Doug Simon <doug.simon@oracle.com>
parents: 5663
diff changeset
75 return top;
5663
77069a28a983 split lowering of NEW into two separate nodes - one for doing the allocation and one for doing the object formatting. Both of these nodes are in turn lowered via snippets.
Doug Simon <doug.simon@oracle.com>
parents: 5648
diff changeset
76 }
5666
48a2505efb54 added verification phase for snippets to ensure word types are not incorrectly mixed with Object types
Doug Simon <doug.simon@oracle.com>
parents: 5663
diff changeset
77 return Word.zero();
5663
77069a28a983 split lowering of NEW into two separate nodes - one for doing the allocation and one for doing the object formatting. Both of these nodes are in turn lowered via snippets.
Doug Simon <doug.simon@oracle.com>
parents: 5648
diff changeset
78 }
5587
bf4f499cc538 added allocation logging to NewInstanceSnippets
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
79
5563
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
80 @Snippet
9688
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
81 public static Object allocateInstance(@ConstantParameter int size, Word hub, Word prototypeMarkWord, @ConstantParameter boolean fillContents) {
7035
52c88c405d07 Simplify how stamp is preserved after lowering of allocation nodes
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7034
diff changeset
82 Object result;
9688
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
83 Word thread = thread();
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
84 Word top = readTlabTop(thread);
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
85 Word end = readTlabEnd(thread);
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
86 Word newTop = top.add(size);
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
87 if (useTLAB() && probability(FAST_PATH_PROBABILITY, newTop.belowOrEqual(end))) {
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
88 writeTlabTop(thread, newTop);
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
89 result = formatObject(hub, size, top, prototypeMarkWord, fillContents);
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
90 } else {
5772
2f7a03583a32 added counters for code paths through the new object snippets
Doug Simon <doug.simon@oracle.com>
parents: 5770
diff changeset
91 new_stub.inc();
7035
52c88c405d07 Simplify how stamp is preserved after lowering of allocation nodes
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7034
diff changeset
92 result = NewInstanceStubCall.call(hub);
6511
0b62a9d44c21 add infrastructure for creating locked objects
Lukas Stadler <lukas.stadler@jku.at>
parents: 6504
diff changeset
93 }
11752
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11732
diff changeset
94 return piCast(verifyOop(result), StampFactory.forNodeIntrinsic());
5624
7d25723b7699 added oop verification to NewInstanceSnippets when -XX:+VerifyOops is enabled
Doug Simon <doug.simon@oracle.com>
parents: 5616
diff changeset
95 }
7d25723b7699 added oop verification to NewInstanceSnippets when -XX:+VerifyOops is enabled
Doug Simon <doug.simon@oracle.com>
parents: 5616
diff changeset
96
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
97 /**
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
98 * Maximum array length for which fast path allocation is used.
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
99 */
7147
88d626e2c2a8 added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents: 7145
diff changeset
100 public static final int MAX_ARRAY_FAST_PATH_ALLOCATION_LENGTH = 0x00FFFFFF;
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
101
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
102 @Snippet
9688
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
103 public static Object allocateArray(Word hub, int length, Word prototypeMarkWord, @ConstantParameter int headerSize, @ConstantParameter int log2ElementSize, @ConstantParameter boolean fillContents) {
5763
a3d71693e0ce removed bytecode disassembly from CodeCacheRuntime into separate BytecodeDisassembler class
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
104 if (!belowThan(length, MAX_ARRAY_FAST_PATH_ALLOCATION_LENGTH)) {
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
105 // This handles both negative array sizes and very large array sizes
7251
c305a0315bea use DeoptAction.None for array allocations with invalid length (very large or negative)
Lukas Stadler <lukas.stadler@jku.at>
parents: 7147
diff changeset
106 DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint);
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
107 }
10542
554f67e4ff3f Use slow-path stub call instead of deopt in lowering of DynamicNewArrayNode.
Roland Schatz <roland.schatz@oracle.com>
parents: 10456
diff changeset
108 return allocateArrayImpl(hub, length, prototypeMarkWord, headerSize, log2ElementSize, fillContents);
554f67e4ff3f Use slow-path stub call instead of deopt in lowering of DynamicNewArrayNode.
Roland Schatz <roland.schatz@oracle.com>
parents: 10456
diff changeset
109 }
9688
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
110
10542
554f67e4ff3f Use slow-path stub call instead of deopt in lowering of DynamicNewArrayNode.
Roland Schatz <roland.schatz@oracle.com>
parents: 10456
diff changeset
111 private static Object allocateArrayImpl(Word hub, int length, Word prototypeMarkWord, int headerSize, int log2ElementSize, boolean fillContents) {
9688
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
112 Object result;
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
113 int alignment = wordSize();
7147
88d626e2c2a8 added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents: 7145
diff changeset
114 int allocationSize = computeArrayAllocationSize(length, alignment, headerSize, log2ElementSize);
9688
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
115 Word thread = thread();
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
116 Word top = readTlabTop(thread);
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
117 Word end = readTlabEnd(thread);
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
118 Word newTop = top.add(allocationSize);
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
119 if (useTLAB() && probability(FAST_PATH_PROBABILITY, newTop.belowOrEqual(end))) {
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
120 writeTlabTop(thread, newTop);
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
121 newarray_loopInit.inc();
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
122 result = formatArray(hub, allocationSize, length, headerSize, top, prototypeMarkWord, fillContents);
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
123 } else {
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
124 newarray_stub.inc();
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
125 result = NewArrayStubCall.call(hub, length);
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
126 }
11752
7e7edb86fb43 Refactor the handling of unsafe casts to distinguish between word-object-conversions, PiNode-like type information, and real unsafe casts.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 11732
diff changeset
127 return piArrayCast(verifyOop(result), length, StampFactory.forNodeIntrinsic());
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
128 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
129
10586
110434bc2913 Remove unnecessary class.
Roland Schatz <roland.schatz@oracle.com>
parents: 10542
diff changeset
130 public static final ForeignCallDescriptor DYNAMIC_NEW_ARRAY = new ForeignCallDescriptor("dynamic_new_array", Object.class, Class.class, int.class);
110434bc2913 Remove unnecessary class.
Roland Schatz <roland.schatz@oracle.com>
parents: 10542
diff changeset
131
110434bc2913 Remove unnecessary class.
Roland Schatz <roland.schatz@oracle.com>
parents: 10542
diff changeset
132 @NodeIntrinsic(ForeignCallNode.class)
110434bc2913 Remove unnecessary class.
Roland Schatz <roland.schatz@oracle.com>
parents: 10542
diff changeset
133 public static native Object dynamicNewArrayStub(@ConstantNodeParameter ForeignCallDescriptor descriptor, Class<?> elementType, int length);
110434bc2913 Remove unnecessary class.
Roland Schatz <roland.schatz@oracle.com>
parents: 10542
diff changeset
134
10027
e561e0a6f727 DynamicNewArrayNode
Roland Schatz <roland.schatz@oracle.com>
parents: 9896
diff changeset
135 @Snippet
e561e0a6f727 DynamicNewArrayNode
Roland Schatz <roland.schatz@oracle.com>
parents: 9896
diff changeset
136 public static Object allocateArrayDynamic(Class<?> elementType, int length, @ConstantParameter boolean fillContents) {
e561e0a6f727 DynamicNewArrayNode
Roland Schatz <roland.schatz@oracle.com>
parents: 9896
diff changeset
137 Word hub = loadWordFromObject(elementType, arrayKlassOffset());
10542
554f67e4ff3f Use slow-path stub call instead of deopt in lowering of DynamicNewArrayNode.
Roland Schatz <roland.schatz@oracle.com>
parents: 10456
diff changeset
138 if (hub.equal(Word.zero()) || !belowThan(length, MAX_ARRAY_FAST_PATH_ALLOCATION_LENGTH)) {
10586
110434bc2913 Remove unnecessary class.
Roland Schatz <roland.schatz@oracle.com>
parents: 10542
diff changeset
139 return dynamicNewArrayStub(DYNAMIC_NEW_ARRAY, elementType, length);
10027
e561e0a6f727 DynamicNewArrayNode
Roland Schatz <roland.schatz@oracle.com>
parents: 9896
diff changeset
140 }
e561e0a6f727 DynamicNewArrayNode
Roland Schatz <roland.schatz@oracle.com>
parents: 9896
diff changeset
141
e561e0a6f727 DynamicNewArrayNode
Roland Schatz <roland.schatz@oracle.com>
parents: 9896
diff changeset
142 int layoutHelper = readLayoutHelper(hub);
e561e0a6f727 DynamicNewArrayNode
Roland Schatz <roland.schatz@oracle.com>
parents: 9896
diff changeset
143 //@formatter:off
10427
58777dad7f90 Cite source of comment in NewObjectSnippets.
Roland Schatz <roland.schatz@oracle.com>
parents: 10030
diff changeset
144 // from src/share/vm/oops/klass.hpp:
58777dad7f90 Cite source of comment in NewObjectSnippets.
Roland Schatz <roland.schatz@oracle.com>
parents: 10030
diff changeset
145 //
10027
e561e0a6f727 DynamicNewArrayNode
Roland Schatz <roland.schatz@oracle.com>
parents: 9896
diff changeset
146 // For arrays, layout helper is a negative number, containing four
e561e0a6f727 DynamicNewArrayNode
Roland Schatz <roland.schatz@oracle.com>
parents: 9896
diff changeset
147 // distinct bytes, as follows:
e561e0a6f727 DynamicNewArrayNode
Roland Schatz <roland.schatz@oracle.com>
parents: 9896
diff changeset
148 // MSB:[tag, hsz, ebt, log2(esz)]:LSB
e561e0a6f727 DynamicNewArrayNode
Roland Schatz <roland.schatz@oracle.com>
parents: 9896
diff changeset
149 // where:
e561e0a6f727 DynamicNewArrayNode
Roland Schatz <roland.schatz@oracle.com>
parents: 9896
diff changeset
150 // tag is 0x80 if the elements are oops, 0xC0 if non-oops
e561e0a6f727 DynamicNewArrayNode
Roland Schatz <roland.schatz@oracle.com>
parents: 9896
diff changeset
151 // hsz is array header size in bytes (i.e., offset of first element)
e561e0a6f727 DynamicNewArrayNode
Roland Schatz <roland.schatz@oracle.com>
parents: 9896
diff changeset
152 // ebt is the BasicType of the elements
e561e0a6f727 DynamicNewArrayNode
Roland Schatz <roland.schatz@oracle.com>
parents: 9896
diff changeset
153 // esz is the element size in bytes
e561e0a6f727 DynamicNewArrayNode
Roland Schatz <roland.schatz@oracle.com>
parents: 9896
diff changeset
154 //@formatter:on
e561e0a6f727 DynamicNewArrayNode
Roland Schatz <roland.schatz@oracle.com>
parents: 9896
diff changeset
155
10456
e4dd840a39de Use values from HotSpotVMConfig instead of hardcoding shifts and bitmasks.
Roland Schatz <roland.schatz@oracle.com>
parents: 10442
diff changeset
156 int headerSize = (layoutHelper >> layoutHelperHeaderSizeShift()) & layoutHelperHeaderSizeMask();
e4dd840a39de Use values from HotSpotVMConfig instead of hardcoding shifts and bitmasks.
Roland Schatz <roland.schatz@oracle.com>
parents: 10442
diff changeset
157 int log2ElementSize = (layoutHelper >> layoutHelperLog2ElementSizeShift()) & layoutHelperLog2ElementSizeMask();
10027
e561e0a6f727 DynamicNewArrayNode
Roland Schatz <roland.schatz@oracle.com>
parents: 9896
diff changeset
158 Word prototypeMarkWord = hub.readWord(prototypeMarkWordOffset(), PROTOTYPE_MARK_WORD_LOCATION);
e561e0a6f727 DynamicNewArrayNode
Roland Schatz <roland.schatz@oracle.com>
parents: 9896
diff changeset
159
10542
554f67e4ff3f Use slow-path stub call instead of deopt in lowering of DynamicNewArrayNode.
Roland Schatz <roland.schatz@oracle.com>
parents: 10456
diff changeset
160 return allocateArrayImpl(hub, length, prototypeMarkWord, headerSize, log2ElementSize, fillContents);
10027
e561e0a6f727 DynamicNewArrayNode
Roland Schatz <roland.schatz@oracle.com>
parents: 9896
diff changeset
161 }
e561e0a6f727 DynamicNewArrayNode
Roland Schatz <roland.schatz@oracle.com>
parents: 9896
diff changeset
162
7147
88d626e2c2a8 added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents: 7145
diff changeset
163 /**
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
164 * Computes the size of the memory chunk allocated for an array. This size accounts for the
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
165 * array header size, boy size and any padding after the last element to satisfy object
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
166 * alignment requirements.
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
167 *
7147
88d626e2c2a8 added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents: 7145
diff changeset
168 * @param length the number of elements in the array
88d626e2c2a8 added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents: 7145
diff changeset
169 * @param alignment the object alignment requirement
88d626e2c2a8 added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents: 7145
diff changeset
170 * @param headerSize the size of the array header
88d626e2c2a8 added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents: 7145
diff changeset
171 * @param log2ElementSize log2 of the size of an element in the array
88d626e2c2a8 added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents: 7145
diff changeset
172 */
88d626e2c2a8 added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents: 7145
diff changeset
173 public static int computeArrayAllocationSize(int length, int alignment, int headerSize, int log2ElementSize) {
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
174 int size = (length << log2ElementSize) + headerSize + (alignment - 1);
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
175 int mask = ~(alignment - 1);
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
176 return size & mask;
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
177 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
178
5563
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
179 /**
6431
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
180 * Calls the runtime stub for implementing MULTIANEWARRAY.
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
181 */
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
182 @Snippet
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
183 public static Object newmultiarray(Word hub, @ConstantParameter int rank, @VarargsParameter int[] dimensions) {
6954
0e20ad1ea98b removed WordStamp (and a nasty bug associated with its misusage)
Doug Simon <doug.simon@oracle.com>
parents: 6950
diff changeset
184 Word dims = DimensionsNode.allocaDimsArray(rank);
6431
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
185 ExplodeLoopNode.explodeLoop();
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
186 for (int i = 0; i < rank; i++) {
7868
7a5bbcc36bb2 add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7701
diff changeset
187 dims.writeInt(i * 4, dimensions[i], ANY_LOCATION);
6431
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
188 }
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
189 return NewMultiArrayStubCall.call(hub, rank, dims);
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
190 }
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
191
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
192 /**
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
193 * Maximum size of an object whose body is initialized by a sequence of zero-stores to its
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
194 * fields. Larger objects have their bodies initialized in a loop.
5687
5d06e32f10df limited length of zeroing instructions for object initialization to object below a certain size
Doug Simon <doug.simon@oracle.com>
parents: 5686
diff changeset
195 */
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
196 private static final int MAX_UNROLLED_OBJECT_ZEROING_SIZE = 10 * wordSize();
5687
5d06e32f10df limited length of zeroing instructions for object initialization to object below a certain size
Doug Simon <doug.simon@oracle.com>
parents: 5686
diff changeset
197
5d06e32f10df limited length of zeroing instructions for object initialization to object below a certain size
Doug Simon <doug.simon@oracle.com>
parents: 5686
diff changeset
198 /**
5683
0ca242de9383 improved type stamp for value flowing out of a lowered NEW bytecode instruction
Doug Simon <doug.simon@oracle.com>
parents: 5679
diff changeset
199 * Formats some allocated memory with an object header zeroes out the rest.
5563
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
200 */
9688
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
201 private static Object formatObject(Word hub, int size, Word memory, Word compileTimePrototypeMarkWord, boolean fillContents) {
7868
7a5bbcc36bb2 add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7701
diff changeset
202 Word prototypeMarkWord = useBiasedLocking() ? hub.readWord(prototypeMarkWordOffset(), PROTOTYPE_MARK_WORD_LOCATION) : compileTimePrototypeMarkWord;
7a5bbcc36bb2 add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7701
diff changeset
203 initializeObjectHeader(memory, prototypeMarkWord, hub);
6355
892d3c82febe add support for fillConents to NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 6328
diff changeset
204 if (fillContents) {
892d3c82febe add support for fillConents to NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 6328
diff changeset
205 if (size <= MAX_UNROLLED_OBJECT_ZEROING_SIZE) {
892d3c82febe add support for fillConents to NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 6328
diff changeset
206 new_seqInit.inc();
892d3c82febe add support for fillConents to NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 6328
diff changeset
207 explodeLoop();
10745
cbaf26740df8 Method renaming
Christos Kotselidis <christos.kotselidis@oracle.com>
parents: 10717
diff changeset
208 for (int offset = instanceHeaderSize(); offset < size; offset += wordSize()) {
11770
7c4595b7ef3a NewInstanceNode: use INIT_LOCATION; NewArrayNode: use INIT_LOCATION and ARRAY_LENGTH_LOCATION
Bernhard Urban <bernhard.urban@jku.at>
parents: 11752
diff changeset
209 memory.writeWord(offset, Word.zero(), INIT_LOCATION);
6355
892d3c82febe add support for fillConents to NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 6328
diff changeset
210 }
892d3c82febe add support for fillConents to NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 6328
diff changeset
211 } else {
892d3c82febe add support for fillConents to NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 6328
diff changeset
212 new_loopInit.inc();
10745
cbaf26740df8 Method renaming
Christos Kotselidis <christos.kotselidis@oracle.com>
parents: 10717
diff changeset
213 for (int offset = instanceHeaderSize(); offset < size; offset += wordSize()) {
11770
7c4595b7ef3a NewInstanceNode: use INIT_LOCATION; NewArrayNode: use INIT_LOCATION and ARRAY_LENGTH_LOCATION
Bernhard Urban <bernhard.urban@jku.at>
parents: 11752
diff changeset
214 memory.writeWord(offset, Word.zero(), INIT_LOCATION);
6355
892d3c82febe add support for fillConents to NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 6328
diff changeset
215 }
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
216 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
217 }
9688
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
218 return memory.toObject();
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
219 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
220
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
221 /**
9688
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
222 * Formats some allocated memory with an object header and zeroes out the rest.
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
223 */
9688
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
224 public static Object formatArray(Word hub, int allocationSize, int length, int headerSize, Word memory, Word prototypeMarkWord, boolean fillContents) {
11770
7c4595b7ef3a NewInstanceNode: use INIT_LOCATION; NewArrayNode: use INIT_LOCATION and ARRAY_LENGTH_LOCATION
Bernhard Urban <bernhard.urban@jku.at>
parents: 11752
diff changeset
225 memory.writeInt(arrayLengthOffset(), length, ARRAY_LENGTH_LOCATION);
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
226 /*
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
227 * store hub last as the concurrent garbage collectors assume length is valid if hub field
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
228 * is not null
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
229 */
7868
7a5bbcc36bb2 add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7701
diff changeset
230 initializeObjectHeader(memory, prototypeMarkWord, hub);
6355
892d3c82febe add support for fillConents to NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 6328
diff changeset
231 if (fillContents) {
7147
88d626e2c2a8 added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents: 7145
diff changeset
232 for (int offset = headerSize; offset < allocationSize; offset += wordSize()) {
11770
7c4595b7ef3a NewInstanceNode: use INIT_LOCATION; NewArrayNode: use INIT_LOCATION and ARRAY_LENGTH_LOCATION
Bernhard Urban <bernhard.urban@jku.at>
parents: 11752
diff changeset
233 memory.writeWord(offset, Word.zero(), INIT_LOCATION);
6355
892d3c82febe add support for fillConents to NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 6328
diff changeset
234 }
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
235 }
9688
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
236 return memory.toObject();
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
237 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
238
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
239 public static class Templates extends AbstractTemplates {
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
240
9688
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
241 private final SnippetInfo allocateInstance = snippet(NewObjectSnippets.class, "allocateInstance");
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
242 private final SnippetInfo allocateArray = snippet(NewObjectSnippets.class, "allocateArray");
10027
e561e0a6f727 DynamicNewArrayNode
Roland Schatz <roland.schatz@oracle.com>
parents: 9896
diff changeset
243 private final SnippetInfo allocateArrayDynamic = snippet(NewObjectSnippets.class, "allocateArrayDynamic");
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
244 private final SnippetInfo newmultiarray = snippet(NewObjectSnippets.class, "newmultiarray");
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
245
9688
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
246 public Templates(CodeCacheProvider runtime, Replacements replacements, TargetDescription target) {
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
247 super(runtime, replacements, target);
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
248 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
249
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
250 /**
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
251 * Lowers a {@link NewInstanceNode}.
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
252 */
9688
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
253 public void lower(NewInstanceNode newInstanceNode) {
9602
19c5a07c7843 Introduce a graph() method that returns a StructuredGraph, to make many explicit casts unnecessary
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9516
diff changeset
254 StructuredGraph graph = newInstanceNode.graph();
7084
9ba90252ce08 HotSpotResolvedJavaType is now the HotSpot implementation of ResolvedJavaType,
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7081
diff changeset
255 HotSpotResolvedObjectType type = (HotSpotResolvedObjectType) newInstanceNode.instanceClass();
9688
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
256 assert !type.isArray();
6950
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6568
diff changeset
257 ConstantNode hub = ConstantNode.forConstant(type.klass(), runtime, graph);
7544
5d9c23b8dbb8 factored out common code in NewObjectSnippets
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
258 int size = instanceSize(type);
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
259
11732
03c781923573 made snippet and substitution graphs lower themselves before being inlined
Doug Simon <doug.simon@oracle.com>
parents: 11348
diff changeset
260 Arguments args = new Arguments(allocateInstance, graph.getGuardsStage());
9688
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
261 args.addConst("size", size);
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
262 args.add("hub", hub);
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
263 args.add("prototypeMarkWord", type.prototypeMarkWord());
10760
59d2d6a30d29 Re-enable omission of array initialization for G1.
Roland Schatz <roland.schatz@oracle.com>
parents: 10745
diff changeset
264 args.addConst("fillContents", newInstanceNode.fillContents());
9688
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
265
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
266 SnippetTemplate template = template(args);
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
267 Debug.log("Lowering allocateInstance in %s: node=%s, template=%s, arguments=%s", graph, newInstanceNode, template, args);
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
268 template.instantiate(runtime, newInstanceNode, DEFAULT_REPLACER, args);
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
269 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
270
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
271 /**
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
272 * Lowers a {@link NewArrayNode}.
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
273 */
9688
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
274 public void lower(NewArrayNode newArrayNode) {
9602
19c5a07c7843 Introduce a graph() method that returns a StructuredGraph, to make many explicit casts unnecessary
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9516
diff changeset
275 StructuredGraph graph = newArrayNode.graph();
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
276 ResolvedJavaType elementType = newArrayNode.elementType();
9688
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
277 HotSpotResolvedObjectType arrayType = (HotSpotResolvedObjectType) elementType.getArrayClass();
6539
2463eb24b644 Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6525
diff changeset
278 Kind elementKind = elementType.getKind();
9688
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
279 ConstantNode hub = ConstantNode.forConstant(arrayType.klass(), runtime, graph);
7099
3656236c7d27 Cleanup of Kind class: remove use of Unsafe class
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7098
diff changeset
280 final int headerSize = HotSpotRuntime.getArrayBaseOffset(elementKind);
9893
b132d7666ac8 Fix Check style error
Christos Kotselidis <christos.kotselidis@oracle.com>
parents: 9884
diff changeset
281 int log2ElementSize = CodeUtil.log2(((HotSpotRuntime) runtime).getScalingFactor(elementKind));
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
282
11732
03c781923573 made snippet and substitution graphs lower themselves before being inlined
Doug Simon <doug.simon@oracle.com>
parents: 11348
diff changeset
283 Arguments args = new Arguments(allocateArray, graph.getGuardsStage());
9688
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
284 args.add("hub", hub);
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
285 args.add("length", newArrayNode.length());
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
286 args.add("prototypeMarkWord", arrayType.prototypeMarkWord());
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
287 args.addConst("headerSize", headerSize);
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
288 args.addConst("log2ElementSize", log2ElementSize);
10760
59d2d6a30d29 Re-enable omission of array initialization for G1.
Roland Schatz <roland.schatz@oracle.com>
parents: 10745
diff changeset
289 args.addConst("fillContents", newArrayNode.fillContents());
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
290
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
291 SnippetTemplate template = template(args);
9688
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
292 Debug.log("Lowering allocateArray in %s: node=%s, template=%s, arguments=%s", graph, newArrayNode, template, args);
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
293 template.instantiate(runtime, newArrayNode, DEFAULT_REPLACER, args);
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
294 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
295
10027
e561e0a6f727 DynamicNewArrayNode
Roland Schatz <roland.schatz@oracle.com>
parents: 9896
diff changeset
296 public void lower(DynamicNewArrayNode newArrayNode) {
11732
03c781923573 made snippet and substitution graphs lower themselves before being inlined
Doug Simon <doug.simon@oracle.com>
parents: 11348
diff changeset
297 Arguments args = new Arguments(allocateArrayDynamic, newArrayNode.graph().getGuardsStage());
10027
e561e0a6f727 DynamicNewArrayNode
Roland Schatz <roland.schatz@oracle.com>
parents: 9896
diff changeset
298 args.add("elementType", newArrayNode.getElementType());
e561e0a6f727 DynamicNewArrayNode
Roland Schatz <roland.schatz@oracle.com>
parents: 9896
diff changeset
299 args.add("length", newArrayNode.length());
10760
59d2d6a30d29 Re-enable omission of array initialization for G1.
Roland Schatz <roland.schatz@oracle.com>
parents: 10745
diff changeset
300 args.addConst("fillContents", newArrayNode.fillContents());
10027
e561e0a6f727 DynamicNewArrayNode
Roland Schatz <roland.schatz@oracle.com>
parents: 9896
diff changeset
301
e561e0a6f727 DynamicNewArrayNode
Roland Schatz <roland.schatz@oracle.com>
parents: 9896
diff changeset
302 SnippetTemplate template = template(args);
e561e0a6f727 DynamicNewArrayNode
Roland Schatz <roland.schatz@oracle.com>
parents: 9896
diff changeset
303 template.instantiate(runtime, newArrayNode, DEFAULT_REPLACER, args);
e561e0a6f727 DynamicNewArrayNode
Roland Schatz <roland.schatz@oracle.com>
parents: 9896
diff changeset
304 }
e561e0a6f727 DynamicNewArrayNode
Roland Schatz <roland.schatz@oracle.com>
parents: 9896
diff changeset
305
9688
0d0645267c32 simplify NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 9602
diff changeset
306 public void lower(NewMultiArrayNode newmultiarrayNode) {
9602
19c5a07c7843 Introduce a graph() method that returns a StructuredGraph, to make many explicit casts unnecessary
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9516
diff changeset
307 StructuredGraph graph = newmultiarrayNode.graph();
6431
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
308 int rank = newmultiarrayNode.dimensionCount();
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
309 ValueNode[] dims = new ValueNode[rank];
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
310 for (int i = 0; i < newmultiarrayNode.dimensionCount(); i++) {
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
311 dims[i] = newmultiarrayNode.dimension(i);
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
312 }
7084
9ba90252ce08 HotSpotResolvedJavaType is now the HotSpot implementation of ResolvedJavaType,
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7081
diff changeset
313 HotSpotResolvedObjectType type = (HotSpotResolvedObjectType) newmultiarrayNode.type();
6950
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6568
diff changeset
314 ConstantNode hub = ConstantNode.forConstant(type.klass(), runtime, graph);
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
315
11732
03c781923573 made snippet and substitution graphs lower themselves before being inlined
Doug Simon <doug.simon@oracle.com>
parents: 11348
diff changeset
316 Arguments args = new Arguments(newmultiarray, graph.getGuardsStage());
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
317 args.add("hub", hub);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
318 args.addConst("rank", rank);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
319 args.addVarargs("dimensions", int.class, StampFactory.forKind(Kind.Int), dims);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
320 template(args).instantiate(runtime, newmultiarrayNode, DEFAULT_REPLACER, args);
6431
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
321 }
7544
5d9c23b8dbb8 factored out common code in NewObjectSnippets
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
322
5d9c23b8dbb8 factored out common code in NewObjectSnippets
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
323 private static int instanceSize(HotSpotResolvedObjectType type) {
5d9c23b8dbb8 factored out common code in NewObjectSnippets
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
324 int size = type.instanceSize();
5d9c23b8dbb8 factored out common code in NewObjectSnippets
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
325 assert (size % wordSize()) == 0;
5d9c23b8dbb8 factored out common code in NewObjectSnippets
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
326 assert size >= 0;
5d9c23b8dbb8 factored out common code in NewObjectSnippets
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
327 return size;
5d9c23b8dbb8 factored out common code in NewObjectSnippets
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
328 }
5563
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
329 }
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
330
9864
063a712fe8d8 converted remaining options in GraalOptions to new system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 9793
diff changeset
331 private static final SnippetCounter.Group countersNew = SnippetCounters.getValue() ? new SnippetCounter.Group("NewInstance") : null;
5772
2f7a03583a32 added counters for code paths through the new object snippets
Doug Simon <doug.simon@oracle.com>
parents: 5770
diff changeset
332 private static final SnippetCounter new_seqInit = new SnippetCounter(countersNew, "tlabSeqInit", "TLAB alloc with unrolled zeroing");
2f7a03583a32 added counters for code paths through the new object snippets
Doug Simon <doug.simon@oracle.com>
parents: 5770
diff changeset
333 private static final SnippetCounter new_loopInit = new SnippetCounter(countersNew, "tlabLoopInit", "TLAB alloc with zeroing in a loop");
2f7a03583a32 added counters for code paths through the new object snippets
Doug Simon <doug.simon@oracle.com>
parents: 5770
diff changeset
334 private static final SnippetCounter new_stub = new SnippetCounter(countersNew, "stub", "alloc and zeroing via stub");
2f7a03583a32 added counters for code paths through the new object snippets
Doug Simon <doug.simon@oracle.com>
parents: 5770
diff changeset
335
9864
063a712fe8d8 converted remaining options in GraalOptions to new system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 9793
diff changeset
336 private static final SnippetCounter.Group countersNewArray = SnippetCounters.getValue() ? new SnippetCounter.Group("NewArray") : null;
7145
6c46172c04bf consolidated new_type_array and new_object_array stubs into one as there no difference between them
Doug Simon <doug.simon@oracle.com>
parents: 7143
diff changeset
337 private static final SnippetCounter newarray_loopInit = new SnippetCounter(countersNewArray, "tlabLoopInit", "TLAB alloc with zeroing in a loop");
6c46172c04bf consolidated new_type_array and new_object_array stubs into one as there no difference between them
Doug Simon <doug.simon@oracle.com>
parents: 7143
diff changeset
338 private static final SnippetCounter newarray_stub = new SnippetCounter(countersNewArray, "stub", "alloc and zeroing via stub");
5563
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
339 }