]> source.dussan.org Git - aspectj.git/commitdiff
Fix for bug 28919: relaxing guard to allow native methods w/ no code
authorehilsdal <ehilsdal>
Tue, 14 Jan 2003 20:02:43 +0000 (20:02 +0000)
committerehilsdal <ehilsdal>
Tue, 14 Jan 2003 20:02:43 +0000 (20:02 +0000)
weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java

index 47435a9048e4a43214de2a9ecf1f2f410ce09c3c..5b4ef7d9d093a9009a72a253e033f1a666893f17 100644 (file)
@@ -100,7 +100,7 @@ public final class LazyMethodGen {
     // build from an existing method
     public LazyMethodGen(Method m, LazyClassGen enclosingClass) {
         this.enclosingClass = enclosingClass;
-        if (!m.isAbstract() && m.getCode() == null) {
+        if (!(m.isAbstract() || m.isNative()) && m.getCode() == null) {
                throw new RuntimeException("bad non-abstract method with no code: " + m + " on " + enclosingClass);
         }
         MethodGen gen = new MethodGen(m, enclosingClass.getName(), enclosingClass.getConstantPoolGen());
@@ -348,6 +348,7 @@ public final class LazyMethodGen {
         }
 
         void run() {
+               killNops();
             assignLabels();
             print();
         }
@@ -407,6 +408,7 @@ public final class LazyMethodGen {
                                for (InstructionHandle xx = r.getStart(); Range.isRangeHandle(xx); xx = xx.getNext()) {
                                         if (xx == r.getEnd()) continue bodyPrint;
                                }
+
                     // doesn't handle nested: if (r.getStart().getNext() == r.getEnd()) continue;
                     if (r.getStart() == ih) {
                         printRangeString(r, depth++);
@@ -634,6 +636,7 @@ public final class LazyMethodGen {
     // ---- packing!
     
     public MethodGen pack() {
+       //killNops();
         MethodGen gen =
             new MethodGen(
                 getAccessFlags(),
@@ -667,7 +670,7 @@ public final class LazyMethodGen {
         
         /* Make copies of all instructions, append them to the new list
          * and associate old instruction references with the new ones, i.e.,
-         * a 1:1 mapping.  
+         * a 1:1 mapping.
          */
         for (InstructionHandle ih = getBody().getStart(); ih != null; ih = ih.getNext()) {
             if (Range.isRangeHandle(ih)) {
@@ -804,8 +807,32 @@ public final class LazyMethodGen {
                 (InstructionHandle) localVariableStarts.get(tag),
                 (InstructionHandle) localVariableEnds.get(tag));
         }
+
     }
 
+
+       public void killNops() {
+       InstructionHandle curr = body.getStart();
+       while (true) {
+                       if (curr == null) break;
+                       InstructionHandle next = curr.getNext();
+               if (curr.getInstruction() instanceof NOP) {
+                       InstructionTargeter[] targeters = curr.getTargeters();
+                       if (targeters != null) {
+                               for (int i = 0, len = targeters.length; i < len; i++) {
+                                               InstructionTargeter targeter = targeters[i];
+                                               targeter.updateTarget(curr, next);
+                               }
+                       }
+                               try {
+                                       body.delete(curr);
+                               } catch (TargetLostException e) {
+                               }
+               }
+                       curr = next;
+       }
+       }
+
     private static InstructionHandle remap(InstructionHandle ih, Map map) {
         while (true) {
             Object ret = map.get(ih);