Skip to content

Commit

Permalink
Merge pull request #8 from DanielSperry/master
Browse files Browse the repository at this point in the history
Fixed problem with the restore order of variables initialized with NULL.
  • Loading branch information
JoeHegarty authored Nov 1, 2016
2 parents 2d253ec + 49a64db commit 8a554c8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
19 changes: 13 additions & 6 deletions async/src/main/java/com/ea/async/instrumentation/Transformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1521,6 +1521,7 @@ private void restoreStackAndLocals(final ClassNode classNode, final MethodNode o
}
}
// push the arguments that must be copied to locals
// must only push
for (int iLocal = 0; iLocal < frame.getLocals(); iLocal += valueSize(frame.getLocal(iLocal)))
{
final BasicValue value = frame.getLocal(iLocal);
Expand All @@ -1531,20 +1532,26 @@ private void restoreStackAndLocals(final ClassNode classNode, final MethodNode o
mv.visitVarInsn(value.getType().getOpcode(ILOAD), se.localToiArgument[iLocal]);
}
}
else if (value != null && value.getType() != null)
{
pushDefault(mv, value);
mv.visitVarInsn(value.getType().getOpcode(ISTORE), iLocal);
}
}
// push the arguments that must be copied to locals
// stores the values that came from arguments
for (int iLocal = frame.getLocals(); --iLocal >= 0; )
{
if (se.localToiArgument[iLocal] >= 0 && se.localToiArgument[iLocal] != iLocal)
{
mv.visitVarInsn(frame.getLocal(iLocal).getType().getOpcode(ISTORE), iLocal);
}
}
// restore values that were initialized as constants (i.e.: ACONST_NULL)
for (int iLocal = 0; iLocal < frame.getLocals(); iLocal += valueSize(frame.getLocal(iLocal)))
{
final BasicValue value = frame.getLocal(iLocal);
if (se.localToiArgument[iLocal] < 0 && value != null && value.getType() != null)
{
pushDefault(mv, value);
mv.visitVarInsn(value.getType().getOpcode(ISTORE), iLocal);
}
}

// reacquire monitors
for (int i = 0; i < se.frame.monitors.length; i++)
{
Expand Down
32 changes: 32 additions & 0 deletions async/src/test/java/com/ea/async/test/NullThenBasicValueTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.ea.async.test;

import com.ea.async.Task;

import org.junit.Test;

import static com.ea.async.Async.await;
import static org.junit.Assert.assertNull;

public class NullThenBasicValueTest extends BaseTest
{
@Test
public void nullThenBasicValueTest() throws Exception
{
debugTransform(NullThenBasicValueTest.class.getName() + "$NullThenBasicVal");
final Task<Void> res = NullThenBasicVal.doIt(getBlockedTask());
completeFutures();
assertNull(res.join());
}

public static class NullThenBasicVal
{
public static Task<Void> doIt(Task<Void> task)
{
String nullString = null; //this variable must be a string and initialized to null
int basicInt = 0; //this variable must be numeric and initialized to anything

await(task);
return Task.done();
}
}
}

0 comments on commit 8a554c8

Please sign in to comment.