Parcourir la source

Merge pull request #448 from catsalty/patch-2

Fix issue in no-standard [new] instruction replace
tags/rel_3_30_0_ga
Shigeru Chiba il y a 5 mois
Parent
révision
cbb59bda5d
Aucun compte lié à l'adresse e-mail de l'auteur
1 fichiers modifiés avec 14 ajouts et 1 suppressions
  1. 14
    1
      src/main/javassist/expr/NewExpr.java

+ 14
- 1
src/main/javassist/expr/NewExpr.java Voir le fichier

@@ -193,6 +193,14 @@ public class NewExpr extends Expr {
*/
int codeSize = canReplace();
int end = pos + codeSize;
//check isStoreBeforeInit ,such as : new xx/xx ; dup;[astoreN];invokespecial xx/xx;
int beforeStoreOp = 0;
int preOp = iterator.byteAt(currentPos - 1);
if (iterator.byteAt(newPos + 3) == Opcode.DUP
&& (preOp >= Opcode.ASTORE_0
&& preOp <= Opcode.ASTORE_3) && currentPos - newPos == 5) {
beforeStoreOp = preOp;
}
for (int i = pos; i < end; ++i)
iterator.writeByte(NOP, i);

@@ -230,7 +238,12 @@ public class NewExpr extends Expr {
if (codeSize > 3) // if the original code includes DUP.
bytecode.addAload(retVar);

replace0(pos, bytecode, bytecodeSize);
if (beforeStoreOp >= Opcode.ASTORE_0) {
bytecode.addOpcode(beforeStoreOp);
replace0(pos - 1, bytecode, bytecodeSize + 1);
} else {
replace0(pos, bytecode, bytecodeSize);
}
}
catch (CompileError e) { throw new CannotCompileException(e); }
catch (NotFoundException e) { throw new CannotCompileException(e); }

Chargement…
Annuler
Enregistrer