annotate graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/NewObjectSnippets.java @ 9015:92d2bedb5dfc

Change of Snippet template and instantiation process
author Christian Wimmer <christian.wimmer@oracle.com>
date Thu, 11 Apr 2013 14:22:03 -0700
parents 9f56bb503db4
children 5e1465ec46d6
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.*;
8415
2361bf148c06 rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents: 8413
diff changeset
26 import static com.oracle.graal.hotspot.replacements.HotSpotSnippetUtils.*;
7035
52c88c405d07 Simplify how stamp is preserved after lowering of allocation nodes
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7034
diff changeset
27 import static com.oracle.graal.nodes.extended.UnsafeArrayCastNode.*;
52c88c405d07 Simplify how stamp is preserved after lowering of allocation nodes
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7034
diff changeset
28 import static com.oracle.graal.nodes.extended.UnsafeCastNode.*;
8415
2361bf148c06 rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents: 8413
diff changeset
29 import static com.oracle.graal.replacements.SnippetTemplate.*;
2361bf148c06 rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents: 8413
diff changeset
30 import static com.oracle.graal.replacements.nodes.BranchProbabilityNode.*;
2361bf148c06 rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents: 8413
diff changeset
31 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
32
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
33 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
34 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
35 import com.oracle.graal.debug.*;
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
36 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
37 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
38 import com.oracle.graal.nodes.*;
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
39 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
40 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
41 import com.oracle.graal.nodes.type.*;
6525
2c913b643422 rename packages in graal.phases to match project name
Doug Simon <doug.simon@oracle.com>
parents: 6511
diff changeset
42 import com.oracle.graal.phases.*;
8415
2361bf148c06 rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents: 8413
diff changeset
43 import com.oracle.graal.replacements.*;
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
44 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
45 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
46 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
47 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
48 import com.oracle.graal.replacements.SnippetTemplate.SnippetInfo;
8415
2361bf148c06 rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents: 8413
diff changeset
49 import com.oracle.graal.replacements.nodes.*;
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7275
diff changeset
50 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
51
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
52 /**
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
53 * 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
54 */
8413
d9347ee39fbe rename: SnippetsInterface -> Snippets
Doug Simon <doug.simon@oracle.com>
parents: 7868
diff changeset
55 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
56
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
57 @Snippet
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
58 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
59 Word thread = thread();
7868
7a5bbcc36bb2 add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7701
diff changeset
60 Word top = readTlabTop(thread);
7a5bbcc36bb2 add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7701
diff changeset
61 Word end = readTlabEnd(thread);
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7275
diff changeset
62 Word newTop = top.add(size);
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
63 /*
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
64 * 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
65 * (checked in c++ code)
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
66 */
7115
1c76a458616e simplified TLAB allocation (don't use + and -)
Lukas Stadler <lukas.stadler@jku.at>
parents: 7105
diff changeset
67 if (newTop.belowOrEqual(end)) {
7554
9472211c812b named constants for snippet probabilities (likely, frequent, fast_path, deopt), see CR-7
Lukas Stadler <lukas.stadler@jku.at>
parents: 7544
diff changeset
68 probability(FAST_PATH_PROBABILITY);
7868
7a5bbcc36bb2 add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7701
diff changeset
69 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
70 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
71 }
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
72 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
73 }
5587
bf4f499cc538 added allocation logging to NewInstanceSnippets
Doug Simon <doug.simon@oracle.com>
parents: 5576
diff changeset
74
5563
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
75 @Snippet
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
76 public static Object initializeObject(Word memory, Word hub, Word prototypeMarkWord, @ConstantParameter int size, @ConstantParameter boolean fillContents, @ConstantParameter boolean locked) {
5602
e79b593e0632 made NewInstanceSnippets respect the UseTLAB HotSpot option
Doug Simon <doug.simon@oracle.com>
parents: 5594
diff changeset
77
7035
52c88c405d07 Simplify how stamp is preserved after lowering of allocation nodes
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7034
diff changeset
78 Object result;
7701
47467b2c3fc5 Use equal() and notEqual() instead of == and != to compare words
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7554
diff changeset
79 if (memory.equal(0)) {
5772
2f7a03583a32 added counters for code paths through the new object snippets
Doug Simon <doug.simon@oracle.com>
parents: 5770
diff changeset
80 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
81 result = NewInstanceStubCall.call(hub);
6511
0b62a9d44c21 add infrastructure for creating locked objects
Lukas Stadler <lukas.stadler@jku.at>
parents: 6504
diff changeset
82 } else {
7554
9472211c812b named constants for snippet probabilities (likely, frequent, fast_path, deopt), see CR-7
Lukas Stadler <lukas.stadler@jku.at>
parents: 7544
diff changeset
83 probability(FAST_PATH_PROBABILITY);
7035
52c88c405d07 Simplify how stamp is preserved after lowering of allocation nodes
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7034
diff changeset
84 if (locked) {
52c88c405d07 Simplify how stamp is preserved after lowering of allocation nodes
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7034
diff changeset
85 formatObject(hub, size, memory, thread().or(biasedLockPattern()), fillContents);
52c88c405d07 Simplify how stamp is preserved after lowering of allocation nodes
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7034
diff changeset
86 } else {
52c88c405d07 Simplify how stamp is preserved after lowering of allocation nodes
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7034
diff changeset
87 formatObject(hub, size, memory, prototypeMarkWord, fillContents);
52c88c405d07 Simplify how stamp is preserved after lowering of allocation nodes
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7034
diff changeset
88 }
52c88c405d07 Simplify how stamp is preserved after lowering of allocation nodes
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7034
diff changeset
89 result = memory.toObject();
6511
0b62a9d44c21 add infrastructure for creating locked objects
Lukas Stadler <lukas.stadler@jku.at>
parents: 6504
diff changeset
90 }
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
91 /*
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
92 * make sure that the unsafeCast is anchored after initialization, see ReadAfterCheckCast
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
93 * and CheckCastSnippets
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
94 */
8897
1a8a0375ba74 unsafeCast: anchor cast after initialization of an object
Bernhard Urban <bernhard.urban@jku.at>
parents: 8637
diff changeset
95 BeginNode anchorNode = BeginNode.anchor(StampFactory.forNodeIntrinsic());
1a8a0375ba74 unsafeCast: anchor cast after initialization of an object
Bernhard Urban <bernhard.urban@jku.at>
parents: 8637
diff changeset
96 return unsafeCast(verifyOop(result), StampFactory.forNodeIntrinsic(), anchorNode);
5624
7d25723b7699 added oop verification to NewInstanceSnippets when -XX:+VerifyOops is enabled
Doug Simon <doug.simon@oracle.com>
parents: 5616
diff changeset
97 }
7d25723b7699 added oop verification to NewInstanceSnippets when -XX:+VerifyOops is enabled
Doug Simon <doug.simon@oracle.com>
parents: 5616
diff changeset
98
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
99 @Snippet
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
100 public static Object initializeArray(Word memory, Word hub, int length, int allocationSize, Word prototypeMarkWord, @ConstantParameter int headerSize, @ConstantParameter boolean fillContents,
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
101 @ConstantParameter boolean locked) {
6511
0b62a9d44c21 add infrastructure for creating locked objects
Lukas Stadler <lukas.stadler@jku.at>
parents: 6504
diff changeset
102 if (locked) {
7147
88d626e2c2a8 added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents: 7145
diff changeset
103 return initializeArray(memory, hub, length, allocationSize, thread().or(biasedLockPattern()), headerSize, fillContents);
6511
0b62a9d44c21 add infrastructure for creating locked objects
Lukas Stadler <lukas.stadler@jku.at>
parents: 6504
diff changeset
104 } else {
7147
88d626e2c2a8 added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents: 7145
diff changeset
105 return initializeArray(memory, hub, length, allocationSize, prototypeMarkWord, headerSize, fillContents);
6511
0b62a9d44c21 add infrastructure for creating locked objects
Lukas Stadler <lukas.stadler@jku.at>
parents: 6504
diff changeset
106 }
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
107 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
108
7147
88d626e2c2a8 added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents: 7145
diff changeset
109 private static Object initializeArray(Word memory, Word hub, int length, int allocationSize, Word prototypeMarkWord, int headerSize, boolean fillContents) {
7035
52c88c405d07 Simplify how stamp is preserved after lowering of allocation nodes
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7034
diff changeset
110 Object result;
7701
47467b2c3fc5 Use equal() and notEqual() instead of == and != to compare words
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7554
diff changeset
111 if (memory.equal(0)) {
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
112 newarray_stub.inc();
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
113 result = NewArrayStubCall.call(hub, length);
5772
2f7a03583a32 added counters for code paths through the new object snippets
Doug Simon <doug.simon@oracle.com>
parents: 5770
diff changeset
114 } else {
7554
9472211c812b named constants for snippet probabilities (likely, frequent, fast_path, deopt), see CR-7
Lukas Stadler <lukas.stadler@jku.at>
parents: 7544
diff changeset
115 probability(FAST_PATH_PROBABILITY);
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
116 newarray_loopInit.inc();
7147
88d626e2c2a8 added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents: 7145
diff changeset
117 formatArray(hub, allocationSize, length, headerSize, memory, prototypeMarkWord, fillContents);
7035
52c88c405d07 Simplify how stamp is preserved after lowering of allocation nodes
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7034
diff changeset
118 result = memory.toObject();
5772
2f7a03583a32 added counters for code paths through the new object snippets
Doug Simon <doug.simon@oracle.com>
parents: 5770
diff changeset
119 }
8898
9f56bb503db4 unsafeArrayCast: anchor cast after initialization of an array
Bernhard Urban <bernhard.urban@jku.at>
parents: 8897
diff changeset
120 BeginNode anchorNode = BeginNode.anchor(StampFactory.forNodeIntrinsic());
9f56bb503db4 unsafeArrayCast: anchor cast after initialization of an array
Bernhard Urban <bernhard.urban@jku.at>
parents: 8897
diff changeset
121 return unsafeArrayCast(verifyOop(result), length, StampFactory.forNodeIntrinsic(), anchorNode);
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
122 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
123
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
124 /**
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
125 * 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
126 */
7147
88d626e2c2a8 added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents: 7145
diff changeset
127 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
128
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
129 @Snippet
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
130 public static Object allocateArrayAndInitialize(int length, @ConstantParameter int alignment, @ConstantParameter int headerSize, @ConstantParameter int log2ElementSize,
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
131 @ConstantParameter boolean fillContents, @ConstantParameter ResolvedJavaType type) {
5763
a3d71693e0ce removed bytecode disassembly from CodeCacheRuntime into separate BytecodeDisassembler class
Doug Simon <doug.simon@oracle.com>
parents: 5760
diff changeset
132 if (!belowThan(length, MAX_ARRAY_FAST_PATH_ALLOCATION_LENGTH)) {
7554
9472211c812b named constants for snippet probabilities (likely, frequent, fast_path, deopt), see CR-7
Lukas Stadler <lukas.stadler@jku.at>
parents: 7544
diff changeset
133 probability(DEOPT_PATH_PROBABILITY);
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
134 // 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
135 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
136 }
7147
88d626e2c2a8 added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents: 7145
diff changeset
137 int allocationSize = computeArrayAllocationSize(length, alignment, headerSize, log2ElementSize);
88d626e2c2a8 added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents: 7145
diff changeset
138 Word memory = TLABAllocateNode.allocateVariableSize(allocationSize);
8562
fc0d57b82c86 Propagate fillContents to allocateArrayAndInitialize snippet.
Roland Schatz <roland.schatz@oracle.com>
parents: 8508
diff changeset
139 return InitializeArrayNode.initialize(memory, length, allocationSize, type, fillContents, false);
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
140 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
141
7147
88d626e2c2a8 added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents: 7145
diff changeset
142 /**
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
143 * 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
144 * 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
145 * alignment requirements.
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
146 *
7147
88d626e2c2a8 added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents: 7145
diff changeset
147 * @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
148 * @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
149 * @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
150 * @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
151 */
88d626e2c2a8 added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents: 7145
diff changeset
152 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
153 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
154 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
155 return size & mask;
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
156 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
157
5563
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
158 /**
6431
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
159 * Calls the runtime stub for implementing MULTIANEWARRAY.
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
160 */
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
161 @Snippet
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
162 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
163 Word dims = DimensionsNode.allocaDimsArray(rank);
6431
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
164 ExplodeLoopNode.explodeLoop();
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
165 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
166 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
167 }
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
168 return NewMultiArrayStubCall.call(hub, rank, dims);
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
169 }
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
170
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
171 /**
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
172 * 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
173 * 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
174 */
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
175 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
176
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
177 /**
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
178 * 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
179 */
6950
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6568
diff changeset
180 private static void 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
181 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
182 initializeObjectHeader(memory, prototypeMarkWord, hub);
6355
892d3c82febe add support for fillConents to NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 6328
diff changeset
183 if (fillContents) {
892d3c82febe add support for fillConents to NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 6328
diff changeset
184 if (size <= MAX_UNROLLED_OBJECT_ZEROING_SIZE) {
892d3c82febe add support for fillConents to NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 6328
diff changeset
185 new_seqInit.inc();
892d3c82febe add support for fillConents to NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 6328
diff changeset
186 explodeLoop();
892d3c82febe add support for fillConents to NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 6328
diff changeset
187 for (int offset = 2 * wordSize(); offset < size; offset += wordSize()) {
7868
7a5bbcc36bb2 add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7701
diff changeset
188 memory.writeWord(offset, Word.zero(), ANY_LOCATION);
6355
892d3c82febe add support for fillConents to NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 6328
diff changeset
189 }
892d3c82febe add support for fillConents to NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 6328
diff changeset
190 } else {
892d3c82febe add support for fillConents to NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 6328
diff changeset
191 new_loopInit.inc();
892d3c82febe add support for fillConents to NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 6328
diff changeset
192 for (int offset = 2 * wordSize(); offset < size; offset += wordSize()) {
7868
7a5bbcc36bb2 add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7701
diff changeset
193 memory.writeWord(offset, Word.zero(), ANY_LOCATION);
6355
892d3c82febe add support for fillConents to NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 6328
diff changeset
194 }
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
195 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
196 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
197 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
198
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
199 /**
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
200 * Formats some allocated memory with an object header zeroes out the rest.
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
201 */
7147
88d626e2c2a8 added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents: 7145
diff changeset
202 public static void formatArray(Word hub, int allocationSize, int length, int headerSize, Word memory, Word prototypeMarkWord, boolean fillContents) {
7868
7a5bbcc36bb2 add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7701
diff changeset
203 memory.writeInt(arrayLengthOffset(), length, ANY_LOCATION);
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
204 /*
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
205 * 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
206 * is not null
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
207 */
7868
7a5bbcc36bb2 add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7701
diff changeset
208 initializeObjectHeader(memory, prototypeMarkWord, hub);
6355
892d3c82febe add support for fillConents to NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 6328
diff changeset
209 if (fillContents) {
7147
88d626e2c2a8 added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents: 7145
diff changeset
210 for (int offset = headerSize; offset < allocationSize; offset += wordSize()) {
7868
7a5bbcc36bb2 add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7701
diff changeset
211 memory.writeWord(offset, Word.zero(), ANY_LOCATION);
6355
892d3c82febe add support for fillConents to NewObjectSnippets
Lukas Stadler <lukas.stadler@jku.at>
parents: 6328
diff changeset
212 }
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
213 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
214 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
215
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
216 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
217
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
218 private final SnippetInfo allocate = snippet(NewObjectSnippets.class, "allocate");
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
219 private final SnippetInfo initializeObject = snippet(NewObjectSnippets.class, "initializeObject");
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
220 private final SnippetInfo initializeArray = snippet(NewObjectSnippets.class, "initializeArray");
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
221 private final SnippetInfo allocateArrayAndInitialize = snippet(NewObjectSnippets.class, "allocateArrayAndInitialize");
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
222 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
223
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
224 private final boolean useTLAB;
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
225
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8604
diff changeset
226 public Templates(CodeCacheProvider runtime, Replacements replacements, TargetDescription target, boolean useTLAB) {
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
227 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
228 this.useTLAB = useTLAB;
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
229 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
230
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
231 /**
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
232 * 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
233 */
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
234 @SuppressWarnings("unused")
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
235 public void lower(NewInstanceNode newInstanceNode, LoweringTool tool) {
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
236 StructuredGraph graph = (StructuredGraph) newInstanceNode.graph();
7084
9ba90252ce08 HotSpotResolvedJavaType is now the HotSpot implementation of ResolvedJavaType,
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7081
diff changeset
237 HotSpotResolvedObjectType type = (HotSpotResolvedObjectType) newInstanceNode.instanceClass();
6950
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6568
diff changeset
238 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
239 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
240
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
241 ValueNode memory;
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
242 if (!useTLAB) {
7105
f1f32b695d1e Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7099
diff changeset
243 memory = ConstantNode.defaultForKind(target.wordKind, graph);
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
244 } else {
5805
013081f7771b consolidated 2 separate size fields in TLABAllocate into 1
Doug Simon <doug.simon@oracle.com>
parents: 5772
diff changeset
245 ConstantNode sizeNode = ConstantNode.forInt(size, graph);
6954
0e20ad1ea98b removed WordStamp (and a nasty bug associated with its misusage)
Doug Simon <doug.simon@oracle.com>
parents: 6950
diff changeset
246 TLABAllocateNode tlabAllocateNode = graph.add(new TLABAllocateNode(sizeNode));
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
247 graph.addBeforeFixed(newInstanceNode, tlabAllocateNode);
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
248 memory = tlabAllocateNode;
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
249 }
6511
0b62a9d44c21 add infrastructure for creating locked objects
Lukas Stadler <lukas.stadler@jku.at>
parents: 6504
diff changeset
250 InitializeObjectNode initializeNode = graph.add(new InitializeObjectNode(memory, type, newInstanceNode.fillContents(), newInstanceNode.locked()));
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
251 graph.replaceFixedWithFixed(newInstanceNode, initializeNode);
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
252 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
253
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
254 /**
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
255 * 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
256 */
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
257 @SuppressWarnings("unused")
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
258 public void lower(NewArrayNode newArrayNode, LoweringTool tool) {
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
259 StructuredGraph graph = (StructuredGraph) newArrayNode.graph();
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
260 ValueNode lengthNode = newArrayNode.length();
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
261 TLABAllocateNode tlabAllocateNode;
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
262 ResolvedJavaType elementType = newArrayNode.elementType();
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
263 ResolvedJavaType arrayType = elementType.getArrayClass();
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
264 Kind elementKind = elementType.getKind();
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
265 final int alignment = target.wordSize;
7099
3656236c7d27 Cleanup of Kind class: remove use of Unsafe class
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7098
diff changeset
266 final int headerSize = HotSpotRuntime.getArrayBaseOffset(elementKind);
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
267 final Integer length = lengthNode.isConstant() ? Integer.valueOf(lengthNode.asConstant().asInt()) : null;
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
268 int log2ElementSize = CodeUtil.log2(target.sizeInBytes(elementKind));
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
269 if (!useTLAB) {
7105
f1f32b695d1e Make constructors of Constant private to ensure proper encapuslation of the type-overloaded primitive field; reduce to one constructor that sets all fields.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7099
diff changeset
270 ConstantNode zero = ConstantNode.defaultForKind(target.wordKind, graph);
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
271 /*
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
272 * value for 'size' doesn't matter as it isn't used since a stub call will be made
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
273 * anyway for both allocation and initialization - it just needs to be non-null
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
274 */
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
275 ConstantNode size = ConstantNode.forInt(-1, graph);
6511
0b62a9d44c21 add infrastructure for creating locked objects
Lukas Stadler <lukas.stadler@jku.at>
parents: 6504
diff changeset
276 InitializeArrayNode initializeNode = graph.add(new InitializeArrayNode(zero, lengthNode, size, arrayType, newArrayNode.fillContents(), newArrayNode.locked()));
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
277 graph.replaceFixedWithFixed(newArrayNode, initializeNode);
7352
00e3c2e4e43c Re-enable fast array allocation/initialization.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7351
diff changeset
278 } else if (length != null && 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
279 // Calculate aligned size
7147
88d626e2c2a8 added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents: 7145
diff changeset
280 int size = computeArrayAllocationSize(length, alignment, headerSize, log2ElementSize);
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
281 ConstantNode sizeNode = ConstantNode.forInt(size, graph);
6954
0e20ad1ea98b removed WordStamp (and a nasty bug associated with its misusage)
Doug Simon <doug.simon@oracle.com>
parents: 6950
diff changeset
282 tlabAllocateNode = graph.add(new TLABAllocateNode(sizeNode));
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
283 graph.addBeforeFixed(newArrayNode, tlabAllocateNode);
6511
0b62a9d44c21 add infrastructure for creating locked objects
Lukas Stadler <lukas.stadler@jku.at>
parents: 6504
diff changeset
284 InitializeArrayNode initializeNode = graph.add(new InitializeArrayNode(tlabAllocateNode, lengthNode, sizeNode, arrayType, newArrayNode.fillContents(), newArrayNode.locked()));
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
285 graph.replaceFixedWithFixed(newArrayNode, initializeNode);
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
286 } else {
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
287 Arguments args = new Arguments(allocateArrayAndInitialize);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
288 args.add("length", lengthNode);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
289 args.addConst("alignment", alignment);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
290 args.addConst("headerSize", headerSize);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
291 args.addConst("log2ElementSize", log2ElementSize);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
292 args.addConst("fillContents", newArrayNode.fillContents());
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
293 args.addConst("type", arrayType);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
294
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
295 SnippetTemplate template = template(args);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
296 Debug.log("Lowering allocateArrayAndInitialize in %s: node=%s, template=%s, arguments=%s", graph, newArrayNode, template, args);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
297 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
298 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
299 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
300
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
301 @SuppressWarnings("unused")
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
302 public void lower(TLABAllocateNode tlabAllocateNode, LoweringTool tool) {
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
303 StructuredGraph graph = (StructuredGraph) tlabAllocateNode.graph();
5805
013081f7771b consolidated 2 separate size fields in TLABAllocate into 1
Doug Simon <doug.simon@oracle.com>
parents: 5772
diff changeset
304 ValueNode size = tlabAllocateNode.size();
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
305 Arguments args = new Arguments(allocate).add("size", size);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
306
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
307 SnippetTemplate template = template(args);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
308 Debug.log("Lowering fastAllocate in %s: node=%s, template=%s, arguments=%s", graph, tlabAllocateNode, template, args);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
309 template.instantiate(runtime, tlabAllocateNode, 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
310 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
311
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
312 @SuppressWarnings("unused")
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
313 public void lower(InitializeObjectNode initializeNode, LoweringTool tool) {
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
314 StructuredGraph graph = (StructuredGraph) initializeNode.graph();
7084
9ba90252ce08 HotSpotResolvedJavaType is now the HotSpot implementation of ResolvedJavaType,
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7081
diff changeset
315 HotSpotResolvedObjectType type = (HotSpotResolvedObjectType) initializeNode.type();
7060
06d5f450f32b rename: ResolvedJavaType.isArrayClass() -> ResolvedJavaType.isArray()
Doug Simon <doug.simon@oracle.com>
parents: 7035
diff changeset
316 assert !type.isArray();
6950
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6568
diff changeset
317 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
318 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
319 ValueNode memory = initializeNode.memory();
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
320
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
321 Arguments args = new Arguments(initializeObject);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
322 args.add("memory", memory);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
323 args.add("hub", hub);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
324 args.add("prototypeMarkWord", type.prototypeMarkWord());
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
325 args.addConst("size", size).addConst("fillContents", initializeNode.fillContents());
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
326 args.addConst("locked", initializeNode.locked());
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
327
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
328 SnippetTemplate template = template(args);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
329 Debug.log("Lowering initializeObject in %s: node=%s, template=%s, arguments=%s", graph, initializeNode, template, args);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
330 template.instantiate(runtime, initializeNode, 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
331 }
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
332
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
333 @SuppressWarnings("unused")
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
334 public void lower(InitializeArrayNode initializeNode, LoweringTool tool) {
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
335 StructuredGraph graph = (StructuredGraph) initializeNode.graph();
7084
9ba90252ce08 HotSpotResolvedJavaType is now the HotSpot implementation of ResolvedJavaType,
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7081
diff changeset
336 HotSpotResolvedObjectType type = (HotSpotResolvedObjectType) initializeNode.type();
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
337 ResolvedJavaType elementType = type.getComponentType();
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
338 assert elementType != null;
6950
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6568
diff changeset
339 ConstantNode hub = ConstantNode.forConstant(type.klass(), runtime, graph);
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
340 Kind elementKind = elementType.getKind();
7099
3656236c7d27 Cleanup of Kind class: remove use of Unsafe class
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7098
diff changeset
341 final int headerSize = HotSpotRuntime.getArrayBaseOffset(elementKind);
5760
87e8baf5447c added snippets for lowering array creation and initialization (in NewObjectSnippets)
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
342 ValueNode memory = initializeNode.memory();
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
343
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
344 Arguments args = new Arguments(initializeArray);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
345 args.add("memory", memory);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
346 args.add("hub", hub);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
347 args.add("length", initializeNode.length());
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
348 args.add("allocationSize", initializeNode.allocationSize());
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
349 args.add("prototypeMarkWord", type.prototypeMarkWord());
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
350 args.addConst("headerSize", headerSize);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
351 args.addConst("fillContents", initializeNode.fillContents());
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
352 args.addConst("locked", initializeNode.locked());
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
353
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
354 SnippetTemplate template = template(args);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
355 Debug.log("Lowering initializeArray in %s: node=%s, template=%s, arguments=%s", graph, initializeNode, template, args);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
356 template.instantiate(runtime, initializeNode, DEFAULT_REPLACER, args);
5563
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
357 }
6431
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
358
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
359 @SuppressWarnings("unused")
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
360 public void lower(NewMultiArrayNode newmultiarrayNode, LoweringTool tool) {
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
361 StructuredGraph graph = (StructuredGraph) newmultiarrayNode.graph();
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
362 int rank = newmultiarrayNode.dimensionCount();
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
363 ValueNode[] dims = new ValueNode[rank];
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
364 for (int i = 0; i < newmultiarrayNode.dimensionCount(); i++) {
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
365 dims[i] = newmultiarrayNode.dimension(i);
2e376f8ea4e2 added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents: 6420
diff changeset
366 }
7084
9ba90252ce08 HotSpotResolvedJavaType is now the HotSpot implementation of ResolvedJavaType,
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7081
diff changeset
367 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
368 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
369
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
370 Arguments args = new Arguments(newmultiarray);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
371 args.add("hub", hub);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
372 args.addConst("rank", rank);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8898
diff changeset
373 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
374 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
375 }
7544
5d9c23b8dbb8 factored out common code in NewObjectSnippets
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
376
5d9c23b8dbb8 factored out common code in NewObjectSnippets
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
377 private static int instanceSize(HotSpotResolvedObjectType type) {
5d9c23b8dbb8 factored out common code in NewObjectSnippets
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
378 int size = type.instanceSize();
5d9c23b8dbb8 factored out common code in NewObjectSnippets
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
379 assert (size % wordSize()) == 0;
5d9c23b8dbb8 factored out common code in NewObjectSnippets
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
380 assert size >= 0;
5d9c23b8dbb8 factored out common code in NewObjectSnippets
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
381 return size;
5d9c23b8dbb8 factored out common code in NewObjectSnippets
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
382 }
5563
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
383 }
6a2671066204 added NewInstanceSnippets for lowering NewInstanceNodes (currently disabled by default)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
384
5772
2f7a03583a32 added counters for code paths through the new object snippets
Doug Simon <doug.simon@oracle.com>
parents: 5770
diff changeset
385 private static final SnippetCounter.Group countersNew = GraalOptions.SnippetCounters ? new SnippetCounter.Group("NewInstance") : null;
2f7a03583a32 added counters for code paths through the new object snippets
Doug Simon <doug.simon@oracle.com>
parents: 5770
diff changeset
386 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
387 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
388 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
389
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
390 private static final SnippetCounter.Group countersNewArray = GraalOptions.SnippetCounters ? new SnippetCounter.Group("NewArray") : null;
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
391 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
392 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
393 }