# HG changeset patch # User twisti # Date 1393529597 28800 # Node ID 390c4b74289002a19c524af40600c93c24b15ad4 # Parent f6c04e69cf75ae59dd31aa5692161362803caae2 made com.oracle.graal.asm.Buffer non-public and a private field in AbstractAssembler diff -r f6c04e69cf75 -r 390c4b742890 graal/com.oracle.graal.asm.amd64.test/src/com/oracle/graal/asm/amd64/test/SimpleAssemblerTest.java --- a/graal/com.oracle.graal.asm.amd64.test/src/com/oracle/graal/asm/amd64/test/SimpleAssemblerTest.java Thu Feb 27 16:05:29 2014 +0100 +++ b/graal/com.oracle.graal.asm.amd64.test/src/com/oracle/graal/asm/amd64/test/SimpleAssemblerTest.java Thu Feb 27 11:33:17 2014 -0800 @@ -30,7 +30,6 @@ import com.oracle.graal.api.code.CompilationResult.ConstantData; import com.oracle.graal.api.code.CompilationResult.RawData; import com.oracle.graal.api.meta.*; -import com.oracle.graal.asm.Buffer; import com.oracle.graal.asm.amd64.*; import com.oracle.graal.asm.test.*; @@ -41,12 +40,12 @@ CodeGenTest test = new CodeGenTest() { @Override - public Buffer generateCode(CompilationResult compResult, TargetDescription target, RegisterConfig registerConfig, CallingConvention cc) { + public byte[] generateCode(CompilationResult compResult, TargetDescription target, RegisterConfig registerConfig, CallingConvention cc) { AMD64Assembler asm = new AMD64Assembler(target, registerConfig); Register ret = registerConfig.getReturnRegister(Kind.Int); asm.movl(ret, 8472); asm.ret(0); - return asm.codeBuffer; + return asm.close(true); } }; assertReturn("intStub", test, 8472); @@ -57,13 +56,13 @@ CodeGenTest test = new CodeGenTest() { @Override - public Buffer generateCode(CompilationResult compResult, TargetDescription target, RegisterConfig registerConfig, CallingConvention cc) { + public byte[] generateCode(CompilationResult compResult, TargetDescription target, RegisterConfig registerConfig, CallingConvention cc) { AMD64MacroAssembler asm = new AMD64MacroAssembler(target, registerConfig); Register ret = registerConfig.getReturnRegister(Kind.Double); - compResult.recordDataReference(asm.codeBuffer.position(), new ConstantData(Constant.forDouble(84.72), 8)); + compResult.recordDataReference(asm.position(), new ConstantData(Constant.forDouble(84.72), 8)); asm.movdbl(ret, asm.getPlaceholder()); asm.ret(0); - return asm.codeBuffer; + return asm.close(true); } }; assertReturn("doubleStub", test, 84.72); @@ -74,16 +73,16 @@ CodeGenTest test = new CodeGenTest() { @Override - public Buffer generateCode(CompilationResult compResult, TargetDescription target, RegisterConfig registerConfig, CallingConvention cc) { + public byte[] generateCode(CompilationResult compResult, TargetDescription target, RegisterConfig registerConfig, CallingConvention cc) { AMD64MacroAssembler asm = new AMD64MacroAssembler(target, registerConfig); Register ret = registerConfig.getReturnRegister(Kind.Double); byte[] rawBytes = new byte[8]; ByteBuffer.wrap(rawBytes).order(ByteOrder.nativeOrder()).putDouble(84.72); - compResult.recordDataReference(asm.codeBuffer.position(), new RawData(rawBytes, 8)); + compResult.recordDataReference(asm.position(), new RawData(rawBytes, 8)); asm.movdbl(ret, asm.getPlaceholder()); asm.ret(0); - return asm.codeBuffer; + return asm.close(true); } }; assertReturn("doubleStub", test, 84.72); diff -r f6c04e69cf75 -r 390c4b742890 graal/com.oracle.graal.asm.amd64/src/com/oracle/graal/asm/amd64/AMD64Assembler.java --- a/graal/com.oracle.graal.asm.amd64/src/com/oracle/graal/asm/amd64/AMD64Assembler.java Thu Feb 27 16:05:29 2014 +0100 +++ b/graal/com.oracle.graal.asm.amd64/src/com/oracle/graal/asm/amd64/AMD64Assembler.java Thu Feb 27 11:33:17 2014 -0800 @@ -746,7 +746,7 @@ public void jcc(ConditionFlag cc, int jumpTarget, boolean forceDisp32) { int shortSize = 2; int longSize = 6; - long disp = jumpTarget - codeBuffer.position(); + long disp = jumpTarget - position(); if (!forceDisp32 && isByte(disp - shortSize)) { // 0111 tttn #8-bit disp emitByte(0x70 | cc.getValue()); @@ -769,7 +769,7 @@ // is the same however, seems to be rather unlikely case. // Note: use jccb() if label to be bound is very close to get // an 8-bit displacement - l.addPatchAt(codeBuffer.position()); + l.addPatchAt(position()); emitByte(0x0F); emitByte(0x80 | cc.getValue()); emitInt(0); @@ -781,13 +781,13 @@ if (l.isBound()) { int shortSize = 2; int entry = l.position(); - assert isByte(entry - (codeBuffer.position() + shortSize)) : "Dispacement too large for a short jmp"; - long disp = entry - codeBuffer.position(); + assert isByte(entry - (position() + shortSize)) : "Dispacement too large for a short jmp"; + long disp = entry - position(); // 0111 tttn #8-bit disp emitByte(0x70 | cc.getValue()); emitByte((int) ((disp - shortSize) & 0xFF)); } else { - l.addPatchAt(codeBuffer.position()); + l.addPatchAt(position()); emitByte(0x70 | cc.getValue()); emitByte(0); } @@ -796,7 +796,7 @@ public final void jmp(int jumpTarget, boolean forceDisp32) { int shortSize = 2; int longSize = 5; - long disp = jumpTarget - codeBuffer.position(); + long disp = jumpTarget - position(); if (!forceDisp32 && isByte(disp - shortSize)) { emitByte(0xEB); emitByte((int) ((disp - shortSize) & 0xFF)); @@ -816,7 +816,7 @@ // the forward jump will not run beyond 256 bytes, use jmpb to // force an 8-bit displacement. - l.addPatchAt(codeBuffer.position()); + l.addPatchAt(position()); emitByte(0xE9); emitInt(0); } @@ -832,13 +832,13 @@ if (l.isBound()) { int shortSize = 2; int entry = l.position(); - assert isByte((entry - codeBuffer.position()) + shortSize) : "Dispacement too large for a short jmp"; - long offs = entry - codeBuffer.position(); + assert isByte((entry - position()) + shortSize) : "Dispacement too large for a short jmp"; + long offs = entry - position(); emitByte(0xEB); emitByte((int) ((offs - shortSize) & 0xFF)); } else { - l.addPatchAt(codeBuffer.position()); + l.addPatchAt(position()); emitByte(0xEB); emitByte(0); } @@ -2446,21 +2446,21 @@ @Override protected final void patchJumpTarget(int branch, int branchTarget) { - int op = codeBuffer.getByte(branch); + int op = getByte(branch); assert op == 0xE8 // call || op == 0x00 // jump table entry || op == 0xE9 // jmp || op == 0xEB // short jmp || (op & 0xF0) == 0x70 // short jcc - || op == 0x0F && (codeBuffer.getByte(branch + 1) & 0xF0) == 0x80 // jcc + || op == 0x0F && (getByte(branch + 1) & 0xF0) == 0x80 // jcc : "Invalid opcode at patch point branch=" + branch + ", branchTarget=" + branchTarget + ", op=" + op; if (op == 0x00) { - int offsetToJumpTableBase = codeBuffer.getShort(branch + 1); + int offsetToJumpTableBase = getShort(branch + 1); int jumpTableBase = branch - offsetToJumpTableBase; int imm32 = branchTarget - jumpTableBase; - codeBuffer.emitInt(imm32, branch); + emitInt(imm32, branch); } else if (op == 0xEB || (op & 0xF0) == 0x70) { // short offset operators (jmp and jcc) @@ -2472,7 +2472,7 @@ if (!NumUtil.isByte(imm8)) { throw new InternalError("branch displacement out of range: " + imm8); } - codeBuffer.emitByte(imm8, branch + 1); + emitByte(imm8, branch + 1); } else { @@ -2482,7 +2482,7 @@ } int imm32 = branchTarget - (branch + 4 + off); - codeBuffer.emitInt(imm32, branch + off); + emitInt(imm32, branch + off); } } @@ -2492,8 +2492,8 @@ @Override public void align(int modulus) { - if (codeBuffer.position() % modulus != 0) { - nop(modulus - (codeBuffer.position() % modulus)); + if (position() % modulus != 0) { + nop(modulus - (position() % modulus)); } } diff -r f6c04e69cf75 -r 390c4b742890 graal/com.oracle.graal.asm.sparc/src/com/oracle/graal/asm/sparc/SPARCAssembler.java --- a/graal/com.oracle.graal.asm.sparc/src/com/oracle/graal/asm/sparc/SPARCAssembler.java Thu Feb 27 16:05:29 2014 +0100 +++ b/graal/com.oracle.graal.asm.sparc/src/com/oracle/graal/asm/sparc/SPARCAssembler.java Thu Feb 27 11:33:17 2014 -0800 @@ -89,7 +89,7 @@ } public static Fmt00a read(SPARCAssembler masm, int pos) { - final int inst = masm.codeBuffer.getInt(pos); + final int inst = masm.getInt(pos); // Make sure it's the right instruction: final int op = (inst & OP_MASK) >> OP_SHIFT; @@ -105,7 +105,7 @@ public void write(SPARCAssembler masm, int pos) { verify(); - masm.codeBuffer.emitInt(getInstructionBits(), pos); + masm.emitInt(getInstructionBits(), pos); } public void emit(SPARCAssembler masm) { @@ -253,7 +253,7 @@ } public static Fmt00c read(SPARCAssembler masm, int pos) { - final int inst = masm.codeBuffer.getInt(pos); + final int inst = masm.getInt(pos); // Make sure it's the right instruction: final int op = (inst & OP_MASK) >> OP_SHIFT; @@ -274,13 +274,13 @@ public void write(SPARCAssembler masm, int pos) { verify(); - masm.codeBuffer.emitInt(getInstructionBits(), pos); + masm.emitInt(getInstructionBits(), pos); } public void emit(SPARCAssembler masm) { if (label != null) { final int pos = label.isBound() ? label.position() : patchUnbound(masm, label); - final int disp = pos - masm.codeBuffer.position(); + final int disp = pos - masm.position(); setDisp19(disp); } verify(); @@ -288,7 +288,7 @@ } private static int patchUnbound(SPARCAssembler masm, Label label) { - label.addPatchAt(masm.codeBuffer.position()); + label.addPatchAt(masm.position()); return 0; } @@ -370,7 +370,7 @@ } public static Fmt01 read(SPARCAssembler masm, int pos) { - final int inst = masm.codeBuffer.getInt(pos); + final int inst = masm.getInt(pos); // Make sure it's the right instruction: final int op = (inst & OP_MASK) >> OP_SHIFT; @@ -386,7 +386,7 @@ public void write(SPARCAssembler masm, int pos) { verify(); - masm.codeBuffer.emitInt(getInstructionBits(), pos); + masm.emitInt(getInstructionBits(), pos); } public void emit(SPARCAssembler masm) { @@ -550,7 +550,7 @@ } public static Fmt10 read(SPARCAssembler masm, int pos) { - final int inst = masm.codeBuffer.getInt(pos); + final int inst = masm.getInt(pos); // Make sure it's the right instruction: final int op = (inst & OP_MASK) >> OP_SHIFT; @@ -571,7 +571,7 @@ public void write(SPARCAssembler masm, int pos) { verify(); - masm.codeBuffer.emitInt(getInstructionBits(), pos); + masm.emitInt(getInstructionBits(), pos); } public void emit(SPARCAssembler masm) { @@ -696,7 +696,7 @@ } public static Fmt11 read(SPARCAssembler masm, int pos) { - final int inst = masm.codeBuffer.getInt(pos); + final int inst = masm.getInt(pos); // Make sure it's the right instruction: final int op = (inst & OP_MASK) >> OP_SHIFT; @@ -716,7 +716,7 @@ public void write(SPARCAssembler masm, int pos) { verify(); - masm.codeBuffer.emitInt(getInstructionBits(), pos); + masm.emitInt(getInstructionBits(), pos); } public void emit(SPARCAssembler masm) { @@ -832,7 +832,7 @@ } public static Fmt10c read(SPARCAssembler masm, int pos) { - final int inst = masm.codeBuffer.getInt(pos); + final int inst = masm.getInt(pos); // Make sure it's the right instruction: final int op = (inst & OP_MASK) >> OP_SHIFT; @@ -852,7 +852,7 @@ public void write(SPARCAssembler masm, int pos) { verify(); - masm.codeBuffer.emitInt(getInstructionBits(), pos); + masm.emitInt(getInstructionBits(), pos); } public void emit(SPARCAssembler masm) { diff -r f6c04e69cf75 -r 390c4b742890 graal/com.oracle.graal.asm.sparc/src/com/oracle/graal/asm/sparc/SPARCMacroAssembler.java --- a/graal/com.oracle.graal.asm.sparc/src/com/oracle/graal/asm/sparc/SPARCMacroAssembler.java Thu Feb 27 16:05:29 2014 +0100 +++ b/graal/com.oracle.graal.asm.sparc/src/com/oracle/graal/asm/sparc/SPARCMacroAssembler.java Thu Feb 27 11:33:17 2014 -0800 @@ -42,8 +42,8 @@ @Override public void align(int modulus) { - if (codeBuffer.position() % modulus != 0) { - final int count = modulus - (codeBuffer.position() % modulus); + if (position() % modulus != 0) { + final int count = modulus - (position() % modulus); for (int i = 0; i < count; i++) { new Nop().emit(this); } @@ -364,7 +364,7 @@ int lo = (int) (value & ~0); // This is the same logic as MacroAssembler::internal_set. - final int startPc = masm.codeBuffer.position(); + final int startPc = masm.position(); if (hi == 0 && lo >= 0) { new Sethi(hi22(lo), dst).emit(masm); @@ -399,7 +399,7 @@ } // Pad out the instruction sequence so it can be patched later. if (forceRelocatable) { - while (masm.codeBuffer.position() < (startPc + (INSTRUCTION_SIZE * 4))) { + while (masm.position() < (startPc + (INSTRUCTION_SIZE * 4))) { new Nop().emit(masm); } } diff -r f6c04e69cf75 -r 390c4b742890 graal/com.oracle.graal.asm.test/src/com/oracle/graal/asm/test/AssemblerTest.java --- a/graal/com.oracle.graal.asm.test/src/com/oracle/graal/asm/test/AssemblerTest.java Thu Feb 27 16:05:29 2014 +0100 +++ b/graal/com.oracle.graal.asm.test/src/com/oracle/graal/asm/test/AssemblerTest.java Thu Feb 27 11:33:17 2014 -0800 @@ -29,7 +29,6 @@ import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; import com.oracle.graal.api.runtime.*; -import com.oracle.graal.asm.*; import com.oracle.graal.phases.util.*; import com.oracle.graal.runtime.*; import com.oracle.graal.test.*; @@ -40,8 +39,7 @@ protected final CodeCacheProvider codeCache; public interface CodeGenTest { - - Buffer generateCode(CompilationResult compResult, TargetDescription target, RegisterConfig registerConfig, CallingConvention cc); + byte[] generateCode(CompilationResult compResult, TargetDescription target, RegisterConfig registerConfig, CallingConvention cc); } public AssemblerTest() { @@ -60,8 +58,8 @@ CallingConvention cc = CodeUtil.getCallingConvention(codeCache, CallingConvention.Type.JavaCallee, method, false); CompilationResult compResult = new CompilationResult(); - Buffer codeBuffer = test.generateCode(compResult, codeCache.getTarget(), registerConfig, cc); - compResult.setTargetCode(codeBuffer.close(true), codeBuffer.position()); + byte[] targetCode = test.generateCode(compResult, codeCache.getTarget(), registerConfig, cc); + compResult.setTargetCode(targetCode, targetCode.length); InstalledCode code = codeCache.addMethod(method, compResult, null); diff -r f6c04e69cf75 -r 390c4b742890 graal/com.oracle.graal.asm/src/com/oracle/graal/asm/AbstractAssembler.java --- a/graal/com.oracle.graal.asm/src/com/oracle/graal/asm/AbstractAssembler.java Thu Feb 27 16:05:29 2014 +0100 +++ b/graal/com.oracle.graal.asm/src/com/oracle/graal/asm/AbstractAssembler.java Thu Feb 27 11:33:17 2014 -0800 @@ -33,11 +33,14 @@ public abstract class AbstractAssembler { public final TargetDescription target; - public final Buffer codeBuffer; + + /** + * Backing code buffer. + */ + private final Buffer codeBuffer; public AbstractAssembler(TargetDescription target) { this.target = target; - if (target.arch.getByteOrder() == ByteOrder.BIG_ENDIAN) { this.codeBuffer = new Buffer.BigEndian(); } else { @@ -45,9 +48,93 @@ } } + /** + * Returns the current position of the underlying code buffer. + * + * @return current position in code buffer + */ + public int position() { + return codeBuffer.position(); + } + + public final void emitByte(int x) { + codeBuffer.emitByte(x); + } + + public final void emitShort(int x) { + codeBuffer.emitShort(x); + } + + public final void emitInt(int x) { + codeBuffer.emitInt(x); + } + + public final void emitLong(long x) { + codeBuffer.emitLong(x); + } + + public final void emitByte(int b, int pos) { + codeBuffer.emitByte(b, pos); + } + + public final void emitShort(int b, int pos) { + codeBuffer.emitShort(b, pos); + } + + public final void emitInt(int b, int pos) { + codeBuffer.emitInt(b, pos); + } + + public final void emitLong(long b, int pos) { + codeBuffer.emitLong(b, pos); + } + + public final int getByte(int pos) { + return codeBuffer.getByte(pos); + } + + public final int getShort(int pos) { + return codeBuffer.getShort(pos); + } + + public final int getInt(int pos) { + return codeBuffer.getInt(pos); + } + + private static final String NEWLINE = System.getProperty("line.separator"); + + /** + * Some GPU architectures have a text based encoding. + */ + public final void emitString(String x) { + emitString0("\t"); // XXX REMOVE ME pretty-printing + emitString0(x); + emitString0(NEWLINE); + } + + // XXX for pretty-printing + public final void emitString0(String x) { + codeBuffer.emitBytes(x.getBytes(), 0, x.length()); + } + + public void emitString(String s, int pos) { + codeBuffer.emitBytes(s.getBytes(), pos); + } + + /** + * Closes this assembler. No extra data can be written to this assembler after this call. + * + * @param trimmedCopy if {@code true}, then a copy of the underlying byte array up to (but not + * including) {@code position()} is returned + * @return the data in this buffer or a trimmed copy if {@code trimmedCopy} is {@code true} + */ + public byte[] close(boolean trimmedCopy) { + return codeBuffer.close(trimmedCopy); + } + public void bind(Label l) { assert !l.isBound() : "can bind label only once"; - l.bind(codeBuffer.position()); + l.bind(position()); l.patchInstructions(this); } @@ -86,34 +173,6 @@ return name; } - protected final void emitByte(int x) { - codeBuffer.emitByte(x); - } - - protected final void emitShort(int x) { - codeBuffer.emitShort(x); - } - - protected final void emitInt(int x) { - codeBuffer.emitInt(x); - } - - protected final void emitLong(long x) { - codeBuffer.emitLong(x); - } - - /** - * Some GPU architectures have a text based encoding. - */ - protected final void emitString(String x) { - codeBuffer.emitString(x); - } - - // XXX for pretty-printing - protected final void emitString0(String x) { - codeBuffer.emitString0(x); - } - /** * This is used by the CompilationResultBuilder to convert a {@link StackSlot} to an * {@link AbstractAddress}. diff -r f6c04e69cf75 -r 390c4b742890 graal/com.oracle.graal.asm/src/com/oracle/graal/asm/Buffer.java --- a/graal/com.oracle.graal.asm/src/com/oracle/graal/asm/Buffer.java Thu Feb 27 16:05:29 2014 +0100 +++ b/graal/com.oracle.graal.asm/src/com/oracle/graal/asm/Buffer.java Thu Feb 27 11:33:17 2014 -0800 @@ -28,7 +28,7 @@ * Code buffer management for the assembler. Support for little endian and big endian architectures * is implemented using subclasses. */ -public abstract class Buffer { +abstract class Buffer { protected byte[] data; protected int position; @@ -105,19 +105,6 @@ position = emitLong(b, position); } - private static final String NEWLINE = System.getProperty("line.separator"); - - public void emitString(String s) { - position = emitString("\t", position); // XXX REMOVE ME pretty-printing - position = emitString(s, position); - position = emitString(NEWLINE, position); - } - - // XXX for pretty-printing - public void emitString0(String s) { - emitBytes(s.getBytes(), 0, s.length()); - } - public int emitBytes(byte[] arr, int pos) { final int len = arr.length; final int newPos = pos + len; @@ -140,10 +127,6 @@ public abstract int emitLong(long b, int pos); - public int emitString(String s, int pos) { - return emitBytes(s.getBytes(), pos); - } - public int getByte(int pos) { return data[pos] & 0xff; } diff -r f6c04e69cf75 -r 390c4b742890 graal/com.oracle.graal.hotspot.amd64.test/src/com/oracle/graal/hotspot/amd64/test/AMD64HotSpotFrameOmissionTest.java --- a/graal/com.oracle.graal.hotspot.amd64.test/src/com/oracle/graal/hotspot/amd64/test/AMD64HotSpotFrameOmissionTest.java Thu Feb 27 16:05:29 2014 +0100 +++ b/graal/com.oracle.graal.hotspot.amd64.test/src/com/oracle/graal/hotspot/amd64/test/AMD64HotSpotFrameOmissionTest.java Thu Feb 27 11:33:17 2014 -0800 @@ -111,7 +111,7 @@ AMD64Assembler asm = new AMD64Assembler(target, registerConfig); gen.generateCode(asm); - byte[] expectedCode = asm.codeBuffer.close(true); + byte[] expectedCode = asm.close(true); // Only compare up to expectedCode.length bytes to ignore // padding instructions adding during code installation diff -r f6c04e69cf75 -r 390c4b742890 graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackend.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackend.java Thu Feb 27 16:05:29 2014 +0100 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackend.java Thu Feb 27 11:33:17 2014 -0800 @@ -98,9 +98,9 @@ disp -= frameSize; } crb.blockComment("[stack overflow check]"); - int pos = asm.codeBuffer.position(); + int pos = asm.position(); asm.movq(new AMD64Address(rsp, -disp), AMD64.rax); - assert i > 0 || !isVerifiedEntryPoint || asm.codeBuffer.position() - pos >= PATCHED_VERIFIED_ENTRY_POINT_INSTRUCTION_SIZE; + assert i > 0 || !isVerifiedEntryPoint || asm.position() - pos >= PATCHED_VERIFIED_ENTRY_POINT_INSTRUCTION_SIZE; } } } @@ -141,14 +141,14 @@ asm.nop(PATCHED_VERIFIED_ENTRY_POINT_INSTRUCTION_SIZE); } } else { - int verifiedEntryPointOffset = asm.codeBuffer.position(); + int verifiedEntryPointOffset = asm.position(); if (!isStub && pagesToBang > 0) { emitStackOverflowCheck(crb, pagesToBang, false, true); - assert asm.codeBuffer.position() - verifiedEntryPointOffset >= PATCHED_VERIFIED_ENTRY_POINT_INSTRUCTION_SIZE; + assert asm.position() - verifiedEntryPointOffset >= PATCHED_VERIFIED_ENTRY_POINT_INSTRUCTION_SIZE; } - if (!isStub && asm.codeBuffer.position() == verifiedEntryPointOffset) { + if (!isStub && asm.position() == verifiedEntryPointOffset) { asm.subqWide(rsp, frameSize); - assert asm.codeBuffer.position() - verifiedEntryPointOffset >= PATCHED_VERIFIED_ENTRY_POINT_INSTRUCTION_SIZE; + assert asm.position() - verifiedEntryPointOffset >= PATCHED_VERIFIED_ENTRY_POINT_INSTRUCTION_SIZE; } else { asm.decrementq(rsp, frameSize); } @@ -174,7 +174,7 @@ CalleeSaveLayout csl = crb.frameMap.registerConfig.getCalleeSaveLayout(); if (csl != null && csl.size != 0) { - crb.compilationResult.setRegisterRestoreEpilogueOffset(asm.codeBuffer.position()); + crb.compilationResult.setRegisterRestoreEpilogueOffset(asm.position()); // saved all registers, restore all registers int frameToCSA = crb.frameMap.offsetToCalleeSaveArea(); asm.restore(csl, frameToCSA); diff -r f6c04e69cf75 -r 390c4b742890 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 Feb 27 16:05:29 2014 +0100 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotMove.java Thu Feb 27 11:33:17 2014 -0800 @@ -133,12 +133,12 @@ encodeKlassPointer(masm, asRegister(scratch), heapBaseReg, encoding); } if (state != null) { - crb.recordImplicitException(masm.codeBuffer.position(), state); + crb.recordImplicitException(masm.position(), state); } masm.movl(address.toAddress(), asRegister(scratch)); } if (state != null) { - crb.recordImplicitException(masm.codeBuffer.position(), state); + crb.recordImplicitException(masm.position(), state); } masm.movl(address.toAddress(), asRegister(scratch)); } diff -r f6c04e69cf75 -r 390c4b742890 graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotSafepointOp.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotSafepointOp.java Thu Feb 27 16:05:29 2014 +0100 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotSafepointOp.java Thu Feb 27 11:33:17 2014 -0800 @@ -81,7 +81,7 @@ // This move will be patched to load the safepoint page from a data segment // co-located with the immutable code. asm.movq(scratch, (AMD64Address) crb.recordDataReferenceInCode(pollingPageAddress, alignment)); - final int pos = asm.codeBuffer.position(); + final int pos = asm.position(); crb.recordMark(atReturn ? MARK_POLL_RETURN_FAR : MARK_POLL_FAR); if (state != null) { crb.recordInfopoint(pos, state, InfopointReason.SAFEPOINT); @@ -90,14 +90,14 @@ } else if (isPollingPageFar(config)) { asm.movq(scratch, config.safepointPollingAddress); crb.recordMark(atReturn ? MARK_POLL_RETURN_FAR : MARK_POLL_FAR); - final int pos = asm.codeBuffer.position(); + final int pos = asm.position(); if (state != null) { crb.recordInfopoint(pos, state, InfopointReason.SAFEPOINT); } asm.testl(rax, new AMD64Address(scratch)); } else { crb.recordMark(atReturn ? MARK_POLL_RETURN_NEAR : MARK_POLL_NEAR); - final int pos = asm.codeBuffer.position(); + final int pos = asm.position(); if (state != null) { crb.recordInfopoint(pos, state, InfopointReason.SAFEPOINT); } diff -r f6c04e69cf75 -r 390c4b742890 graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotBackend.java --- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotBackend.java Thu Feb 27 16:05:29 2014 +0100 +++ b/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotBackend.java Thu Feb 27 11:33:17 2014 -0800 @@ -58,7 +58,6 @@ public class HSAILHotSpotBackend extends HotSpotBackend { private Map paramTypeMap = new HashMap<>(); - private Buffer codeBuffer; private final boolean deviceInitialized; public HSAILHotSpotBackend(HotSpotGraalRuntime runtime, HotSpotProviders providers) { @@ -193,14 +192,6 @@ return new HSAILHotSpotLIRGenerator(graph, getProviders(), getRuntime().getConfig(), frameMap, cc, lir); } - public String getPartialCodeString() { - if (codeBuffer == null) { - return ""; - } - byte[] data = codeBuffer.copyData(0, codeBuffer.position()); - return (data == null ? "" : new String(data)); - } - class HotSpotFrameContext implements FrameContext { public boolean hasFrame() { @@ -237,9 +228,9 @@ public void emitCode(CompilationResultBuilder crb, LIRGenerator lirGen, ResolvedJavaMethod method) { assert method != null : lirGen.getGraph() + " is not associated with a method"; // Emit the prologue. - codeBuffer = crb.asm.codeBuffer; - codeBuffer.emitString0("version 0:95: $full : $large;"); - codeBuffer.emitString(""); + AbstractAssembler asm = crb.asm; + asm.emitString0("version 0:95: $full : $large;"); + asm.emitString(""); Signature signature = method.getSignature(); int sigParamCount = signature.getParameterCount(false); @@ -284,10 +275,10 @@ } } - codeBuffer.emitString0("// " + (isStatic ? "static" : "instance") + " method " + method); - codeBuffer.emitString(""); - codeBuffer.emitString0("kernel &run ("); - codeBuffer.emitString(""); + asm.emitString0("// " + (isStatic ? "static" : "instance") + " method " + method); + asm.emitString(""); + asm.emitString0("kernel &run ("); + asm.emitString(""); FrameMap frameMap = crb.frameMap; RegisterConfig regConfig = frameMap.registerConfig; @@ -322,9 +313,9 @@ if (i != totalParamCount - 1) { str += ","; } - codeBuffer.emitString(str); + asm.emitString(str); } - codeBuffer.emitString(") {"); + asm.emitString(") {"); /* * End of parameters start of prolog code. Emit the load instructions for loading of the @@ -332,7 +323,7 @@ * loaded up front but will be loaded as needed. */ for (int i = 0; i < nonConstantParamCount; i++) { - codeBuffer.emitString("ld_kernarg_" + paramHsailSizes[i] + " " + HSAIL.mapRegister(cc.getArgument(i)) + ", [" + paramNames[i] + "];"); + asm.emitString("ld_kernarg_" + paramHsailSizes[i] + " " + HSAIL.mapRegister(cc.getArgument(i)) + ", [" + paramNames[i] + "];"); } /* @@ -340,16 +331,16 @@ * the register as if it were the last of the nonConstant parameters. */ String workItemReg = "$s" + Integer.toString(asRegister(cc.getArgument(nonConstantParamCount)).encoding()); - codeBuffer.emitString("workitemabsid_u32 " + workItemReg + ", 0;"); + asm.emitString("workitemabsid_u32 " + workItemReg + ", 0;"); /* * Note the logic used for this spillseg size is to leave space and then go back and patch * in the correct size once we have generated all the instructions. This should probably be * done in a more robust way by implementing something like codeBuffer.insertString. */ - int spillsegDeclarationPosition = codeBuffer.position() + 1; + int spillsegDeclarationPosition = asm.position() + 1; String spillsegTemplate = "align 4 spill_u8 %spillseg[123456];"; - codeBuffer.emitString(spillsegTemplate); + asm.emitString(spillsegTemplate); // Emit object array load prologue here. if (isObjectLambda) { boolean useCompressedOops = getRuntime().getConfig().useCompressedOops; @@ -359,37 +350,37 @@ // so tempReg can be the next higher $d register String tmpReg = "$d" + (asRegister(cc.getArgument(nonConstantParamCount - 1)).encoding() + 1); // Convert gid to long. - codeBuffer.emitString("cvt_u64_s32 " + tmpReg + ", " + workItemReg + "; // Convert gid to long"); + asm.emitString("cvt_u64_s32 " + tmpReg + ", " + workItemReg + "; // Convert gid to long"); // Adjust index for sizeof ref. Where to pull this size from? - codeBuffer.emitString("mul_u64 " + tmpReg + ", " + tmpReg + ", " + (useCompressedOops ? 4 : 8) + "; // Adjust index for sizeof ref"); + asm.emitString("mul_u64 " + tmpReg + ", " + tmpReg + ", " + (useCompressedOops ? 4 : 8) + "; // Adjust index for sizeof ref"); // Adjust for actual data start. - codeBuffer.emitString("add_u64 " + tmpReg + ", " + tmpReg + ", " + arrayElementsOffset + "; // Adjust for actual elements data start"); + asm.emitString("add_u64 " + tmpReg + ", " + tmpReg + ", " + arrayElementsOffset + "; // Adjust for actual elements data start"); // Add to array ref ptr. - codeBuffer.emitString("add_u64 " + tmpReg + ", " + tmpReg + ", " + iterationObjArgReg + "; // Add to array ref ptr"); + asm.emitString("add_u64 " + tmpReg + ", " + tmpReg + ", " + iterationObjArgReg + "; // Add to array ref ptr"); // Load the object into the parameter reg. if (useCompressedOops) { // Load u32 into the d 64 reg since it will become an object address - codeBuffer.emitString("ld_global_u32 " + tmpReg + ", " + "[" + tmpReg + "]" + "; // Load compressed ptr from array"); + asm.emitString("ld_global_u32 " + tmpReg + ", " + "[" + tmpReg + "]" + "; // Load compressed ptr from array"); long narrowOopBase = getRuntime().getConfig().narrowOopBase; long narrowOopShift = getRuntime().getConfig().narrowOopShift; if (narrowOopBase == 0 && narrowOopShift == 0) { // No more calculation to do, mov to target register - codeBuffer.emitString("mov_b64 " + iterationObjArgReg + ", " + tmpReg + "; // no shift or base addition"); + asm.emitString("mov_b64 " + iterationObjArgReg + ", " + tmpReg + "; // no shift or base addition"); } else { if (narrowOopBase == 0) { - codeBuffer.emitString("shl_u64 " + iterationObjArgReg + ", " + tmpReg + ", " + narrowOopShift + "; // do narrowOopShift"); + asm.emitString("shl_u64 " + iterationObjArgReg + ", " + tmpReg + ", " + narrowOopShift + "; // do narrowOopShift"); } else if (narrowOopShift == 0) { - codeBuffer.emitString("add_u64 " + iterationObjArgReg + ", " + tmpReg + ", " + narrowOopBase + "; // add narrowOopBase"); + asm.emitString("add_u64 " + iterationObjArgReg + ", " + tmpReg + ", " + narrowOopBase + "; // add narrowOopBase"); } else { - codeBuffer.emitString("mad_u64 " + iterationObjArgReg + ", " + tmpReg + ", " + (1 << narrowOopShift) + ", " + narrowOopBase + "; // shift and add narrowOopBase"); + asm.emitString("mad_u64 " + iterationObjArgReg + ", " + tmpReg + ", " + (1 << narrowOopShift) + ", " + narrowOopBase + "; // shift and add narrowOopBase"); } } } else { - codeBuffer.emitString("ld_global_u64 " + iterationObjArgReg + ", " + "[" + tmpReg + "]" + "; // Load from array element into parameter reg"); + asm.emitString("ld_global_u64 " + iterationObjArgReg + ", " + "[" + tmpReg + "]" + "; // Load from array element into parameter reg"); } } // Prologue done, Emit code for the LIR. @@ -405,9 +396,10 @@ } else { spillsegStringFinal = spillsegTemplate.replace("123456", String.format("%6d", maxStackSize)); } - codeBuffer.emitString(spillsegStringFinal, spillsegDeclarationPosition); + asm.emitString(spillsegStringFinal, spillsegDeclarationPosition); + // Emit the epilogue. - codeBuffer.emitString0("};"); - codeBuffer.emitString(""); + asm.emitString0("};"); + asm.emitString(""); } } diff -r f6c04e69cf75 -r 390c4b742890 graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotBackend.java --- a/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotBackend.java Thu Feb 27 16:05:29 2014 +0100 +++ b/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotBackend.java Thu Feb 27 11:33:17 2014 -0800 @@ -261,24 +261,24 @@ LIRInstruction op; - void emitDeclarations(Buffer codeBuffer) { + void emitDeclarations(AbstractAssembler asm) { for (Integer i : unsigned8) { - codeBuffer.emitString(".reg .u8 %r" + i.intValue() + ";"); + asm.emitString(".reg .u8 %r" + i.intValue() + ";"); } for (Integer i : signed32) { - codeBuffer.emitString(".reg .s32 %r" + i.intValue() + ";"); + asm.emitString(".reg .s32 %r" + i.intValue() + ";"); } for (Integer i : signed64) { - codeBuffer.emitString(".reg .s64 %r" + i.intValue() + ";"); + asm.emitString(".reg .s64 %r" + i.intValue() + ";"); } for (Integer i : unsigned64) { - codeBuffer.emitString(".reg .u64 %r" + i.intValue() + ";"); + asm.emitString(".reg .u64 %r" + i.intValue() + ";"); } for (Integer i : float32) { - codeBuffer.emitString(".reg .f32 %r" + i.intValue() + ";"); + asm.emitString(".reg .f32 %r" + i.intValue() + ";"); } for (Integer i : float64) { - codeBuffer.emitString(".reg .f64 %r" + i.intValue() + ";"); + asm.emitString(".reg .f64 %r" + i.intValue() + ";"); } } @@ -384,13 +384,13 @@ // facilitate seemless PTX code generation subsequently. assert codeCacheOwner != null : lirGen.getGraph() + " is not associated with a method"; final String name = codeCacheOwner.getName(); - Buffer codeBuffer = crb.asm.codeBuffer; + AbstractAssembler asm = crb.asm; // Emit initial boiler-plate directives. - codeBuffer.emitString(".version 3.0"); - codeBuffer.emitString(".target sm_30"); - codeBuffer.emitString0(".entry " + name + " ("); - codeBuffer.emitString(""); + asm.emitString(".version 3.0"); + asm.emitString(".target sm_30"); + asm.emitString0(".entry " + name + " ("); + asm.emitString(""); // Get the start block Block startBlock = lirGen.lir.cfg.getStartBlock(); @@ -413,8 +413,8 @@ } // Start emiting body of the PTX kernel. - codeBuffer.emitString0(") {"); - codeBuffer.emitString(""); + asm.emitString0(") {"); + asm.emitString(""); } // Emit .reg space declarations @@ -422,7 +422,6 @@ assert codeCacheOwner != null : lirGen.getGraph() + " is not associated with a method"; - Buffer codeBuffer = crb.asm.codeBuffer; RegisterAnalysis registerAnalysis = new RegisterAnalysis(); for (Block b : lirGen.lir.codeEmittingOrder()) { @@ -437,19 +436,21 @@ } } - registerAnalysis.emitDeclarations(codeBuffer); + AbstractAssembler asm = crb.asm; + registerAnalysis.emitDeclarations(asm); // emit predicate register declaration int maxPredRegNum = ((PTXLIRGenerator) lirGen).getNextPredRegNumber(); if (maxPredRegNum > 0) { - codeBuffer.emitString(".reg .pred %p<" + maxPredRegNum + ">;"); + asm.emitString(".reg .pred %p<" + maxPredRegNum + ">;"); } } @Override public void emitCode(CompilationResultBuilder crb, LIRGenerator lirGen, ResolvedJavaMethod codeCacheOwner) { assert codeCacheOwner != null : lirGen.getGraph() + " is not associated with a method"; - Buffer codeBuffer = crb.asm.codeBuffer; + AbstractAssembler asm = crb.asm; + // Emit the prologue emitKernelEntry(crb, lirGen, codeCacheOwner); @@ -460,8 +461,7 @@ e.printStackTrace(); // TODO : Better error handling needs to be done once // all types of parameters are handled. - codeBuffer.setPosition(0); - codeBuffer.close(false); + asm.close(false); return; } // Emit code for the LIR @@ -471,14 +471,13 @@ e.printStackTrace(); // TODO : Better error handling needs to be done once // all types of parameters are handled. - codeBuffer.setPosition(0); - codeBuffer.close(false); + asm.close(false); return; } // Emit the epilogue - codeBuffer.emitString0("}"); - codeBuffer.emitString(""); + asm.emitString0("}"); + asm.emitString(""); } /** diff -r f6c04e69cf75 -r 390c4b742890 graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotSafepointOp.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotSafepointOp.java Thu Feb 27 16:05:29 2014 +0100 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotSafepointOp.java Thu Feb 27 11:33:17 2014 -0800 @@ -59,7 +59,7 @@ } public static void emitCode(CompilationResultBuilder crb, SPARCMacroAssembler masm, HotSpotVMConfig config, boolean atReturn, LIRFrameState state, Register scratch) { - final int pos = masm.codeBuffer.position(); + final int pos = masm.position(); new Setx(config.safepointPollingAddress, scratch).emit(masm); crb.recordMark(atReturn ? MARK_POLL_RETURN_FAR : MARK_POLL_FAR); if (state != null) { diff -r f6c04e69cf75 -r 390c4b742890 graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Arithmetic.java --- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Arithmetic.java Thu Feb 27 16:05:29 2014 +0100 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Arithmetic.java Thu Feb 27 11:33:17 2014 -0800 @@ -554,7 +554,7 @@ case IDIV: case IREM: masm.cdql(); - exceptionOffset = masm.codeBuffer.position(); + exceptionOffset = masm.position(); masm.idivl(asRegister(src)); break; @@ -562,7 +562,7 @@ case LDIV: case LREM: masm.cdqq(); - exceptionOffset = masm.codeBuffer.position(); + exceptionOffset = masm.position(); masm.idivq(asRegister(src)); break; @@ -570,7 +570,7 @@ case IUREM: // Must zero the high 64-bit word (in RDX) of the dividend masm.xorq(AMD64.rdx, AMD64.rdx); - exceptionOffset = masm.codeBuffer.position(); + exceptionOffset = masm.position(); masm.divl(asRegister(src)); break; @@ -578,7 +578,7 @@ case LUREM: // Must zero the high 64-bit word (in RDX) of the dividend masm.xorq(AMD64.rdx, AMD64.rdx); - exceptionOffset = masm.codeBuffer.position(); + exceptionOffset = masm.position(); masm.divq(asRegister(src)); break; default: diff -r f6c04e69cf75 -r 390c4b742890 graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Call.java --- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Call.java Thu Feb 27 16:05:29 2014 +0100 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Call.java Thu Feb 27 11:33:17 2014 -0800 @@ -155,7 +155,7 @@ if (align) { emitAlignmentForDirectCall(crb, masm); } - int before = masm.codeBuffer.position(); + int before = masm.position(); if (scratch != null) { // offset might not fit a 32-bit immediate, generate an // indirect call with a 64-bit immediate @@ -164,7 +164,7 @@ } else { masm.call(); } - int after = masm.codeBuffer.position(); + int after = masm.position(); crb.recordDirectCall(before, after, callTarget, info); crb.recordExceptionHandlers(after, info); masm.ensureUniquePC(); @@ -172,7 +172,7 @@ protected static void emitAlignmentForDirectCall(CompilationResultBuilder crb, AMD64MacroAssembler masm) { // make sure that the displacement word of the call ends up word aligned - int offset = masm.codeBuffer.position(); + int offset = masm.position(); offset += crb.target.arch.getMachineCodeCallDisplacementOffset(); int modulus = crb.target.wordSize; if (offset % modulus != 0) { @@ -181,25 +181,25 @@ } public static void directJmp(CompilationResultBuilder crb, AMD64MacroAssembler masm, InvokeTarget target) { - int before = masm.codeBuffer.position(); + int before = masm.position(); masm.jmp(0, true); - int after = masm.codeBuffer.position(); + int after = masm.position(); crb.recordDirectCall(before, after, target, null); masm.ensureUniquePC(); } public static void directConditionalJmp(CompilationResultBuilder crb, AMD64MacroAssembler masm, InvokeTarget target, ConditionFlag cond) { - int before = masm.codeBuffer.position(); + int before = masm.position(); masm.jcc(cond, 0, true); - int after = masm.codeBuffer.position(); + int after = masm.position(); crb.recordDirectCall(before, after, target, null); masm.ensureUniquePC(); } public static void indirectCall(CompilationResultBuilder crb, AMD64MacroAssembler masm, Register dst, InvokeTarget callTarget, LIRFrameState info) { - int before = masm.codeBuffer.position(); + int before = masm.position(); masm.call(dst); - int after = masm.codeBuffer.position(); + int after = masm.position(); crb.recordIndirectCall(before, after, callTarget, info); crb.recordExceptionHandlers(after, info); masm.ensureUniquePC(); diff -r f6c04e69cf75 -r 390c4b742890 graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ControlFlow.java --- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ControlFlow.java Thu Feb 27 16:05:29 2014 +0100 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ControlFlow.java Thu Feb 27 11:33:17 2014 -0800 @@ -198,7 +198,6 @@ masm.movl(idxScratchReg, indexReg); } - Buffer buf = masm.codeBuffer; // Compare index against jump table bounds int highKey = lowKey + targets.length - 1; if (lowKey != 0) { @@ -215,9 +214,8 @@ } // Set scratch to address of jump table - int leaPos = buf.position(); masm.leaq(scratchReg, new AMD64Address(AMD64.rip, 0)); - int afterLea = buf.position(); + final int afterLea = masm.position(); // Load jump table entry into scratch and jump to it masm.movslq(idxScratchReg, new AMD64Address(scratchReg, idxScratchReg, Scale.Times4, 0)); @@ -225,29 +223,29 @@ masm.jmp(scratchReg); // Inserting padding so that jump table address is 4-byte aligned - if ((buf.position() & 0x3) != 0) { - masm.nop(4 - (buf.position() & 0x3)); + if ((masm.position() & 0x3) != 0) { + masm.nop(4 - (masm.position() & 0x3)); } // Patch LEA instruction above now that we know the position of the jump table - int jumpTablePos = buf.position(); - buf.setPosition(leaPos); - masm.leaq(scratchReg, new AMD64Address(AMD64.rip, jumpTablePos - afterLea)); - buf.setPosition(jumpTablePos); + // TODO this is ugly and should be done differently + final int jumpTablePos = masm.position(); + final int leaDisplacementPosition = afterLea - 4; + masm.emitInt(jumpTablePos - afterLea, leaDisplacementPosition); // Emit jump table entries for (LabelRef target : targets) { Label label = target.label(); - int offsetToJumpTableBase = buf.position() - jumpTablePos; + int offsetToJumpTableBase = masm.position() - jumpTablePos; if (label.isBound()) { int imm32 = label.position() - jumpTablePos; - buf.emitInt(imm32); + masm.emitInt(imm32); } else { - label.addPatchAt(buf.position()); + label.addPatchAt(masm.position()); - buf.emitByte(0); // pseudo-opcode for jump table entry - buf.emitShort(offsetToJumpTableBase); - buf.emitByte(0); // padding to make jump table entry 4 bytes wide + masm.emitByte(0); // pseudo-opcode for jump table entry + masm.emitShort(offsetToJumpTableBase); + masm.emitByte(0); // padding to make jump table entry 4 bytes wide } } diff -r f6c04e69cf75 -r 390c4b742890 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 Thu Feb 27 16:05:29 2014 +0100 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64Move.java Thu Feb 27 11:33:17 2014 -0800 @@ -112,7 +112,7 @@ @Override public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) { if (state != null) { - crb.recordImplicitException(masm.codeBuffer.position(), state); + crb.recordImplicitException(masm.position(), state); } emitMemAccess(crb, masm); } @@ -319,7 +319,7 @@ @Override public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) { - crb.recordImplicitException(masm.codeBuffer.position(), state); + crb.recordImplicitException(masm.position(), state); masm.nullCheck(asRegister(input)); } diff -r f6c04e69cf75 -r 390c4b742890 graal/com.oracle.graal.lir.hsail/src/com/oracle/graal/lir/hsail/HSAILMove.java --- a/graal/com.oracle.graal.lir.hsail/src/com/oracle/graal/lir/hsail/HSAILMove.java Thu Feb 27 16:05:29 2014 +0100 +++ b/graal/com.oracle.graal.lir.hsail/src/com/oracle/graal/lir/hsail/HSAILMove.java Thu Feb 27 11:33:17 2014 -0800 @@ -146,7 +146,7 @@ @Override public void emitCode(CompilationResultBuilder crb, HSAILAssembler masm) { if (state != null) { - // crb.recordImplicitException(masm.codeBuffer.position(), state); + // crb.recordImplicitException(masm.position(), state); throw new InternalError("NYI"); } emitMemAccess(masm); @@ -305,7 +305,7 @@ encodePointer(masm, scratch, base, shift, alignment, testForNull); if (state != null) { throw new InternalError("NYI"); - // crb.recordImplicitException(masm.codeBuffer.position(), state); + // crb.recordImplicitException(masm.position(), state); } masm.emitStore(scratch, address.toAddress(), "u32"); } diff -r f6c04e69cf75 -r 390c4b742890 graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXControlFlow.java --- a/graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXControlFlow.java Thu Feb 27 16:05:29 2014 +0100 +++ b/graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXControlFlow.java Thu Feb 27 11:33:17 2014 -0800 @@ -266,8 +266,6 @@ @Override public void emitCode(CompilationResultBuilder crb, PTXMacroAssembler masm) { - Buffer buf = masm.codeBuffer; - // Compare index against jump table bounds int highKey = lowKey + targets.length - 1; @@ -285,7 +283,7 @@ } // address of jump table - int tablePos = buf.position(); + int tablePos = masm.position(); JumpTable jt = new JumpTable(tablePos, lowKey, highKey, 4); String name = "jumptable" + jt.position; diff -r f6c04e69cf75 -r 390c4b742890 graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXMove.java --- a/graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXMove.java Thu Feb 27 16:05:29 2014 +0100 +++ b/graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXMove.java Thu Feb 27 11:33:17 2014 -0800 @@ -252,7 +252,7 @@ @Override public void emitCode(CompilationResultBuilder crb, PTXMacroAssembler masm) { - crb.recordImplicitException(masm.codeBuffer.position(), state); + crb.recordImplicitException(masm.position(), state); masm.nullCheck(asRegister(input)); } diff -r f6c04e69cf75 -r 390c4b742890 graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCCall.java --- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCCall.java Thu Feb 27 16:05:29 2014 +0100 +++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCCall.java Thu Feb 27 11:33:17 2014 -0800 @@ -147,7 +147,7 @@ if (align) { // We don't need alignment on SPARC. } - int before = masm.codeBuffer.position(); + int before = masm.position(); if (scratch != null) { // offset might not fit a 30-bit displacement, generate an // indirect call with a 64-bit immediate @@ -156,7 +156,7 @@ } else { new Call(0).emit(masm); } - int after = masm.codeBuffer.position(); + int after = masm.position(); crb.recordDirectCall(before, after, callTarget, info); crb.recordExceptionHandlers(after, info); new Nop().emit(masm); // delay slot @@ -164,19 +164,19 @@ } public static void indirectJmp(CompilationResultBuilder crb, SPARCMacroAssembler masm, Register dst, InvokeTarget target) { - int before = masm.codeBuffer.position(); + int before = masm.position(); new Sethix(0L, dst, true).emit(masm); new Jmp(new SPARCAddress(dst, 0)).emit(masm); - int after = masm.codeBuffer.position(); + int after = masm.position(); crb.recordIndirectCall(before, after, target, null); new Nop().emit(masm); // delay slot masm.ensureUniquePC(); } public static void indirectCall(CompilationResultBuilder crb, SPARCMacroAssembler masm, Register dst, InvokeTarget callTarget, LIRFrameState info) { - int before = masm.codeBuffer.position(); + int before = masm.position(); new Jmpl(dst, 0, o7).emit(masm); - int after = masm.codeBuffer.position(); + int after = masm.position(); crb.recordIndirectCall(before, after, callTarget, info); crb.recordExceptionHandlers(after, info); new Nop().emit(masm); // delay slot diff -r f6c04e69cf75 -r 390c4b742890 graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCControlFlow.java --- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCControlFlow.java Thu Feb 27 16:05:29 2014 +0100 +++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCControlFlow.java Thu Feb 27 11:33:17 2014 -0800 @@ -234,7 +234,6 @@ Register value = asIntReg(index); Register scratchReg = asLongReg(scratch); - Buffer buf = masm.codeBuffer; // Compare index against jump table bounds int highKey = lowKey + targets.length - 1; if (lowKey != 0) { @@ -258,7 +257,7 @@ new Nop().emit(masm); // delay slot // address of jump table - int tablePos = buf.position(); + int tablePos = masm.position(); JumpTable jt = new JumpTable(tablePos, lowKey, highKey, 4); crb.compilationResult.addAnnotation(jt); diff -r f6c04e69cf75 -r 390c4b742890 graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCMove.java --- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCMove.java Thu Feb 27 16:05:29 2014 +0100 +++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCMove.java Thu Feb 27 11:33:17 2014 -0800 @@ -110,7 +110,7 @@ @Override public void emitCode(CompilationResultBuilder crb, SPARCMacroAssembler masm) { if (state != null) { - crb.recordImplicitException(masm.codeBuffer.position(), state); + crb.recordImplicitException(masm.position(), state); } emitMemAccess(masm); } @@ -215,7 +215,7 @@ @Override public void emitCode(CompilationResultBuilder crb, SPARCMacroAssembler masm) { - crb.recordImplicitException(masm.codeBuffer.position(), state); + crb.recordImplicitException(masm.position(), state); new Ldx(new SPARCAddress(asRegister(input), 0), r0).emit(masm); } diff -r f6c04e69cf75 -r 390c4b742890 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/InfopointOp.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/InfopointOp.java Thu Feb 27 16:05:29 2014 +0100 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/InfopointOp.java Thu Feb 27 11:33:17 2014 -0800 @@ -42,6 +42,6 @@ @Override public void emitCode(CompilationResultBuilder crb) { - crb.recordInfopoint(crb.asm.codeBuffer.position(), state, reason); + crb.recordInfopoint(crb.asm.position(), state, reason); } } diff -r f6c04e69cf75 -r 390c4b742890 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/asm/CompilationResultBuilder.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/asm/CompilationResultBuilder.java Thu Feb 27 16:05:29 2014 +0100 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/asm/CompilationResultBuilder.java Thu Feb 27 11:33:17 2014 -0800 @@ -97,15 +97,15 @@ private static final CompilationResult.Mark[] NO_REFS = {}; public CompilationResult.Mark recordMark(Object id) { - return compilationResult.recordMark(asm.codeBuffer.position(), id, NO_REFS); + return compilationResult.recordMark(asm.position(), id, NO_REFS); } public CompilationResult.Mark recordMark(Object id, CompilationResult.Mark... references) { - return compilationResult.recordMark(asm.codeBuffer.position(), id, references); + return compilationResult.recordMark(asm.position(), id, references); } public void blockComment(String s) { - compilationResult.addAnnotation(new CompilationResult.CodeComment(asm.codeBuffer.position(), s)); + compilationResult.addAnnotation(new CompilationResult.CodeComment(asm.position(), s)); } /** @@ -114,7 +114,7 @@ * the compilation result. */ public void finish() { - compilationResult.setTargetCode(asm.codeBuffer.close(false), asm.codeBuffer.position()); + compilationResult.setTargetCode(asm.close(false), asm.position()); // Record exception handlers if they exist if (exceptionInfoList != null) { @@ -159,7 +159,7 @@ public void recordInlineDataInCode(Constant data) { assert data != null; - int pos = asm.codeBuffer.position(); + int pos = asm.position(); Debug.log("Inline data in code: pos = %d, data = %s", pos, data); compilationResult.recordInlineData(pos, data); } @@ -171,7 +171,7 @@ public AbstractAddress recordDataReferenceInCode(Data data) { assert data != null; - int pos = asm.codeBuffer.position(); + int pos = asm.position(); Debug.log("Data reference in code: pos = %d, data = %s", pos, data); compilationResult.recordDataReference(pos, data); return asm.getPlaceholder(); diff -r f6c04e69cf75 -r 390c4b742890 graal/com.oracle.graal.truffle.hotspot.amd64/src/com/oracle/graal/truffle/hotspot/amd64/AMD64OptimizedCallTargetInstrumentationFactory.java --- a/graal/com.oracle.graal.truffle.hotspot.amd64/src/com/oracle/graal/truffle/hotspot/amd64/AMD64OptimizedCallTargetInstrumentationFactory.java Thu Feb 27 16:05:29 2014 +0100 +++ b/graal/com.oracle.graal.truffle.hotspot.amd64/src/com/oracle/graal/truffle/hotspot/amd64/AMD64OptimizedCallTargetInstrumentationFactory.java Thu Feb 27 11:33:17 2014 -0800 @@ -51,14 +51,14 @@ Register thisRegister = codeCache.getRegisterConfig().getCallingConventionRegisters(Type.JavaCall, Kind.Object)[0]; Register spillRegister = AMD64.r10; // TODO(mg): fix me AMD64Address nMethodAddress = new AMD64Address(thisRegister, getFieldOffset("installedCode", OptimizedCallTarget.class)); - int verifiedEntryPoint = asm.codeBuffer.position(); + int verifiedEntryPoint = asm.position(); if (config.useCompressedOops) { asm.movl(spillRegister, nMethodAddress); - asm.nop(AMD64HotSpotBackend.PATCHED_VERIFIED_ENTRY_POINT_INSTRUCTION_SIZE - (asm.codeBuffer.position() - verifiedEntryPoint)); + asm.nop(AMD64HotSpotBackend.PATCHED_VERIFIED_ENTRY_POINT_INSTRUCTION_SIZE - (asm.position() - verifiedEntryPoint)); AMD64HotSpotMove.decodePointer(asm, spillRegister, registers.getHeapBaseRegister(), config.getOopEncoding()); } else { asm.movq(spillRegister, nMethodAddress); - asm.nop(AMD64HotSpotBackend.PATCHED_VERIFIED_ENTRY_POINT_INSTRUCTION_SIZE - (asm.codeBuffer.position() - verifiedEntryPoint)); + asm.nop(AMD64HotSpotBackend.PATCHED_VERIFIED_ENTRY_POINT_INSTRUCTION_SIZE - (asm.position() - verifiedEntryPoint)); } Label doProlog = new Label();