You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ko...@apache.org on 2005/12/28 22:41:04 UTC

svn commit: r359644 - /jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/bcel/BcelClassTransformer.java

Author: kohsuke
Date: Wed Dec 28 13:41:03 2005
New Revision: 359644

URL: http://svn.apache.org/viewcvs?rev=359644&view=rev
Log:
L-value of a method invocation may be an array.

Modified:
    jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/bcel/BcelClassTransformer.java

Modified: jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/bcel/BcelClassTransformer.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/bcel/BcelClassTransformer.java?rev=359644&r1=359643&r2=359644&view=diff
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/bcel/BcelClassTransformer.java (original)
+++ jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/bcel/BcelClassTransformer.java Wed Dec 28 13:41:03 2005
@@ -420,9 +420,9 @@
                     // determine type of object for the method invocation
                     final InvokeInstruction invoke = (InvokeInstruction) ins.getInstruction();
                     final Type[] arguments = invoke.getArgumentTypes(method.getConstantPool());
-                    ObjectType objecttype = null;
+                    ReferenceType objecttype = null;
                     if (!(invoke instanceof INVOKESTATIC)) {
-                        objecttype = (ObjectType) context.getInFrame().getStack().peek(arguments.length);
+                        objecttype = (ReferenceType) context.getInFrame().getStack().peek(arguments.length);
                     }
                     final InstructionList rList = restoreFrame(method, ins, insFactory, frame, objecttype);
                     insList.append(ins, saveFrame(method, ins, count++, insFactory, frame));
@@ -435,7 +435,7 @@
                         // remove additional dup's
                         while (next != null && next.getInstruction().getOpcode() == Constants.DUP) {
                             context = cfg.contextOf(next);
-                            frame = context.getOutFrame(new ArrayList());
+                            context.getOutFrame(new ArrayList());
                             final InstructionHandle newnext = next.getNext();
                             insList.delete(next);
                             next = newnext;
@@ -578,26 +578,26 @@
     private boolean rewriteable(MethodGen method, InstructionHandle handle) {
         // check in the invocation can be a breakpoint.
         int opcode = handle.getInstruction().getOpcode();
-        boolean invokeSpecialSuper = false;
+
+        if(!(handle.getInstruction() instanceof InvokeInstruction))
+            return false;   // not an INVOKE***
+
         if (opcode == Constants.INVOKESPECIAL) {
             final InvokeInstruction ivs = (InvokeInstruction) handle.getInstruction();
             final String mName = ivs.getMethodName(method.getConstantPool());
-            invokeSpecialSuper = !mName.equals(Constants.CONSTRUCTOR_NAME);
+            if(mName.equals(Constants.CONSTRUCTOR_NAME))
+                return false;   // can't instrument the constructor invocation
         }
 
-        if (opcode == Constants.INVOKEVIRTUAL || opcode == Constants.INVOKESTATIC || opcode == Constants.INVOKEINTERFACE || invokeSpecialSuper) {
-
-            // final int index = ((InvokeInstruction) handle.getInstruction()).getIndex();
-            // final String classname = getObjectType(method.getConstantPool().getConstantPool(), index).getClassName();
+        // final int index = ((InvokeInstruction) handle.getInstruction()).getIndex();
+        // final String classname = getObjectType(method.getConstantPool().getConstantPool(), index).getClassName();
 
-            // rewrite invocation if object is continuable or a continuation
-            // object
+        // rewrite invocation if object is continuable or a continuation
+        // object
 
-            // FIXME:
-            //return Repository.implementationOf(classname, CONTINUABLE_CLASS) || Repository.instanceOf(classname, CONTINUATION_CLASS);
-            return true;
-        }
-        return false;
+        // FIXME:
+        //return Repository.implementationOf(classname, CONTINUABLE_CLASS) || Repository.instanceOf(classname, CONTINUATION_CLASS);
+        return true;
     }
 
     private InstructionList saveFrame(MethodGen method, InstructionHandle handle, int pc, InstructionFactory insFactory, Frame frame) {
@@ -712,7 +712,7 @@
         return insList;
     }
 
-    private InstructionList restoreFrame(MethodGen method, InstructionHandle handle, InstructionFactory insFactory, Frame frame, ObjectType objecttype) {
+    private InstructionList restoreFrame(MethodGen method, InstructionHandle handle, InstructionFactory insFactory, Frame frame, ReferenceType objecttype) {
         final InstructionList insList = new InstructionList();
         // restore local variables
         //if (debug) {
@@ -799,12 +799,6 @@
         // go to last invocation
         insList.append(new GOTO(handle));
         return insList;
-    }
-
-    private ObjectType getObjectType(ConstantPool cp, int index) {
-        final ConstantCP cmr = (ConstantCP) cp.getConstant(index);
-        final String sig = cp.getConstantString(cmr.getClassIndex(), Constants.CONSTANT_Class);
-        return new ObjectType(sig.replace('/', '.'));
     }
 
     private Type[] getParamTypes(ConstantPool cp, int index) {



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org