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