Avoid double-lens application to field instructions in backend
Bug: b/267463817
Change-Id: I0b5235619c0dc3773b82d6032a5755006c01d4cb
diff --git a/src/main/java/com/android/tools/r8/dex/DexOutputBuffer.java b/src/main/java/com/android/tools/r8/dex/DexOutputBuffer.java
index 08f8cad..6eedbaf 100644
--- a/src/main/java/com/android/tools/r8/dex/DexOutputBuffer.java
+++ b/src/main/java/com/android/tools/r8/dex/DexOutputBuffer.java
@@ -5,6 +5,7 @@
import com.android.tools.r8.ByteBufferProvider;
import com.android.tools.r8.errors.CompilationError;
+import com.android.tools.r8.graph.AppView;
import com.android.tools.r8.graph.DexWritableCode;
import com.android.tools.r8.graph.ObjectToOffsetMapping;
import com.android.tools.r8.graph.ProgramMethod;
@@ -92,6 +93,7 @@
}
public void putInstructions(
+ AppView<?> appView,
DexWritableCode code,
ProgramMethod context,
ObjectToOffsetMapping mapping,
@@ -101,7 +103,12 @@
assert byteBuffer.position() % 2 == 0;
ShortBuffer shortBuffer = byteBuffer.asShortBuffer();
code.writeDex(
- shortBuffer, context, mapping.getGraphLens(), mapping.getLensCodeRewriter(), mapping);
+ shortBuffer,
+ context,
+ mapping.getGraphLens(),
+ code.getCodeLens(appView),
+ mapping.getLensCodeRewriter(),
+ mapping);
code.writeKeepRulesForDesugaredLibrary(desugaredLibraryCodeToKeep);
byteBuffer.position(byteBuffer.position() + shortBuffer.position() * Short.BYTES);
}
diff --git a/src/main/java/com/android/tools/r8/dex/FileWriter.java b/src/main/java/com/android/tools/r8/dex/FileWriter.java
index a6f6a52..1f22038 100644
--- a/src/main/java/com/android/tools/r8/dex/FileWriter.java
+++ b/src/main/java/com/android/tools/r8/dex/FileWriter.java
@@ -486,7 +486,7 @@
int insnSizeOffset = dest.position();
dest.forward(4);
// Write instruction stream.
- dest.putInstructions(code, method, mapping, desugaredLibraryCodeToKeep);
+ dest.putInstructions(appView, code, method, mapping, desugaredLibraryCodeToKeep);
// Compute size and do the backward/forward dance to write the size at the beginning.
int insnSize = dest.position() - insnSizeOffset - 4;
dest.rewind(insnSize + 4);
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexCheckCast.java b/src/main/java/com/android/tools/r8/dex/code/DexCheckCast.java
index 650655a..6d95477 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexCheckCast.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexCheckCast.java
@@ -74,6 +74,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
DexType rewritten = graphLens.lookupType(getType());
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexConstClass.java b/src/main/java/com/android/tools/r8/dex/code/DexConstClass.java
index bc476c1..791eef5 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexConstClass.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexConstClass.java
@@ -74,6 +74,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
DexType rewritten = graphLens.lookupType(getType());
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexConstMethodHandle.java b/src/main/java/com/android/tools/r8/dex/code/DexConstMethodHandle.java
index 87964c8..9902b5a 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexConstMethodHandle.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexConstMethodHandle.java
@@ -78,6 +78,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
DexMethodHandle rewritten =
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexConstMethodType.java b/src/main/java/com/android/tools/r8/dex/code/DexConstMethodType.java
index 68f49fb..abc78c5 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexConstMethodType.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexConstMethodType.java
@@ -76,6 +76,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
DexProto rewritten = rewriter.rewriteProto(getMethodType());
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexConstString.java b/src/main/java/com/android/tools/r8/dex/code/DexConstString.java
index 0117785..b563580 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexConstString.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexConstString.java
@@ -89,6 +89,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
int index = BBBB.getOffset(mapping);
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexFillArrayDataPayload.java b/src/main/java/com/android/tools/r8/dex/code/DexFillArrayDataPayload.java
index 67d796c..ce3aa5f 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexFillArrayDataPayload.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexFillArrayDataPayload.java
@@ -56,6 +56,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
writeFirst(3, dest); // Pseudo-opcode = 0x0300
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexFilledNewArray.java b/src/main/java/com/android/tools/r8/dex/code/DexFilledNewArray.java
index ab52b2b..08d174c 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexFilledNewArray.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexFilledNewArray.java
@@ -72,6 +72,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
DexType rewritten = graphLens.lookupType(getType());
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexFilledNewArrayRange.java b/src/main/java/com/android/tools/r8/dex/code/DexFilledNewArrayRange.java
index 5e473dc..5a7ab7d 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexFilledNewArrayRange.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexFilledNewArrayRange.java
@@ -72,6 +72,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
DexType rewritten = graphLens.lookupType(getType());
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexFormat10t.java b/src/main/java/com/android/tools/r8/dex/code/DexFormat10t.java
index ba9065a..45ade87 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexFormat10t.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexFormat10t.java
@@ -35,6 +35,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
writeFirst(AA, dest);
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexFormat10x.java b/src/main/java/com/android/tools/r8/dex/code/DexFormat10x.java
index 3cb41fb..86944cb 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexFormat10x.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexFormat10x.java
@@ -27,6 +27,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
writeFirst(0, dest);
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexFormat11n.java b/src/main/java/com/android/tools/r8/dex/code/DexFormat11n.java
index fe02384..204e7e1 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexFormat11n.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexFormat11n.java
@@ -49,6 +49,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
writeFirst(B, A, dest);
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexFormat11x.java b/src/main/java/com/android/tools/r8/dex/code/DexFormat11x.java
index b07478c..44f5c30 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexFormat11x.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexFormat11x.java
@@ -35,6 +35,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
writeFirst(AA, dest);
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexFormat12x.java b/src/main/java/com/android/tools/r8/dex/code/DexFormat12x.java
index 633837d..ee1e5f9 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexFormat12x.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexFormat12x.java
@@ -43,6 +43,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
writeFirst(B, A, dest);
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexFormat20t.java b/src/main/java/com/android/tools/r8/dex/code/DexFormat20t.java
index 0c0e15e..34e8f65 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexFormat20t.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexFormat20t.java
@@ -34,6 +34,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
writeFirst(0, dest);
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexFormat21h.java b/src/main/java/com/android/tools/r8/dex/code/DexFormat21h.java
index 246c6cc..40d5684 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexFormat21h.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexFormat21h.java
@@ -43,6 +43,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
writeFirst(AA, dest);
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexFormat21s.java b/src/main/java/com/android/tools/r8/dex/code/DexFormat21s.java
index 97e3529..29fc6dc 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexFormat21s.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexFormat21s.java
@@ -45,6 +45,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
writeFirst(AA, dest);
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexFormat21t.java b/src/main/java/com/android/tools/r8/dex/code/DexFormat21t.java
index 1c80b33..3714ab9 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexFormat21t.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexFormat21t.java
@@ -47,6 +47,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
writeFirst(AA, dest);
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexFormat22b.java b/src/main/java/com/android/tools/r8/dex/code/DexFormat22b.java
index 687d7e7..f401ad1 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexFormat22b.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexFormat22b.java
@@ -49,6 +49,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
writeFirst(AA, dest);
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexFormat22s.java b/src/main/java/com/android/tools/r8/dex/code/DexFormat22s.java
index e503467..ac516bf 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexFormat22s.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexFormat22s.java
@@ -49,6 +49,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
writeFirst(B, A, dest);
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexFormat22t.java b/src/main/java/com/android/tools/r8/dex/code/DexFormat22t.java
index 17695d7..93a9d78 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexFormat22t.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexFormat22t.java
@@ -51,6 +51,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
writeFirst(B, A, dest);
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexFormat22x.java b/src/main/java/com/android/tools/r8/dex/code/DexFormat22x.java
index 3c34540..a4d26be 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexFormat22x.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexFormat22x.java
@@ -44,6 +44,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
writeFirst(AA, dest);
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexFormat23x.java b/src/main/java/com/android/tools/r8/dex/code/DexFormat23x.java
index df098d9..c02f40c 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexFormat23x.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexFormat23x.java
@@ -48,6 +48,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
writeFirst(AA, dest);
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexFormat30t.java b/src/main/java/com/android/tools/r8/dex/code/DexFormat30t.java
index aa744ad..f44ec09 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexFormat30t.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexFormat30t.java
@@ -33,6 +33,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
writeFirst(0, dest);
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexFormat31c.java b/src/main/java/com/android/tools/r8/dex/code/DexFormat31c.java
index 8023664..2a215d6 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexFormat31c.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexFormat31c.java
@@ -47,6 +47,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
writeFirst(AA, dest);
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexFormat31i.java b/src/main/java/com/android/tools/r8/dex/code/DexFormat31i.java
index 0795a92..506830b 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexFormat31i.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexFormat31i.java
@@ -43,6 +43,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
writeFirst(AA, dest);
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexFormat31t.java b/src/main/java/com/android/tools/r8/dex/code/DexFormat31t.java
index 320514d..5e995c0 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexFormat31t.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexFormat31t.java
@@ -43,6 +43,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
writeFirst(AA, dest);
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexFormat32x.java b/src/main/java/com/android/tools/r8/dex/code/DexFormat32x.java
index 00cf1f4..a50fa95 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexFormat32x.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexFormat32x.java
@@ -45,6 +45,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
writeFirst(0, dest);
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexFormat45cc.java b/src/main/java/com/android/tools/r8/dex/code/DexFormat45cc.java
index 61a0257..13ee6b6 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexFormat45cc.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexFormat45cc.java
@@ -120,6 +120,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
// The method is one of java.lang.MethodHandle.invoke/invokeExact.
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexFormat4rcc.java b/src/main/java/com/android/tools/r8/dex/code/DexFormat4rcc.java
index b795316..5def9bb 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexFormat4rcc.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexFormat4rcc.java
@@ -57,6 +57,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
// The method is one of java.lang.MethodHandle.invoke/invokeExact.
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexFormat51l.java b/src/main/java/com/android/tools/r8/dex/code/DexFormat51l.java
index 30ddee5..7acfa1c 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexFormat51l.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexFormat51l.java
@@ -43,6 +43,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
writeFirst(AA, dest);
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexIgetOrIput.java b/src/main/java/com/android/tools/r8/dex/code/DexIgetOrIput.java
index d1c298a..1f77b9f 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexIgetOrIput.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexIgetOrIput.java
@@ -42,9 +42,10 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
- DexField lookup = graphLens.lookupField(getField());
+ DexField lookup = graphLens.lookupField(getField(), codeLens);
writeFirst(B, A, dest);
write16BitReference(lookup, dest, mapping);
}
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexInitClass.java b/src/main/java/com/android/tools/r8/dex/code/DexInitClass.java
index c600656..bf0fd38 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexInitClass.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexInitClass.java
@@ -118,6 +118,7 @@
ShortBuffer buffer,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
// We intentionally apply the graph lens first, and then the init class lens, using the fact
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexInstanceOf.java b/src/main/java/com/android/tools/r8/dex/code/DexInstanceOf.java
index 601dffb..ba204cd 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexInstanceOf.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexInstanceOf.java
@@ -88,6 +88,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
DexType lookup = graphLens.lookupType(getType());
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexInstruction.java b/src/main/java/com/android/tools/r8/dex/code/DexInstruction.java
index d5f8183..d12d986 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexInstruction.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexInstruction.java
@@ -393,6 +393,7 @@
ShortBuffer buffer,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter);
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexInvokeCustom.java b/src/main/java/com/android/tools/r8/dex/code/DexInvokeCustom.java
index 605b420..28464af 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexInvokeCustom.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexInvokeCustom.java
@@ -79,6 +79,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
writeFirst(A, G, dest);
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexInvokeCustomRange.java b/src/main/java/com/android/tools/r8/dex/code/DexInvokeCustomRange.java
index a88f338..51f0908 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexInvokeCustomRange.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexInvokeCustomRange.java
@@ -79,6 +79,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
DexCallSite rewritten = rewriter.rewriteCallSite(getCallSite(), context);
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexInvokeMethod.java b/src/main/java/com/android/tools/r8/dex/code/DexInvokeMethod.java
index 9340e4a..a390eff 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexInvokeMethod.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexInvokeMethod.java
@@ -50,6 +50,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
MethodLookupResult lookup =
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexInvokeMethodRange.java b/src/main/java/com/android/tools/r8/dex/code/DexInvokeMethodRange.java
index 34243ac..3c1ffc7 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexInvokeMethodRange.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexInvokeMethodRange.java
@@ -50,6 +50,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
MethodLookupResult lookup =
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexItemBasedConstString.java b/src/main/java/com/android/tools/r8/dex/code/DexItemBasedConstString.java
index d34a783..0917719 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexItemBasedConstString.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexItemBasedConstString.java
@@ -101,6 +101,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
throw new Unreachable(
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexNewArray.java b/src/main/java/com/android/tools/r8/dex/code/DexNewArray.java
index 8d35555..285b82e 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexNewArray.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexNewArray.java
@@ -78,6 +78,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
DexType lookup = graphLens.lookupType(getType());
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexNewInstance.java b/src/main/java/com/android/tools/r8/dex/code/DexNewInstance.java
index 4382e71..e3bc04d 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexNewInstance.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexNewInstance.java
@@ -65,6 +65,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
DexType rewritten = graphLens.lookupType(getType());
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexNewUnboxedEnumInstance.java b/src/main/java/com/android/tools/r8/dex/code/DexNewUnboxedEnumInstance.java
index 387952c..3992859 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexNewUnboxedEnumInstance.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexNewUnboxedEnumInstance.java
@@ -64,6 +64,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
throw new Unreachable();
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexPackedSwitchPayload.java b/src/main/java/com/android/tools/r8/dex/code/DexPackedSwitchPayload.java
index d06f619..64b57b8 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexPackedSwitchPayload.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexPackedSwitchPayload.java
@@ -52,6 +52,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
writeFirst(1, dest); // Pseudo-opcode = 0x0100
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexRecordFieldValues.java b/src/main/java/com/android/tools/r8/dex/code/DexRecordFieldValues.java
index 955f67e..95d3348 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexRecordFieldValues.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexRecordFieldValues.java
@@ -117,6 +117,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
throw new Unreachable(
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexSgetOrSput.java b/src/main/java/com/android/tools/r8/dex/code/DexSgetOrSput.java
index 85c8ea3..0e9b3b8 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexSgetOrSput.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexSgetOrSput.java
@@ -38,9 +38,10 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
- DexField rewritten = graphLens.lookupField(getField());
+ DexField rewritten = graphLens.lookupField(getField(), codeLens);
writeFirst(AA, dest);
write16BitReference(rewritten, dest, mapping);
}
diff --git a/src/main/java/com/android/tools/r8/dex/code/DexSparseSwitchPayload.java b/src/main/java/com/android/tools/r8/dex/code/DexSparseSwitchPayload.java
index 97d369a..4d79273 100644
--- a/src/main/java/com/android/tools/r8/dex/code/DexSparseSwitchPayload.java
+++ b/src/main/java/com/android/tools/r8/dex/code/DexSparseSwitchPayload.java
@@ -56,6 +56,7 @@
ShortBuffer dest,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
ObjectToOffsetMapping mapping,
LensCodeRewriterUtils rewriter) {
writeFirst(2, dest); // Pseudo-opcode = 0x0200
diff --git a/src/main/java/com/android/tools/r8/graph/DefaultInstanceInitializerCode.java b/src/main/java/com/android/tools/r8/graph/DefaultInstanceInitializerCode.java
index 5569e34..f8d8f0a 100644
--- a/src/main/java/com/android/tools/r8/graph/DefaultInstanceInitializerCode.java
+++ b/src/main/java/com/android/tools/r8/graph/DefaultInstanceInitializerCode.java
@@ -368,11 +368,12 @@
ShortBuffer shortBuffer,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
LensCodeRewriterUtils lensCodeRewriter,
ObjectToOffsetMapping mapping) {
new DexInvokeDirect(1, getParentConstructor(context, mapping.dexItemFactory()), 0, 0, 0, 0, 0)
- .write(shortBuffer, context, graphLens, mapping, lensCodeRewriter);
- new DexReturnVoid().write(shortBuffer, context, graphLens, mapping, lensCodeRewriter);
+ .write(shortBuffer, context, graphLens, codeLens, mapping, lensCodeRewriter);
+ new DexReturnVoid().write(shortBuffer, context, graphLens, codeLens, mapping, lensCodeRewriter);
}
@Override
diff --git a/src/main/java/com/android/tools/r8/graph/DexCode.java b/src/main/java/com/android/tools/r8/graph/DexCode.java
index 569af23..1869581 100644
--- a/src/main/java/com/android/tools/r8/graph/DexCode.java
+++ b/src/main/java/com/android/tools/r8/graph/DexCode.java
@@ -79,6 +79,20 @@
.withItemArray(c -> c.instructions);
}
+ private DexCode(DexCode code) {
+ this(
+ code.registerSize,
+ code.incomingRegisterSize,
+ code.outgoingRegisterSize,
+ code.instructions,
+ code.tries,
+ code.handlers,
+ code.debugInfo,
+ code.metadata);
+ this.debugInfoForWriting = code.debugInfoForWriting;
+ this.highestSortingString = code.highestSortingString;
+ }
+
public DexCode(int registerSize, int insSize, int outsSize, DexInstruction[] instructions) {
this(
registerSize,
@@ -132,6 +146,16 @@
hashCode(); // Cache the hash code eagerly.
}
+ public DexCode withCodeLens(GraphLens codeLens) {
+ return new DexCode(this) {
+
+ @Override
+ public GraphLens getCodeLens(AppView<?> appView) {
+ return codeLens;
+ }
+ };
+ }
+
@Override
public DexCode self() {
return this;
@@ -727,10 +751,11 @@
ShortBuffer shortBuffer,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
LensCodeRewriterUtils lensCodeRewriter,
ObjectToOffsetMapping mapping) {
for (DexInstruction instruction : instructions) {
- instruction.write(shortBuffer, context, graphLens, mapping, lensCodeRewriter);
+ instruction.write(shortBuffer, context, graphLens, codeLens, mapping, lensCodeRewriter);
}
}
diff --git a/src/main/java/com/android/tools/r8/graph/DexWritableCode.java b/src/main/java/com/android/tools/r8/graph/DexWritableCode.java
index 1458f08..af4b8a0 100644
--- a/src/main/java/com/android/tools/r8/graph/DexWritableCode.java
+++ b/src/main/java/com/android/tools/r8/graph/DexWritableCode.java
@@ -63,6 +63,8 @@
void writeKeepRulesForDesugaredLibrary(CodeToKeep codeToKeep);
+ GraphLens getCodeLens(AppView<?> appView);
+
DexDebugInfoForWriting getDebugInfoForWriting();
DexWritableCodeKind getDexWritableCodeKind();
@@ -99,6 +101,7 @@
ShortBuffer shortBuffer,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
LensCodeRewriterUtils lensCodeRewriter,
ObjectToOffsetMapping mapping);
}
diff --git a/src/main/java/com/android/tools/r8/graph/NestedGraphLens.java b/src/main/java/com/android/tools/r8/graph/NestedGraphLens.java
index fe15a02..4c61282 100644
--- a/src/main/java/com/android/tools/r8/graph/NestedGraphLens.java
+++ b/src/main/java/com/android/tools/r8/graph/NestedGraphLens.java
@@ -135,7 +135,7 @@
if (this == codeLens) {
return originalField;
}
- DexField renamedField = getPrevious().getRenamedFieldSignature(originalField);
+ DexField renamedField = getPrevious().getRenamedFieldSignature(originalField, codeLens);
return internalGetNextFieldSignature(renamedField);
}
diff --git a/src/main/java/com/android/tools/r8/graph/ThrowExceptionCode.java b/src/main/java/com/android/tools/r8/graph/ThrowExceptionCode.java
index 789bb19..8fe2e15 100644
--- a/src/main/java/com/android/tools/r8/graph/ThrowExceptionCode.java
+++ b/src/main/java/com/android/tools/r8/graph/ThrowExceptionCode.java
@@ -211,19 +211,21 @@
ShortBuffer shortBuffer,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
LensCodeRewriterUtils lensCodeRewriter,
ObjectToOffsetMapping mapping) {
int register = 0;
int notUsed = 0;
int argumentCount = 1;
new DexNewInstance(register, exceptionType)
- .write(shortBuffer, context, graphLens, mapping, lensCodeRewriter);
+ .write(shortBuffer, context, graphLens, codeLens, mapping, lensCodeRewriter);
DexMethod instanceInitializer =
lensCodeRewriter.dexItemFactory().createInstanceInitializer(exceptionType);
new DexInvokeDirect(
argumentCount, instanceInitializer, register, notUsed, notUsed, notUsed, notUsed)
- .write(shortBuffer, context, graphLens, mapping, lensCodeRewriter);
- new DexThrow(register).write(shortBuffer, context, graphLens, mapping, lensCodeRewriter);
+ .write(shortBuffer, context, graphLens, codeLens, mapping, lensCodeRewriter);
+ new DexThrow(register)
+ .write(shortBuffer, context, graphLens, codeLens, mapping, lensCodeRewriter);
}
@Override
diff --git a/src/main/java/com/android/tools/r8/graph/ThrowNullCode.java b/src/main/java/com/android/tools/r8/graph/ThrowNullCode.java
index cac6f7a..04a82ce 100644
--- a/src/main/java/com/android/tools/r8/graph/ThrowNullCode.java
+++ b/src/main/java/com/android/tools/r8/graph/ThrowNullCode.java
@@ -248,11 +248,14 @@
ShortBuffer shortBuffer,
ProgramMethod context,
GraphLens graphLens,
+ GraphLens codeLens,
LensCodeRewriterUtils lensCodeRewriter,
ObjectToOffsetMapping mapping) {
int register = 0;
- new DexConst4(register, 0).write(shortBuffer, context, graphLens, mapping, lensCodeRewriter);
- new DexThrow(register).write(shortBuffer, context, graphLens, mapping, lensCodeRewriter);
+ new DexConst4(register, 0)
+ .write(shortBuffer, context, graphLens, codeLens, mapping, lensCodeRewriter);
+ new DexThrow(register)
+ .write(shortBuffer, context, graphLens, codeLens, mapping, lensCodeRewriter);
}
@Override
diff --git a/src/main/java/com/android/tools/r8/horizontalclassmerging/code/SyntheticInitializerConverter.java b/src/main/java/com/android/tools/r8/horizontalclassmerging/code/SyntheticInitializerConverter.java
index a3e5972..1872754 100644
--- a/src/main/java/com/android/tools/r8/horizontalclassmerging/code/SyntheticInitializerConverter.java
+++ b/src/main/java/com/android/tools/r8/horizontalclassmerging/code/SyntheticInitializerConverter.java
@@ -6,7 +6,9 @@
import com.android.tools.r8.graph.AppInfo;
import com.android.tools.r8.graph.AppView;
+import com.android.tools.r8.graph.Code;
import com.android.tools.r8.graph.DexProgramClass;
+import com.android.tools.r8.graph.GraphLens;
import com.android.tools.r8.graph.ProgramMethod;
import com.android.tools.r8.horizontalclassmerging.HorizontalClassMerger.Mode;
import com.android.tools.r8.horizontalclassmerging.IRCodeProvider;
@@ -78,10 +80,18 @@
assert appView.options().isGeneratingDex();
assert mode.isFinal();
clazz.forEachProgramInstanceInitializerMatching(
- method -> !method.getCode().isDexCode(),
+ method -> method.getCode().isCfCode(),
method -> {
+ GraphLens codeLens = method.getDefinition().getCode().getCodeLens(appView);
+ assert codeLens != appView.codeLens();
+
+ // Convert to dex.
processMethod(method, converter);
- assert method.getDefinition().getCode().isDexCode();
+
+ // Recover code lens.
+ Code code = method.getDefinition().getCode();
+ assert code.isDexCode();
+ method.setCode(code.asDexCode().withCodeLens(codeLens), appView);
});
}