# HG changeset patch # User adlertz # Date 1418322925 -3600 # Node ID c9d57a5fb655d586f054489daba65173f2afc3fd # Parent aa4f2e3629ca3219a6854d0b5578b1984413b8ab Added PIC support for metaspace access diff -r aa4f2e3629ca -r c9d57a5fb655 graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotCompare.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotCompare.java Thu Dec 11 19:35:02 2014 +0100 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotCompare.java Thu Dec 11 19:35:25 2014 +0100 @@ -25,6 +25,7 @@ import static com.oracle.graal.api.code.ValueUtil.*; import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; +import com.oracle.graal.hotspot.HotSpotGraalRuntime; import com.oracle.graal.api.meta.*; import com.oracle.graal.asm.*; import com.oracle.graal.asm.amd64.*; @@ -66,14 +67,31 @@ masm.cmpq(asRegister(x), patch); } } else if (y instanceof HotSpotMetaspaceConstant) { + boolean isImmutable = GraalOptions.ImmutableCode.getValue(); + boolean generatePIC = GraalOptions.GeneratePIC.getValue(); if (y.getKind() == Kind.Int) { // compressed metaspace pointer crb.recordInlineDataInCode(y); - masm.cmpl(asRegister(x), y.asInt()); + if (isImmutable && generatePIC) { + Kind hostWordKind = HotSpotGraalRuntime.getHostWordKind(); + int alignment = hostWordKind.getBitCount() / Byte.SIZE; + // recordDataReferenceInCode forces the mov to be rip-relative + masm.cmpl(asRegister(x), (AMD64Address) crb.recordDataReferenceInCode(JavaConstant.INT_0, alignment)); + } else { + masm.cmpl(asRegister(x), y.asInt()); + } } else { // uncompressed metaspace pointer - AMD64Address patch = (AMD64Address) crb.recordDataReferenceInCode(y, 8); - masm.cmpq(asRegister(x), patch); + if (isImmutable && generatePIC) { + crb.recordInlineDataInCode(y); + Kind hostWordKind = HotSpotGraalRuntime.getHostWordKind(); + int alignment = hostWordKind.getBitCount() / Byte.SIZE; + // recordDataReferenceInCode forces the mov to be rip-relative + masm.cmpq(asRegister(x), (AMD64Address) crb.recordDataReferenceInCode(JavaConstant.INT_0, alignment)); + } else { + AMD64Address patch = (AMD64Address) crb.recordDataReferenceInCode(y, 8); + masm.cmpq(asRegister(x), patch); + } } } else { throw GraalInternalError.shouldNotReachHere(); diff -r aa4f2e3629ca -r c9d57a5fb655 graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotMove.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotMove.java Thu Dec 11 19:35:02 2014 +0100 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotMove.java Thu Dec 11 19:35:25 2014 +0100 @@ -32,6 +32,7 @@ import com.oracle.graal.asm.amd64.*; import com.oracle.graal.asm.amd64.AMD64Assembler.ConditionFlag; import com.oracle.graal.compiler.common.*; +import com.oracle.graal.hotspot.*; import com.oracle.graal.hotspot.HotSpotVMConfig.CompressEncoding; import com.oracle.graal.hotspot.meta.*; import com.oracle.graal.lir.*; @@ -94,17 +95,37 @@ } else if (input instanceof HotSpotMetaspaceConstant) { assert input.getKind() == Kind.Int || input.getKind() == Kind.Long; boolean compressed = input.getKind() == Kind.Int; + boolean isImmutable = GraalOptions.ImmutableCode.getValue(); + boolean generatePIC = GraalOptions.GeneratePIC.getValue(); crb.recordInlineDataInCode(input); if (isRegister(result)) { if (compressed) { - masm.movl(asRegister(result), input.asInt()); + if (isImmutable && generatePIC) { + Kind hostWordKind = HotSpotGraalRuntime.getHostWordKind(); + int alignment = hostWordKind.getBitCount() / Byte.SIZE; + // recordDataReferenceInCode forces the mov to be rip-relative + masm.movl(asRegister(result), (AMD64Address) crb.recordDataReferenceInCode(JavaConstant.INT_0, alignment)); + } else { + masm.movl(asRegister(result), input.asInt()); + } } else { - masm.movq(asRegister(result), input.asLong()); + if (isImmutable && generatePIC) { + Kind hostWordKind = HotSpotGraalRuntime.getHostWordKind(); + int alignment = hostWordKind.getBitCount() / Byte.SIZE; + // recordDataReferenceInCode forces the mov to be rip-relative + masm.movq(asRegister(result), (AMD64Address) crb.recordDataReferenceInCode(JavaConstant.INT_0, alignment)); + } else { + masm.movq(asRegister(result), input.asLong()); + } } } else { assert isStackSlot(result); if (compressed) { - masm.movl((AMD64Address) crb.asAddress(result), input.asInt()); + if (isImmutable && generatePIC) { + throw GraalInternalError.shouldNotReachHere("Unsupported operation offset(%rip) -> mem (mem -> mem)"); + } else { + masm.movl((AMD64Address) crb.asAddress(result), input.asInt()); + } } else { throw GraalInternalError.shouldNotReachHere("Cannot store 64-bit constants to memory"); }