IDEA-140321 Wrong current line highlighting when debugging synchronized block in decompiled code

master
Egor.Ushakov 10 years ago
parent 44ba5816f2
commit 022d552b30
  1. 11
      src/org/jetbrains/java/decompiler/modules/decompiler/stats/SynchronizedStatement.java
  2. BIN
      testData/classes/pkg/TestSynchronizedMapping.class
  3. 30
      testData/results/TestSynchronizedMapping.dec
  4. 3
      testData/src/pkg/TestSynchronizedMapping.java

@ -15,6 +15,8 @@
*/ */
package org.jetbrains.java.decompiler.modules.decompiler.stats; package org.jetbrains.java.decompiler.modules.decompiler.stats;
import org.jetbrains.java.decompiler.code.CodeConstants;
import org.jetbrains.java.decompiler.code.cfg.BasicBlock;
import org.jetbrains.java.decompiler.main.TextBuffer; import org.jetbrains.java.decompiler.main.TextBuffer;
import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer; import org.jetbrains.java.decompiler.main.collectors.BytecodeMappingTracer;
import org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor; import org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor;
@ -84,11 +86,20 @@ public class SynchronizedStatement extends Statement {
buf.append(ExprProcessor.jmpWrapper(body, indent + 1, true, tracer)); buf.append(ExprProcessor.jmpWrapper(body, indent + 1, true, tracer));
buf.appendIndent(indent).append("}").appendLineSeparator(); buf.appendIndent(indent).append("}").appendLineSeparator();
mapMonitorExitInstr(tracer);
tracer.incrementCurrentSourceLine(); tracer.incrementCurrentSourceLine();
return buf; return buf;
} }
private void mapMonitorExitInstr(BytecodeMappingTracer tracer) {
BasicBlock block = body.getBasichead().getBlock();
if (!block.getSeq().isEmpty() && block.getLastInstruction().opcode == CodeConstants.opc_monitorexit) {
Integer offset = block.getOldOffset(block.size() - 1);
if (offset > -1) tracer.addMapping(offset);
}
}
public void initExprents() { public void initExprents() {
headexprent.set(0, first.getExprents().remove(first.getExprents().size() - 1)); headexprent.set(0, first.getExprents().remove(first.getExprents().size() - 1));
} }

@ -3,33 +3,37 @@ package pkg;
public class TestSynchronizedMapping { public class TestSynchronizedMapping {
public int test(int var1) { public int test(int var1) {
synchronized(this) {// 8 synchronized(this) {// 8
return var1++;// 9 ++var1;// 9
} }// 10
return var1++;// 11
} }
public void test2(String var1) { public void test2(String var1) {
System.out.println(var1);// 14 System.out.println(var1);// 15
}// 15 }// 16
} }
class 'pkg/TestSynchronizedMapping' { class 'pkg/TestSynchronizedMapping' {
method 'test (I)I' { method 'test (I)I' {
3 4 3 4
5 5 4 5
a 5 8 6
12 8
15 8
} }
method 'test2 (Ljava/lang/String;)V' { method 'test2 (Ljava/lang/String;)V' {
0 10 0 12
4 10 4 12
7 11 7 13
} }
} }
Lines mapping: Lines mapping:
8 <-> 5 8 <-> 5
9 <-> 6 9 <-> 6
14 <-> 11 10 <-> 7
15 <-> 12 11 <-> 9
Not mapped: 15 <-> 13
10 16 <-> 14

@ -6,8 +6,9 @@ import java.lang.Runnable;
public class TestSynchronizedMapping { public class TestSynchronizedMapping {
public int test(int a) { public int test(int a) {
synchronized (this) { synchronized (this) {
return a++; a++;
} }
return a++;
} }
public void test2(String a) { public void test2(String a) {

Loading…
Cancel
Save