harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjanu...@apache.org
Subject svn commit: r775082 - in /harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200: BcBands.java Segment.java
Date Fri, 15 May 2009 10:50:41 GMT
Author: sjanuary
Date: Fri May 15 10:50:40 2009
New Revision: 775082

URL: http://svn.apache.org/viewvc?rev=775082&view=rev
Log:
Pack200 - complete implementation of BcBands

Modified:
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java?rev=775082&r1=775081&r2=775082&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java
Fri May 15 10:50:40 2009
@@ -58,10 +58,12 @@
     private List bcThisField = new ArrayList();
     private final List bcSuperField = new ArrayList();
     private List bcThisMethod = new ArrayList();
-    private final List bcSuperMethod = new ArrayList();
-    private final List bcInitRef = new ArrayList();
+    private List bcSuperMethod = new ArrayList();
+    private List bcInitRef = new ArrayList();
 
     private String currentClass;
+    private String superClass;
+    private String currentNewClass;
 
     private static final int MULTIANEWARRAY = 197;
     private static final int ALOAD_0 = 42;
@@ -78,13 +80,16 @@
     private int renumberedOffset;
     private final IntList bcLabelRelativeOffsets = new IntList();
 
-    public void setCurrentClass(String name) {
+    public void setCurrentClass(String name, String superName) {
         currentClass = name;
+        superClass = superName;
     }
 
     public void finaliseBands() {
         bcThisField = getIndexInClass(bcThisField);
         bcThisMethod = getIndexInClass(bcThisMethod);
+        bcSuperMethod = getIndexInClass(bcSuperMethod);
+        bcInitRef = getIndexInClassForConstructor(bcInitRef);
     }
 
     public void pack(OutputStream out) throws IOException, Pack200Exception {
@@ -144,6 +149,15 @@
         return indices;
     }
 
+    private List getIndexInClassForConstructor(List cPMethodList) {
+        List indices = new ArrayList(cPMethodList.size());
+        for (int i = 0; i < cPMethodList.size(); i++) {
+            CPMethodOrField cpMF = (CPMethodOrField) cPMethodList.get(i);
+            indices.add(new Integer(cpMF.getIndexInClassForConstructor()));
+        }
+        return indices;
+    }
+
     public void visitEnd() {
         for (int i = 0; i < bciRenumbering.size(); i++) {
             if (bciRenumbering.get(i) == -1) {
@@ -351,23 +365,25 @@
                 aload_0 = true;
                 opcode += 7;
             }
-
-//            if (opcode == 183 && name.equals("<init>") && !aload_0
-//                    && owner.equals(currentClass)) {
-//                opcode = 230;
-//            } else if (opcode == 183 && name.equals("<init>") &&
!aload_0
-//                    && owner.equals(superClass)) {
-//                opcode = 231;
-//                // TODO: 232
-//            } else
             if (owner.equals(currentClass)) {
                 opcode += 24; // change to invokevirtual_this,
                 // invokespecial_this etc.
-                bcThisMethod.add(cpBands.getCPMethod(owner, name, desc));
-//            } else if (owner.equals(superClass)) { // TODO
-//                opcode += 38; // change to invokevirtual_super,
-//                // invokespecial_super etc.
-//                bcSuperMethod.add(cpBands.getCPMethod(owner, name, desc));
+
+                if(name.equals("<init>") && opcode == 207) {
+                    opcode = 230; // invokespecial_this_init
+                    bcInitRef.add(cpBands.getCPMethod(owner, name, desc));
+                } else {
+                    bcThisMethod.add(cpBands.getCPMethod(owner, name, desc));
+                }
+            } else if (owner.equals(superClass)) { // TODO
+                opcode += 38; // change to invokevirtual_super,
+                // invokespecial_super etc.
+                if(name.equals("<init>") && opcode == 221) {
+                    opcode = 231; // invokespecial_super_init
+                    bcInitRef.add(cpBands.getCPMethod(owner, name, desc));
+                } else {
+                    bcSuperMethod.add(cpBands.getCPMethod(owner, name, desc));
+                }
             } else {
                 if (aload_0) {
                     opcode -= 7;
@@ -376,7 +392,12 @@
                     // special rewrite in this
                     // case.
                 }
-                bcMethodRef.add(cpBands.getCPMethod(owner, name, desc));
+                if(name.equals("<init>") && opcode == 183 && owner.equals(currentNewClass))
{
+                    opcode = 232; // invokespecial_new_init
+                    bcInitRef.add(cpBands.getCPMethod(owner, name, desc));
+                } else {
+                    bcMethodRef.add(cpBands.getCPMethod(owner, name, desc));
+                }
             }
             bcCodes.add(opcode);
             break;
@@ -419,6 +440,9 @@
         updateRenumbering();
         bcCodes.add(opcode);
         bcClassRef.add(cpBands.getCPClass(type));
+        if(opcode == 187) { // NEW
+            currentNewClass = type;
+        }
     }
 
     public void visitVarInsn(int opcode, int var) {

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java?rev=775082&r1=775081&r2=775082&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java
Fri May 15 10:50:40 2009
@@ -95,7 +95,7 @@
 
     public void visit(int version, int access, String name, String signature,
             String superName, String[] interfaces) {
-        bcBands.setCurrentClass(name);
+        bcBands.setCurrentClass(name, superName);
         segmentHeader.addMajorVersion(version);
         classBands.addClass(version, access, name, signature, superName,
                 interfaces);



Mime
View raw message