Fix various bugs found when debugger is attached to the VM.
See b/2161257 for details.
diff --git a/vm/compiler/Frontend.c b/vm/compiler/Frontend.c
index b224614..163cdf8 100644
--- a/vm/compiler/Frontend.c
+++ b/vm/compiler/Frontend.c
@@ -47,6 +47,8 @@
return insnWidth;
}
+#define UNKNOWN_TARGET 0xffffffff
+
/*
* Identify block-ending instructions and collect supplemental information
* regarding the following instructions.
@@ -63,6 +65,8 @@
case OP_RETURN_WIDE:
case OP_RETURN_OBJECT:
case OP_THROW:
+ *target = UNKNOWN_TARGET;
+ break;
case OP_INVOKE_VIRTUAL:
case OP_INVOKE_VIRTUAL_RANGE:
case OP_INVOKE_INTERFACE:
@@ -146,7 +150,8 @@
default:
return false;
- } return true;
+ }
+ return true;
}
/*
@@ -524,7 +529,8 @@
/* Target block not included in the trace */
if (curBB->taken == NULL &&
- (isInvoke || (targetOffset != curOffset))) {
+ (isInvoke || (targetOffset != UNKNOWN_TARGET &&
+ targetOffset != curOffset))) {
BasicBlock *newBB;
if (isInvoke) {
/* Monomorphic callee */
diff --git a/vm/interp/Jit.c b/vm/interp/Jit.c
index 5147e9c..68137a0 100644
--- a/vm/interp/Jit.c
+++ b/vm/interp/Jit.c
@@ -644,7 +644,11 @@
break;
#endif
default:
- dvmAbort();
+ if (!debugOrProfile) {
+ LOGE("Unexpected JIT state: %d", interpState->jitState);
+ dvmAbort();
+ }
+ break;
}
return switchInterp;
}
@@ -908,6 +912,7 @@
#endif
break;
default:
+ LOGE("Unexpected JIT state: %d", interpState->jitState);
dvmAbort();
}
}
diff --git a/vm/mterp/armv5te/footer.S b/vm/mterp/armv5te/footer.S
index c204470..d92c537 100644
--- a/vm/mterp/armv5te/footer.S
+++ b/vm/mterp/armv5te/footer.S
@@ -218,6 +218,8 @@
common_selectTrace:
mov r2,#kJitTSelectRequest @ ask for trace selection
str r2,[rGLUE,#offGlue_jitState]
+ mov r2,#kInterpEntryInstr @ normal entry reason
+ str r2,[rGLUE,#offGlue_entryPoint]
mov r1,#1 @ set changeInterp
b common_gotoBail
@@ -306,6 +308,9 @@
common_periodicChecks:
ldr r3, [rGLUE, #offGlue_pSelfSuspendCount] @ r3<- &suspendCount
+ @ speculatively store r0 before it is clobbered by dvmCheckSuspendPending
+ str r0, [rGLUE, #offGlue_entryPoint]
+
#if defined(WITH_DEBUGGER)
ldr r1, [rGLUE, #offGlue_pDebuggerActive] @ r1<- &debuggerActive
#endif
@@ -346,7 +351,6 @@
3: @ debugger/profiler enabled, bail out
add rPC, rPC, r9 @ update rPC
- str r0, [rGLUE, #offGlue_entryPoint]
mov r1, #1 @ "want switch" = true
b common_gotoBail
diff --git a/vm/mterp/out/InterpAsm-armv4t.S b/vm/mterp/out/InterpAsm-armv4t.S
index 3f9d371..9c7fcdc 100644
--- a/vm/mterp/out/InterpAsm-armv4t.S
+++ b/vm/mterp/out/InterpAsm-armv4t.S
@@ -9690,6 +9690,8 @@
common_selectTrace:
mov r2,#kJitTSelectRequest @ ask for trace selection
str r2,[rGLUE,#offGlue_jitState]
+ mov r2,#kInterpEntryInstr @ normal entry reason
+ str r2,[rGLUE,#offGlue_entryPoint]
mov r1,#1 @ set changeInterp
b common_gotoBail
@@ -9778,6 +9780,9 @@
common_periodicChecks:
ldr r3, [rGLUE, #offGlue_pSelfSuspendCount] @ r3<- &suspendCount
+ @ speculatively store r0 before it is clobbered by dvmCheckSuspendPending
+ str r0, [rGLUE, #offGlue_entryPoint]
+
#if defined(WITH_DEBUGGER)
ldr r1, [rGLUE, #offGlue_pDebuggerActive] @ r1<- &debuggerActive
#endif
@@ -9818,7 +9823,6 @@
3: @ debugger/profiler enabled, bail out
add rPC, rPC, r9 @ update rPC
- str r0, [rGLUE, #offGlue_entryPoint]
mov r1, #1 @ "want switch" = true
b common_gotoBail
diff --git a/vm/mterp/out/InterpAsm-armv5te-vfp.S b/vm/mterp/out/InterpAsm-armv5te-vfp.S
index f36575b..d367124 100644
--- a/vm/mterp/out/InterpAsm-armv5te-vfp.S
+++ b/vm/mterp/out/InterpAsm-armv5te-vfp.S
@@ -9208,6 +9208,8 @@
common_selectTrace:
mov r2,#kJitTSelectRequest @ ask for trace selection
str r2,[rGLUE,#offGlue_jitState]
+ mov r2,#kInterpEntryInstr @ normal entry reason
+ str r2,[rGLUE,#offGlue_entryPoint]
mov r1,#1 @ set changeInterp
b common_gotoBail
@@ -9296,6 +9298,9 @@
common_periodicChecks:
ldr r3, [rGLUE, #offGlue_pSelfSuspendCount] @ r3<- &suspendCount
+ @ speculatively store r0 before it is clobbered by dvmCheckSuspendPending
+ str r0, [rGLUE, #offGlue_entryPoint]
+
#if defined(WITH_DEBUGGER)
ldr r1, [rGLUE, #offGlue_pDebuggerActive] @ r1<- &debuggerActive
#endif
@@ -9336,7 +9341,6 @@
3: @ debugger/profiler enabled, bail out
add rPC, rPC, r9 @ update rPC
- str r0, [rGLUE, #offGlue_entryPoint]
mov r1, #1 @ "want switch" = true
b common_gotoBail
diff --git a/vm/mterp/out/InterpAsm-armv5te.S b/vm/mterp/out/InterpAsm-armv5te.S
index d05ccbb..1ff0d19 100644
--- a/vm/mterp/out/InterpAsm-armv5te.S
+++ b/vm/mterp/out/InterpAsm-armv5te.S
@@ -9684,6 +9684,8 @@
common_selectTrace:
mov r2,#kJitTSelectRequest @ ask for trace selection
str r2,[rGLUE,#offGlue_jitState]
+ mov r2,#kInterpEntryInstr @ normal entry reason
+ str r2,[rGLUE,#offGlue_entryPoint]
mov r1,#1 @ set changeInterp
b common_gotoBail
@@ -9772,6 +9774,9 @@
common_periodicChecks:
ldr r3, [rGLUE, #offGlue_pSelfSuspendCount] @ r3<- &suspendCount
+ @ speculatively store r0 before it is clobbered by dvmCheckSuspendPending
+ str r0, [rGLUE, #offGlue_entryPoint]
+
#if defined(WITH_DEBUGGER)
ldr r1, [rGLUE, #offGlue_pDebuggerActive] @ r1<- &debuggerActive
#endif
@@ -9812,7 +9817,6 @@
3: @ debugger/profiler enabled, bail out
add rPC, rPC, r9 @ update rPC
- str r0, [rGLUE, #offGlue_entryPoint]
mov r1, #1 @ "want switch" = true
b common_gotoBail
diff --git a/vm/mterp/out/InterpAsm-armv7-a.S b/vm/mterp/out/InterpAsm-armv7-a.S
index 9c77641..e3ed962 100644
--- a/vm/mterp/out/InterpAsm-armv7-a.S
+++ b/vm/mterp/out/InterpAsm-armv7-a.S
@@ -9144,6 +9144,8 @@
common_selectTrace:
mov r2,#kJitTSelectRequest @ ask for trace selection
str r2,[rGLUE,#offGlue_jitState]
+ mov r2,#kInterpEntryInstr @ normal entry reason
+ str r2,[rGLUE,#offGlue_entryPoint]
mov r1,#1 @ set changeInterp
b common_gotoBail
@@ -9232,6 +9234,9 @@
common_periodicChecks:
ldr r3, [rGLUE, #offGlue_pSelfSuspendCount] @ r3<- &suspendCount
+ @ speculatively store r0 before it is clobbered by dvmCheckSuspendPending
+ str r0, [rGLUE, #offGlue_entryPoint]
+
#if defined(WITH_DEBUGGER)
ldr r1, [rGLUE, #offGlue_pDebuggerActive] @ r1<- &debuggerActive
#endif
@@ -9272,7 +9277,6 @@
3: @ debugger/profiler enabled, bail out
add rPC, rPC, r9 @ update rPC
- str r0, [rGLUE, #offGlue_entryPoint]
mov r1, #1 @ "want switch" = true
b common_gotoBail
diff --git a/vm/mterp/out/InterpC-portdbg.c b/vm/mterp/out/InterpC-portdbg.c
index c2ae63c..03fe00e 100644
--- a/vm/mterp/out/InterpC-portdbg.c
+++ b/vm/mterp/out/InterpC-portdbg.c
@@ -421,11 +421,9 @@
checkDebugAndProf(pc, fp, self, curMethod, &debugIsMethodEntry)
#if defined(WITH_JIT)
-#define CHECK_JIT() \
- if (dvmCheckJit(pc, self, interpState)) GOTO_bail_switch()
+#define CHECK_JIT() (dvmCheckJit(pc, self, interpState))
#else
-#define CHECK_JIT() \
- ((void)0)
+#define CHECK_JIT() (0)
#endif
/* File: portable/stubdefs.c */
@@ -459,7 +457,7 @@
inst = FETCH(0); \
CHECK_DEBUG_AND_PROF(); \
CHECK_TRACKED_REFS(); \
- CHECK_JIT(); \
+ if (CHECK_JIT()) GOTO_bail_switch(); \
goto *handlerTable[INST_INST(inst)]; \
}
#else
@@ -520,7 +518,6 @@
} \
}
-
/* File: c/opcommon.c */
/* forward declarations of goto targets */
GOTO_TARGET_DECL(filledNewArray, bool methodCallRange);
@@ -1546,6 +1543,7 @@
/* just fall through to instruction loop or threaded kickstart */
break;
case kInterpEntryReturn:
+ CHECK_JIT();
goto returnFromMethod;
case kInterpEntryThrow:
goto exceptionThrown;
diff --git a/vm/mterp/out/InterpC-portstd.c b/vm/mterp/out/InterpC-portstd.c
index b695b43..a092da0 100644
--- a/vm/mterp/out/InterpC-portstd.c
+++ b/vm/mterp/out/InterpC-portstd.c
@@ -419,7 +419,7 @@
#define CHECK_DEBUG_AND_PROF() ((void)0)
-#define CHECK_JIT() ((void)0)
+#define CHECK_JIT() (0)
/* File: portable/stubdefs.c */
/*
@@ -452,7 +452,7 @@
inst = FETCH(0); \
CHECK_DEBUG_AND_PROF(); \
CHECK_TRACKED_REFS(); \
- CHECK_JIT(); \
+ if (CHECK_JIT()) GOTO_bail_switch(); \
goto *handlerTable[INST_INST(inst)]; \
}
#else
@@ -513,7 +513,6 @@
} \
}
-
/* File: c/opcommon.c */
/* forward declarations of goto targets */
GOTO_TARGET_DECL(filledNewArray, bool methodCallRange);
@@ -1260,6 +1259,7 @@
/* just fall through to instruction loop or threaded kickstart */
break;
case kInterpEntryReturn:
+ CHECK_JIT();
goto returnFromMethod;
case kInterpEntryThrow:
goto exceptionThrown;
diff --git a/vm/mterp/portable/entry.c b/vm/mterp/portable/entry.c
index f0e63f1..4a6ed4e 100644
--- a/vm/mterp/portable/entry.c
+++ b/vm/mterp/portable/entry.c
@@ -95,6 +95,7 @@
/* just fall through to instruction loop or threaded kickstart */
break;
case kInterpEntryReturn:
+ CHECK_JIT();
goto returnFromMethod;
case kInterpEntryThrow:
goto exceptionThrown;
diff --git a/vm/mterp/portable/portdbg.c b/vm/mterp/portable/portdbg.c
index 04132cb..014d866 100644
--- a/vm/mterp/portable/portdbg.c
+++ b/vm/mterp/portable/portdbg.c
@@ -5,9 +5,7 @@
checkDebugAndProf(pc, fp, self, curMethod, &debugIsMethodEntry)
#if defined(WITH_JIT)
-#define CHECK_JIT() \
- if (dvmCheckJit(pc, self, interpState)) GOTO_bail_switch()
+#define CHECK_JIT() (dvmCheckJit(pc, self, interpState))
#else
-#define CHECK_JIT() \
- ((void)0)
+#define CHECK_JIT() (0)
#endif
diff --git a/vm/mterp/portable/portstd.c b/vm/mterp/portable/portstd.c
index f55e8e7..f13bca7 100644
--- a/vm/mterp/portable/portstd.c
+++ b/vm/mterp/portable/portstd.c
@@ -3,4 +3,4 @@
#define CHECK_DEBUG_AND_PROF() ((void)0)
-#define CHECK_JIT() ((void)0)
+#define CHECK_JIT() (0)
diff --git a/vm/mterp/portable/stubdefs.c b/vm/mterp/portable/stubdefs.c
index 305aebb..717e746 100644
--- a/vm/mterp/portable/stubdefs.c
+++ b/vm/mterp/portable/stubdefs.c
@@ -28,7 +28,7 @@
inst = FETCH(0); \
CHECK_DEBUG_AND_PROF(); \
CHECK_TRACKED_REFS(); \
- CHECK_JIT(); \
+ if (CHECK_JIT()) GOTO_bail_switch(); \
goto *handlerTable[INST_INST(inst)]; \
}
#else
@@ -88,4 +88,3 @@
GOTO_bail_switch(); \
} \
}
-