Mercurial > hg > graal-compiler
annotate graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewArrayStub.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 | ce5750014c3d |
children | 0266549ff6e0 |
rev | line source |
---|---|
7147
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1 /* |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
4 * |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
8 * |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
14 * |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
18 * |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
21 * questions. |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
22 */ |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.graal.hotspot.stubs; |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
24 |
8415
2361bf148c06
rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents:
7868
diff
changeset
|
25 import static com.oracle.graal.hotspot.replacements.HotSpotSnippetUtils.*; |
2361bf148c06
rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents:
7868
diff
changeset
|
26 import static com.oracle.graal.hotspot.replacements.NewObjectSnippets.*; |
7147
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
27 import static com.oracle.graal.hotspot.stubs.NewInstanceStub.*; |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
28 |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
29 import com.oracle.graal.api.code.*; |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8415
diff
changeset
|
30 import com.oracle.graal.hotspot.*; |
7147
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
31 import com.oracle.graal.hotspot.meta.*; |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
32 import com.oracle.graal.hotspot.nodes.*; |
8415
2361bf148c06
rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents:
7868
diff
changeset
|
33 import com.oracle.graal.hotspot.replacements.*; |
8637
ce5750014c3d
moved Replacements and MacroSubstitution from the graal.api.replacements project to graal.nodes project and reversed the dependency between these two projects (the latter now/again depends on the former)
Doug Simon <doug.simon@oracle.com>
parents:
8627
diff
changeset
|
34 import com.oracle.graal.nodes.spi.*; |
8415
2361bf148c06
rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents:
7868
diff
changeset
|
35 import com.oracle.graal.replacements.*; |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8637
diff
changeset
|
36 import com.oracle.graal.replacements.Snippet.ConstantParameter; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8637
diff
changeset
|
37 import com.oracle.graal.replacements.SnippetTemplate.Arguments; |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8637
diff
changeset
|
38 import com.oracle.graal.replacements.SnippetTemplate.SnippetInfo; |
7300
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7275
diff
changeset
|
39 import com.oracle.graal.word.*; |
7147
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
40 |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
41 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
42 * Stub implementing the fast path for TLAB refill during instance class allocation. This stub is |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
43 * called from the {@linkplain NewObjectSnippets inline} allocation code when TLAB allocation fails. |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
44 * If this stub fails to refill the TLAB or allocate the object, it calls out to the HotSpot C++ |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
45 * runtime for to complete the allocation. |
7147
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
46 */ |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
47 public class NewArrayStub extends Stub { |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
48 |
8627
75db7afee829
implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents:
8415
diff
changeset
|
49 public NewArrayStub(final HotSpotRuntime runtime, Replacements replacements, TargetDescription target, HotSpotRuntimeCallTarget linkage) { |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8637
diff
changeset
|
50 super(runtime, replacements, target, linkage, "newArray"); |
7147
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
51 } |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
52 |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
53 @Override |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8637
diff
changeset
|
54 protected Arguments makeArguments(SnippetInfo stub) { |
7147
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
55 HotSpotResolvedObjectType intArrayType = (HotSpotResolvedObjectType) runtime.lookupJavaType(int[].class); |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8637
diff
changeset
|
56 |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8637
diff
changeset
|
57 Arguments args = new Arguments(stub); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8637
diff
changeset
|
58 args.add("hub", null); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8637
diff
changeset
|
59 args.add("length", null); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8637
diff
changeset
|
60 args.addConst("intArrayHub", intArrayType.klass()); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8637
diff
changeset
|
61 args.addConst("log", Boolean.getBoolean("graal.logNewArrayStub")); |
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8637
diff
changeset
|
62 return args; |
7147
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
63 } |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
64 |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
65 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
66 * Re-attempts allocation after an initial TLAB allocation failed or was skipped (e.g., due to |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
67 * -XX:-UseTLAB). |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7356
diff
changeset
|
68 * |
7147
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
69 * @param hub the hub of the object to be allocated |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
70 * @param length the length of the array |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
71 * @param intArrayHub the hub for {@code int[].class} |
7237
509d72a1d81b
made the effect of graal.logNewArrayStub independent from graal.logNewInstanceStub
Doug Simon <doug.simon@oracle.com>
parents:
7147
diff
changeset
|
72 * @param log specifies if logging is enabled |
7147
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
73 */ |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
74 @Snippet |
9015
92d2bedb5dfc
Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents:
8637
diff
changeset
|
75 private static Object newArray(Word hub, int length, @ConstantParameter Word intArrayHub, @ConstantParameter boolean log) { |
7868
7a5bbcc36bb2
add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents:
7701
diff
changeset
|
76 int layoutHelper = hub.readInt(layoutHelperOffset(), FINAL_LOCATION); |
7147
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
77 int log2ElementSize = (layoutHelper >> layoutHelperLog2ElementSizeShift()) & layoutHelperLog2ElementSizeMask(); |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
78 int headerSize = (layoutHelper >> layoutHelperHeaderSizeShift()) & layoutHelperHeaderSizeMask(); |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
79 int elementKind = (layoutHelper >> layoutHelperElementTypeShift()) & layoutHelperElementTypeMask(); |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
80 int sizeInBytes = computeArrayAllocationSize(length, wordSize(), headerSize, log2ElementSize); |
7237
509d72a1d81b
made the effect of graal.logNewArrayStub independent from graal.logNewInstanceStub
Doug Simon <doug.simon@oracle.com>
parents:
7147
diff
changeset
|
81 log(log, "newArray: element kind %d\n", elementKind); |
509d72a1d81b
made the effect of graal.logNewArrayStub independent from graal.logNewInstanceStub
Doug Simon <doug.simon@oracle.com>
parents:
7147
diff
changeset
|
82 log(log, "newArray: array length %d\n", length); |
509d72a1d81b
made the effect of graal.logNewArrayStub independent from graal.logNewInstanceStub
Doug Simon <doug.simon@oracle.com>
parents:
7147
diff
changeset
|
83 log(log, "newArray: array size %d\n", sizeInBytes); |
7300
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7275
diff
changeset
|
84 log(log, "newArray: hub=%p\n", hub); |
7147
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
85 |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
86 // check that array length is small enough for fast path. |
7254
9e155cd2bb2f
enable tlab stub for array allocation
Lukas Stadler <lukas.stadler@jku.at>
parents:
7253
diff
changeset
|
87 if (length <= MAX_ARRAY_FAST_PATH_ALLOCATION_LENGTH) { |
7253
c66968130037
replicate c1 tlab refill behavior more closely, fixes problem with huge tlab sizes
Lukas Stadler <lukas.stadler@jku.at>
parents:
7239
diff
changeset
|
88 Word memory = refillAllocate(intArrayHub, sizeInBytes, log); |
7701
47467b2c3fc5
Use equal() and notEqual() instead of == and != to compare words
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7556
diff
changeset
|
89 if (memory.notEqual(0)) { |
7300
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7275
diff
changeset
|
90 log(log, "newArray: allocated new array at %p\n", memory); |
2912b72d840a
More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents:
7275
diff
changeset
|
91 formatArray(hub, sizeInBytes, length, headerSize, memory, Word.unsigned(arrayPrototypeMarkWord()), true); |
7147
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
92 return verifyOop(memory.toObject()); |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
93 } |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
94 } |
7237
509d72a1d81b
made the effect of graal.logNewArrayStub independent from graal.logNewInstanceStub
Doug Simon <doug.simon@oracle.com>
parents:
7147
diff
changeset
|
95 log(log, "newArray: calling new_array_slow", 0L); |
7147
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
96 return verifyOop(NewArraySlowStubCall.call(hub, length)); |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
97 } |
88d626e2c2a8
added TLAB fast refill stub for array allocation
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
98 } |