Mercurial > hg > icedrobot > daneel
changeset 114:63f4cff176e1
Interpreter registers state is not propagated from the start of a try to the corresponding exception handler.
This chnageset also include a non-regression test TryTest.java
author | forax |
---|---|
date | Mon, 04 Apr 2011 13:51:54 +0200 |
parents | 4dfa6db13f7c |
children | b880d6db5210 |
files | src/main/java/org/icedrobot/daneel/rewriter/DexRewriter.java src/test/java/org/icedrobot/daneel/rewriter/TryTest.java |
diffstat | 2 files changed, 74 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/org/icedrobot/daneel/rewriter/DexRewriter.java Fri Apr 01 23:52:15 2011 +0200 +++ b/src/main/java/org/icedrobot/daneel/rewriter/DexRewriter.java Mon Apr 04 13:51:54 2011 +0200 @@ -175,6 +175,9 @@ // set which contains all labels which is the start of an exception handler private final Set<Label> exceptionHandlerSet = Collections.newSetFromMap(new IdentityHashMap<Label, Boolean>()); + // map the start label of the try label to the corresponding exception handler label + private final IdentityHashMap<Label, Label> exceptionTryStartToHandlerMap = + new IdentityHashMap<Label, Label>(); public MethodRewriter(MethodVisitor mv, boolean isStatic, String desc) { this.mv = new PatchMethodVisitor(mv); @@ -815,6 +818,12 @@ fixStackAfterAMethodCallOrAnExceptionHandler(); exceptionOnTop = exceptionHandlerSet.contains(label); + // if it's the start of a try, find the corresponding handler + Label handler = exceptionTryStartToHandlerMap.get(label); + if (handler != null) { + createOrMergeJoinPoint(handler); + } + createOrMergeJoinPoint(label); mv.visitLabel(getASMLabel(label)); } @@ -1063,6 +1072,7 @@ @Override public void visitTryCatch(Label start, Label end, Label handler, String type) { exceptionHandlerSet.add(handler); + exceptionTryStartToHandlerMap.put(start, handler); type = (type == null)? null: TypeUtil.convertDescToInternal(type); mv.visitTryCatchBlock(getASMLabel(start), getASMLabel(end), getASMLabel(handler),
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/icedrobot/daneel/rewriter/TryTest.java Mon Apr 04 13:51:54 2011 +0200 @@ -0,0 +1,64 @@ +/* + * Daneel - Dalvik to Java bytecode compiler + * Copyright (C) 2011 IcedRobot team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * This file is subject to the "Classpath" exception: + * + * Linking this library statically or dynamically with other modules is + * making a combined work based on this library. Thus, the terms and + * conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce an + * executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. An + * independent module is a module which is not derived from or based on + * this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obligated to do so. If + * you do not wish to do so, delete this exception statement from your + * version. + */ + +package org.icedrobot.daneel.rewriter; + +import org.icedrobot.daneel.DexifyingRunner; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(DexifyingRunner.class) +public class TryTest { + @Test + public void testInferenceInCatch() { + DEXCode.foo(); + } + + // Keep this class named "DEXCode" to push it through Daneel. + private static class DEXCode { + static Object foo() { + int i = 0; + try { + String j = "foo"; + return j; + } catch(Throwable t) { + int j = i; + return null; + } + } + } +}