From 022d552b30c0d291bfc11360124302b6056fd6c3 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Mon, 18 May 2015 18:40:38 +0300 Subject: [PATCH] IDEA-140321 Wrong current line highlighting when debugging synchronized block in decompiled code --- .../stats/SynchronizedStatement.java | 11 +++++++ .../classes/pkg/TestSynchronizedMapping.class | Bin 577 -> 590 bytes testData/results/TestSynchronizedMapping.dec | 30 ++++++++++-------- testData/src/pkg/TestSynchronizedMapping.java | 3 +- 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/SynchronizedStatement.java b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/SynchronizedStatement.java index 3460e14..b71531f 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/SynchronizedStatement.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/SynchronizedStatement.java @@ -15,6 +15,8 @@ */ 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.collectors.BytecodeMappingTracer; 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.appendIndent(indent).append("}").appendLineSeparator(); + mapMonitorExitInstr(tracer); tracer.incrementCurrentSourceLine(); 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() { headexprent.set(0, first.getExprents().remove(first.getExprents().size() - 1)); } diff --git a/testData/classes/pkg/TestSynchronizedMapping.class b/testData/classes/pkg/TestSynchronizedMapping.class index 4691cfd73b71245676afb1d365d86eb3f6efac4c..e320211ee8c1d159d989ef836cb6cc6dcd0b574f 100644 GIT binary patch delta 155 zcmW-ZJrV&y6okJwrfOzbX05V`l8Mwh3b_lohQtjVLO`HgK(V<4N$8rS`}OOem;do?DZ)UCLQN{NbG*pZ}~(u%@FV91nFaa-I^#~?7azyv}5 cDrMBl7*XAoR-HILI4|8iXD!t78vPuzKiYE;XaE2J delta 118 zcmW-Y!4W_(6h!w&W+FkDIO@Pq3iqf-2g=}}1B1Jk*m2pvZ+HKrPra`)MJQ+hRU3z^ znMJyL8@szd{@fvBm%;y6!IC@@YRWIm)FCI;ke84c6k@obluJ;3=|KlU;7FnV06Mk| A)&Kwi diff --git a/testData/results/TestSynchronizedMapping.dec b/testData/results/TestSynchronizedMapping.dec index 82b553b..84ad48a 100644 --- a/testData/results/TestSynchronizedMapping.dec +++ b/testData/results/TestSynchronizedMapping.dec @@ -3,33 +3,37 @@ package pkg; public class TestSynchronizedMapping { public int test(int var1) { synchronized(this) {// 8 - return var1++;// 9 - } + ++var1;// 9 + }// 10 + + return var1++;// 11 } public void test2(String var1) { - System.out.println(var1);// 14 - }// 15 + System.out.println(var1);// 15 + }// 16 } class 'pkg/TestSynchronizedMapping' { method 'test (I)I' { 3 4 - 5 5 - a 5 + 4 5 + 8 6 + 12 8 + 15 8 } method 'test2 (Ljava/lang/String;)V' { - 0 10 - 4 10 - 7 11 + 0 12 + 4 12 + 7 13 } } Lines mapping: 8 <-> 5 9 <-> 6 -14 <-> 11 -15 <-> 12 -Not mapped: -10 +10 <-> 7 +11 <-> 9 +15 <-> 13 +16 <-> 14 diff --git a/testData/src/pkg/TestSynchronizedMapping.java b/testData/src/pkg/TestSynchronizedMapping.java index 37f0282..8effb75 100644 --- a/testData/src/pkg/TestSynchronizedMapping.java +++ b/testData/src/pkg/TestSynchronizedMapping.java @@ -6,8 +6,9 @@ import java.lang.Runnable; public class TestSynchronizedMapping { public int test(int a) { synchronized (this) { - return a++; + a++; } + return a++; } public void test2(String a) {