From 68aa193728edb43879faabf897fa4d7976081116 Mon Sep 17 00:00:00 2001 From: Steve Hannah Date: Sat, 7 Feb 2015 07:22:13 -0800 Subject: [PATCH] Made some changes based on Alexey's comments of previous changes. Still getting same error on build. --- .../main/java/org/teavm/cache/ProgramIO.java | 26 +++++++++++++++++-- .../dependency/DependencyGraphBuilder.java | 14 ++++++++++ .../javascript/ast/MonitorEnterStatement.java | 6 ++--- .../javascript/ast/MonitorExitStatement.java | 6 ++--- .../model/instructions/InstructionReader.java | 4 +++ .../model/util/InstructionStringifier.java | 10 +++++++ .../org/teavm/model/util/ProgramUtils.java | 16 ++++++++++++ .../tooling/ProgramSourceAggregator.java | 10 +++++++ 8 files changed, 84 insertions(+), 8 deletions(-) diff --git a/teavm-core/src/main/java/org/teavm/cache/ProgramIO.java b/teavm-core/src/main/java/org/teavm/cache/ProgramIO.java index 19978b16d..b4689db64 100644 --- a/teavm-core/src/main/java/org/teavm/cache/ProgramIO.java +++ b/teavm-core/src/main/java/org/teavm/cache/ProgramIO.java @@ -597,12 +597,24 @@ public class ProgramIO { @Override public void visit(MonitorEnterInstruction insn) { - + try { + output.writeByte(39); + output.writeShort(insn.getObjectRef().getIndex()); + + } catch (IOException e) { + throw new IOExceptionWrapper(e); + } } @Override public void visit(MonitorExitInstruction insn) { - + try { + output.writeByte(40); + output.writeShort(insn.getObjectRef().getIndex()); + + } catch (IOException e) { + throw new IOExceptionWrapper(e); + } } } @@ -908,6 +920,16 @@ public class ProgramIO { insn.setValue(program.variableAt(input.readShort())); return insn; } + case 39: { + MonitorEnterInstruction insn = new MonitorEnterInstruction(); + insn.setObjectRef(program.variableAt(input.readShort())); + return insn; + } + case 40: { + MonitorExitInstruction insn = new MonitorExitInstruction(); + insn.setObjectRef(program.variableAt(input.readShort())); + return insn; + } default: throw new RuntimeException("Unknown instruction type: " + insnType); } diff --git a/teavm-core/src/main/java/org/teavm/dependency/DependencyGraphBuilder.java b/teavm-core/src/main/java/org/teavm/dependency/DependencyGraphBuilder.java index 232548688..5e13cca03 100644 --- a/teavm-core/src/main/java/org/teavm/dependency/DependencyGraphBuilder.java +++ b/teavm-core/src/main/java/org/teavm/dependency/DependencyGraphBuilder.java @@ -490,5 +490,19 @@ class DependencyGraphBuilder { new CallLocation(caller.getMethod(), currentLocation)).use(); currentExceptionConsumer.consume(dependencyChecker.getType("java.lang.NullPointerException")); } + + @Override + public void monitorEnter(VariableReader objectRef) { + dependencyChecker.linkMethod( + new MethodReference(Object.class, "monitorEnter", Object.class, void.class), + new CallLocation(caller.getMethod(), currentLocation)).use(); + } + + @Override + public void monitorExit(VariableReader objectRef) { + dependencyChecker.linkMethod( + new MethodReference(Object.class, "monitorExit", Object.class, void.class), + new CallLocation(caller.getMethod(), currentLocation)).use(); + } }; } diff --git a/teavm-core/src/main/java/org/teavm/javascript/ast/MonitorEnterStatement.java b/teavm-core/src/main/java/org/teavm/javascript/ast/MonitorEnterStatement.java index 1735e8d00..9051f32f0 100644 --- a/teavm-core/src/main/java/org/teavm/javascript/ast/MonitorEnterStatement.java +++ b/teavm-core/src/main/java/org/teavm/javascript/ast/MonitorEnterStatement.java @@ -22,7 +22,7 @@ package org.teavm.javascript.ast; public class MonitorEnterStatement extends Statement { private NodeLocation location; - private VariableExpr objectRef; + private Expr objectRef; @Override public void acceptVisitor(StatementVisitor visitor) { @@ -46,14 +46,14 @@ public class MonitorEnterStatement extends Statement { /** * @return the objectRef */ - public VariableExpr getObjectRef() { + public Expr getObjectRef() { return objectRef; } /** * @param objectRef the objectRef to set */ - public void setObjectRef(VariableExpr objectRef) { + public void setObjectRef(Expr objectRef) { this.objectRef = objectRef; } diff --git a/teavm-core/src/main/java/org/teavm/javascript/ast/MonitorExitStatement.java b/teavm-core/src/main/java/org/teavm/javascript/ast/MonitorExitStatement.java index b13fd370a..2f6d61fdc 100644 --- a/teavm-core/src/main/java/org/teavm/javascript/ast/MonitorExitStatement.java +++ b/teavm-core/src/main/java/org/teavm/javascript/ast/MonitorExitStatement.java @@ -22,7 +22,7 @@ package org.teavm.javascript.ast; public class MonitorExitStatement extends Statement { private NodeLocation location; - private VariableExpr objectRef; + private Expr objectRef; @Override public void acceptVisitor(StatementVisitor visitor) { @@ -46,14 +46,14 @@ public class MonitorExitStatement extends Statement { /** * @return the objectRef */ - public VariableExpr getObjectRef() { + public Expr getObjectRef() { return objectRef; } /** * @param objectRef the objectRef to set */ - public void setObjectRef(VariableExpr objectRef) { + public void setObjectRef(Expr objectRef) { this.objectRef = objectRef; } diff --git a/teavm-core/src/main/java/org/teavm/model/instructions/InstructionReader.java b/teavm-core/src/main/java/org/teavm/model/instructions/InstructionReader.java index c2c191b66..2b022cf8b 100644 --- a/teavm-core/src/main/java/org/teavm/model/instructions/InstructionReader.java +++ b/teavm-core/src/main/java/org/teavm/model/instructions/InstructionReader.java @@ -100,4 +100,8 @@ public interface InstructionReader { void initClass(String className); void nullCheck(VariableReader receiver, VariableReader value); + + void monitorEnter(VariableReader objectRef); + + void monitorExit(VariableReader objectRef); } diff --git a/teavm-core/src/main/java/org/teavm/model/util/InstructionStringifier.java b/teavm-core/src/main/java/org/teavm/model/util/InstructionStringifier.java index 053c7372c..c3a2a1a54 100644 --- a/teavm-core/src/main/java/org/teavm/model/util/InstructionStringifier.java +++ b/teavm-core/src/main/java/org/teavm/model/util/InstructionStringifier.java @@ -352,4 +352,14 @@ public class InstructionStringifier implements InstructionReader { public void nullCheck(VariableReader receiver, VariableReader value) { sb.append("@").append(receiver.getIndex()).append(" := nullCheck @").append(value.getIndex()); } + + @Override + public void monitorEnter(VariableReader objectRef) { + sb.append("monitorenter @").append(objectRef.getIndex()); + } + + @Override + public void monitorExit(VariableReader objectRef) { + sb.append("monitorexit @").append(objectRef.getIndex()); + } } diff --git a/teavm-core/src/main/java/org/teavm/model/util/ProgramUtils.java b/teavm-core/src/main/java/org/teavm/model/util/ProgramUtils.java index a570efe8b..4f5a2b80e 100644 --- a/teavm-core/src/main/java/org/teavm/model/util/ProgramUtils.java +++ b/teavm-core/src/main/java/org/teavm/model/util/ProgramUtils.java @@ -495,5 +495,21 @@ public final class ProgramUtils { copy = insnCopy; copy.setLocation(location); } + + @Override + public void monitorEnter(VariableReader objectRef) { + MonitorEnterInstruction insnCopy = new MonitorEnterInstruction(); + insnCopy.setObjectRef(copyVar(objectRef)); + copy = insnCopy; + copy.setLocation(location); + } + + @Override + public void monitorExit(VariableReader objectRef) { + MonitorExitInstruction insnCopy = new MonitorExitInstruction(); + insnCopy.setObjectRef(copyVar(objectRef)); + copy = insnCopy; + copy.setLocation(location); + } } } diff --git a/teavm-core/src/main/java/org/teavm/tooling/ProgramSourceAggregator.java b/teavm-core/src/main/java/org/teavm/tooling/ProgramSourceAggregator.java index de340d0cc..9dc33d3d6 100644 --- a/teavm-core/src/main/java/org/teavm/tooling/ProgramSourceAggregator.java +++ b/teavm-core/src/main/java/org/teavm/tooling/ProgramSourceAggregator.java @@ -88,4 +88,14 @@ class ProgramSourceAggregator implements InstructionReader { @Override public void isInstance(VariableReader receiver, VariableReader value, ValueType type) { } @Override public void initClass(String className) { } @Override public void nullCheck(VariableReader receiver, VariableReader value) { } + + @Override + public void monitorEnter(VariableReader objectRef) { + + } + + @Override + public void monitorExit(VariableReader objectRef) { + + } }