From: ehilsdal Date: Tue, 14 Jan 2003 20:02:43 +0000 (+0000) Subject: Fix for bug 28919: relaxing guard to allow native methods w/ no code X-Git-Tag: V_1_1_b5~115 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=27817202657a92778479de5063097086b511385b;p=aspectj.git Fix for bug 28919: relaxing guard to allow native methods w/ no code --- diff --git a/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java b/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java index 47435a904..5b4ef7d9d 100644 --- a/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java +++ b/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java @@ -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);