Permalink
Browse files

Revert "Add lambda experimental dalvik opcodes"

This reverts commit 144951a.
  • Loading branch information...
narayank committed Aug 17, 2016
1 parent afc1f15 commit 99b80bbc5a55f53e73a143a90f94faefbd5e4f7f
Showing with 2 additions and 729 deletions.
  1. +0 −42 baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/InstructionMethodItem.java
  2. +0 −55 baksmali/src/test/resources/LambdaTest/HelloWorldLambda.smali
  3. +0 −1 dexlib2/src/main/java/org/jf/dexlib2/Format.java
  4. +0 −9 dexlib2/src/main/java/org/jf/dexlib2/Opcode.java
  5. +0 −15 dexlib2/src/main/java/org/jf/dexlib2/builder/MutableMethodImplementation.java
  6. +0 −82 dexlib2/src/main/java/org/jf/dexlib2/builder/instruction/BuilderInstruction25x.java
  7. +0 −2 dexlib2/src/main/java/org/jf/dexlib2/dexbacked/instruction/DexBackedInstruction.java
  8. +0 −83 dexlib2/src/main/java/org/jf/dexlib2/dexbacked/instruction/DexBackedInstruction25x.java
  9. +0 −27 dexlib2/src/main/java/org/jf/dexlib2/dexbacked/raw/CodeItem.java
  10. +0 −47 dexlib2/src/main/java/org/jf/dexlib2/iface/instruction/OneFixedFourParameterRegisterInstruction.java
  11. +0 −37 dexlib2/src/main/java/org/jf/dexlib2/iface/instruction/formats/Instruction25x.java
  12. +0 −2 dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableInstruction.java
  13. +0 −97 dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableInstruction25x.java
  14. +0 −9 dexlib2/src/main/java/org/jf/dexlib2/util/Preconditions.java
  15. +0 −3 dexlib2/src/main/java/org/jf/dexlib2/writer/DexWriter.java
  16. +0 −14 dexlib2/src/main/java/org/jf/dexlib2/writer/InstructionWriter.java
  17. +0 −8 examples/HelloWorldLambda/HelloWorldFunctionalInterface.smali
  18. +0 −57 examples/HelloWorldLambda/HelloWorldLambda.smali
  19. +0 −36 smali/src/main/antlr/smaliParser.g
  20. +0 −73 smali/src/main/antlr/smaliTreeWalker.g
  21. +2 −18 smali/src/main/jflex/smaliLexer.jflex
  22. +0 −6 smali/src/test/resources/LexerTest/InstructionTest.smali
  23. +0 −6 smali/src/test/resources/LexerTest/InstructionTest.tokens
@@ -330,11 +330,6 @@ public boolean writeTo(IndentingWriter writer) throws IOException {
writer.write(", ");
writeThirdRegister(writer);
break;
case Format25x:
writeOpcode(writer);
writer.write(' ');
writeInvoke25xRegisters(writer); // vC, {vD, ...}
break;
case Format35c:
writeOpcode(writer);
writer.write(' ');
@@ -478,43 +473,6 @@ protected void writeInvokeRegisters(IndentingWriter writer) throws IOException {
writer.write('}');
}
protected void writeInvoke25xRegisters(IndentingWriter writer) throws IOException {
OneFixedFourParameterRegisterInstruction instruction =
(OneFixedFourParameterRegisterInstruction)this.instruction;
final int parameterRegCount = instruction.getParameterRegisterCount();
writeRegister(writer, instruction.getRegisterFixedC()); // fixed register always present
writer.write(", {");
switch (parameterRegCount) {
case 1:
writeRegister(writer, instruction.getRegisterParameterD());
break;
case 2:
writeRegister(writer, instruction.getRegisterParameterD());
writer.write(", ");
writeRegister(writer, instruction.getRegisterParameterE());
break;
case 3:
writeRegister(writer, instruction.getRegisterParameterD());
writer.write(", ");
writeRegister(writer, instruction.getRegisterParameterE());
writer.write(", ");
writeRegister(writer, instruction.getRegisterParameterF());
break;
case 4:
writeRegister(writer, instruction.getRegisterParameterD());
writer.write(", ");
writeRegister(writer, instruction.getRegisterParameterE());
writer.write(", ");
writeRegister(writer, instruction.getRegisterParameterF());
writer.write(", ");
writeRegister(writer, instruction.getRegisterParameterG());
break;
}
writer.write('}');
}
protected void writeInvokeRangeRegisters(IndentingWriter writer) throws IOException {
RegisterRangeInstruction instruction = (RegisterRangeInstruction)this.instruction;
@@ -1,55 +0,0 @@
.class public LHelloWorldLambda;
#Ye olde hello world application (with lambdas!)
#To assemble and run this on a phone or emulator:
#
#java -jar smali.jar -o classes.dex HelloWorldLambda.smali HelloWorldFunctionalInterface.smali
#zip HelloWorld.zip classes.dex
#adb push HelloWorld.zip /data/local
#adb shell dalvikvm -cp /data/local/HelloWorld.zip HelloWorld
#
#if you get out of memory type errors when running smali.jar, try
#java -Xmx512m -jar smali.jar HelloWorldLambda.smali
#instead
.super Ljava/lang/Object;
.method public static doHelloWorld(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
.registers 6 # 4 parameters, 2 locals
liberate-variable v0, p0, "helloworld"
sget-object v1, Ljava/lang/System;->out:Ljava/io/PrintStream;
invoke-virtual {v1, v0}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V
return-void
.end method
.method public static main([Ljava/lang/String;)V
.registers 9 # 1 parameter, 8 locals
sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;
const-string v1, "Hello World!"
const-string v2, "How" # vD
const-string v3, "are" # vE
const-string v4, "you" # vF
const-string v5, "doing?" # vG
capture-variable v1, "helloworld"
# TODO: do I need to pass the type of the lambda's functional interface here as a type id?
create-lambda v1, LHelloWorldLambda;->doHelloWorld(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
# Method descriptor is not required here, because only the single-abstract method is ever invoked.
invoke-lambda v1, {v2, v3, v4, v5}
box-lambda v6, v1
invoke-virtual {v6, v2, v3, v4, v5}, LHelloWorldFunctionalInterface;->applyFourStrings(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
# FIXME: should be \HelloWorldFunctionalInterface; instead of L...;
# TODO: do we really need the type descriptor here at all?
unbox-lambda v7, v6, LHelloWorldFunctionalInterface;
invoke-lambda v7, {v2, v3, v4, v5}
return-void
.end method
@@ -51,7 +51,6 @@
Format22t(4),
Format22x(4),
Format23x(4),
Format25x(4),
Format30t(6),
Format31c(6),
Format31i(6),
@@ -305,15 +305,6 @@
SPARSE_SWITCH_PAYLOAD(0x200, "sparse-switch-payload", ReferenceType.NONE, Format.SparseSwitchPayload, 0),
ARRAY_PAYLOAD(0x300, "array-payload", ReferenceType.NONE, Format.ArrayPayload, 0),
// Reuse the deprecated f3-ff opcodes in Art:
INVOKE_LAMBDA(allArtVersions(0xf3),"invoke-lambda", ReferenceType.NONE, Format.Format25x, Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_RESULT | Opcode.EXPERIMENTAL),
// TODO: What about JUMBO support if the string ID is too large?
CAPTURE_VARIABLE(allArtVersions(0xf5), "capture-variable", ReferenceType.STRING, Format.Format21c, Opcode.EXPERIMENTAL),
CREATE_LAMBDA(allArtVersions(0xf6), "create-lambda", ReferenceType.METHOD, Format.Format21c, Opcode.SETS_REGISTER | Opcode.EXPERIMENTAL),
// TODO: do we need a capture/liberate wide?
LIBERATE_VARIABLE(allArtVersions(0xf7), "liberate-variable", ReferenceType.STRING, Format.Format22c, Opcode.SETS_REGISTER | Opcode.EXPERIMENTAL),
BOX_LAMBDA(allArtVersions(0xf8), "box-lambda", ReferenceType.NONE, Format.Format22x, Opcode.SETS_REGISTER | Opcode.EXPERIMENTAL),
UNBOX_LAMBDA(allArtVersions(0xf9), "unbox-lambda", ReferenceType.TYPE, Format.Format22c, Opcode.SETS_REGISTER | Opcode.EXPERIMENTAL),
INVOKE_POLYMORPHIC(firstApi(0xfa, 26), "invoke-polymorphic", ReferenceType.METHOD, ReferenceType.METHOD_PROTO, Format.Format45cc, Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_RESULT),
INVOKE_POLYMORPHIC_RANGE(firstApi(0xfb, 26), "invoke-polymorphic/range", ReferenceType.METHOD, ReferenceType.METHOD_PROTO, Format.Format4rcc, Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_RESULT);
@@ -615,9 +615,6 @@ private void convertAndSetInstruction(@Nonnull MethodLocation location, int[] co
case Format23x:
setInstruction(location, newBuilderInstruction23x((Instruction23x) instruction));
return;
case Format25x:
setInstruction(location, newBuilderInstruction25x((Instruction25x) instruction));
return;
case Format30t:
setInstruction(location, newBuilderInstruction30t(location.codeAddress,
codeAddressToIndex,
@@ -871,18 +868,6 @@ private BuilderInstruction35c newBuilderInstruction35c(@Nonnull Instruction35c i
instruction.getReference());
}
@Nonnull
private BuilderInstruction25x newBuilderInstruction25x(@Nonnull Instruction25x instruction) {
return new BuilderInstruction25x(
instruction.getOpcode(),
instruction.getParameterRegisterCount(),
instruction.getRegisterFixedC(),
instruction.getRegisterParameterD(),
instruction.getRegisterParameterE(),
instruction.getRegisterParameterF(),
instruction.getRegisterParameterG());
}
@Nonnull
private BuilderInstruction3rc newBuilderInstruction3rc(@Nonnull Instruction3rc instruction) {
return new BuilderInstruction3rc(
@@ -1,82 +0,0 @@
/*
* Copyright 2015, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.builder.instruction;
import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.builder.BuilderInstruction;
import org.jf.dexlib2.iface.instruction.formats.Instruction25x;
import org.jf.dexlib2.util.Preconditions;
import javax.annotation.Nonnull;
public class BuilderInstruction25x extends BuilderInstruction implements Instruction25x {
public static final Format FORMAT = Format.Format25x;
protected final int parameterRegisterCount;
protected final int registerClosure;
protected final int registerD;
protected final int registerE;
protected final int registerF;
protected final int registerG;
public BuilderInstruction25x(@Nonnull Opcode opcode,
int parameterRegisterCount,
int registerClosure,
int registerD,
int registerE,
int registerF,
int registerG) {
super(opcode);
this.parameterRegisterCount =
Preconditions.check25xParameterRegisterCount(parameterRegisterCount);
this.registerClosure = Preconditions.checkNibbleRegister(registerClosure); //at least 1 reg
this.registerD = (parameterRegisterCount>0) ?
Preconditions.checkNibbleRegister(registerD) : 0;
this.registerE = (parameterRegisterCount>1) ?
Preconditions.checkNibbleRegister(registerE) : 0;
this.registerF = (parameterRegisterCount>2) ?
Preconditions.checkNibbleRegister(registerF) : 0;
this.registerG = (parameterRegisterCount>3) ?
Preconditions.checkNibbleRegister(registerG) : 0;
}
@Override public int getRegisterCount() { return parameterRegisterCount + 1; }
@Override public int getParameterRegisterCount() { return parameterRegisterCount; }
@Override public int getRegisterFixedC() { return registerClosure; }
@Override public int getRegisterParameterD() { return registerD; }
@Override public int getRegisterParameterE() { return registerE; }
@Override public int getRegisterParameterF() { return registerF; }
@Override public int getRegisterParameterG() { return registerG; }
@Override public Format getFormat() { return FORMAT; }
}
@@ -115,8 +115,6 @@ private static DexBackedInstruction buildInstruction(@Nonnull DexBackedDexFile d
return new DexBackedInstruction22x(dexFile, opcode, instructionStartOffset);
case Format23x:
return new DexBackedInstruction23x(dexFile, opcode, instructionStartOffset);
case Format25x:
return new DexBackedInstruction25x(dexFile, opcode, instructionStartOffset);
case Format30t:
return new DexBackedInstruction30t(dexFile, opcode, instructionStartOffset);
case Format31c:
@@ -1,83 +0,0 @@
/*
* Copyright 2015, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.dexbacked.instruction;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.dexbacked.DexBackedDexFile;
import org.jf.dexlib2.iface.instruction.formats.Instruction25x;
import org.jf.util.NibbleUtils;
import javax.annotation.Nonnull;
public class DexBackedInstruction25x extends DexBackedInstruction implements Instruction25x {
public DexBackedInstruction25x(@Nonnull DexBackedDexFile dexFile,
@Nonnull Opcode opcode,
int instructionStart) {
super(dexFile, opcode, instructionStart);
}
@Override
public int getRegisterCount() {
return getParameterRegisterCount() + 1;
}
@Override
public int getParameterRegisterCount() {
return NibbleUtils.extractHighUnsignedNibble(dexFile.readUbyte(instructionStart + 1));
}
@Override
public int getRegisterFixedC() {
return NibbleUtils.extractLowUnsignedNibble(dexFile.readUbyte(instructionStart + 2));
}
@Override
public int getRegisterParameterD() {
return NibbleUtils.extractHighUnsignedNibble(dexFile.readUbyte(instructionStart + 2));
}
@Override
public int getRegisterParameterE() {
return NibbleUtils.extractLowUnsignedNibble(dexFile.readUbyte(instructionStart + 3));
}
@Override
public int getRegisterParameterF() {
return NibbleUtils.extractHighUnsignedNibble(dexFile.readUbyte(instructionStart + 3));
}
@Override
public int getRegisterParameterG() {
return NibbleUtils.extractLowUnsignedNibble(dexFile.readUbyte(instructionStart + 1));
}
}
@@ -129,9 +129,6 @@ public void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable S
case Format10x:
annotateInstruction10x(out, instruction);
break;
case Format25x:
annotateInstruction25x(out, (Instruction25x) instruction);
break;
case Format35c:
annotateInstruction35c(out, (Instruction35c)instruction);
break;
@@ -285,30 +282,6 @@ private void annotateInstruction35c(@Nonnull AnnotatedBytes out, @Nonnull Instru
instruction.getOpcode().name, Joiner.on(", ").join(args), reference));
}
private void annotateInstruction25x(@Nonnull AnnotatedBytes out,
@Nonnull Instruction25x instruction) {
List<String> args = Lists.newArrayList();
int registerCount = instruction.getRegisterCount(); //at least 1.
if (registerCount == 2) {
args.add(formatRegister(instruction.getRegisterParameterD()));
} else if (registerCount == 3) {
args.add(formatRegister(instruction.getRegisterParameterD()));
args.add(formatRegister(instruction.getRegisterParameterE()));
} else if (registerCount == 4) {
args.add(formatRegister(instruction.getRegisterParameterD()));
args.add(formatRegister(instruction.getRegisterParameterE()));
args.add(formatRegister(instruction.getRegisterParameterF()));
} else if (registerCount == 5) {
args.add(formatRegister(instruction.getRegisterParameterD()));
args.add(formatRegister(instruction.getRegisterParameterE()));
args.add(formatRegister(instruction.getRegisterParameterF()));
args.add(formatRegister(instruction.getRegisterParameterG()));
}
out.annotate(6, String.format("%s %s, {%s}",
instruction.getOpcode().name, instruction.getRegisterFixedC(), Joiner.on(", ").join(args)));
}
private void annotateInstruction3rc(@Nonnull AnnotatedBytes out, @Nonnull Instruction3rc instruction) {
int startRegister = instruction.getStartRegister();
int endRegister = startRegister + instruction.getRegisterCount() - 1;
Oops, something went wrong.

0 comments on commit 99b80bb

Please sign in to comment.