Add test to prove that all modification to a local variable are visible in a corresponding catch block

This commit is contained in:
Alexey Andreev 2016-07-19 21:26:21 +03:00 committed by Alexey Andreev
parent 6196dc80ed
commit 1f30e5fd88
10 changed files with 29 additions and 45 deletions

View File

@ -19,10 +19,6 @@ import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
/**
*
* @author Alexey Andreev
*/
public class Variable implements VariableReader { public class Variable implements VariableReader {
private Program program; private Program program;
private int index; private int index;

View File

@ -98,10 +98,12 @@ public class Parser {
debugNames = newDebugNames; debugNames = newDebugNames;
} }
for (Variable definedVar : defExtractor.getDefinedVariables()) { for (Variable definedVar : defExtractor.getDefinedVariables()) {
/*
int sourceVar = phiUpdater.getSourceVariable(definedVar.getIndex()); int sourceVar = phiUpdater.getSourceVariable(definedVar.getIndex());
if (sourceVar >= 0) { if (sourceVar >= 0) {
varMap.put(sourceVar, definedVar.getIndex()); varMap.put(sourceVar, definedVar.getIndex());
} }
*/
} }
for (Map.Entry<Integer, String> debugName : debugNames.entrySet()) { for (Map.Entry<Integer, String> debugName : debugNames.entrySet()) {
int receiver = varMap.getOrDefault(debugName.getKey(), -1); int receiver = varMap.getOrDefault(debugName.getKey(), -1);
@ -147,6 +149,7 @@ public class Parser {
IntIntMap varMap = new IntIntOpenHashMap(step.varMap); IntIntMap varMap = new IntIntOpenHashMap(step.varMap);
BasicBlock block = program.basicBlockAt(node); BasicBlock block = program.basicBlockAt(node);
/*
for (TryCatchJoint joint : block.getTryCatchJoints()) { for (TryCatchJoint joint : block.getTryCatchJoints()) {
int receiver = joint.getReceiver().getIndex(); int receiver = joint.getReceiver().getIndex();
int sourceVar = phiUpdater.getSourceVariable(receiver); int sourceVar = phiUpdater.getSourceVariable(receiver);
@ -161,9 +164,11 @@ public class Parser {
varMap.put(sourceVar, receiver); varMap.put(sourceVar, receiver);
} }
} }
*/
result[node] = new IntIntOpenHashMap(varMap); result[node] = new IntIntOpenHashMap(varMap);
/*
for (Instruction insn : block.getInstructions()) { for (Instruction insn : block.getInstructions()) {
insn.acceptVisitor(defExtractor); insn.acceptVisitor(defExtractor);
for (Variable definedVar : defExtractor.getDefinedVariables()) { for (Variable definedVar : defExtractor.getDefinedVariables()) {
@ -173,6 +178,7 @@ public class Parser {
} }
} }
} }
*/
for (int successor : dom.outgoingEdges(node)) { for (int successor : dom.outgoingEdges(node)) {
stack[top++] = new Step(successor, new IntIntOpenHashMap(varMap)); stack[top++] = new Step(successor, new IntIntOpenHashMap(varMap));

View File

@ -25,7 +25,7 @@
<orderEntry type="module" module-name="teavm-classlib" scope="PROVIDED" /> <orderEntry type="module" module-name="teavm-classlib" scope="PROVIDED" />
<orderEntry type="module" module-name="teavm-platform" scope="PROVIDED" /> <orderEntry type="module" module-name="teavm-platform" scope="PROVIDED" />
<orderEntry type="module" module-name="teavm-core" scope="PROVIDED" /> <orderEntry type="module" module-name="teavm-core" scope="PROVIDED" />
<orderEntry type="module" module-name="teavm-metaprogramming-api" scope="PROVIDED" /> <orderEntry type="module" module-name="teavm-interop" scope="PROVIDED" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-io:commons-io:2.4" level="project" /> <orderEntry type="library" scope="PROVIDED" name="Maven: commons-io:commons-io:2.4" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.carrotsearch:hppc:0.6.1" level="project" /> <orderEntry type="library" scope="PROVIDED" name="Maven: com.carrotsearch:hppc:0.6.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.objenesis:objenesis:2.4" level="project" /> <orderEntry type="library" scope="PROVIDED" name="Maven: org.objenesis:objenesis:2.4" level="project" />
@ -38,9 +38,4 @@
<orderEntry type="library" scope="PROVIDED" name="Maven: com.jcraft:jzlib:1.1.3" level="project" /> <orderEntry type="library" scope="PROVIDED" name="Maven: com.jcraft:jzlib:1.1.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: joda-time:joda-time:2.7" level="project" /> <orderEntry type="library" scope="PROVIDED" name="Maven: joda-time:joda-time:2.7" level="project" />
</component> </component>
<component name="teavm">
<option name="enabled" value="true" />
<option name="mainClass" value="org.teavm.samples.async.AsyncProgram" />
<option name="targetDirectory" value="$MODULE_DIR$/target/generated/js/teavm" />
</component>
</module> </module>

View File

@ -35,7 +35,7 @@
<orderEntry type="module" module-name="teavm-classlib" scope="PROVIDED" /> <orderEntry type="module" module-name="teavm-classlib" scope="PROVIDED" />
<orderEntry type="module" module-name="teavm-platform" scope="PROVIDED" /> <orderEntry type="module" module-name="teavm-platform" scope="PROVIDED" />
<orderEntry type="module" module-name="teavm-core" scope="PROVIDED" /> <orderEntry type="module" module-name="teavm-core" scope="PROVIDED" />
<orderEntry type="module" module-name="teavm-metaprogramming-api" scope="PROVIDED" /> <orderEntry type="module" module-name="teavm-interop" scope="PROVIDED" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-io:commons-io:2.4" level="project" /> <orderEntry type="library" scope="PROVIDED" name="Maven: commons-io:commons-io:2.4" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.carrotsearch:hppc:0.6.1" level="project" /> <orderEntry type="library" scope="PROVIDED" name="Maven: com.carrotsearch:hppc:0.6.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.objenesis:objenesis:2.4" level="project" /> <orderEntry type="library" scope="PROVIDED" name="Maven: org.objenesis:objenesis:2.4" level="project" />
@ -63,9 +63,4 @@
<orderEntry type="library" name="Maven: org.netbeans.html:net.java.html.boot:1.2.3" level="project" /> <orderEntry type="library" name="Maven: org.netbeans.html:net.java.html.boot:1.2.3" level="project" />
<orderEntry type="library" name="Maven: org.netbeans.html:net.java.html:1.2.3" level="project" /> <orderEntry type="library" name="Maven: org.netbeans.html:net.java.html:1.2.3" level="project" />
</component> </component>
<component name="teavm">
<option name="enabled" value="true" />
<option name="mainClass" value="org.teavm.samples.benchmark.teavm.BenchmarkStarter" />
<option name="targetDirectory" value="$MODULE_DIR$/target/generated/js/teavm" />
</component>
</module> </module>

View File

@ -29,7 +29,7 @@
<orderEntry type="module" module-name="teavm-classlib" scope="PROVIDED" /> <orderEntry type="module" module-name="teavm-classlib" scope="PROVIDED" />
<orderEntry type="module" module-name="teavm-platform" scope="PROVIDED" /> <orderEntry type="module" module-name="teavm-platform" scope="PROVIDED" />
<orderEntry type="module" module-name="teavm-core" scope="PROVIDED" /> <orderEntry type="module" module-name="teavm-core" scope="PROVIDED" />
<orderEntry type="module" module-name="teavm-metaprogramming-api" scope="PROVIDED" /> <orderEntry type="module" module-name="teavm-interop" scope="PROVIDED" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-io:commons-io:2.4" level="project" /> <orderEntry type="library" scope="PROVIDED" name="Maven: commons-io:commons-io:2.4" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.carrotsearch:hppc:0.6.1" level="project" /> <orderEntry type="library" scope="PROVIDED" name="Maven: com.carrotsearch:hppc:0.6.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.objenesis:objenesis:2.4" level="project" /> <orderEntry type="library" scope="PROVIDED" name="Maven: org.objenesis:objenesis:2.4" level="project" />
@ -42,9 +42,4 @@
<orderEntry type="library" scope="PROVIDED" name="Maven: joda-time:joda-time:2.7" level="project" /> <orderEntry type="library" scope="PROVIDED" name="Maven: joda-time:joda-time:2.7" level="project" />
<orderEntry type="module" module-name="teavm-jso-apis" scope="PROVIDED" /> <orderEntry type="module" module-name="teavm-jso-apis" scope="PROVIDED" />
</component> </component>
<component name="teavm">
<option name="enabled" value="true" />
<option name="mainClass" value="org.teavm.samples.kotlin.HelloKt" />
<option name="targetDirectory" value="$MODULE_DIR$/target/generated/js/teavm" />
</component>
</module> </module>

View File

@ -25,7 +25,7 @@
<orderEntry type="module" module-name="teavm-classlib" scope="PROVIDED" /> <orderEntry type="module" module-name="teavm-classlib" scope="PROVIDED" />
<orderEntry type="module" module-name="teavm-platform" scope="PROVIDED" /> <orderEntry type="module" module-name="teavm-platform" scope="PROVIDED" />
<orderEntry type="module" module-name="teavm-core" scope="PROVIDED" /> <orderEntry type="module" module-name="teavm-core" scope="PROVIDED" />
<orderEntry type="module" module-name="teavm-metaprogramming-api" scope="PROVIDED" /> <orderEntry type="module" module-name="teavm-interop" scope="PROVIDED" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-io:commons-io:2.4" level="project" /> <orderEntry type="library" scope="PROVIDED" name="Maven: commons-io:commons-io:2.4" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.carrotsearch:hppc:0.6.1" level="project" /> <orderEntry type="library" scope="PROVIDED" name="Maven: com.carrotsearch:hppc:0.6.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.objenesis:objenesis:2.4" level="project" /> <orderEntry type="library" scope="PROVIDED" name="Maven: org.objenesis:objenesis:2.4" level="project" />
@ -39,9 +39,4 @@
<orderEntry type="module" module-name="teavm-jso" /> <orderEntry type="module" module-name="teavm-jso" />
<orderEntry type="library" name="Maven: org.scala-lang:scala-library:2.11.7" level="project" /> <orderEntry type="library" name="Maven: org.scala-lang:scala-library:2.11.7" level="project" />
</component> </component>
<component name="teavm">
<option name="enabled" value="true" />
<option name="mainClass" value="org.teavm.samples.scala.Client" />
<option name="targetDirectory" value="$MODULE_DIR$/target/generated/js/teavm" />
</component>
</module> </module>

View File

@ -25,7 +25,7 @@
<orderEntry type="module" module-name="teavm-classlib" scope="PROVIDED" /> <orderEntry type="module" module-name="teavm-classlib" scope="PROVIDED" />
<orderEntry type="module" module-name="teavm-platform" scope="PROVIDED" /> <orderEntry type="module" module-name="teavm-platform" scope="PROVIDED" />
<orderEntry type="module" module-name="teavm-core" scope="PROVIDED" /> <orderEntry type="module" module-name="teavm-core" scope="PROVIDED" />
<orderEntry type="module" module-name="teavm-metaprogramming-api" scope="PROVIDED" /> <orderEntry type="module" module-name="teavm-interop" scope="PROVIDED" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-io:commons-io:2.4" level="project" /> <orderEntry type="library" scope="PROVIDED" name="Maven: commons-io:commons-io:2.4" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.carrotsearch:hppc:0.6.1" level="project" /> <orderEntry type="library" scope="PROVIDED" name="Maven: com.carrotsearch:hppc:0.6.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.objenesis:objenesis:2.4" level="project" /> <orderEntry type="library" scope="PROVIDED" name="Maven: org.objenesis:objenesis:2.4" level="project" />
@ -39,9 +39,4 @@
<orderEntry type="module" module-name="teavm-jso-apis" scope="PROVIDED" /> <orderEntry type="module" module-name="teavm-jso-apis" scope="PROVIDED" />
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.servlet:javax.servlet-api:3.1.0" level="project" /> <orderEntry type="library" scope="PROVIDED" name="Maven: javax.servlet:javax.servlet-api:3.1.0" level="project" />
</component> </component>
<component name="teavm">
<option name="enabled" value="true" />
<option name="mainClass" value="org.teavm.samples.storage.Application" />
<option name="targetDirectory" value="$MODULE_DIR$/target/generated/js/teavm" />
</component>
</module> </module>

View File

@ -25,7 +25,7 @@
<orderEntry type="module" module-name="teavm-classlib" scope="PROVIDED" /> <orderEntry type="module" module-name="teavm-classlib" scope="PROVIDED" />
<orderEntry type="module" module-name="teavm-platform" scope="PROVIDED" /> <orderEntry type="module" module-name="teavm-platform" scope="PROVIDED" />
<orderEntry type="module" module-name="teavm-core" scope="PROVIDED" /> <orderEntry type="module" module-name="teavm-core" scope="PROVIDED" />
<orderEntry type="module" module-name="teavm-metaprogramming-api" scope="PROVIDED" /> <orderEntry type="module" module-name="teavm-interop" scope="PROVIDED" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-io:commons-io:2.4" level="project" /> <orderEntry type="library" scope="PROVIDED" name="Maven: commons-io:commons-io:2.4" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.carrotsearch:hppc:0.6.1" level="project" /> <orderEntry type="library" scope="PROVIDED" name="Maven: com.carrotsearch:hppc:0.6.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.objenesis:objenesis:2.4" level="project" /> <orderEntry type="library" scope="PROVIDED" name="Maven: org.objenesis:objenesis:2.4" level="project" />
@ -39,9 +39,4 @@
<orderEntry type="module" module-name="teavm-jso-apis" scope="PROVIDED" /> <orderEntry type="module" module-name="teavm-jso-apis" scope="PROVIDED" />
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.servlet:javax.servlet-api:3.1.0" level="project" /> <orderEntry type="library" scope="PROVIDED" name="Maven: javax.servlet:javax.servlet-api:3.1.0" level="project" />
</component> </component>
<component name="teavm">
<option name="enabled" value="true" />
<option name="mainClass" value="org.teavm.samples.video.Player" />
<option name="targetDirectory" value="$MODULE_DIR$/target/generated/js/teavm" />
</component>
</module> </module>

View File

@ -16,7 +16,6 @@
package org.teavm.classlib.java.lang; package org.teavm.classlib.java.lang;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import java.lang.annotation.Retention;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.teavm.junit.TeaVMTestRunner; import org.teavm.junit.TeaVMTestRunner;
@ -118,6 +117,21 @@ public class VMTest {
assertEquals("SECOND ", ClassWithStaticField.foo(false)); assertEquals("SECOND ", ClassWithStaticField.foo(false));
} }
@Test
public void variableReadInCatchBlock() {
int n = foo();
try {
for (int i = 0; i < 10; ++i) {
n += foo();
}
bar();
n += foo() * 5;
} catch (RuntimeException e) {
assertEquals(RuntimeException.class, e.getClass());
assertEquals(n, 22);
}
}
private static class ClassWithStaticField { private static class ClassWithStaticField {
public final static String CONST1 = "FIRST"; public final static String CONST1 = "FIRST";
public final static String CONST2 = "SECOND"; public final static String CONST2 = "SECOND";

View File

@ -64,8 +64,8 @@ import org.teavm.idea.jps.model.TeaVMJpsConfiguration;
import org.teavm.idea.jps.remote.TeaVMBuilderAssistant; import org.teavm.idea.jps.remote.TeaVMBuilderAssistant;
import org.teavm.idea.jps.remote.TeaVMElementLocation; import org.teavm.idea.jps.remote.TeaVMElementLocation;
import org.teavm.model.CallLocation; import org.teavm.model.CallLocation;
import org.teavm.model.InstructionLocation;
import org.teavm.model.MethodReference; import org.teavm.model.MethodReference;
import org.teavm.model.TextLocation;
import org.teavm.model.ValueType; import org.teavm.model.ValueType;
import org.teavm.tooling.EmptyTeaVMToolLog; import org.teavm.tooling.EmptyTeaVMToolLog;
import org.teavm.tooling.TeaVMTool; import org.teavm.tooling.TeaVMTool;
@ -243,7 +243,7 @@ class TeaVMBuild {
int endOffset = -1; int endOffset = -1;
if (callLocation != null) { if (callLocation != null) {
InstructionLocation insnLocation = callLocation.getSourceLocation(); TextLocation insnLocation = callLocation.getSourceLocation();
if (insnLocation != null) { if (insnLocation != null) {
path = insnLocation.getFileName(); path = insnLocation.getFileName();
line = insnLocation.getLine(); line = insnLocation.getLine();
@ -449,8 +449,6 @@ class TeaVMBuild {
return "Discovering classes to compile"; return "Discovering classes to compile";
case LINKING: case LINKING:
return "Resolving method invocations"; return "Resolving method invocations";
case DEVIRTUALIZATION:
return "Eliminating virtual calls";
case DECOMPILATION: case DECOMPILATION:
return "Compiling classes"; return "Compiling classes";
case RENDERING: case RENDERING: