bytedance / ByteX

ByteX is a bytecode plugin platform based on Android Gradle Transform API and ASM. 字节码插件开发平台
Apache License 2.0
3.15k stars 463 forks source link

field_assign_opt 为何优化掉构造函数中对父类参数的赋值? #123

Open hesheng1024-p opened 3 years ago

hesheng1024-p commented 3 years ago

父类

public abstract class BaseRequest<T> {
    protected int mDataType = -1;

    public BaseRequest() {

    }
}

子类

public class InfoRequest extends BaseRequest<ArrayList<Info>> {

    public VipInfoRequest() {
        mDataType = 0;
    }

子类字节码

# direct methods
.method public constructor <init>()V
    .registers 1

    .line 20
    invoke-direct {p0}, Lcom/demo/BaseRequest;-><init>()V

    .line 22
    return-void
.end method

父类字节码

.field protected mVipDataType:I

# direct methods
.method public constructor <init>()V
    .registers 2

    .line 18
    const/4 v0, -0x1

    iput v0, p0, Lcom/demo/BaseRequest;->mDataType:I

    .line 20
    const-string v0, ""

    .line 32
    return-void
.end method

中间省略了不相干代码,主要就是在子类构造函数赋值对mDataType赋值时,被插件优化掉了

yangzhiqian commented 3 years ago

bug

popoaichuiniu commented 2 years ago

bug

请问这个插件已经在抖音上使用了嘛,

ldy441040480 commented 2 years ago

需要判断要优化的 FieldInsnNode 在当前classNode的 List fields中