且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是什么原因导致了Android的Dalvik java.lang.VerifyError"无效寄存器类型数组索引"?

更新时间:2022-03-25 07:43:26

我找不到在构建工具,浮出水面的问题,具体的变化,但在看的的答案,不同的Dalvik问题,我想通了错误。

I can't find the specific change in the build tools that surfaced the problem, but after looking at the answer to a different Dalvik problem, I figured out the error.

Dalvik的拒绝 Ed25519FieldElement.multiply() ,因为它包含155局部变量。这种方法是由相应的C code直接移植,并没有很好地转化为Java字节code。这似乎与19.1.0和21.0 +,编译器在编译工具是在某种程度上改变了prevents的Dalvik从处理这么多的局部变量。

Dalvik rejects Ed25519FieldElement.multiply() because it contains 155 local variables. This method was directly ported from corresponding C code, and does not translate well into Java bytecode. It would seem that between 19.1.0 and 21.0.+, the compiler in the build tools was changed in a way that prevents Dalvik from handling this many local variables.

最后的后该页面提供了一些额外的观点:

The last post on this page provides some additional insight:

是的,在Dalvik编译器试图分配一个注册到每一个   在该方法的局部变量。它应该能够处理很多,   但显然不能。通过使它们的实例变量删除   编译器的需求/欲望管理他们(也使该方法   一个相当小)。

Yep, the Dalvik compiler attempts to assign a "register" to every local variable in the method. It should be able to handle that many, but apparently can't. By making them instance variables you remove the compiler's need/desire to "manage" them (and also make the method a fair amount smaller).

我的解决办法是消除不必要的20变量(无操作任务如 G0 = G [0] ),并直接使用,而不是阵列。这确实会增加将来的错误蔓延到了code(如果数组索引中的一个意外改变)的可能性,但降低了局部变量的数量,以135解决了运行时类排斥反应。

My solution was to remove twenty unnecessary variables (the no-op assignments like g0 = g[0]), and instead using the arrays directly. This does increase the likelihood of a future bug creeping into the code (if one of the array indices is changed accidentally), but reducing the number of local variables to 135 resolved the runtime class rejection.

的正确的解决方案是重构方法完全以减少其长度。这必须格外小心,以避免导入侧信道攻击向量的。

The "correct" solution would be to refactor the method entirely to reduce its length. This must be done with care, to avoid introducing side-channel attack vectors.