java判断栈中元素数目,尝试检测java字节码时,堆栈中的参数数量错误

看起来第一个屏幕截图上的代码从根本上被打破了. JVM字节码中的对象构造可以分为两个阶段:在堆上分配内存并针对分配的内存调用构造函数(带有可选参数):

new #1 //allocate memory

dup //duplicate to not loose the object after calling constructor

//push c-tor args onto the stack here

invokespecial > //constructor, second `this` is lost

areturn //returns first `this`

你基本上做的是:在堆上分配一些原始(可能是零)内存并对该内存块调用虚方法Fraction_congu.你还没有调用构造函数!

还应该有invokevirtual,我猜这个生成的方法是私有的.

更新:我假设您要转换以下类:

class Fraction {

public Fraction(float den, float num) {

//original constructor code here

}

public int m() {

return 1;

}

}

成:

class Fraction {

public Fraction(float den, float num) {

//proxy method

//place for extra logic

Fraction_CONGU(den, num);

}

private Fraction_CONGU(float den, float num) {

//original constructor code here

}

public int m() {

//proxy method

//place for extra logic

return m_CONGU

}

private int m_CONGU() {

return 1;

}

}

如你所见,这是完全可能的(如果我的想法正确).只需编译此Java代码,看看编译器如何实现它.

这引出了一个问题:你不能只使用AspectJ进行编译时编织吗?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值