# HG changeset patch # User adlertz # Date 1418322902 -3600 # Node ID aa4f2e3629ca3219a6854d0b5578b1984413b8ab # Parent e8634d0e6667b37c2b494373cd533c987ece722b Added card table PIC support diff -r e8634d0e6667 -r aa4f2e3629ca graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotCardTableAddressOp.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotCardTableAddressOp.java Thu Dec 11 19:35:02 2014 +0100 @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2014, 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. + * + * 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 com.oracle.graal.hotspot.amd64; + +import com.oracle.graal.api.code.*; +import com.oracle.graal.api.meta.*; +import com.oracle.graal.asm.amd64.*; +import com.oracle.graal.hotspot.meta.HotSpotCodeCacheProvider.*; +import com.oracle.graal.lir.amd64.*; +import com.oracle.graal.lir.asm.*; +import com.oracle.graal.hotspot.HotSpotGraalRuntime; + +public class AMD64HotSpotCardTableAddressOp extends AMD64LIRInstruction { + + @Def({OperandFlag.REG}) private AllocatableValue result; + + public AMD64HotSpotCardTableAddressOp(AllocatableValue result) { + this.result = result; + } + + @Override + public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler asm) { + Kind hostWordKind = HotSpotGraalRuntime.getHostWordKind(); + int alignment = hostWordKind.getBitCount() / Byte.SIZE; + JavaConstant address = JavaConstant.forIntegerKind(hostWordKind, 0); + // recordDataReferenceInCode forces the mov to be rip-relative + asm.movq(ValueUtil.asRegister(result), (AMD64Address) crb.recordDataReferenceInCode(address, alignment)); + MarkId.recordMark(crb, MarkId.CARD_TABLE_ADDRESS); + } + +} diff -r e8634d0e6667 -r aa4f2e3629ca graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotCardTableShiftOp.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotCardTableShiftOp.java Thu Dec 11 19:35:02 2014 +0100 @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2014, 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. + * + * 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 com.oracle.graal.hotspot.amd64; + +import com.oracle.graal.api.code.*; +import com.oracle.graal.api.meta.*; +import com.oracle.graal.asm.amd64.*; +import com.oracle.graal.hotspot.meta.HotSpotCodeCacheProvider.*; +import com.oracle.graal.lir.amd64.*; +import com.oracle.graal.lir.asm.*; +import com.oracle.graal.hotspot.HotSpotGraalRuntime; + +public class AMD64HotSpotCardTableShiftOp extends AMD64LIRInstruction { + + @Def({OperandFlag.REG, OperandFlag.ILLEGAL}) private AllocatableValue result; + + public AMD64HotSpotCardTableShiftOp(AllocatableValue result) { + this.result = result; + } + + @Override + public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler asm) { + Kind hostWordKind = HotSpotGraalRuntime.getHostWordKind(); + int alignment = Kind.Int.getBitCount() / Byte.SIZE; + JavaConstant shift = JavaConstant.forIntegerKind(hostWordKind, 0); + // recordDataReferenceInCode forces the mov to be rip-relative + asm.movq(ValueUtil.asRegister(result), (AMD64Address) crb.recordDataReferenceInCode(shift, alignment)); + MarkId.recordMark(crb, MarkId.CARD_TABLE_SHIFT); + } +} diff -r e8634d0e6667 -r aa4f2e3629ca graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java Thu Dec 11 15:46:06 2014 +0100 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java Thu Dec 11 19:35:02 2014 +0100 @@ -211,6 +211,20 @@ append(new AMD64HotSpotLeaveUnpackFramesStackFrameOp(threadRegister, config.threadLastJavaSpOffset(), config.threadLastJavaPcOffset(), config.threadLastJavaFpOffset(), saveRegisterOp)); } + @Override + public Value emitCardTableShift() { + Variable result = newVariable(LIRKind.value(Kind.Long)); + append(new AMD64HotSpotCardTableShiftOp(result)); + return result; + } + + @Override + public Value emitCardTableAddress() { + Variable result = newVariable(LIRKind.value(Kind.Long)); + append(new AMD64HotSpotCardTableAddressOp(result)); + return result; + } + /** * @param savedRegisters the registers saved by this operation which may be subject to pruning * @param savedRegisterLocations the slots to which the registers are saved diff -r e8634d0e6667 -r aa4f2e3629ca graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotLIRGenerator.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotLIRGenerator.java Thu Dec 11 15:46:06 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotLIRGenerator.java Thu Dec 11 19:35:02 2014 +0100 @@ -127,6 +127,14 @@ throw GraalInternalError.unimplemented(); } + default Value emitCardTableShift() { + throw GraalInternalError.unimplemented(); + } + + default Value emitCardTableAddress() { + throw GraalInternalError.unimplemented(); + } + /** * Gets a stack slot for a lock at a given lock nesting depth. */ diff -r e8634d0e6667 -r aa4f2e3629ca graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java Thu Dec 11 15:46:06 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java Thu Dec 11 19:35:02 2014 +0100 @@ -1554,6 +1554,8 @@ @HotSpotVMConstant(name = "CodeInstaller::POLL_RETURN_NEAR") @Stable public int codeInstallerMarkIdPollReturnNear; @HotSpotVMConstant(name = "CodeInstaller::POLL_FAR") @Stable public int codeInstallerMarkIdPollFar; @HotSpotVMConstant(name = "CodeInstaller::POLL_RETURN_FAR") @Stable public int codeInstallerMarkIdPollReturnFar; + @HotSpotVMConstant(name = "CodeInstaller::CARD_TABLE_SHIFT") @Stable public int codeInstallerMarkIdCardTableShift; + @HotSpotVMConstant(name = "CodeInstaller::CARD_TABLE_ADDRESS") @Stable public int codeInstallerMarkIdCardTableAddress; @HotSpotVMConstant(name = "CodeInstaller::INVOKE_INVALID") @Stable public int codeInstallerMarkIdInvokeInvalid; public boolean check() { diff -r e8634d0e6667 -r aa4f2e3629ca graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotCodeCacheProvider.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotCodeCacheProvider.java Thu Dec 11 15:46:06 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotCodeCacheProvider.java Thu Dec 11 19:35:02 2014 +0100 @@ -80,7 +80,9 @@ POLL_NEAR(config().codeInstallerMarkIdPollNear), POLL_RETURN_NEAR(config().codeInstallerMarkIdPollReturnNear), POLL_FAR(config().codeInstallerMarkIdPollFar), - POLL_RETURN_FAR(config().codeInstallerMarkIdPollReturnFar); + POLL_RETURN_FAR(config().codeInstallerMarkIdPollReturnFar), + CARD_TABLE_SHIFT(config().codeInstallerMarkIdCardTableShift), + CARD_TABLE_ADDRESS(config().codeInstallerMarkIdCardTableAddress); private final int value; diff -r e8634d0e6667 -r aa4f2e3629ca graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/CardTableAddressNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/CardTableAddressNode.java Thu Dec 11 19:35:02 2014 +0100 @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2014, 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. + * + * 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 com.oracle.graal.hotspot.replacements; + +import com.oracle.graal.api.meta.*; +import com.oracle.graal.compiler.common.type.*; +import com.oracle.graal.hotspot.*; +import com.oracle.graal.nodeinfo.*; +import com.oracle.graal.nodes.calc.*; +import com.oracle.graal.nodes.spi.*; + +@NodeInfo +public class CardTableAddressNode extends FloatingNode implements LIRLowerable { + + public static CardTableAddressNode create() { + return new CardTableAddressNode(); + } + + protected CardTableAddressNode() { + super(StampFactory.forKind(Kind.Long)); + } + + @Override + public void generate(NodeLIRBuilderTool generator) { + Value res = ((HotSpotLIRGenerator) generator.getLIRGeneratorTool()).emitCardTableAddress(); + generator.setResult(this, res); + } + + @NodeIntrinsic + public static native long cardTableAddress(); +} diff -r e8634d0e6667 -r aa4f2e3629ca graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/CardTableShiftNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/CardTableShiftNode.java Thu Dec 11 19:35:02 2014 +0100 @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2014, 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. + * + * 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 com.oracle.graal.hotspot.replacements; + +import com.oracle.graal.api.meta.*; +import com.oracle.graal.compiler.common.type.*; +import com.oracle.graal.hotspot.*; +import com.oracle.graal.nodeinfo.*; +import com.oracle.graal.nodes.calc.*; +import com.oracle.graal.nodes.spi.*; + +@NodeInfo +public class CardTableShiftNode extends FloatingNode implements LIRLowerable { + + public static CardTableShiftNode create() { + return new CardTableShiftNode(); + } + + protected CardTableShiftNode() { + super(StampFactory.intValue()); + } + + @Override + public void generate(NodeLIRBuilderTool generator) { + Value res = ((HotSpotLIRGenerator) generator.getLIRGeneratorTool()).emitCardTableShift(); + generator.setResult(this, res); + } + + @NodeIntrinsic + public static native int cardTableShift(); +} diff -r e8634d0e6667 -r aa4f2e3629ca graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotReplacementsUtil.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotReplacementsUtil.java Thu Dec 11 15:46:06 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotReplacementsUtil.java Thu Dec 11 19:35:02 2014 +0100 @@ -810,6 +810,16 @@ public static native int identityHashCode(@ConstantNodeParameter ForeignCallDescriptor descriptor, Object object); @Fold + public static boolean isImmutableCode() { + return GraalOptions.ImmutableCode.getValue(); + } + + @Fold + public static boolean generatePIC() { + return GraalOptions.GeneratePIC.getValue(); + } + + @Fold public static int verifiedEntryPointOffset() { return config().nmethodEntryOffset; } diff -r e8634d0e6667 -r aa4f2e3629ca graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/WriteBarrierSnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/WriteBarrierSnippets.java Thu Dec 11 15:46:06 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/WriteBarrierSnippets.java Thu Dec 11 19:35:02 2014 +0100 @@ -77,13 +77,15 @@ oop = Word.fromObject(fixedObject); } serialWriteBarrierCounter.inc(); - Word base = (Word) oop.unsignedShiftRight(cardTableShift()); - long startAddress = cardTableStart(); + int cardTableShift = (isImmutableCode() && generatePIC()) ? CardTableShiftNode.cardTableShift() : cardTableShift(); + long cardTableAddress = (isImmutableCode() && generatePIC()) ? CardTableAddressNode.cardTableAddress() : cardTableStart(); + Word base = (Word) oop.unsignedShiftRight(cardTableShift); + long startAddress = cardTableAddress; int displacement = 0; if (((int) startAddress) == startAddress) { displacement = (int) startAddress; } else { - base = base.add(Word.unsigned(cardTableStart())); + base = base.add(Word.unsigned(cardTableAddress)); } base.writeByte(displacement, (byte) 0, GC_CARD_LOCATION); } diff -r e8634d0e6667 -r aa4f2e3629ca src/share/vm/graal/graalCodeInstaller.cpp --- a/src/share/vm/graal/graalCodeInstaller.cpp Thu Dec 11 15:46:06 2014 +0100 +++ b/src/share/vm/graal/graalCodeInstaller.cpp Thu Dec 11 19:35:02 2014 +0100 @@ -962,6 +962,9 @@ case POLL_RETURN_FAR: pd_relocate_poll(pc, id); break; + case CARD_TABLE_SHIFT: + case CARD_TABLE_ADDRESS: + break; default: ShouldNotReachHere(); break; diff -r e8634d0e6667 -r aa4f2e3629ca src/share/vm/graal/graalCodeInstaller.hpp --- a/src/share/vm/graal/graalCodeInstaller.hpp Thu Dec 11 15:46:06 2014 +0100 +++ b/src/share/vm/graal/graalCodeInstaller.hpp Thu Dec 11 19:35:02 2014 +0100 @@ -47,6 +47,8 @@ POLL_RETURN_NEAR = 12, POLL_FAR = 13, POLL_RETURN_FAR = 14, + CARD_TABLE_ADDRESS = 15, + CARD_TABLE_SHIFT = 16, INVOKE_INVALID = -1 }; diff -r e8634d0e6667 -r aa4f2e3629ca src/share/vm/graal/vmStructs_graal.hpp --- a/src/share/vm/graal/vmStructs_graal.hpp Thu Dec 11 15:46:06 2014 +0100 +++ b/src/share/vm/graal/vmStructs_graal.hpp Thu Dec 11 19:35:02 2014 +0100 @@ -73,6 +73,8 @@ declare_constant(CodeInstaller::POLL_RETURN_NEAR) \ declare_constant(CodeInstaller::POLL_FAR) \ declare_constant(CodeInstaller::POLL_RETURN_FAR) \ + declare_constant(CodeInstaller::CARD_TABLE_SHIFT) \ + declare_constant(CodeInstaller::CARD_TABLE_ADDRESS) \ declare_constant(CodeInstaller::INVOKE_INVALID) \ \ declare_constant(Method::invalid_vtable_index) \