diff options
10 files changed, 113 insertions, 3 deletions
diff --git a/jack-tests/tests/com/android/jack/cast/CastTests.java b/jack-tests/tests/com/android/jack/cast/CastTests.java index 0debeaf..96fa92c 100644 --- a/jack-tests/tests/com/android/jack/cast/CastTests.java +++ b/jack-tests/tests/com/android/jack/cast/CastTests.java @@ -63,6 +63,10 @@ public class CastTests extends RuntimeTest { AbstractTestTools.getTestRootDir("com.android.jack.cast.useless002"), "com.android.jack.cast.useless002.dx.Tests"); + private RuntimeTestInfo USELESS004 = new RuntimeTestInfo( + AbstractTestTools.getTestRootDir("com.android.jack.cast.useless004"), + "com.android.jack.cast.useless004.dx.Tests"); + @Test @Category(RuntimeRegressionTest.class) public void explicit001() throws Exception { @@ -121,6 +125,13 @@ public class CastTests extends RuntimeTest { new RuntimeTestHelper(USELESS002).compileAndRunTest(); } + @Test + @Category(RuntimeRegressionTest.class) + public void useless004() throws Exception { + new RuntimeTestHelper(USELESS004).compileAndRunTest(); + } + + /** * Verifies that the test source can compile from source to dex file. */ @@ -142,5 +153,6 @@ public class CastTests extends RuntimeTest { rtTestInfos.add(IMPLICIT004); rtTestInfos.add(USELESS001); rtTestInfos.add(USELESS002); + rtTestInfos.add(USELESS004); } } diff --git a/jack-tests/tests/com/android/jack/cast/useless004/dx/Tests.java b/jack-tests/tests/com/android/jack/cast/useless004/dx/Tests.java new file mode 100644 index 0000000..233cc3c --- /dev/null +++ b/jack-tests/tests/com/android/jack/cast/useless004/dx/Tests.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.cast.useless004.dx; + +import com.android.jack.cast.useless004.jack.UselessCast; + +import org.junit.Assert; +import org.junit.Test; + +public class Tests { + + @Test + public void test1() { + Assert.assertEquals(1, UselessCast.test(true)); + Assert.assertEquals(2, UselessCast.test(false)); + } +} diff --git a/jack-tests/tests/com/android/jack/cast/useless004/jack/UselessCast.java b/jack-tests/tests/com/android/jack/cast/useless004/jack/UselessCast.java new file mode 100644 index 0000000..8c9d6c8 --- /dev/null +++ b/jack-tests/tests/com/android/jack/cast/useless004/jack/UselessCast.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.cast.useless004.jack; + +public class UselessCast { + + /** + * Check that casts that are written in the source code are kept until they are useful, even if + * they are useless for the generated dex and will be remove later into the plan. + */ + public static long test(boolean b) { + Number result = (b) ? (Number)Integer.valueOf(1) : (Number)Long.valueOf(2); + + return result.longValue(); + } +} diff --git a/jack/src/com/android/jack/Jack.java b/jack/src/com/android/jack/Jack.java index 84228a6..3c93b96 100644 --- a/jack/src/com/android/jack/Jack.java +++ b/jack/src/com/android/jack/Jack.java @@ -1072,7 +1072,6 @@ public abstract class Jack { methodPlan.append(NestedAssignRemover.class); methodPlan.append(TypeLegalizer.class); methodPlan.append(RopCastLegalizer.class); - methodPlan.append(UselessCastRemover.class); if (features.contains(CodeStats.class)) { methodPlan.append(BinaryOperationWithCst.class); } @@ -1085,6 +1084,7 @@ public abstract class Jack { methodPlan.append(ExceptionRuntimeValueAdder.class); methodPlan.append(DefinitionMarkerAdder.class); methodPlan.append(ThreeAddressCodeBuilder.class); + methodPlan.append(UselessCastRemover.class); methodPlan.append(DefinitionMarkerRemover.class); methodPlan.append(TryCatchRemover.class); methodPlan.append(ExpressionStatementLegalizer.class); diff --git a/jack/src/com/android/jack/backend/dex/rop/CodeItemBuilder.java b/jack/src/com/android/jack/backend/dex/rop/CodeItemBuilder.java index 28a2c87..6af70f4 100644 --- a/jack/src/com/android/jack/backend/dex/rop/CodeItemBuilder.java +++ b/jack/src/com/android/jack/backend/dex/rop/CodeItemBuilder.java @@ -83,6 +83,7 @@ import com.android.jack.transformations.ast.UnassignedValues; import com.android.jack.transformations.ast.inner.InnerAccessor; import com.android.jack.transformations.ast.switches.UselessSwitches; import com.android.jack.transformations.booleanoperators.FallThroughMarker; +import com.android.jack.transformations.cast.SourceCast; import com.android.jack.transformations.rop.cast.RopLegalCast; import com.android.jack.transformations.threeaddresscode.ThreeAddressCodeForm; import com.android.jack.util.filter.Filter; @@ -136,7 +137,8 @@ import javax.annotation.Nonnull; JAssertStatement.class, JConditionalOperation.class, EmptyClinit.class, - UselessSwitches.class}) + UselessSwitches.class, + SourceCast.class}) @Transform(add = DexCodeMarker.class) public class CodeItemBuilder implements RunnableSchedulable<JMethod> { diff --git a/jack/src/com/android/jack/ir/JackFormatIr.java b/jack/src/com/android/jack/ir/JackFormatIr.java index 01f0549..be23111 100644 --- a/jack/src/com/android/jack/ir/JackFormatIr.java +++ b/jack/src/com/android/jack/ir/JackFormatIr.java @@ -122,6 +122,7 @@ import com.android.jack.transformations.ast.MultiDimensionNewArray; import com.android.jack.transformations.ast.NoImplicitBlock; import com.android.jack.transformations.ast.inner.InnerAccessor; import com.android.jack.transformations.ast.switches.UselessSwitches; +import com.android.jack.transformations.cast.SourceCast; import com.android.sched.item.AbstractComponent; import com.android.sched.item.ComposedOf; import com.android.sched.item.Description; @@ -238,6 +239,7 @@ import com.android.sched.item.Name; NotSimplifier.NotExpressionsSimplified.class, GenericSignature.class, SimpleName.class, + SourceCast.class, ThisRefTypeInfo.class, UselessSwitches.class}) public class JackFormatIr implements AbstractComponent { diff --git a/jack/src/com/android/jack/ir/JavaSourceIr.java b/jack/src/com/android/jack/ir/JavaSourceIr.java index e16cd6a..4c2aeac 100644 --- a/jack/src/com/android/jack/ir/JavaSourceIr.java +++ b/jack/src/com/android/jack/ir/JavaSourceIr.java @@ -145,6 +145,7 @@ import com.android.jack.transformations.ast.MultiDimensionNewArray; import com.android.jack.transformations.ast.removeinit.FieldInitMethod; import com.android.jack.transformations.ast.removeinit.FieldInitMethodCall; import com.android.jack.transformations.ast.switches.UselessSwitches; +import com.android.jack.transformations.cast.SourceCast; import com.android.sched.item.AbstractComponent; import com.android.sched.item.ComposedOf; import com.android.sched.item.Description; @@ -285,6 +286,7 @@ import com.android.sched.item.Name; MultiDimensionNewArray.class, GenericSignature.class, SimpleName.class, + SourceCast.class, ThisRefTypeInfo.class, ThrownExceptionMarker.class, UselessSwitches.class}) diff --git a/jack/src/com/android/jack/transformations/cast/SourceCast.java b/jack/src/com/android/jack/transformations/cast/SourceCast.java new file mode 100644 index 0000000..f6b4ade --- /dev/null +++ b/jack/src/com/android/jack/transformations/cast/SourceCast.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.transformations.cast; + +import com.android.sched.item.Description; +import com.android.sched.item.Tag; + +/** + * The tag {@code SourceCast} allows to know that the code contains all casts that have been written + * into the source. + */ +@Description("Code contains all casts that have been written into the source.") +public final class SourceCast implements Tag { +} diff --git a/jack/src/com/android/jack/transformations/cast/UselessCastRemover.java b/jack/src/com/android/jack/transformations/cast/UselessCastRemover.java index 42e9c4e..f4da144 100644 --- a/jack/src/com/android/jack/transformations/cast/UselessCastRemover.java +++ b/jack/src/com/android/jack/transformations/cast/UselessCastRemover.java @@ -32,6 +32,7 @@ import com.android.sched.item.Description; import com.android.sched.item.Name; import com.android.sched.schedulable.Constraint; import com.android.sched.schedulable.RunnableSchedulable; +import com.android.sched.schedulable.Transform; import com.android.sched.util.config.ThreadConfig; import javax.annotation.Nonnull; @@ -41,6 +42,7 @@ import javax.annotation.Nonnull; @Description("Removes useless casts.") @Name("UselessCastRemover") @Constraint(need = JDynamicCastOperation.class) +@Transform(remove = SourceCast.class) public class UselessCastRemover implements RunnableSchedulable<JMethod> { @Nonnull diff --git a/jack/src/com/android/jack/transformations/threeaddresscode/ThreeAddressCodeBuilder.java b/jack/src/com/android/jack/transformations/threeaddresscode/ThreeAddressCodeBuilder.java index f79b8ee..aa454bf 100644 --- a/jack/src/com/android/jack/transformations/threeaddresscode/ThreeAddressCodeBuilder.java +++ b/jack/src/com/android/jack/transformations/threeaddresscode/ThreeAddressCodeBuilder.java @@ -56,6 +56,7 @@ import com.android.jack.transformations.ast.InitInNewArray; import com.android.jack.transformations.ast.NoImplicitBlock; import com.android.jack.transformations.ast.RefAsStatement; import com.android.jack.transformations.booleanoperators.FallThroughMarker; +import com.android.jack.transformations.cast.SourceCast; import com.android.jack.transformations.request.AppendBefore; import com.android.jack.transformations.request.Remove; import com.android.jack.transformations.request.Replace; @@ -82,7 +83,7 @@ import javax.annotation.Nonnull; */ @Description("Transform body of a JMethod to into a three address form.") @Name("ThreeAddressCodeBuilder") -@Constraint(need = {NoImplicitBlock.class}, no = {InitInNewArray.class, +@Constraint(need = {NoImplicitBlock.class, SourceCast.class}, no = {InitInNewArray.class, JAssertStatement.class, JAsgOperation.class, JFieldInitializer.class, JConditionalOperation.class, JLoop.class}) @Transform(add = {ThreeAddressCodeForm.class, |