summaryrefslogtreecommitdiffstats
path: root/jack
diff options
context:
space:
mode:
authormikaelpeltier <mikaelpeltier@google.com>2014-09-19 14:45:43 +0200
committerJean-Philippe Lesot <jpl@gloups.org>2014-09-19 13:30:47 +0000
commit24e7ff5d7d921abd748290a560e476a108261b85 (patch)
treed0210f5885d58aec4dac3ef039f06565deca9c48 /jack
parent5e0979aa6475f14b4316d9b8a326e7720d7add7e (diff)
downloadtoolchain_jack-24e7ff5d7d921abd748290a560e476a108261b85.zip
toolchain_jack-24e7ff5d7d921abd748290a560e476a108261b85.tar.gz
toolchain_jack-24e7ff5d7d921abd748290a560e476a108261b85.tar.bz2
Add option to sort enum fields into SwitchEnumSupport
- In order to be able to use dex comparator with dex generated by incremental support, the code must be generated in a deterministic way. To achieve this, enum fields are sorted into SwitchEnumSupport to generate always the same code and not a code that can change depending in which order fields are added to the enum. Change-Id: Ia9ec0de4dd28a54ca360ceed96393dc1ff076a7c
Diffstat (limited to 'jack')
-rw-r--r--jack/src/com/android/jack/transformations/enums/SwitchEnumSupport.java24
1 files changed, 23 insertions, 1 deletions
diff --git a/jack/src/com/android/jack/transformations/enums/SwitchEnumSupport.java b/jack/src/com/android/jack/transformations/enums/SwitchEnumSupport.java
index dc5f8af..fd55f06 100644
--- a/jack/src/com/android/jack/transformations/enums/SwitchEnumSupport.java
+++ b/jack/src/com/android/jack/transformations/enums/SwitchEnumSupport.java
@@ -81,10 +81,13 @@ import com.android.sched.schedulable.Constraint;
import com.android.sched.schedulable.RunnableSchedulable;
import com.android.sched.schedulable.Transform;
import com.android.sched.schedulable.Use;
+import com.android.sched.util.config.HasKeyId;
import com.android.sched.util.config.ThreadConfig;
+import com.android.sched.util.config.id.BooleanPropertyId;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Comparator;
import java.util.List;
import java.util.Set;
@@ -109,8 +112,16 @@ import javax.annotation.Nonnull;
EnumMappingSchedulingSeparator.SeparatorTag.class},
remove = {JSwitchStatement.SwitchWithEnum.class, ThreeAddressCodeForm.class})
@Use(value = {LocalVarCreator.class})
+@HasKeyId
public class SwitchEnumSupport implements RunnableSchedulable<JMethod> {
+ // Private option that must be used only for incremental test in order to use dex comparator.
+ @Nonnull
+ public static final BooleanPropertyId SORT_ENUM_FIELD = BooleanPropertyId.create(
+ "jack.internal.switch-enumfield.sort",
+ "Sort enum fields by their name for enum partial recompilation support")
+ .addDefaultValue(Boolean.FALSE).makePrivate();
+
/**
* Enum fields used into switch.
*/
@@ -140,6 +151,8 @@ public class SwitchEnumSupport implements RunnableSchedulable<JMethod> {
private static class Visitor extends JVisitor {
+ private final boolean sortEnumField = ThreadConfig.get(SORT_ENUM_FIELD).booleanValue();
+
private static final String ORDINAL = "ordinal";
@Nonnull
@@ -295,7 +308,16 @@ public class SwitchEnumSupport implements RunnableSchedulable<JMethod> {
JType noSuchFieldErrorType = lookup.getType("Ljava/lang/NoSuchFieldError;");
EnumMappingMarker emm = new EnumMappingMarker();
- for (JField enumField : enumType.getFields()) {
+ List<JField> enumFields = enumType.getFields();
+ if (sortEnumField) {
+ Collections.sort(enumFields, new Comparator<JField>() {
+ @Override
+ public int compare(JField o1, JField o2) {
+ return o1.getName().compareTo(o2.getName());
+ }
+ });
+ }
+ for (JField enumField : enumFields) {
if (!(enumField instanceof JEnumField)) {
continue;