author | jwilhelm |
Thu, 27 Jun 2019 03:33:44 +0200 | |
changeset 55509 | d58442b8abc1 |
parent 54724 | 62f373a53296 |
child 57537 | ecc6e394475f |
permissions | -rw-r--r-- |
43972 | 1 |
/* |
54724 | 2 |
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved. |
43972 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
50858 | 23 |
|
24 |
||
43972 | 25 |
package org.graalvm.compiler.hotspot.replacements; |
26 |
||
52033
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
27 |
import static jdk.vm.ci.meta.DeoptimizationAction.None; |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
28 |
import static jdk.vm.ci.meta.DeoptimizationReason.RuntimeConstraint; |
43972 | 29 |
import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC; |
54724 | 30 |
import static org.graalvm.compiler.core.common.GraalOptions.MinimalBulkZeroingSize; |
43972 | 31 |
import static org.graalvm.compiler.core.common.calc.UnsignedMath.belowThan; |
52956 | 32 |
import static org.graalvm.compiler.hotspot.GraalHotSpotVMConfigBase.INJECTED_OPTIONVALUES; |
52033
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
33 |
import static org.graalvm.compiler.hotspot.GraalHotSpotVMConfigBase.INJECTED_VMCONFIG; |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
34 |
import static org.graalvm.compiler.hotspot.HotSpotBackend.NEW_ARRAY; |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
35 |
import static org.graalvm.compiler.hotspot.HotSpotBackend.NEW_ARRAY_OR_NULL; |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
36 |
import static org.graalvm.compiler.hotspot.HotSpotBackend.NEW_INSTANCE; |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
37 |
import static org.graalvm.compiler.hotspot.HotSpotBackend.NEW_INSTANCE_OR_NULL; |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
38 |
import static org.graalvm.compiler.hotspot.HotSpotBackend.NEW_MULTI_ARRAY; |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
39 |
import static org.graalvm.compiler.hotspot.HotSpotBackend.NEW_MULTI_ARRAY_OR_NULL; |
43972 | 40 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.CLASS_ARRAY_KLASS_LOCATION; |
55509 | 41 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.CLASS_STATE_LOCATION; |
43972 | 42 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.HUB_WRITE_LOCATION; |
43 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.MARK_WORD_LOCATION; |
|
44 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.PROTOTYPE_MARK_WORD_LOCATION; |
|
45 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.TLAB_END_LOCATION; |
|
46 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.TLAB_TOP_LOCATION; |
|
52956 | 47 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.allocateInstancePrefetchLines; |
48 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.allocatePrefetchDistance; |
|
49 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.allocatePrefetchLines; |
|
50 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.allocatePrefetchStepSize; |
|
51 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.allocatePrefetchStyle; |
|
48505
5db30620a3db
8191362: [Graal] gc/g1/TestShrinkAuxiliaryData tests crash with "assert(check_klass_alignment(result)) failed: address not aligned"
thartmann
parents:
47216
diff
changeset
|
52 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.arrayAllocationSize; |
43972 | 53 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.arrayKlassOffset; |
54 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.arrayLengthOffset; |
|
55 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.initializeObjectHeader; |
|
56 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.instanceHeaderSize; |
|
57 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.isInstanceKlassFullyInitialized; |
|
58 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.layoutHelperHeaderSizeMask; |
|
59 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.layoutHelperHeaderSizeShift; |
|
60 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.layoutHelperLog2ElementSizeMask; |
|
61 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.layoutHelperLog2ElementSizeShift; |
|
62 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.loadKlassFromObject; |
|
63 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.prototypeMarkWordOffset; |
|
64 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.readLayoutHelper; |
|
65 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.readTlabEnd; |
|
66 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.readTlabTop; |
|
67 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.registerAsWord; |
|
68 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.useBiasedLocking; |
|
69 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.useTLAB; |
|
70 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.verifyOop; |
|
71 |
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.writeTlabTop; |
|
46344 | 72 |
import static org.graalvm.compiler.hotspot.replacements.HotspotSnippetsOptions.ProfileAllocations; |
73 |
import static org.graalvm.compiler.hotspot.replacements.HotspotSnippetsOptions.ProfileAllocationsContext; |
|
46371 | 74 |
import static org.graalvm.compiler.nodes.PiArrayNode.piArrayCastToSnippetReplaceeStamp; |
46344 | 75 |
import static org.graalvm.compiler.nodes.PiNode.piCastToSnippetReplaceeStamp; |
43972 | 76 |
import static org.graalvm.compiler.nodes.extended.BranchProbabilityNode.FAST_PATH_PROBABILITY; |
77 |
import static org.graalvm.compiler.nodes.extended.BranchProbabilityNode.FREQUENT_PROBABILITY; |
|
78 |
import static org.graalvm.compiler.nodes.extended.BranchProbabilityNode.SLOW_PATH_PROBABILITY; |
|
79 |
import static org.graalvm.compiler.nodes.extended.BranchProbabilityNode.probability; |
|
80 |
import static org.graalvm.compiler.replacements.ReplacementsUtil.REPLACEMENTS_ASSERTIONS_ENABLED; |
|
48861 | 81 |
import static org.graalvm.compiler.replacements.ReplacementsUtil.runtimeAssert; |
43972 | 82 |
import static org.graalvm.compiler.replacements.ReplacementsUtil.staticAssert; |
83 |
import static org.graalvm.compiler.replacements.SnippetTemplate.DEFAULT_REPLACER; |
|
84 |
import static org.graalvm.compiler.replacements.nodes.CStringConstant.cstring; |
|
85 |
import static org.graalvm.compiler.replacements.nodes.ExplodeLoopNode.explodeLoop; |
|
86 |
||
87 |
import org.graalvm.compiler.api.replacements.Fold; |
|
52033
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
88 |
import org.graalvm.compiler.api.replacements.Fold.InjectedParameter; |
43972 | 89 |
import org.graalvm.compiler.api.replacements.Snippet; |
90 |
import org.graalvm.compiler.api.replacements.Snippet.ConstantParameter; |
|
91 |
import org.graalvm.compiler.api.replacements.Snippet.VarargsParameter; |
|
92 |
import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor; |
|
93 |
import org.graalvm.compiler.core.common.type.StampFactory; |
|
46640 | 94 |
import org.graalvm.compiler.debug.DebugHandlersFactory; |
43972 | 95 |
import org.graalvm.compiler.debug.GraalError; |
96 |
import org.graalvm.compiler.graph.Node.ConstantNodeParameter; |
|
97 |
import org.graalvm.compiler.graph.Node.NodeIntrinsic; |
|
98 |
import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig; |
|
99 |
import org.graalvm.compiler.hotspot.meta.HotSpotProviders; |
|
100 |
import org.graalvm.compiler.hotspot.meta.HotSpotRegistersProvider; |
|
101 |
import org.graalvm.compiler.hotspot.nodes.DimensionsNode; |
|
102 |
import org.graalvm.compiler.hotspot.nodes.aot.LoadConstantIndirectlyFixedNode; |
|
103 |
import org.graalvm.compiler.hotspot.nodes.aot.LoadConstantIndirectlyNode; |
|
104 |
import org.graalvm.compiler.hotspot.nodes.type.KlassPointerStamp; |
|
105 |
import org.graalvm.compiler.hotspot.word.KlassPointer; |
|
106 |
import org.graalvm.compiler.nodes.ConstantNode; |
|
107 |
import org.graalvm.compiler.nodes.DeoptimizeNode; |
|
46344 | 108 |
import org.graalvm.compiler.nodes.PiNode; |
43972 | 109 |
import org.graalvm.compiler.nodes.PrefetchAllocateNode; |
46344 | 110 |
import org.graalvm.compiler.nodes.SnippetAnchorNode; |
43972 | 111 |
import org.graalvm.compiler.nodes.StructuredGraph; |
112 |
import org.graalvm.compiler.nodes.ValueNode; |
|
113 |
import org.graalvm.compiler.nodes.debug.DynamicCounterNode; |
|
114 |
import org.graalvm.compiler.nodes.debug.VerifyHeapNode; |
|
115 |
import org.graalvm.compiler.nodes.extended.ForeignCallNode; |
|
116 |
import org.graalvm.compiler.nodes.extended.MembarNode; |
|
117 |
import org.graalvm.compiler.nodes.java.DynamicNewArrayNode; |
|
118 |
import org.graalvm.compiler.nodes.java.DynamicNewInstanceNode; |
|
119 |
import org.graalvm.compiler.nodes.java.NewArrayNode; |
|
120 |
import org.graalvm.compiler.nodes.java.NewInstanceNode; |
|
121 |
import org.graalvm.compiler.nodes.java.NewMultiArrayNode; |
|
122 |
import org.graalvm.compiler.nodes.memory.address.OffsetAddressNode; |
|
123 |
import org.graalvm.compiler.nodes.spi.LoweringTool; |
|
124 |
import org.graalvm.compiler.nodes.util.GraphUtil; |
|
46344 | 125 |
import org.graalvm.compiler.options.OptionValues; |
43972 | 126 |
import org.graalvm.compiler.replacements.ReplacementsUtil; |
127 |
import org.graalvm.compiler.replacements.SnippetCounter; |
|
46344 | 128 |
import org.graalvm.compiler.replacements.SnippetCounter.Group; |
43972 | 129 |
import org.graalvm.compiler.replacements.SnippetTemplate; |
130 |
import org.graalvm.compiler.replacements.SnippetTemplate.AbstractTemplates; |
|
131 |
import org.graalvm.compiler.replacements.SnippetTemplate.Arguments; |
|
132 |
import org.graalvm.compiler.replacements.SnippetTemplate.SnippetInfo; |
|
133 |
import org.graalvm.compiler.replacements.Snippets; |
|
134 |
import org.graalvm.compiler.replacements.nodes.ExplodeLoopNode; |
|
54724 | 135 |
import org.graalvm.compiler.replacements.nodes.ZeroMemoryNode; |
43972 | 136 |
import org.graalvm.compiler.word.Word; |
49873 | 137 |
import jdk.internal.vm.compiler.word.LocationIdentity; |
138 |
import jdk.internal.vm.compiler.word.WordFactory; |
|
43972 | 139 |
|
140 |
import jdk.vm.ci.code.CodeUtil; |
|
141 |
import jdk.vm.ci.code.MemoryBarriers; |
|
142 |
import jdk.vm.ci.code.Register; |
|
143 |
import jdk.vm.ci.code.TargetDescription; |
|
144 |
import jdk.vm.ci.hotspot.HotSpotResolvedObjectType; |
|
145 |
import jdk.vm.ci.meta.JavaKind; |
|
146 |
import jdk.vm.ci.meta.ResolvedJavaType; |
|
147 |
||
148 |
/** |
|
149 |
* Snippets used for implementing NEW, ANEWARRAY and NEWARRAY. |
|
150 |
*/ |
|
151 |
public class NewObjectSnippets implements Snippets { |
|
152 |
||
153 |
enum ProfileContext { |
|
154 |
AllocatingMethod, |
|
155 |
InstanceOrArray, |
|
156 |
AllocatedType, |
|
157 |
AllocatedTypesInMethod, |
|
158 |
Total |
|
159 |
} |
|
160 |
||
161 |
@Fold |
|
52956 | 162 |
static String createName(@Fold.InjectedParameter OptionValues options, String path, String typeContext) { |
46344 | 163 |
switch (ProfileAllocationsContext.getValue(options)) { |
43972 | 164 |
case AllocatingMethod: |
165 |
return ""; |
|
166 |
case InstanceOrArray: |
|
167 |
return path; |
|
168 |
case AllocatedType: |
|
169 |
case AllocatedTypesInMethod: |
|
170 |
return typeContext; |
|
171 |
case Total: |
|
172 |
return "bytes"; |
|
173 |
default: |
|
174 |
throw GraalError.shouldNotReachHere(); |
|
175 |
} |
|
176 |
} |
|
177 |
||
178 |
@Fold |
|
52956 | 179 |
static boolean doProfile(@Fold.InjectedParameter OptionValues options) { |
46344 | 180 |
return ProfileAllocations.getValue(options); |
43972 | 181 |
} |
182 |
||
183 |
@Fold |
|
52956 | 184 |
static boolean withContext(@Fold.InjectedParameter OptionValues options) { |
46344 | 185 |
ProfileContext context = ProfileAllocationsContext.getValue(options); |
43972 | 186 |
return context == ProfileContext.AllocatingMethod || context == ProfileContext.AllocatedTypesInMethod; |
187 |
} |
|
188 |
||
52956 | 189 |
protected static void profileAllocation(String path, long size, String typeContext) { |
190 |
if (doProfile(INJECTED_OPTIONVALUES)) { |
|
191 |
String name = createName(INJECTED_OPTIONVALUES, path, typeContext); |
|
43972 | 192 |
|
52956 | 193 |
boolean context = withContext(INJECTED_OPTIONVALUES); |
51436 | 194 |
DynamicCounterNode.counter("number of bytes allocated", name, size, context); |
195 |
DynamicCounterNode.counter("number of allocations", name, 1, context); |
|
43972 | 196 |
} |
197 |
} |
|
198 |
||
199 |
public static void emitPrefetchAllocate(Word address, boolean isArray) { |
|
52956 | 200 |
if (allocatePrefetchStyle(INJECTED_VMCONFIG) > 0) { |
43972 | 201 |
// Insert a prefetch for each allocation only on the fast-path |
202 |
// Generate several prefetch instructions. |
|
52956 | 203 |
int lines = isArray ? allocatePrefetchLines(INJECTED_VMCONFIG) : allocateInstancePrefetchLines(INJECTED_VMCONFIG); |
204 |
int stepSize = allocatePrefetchStepSize(INJECTED_VMCONFIG); |
|
205 |
int distance = allocatePrefetchDistance(INJECTED_VMCONFIG); |
|
43972 | 206 |
ExplodeLoopNode.explodeLoop(); |
207 |
for (int i = 0; i < lines; i++) { |
|
208 |
PrefetchAllocateNode.prefetch(OffsetAddressNode.address(address, distance)); |
|
209 |
distance += stepSize; |
|
210 |
} |
|
211 |
} |
|
212 |
} |
|
213 |
||
214 |
@Snippet |
|
54084 | 215 |
public static Object allocateInstance(@ConstantParameter long size, KlassPointer hub, Word prototypeMarkWord, @ConstantParameter boolean fillContents, |
52956 | 216 |
@ConstantParameter Register threadRegister, @ConstantParameter boolean constantSize, @ConstantParameter String typeContext, |
46344 | 217 |
@ConstantParameter Counters counters) { |
52956 | 218 |
return piCastToSnippetReplaceeStamp(allocateInstanceHelper(size, hub, prototypeMarkWord, fillContents, threadRegister, constantSize, typeContext, counters)); |
46344 | 219 |
} |
220 |
||
54084 | 221 |
public static Object allocateInstanceHelper(long size, KlassPointer hub, Word prototypeMarkWord, boolean fillContents, |
52956 | 222 |
Register threadRegister, boolean constantSize, String typeContext, Counters counters) { |
43972 | 223 |
Object result; |
224 |
Word thread = registerAsWord(threadRegister); |
|
225 |
Word top = readTlabTop(thread); |
|
226 |
Word end = readTlabEnd(thread); |
|
54084 | 227 |
Word newTop = top.add(WordFactory.unsigned(size)); |
43972 | 228 |
if (useTLAB(INJECTED_VMCONFIG) && probability(FAST_PATH_PROBABILITY, newTop.belowOrEqual(end))) { |
229 |
writeTlabTop(thread, newTop); |
|
230 |
emitPrefetchAllocate(newTop, false); |
|
46344 | 231 |
result = formatObject(hub, size, top, prototypeMarkWord, fillContents, constantSize, counters); |
43972 | 232 |
} else { |
52956 | 233 |
Counters theCounters = counters; |
234 |
if (theCounters != null && theCounters.stub != null) { |
|
235 |
theCounters.stub.inc(); |
|
46344 | 236 |
} |
52033
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
237 |
result = newInstanceStub(hub); |
43972 | 238 |
} |
52956 | 239 |
profileAllocation("instance", size, typeContext); |
46344 | 240 |
return verifyOop(result); |
43972 | 241 |
} |
242 |
||
52033
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
243 |
public static Object newInstanceStub(KlassPointer hub) { |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
244 |
if (useNullAllocationStubs(INJECTED_VMCONFIG)) { |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
245 |
return nonNullOrDeopt(newInstanceOrNull(NEW_INSTANCE_OR_NULL, hub)); |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
246 |
} else { |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
247 |
return newInstance(NEW_INSTANCE, hub); |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
248 |
} |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
249 |
} |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
250 |
|
46371 | 251 |
@NodeIntrinsic(value = ForeignCallNode.class, injectedStampIsNonNull = true) |
52033
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
252 |
private static native Object newInstance(@ConstantNodeParameter ForeignCallDescriptor descriptor, KlassPointer hub); |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
253 |
|
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
254 |
@NodeIntrinsic(value = ForeignCallNode.class, injectedStampIsNonNull = false) |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
255 |
private static native Object newInstanceOrNull(@ConstantNodeParameter ForeignCallDescriptor descriptor, KlassPointer hub); |
43972 | 256 |
|
257 |
@Snippet |
|
54084 | 258 |
public static Object allocateInstancePIC(@ConstantParameter long size, KlassPointer hub, Word prototypeMarkWord, @ConstantParameter boolean fillContents, |
52956 | 259 |
@ConstantParameter Register threadRegister, @ConstantParameter boolean constantSize, @ConstantParameter String typeContext, |
46344 | 260 |
@ConstantParameter Counters counters) { |
43972 | 261 |
// Klass must be initialized by the time the first instance is allocated, therefore we can |
262 |
// just load it from the corresponding cell and avoid the resolution check. We have to use a |
|
263 |
// fixed load though, to prevent it from floating above the initialization. |
|
264 |
KlassPointer picHub = LoadConstantIndirectlyFixedNode.loadKlass(hub); |
|
52956 | 265 |
return piCastToSnippetReplaceeStamp(allocateInstanceHelper(size, picHub, prototypeMarkWord, fillContents, threadRegister, constantSize, typeContext, counters)); |
43972 | 266 |
} |
267 |
||
268 |
@Snippet |
|
46344 | 269 |
public static Object allocateInstanceDynamic(Class<?> type, Class<?> classClass, @ConstantParameter boolean fillContents, @ConstantParameter Register threadRegister, |
52956 | 270 |
@ConstantParameter Counters counters) { |
46344 | 271 |
if (probability(SLOW_PATH_PROBABILITY, type == null)) { |
52033
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
272 |
DeoptimizeNode.deopt(None, RuntimeConstraint); |
46344 | 273 |
} |
274 |
Class<?> nonNullType = PiNode.piCastNonNullClass(type, SnippetAnchorNode.anchor()); |
|
275 |
||
276 |
if (probability(SLOW_PATH_PROBABILITY, DynamicNewInstanceNode.throwsInstantiationException(type, classClass))) { |
|
52033
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
277 |
DeoptimizeNode.deopt(None, RuntimeConstraint); |
43972 | 278 |
} |
279 |
||
52956 | 280 |
return PiNode.piCastToSnippetReplaceeStamp(allocateInstanceDynamicHelper(type, fillContents, threadRegister, counters, nonNullType)); |
46344 | 281 |
} |
282 |
||
52956 | 283 |
private static Object allocateInstanceDynamicHelper(Class<?> type, boolean fillContents, Register threadRegister, Counters counters, Class<?> nonNullType) { |
46344 | 284 |
KlassPointer hub = ClassGetHubNode.readClass(nonNullType); |
43972 | 285 |
if (probability(FAST_PATH_PROBABILITY, !hub.isNull())) { |
46344 | 286 |
KlassPointer nonNullHub = ClassGetHubNode.piCastNonNull(hub, SnippetAnchorNode.anchor()); |
287 |
||
288 |
if (probability(FAST_PATH_PROBABILITY, isInstanceKlassFullyInitialized(nonNullHub))) { |
|
289 |
int layoutHelper = readLayoutHelper(nonNullHub); |
|
43972 | 290 |
/* |
291 |
* src/share/vm/oops/klass.hpp: For instances, layout helper is a positive number, |
|
292 |
* the instance size. This size is already passed through align_object_size and |
|
293 |
* scaled to bytes. The low order bit is set if instances of this class cannot be |
|
294 |
* allocated using the fastpath. |
|
295 |
*/ |
|
296 |
if (probability(FAST_PATH_PROBABILITY, (layoutHelper & 1) == 0)) { |
|
46344 | 297 |
Word prototypeMarkWord = nonNullHub.readWord(prototypeMarkWordOffset(INJECTED_VMCONFIG), PROTOTYPE_MARK_WORD_LOCATION); |
43972 | 298 |
/* |
299 |
* FIXME(je,ds): we should actually pass typeContext instead of "" but late |
|
300 |
* binding of parameters is not yet supported by the GraphBuilderPlugin system. |
|
301 |
*/ |
|
52956 | 302 |
return allocateInstanceHelper(layoutHelper, nonNullHub, prototypeMarkWord, fillContents, threadRegister, false, "", counters); |
43972 | 303 |
} |
51436 | 304 |
} else { |
52033
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
305 |
DeoptimizeNode.deopt(None, RuntimeConstraint); |
43972 | 306 |
} |
307 |
} |
|
52578 | 308 |
return dynamicNewInstanceStub(type); |
43972 | 309 |
} |
310 |
||
311 |
/** |
|
312 |
* Maximum array length for which fast path allocation is used. |
|
313 |
*/ |
|
314 |
public static final int MAX_ARRAY_FAST_PATH_ALLOCATION_LENGTH = 0x00FFFFFF; |
|
315 |
||
316 |
@Snippet |
|
54724 | 317 |
public static Object allocatePrimitiveArrayPIC(KlassPointer hub, |
318 |
int length, |
|
319 |
Word prototypeMarkWord, |
|
320 |
@ConstantParameter int headerSize, |
|
321 |
@ConstantParameter int log2ElementSize, |
|
322 |
@ConstantParameter boolean fillContents, |
|
323 |
@ConstantParameter Register threadRegister, |
|
324 |
@ConstantParameter boolean maybeUnroll, |
|
325 |
@ConstantParameter String typeContext, |
|
326 |
@ConstantParameter boolean useBulkZeroing, |
|
52956 | 327 |
@ConstantParameter Counters counters) { |
46551 | 328 |
// Primitive array types are eagerly pre-resolved. We can use a floating load. |
43972 | 329 |
KlassPointer picHub = LoadConstantIndirectlyNode.loadKlass(hub); |
54724 | 330 |
return allocateArrayImpl(picHub, length, prototypeMarkWord, headerSize, log2ElementSize, fillContents, |
331 |
threadRegister, maybeUnroll, typeContext, useBulkZeroing, counters); |
|
43972 | 332 |
} |
333 |
||
334 |
@Snippet |
|
54724 | 335 |
public static Object allocateArrayPIC(KlassPointer hub, |
336 |
int length, |
|
337 |
Word prototypeMarkWord, |
|
338 |
@ConstantParameter int headerSize, |
|
339 |
@ConstantParameter int log2ElementSize, |
|
340 |
@ConstantParameter boolean fillContents, |
|
341 |
@ConstantParameter Register threadRegister, |
|
342 |
@ConstantParameter boolean maybeUnroll, |
|
343 |
@ConstantParameter String typeContext, |
|
344 |
@ConstantParameter boolean useBulkZeroing, |
|
52956 | 345 |
@ConstantParameter Counters counters) { |
46566 | 346 |
// Array type would be resolved by dominating resolution. |
347 |
KlassPointer picHub = LoadConstantIndirectlyFixedNode.loadKlass(hub); |
|
54724 | 348 |
return allocateArrayImpl(picHub, length, prototypeMarkWord, headerSize, log2ElementSize, fillContents, |
349 |
threadRegister, maybeUnroll, typeContext, useBulkZeroing, counters); |
|
43972 | 350 |
} |
351 |
||
352 |
@Snippet |
|
52033
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
353 |
public static Object allocateArray(KlassPointer hub, |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
354 |
int length, |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
355 |
Word prototypeMarkWord, |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
356 |
@ConstantParameter int headerSize, |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
357 |
@ConstantParameter int log2ElementSize, |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
358 |
@ConstantParameter boolean fillContents, |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
359 |
@ConstantParameter Register threadRegister, |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
360 |
@ConstantParameter boolean maybeUnroll, |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
361 |
@ConstantParameter String typeContext, |
54724 | 362 |
@ConstantParameter boolean useBulkZeroing, |
52033
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
363 |
@ConstantParameter Counters counters) { |
52956 | 364 |
Object result = allocateArrayImpl(hub, |
365 |
length, |
|
366 |
prototypeMarkWord, |
|
367 |
headerSize, |
|
368 |
log2ElementSize, |
|
369 |
fillContents, |
|
370 |
threadRegister, |
|
371 |
maybeUnroll, |
|
372 |
typeContext, |
|
54724 | 373 |
useBulkZeroing, |
52956 | 374 |
counters); |
46371 | 375 |
return piArrayCastToSnippetReplaceeStamp(verifyOop(result), length); |
43972 | 376 |
} |
377 |
||
52033
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
378 |
/** |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
379 |
* When allocating on the slow path, determines whether to use a version of the runtime call |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
380 |
* that returns {@code null} on a failed allocation instead of raising an OutOfMemoryError. |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
381 |
*/ |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
382 |
@Fold |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
383 |
static boolean useNullAllocationStubs(@InjectedParameter GraalHotSpotVMConfig config) { |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
384 |
return config.areNullAllocationStubsAvailable(); |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
385 |
} |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
386 |
|
46344 | 387 |
private static Object allocateArrayImpl(KlassPointer hub, int length, Word prototypeMarkWord, int headerSize, int log2ElementSize, boolean fillContents, Register threadRegister, |
54724 | 388 |
boolean maybeUnroll, String typeContext, boolean useBulkZeroing, Counters counters) { |
43972 | 389 |
Object result; |
54084 | 390 |
long allocationSize = arrayAllocationSize(length, headerSize, log2ElementSize); |
43972 | 391 |
Word thread = registerAsWord(threadRegister); |
392 |
Word top = readTlabTop(thread); |
|
393 |
Word end = readTlabEnd(thread); |
|
54084 | 394 |
Word newTop = top.add(WordFactory.unsigned(allocationSize)); |
395 |
if (probability(FREQUENT_PROBABILITY, belowThan(length, MAX_ARRAY_FAST_PATH_ALLOCATION_LENGTH)) && useTLAB(INJECTED_VMCONFIG) && |
|
43972 | 396 |
probability(FAST_PATH_PROBABILITY, newTop.belowOrEqual(end))) { |
397 |
writeTlabTop(thread, newTop); |
|
398 |
emitPrefetchAllocate(newTop, true); |
|
52956 | 399 |
Counters theCounters = counters; |
400 |
if (theCounters != null && theCounters.arrayLoopInit != null) { |
|
401 |
theCounters.arrayLoopInit.inc(); |
|
46344 | 402 |
} |
54724 | 403 |
result = formatArray(hub, allocationSize, length, headerSize, top, prototypeMarkWord, fillContents, maybeUnroll, useBulkZeroing, counters); |
43972 | 404 |
} else { |
52033
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
405 |
result = newArrayStub(hub, length); |
43972 | 406 |
} |
52956 | 407 |
profileAllocation("array", allocationSize, typeContext); |
43972 | 408 |
return result; |
409 |
} |
|
410 |
||
52033
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
411 |
public static Object newArrayStub(KlassPointer hub, int length) { |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
412 |
if (useNullAllocationStubs(INJECTED_VMCONFIG)) { |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
413 |
return nonNullOrDeopt(newArrayOrNull(NEW_ARRAY_OR_NULL, hub, length)); |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
414 |
} else { |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
415 |
return newArray(NEW_ARRAY, hub, length); |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
416 |
} |
43972 | 417 |
} |
418 |
||
46371 | 419 |
@NodeIntrinsic(value = ForeignCallNode.class, injectedStampIsNonNull = true) |
52033
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
420 |
private static native Object newArray(@ConstantNodeParameter ForeignCallDescriptor descriptor, KlassPointer hub, int length); |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
421 |
|
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
422 |
@NodeIntrinsic(value = ForeignCallNode.class, injectedStampIsNonNull = false) |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
423 |
private static native Object newArrayOrNull(@ConstantNodeParameter ForeignCallDescriptor descriptor, KlassPointer hub, int length); |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
424 |
|
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
425 |
/** |
52578 | 426 |
* New dynamic array stub that throws an {@link OutOfMemoryError} on allocation failure. |
427 |
*/ |
|
428 |
public static final ForeignCallDescriptor DYNAMIC_NEW_INSTANCE = new ForeignCallDescriptor("dynamic_new_instance", Object.class, Class.class); |
|
429 |
||
430 |
/** |
|
431 |
* New dynamic array stub that returns null on allocation failure. |
|
432 |
*/ |
|
433 |
public static final ForeignCallDescriptor DYNAMIC_NEW_INSTANCE_OR_NULL = new ForeignCallDescriptor("dynamic_new_instance_or_null", Object.class, Class.class); |
|
434 |
||
435 |
public static Object dynamicNewInstanceStub(Class<?> elementType) { |
|
436 |
if (useNullAllocationStubs(INJECTED_VMCONFIG)) { |
|
437 |
return nonNullOrDeopt(dynamicNewInstanceOrNull(DYNAMIC_NEW_INSTANCE_OR_NULL, elementType)); |
|
438 |
} else { |
|
439 |
return dynamicNewInstance(DYNAMIC_NEW_INSTANCE, elementType); |
|
440 |
} |
|
441 |
} |
|
442 |
||
443 |
/** |
|
52033
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
444 |
* Deoptimizes if {@code obj == null} otherwise returns {@code obj}. |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
445 |
*/ |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
446 |
private static Object nonNullOrDeopt(Object obj) { |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
447 |
if (obj == null) { |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
448 |
DeoptimizeNode.deopt(None, RuntimeConstraint); |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
449 |
} |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
450 |
return obj; |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
451 |
} |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
452 |
|
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
453 |
@NodeIntrinsic(value = ForeignCallNode.class, injectedStampIsNonNull = true) |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
454 |
public static native Object dynamicNewInstance(@ConstantNodeParameter ForeignCallDescriptor descriptor, Class<?> elementType); |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
455 |
|
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
456 |
@NodeIntrinsic(value = ForeignCallNode.class, injectedStampIsNonNull = false) |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
457 |
public static native Object dynamicNewInstanceOrNull(@ConstantNodeParameter ForeignCallDescriptor descriptor, Class<?> elementType); |
43972 | 458 |
|
459 |
@Snippet |
|
54724 | 460 |
public static Object allocateArrayDynamic(Class<?> elementType, |
461 |
Class<?> voidClass, |
|
462 |
int length, |
|
463 |
@ConstantParameter boolean fillContents, |
|
464 |
@ConstantParameter Register threadRegister, |
|
465 |
@ConstantParameter JavaKind knownElementKind, |
|
466 |
@ConstantParameter int knownLayoutHelper, |
|
467 |
@ConstantParameter boolean useBulkZeroing, |
|
468 |
Word prototypeMarkWord, |
|
46344 | 469 |
@ConstantParameter Counters counters) { |
54724 | 470 |
Object result = allocateArrayDynamicImpl(elementType, voidClass, length, fillContents, threadRegister, knownElementKind, |
471 |
knownLayoutHelper, useBulkZeroing, prototypeMarkWord, counters); |
|
43972 | 472 |
return result; |
473 |
} |
|
474 |
||
475 |
private static Object allocateArrayDynamicImpl(Class<?> elementType, Class<?> voidClass, int length, boolean fillContents, Register threadRegister, JavaKind knownElementKind, |
|
54724 | 476 |
int knownLayoutHelper, boolean useBulkZeroing, Word prototypeMarkWord, Counters counters) { |
43972 | 477 |
/* |
478 |
* We only need the dynamic check for void when we have no static information from |
|
479 |
* knownElementKind. |
|
480 |
*/ |
|
481 |
staticAssert(knownElementKind != JavaKind.Void, "unsupported knownElementKind"); |
|
482 |
if (knownElementKind == JavaKind.Illegal && probability(SLOW_PATH_PROBABILITY, elementType == null || DynamicNewArrayNode.throwsIllegalArgumentException(elementType, voidClass))) { |
|
52033
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
483 |
DeoptimizeNode.deopt(None, RuntimeConstraint); |
43972 | 484 |
} |
485 |
||
486 |
KlassPointer klass = loadKlassFromObject(elementType, arrayKlassOffset(INJECTED_VMCONFIG), CLASS_ARRAY_KLASS_LOCATION); |
|
46344 | 487 |
if (klass.isNull()) { |
52033
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
488 |
DeoptimizeNode.deopt(None, RuntimeConstraint); |
43972 | 489 |
} |
46344 | 490 |
KlassPointer nonNullKlass = ClassGetHubNode.piCastNonNull(klass, SnippetAnchorNode.anchor()); |
491 |
||
492 |
if (length < 0) { |
|
52033
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
493 |
DeoptimizeNode.deopt(None, RuntimeConstraint); |
46344 | 494 |
} |
48861 | 495 |
int layoutHelper; |
496 |
if (knownElementKind == JavaKind.Illegal) { |
|
497 |
layoutHelper = readLayoutHelper(nonNullKlass); |
|
498 |
} else { |
|
499 |
runtimeAssert(knownLayoutHelper == readLayoutHelper(nonNullKlass), "layout mismatch"); |
|
500 |
layoutHelper = knownLayoutHelper; |
|
501 |
} |
|
43972 | 502 |
//@formatter:off |
503 |
// from src/share/vm/oops/klass.hpp: |
|
504 |
// |
|
505 |
// For arrays, layout helper is a negative number, containing four |
|
506 |
// distinct bytes, as follows: |
|
507 |
// MSB:[tag, hsz, ebt, log2(esz)]:LSB |
|
508 |
// where: |
|
509 |
// tag is 0x80 if the elements are oops, 0xC0 if non-oops |
|
510 |
// hsz is array header size in bytes (i.e., offset of first element) |
|
511 |
// ebt is the BasicType of the elements |
|
512 |
// esz is the element size in bytes |
|
513 |
//@formatter:on |
|
514 |
||
515 |
int headerSize = (layoutHelper >> layoutHelperHeaderSizeShift(INJECTED_VMCONFIG)) & layoutHelperHeaderSizeMask(INJECTED_VMCONFIG); |
|
516 |
int log2ElementSize = (layoutHelper >> layoutHelperLog2ElementSizeShift(INJECTED_VMCONFIG)) & layoutHelperLog2ElementSizeMask(INJECTED_VMCONFIG); |
|
517 |
||
54724 | 518 |
Object result = allocateArrayImpl(nonNullKlass, length, prototypeMarkWord, headerSize, log2ElementSize, fillContents, |
519 |
threadRegister, false, "dynamic type", useBulkZeroing, counters); |
|
46371 | 520 |
return piArrayCastToSnippetReplaceeStamp(verifyOop(result), length); |
43972 | 521 |
} |
522 |
||
523 |
/** |
|
524 |
* Calls the runtime stub for implementing MULTIANEWARRAY. |
|
525 |
*/ |
|
526 |
@Snippet |
|
52033
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
527 |
private static Object newmultiarray(KlassPointer hub, @ConstantParameter int rank, @VarargsParameter int[] dimensions) { |
43972 | 528 |
Word dims = DimensionsNode.allocaDimsArray(rank); |
529 |
ExplodeLoopNode.explodeLoop(); |
|
530 |
for (int i = 0; i < rank; i++) { |
|
46344 | 531 |
dims.writeInt(i * 4, dimensions[i], LocationIdentity.init()); |
43972 | 532 |
} |
52033
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
533 |
return newMultiArrayStub(hub, rank, dims); |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
534 |
} |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
535 |
|
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
536 |
private static Object newMultiArrayStub(KlassPointer hub, int rank, Word dims) { |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
537 |
if (useNullAllocationStubs(INJECTED_VMCONFIG)) { |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
538 |
return nonNullOrDeopt(newMultiArrayOrNull(NEW_MULTI_ARRAY_OR_NULL, hub, rank, dims)); |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
539 |
} else { |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
540 |
return newMultiArray(NEW_MULTI_ARRAY, hub, rank, dims); |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
541 |
} |
43972 | 542 |
} |
543 |
||
544 |
@Snippet |
|
52033
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
545 |
private static Object newmultiarrayPIC(KlassPointer hub, @ConstantParameter int rank, @VarargsParameter int[] dimensions) { |
46566 | 546 |
// Array type would be resolved by dominating resolution. |
46509 | 547 |
KlassPointer picHub = LoadConstantIndirectlyFixedNode.loadKlass(hub); |
548 |
return newmultiarray(picHub, rank, dimensions); |
|
43972 | 549 |
} |
550 |
||
46371 | 551 |
@NodeIntrinsic(value = ForeignCallNode.class, injectedStampIsNonNull = true) |
52033
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
552 |
private static native Object newMultiArray(@ConstantNodeParameter ForeignCallDescriptor descriptor, KlassPointer hub, int rank, Word dims); |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
553 |
|
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
554 |
@NodeIntrinsic(value = ForeignCallNode.class, injectedStampIsNonNull = false) |
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
555 |
private static native Object newMultiArrayOrNull(@ConstantNodeParameter ForeignCallDescriptor descriptor, KlassPointer hub, int rank, Word dims); |
43972 | 556 |
|
557 |
/** |
|
558 |
* Maximum number of long stores to emit when zeroing an object with a constant size. Larger |
|
559 |
* objects have their bodies initialized in a loop. |
|
560 |
*/ |
|
561 |
private static final int MAX_UNROLLED_OBJECT_ZEROING_STORES = 8; |
|
562 |
||
563 |
/** |
|
564 |
* Zero uninitialized memory in a newly allocated object, unrolling as necessary and ensuring |
|
565 |
* that stores are aligned. |
|
566 |
* |
|
567 |
* @param size number of bytes to zero |
|
568 |
* @param memory beginning of object which is being zeroed |
|
569 |
* @param constantSize is {@code size} known to be constant in the snippet |
|
570 |
* @param startOffset offset to begin zeroing. May not be word aligned. |
|
571 |
* @param manualUnroll maximally unroll zeroing |
|
54724 | 572 |
* @param useBulkZeroing apply bulk zeroing |
43972 | 573 |
*/ |
54724 | 574 |
private static void zeroMemory(long size, Word memory, boolean constantSize, int startOffset, boolean manualUnroll, |
575 |
boolean useBulkZeroing, Counters counters) { |
|
576 |
fillMemory(0, size, memory, constantSize, startOffset, manualUnroll, useBulkZeroing, counters); |
|
43972 | 577 |
} |
578 |
||
54724 | 579 |
private static void fillMemory(long value, long size, Word memory, boolean constantSize, int startOffset, boolean manualUnroll, |
580 |
boolean useBulkZeroing, Counters counters) { |
|
43972 | 581 |
ReplacementsUtil.runtimeAssert((size & 0x7) == 0, "unaligned object size"); |
582 |
int offset = startOffset; |
|
583 |
if ((offset & 0x7) != 0) { |
|
46344 | 584 |
memory.writeInt(offset, (int) value, LocationIdentity.init()); |
43972 | 585 |
offset += 4; |
586 |
} |
|
587 |
ReplacementsUtil.runtimeAssert((offset & 0x7) == 0, "unaligned offset"); |
|
52956 | 588 |
Counters theCounters = counters; |
43972 | 589 |
if (manualUnroll && ((size - offset) / 8) <= MAX_UNROLLED_OBJECT_ZEROING_STORES) { |
590 |
ReplacementsUtil.staticAssert(!constantSize, "size shouldn't be constant at instantiation time"); |
|
591 |
// This case handles arrays of constant length. Instead of having a snippet variant for |
|
592 |
// each length, generate a chain of stores of maximum length. Once it's inlined the |
|
593 |
// break statement will trim excess stores. |
|
52956 | 594 |
if (theCounters != null && theCounters.instanceSeqInit != null) { |
595 |
theCounters.instanceSeqInit.inc(); |
|
43972 | 596 |
} |
46344 | 597 |
|
43972 | 598 |
explodeLoop(); |
599 |
for (int i = 0; i < MAX_UNROLLED_OBJECT_ZEROING_STORES; i++, offset += 8) { |
|
600 |
if (offset == size) { |
|
601 |
break; |
|
602 |
} |
|
46344 | 603 |
memory.initializeLong(offset, value, LocationIdentity.init()); |
43972 | 604 |
} |
605 |
} else { |
|
606 |
// Use Word instead of int to avoid extension to long in generated code |
|
46459 | 607 |
Word off = WordFactory.signed(offset); |
55509 | 608 |
if (useBulkZeroing && value == 0 && probability(SLOW_PATH_PROBABILITY, (size - offset) >= getMinimalBulkZeroingSize(INJECTED_OPTIONVALUES))) { |
54724 | 609 |
if (theCounters != null && theCounters.instanceBulkInit != null) { |
610 |
theCounters.instanceBulkInit.inc(); |
|
43972 | 611 |
} |
54724 | 612 |
ZeroMemoryNode.zero(memory.add(off), size - offset, LocationIdentity.init()); |
43972 | 613 |
} else { |
54724 | 614 |
if (constantSize && ((size - offset) / 8) <= MAX_UNROLLED_OBJECT_ZEROING_STORES) { |
615 |
if (theCounters != null && theCounters.instanceSeqInit != null) { |
|
616 |
theCounters.instanceSeqInit.inc(); |
|
617 |
} |
|
618 |
explodeLoop(); |
|
619 |
} else { |
|
620 |
if (theCounters != null && theCounters.instanceLoopInit != null) { |
|
621 |
theCounters.instanceLoopInit.inc(); |
|
622 |
} |
|
43972 | 623 |
} |
54724 | 624 |
for (; off.rawValue() < size; off = off.add(8)) { |
625 |
memory.initializeLong(off, value, LocationIdentity.init()); |
|
626 |
} |
|
43972 | 627 |
} |
628 |
} |
|
629 |
} |
|
630 |
||
54724 | 631 |
@Fold |
632 |
static int getMinimalBulkZeroingSize(@InjectedParameter OptionValues optionValues) { |
|
633 |
return MinimalBulkZeroingSize.getValue(optionValues); |
|
634 |
} |
|
635 |
||
43972 | 636 |
/** |
637 |
* Fill uninitialized memory with garbage value in a newly allocated object, unrolling as |
|
638 |
* necessary and ensuring that stores are aligned. |
|
639 |
* |
|
640 |
* @param size number of bytes to zero |
|
641 |
* @param memory beginning of object which is being zeroed |
|
642 |
* @param constantSize is {@code size} known to be constant in the snippet |
|
643 |
* @param startOffset offset to begin zeroing. May not be word aligned. |
|
644 |
* @param manualUnroll maximally unroll zeroing |
|
645 |
*/ |
|
54084 | 646 |
private static void fillWithGarbage(long size, Word memory, boolean constantSize, int startOffset, boolean manualUnroll, Counters counters) { |
54724 | 647 |
fillMemory(0xfefefefefefefefeL, size, memory, constantSize, startOffset, manualUnroll, false, counters); |
43972 | 648 |
} |
649 |
||
650 |
/** |
|
651 |
* Formats some allocated memory with an object header and zeroes out the rest. |
|
652 |
*/ |
|
54084 | 653 |
private static Object formatObject(KlassPointer hub, long size, Word memory, Word compileTimePrototypeMarkWord, boolean fillContents, boolean constantSize, Counters counters) { |
43972 | 654 |
Word prototypeMarkWord = useBiasedLocking(INJECTED_VMCONFIG) ? hub.readWord(prototypeMarkWordOffset(INJECTED_VMCONFIG), PROTOTYPE_MARK_WORD_LOCATION) : compileTimePrototypeMarkWord; |
655 |
initializeObjectHeader(memory, prototypeMarkWord, hub); |
|
656 |
if (fillContents) { |
|
54724 | 657 |
zeroMemory(size, memory, constantSize, instanceHeaderSize(INJECTED_VMCONFIG), false, false, counters); |
43972 | 658 |
} else if (REPLACEMENTS_ASSERTIONS_ENABLED) { |
46344 | 659 |
fillWithGarbage(size, memory, constantSize, instanceHeaderSize(INJECTED_VMCONFIG), false, counters); |
43972 | 660 |
} |
46344 | 661 |
MembarNode.memoryBarrier(MemoryBarriers.STORE_STORE, LocationIdentity.init()); |
662 |
return memory.toObjectNonNull(); |
|
43972 | 663 |
} |
664 |
||
665 |
@Snippet |
|
52033
d6aa9ea2405d
8208686: [AOT] JVMTI ResourceExhausted event repeated for same allocation
dnsimon
parents:
51736
diff
changeset
|
666 |
private static void verifyHeap(@ConstantParameter Register threadRegister) { |
43972 | 667 |
Word thread = registerAsWord(threadRegister); |
668 |
Word topValue = readTlabTop(thread); |
|
46459 | 669 |
if (!topValue.equal(WordFactory.zero())) { |
43972 | 670 |
Word topValueContents = topValue.readWord(0, MARK_WORD_LOCATION); |
46459 | 671 |
if (topValueContents.equal(WordFactory.zero())) { |
43972 | 672 |
AssertionSnippets.vmMessageC(AssertionSnippets.ASSERTION_VM_MESSAGE_C, true, cstring("overzeroing of TLAB detected"), 0L, 0L, 0L); |
673 |
} |
|
674 |
} |
|
675 |
} |
|
676 |
||
677 |
/** |
|
678 |
* Formats some allocated memory with an object header and zeroes out the rest. |
|
679 |
*/ |
|
54084 | 680 |
private static Object formatArray(KlassPointer hub, long allocationSize, int length, int headerSize, Word memory, Word prototypeMarkWord, boolean fillContents, boolean maybeUnroll, |
54724 | 681 |
boolean useBulkZeroing, Counters counters) { |
46344 | 682 |
memory.writeInt(arrayLengthOffset(INJECTED_VMCONFIG), length, LocationIdentity.init()); |
43972 | 683 |
/* |
684 |
* store hub last as the concurrent garbage collectors assume length is valid if hub field |
|
685 |
* is not null |
|
686 |
*/ |
|
687 |
initializeObjectHeader(memory, prototypeMarkWord, hub); |
|
688 |
if (fillContents) { |
|
54724 | 689 |
zeroMemory(allocationSize, memory, false, headerSize, maybeUnroll, useBulkZeroing, counters); |
43972 | 690 |
} else if (REPLACEMENTS_ASSERTIONS_ENABLED) { |
46344 | 691 |
fillWithGarbage(allocationSize, memory, false, headerSize, maybeUnroll, counters); |
43972 | 692 |
} |
46344 | 693 |
MembarNode.memoryBarrier(MemoryBarriers.STORE_STORE, LocationIdentity.init()); |
694 |
return memory.toObjectNonNull(); |
|
695 |
} |
|
696 |
||
697 |
static class Counters { |
|
698 |
Counters(SnippetCounter.Group.Factory factory) { |
|
699 |
Group newInstance = factory.createSnippetCounterGroup("NewInstance"); |
|
700 |
Group newArray = factory.createSnippetCounterGroup("NewArray"); |
|
701 |
instanceSeqInit = new SnippetCounter(newInstance, "tlabSeqInit", "TLAB alloc with unrolled zeroing"); |
|
702 |
instanceLoopInit = new SnippetCounter(newInstance, "tlabLoopInit", "TLAB alloc with zeroing in a loop"); |
|
54724 | 703 |
instanceBulkInit = new SnippetCounter(newArray, "tlabBulkInit", "TLAB alloc with bulk zeroing"); |
46344 | 704 |
arrayLoopInit = new SnippetCounter(newArray, "tlabLoopInit", "TLAB alloc with zeroing in a loop"); |
705 |
stub = new SnippetCounter(newInstance, "stub", "alloc and zeroing via stub"); |
|
706 |
} |
|
707 |
||
708 |
final SnippetCounter instanceSeqInit; |
|
709 |
final SnippetCounter instanceLoopInit; |
|
54724 | 710 |
final SnippetCounter instanceBulkInit; |
46344 | 711 |
final SnippetCounter arrayLoopInit; |
712 |
final SnippetCounter stub; |
|
43972 | 713 |
} |
714 |
||
715 |
public static class Templates extends AbstractTemplates { |
|
716 |
||
55509 | 717 |
private final SnippetInfo allocateInstance = snippet(NewObjectSnippets.class, "allocateInstance", MARK_WORD_LOCATION, HUB_WRITE_LOCATION, TLAB_TOP_LOCATION, TLAB_END_LOCATION, |
718 |
PROTOTYPE_MARK_WORD_LOCATION); |
|
46344 | 719 |
private final SnippetInfo allocateInstancePIC = snippet(NewObjectSnippets.class, "allocateInstancePIC", MARK_WORD_LOCATION, HUB_WRITE_LOCATION, TLAB_TOP_LOCATION, |
55509 | 720 |
TLAB_END_LOCATION, PROTOTYPE_MARK_WORD_LOCATION); |
46344 | 721 |
private final SnippetInfo allocateArray = snippet(NewObjectSnippets.class, "allocateArray", MARK_WORD_LOCATION, HUB_WRITE_LOCATION, TLAB_TOP_LOCATION, TLAB_END_LOCATION); |
722 |
private final SnippetInfo allocateArrayPIC = snippet(NewObjectSnippets.class, "allocateArrayPIC", MARK_WORD_LOCATION, HUB_WRITE_LOCATION, TLAB_TOP_LOCATION, TLAB_END_LOCATION); |
|
723 |
private final SnippetInfo allocatePrimitiveArrayPIC = snippet(NewObjectSnippets.class, "allocatePrimitiveArrayPIC", MARK_WORD_LOCATION, HUB_WRITE_LOCATION, TLAB_TOP_LOCATION, |
|
43972 | 724 |
TLAB_END_LOCATION); |
46344 | 725 |
private final SnippetInfo allocateArrayDynamic = snippet(NewObjectSnippets.class, "allocateArrayDynamic", MARK_WORD_LOCATION, HUB_WRITE_LOCATION, TLAB_TOP_LOCATION, |
43972 | 726 |
TLAB_END_LOCATION); |
46344 | 727 |
private final SnippetInfo allocateInstanceDynamic = snippet(NewObjectSnippets.class, "allocateInstanceDynamic", MARK_WORD_LOCATION, HUB_WRITE_LOCATION, TLAB_TOP_LOCATION, |
55509 | 728 |
TLAB_END_LOCATION, PROTOTYPE_MARK_WORD_LOCATION, CLASS_STATE_LOCATION); |
46344 | 729 |
private final SnippetInfo newmultiarray = snippet(NewObjectSnippets.class, "newmultiarray", TLAB_TOP_LOCATION, TLAB_END_LOCATION); |
730 |
private final SnippetInfo newmultiarrayPIC = snippet(NewObjectSnippets.class, "newmultiarrayPIC", TLAB_TOP_LOCATION, TLAB_END_LOCATION); |
|
43972 | 731 |
private final SnippetInfo verifyHeap = snippet(NewObjectSnippets.class, "verifyHeap"); |
732 |
private final GraalHotSpotVMConfig config; |
|
46344 | 733 |
private final Counters counters; |
43972 | 734 |
|
46640 | 735 |
public Templates(OptionValues options, Iterable<DebugHandlersFactory> factories, SnippetCounter.Group.Factory factory, HotSpotProviders providers, TargetDescription target, |
736 |
GraalHotSpotVMConfig config) { |
|
737 |
super(options, factories, providers, providers.getSnippetReflection(), target); |
|
43972 | 738 |
this.config = config; |
46344 | 739 |
counters = new Counters(factory); |
43972 | 740 |
} |
741 |
||
742 |
/** |
|
743 |
* Lowers a {@link NewInstanceNode}. |
|
744 |
*/ |
|
745 |
public void lower(NewInstanceNode newInstanceNode, HotSpotRegistersProvider registers, LoweringTool tool) { |
|
746 |
StructuredGraph graph = newInstanceNode.graph(); |
|
747 |
HotSpotResolvedObjectType type = (HotSpotResolvedObjectType) newInstanceNode.instanceClass(); |
|
748 |
assert !type.isArray(); |
|
749 |
ConstantNode hub = ConstantNode.forConstant(KlassPointerStamp.klassNonNull(), type.klass(), providers.getMetaAccess(), graph); |
|
54084 | 750 |
long size = instanceSize(type); |
43972 | 751 |
|
46344 | 752 |
OptionValues localOptions = graph.getOptions(); |
753 |
SnippetInfo snippet = GeneratePIC.getValue(localOptions) ? allocateInstancePIC : allocateInstance; |
|
43972 | 754 |
Arguments args = new Arguments(snippet, graph.getGuardsStage(), tool.getLoweringStage()); |
755 |
args.addConst("size", size); |
|
756 |
args.add("hub", hub); |
|
757 |
args.add("prototypeMarkWord", type.prototypeMarkWord()); |
|
758 |
args.addConst("fillContents", newInstanceNode.fillContents()); |
|
759 |
args.addConst("threadRegister", registers.getThreadRegister()); |
|
760 |
args.addConst("constantSize", true); |
|
46344 | 761 |
args.addConst("typeContext", ProfileAllocations.getValue(localOptions) ? type.toJavaName(false) : ""); |
762 |
args.addConst("counters", counters); |
|
43972 | 763 |
|
49451 | 764 |
SnippetTemplate template = template(newInstanceNode, args); |
46640 | 765 |
graph.getDebug().log("Lowering allocateInstance in %s: node=%s, template=%s, arguments=%s", graph, newInstanceNode, template, args); |
43972 | 766 |
template.instantiate(providers.getMetaAccess(), newInstanceNode, DEFAULT_REPLACER, args); |
767 |
} |
|
768 |
||
769 |
/** |
|
770 |
* Lowers a {@link NewArrayNode}. |
|
771 |
*/ |
|
772 |
public void lower(NewArrayNode newArrayNode, HotSpotRegistersProvider registers, LoweringTool tool) { |
|
773 |
StructuredGraph graph = newArrayNode.graph(); |
|
774 |
ResolvedJavaType elementType = newArrayNode.elementType(); |
|
775 |
HotSpotResolvedObjectType arrayType = (HotSpotResolvedObjectType) elementType.getArrayClass(); |
|
776 |
JavaKind elementKind = elementType.getJavaKind(); |
|
777 |
ConstantNode hub = ConstantNode.forConstant(KlassPointerStamp.klassNonNull(), arrayType.klass(), providers.getMetaAccess(), graph); |
|
50858 | 778 |
final int headerSize = tool.getMetaAccess().getArrayBaseOffset(elementKind); |
779 |
int log2ElementSize = CodeUtil.log2(tool.getMetaAccess().getArrayIndexScale(elementKind)); |
|
43972 | 780 |
|
46344 | 781 |
OptionValues localOptions = graph.getOptions(); |
43972 | 782 |
SnippetInfo snippet; |
46344 | 783 |
if (GeneratePIC.getValue(localOptions)) { |
43972 | 784 |
if (elementType.isPrimitive()) { |
785 |
snippet = allocatePrimitiveArrayPIC; |
|
786 |
} else { |
|
787 |
snippet = allocateArrayPIC; |
|
788 |
} |
|
789 |
} else { |
|
790 |
snippet = allocateArray; |
|
791 |
} |
|
792 |
||
793 |
Arguments args = new Arguments(snippet, graph.getGuardsStage(), tool.getLoweringStage()); |
|
794 |
args.add("hub", hub); |
|
795 |
ValueNode length = newArrayNode.length(); |
|
796 |
args.add("length", length.isAlive() ? length : graph.addOrUniqueWithInputs(length)); |
|
797 |
assert arrayType.prototypeMarkWord() == lookupArrayClass(tool, JavaKind.Object).prototypeMarkWord() : "all array types are assumed to have the same prototypeMarkWord"; |
|
798 |
args.add("prototypeMarkWord", arrayType.prototypeMarkWord()); |
|
799 |
args.addConst("headerSize", headerSize); |
|
800 |
args.addConst("log2ElementSize", log2ElementSize); |
|
801 |
args.addConst("fillContents", newArrayNode.fillContents()); |
|
802 |
args.addConst("threadRegister", registers.getThreadRegister()); |
|
803 |
args.addConst("maybeUnroll", length.isConstant()); |
|
46344 | 804 |
args.addConst("typeContext", ProfileAllocations.getValue(localOptions) ? arrayType.toJavaName(false) : ""); |
54724 | 805 |
args.addConst("useBulkZeroing", tool.getLowerer().supportBulkZeroing()); |
46344 | 806 |
args.addConst("counters", counters); |
49451 | 807 |
SnippetTemplate template = template(newArrayNode, args); |
46640 | 808 |
graph.getDebug().log("Lowering allocateArray in %s: node=%s, template=%s, arguments=%s", graph, newArrayNode, template, args); |
43972 | 809 |
template.instantiate(providers.getMetaAccess(), newArrayNode, DEFAULT_REPLACER, args); |
810 |
} |
|
811 |
||
812 |
public void lower(DynamicNewInstanceNode newInstanceNode, HotSpotRegistersProvider registers, LoweringTool tool) { |
|
813 |
Arguments args = new Arguments(allocateInstanceDynamic, newInstanceNode.graph().getGuardsStage(), tool.getLoweringStage()); |
|
814 |
args.add("type", newInstanceNode.getInstanceType()); |
|
815 |
ValueNode classClass = newInstanceNode.getClassClass(); |
|
816 |
assert classClass != null; |
|
817 |
args.add("classClass", classClass); |
|
818 |
args.addConst("fillContents", newInstanceNode.fillContents()); |
|
819 |
args.addConst("threadRegister", registers.getThreadRegister()); |
|
46344 | 820 |
args.addConst("counters", counters); |
43972 | 821 |
|
49451 | 822 |
SnippetTemplate template = template(newInstanceNode, args); |
43972 | 823 |
template.instantiate(providers.getMetaAccess(), newInstanceNode, DEFAULT_REPLACER, args); |
824 |
} |
|
825 |
||
826 |
public void lower(DynamicNewArrayNode newArrayNode, HotSpotRegistersProvider registers, LoweringTool tool) { |
|
827 |
StructuredGraph graph = newArrayNode.graph(); |
|
54724 | 828 |
Arguments args = new Arguments(allocateArrayDynamic, graph.getGuardsStage(), tool.getLoweringStage()); |
43972 | 829 |
args.add("elementType", newArrayNode.getElementType()); |
830 |
ValueNode voidClass = newArrayNode.getVoidClass(); |
|
831 |
assert voidClass != null; |
|
832 |
args.add("voidClass", voidClass); |
|
833 |
ValueNode length = newArrayNode.length(); |
|
834 |
args.add("length", length.isAlive() ? length : graph.addOrUniqueWithInputs(length)); |
|
835 |
args.addConst("fillContents", newArrayNode.fillContents()); |
|
836 |
args.addConst("threadRegister", registers.getThreadRegister()); |
|
837 |
/* |
|
838 |
* We use Kind.Illegal as a marker value instead of null because constant snippet |
|
839 |
* parameters cannot be null. |
|
840 |
*/ |
|
841 |
args.addConst("knownElementKind", newArrayNode.getKnownElementKind() == null ? JavaKind.Illegal : newArrayNode.getKnownElementKind()); |
|
842 |
if (newArrayNode.getKnownElementKind() != null) { |
|
843 |
args.addConst("knownLayoutHelper", lookupArrayClass(tool, newArrayNode.getKnownElementKind()).layoutHelper()); |
|
844 |
} else { |
|
845 |
args.addConst("knownLayoutHelper", 0); |
|
846 |
} |
|
54724 | 847 |
args.addConst("useBulkZeroing", tool.getLowerer().supportBulkZeroing()); |
43972 | 848 |
args.add("prototypeMarkWord", lookupArrayClass(tool, JavaKind.Object).prototypeMarkWord()); |
46344 | 849 |
args.addConst("counters", counters); |
49451 | 850 |
SnippetTemplate template = template(newArrayNode, args); |
43972 | 851 |
template.instantiate(providers.getMetaAccess(), newArrayNode, DEFAULT_REPLACER, args); |
852 |
} |
|
853 |
||
854 |
private static HotSpotResolvedObjectType lookupArrayClass(LoweringTool tool, JavaKind kind) { |
|
855 |
return (HotSpotResolvedObjectType) tool.getMetaAccess().lookupJavaType(kind == JavaKind.Object ? Object.class : kind.toJavaClass()).getArrayClass(); |
|
856 |
} |
|
857 |
||
858 |
public void lower(NewMultiArrayNode newmultiarrayNode, LoweringTool tool) { |
|
859 |
StructuredGraph graph = newmultiarrayNode.graph(); |
|
46344 | 860 |
OptionValues localOptions = graph.getOptions(); |
43972 | 861 |
int rank = newmultiarrayNode.dimensionCount(); |
862 |
ValueNode[] dims = new ValueNode[rank]; |
|
863 |
for (int i = 0; i < newmultiarrayNode.dimensionCount(); i++) { |
|
864 |
dims[i] = newmultiarrayNode.dimension(i); |
|
865 |
} |
|
866 |
HotSpotResolvedObjectType type = (HotSpotResolvedObjectType) newmultiarrayNode.type(); |
|
867 |
ConstantNode hub = ConstantNode.forConstant(KlassPointerStamp.klassNonNull(), type.klass(), providers.getMetaAccess(), graph); |
|
868 |
||
46344 | 869 |
SnippetInfo snippet = GeneratePIC.getValue(localOptions) ? newmultiarrayPIC : newmultiarray; |
43972 | 870 |
Arguments args = new Arguments(snippet, graph.getGuardsStage(), tool.getLoweringStage()); |
871 |
args.add("hub", hub); |
|
872 |
args.addConst("rank", rank); |
|
873 |
args.addVarargs("dimensions", int.class, StampFactory.forKind(JavaKind.Int), dims); |
|
49451 | 874 |
template(newmultiarrayNode, args).instantiate(providers.getMetaAccess(), newmultiarrayNode, DEFAULT_REPLACER, args); |
43972 | 875 |
} |
876 |
||
54084 | 877 |
private static long instanceSize(HotSpotResolvedObjectType type) { |
878 |
long size = type.instanceSize(); |
|
43972 | 879 |
assert size >= 0; |
880 |
return size; |
|
881 |
} |
|
882 |
||
883 |
public void lower(VerifyHeapNode verifyHeapNode, HotSpotRegistersProvider registers, LoweringTool tool) { |
|
884 |
if (config.cAssertions) { |
|
885 |
Arguments args = new Arguments(verifyHeap, verifyHeapNode.graph().getGuardsStage(), tool.getLoweringStage()); |
|
886 |
args.addConst("threadRegister", registers.getThreadRegister()); |
|
887 |
||
49451 | 888 |
SnippetTemplate template = template(verifyHeapNode, args); |
43972 | 889 |
template.instantiate(providers.getMetaAccess(), verifyHeapNode, DEFAULT_REPLACER, args); |
890 |
} else { |
|
891 |
GraphUtil.removeFixedWithUnusedInputs(verifyHeapNode); |
|
892 |
} |
|
893 |
} |
|
894 |
} |
|
895 |
} |