# HG changeset patch # User Christos Kotselidis # Date 1373631377 -7200 # Node ID 40f6bda3f91dd616681918f37cb00c3ae4c887c0 # Parent 867588b3ecb423e8f6f8493c30cd4398140c264a Add compressed klass pointers support in LIR diff -r 867588b3ecb4 -r 40f6bda3f91d 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 Fri Jul 12 12:48:06 2013 +0200 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java Fri Jul 12 14:16:17 2013 +0200 @@ -413,9 +413,16 @@ AMD64AddressValue loadAddress = asAddressValue(address); Variable result = newVariable(kind); assert access == null || access instanceof HeapAccess; - if (runtime().config.useCompressedOops && isCompressCandidate(access)) { - append(new LoadCompressedPointer(kind, result, loadAddress, access != null ? state(access) : null, runtime().config.narrowOopBase, runtime().config.narrowOopShift, - runtime().config.logMinObjAlignment)); + if (isCompressCandidate(access)) { + if (runtime().config.useCompressedOops && kind == Kind.Object) { + append(new LoadCompressedPointer(kind, result, loadAddress, access != null ? state(access) : null, runtime().config.narrowOopBase, runtime().config.narrowOopShift, + runtime().config.logMinObjAlignment)); + } else if (runtime().config.useCompressedKlassPointers && kind == Kind.Long) { + append(new LoadCompressedPointer(kind, result, loadAddress, access != null ? state(access) : null, runtime().config.narrowKlassBase, runtime().config.narrowKlassShift, + runtime().config.logKlassAlignment)); + } else { + append(new LoadOp(kind, result, loadAddress, access != null ? state(access) : null)); + } } else { append(new LoadOp(kind, result, loadAddress, access != null ? state(access) : null)); } @@ -429,17 +436,26 @@ if (isConstant(inputVal)) { Constant c = asConstant(inputVal); if (canStoreConstant(c)) { - append(new StoreConstantOp(kind, storeAddress, c, state, runtime().config.useCompressedOops && isCompressCandidate(access))); + if (inputVal.getKind() == Kind.Object) { + append(new StoreConstantOp(kind, storeAddress, c, state, runtime().config.useCompressedOops && isCompressCandidate(access))); + } else if (inputVal.getKind() == Kind.Long) { + append(new StoreConstantOp(kind, storeAddress, c, state, runtime().config.useCompressedKlassPointers && isCompressCandidate(access))); + } else { + append(new StoreConstantOp(kind, storeAddress, c, state, false)); + } return; } } Variable input = load(inputVal); - if (runtime().config.useCompressedOops && isCompressCandidate(access)) { - if (input.getKind() == Kind.Object) { + if (isCompressCandidate(access)) { + if (runtime().config.useCompressedOops && kind == Kind.Object) { Variable scratch = newVariable(Kind.Long); append(new StoreCompressedPointer(kind, storeAddress, input, scratch, state, runtime().config.narrowOopBase, runtime().config.narrowOopShift, runtime().config.logMinObjAlignment)); + } else if (runtime().config.useCompressedKlassPointers && kind == Kind.Long) { + Variable scratch = newVariable(Kind.Long); + append(new StoreCompressedPointer(kind, storeAddress, input, scratch, state, runtime().config.narrowKlassBase, runtime().config.narrowKlassShift, runtime().config.logKlassAlignment)); } else { - append(new StoreOp(input.getKind(), storeAddress, input, state)); + append(new StoreOp(kind, storeAddress, input, state)); } } else { append(new StoreOp(kind, storeAddress, input, state)); diff -r 867588b3ecb4 -r 40f6bda3f91d graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Move.java --- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Move.java Fri Jul 12 12:48:06 2013 +0200 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Move.java Fri Jul 12 14:16:17 2013 +0200 @@ -129,14 +129,18 @@ this.base = base; this.shift = shift; this.alignment = alignment; - assert kind == Kind.Object; + assert kind == Kind.Object || kind == Kind.Long; } @Override public void emitMemAccess(AMD64MacroAssembler masm) { Register resRegister = asRegister(result); masm.movl(resRegister, address.toAddress()); - decodePointer(masm, resRegister, base, shift, alignment); + if (kind == Kind.Object) { + decodePointer(masm, resRegister, base, shift, alignment); + } else { + decodeKlassPointer(masm, resRegister, base, shift, alignment); + } } } @@ -203,13 +207,17 @@ this.address = address; this.state = state; this.input = input; - assert kind == Kind.Object; + assert kind == Kind.Object || kind == Kind.Long; } @Override public void emitCode(TargetMethodAssembler tasm, AMD64MacroAssembler masm) { masm.movq(asRegister(scratch), asRegister(input)); - encodePointer(masm, asRegister(scratch), base, shift, alignment); + if (kind == Kind.Object) { + encodePointer(masm, asRegister(scratch), base, shift, alignment); + } else { + encodeKlassPointer(masm, asRegister(scratch), base, shift, alignment); + } if (state != null) { tasm.recordImplicitException(masm.codeBuffer.position(), state); } @@ -286,7 +294,11 @@ break; case Long: if (NumUtil.isInt(input.asLong())) { - masm.movslq(address.toAddress(), (int) input.asLong()); + if (compress) { + masm.movl(address.toAddress(), (int) input.asLong()); + } else { + masm.movslq(address.toAddress(), (int) input.asLong()); + } } else { throw GraalInternalError.shouldNotReachHere("Cannot store 64-bit constants to memory"); } @@ -691,4 +703,30 @@ } } + private static void encodeKlassPointer(AMD64MacroAssembler masm, Register scratchRegister, long base, int shift, int alignment) { + if (base != 0) { + masm.subq(scratchRegister, AMD64.r12); + } + if (shift != 0) { + assert alignment == shift : "Encode algorithm is wrong"; + masm.shrq(scratchRegister, alignment); + } + } + + private static void decodeKlassPointer(AMD64MacroAssembler masm, Register resRegister, long base, int shift, int alignment) { + if (shift != 0) { + assert alignment == shift : "Decode algorighm is wrong"; + masm.shlq(resRegister, alignment); + if (base != 0) { + masm.addq(resRegister, AMD64.r12); + } + } else { + assert base == 0 : "Sanity"; + } + } + + public static void decodeKlassPointer(AMD64MacroAssembler masm, Register register, AMD64Address address, long narrowKlassBase, int narrowKlassShift, int logKlassAlignment) { + masm.movl(register, address); + decodeKlassPointer(masm, register, narrowKlassBase, narrowKlassShift, logKlassAlignment); + } }