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