]> source.dussan.org Git - aspectj.git/commitdiff
big refactoring
authoraclement <aclement>
Fri, 9 May 2008 21:42:50 +0000 (21:42 +0000)
committeraclement <aclement>
Fri, 9 May 2008 21:42:50 +0000 (21:42 +0000)
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java

index a823da0d839c91b7cf461415d1a967714c5ef115..ffc6a000efe6932581cd1d41292c788f00905bd4 100644 (file)
@@ -2445,6 +2445,52 @@ class BcelClassWeaver implements IClassWeaver {
                List shadowAccumulator) 
        {
                Instruction i = ih.getInstruction();
+        
+        // Exception handlers (pr230817)
+        if (canMatch(Shadow.ExceptionHandler) && !Range.isRangeHandle(ih)) {
+            InstructionTargeter[] targeters = ih.getTargeters();
+            if (targeters != null) {
+                for (int j = 0; j < targeters.length; j++) {
+                    InstructionTargeter t = targeters[j];
+                    if (t instanceof ExceptionRange) {
+                        // assert t.getHandler() == ih
+                        ExceptionRange er = (ExceptionRange) t;
+                        if (er.getCatchType() == null) continue;
+                        if (isInitFailureHandler(ih)) return;
+                        
+                        if (!ih.getInstruction().isStoreInstruction() && ih.getInstruction().getOpcode()!=Constants.NOP) {
+                            // If using cobertura, the catch block stats with INVOKESTATIC rather than ASTORE, in order that the ranges 
+                            // for the methodcall and exceptionhandler shadows that occur at this same 
+                            // line, we need to modify the instruction list to split them - adding a 
+                            // NOP before the invokestatic that gets all the targeters
+                            // that were aimed at the INVOKESTATIC
+                            mg.getBody().insert(ih,InstructionConstants.NOP);
+                            InstructionHandle newNOP = ih.getPrev();
+                            // what about a try..catch that starts at the start of the exception handler? need to only include certain targeters really.
+                            er.updateTarget(ih, newNOP,mg.getBody());
+                            for (int ii=0;ii<targeters.length;ii++) {
+                                newNOP.addTargeter(targeters[ii]);
+                            }
+                            ih.removeAllTargeters();
+                            match(
+                                BcelShadow.makeExceptionHandler(
+                                    world, 
+                                    er,
+                                    mg, newNOP, enclosingShadow),
+                                shadowAccumulator);
+                        } else {                    
+                            match(
+                                BcelShadow.makeExceptionHandler(
+                                    world, 
+                                    er,
+                                    mg, ih, enclosingShadow),
+                                shadowAccumulator);
+                        }
+                    }
+                }
+            }
+        }
+        
                if ((i instanceof FieldInstruction) && 
                        (canMatch(Shadow.FieldGet) || canMatch(Shadow.FieldSet))
                ) {
@@ -2539,31 +2585,8 @@ class BcelClassWeaver implements IClassWeaver {
                          }
                        // }
                }
-               // performance optimization... we only actually care about ASTORE instructions, 
-               // since that's what every javac type thing ever uses to start a handler, but for
-               // now we'll do this for everybody.
-               if (!canMatch(Shadow.ExceptionHandler)) return;
-               if (Range.isRangeHandle(ih)) return;
-               InstructionTargeter[] targeters = ih.getTargeters();
-               if (targeters != null) {
-                       for (int j = 0; j < targeters.length; j++) {
-                               InstructionTargeter t = targeters[j];
-                               if (t instanceof ExceptionRange) {
-                                       // assert t.getHandler() == ih
-                                       ExceptionRange er = (ExceptionRange) t;
-                                       if (er.getCatchType() == null) continue;
-                                       if (isInitFailureHandler(ih)) return;
                                        
-                                       match(
-                                               BcelShadow.makeExceptionHandler(
-                                                       world, 
-                                                       er,
-                                                       mg, ih, enclosingShadow),
-                                               shadowAccumulator);
-                               }
-                       }
                }
-       }
 
        private boolean isInitFailureHandler(InstructionHandle ih) {
                // Skip the astore_0 and aload_0 at the start of the handler and