diff options
author | mikaelpeltier <mikaelpeltier@google.com> | 2014-10-02 13:16:00 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-10-02 13:16:01 +0000 |
commit | 9d4a42cb216568aafa70007e16e86a83b27a9963 (patch) | |
tree | 0a6cca2b4c449b499cea3dd18ffe22ecf697584b /jack | |
parent | 4ee8e304b7368cf4b6851c33321e3f454855bcde (diff) | |
parent | d0e77f3cf8b4c97128b4c844f28a3e6bc5a86fcd (diff) | |
download | toolchain_jack-9d4a42cb216568aafa70007e16e86a83b27a9963.zip toolchain_jack-9d4a42cb216568aafa70007e16e86a83b27a9963.tar.gz toolchain_jack-9d4a42cb216568aafa70007e16e86a83b27a9963.tar.bz2 |
Merge "Lookup j.l.Object directly into the RunnableSchedulable" into ub-jack
Diffstat (limited to 'jack')
6 files changed, 74 insertions, 44 deletions
diff --git a/jack/src/com/android/jack/transformations/AssertionTransformer.java b/jack/src/com/android/jack/transformations/AssertionTransformer.java index 0035396..217615c 100644 --- a/jack/src/com/android/jack/transformations/AssertionTransformer.java +++ b/jack/src/com/android/jack/transformations/AssertionTransformer.java @@ -93,14 +93,18 @@ public class AssertionTransformer implements RunnableSchedulable<JMethod> { @Nonnull private final Filter<JMethod> filter = ThreadConfig.get(Options.METHOD_FILTER); - private static class Visitor extends JVisitor { + @Nonnull + private final JClass jlo = + Jack.getSession().getPhantomLookup().getClass(CommonTypes.JAVA_LANG_OBJECT); - @Nonnull - private final JDefinedClassOrInterface currentType; + @Nonnull + private static final String ASSERTION_FIELD_NAME = + NamingTools.getNonSourceConflictingName("assertionsDisabled"); + + private class Visitor extends JVisitor { @Nonnull - private static final String ASSERTION_FIELD_NAME = - NamingTools.getNonSourceConflictingName("assertionsDisabled"); + private final JDefinedClassOrInterface currentType; public Visitor(@Nonnull JDefinedClassOrInterface type) { this.currentType = type; @@ -172,8 +176,7 @@ public class AssertionTransformer implements RunnableSchedulable<JMethod> { List<JType> ctorDescriptor = new ArrayList<JType>(); if (assertSt.getArg() != null) { - ctorDescriptor.add( - Jack.getSession().getPhantomLookup().getClass(CommonTypes.JAVA_LANG_OBJECT)); + ctorDescriptor.add(jlo); } JClass assertionError = diff --git a/jack/src/com/android/jack/transformations/ast/ConcatRemover.java b/jack/src/com/android/jack/transformations/ast/ConcatRemover.java index 3dd4701..d014177 100644 --- a/jack/src/com/android/jack/transformations/ast/ConcatRemover.java +++ b/jack/src/com/android/jack/transformations/ast/ConcatRemover.java @@ -16,9 +16,11 @@ package com.android.jack.transformations.ast; +import com.android.jack.Jack; import com.android.jack.Options; import com.android.jack.ir.ast.JAsgConcatOperation; import com.android.jack.ir.ast.JBinaryOperation; +import com.android.jack.ir.ast.JClass; import com.android.jack.ir.ast.JClassOrInterface; import com.android.jack.ir.ast.JConcatOperation; import com.android.jack.ir.ast.JDefinedClassOrInterface; @@ -82,6 +84,14 @@ public class ConcatRemover implements RunnableSchedulable<JMethod> { private static final String TO_STRING = "toString"; @Nonnull + private final JClass jlo = + Jack.getSession().getPhantomLookup().getClass(CommonTypes.JAVA_LANG_OBJECT); + + @Nonnull + private final JClass jls = + Jack.getSession().getPhantomLookup().getClass(CommonTypes.JAVA_LANG_STRING); + + @Nonnull private final Filter<JMethod> filter = ThreadConfig.get(Options.METHOD_FILTER); @CheckForNull private JSession session; @@ -135,7 +145,7 @@ public class ConcatRemover implements RunnableSchedulable<JMethod> { appendRhs, stringBuilder, stringBuilderToString, - session.getPhantomLookup().getClass(CommonTypes.JAVA_LANG_STRING), + jls, stringBuilderToString.canBeVirtual()); tr.append(new Replace(binary, toString)); @@ -225,16 +235,15 @@ public class ConcatRemover implements RunnableSchedulable<JMethod> { default: throw new AssertionError(); } - } else if (elementType.isSameType( - session.getPhantomLookup().getClass(CommonTypes.JAVA_LANG_STRING))) { - appendArgType = session.getPhantomLookup().getClass(CommonTypes.JAVA_LANG_STRING); + } else if (elementType.isSameType(jls)) { + appendArgType = jls; } else { JType charSequence = getCharSequence(); assert session != null; // FINDBUGS if (elementType == charSequence){ appendArgType = charSequence; } else { - appendArgType = session.getPhantomLookup().getClass(CommonTypes.JAVA_LANG_OBJECT); + appendArgType = jlo; } } diff --git a/jack/src/com/android/jack/transformations/ast/MultiDimensionNewArrayRemover.java b/jack/src/com/android/jack/transformations/ast/MultiDimensionNewArrayRemover.java index 8ea3f5f..c510a19 100644 --- a/jack/src/com/android/jack/transformations/ast/MultiDimensionNewArrayRemover.java +++ b/jack/src/com/android/jack/transformations/ast/MultiDimensionNewArrayRemover.java @@ -16,9 +16,11 @@ package com.android.jack.transformations.ast; +import com.android.jack.Jack; import com.android.jack.Options; import com.android.jack.ir.ast.JAbsentArrayDimension; import com.android.jack.ir.ast.JArrayType; +import com.android.jack.ir.ast.JClass; import com.android.jack.ir.ast.JClassLiteral; import com.android.jack.ir.ast.JClassOrInterface; import com.android.jack.ir.ast.JDefinedClassOrInterface; @@ -68,7 +70,15 @@ public class MultiDimensionNewArrayRemover implements RunnableSchedulable<JMetho @Nonnull private final Filter<JMethod> filter = ThreadConfig.get(Options.METHOD_FILTER); - private static class Visitor extends JVisitor { + @Nonnull + private final JClass jlo = + Jack.getSession().getPhantomLookup().getClass(CommonTypes.JAVA_LANG_OBJECT); + + @Nonnull + private final JClass jlc = + Jack.getSession().getPhantomLookup().getClass(CommonTypes.JAVA_LANG_CLASS); + + private class Visitor extends JVisitor { @Nonnull private final TransformationRequest tr; @@ -97,12 +107,14 @@ public class MultiDimensionNewArrayRemover implements RunnableSchedulable<JMetho SourceInfo sourceInfo = newArray.getSourceInfo(); JClassOrInterface reflectArrayType = getReflectArrayType(); JMethodId newInstanceId = getNewInstanceId(reflectArrayType); - JMethodCall call = new JMethodCall(sourceInfo, null, reflectArrayType, newInstanceId, - session.getPhantomLookup().getClass(CommonTypes.JAVA_LANG_OBJECT), + JMethodCall call = new JMethodCall(sourceInfo, + null, + reflectArrayType, + newInstanceId, + jlo, newInstanceId.canBeVirtual()); - call.addArg(new JClassLiteral( - sourceInfo, getComponentTypeForNewInstance(newArray, nbPresentDimensions), - session.getPhantomLookup().getClass(CommonTypes.JAVA_LANG_CLASS))); + call.addArg(new JClassLiteral(sourceInfo, + getComponentTypeForNewInstance(newArray, nbPresentDimensions), jlc)); call.addArg(JNewArray.createWithInits(sourceInfo, getIntArrayType(), presentDimensions)); tr.append(new Replace(newArray, new JDynamicCastOperation(sourceInfo, newArray .getArrayType(), call))); @@ -115,7 +127,7 @@ public class MultiDimensionNewArrayRemover implements RunnableSchedulable<JMetho private JMethodId getNewInstanceId(JClassOrInterface reflectArrayType) { if (newInstance == null) { List<JType> argsType = new ArrayList<JType>(2); - argsType.add(session.getPhantomLookup().getClass(CommonTypes.JAVA_LANG_CLASS)); + argsType.add(jlc); argsType.add(getIntArrayType()); newInstance = reflectArrayType.getOrCreateMethodId("newInstance", argsType, MethodKind.STATIC); diff --git a/jack/src/com/android/jack/transformations/ast/switches/SwitchStringSupport.java b/jack/src/com/android/jack/transformations/ast/switches/SwitchStringSupport.java index 73dd442..635f905 100644 --- a/jack/src/com/android/jack/transformations/ast/switches/SwitchStringSupport.java +++ b/jack/src/com/android/jack/transformations/ast/switches/SwitchStringSupport.java @@ -16,6 +16,7 @@ package com.android.jack.transformations.ast.switches; +import com.android.jack.Jack; import com.android.jack.Options; import com.android.jack.ir.ast.JAbstractStringLiteral; import com.android.jack.ir.ast.JAsgOperation; @@ -79,13 +80,24 @@ public class SwitchStringSupport implements RunnableSchedulable<JMethod> { @Nonnull private final Filter<JMethod> filter = ThreadConfig.get(Options.METHOD_FILTER); - private static class Visitor extends JVisitor { + @Nonnull + private final JMethodId equalsMethodId; - @Nonnull - private final TransformationRequest tr; + { + JSession session = Jack.getSession(); + JPhantomLookup lookup = session.getPhantomLookup(); + JClass jlo = lookup.getClass(CommonTypes.JAVA_LANG_OBJECT); + JClass jls = lookup.getClass(CommonTypes.JAVA_LANG_STRING); + equalsMethodId = + jls.getMethodId("equals", Collections.singletonList((JType) jlo), + MethodKind.INSTANCE_VIRTUAL); + + } + + private class Visitor extends JVisitor { @Nonnull - private final JMethodId equalsMethodId; + private final TransformationRequest tr; @Nonnull private final LocalVarCreator localVarCreator; @@ -95,13 +107,6 @@ public class SwitchStringSupport implements RunnableSchedulable<JMethod> { public Visitor(@Nonnull TransformationRequest tr, @Nonnull JMethod method) { this.tr = tr; - JSession session = method.getEnclosingType().getSession(); - JPhantomLookup lookup = session.getPhantomLookup(); - JClass jlo = lookup.getClass(CommonTypes.JAVA_LANG_OBJECT); - JClass jls = lookup.getClass(CommonTypes.JAVA_LANG_STRING); - equalsMethodId = - jls.getMethodId("equals", Collections.singletonList((JType) jlo), - MethodKind.INSTANCE_VIRTUAL); localVarCreator = new LocalVarCreator(method, "switch_var_"); } diff --git a/jack/src/com/android/jack/transformations/exceptions/TryCatchRemover.java b/jack/src/com/android/jack/transformations/exceptions/TryCatchRemover.java index ef79b23..cf7f093 100644 --- a/jack/src/com/android/jack/transformations/exceptions/TryCatchRemover.java +++ b/jack/src/com/android/jack/transformations/exceptions/TryCatchRemover.java @@ -71,14 +71,18 @@ public class TryCatchRemover implements RunnableSchedulable<JMethod> { @Nonnull private final Filter<JMethod> filter = ThreadConfig.get(Options.METHOD_FILTER); - private static class Visitor extends JVisitor { + @Nonnull + private final JClass jlo = + Jack.getSession().getPhantomLookup().getClass(CommonTypes.JAVA_LANG_OBJECT); + + private class Visitor extends JVisitor { /** * Represent all try statement and specify if it is a starting point or not. Starting point * means that {@code tryStmt} represent the first try that will catch exceptions, others before * this try must be ignore. */ - private static class TryStmtCatchingExceptions { + private class TryStmtCatchingExceptions { @CheckForNull private final JTryStatement tryStmt; private final boolean isStartingPoint; @@ -209,8 +213,7 @@ public class TryCatchRemover implements RunnableSchedulable<JMethod> { int catchTypesCount = catchTypes.size(); for (JClass catchedType : bb.getCatchTypes()) { - if (catchedType.isSameType(Jack.getSession().getPhantomLookup() - .getClass(CommonTypes.JAVA_LANG_OBJECT))) { + if (catchedType.isSameType(jlo)) { assert bb.getCatchTypes().size() == 1; stmt.appendCatchBlock(bb); // means any, thus could not be catch again diff --git a/jack/src/com/android/jack/transformations/finallyblock/FinallyRemover.java b/jack/src/com/android/jack/transformations/finallyblock/FinallyRemover.java index 0b9fbfe..ae88306 100644 --- a/jack/src/com/android/jack/transformations/finallyblock/FinallyRemover.java +++ b/jack/src/com/android/jack/transformations/finallyblock/FinallyRemover.java @@ -16,6 +16,7 @@ package com.android.jack.transformations.finallyblock; +import com.android.jack.Jack; import com.android.jack.Options; import com.android.jack.ir.ast.JAsgOperation; import com.android.jack.ir.ast.JBlock; @@ -92,11 +93,15 @@ public class FinallyRemover implements RunnableSchedulable<JMethod> { @Nonnull private final Filter<JMethod> filter = ThreadConfig.get(Options.METHOD_FILTER); + @Nonnull + private final JClass throwableType = + Jack.getSession().getPhantomLookup().getClass(CommonTypes.JAVA_LANG_OBJECT); + /** * Finds the most nested {@link JTryStatement}s to inline its finally block. Then all of them are * handled going back up and the transformations are applied each time. */ - private static class JTryStatementVisitor extends JVisitor { + private class JTryStatementVisitor extends JVisitor { /** * A stack of {@link TransformationRequest} that contains the original @@ -109,18 +114,14 @@ public class FinallyRemover implements RunnableSchedulable<JMethod> { private final Stack<TransformationRequest> requestStack = new Stack<TransformationRequest>(); @Nonnull - private final JType throwableType; - @Nonnull private final JMethod currentMethod; @Nonnull private final List<InlinedFinallyMarker> inlinedFinallyMarkers = new ArrayList<InlinedFinallyMarker>(); private JTryStatementVisitor(@Nonnull TransformationRequest trRequest, - @Nonnull JType throwableType, @Nonnull JMethod currentMethod) { - + @Nonnull JMethod currentMethod) { this.requestStack.add(trRequest); - this.throwableType = throwableType; this.currentMethod = currentMethod; } @@ -410,12 +411,9 @@ public class FinallyRemover implements RunnableSchedulable<JMethod> { JDefinedClassOrInterface enclosingType = method.getEnclosingType(); assert enclosingType != null; - JClass throwableType = enclosingType.getSession().getPhantomLookup().getClass( - CommonTypes.JAVA_LANG_OBJECT); - TransformationRequest trRequest = new TransformationRequest(method); - JTryStatementVisitor visitor = new JTryStatementVisitor(trRequest, throwableType, method); + JTryStatementVisitor visitor = new JTryStatementVisitor(trRequest, method); visitor.accept(method); |