forked from oracle/graal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GR-12682] Use bulk zeroing when instantiating large arrays.
PullRequest: graal/3288
- Loading branch information
Showing
10 changed files
with
320 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 82 additions & 32 deletions
114
...lvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/replacements/NewObjectSnippets.java
Large diffs are not rendered by default.
Oops, something went wrong.
71 changes: 71 additions & 0 deletions
71
.../org.graalvm.compiler.lir.amd64/src/org/graalvm/compiler/lir/amd64/AMD64ZeroMemoryOp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
package org.graalvm.compiler.lir.amd64; | ||
|
||
import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.COMPOSITE; | ||
import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.REG; | ||
|
||
import org.graalvm.compiler.asm.amd64.AMD64MacroAssembler; | ||
import org.graalvm.compiler.core.common.LIRKind; | ||
import org.graalvm.compiler.lir.LIRInstructionClass; | ||
import org.graalvm.compiler.lir.Opcode; | ||
import org.graalvm.compiler.lir.asm.CompilationResultBuilder; | ||
|
||
import jdk.vm.ci.amd64.AMD64; | ||
import jdk.vm.ci.amd64.AMD64Kind; | ||
import jdk.vm.ci.code.RegisterValue; | ||
import jdk.vm.ci.meta.Value; | ||
|
||
/** | ||
* Zeros a chunk of memory using rep stosb. | ||
*/ | ||
@Opcode("ZERO_MEMORY") | ||
public final class AMD64ZeroMemoryOp extends AMD64LIRInstruction { | ||
|
||
public static final LIRInstructionClass<AMD64ZeroMemoryOp> TYPE = LIRInstructionClass.create(AMD64ZeroMemoryOp.class); | ||
|
||
@Use({COMPOSITE}) protected AMD64AddressValue pointer; | ||
@Use({REG}) protected RegisterValue length; | ||
|
||
@Temp protected Value pointerTemp; | ||
@Temp protected Value valueTemp; | ||
|
||
public AMD64ZeroMemoryOp(AMD64AddressValue pointer, RegisterValue length) { | ||
super(TYPE); | ||
this.pointer = pointer; | ||
this.length = length; | ||
|
||
this.pointerTemp = AMD64.rdi.asValue(LIRKind.value(AMD64Kind.QWORD)); | ||
this.valueTemp = AMD64.rax.asValue(LIRKind.value(AMD64Kind.QWORD)); | ||
} | ||
|
||
@Override | ||
public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) { | ||
assert AMD64.rcx.equals(length.getRegister()); | ||
masm.leaq(AMD64.rdi, pointer.toAddress()); | ||
masm.xorq(AMD64.rax, AMD64.rax); | ||
masm.repStosb(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...lvm.compiler.replacements/src/org/graalvm/compiler/replacements/nodes/ZeroMemoryNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
package org.graalvm.compiler.replacements.nodes; | ||
|
||
import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_8; | ||
import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_8; | ||
|
||
import org.graalvm.compiler.core.common.type.StampFactory; | ||
import org.graalvm.compiler.graph.NodeClass; | ||
import org.graalvm.compiler.nodeinfo.InputType; | ||
import org.graalvm.compiler.nodeinfo.NodeInfo; | ||
import org.graalvm.compiler.nodes.ValueNode; | ||
import org.graalvm.compiler.nodes.memory.FixedAccessNode; | ||
import org.graalvm.compiler.nodes.memory.address.AddressNode; | ||
import org.graalvm.compiler.nodes.memory.address.OffsetAddressNode; | ||
import org.graalvm.compiler.nodes.spi.LIRLowerable; | ||
import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool; | ||
import org.graalvm.compiler.word.Word; | ||
import org.graalvm.word.LocationIdentity; | ||
|
||
/** | ||
* Zeros a chunk of memory. | ||
*/ | ||
@NodeInfo(nameTemplate = "ZeroMemory#{p#location/s}", allowedUsageTypes = {InputType.Memory}, cycles = CYCLES_8, size = SIZE_8) | ||
public class ZeroMemoryNode extends FixedAccessNode implements LIRLowerable { | ||
public static final NodeClass<ZeroMemoryNode> TYPE = NodeClass.create(ZeroMemoryNode.class); | ||
|
||
@Input ValueNode length; | ||
|
||
public ZeroMemoryNode(ValueNode address, ValueNode length, LocationIdentity locationIdentity) { | ||
this(OffsetAddressNode.create(address), length, locationIdentity, BarrierType.NONE); | ||
} | ||
|
||
public ZeroMemoryNode(AddressNode address, ValueNode length, LocationIdentity locationIdentity, BarrierType type) { | ||
super(TYPE, address, locationIdentity, StampFactory.forVoid(), type); | ||
this.length = length; | ||
} | ||
|
||
@Override | ||
public void generate(NodeLIRBuilderTool gen) { | ||
gen.getLIRGeneratorTool().getArithmetic().emitZeroMemory(gen.operand(getAddress()), gen.operand(length)); | ||
} | ||
|
||
@Override | ||
public boolean canNullCheck() { | ||
return false; | ||
} | ||
|
||
@NodeIntrinsic | ||
public static native void zero(Word address, long length, @ConstantNodeParameter LocationIdentity locationIdentity); | ||
} |
51 changes: 51 additions & 0 deletions
51
compiler/src/org.graalvm.micro.benchmarks/src/micro/benchmarks/ArrayAllocationBenchmark.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
package micro.benchmarks; | ||
|
||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.Param; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.annotations.Threads; | ||
import org.openjdk.jmh.annotations.Warmup; | ||
|
||
/** | ||
* Benchmarks cost of ArrayList. | ||
*/ | ||
public class ArrayAllocationBenchmark extends BenchmarkBase { | ||
|
||
@State(Scope.Benchmark) | ||
public static class ThreadState { | ||
@Param({"128", "256", "512", "1024", "2048", "4096", "8192", "16384", "32768", "65536", "131072"}) int size; | ||
byte[] result; | ||
} | ||
|
||
@Benchmark | ||
@Threads(8) | ||
@Warmup(iterations = 10) | ||
public void arrayAllocate(ThreadState state) { | ||
state.result = new byte[state.size]; | ||
} | ||
} |