commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kohs...@apache.org
Subject svn commit: r359670 - /jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/bcel/BcelClassTransformer.java
Date Thu, 29 Dec 2005 01:03:27 GMT
Author: kohsuke
Date: Wed Dec 28 17:03:25 2005
New Revision: 359670

URL: http://svn.apache.org/viewcvs?rev=359670&view=rev
Log:
fixed another instrumentation issue in a rather ad-hoc way.
A proper fix would require more sophisticated stack analysis.
for now just do a simple pattern-match to find what javac often produces.
-----
                        // if there are any dup_x2 following new and dup, replace them with
dup.
                        // some java compiler generates such bytecode for code like
                        //  someObject.someStringField += "abc"
                        //
                        // which yield
                        //   NEW StringBuffer
                        //   DUP
                        //   ALOAD  // someObject
                        //   DUP_x2
                        //   GETFIELD someStringField
                        //   INVOKESPECIAL StringBuffer.<init>
                        //   LDC "abc"
                        //   INVOKEVIRTUAL StringBuffer.append
                        //   INVOKEVIRTUAL StringBuffer.toString
                        //   PUTFIELD someStringField
                        //
                        // replacing this DUP_x2 -> DUP is required for moving the new.

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=359670&r1=359669&r2=359670&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 17:03:25 2005
@@ -438,6 +438,30 @@
                             insList.delete(next);
                             next = newnext;
                         }
+                        // if there are any dup_x2 following new and dup, replace them with
dup.
+                        // some java compiler generates such bytecode for code like
+                        //  someObject.someStringField += "abc"
+                        //
+                        // which yield
+                        //   NEW StringBuffer
+                        //   DUP
+                        //   ALOAD  // someObject
+                        //   DUP_x2
+                        //   GETFIELD someStringField
+                        //   INVOKESPECIAL StringBuffer.<init>
+                        //   LDC "abc"
+                        //   INVOKEVIRTUAL StringBuffer.append
+                        //   INVOKEVIRTUAL StringBuffer.toString
+                        //   PUTFIELD someStringField
+                        //
+                        // replacing this DUP_x2 -> DUP is required for moving the new.
+                        if(next!=null && next.getNext()!=null && next.getNext().getInstruction().getOpcode()
== Constants.DUP_X2) {
+                            InstructionHandle dupx2ptr = next.getNext();
+                            final InstructionHandle newnext = dupx2ptr.getNext();
+                            insList.insert(dupx2ptr, InstructionConstants.DUP);
+                            insList.delete(dupx2ptr);
+                            next = newnext;
+                        }
                         final InstructionTargeter[] targeter = ins.getTargeters();
                         if (targeter != null) {
                             final InstructionHandle newnext = ins.getNext();



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


Mime
View raw message