summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormikaelpeltier <mikaelpeltier@google.com>2014-09-11 11:53:23 +0200
committermikaelpeltier <mikaelpeltier@google.com>2014-09-11 16:46:33 +0200
commit8a0bdadce907ccf7c652cf7aa31e882e61823bef (patch)
tree6d613d34cbe6ce72e3ea8811635b9606b3712d82
parenta1ba5b090c002e864581a107865666bd077a456a (diff)
downloadtoolchain_jill-8a0bdadce907ccf7c652cf7aa31e882e61823bef.zip
toolchain_jill-8a0bdadce907ccf7c652cf7aa31e882e61823bef.tar.gz
toolchain_jill-8a0bdadce907ccf7c652cf7aa31e882e61823bef.tar.bz2
Add multi catches support
- Avoid to add several ids for the same handler into the current catch list. - Add all caught types into a catch block - Set the common type of multi catches block to Throwable. This type will be cast to a more precise type when it will be used. Bug: 17387653 Change-Id: Ifa31715565b7a78edf39f6572792bad3d6d9d04c
-rw-r--r--jill/src/com/android/jill/backend/jayce/JayceWriter.java3
-rw-r--r--jill/src/com/android/jill/frontend/java/MethodBodyWriter.java27
2 files changed, 23 insertions, 7 deletions
diff --git a/jill/src/com/android/jill/backend/jayce/JayceWriter.java b/jill/src/com/android/jill/backend/jayce/JayceWriter.java
index 0cbe1ee..f40f8db 100644
--- a/jill/src/com/android/jill/backend/jayce/JayceWriter.java
+++ b/jill/src/com/android/jill/backend/jayce/JayceWriter.java
@@ -27,6 +27,7 @@ import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
import java.util.Stack;
import javax.annotation.CheckForNull;
@@ -166,7 +167,7 @@ public class JayceWriter {
writeClose();
}
- public void writeCatchBlockIds(@Nonnull List<String> list) throws IOException {
+ public void writeCatchBlockIds(@Nonnull Set<String> list) throws IOException {
List<String> removedIds = new ArrayList<String>(currentCatchBlockList.size());
List<String> addedIds = new ArrayList<String>(list.size());
diff --git a/jill/src/com/android/jill/frontend/java/MethodBodyWriter.java b/jill/src/com/android/jill/frontend/java/MethodBodyWriter.java
index 0559a40..efe9285 100644
--- a/jill/src/com/android/jill/frontend/java/MethodBodyWriter.java
+++ b/jill/src/com/android/jill/frontend/java/MethodBodyWriter.java
@@ -153,7 +153,7 @@ public class MethodBodyWriter extends JillWriter implements Opcodes {
private static final int TOP_OF_STACK = -1;
@Nonnull
- private final List<String> currentCatchList = new ArrayList<String>();
+ private final Set<String> currentCatchList = new HashSet<String>();
@Nonnegative
private int currentLine = 0;
@@ -357,7 +357,11 @@ public class MethodBodyWriter extends JillWriter implements Opcodes {
// Jack represents finally by a catch on java.lang.Object.
catchedType = Type.getType(Object.class);
} else {
- catchedType = Type.getObjectType(tryCatchNode.type);
+ // If there is multi catches, it is not possible to compute precisely the common type of
+ // exceptions without having the full classpath and by loading all classes. Jill uses
+ // Throwable as common type even when a more precise type is known.
+ // This type will be cast with a reinterpret cast to the right type when it will be used.
+ catchedType = Type.getType(Throwable.class);
}
String id = "catchedExceptionNotUsed" + (unusedVarCount++);
declaringCatchVariable = new Variable(id, id, catchedType, null);
@@ -491,10 +495,21 @@ public class MethodBodyWriter extends JillWriter implements Opcodes {
writer.writeOpen();
writer.writeId(getCatchId(tryCatchNode.handler));
- writer.writeOpen();
- writer.writeInt(1);
- writer.writeId(declaringCatchVariable.getType().getDescriptor());
- writer.writeClose();
+ // Take into account multi catches by computing the list of caught types for this handler
+ List<String> ids = new ArrayList<String>();
+ if (tryCatchNode.type == null) {
+ // Jack represents finally by a catch on java.lang.Object.
+ ids.add(Type.getType(Object.class).getDescriptor());
+ } else {
+ ids.add(Type.getObjectType(tryCatchNode.type).getDescriptor());
+ for (TryCatchBlockNode tryCatchNode2 : currentMethod.tryCatchBlocks) {
+ if (labelNode == tryCatchNode2.handler && tryCatchNode != tryCatchNode2
+ && !tryCatchNode.type.equals(tryCatchNode2.type)) {
+ ids.add(Type.getObjectType(tryCatchNode2.type).getDescriptor());
+ }
+ }
+ }
+ writer.writeIds(ids);
writeLocal(declaringCatchVariable);