# HG changeset patch # User Stefan Anzinger # Date 1446828278 -3600 # Node ID 225483fd8f3b8f1dd227e2d6ff1a02b2671ff085 # Parent 26618cb3ff27e878d6bbdc4d0989ab0e5cf097ba Allow to specify whether NewArrayStub should fill the array with zero or not diff -r 26618cb3ff27 -r 225483fd8f3b graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotBackend.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotBackend.java Fri Nov 06 12:38:19 2015 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotBackend.java Fri Nov 06 17:44:38 2015 +0100 @@ -154,7 +154,7 @@ /** * New array stub. */ - public static final ForeignCallDescriptor NEW_ARRAY = new ForeignCallDescriptor("new_array", Object.class, Word.class, int.class); + public static final ForeignCallDescriptor NEW_ARRAY = new ForeignCallDescriptor("new_array", Object.class, Word.class, int.class, boolean.class); /** * New insstance stub. diff -r 26618cb3ff27 -r 225483fd8f3b graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/NewObjectSnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/NewObjectSnippets.java Fri Nov 06 12:38:19 2015 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/NewObjectSnippets.java Fri Nov 06 17:44:38 2015 +0100 @@ -264,14 +264,14 @@ newarray_loopInit.inc(); result = formatArray(hub, allocationSize, length, headerSize, top, prototypeMarkWord, fillContents, maybeUnroll, true); } else { - result = newArray(HotSpotBackend.NEW_ARRAY, hub, length); + result = newArray(HotSpotBackend.NEW_ARRAY, hub, length, fillContents); } profileAllocation("array", allocationSize, typeContext); return result; } @NodeIntrinsic(ForeignCallNode.class) - public static native Object newArray(@ConstantNodeParameter ForeignCallDescriptor descriptor, KlassPointer hub, int length); + public static native Object newArray(@ConstantNodeParameter ForeignCallDescriptor descriptor, KlassPointer hub, int length, boolean fillContents); public static final ForeignCallDescriptor DYNAMIC_NEW_ARRAY = new ForeignCallDescriptor("dynamic_new_array", Object.class, Class.class, int.class); public static final ForeignCallDescriptor DYNAMIC_NEW_INSTANCE = new ForeignCallDescriptor("dynamic_new_instance", Object.class, Class.class); @@ -537,7 +537,6 @@ args.addConst("threadRegister", registers.getThreadRegister()); args.addConst("maybeUnroll", length.isConstant()); args.addConst("typeContext", ProfileAllocations.getValue() ? arrayType.toJavaName(false) : ""); - SnippetTemplate template = template(args); Debug.log("Lowering allocateArray in %s: node=%s, template=%s, arguments=%s", graph, newArrayNode, template, args); template.instantiate(providers.getMetaAccess(), newArrayNode, DEFAULT_REPLACER, args); diff -r 26618cb3ff27 -r 225483fd8f3b graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewArrayStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewArrayStub.java Fri Nov 06 12:38:19 2015 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewArrayStub.java Fri Nov 06 17:44:38 2015 +0100 @@ -76,10 +76,10 @@ HotSpotResolvedObjectType intArrayType = (HotSpotResolvedObjectType) providers.getMetaAccess().lookupJavaType(int[].class); int count = method.getSignature().getParameterCount(false); Object[] args = new Object[count]; - assert checkConstArg(2, "intArrayHub"); - assert checkConstArg(3, "threadRegister"); - args[2] = ConstantNode.forConstant(KlassPointerStamp.klassNonNull(), intArrayType.klass(), null); - args[3] = providers.getRegisters().getThreadRegister(); + assert checkConstArg(3, "intArrayHub"); + assert checkConstArg(4, "threadRegister"); + args[3] = ConstantNode.forConstant(KlassPointerStamp.klassNonNull(), intArrayType.klass(), null); + args[4] = providers.getRegisters().getThreadRegister(); return args; } @@ -94,10 +94,11 @@ * * @param hub the hub of the object to be allocated * @param length the length of the array + * @param fillContents Should the array be filled with zeroes? * @param intArrayHub the hub for {@code int[].class} */ @Snippet - private static Object newArray(KlassPointer hub, int length, @ConstantParameter KlassPointer intArrayHub, @ConstantParameter Register threadRegister) { + private static Object newArray(KlassPointer hub, int length, boolean fillContents, @ConstantParameter KlassPointer intArrayHub, @ConstantParameter Register threadRegister) { int layoutHelper = loadKlassLayoutHelperIntrinsic(hub); int log2ElementSize = (layoutHelper >> layoutHelperLog2ElementSizeShift()) & layoutHelperLog2ElementSizeMask(); int headerSize = (layoutHelper >> layoutHelperHeaderSizeShift()) & layoutHelperHeaderSizeMask(); @@ -118,7 +119,7 @@ if (logging()) { printf("newArray: allocated new array at %p\n", memory.rawValue()); } - return verifyObject(formatArray(hub, sizeInBytes, length, headerSize, memory, Word.unsigned(arrayPrototypeMarkWord()), true, false, false)); + return verifyObject(formatArray(hub, sizeInBytes, length, headerSize, memory, Word.unsigned(arrayPrototypeMarkWord()), fillContents, false, false)); } } if (logging()) {