From: chiba Date: Mon, 6 Oct 2003 14:39:17 +0000 (+0000) Subject: improved the compilation of static method calls. X-Git-Tag: rel_3_17_1_ga~559 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b730655d0d439dee1f7d0ca1ecf9750bee12739d;p=javassist.git improved the compilation of static method calls. git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@49 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- diff --git a/src/main/javassist/compiler/MemberCodeGen.java b/src/main/javassist/compiler/MemberCodeGen.java index 3438671d..c97855f3 100644 --- a/src/main/javassist/compiler/MemberCodeGen.java +++ b/src/main/javassist/compiler/MemberCodeGen.java @@ -122,7 +122,7 @@ public class MemberCodeGen extends CodeGen { bytecode.addNew(cname); bytecode.addOpcode(DUP); - atMethodCall2(clazz, MethodInfo.nameInit, args, false, true); + atMethodCall2(clazz, MethodInfo.nameInit, args, false, true, -1); exprType = CLASS; arrayDim = 0; @@ -227,14 +227,17 @@ public class MemberCodeGen extends CodeGen { ASTList args = (ASTList)expr.oprand2(); boolean isStatic = false; boolean isSpecial = false; + int aload0pos = -1; if (method instanceof Member) { mname = ((Member)method).get(); targetClass = thisClass; if (inStaticMethod) isStatic = true; // should be static - else + else { + aload0pos = bytecode.currentPc(); bytecode.addAload(0); // this + } } else if (method instanceof Keyword) { // constructor isSpecial = true; @@ -289,7 +292,8 @@ public class MemberCodeGen extends CodeGen { else fatal(); - atMethodCall2(targetClass, mname, args, isStatic, isSpecial); + atMethodCall2(targetClass, mname, args, isStatic, isSpecial, + aload0pos); } private static void badMethod() throws CompileError { @@ -307,7 +311,8 @@ public class MemberCodeGen extends CodeGen { } public void atMethodCall2(CtClass targetClass, String mname, - ASTList args, boolean isStatic, boolean isSpecial) + ASTList args, boolean isStatic, boolean isSpecial, + int aload0pos) throws CompileError { int nargs = atMethodArgsLength(args); @@ -355,10 +360,15 @@ public class MemberCodeGen extends CodeGen { if ((acc & AccessFlag.STATIC) != 0) { if (!isStatic) { /* this method is static but the target object is - on stack. It must be popped out. + on stack. It must be popped out. If aload0pos >= 0, + then the target object was pushed by aload_0. It is + overwritten by NOP. */ isStatic = true; - popTarget = true; + if (aload0pos >= 0) + bytecode.write(aload0pos, NOP); + else + popTarget = true; } bytecode.addInvokestatic(declClass, mname, desc); diff --git a/src/main/javassist/expr/NewExpr.java b/src/main/javassist/expr/NewExpr.java index 2452b95c..423a5d72 100644 --- a/src/main/javassist/expr/NewExpr.java +++ b/src/main/javassist/expr/NewExpr.java @@ -206,7 +206,7 @@ public class NewExpr extends Expr { bytecode.addIndex(newIndex); bytecode.addOpcode(DUP); gen.atMethodCall2(newType, MethodInfo.nameInit, - args, false, true); + args, false, true, -1); gen.setType(newType); } }