Commit 8c55ba5b authored by Yi Lin's avatar Yi Lin

working on codepatching opt

parent deeff9a3
......@@ -12,9 +12,9 @@
#
target.arch=ia32
target.os=Linux
target.bootimage.code.address=0x64000000
target.bootimage.code.address=0x68000000
target.bootimage.data.address=0x60000000
target.bootimage.rmap.address=0x67000000
target.bootimage.rmap.address=0x6b000000
target.max-mappable.address=0xb0000000
target.address.size=32
target.dll-ext=.so
......
......@@ -1323,6 +1323,10 @@ public class GenerateAssembler {
emitTab(3);
emit("case FORCENOP_opcode:\n");
emitTab(4);
emit("if (org.mmtk.vm.VM.config.YIELDPOINT_IMPL == org.mmtk.vm.Config.USE_CODE_PATCHING_YP)\n");
emitTab(5);
emit("ir.compiledMethod.addYPOffset(mi);\n");
emitTab(4);
emit("emitNOP(1);\n");
emitTab(4);
emit("break;\n");
......
......@@ -36,7 +36,7 @@ public final class HeapLayoutConstants {
Address.@_ADDRESS_METHOD_@( @_MAXIMUM_MAPPABLE_ADDRESS_@ );
/** The maximum boot image data size */
public static final int BOOT_IMAGE_DATA_SIZE = 56<<20;
public static final int BOOT_IMAGE_DATA_SIZE = 120<<20;
/** The maximum boot image code size */
public static final int BOOT_IMAGE_CODE_SIZE = 24<<20;
......
......@@ -83,12 +83,17 @@ public abstract class CompiledMethod {
*/
protected CodeArray instructions;
public static final int MAX_YP = 128;
public int[] ypOffsets = new int[MAX_YP];
public int ypOffsetsIndex = 0;
private static final int MAX_YP = 512;
private int[] ypOffsets = new int[MAX_YP];
private int ypOffsetsIndex = 0;
@Uninterruptible
public final void addYPOffset(int offset) {
public final void addYPOffset(int offset) {
VM.sysWrite("adding YP offset ", offset);
VM.sysWrite(" to method: ");
VM.sysWrite(method.getDeclaringClass().getDescriptor());
VM.sysWriteln(method.getName());
if (ypOffsetsIndex < MAX_YP) {
ypOffsets[ypOffsetsIndex] = offset;
ypOffsetsIndex ++;
......@@ -101,7 +106,7 @@ public abstract class CompiledMethod {
static final byte NOP = (byte) 0x90;
@Uninterruptible
public final void nop2int() {
public final void nop2int() {
int instrSize = instructions.length();
for (int i = 0; i < ypOffsetsIndex; i++) {
......
......@@ -335,6 +335,8 @@ public class CompiledMethods {
@Uninterruptible
public static void setNOP2INT() {
VM.sysWriteln("-----Start patching code-----");
int patched = 0;
long start = Magic.getTimeBase();
......
......@@ -441,6 +441,10 @@ public class FinalMIRExpansion extends IRTools {
} else if (org.mmtk.vm.VM.config.YIELDPOINT_IMPL == org.mmtk.vm.Config.USE_NONOP_YP) {
expandNopYieldpoint(p, ir, 0);
}
// code patching
else if (org.mmtk.vm.VM.config.YIELDPOINT_IMPL == org.mmtk.vm.Config.USE_CODE_PATCHING_YP) {
expandCodePatchingYieldpoint(p, ir);
}
break;
case YIELDPOINT_EPILOGUE_opcode:
......@@ -471,6 +475,10 @@ public class FinalMIRExpansion extends IRTools {
} else if (org.mmtk.vm.VM.config.YIELDPOINT_IMPL == org.mmtk.vm.Config.USE_NONOP_YP) {
expandNopYieldpoint(p, ir, 0);
}
// code patching
else if (org.mmtk.vm.VM.config.YIELDPOINT_IMPL == org.mmtk.vm.Config.USE_CODE_PATCHING_YP) {
expandCodePatchingYieldpoint(p, ir);
}
break;
case YIELDPOINT_BACKEDGE_opcode:
......@@ -501,6 +509,10 @@ public class FinalMIRExpansion extends IRTools {
} else if (org.mmtk.vm.VM.config.YIELDPOINT_IMPL == org.mmtk.vm.Config.USE_NONOP_YP) {
expandNopYieldpoint(p, ir, 0);
}
// code patching
else if (org.mmtk.vm.VM.config.YIELDPOINT_IMPL == org.mmtk.vm.Config.USE_CODE_PATCHING_YP) {
expandCodePatchingYieldpoint(p, ir);
}
break;
case YIELDPOINT_OSR_opcode:
......@@ -513,6 +525,10 @@ public class FinalMIRExpansion extends IRTools {
return 0;
}
private static void expandCodePatchingYieldpoint(Instruction p, IR ir) {
MIR_Empty.mutate(p, FORCENOP);
}
private static void expandNopYieldpoint(Instruction p, IR ir, int n) {
Instruction nop = null;
if (n == 1) {
......
......@@ -5663,6 +5663,10 @@ public final class RVMThread extends ThreadContext {
public static final Address PROTECT_GLOBAL_PAGE_OPT = PROTECT_GLOBAL_PAGE_BL.plus(4);
public static void turnOnGlobalYieldpoints() {
if (!VM.runningVM) {
RVMThread.dumpStack();
}
if (org.mmtk.vm.VM.config.YIELDPOINT_IMPL == org.mmtk.vm.Config.USE_GLOBAL_CHECKING_YP)
takeYieldpointGlobal = 1;
else if (org.mmtk.vm.VM.config.YIELDPOINT_IMPL == org.mmtk.vm.Config.USE_GLOBAL_PAGE_PROTECTION_READ_YP ||
......
......@@ -104,7 +104,7 @@ const char *bootDataFilename = 0;
const char *bootRMapFilename = 0;
/* Emit trace information? */
int lib_verbose = 0;
int lib_verbose = 1;
/* Location of jtoc within virtual machine image. */
static Address VmToc;
......@@ -654,18 +654,27 @@ hardwareTrapHandler(int signo, siginfo_t *si, void *context)
/* Test for code patching yield point */
if (YIELDPOINT_IMPL == 3 && signo == 5){
/* Insert artifical stackframe at the stack top */
Address * sp = (Address *)(IA32_ESP(context) - 4);
IA32_ESP(context) = IA32_ESP(context) - 4;
// instructionFollowing = getInstructionFollowing(localInstructionAddress);
*sp = localInstructionAddress;
printf("code patching YP handler.\n");
printf("-cur instruction=%x\n", *(unsigned char *)(localInstructionAddress));
printf("-last instruction=%x\n", *(unsigned char *)(localInstructionAddress - 1));
printf("-next instruction=%x\n", *(unsigned char *)(localInstructionAddress + 1));
printf("code patching YP handler\n");
if (*(unsigned char *)(localInstructionAddress - 1) == 0xCC) {
// is INT 3 instruction
/* Insert artifical stackframe at the stack top */
Address * sp = (Address *)(IA32_ESP(context) - 4);
IA32_ESP(context) = IA32_ESP(context) - 4;
// instructionFollowing = getInstructionFollowing(localInstructionAddress);
*sp = localInstructionAddress;
unsigned int yieldPointHandlerAddress =
*(unsigned int *) (localJTOC + bootRecord->yieldpointFromPrologueOffset);
IA32_EIP(context) = yieldPointHandlerAddress;
return;
}
unsigned int yieldPointHandlerAddress =
*(unsigned int *) (localJTOC + bootRecord->yieldpointFromPrologueOffset);
IA32_EIP(context) = yieldPointHandlerAddress;
return;
}
if (YIELDPOINT_IMPL == 11 || YIELDPOINT_IMPL == 12) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment