< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/NewObjectSnippets.java

Print this page
rev 52509 : [mq]: graal2

*** 267,280 **** if (probability(SLOW_PATH_PROBABILITY, DynamicNewInstanceNode.throwsInstantiationException(type, classClass))) { DeoptimizeNode.deopt(None, RuntimeConstraint); } ! return PiNode.piCastToSnippetReplaceeStamp(allocateInstanceDynamicHelper(fillContents, threadRegister, options, counters, nonNullType)); } ! private static Object allocateInstanceDynamicHelper(boolean fillContents, Register threadRegister, OptionValues options, Counters counters, Class<?> nonNullType) { KlassPointer hub = ClassGetHubNode.readClass(nonNullType); if (probability(FAST_PATH_PROBABILITY, !hub.isNull())) { KlassPointer nonNullHub = ClassGetHubNode.piCastNonNull(hub, SnippetAnchorNode.anchor()); if (probability(FAST_PATH_PROBABILITY, isInstanceKlassFullyInitialized(nonNullHub))) { --- 267,280 ---- if (probability(SLOW_PATH_PROBABILITY, DynamicNewInstanceNode.throwsInstantiationException(type, classClass))) { DeoptimizeNode.deopt(None, RuntimeConstraint); } ! return PiNode.piCastToSnippetReplaceeStamp(allocateInstanceDynamicHelper(type, fillContents, threadRegister, options, counters, nonNullType)); } ! private static Object allocateInstanceDynamicHelper(Class<?> type, boolean fillContents, Register threadRegister, OptionValues options, Counters counters, Class<?> nonNullType) { KlassPointer hub = ClassGetHubNode.readClass(nonNullType); if (probability(FAST_PATH_PROBABILITY, !hub.isNull())) { KlassPointer nonNullHub = ClassGetHubNode.piCastNonNull(hub, SnippetAnchorNode.anchor()); if (probability(FAST_PATH_PROBABILITY, isInstanceKlassFullyInitialized(nonNullHub))) {
*** 295,306 **** } } else { DeoptimizeNode.deopt(None, RuntimeConstraint); } } ! DeoptimizeNode.deopt(None, RuntimeConstraint); ! return null; } /** * Maximum array length for which fast path allocation is used. */ --- 295,305 ---- } } else { DeoptimizeNode.deopt(None, RuntimeConstraint); } } ! return dynamicNewInstanceStub(type); } /** * Maximum array length for which fast path allocation is used. */
*** 385,394 **** --- 384,411 ---- @NodeIntrinsic(value = ForeignCallNode.class, injectedStampIsNonNull = false) private static native Object newArrayOrNull(@ConstantNodeParameter ForeignCallDescriptor descriptor, KlassPointer hub, int length); /** + * New dynamic array stub that throws an {@link OutOfMemoryError} on allocation failure. + */ + public static final ForeignCallDescriptor DYNAMIC_NEW_INSTANCE = new ForeignCallDescriptor("dynamic_new_instance", Object.class, Class.class); + + /** + * New dynamic array stub that returns null on allocation failure. + */ + public static final ForeignCallDescriptor DYNAMIC_NEW_INSTANCE_OR_NULL = new ForeignCallDescriptor("dynamic_new_instance_or_null", Object.class, Class.class); + + public static Object dynamicNewInstanceStub(Class<?> elementType) { + if (useNullAllocationStubs(INJECTED_VMCONFIG)) { + return nonNullOrDeopt(dynamicNewInstanceOrNull(DYNAMIC_NEW_INSTANCE_OR_NULL, elementType)); + } else { + return dynamicNewInstance(DYNAMIC_NEW_INSTANCE, elementType); + } + } + + /** * Deoptimizes if {@code obj == null} otherwise returns {@code obj}. */ private static Object nonNullOrDeopt(Object obj) { if (obj == null) { DeoptimizeNode.deopt(None, RuntimeConstraint);
< prev index next >