Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/kilim/kilim
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregory Burd committed Oct 10, 2011
2 parents dd22577 + 4e59bbb commit c55e16f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/main/java/kilim/analysis/MethodWeaver.java
Expand Up @@ -417,15 +417,17 @@ private void genException(MethodVisitor mv, BasicBlock bb, List<CallWeaver> cwLi
VMType.loadVar(mv, VMType.TOBJECT, getFiberVar());
mv.visitMethodInsn(INVOKEVIRTUAL, FIBER_CLASS, "upEx", "()I");
// fiber.pc is on stack
Label[] labels = new Label[cwList.size() + 1];
labels[0] = resumeLabel;
Label[] labels = new Label[cwList.size()];
int[] keys = new int[cwList.size()];
for (int i = 0; i < cwList.size(); i++) {
labels[i + 1] = new Label();
labels[i] = new Label();
keys[i] = callWeavers.indexOf(cwList.get(i)) + 1;
}
mv.visitTableSwitchInsn(0, cwList.size(), resumeLabel, labels);
int i = 1;

mv.visitLookupSwitchInsn(resumeLabel, keys, labels);
int i = 0;
for (CallWeaver cw: cwList) {
if (i > 1) {
if (i > 0) {
// This is the jump (to normal exception handling) for the previous
// switch case.
mv.visitJumpInsn(GOTO, resumeLabel);
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/kilim/test/TestYieldExceptions.java
Expand Up @@ -39,4 +39,9 @@ public void testNestedException() throws Exception {
public void testTryCatchFinally() throws Exception {
TestYield.runTask(new kilim.test.ex.ExCatch(3));
}


public void testPausableBlocksBeforeCatch() throws Exception {
TestYield.runTask(new kilim.test.ex.ExCatch(4));
}
}
27 changes: 27 additions & 0 deletions src/test/java/kilim/test/ex/ExCatch.java
Expand Up @@ -30,6 +30,7 @@ private void test() throws Pausable {
case 1: pausableCatch(); break;
case 2: nestedPausableCatch(); break;
case 3: tryCatchFinally(); break;
case 4: pausableBeforeCatch(); break;
default: throw new IllegalStateException("Unknown test case: " + testCase);
}
}
Expand Down Expand Up @@ -72,6 +73,32 @@ void pausableCatch() throws Pausable {
verify(l);
}

// Issue#6 on github. A pausable block before the catch block.
void pausableBeforeCatch() throws Pausable {
int foo = 0;
Task.sleep(1);
if (foo != 0) throw new RuntimeException("Expected 0");

foo = 1;
Task.sleep(1);
if (foo != 1) throw new RuntimeException("Expected 1");

foo = 2;
Task.sleep(1);
if (foo != 2) throw new RuntimeException("Expected 2");

try {
foo = 3;
throwEx();
} catch (Throwable t) {
if (foo != 3) throw new RuntimeException("Expected 3");
}
}
private static void throwEx() throws Pausable {
Task.sleep(1);
throw new RuntimeException();
}

void tryCatchFinally() throws Pausable {
short sh = fsh;
String s = fs;
Expand Down

0 comments on commit c55e16f

Please sign in to comment.