public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute) {
    // Set up the code attribute editor.
    codeAttributeEditor.reset(codeAttribute.u4codeLength);

    // Find the peephole changes.
    codeAttribute.instructionsAccept(clazz, method, instructionSequenceReplacer);

    // Apply the peephole changes.
    codeAttributeEditor.visitCodeAttribute(clazz, method, codeAttribute);
  }
  /** Appends the specified subroutine. */
  private void inlineSubroutine(
      Clazz clazz,
      Method method,
      CodeAttribute codeAttribute,
      int subroutineInvocationOffset,
      int subroutineStart) {
    int subroutineEnd = branchTargetFinder.subroutineEnd(subroutineStart);

    if (DEBUG) {
      System.out.println(
          "  Inlining subroutine ["
              + subroutineStart
              + " -> "
              + subroutineEnd
              + "] at ["
              + subroutineInvocationOffset
              + "]");
    }

    // Don't go inlining exceptions that are already applicable to this
    // subroutine invocation.
    ExceptionInfoVisitor oldSubroutineExceptionInliner = subroutineExceptionInliner;
    int oldClipStart = clipStart;
    int oldClipEnd = clipEnd;

    subroutineExceptionInliner =
        new ExceptionExcludedOffsetFilter(subroutineInvocationOffset, subroutineExceptionInliner);
    clipStart = subroutineStart;
    clipEnd = subroutineEnd;

    codeAttributeComposer.beginCodeFragment(codeAttribute.u4codeLength);

    // Copy the subroutine instructions, inlining any subroutine calls
    // recursively.
    codeAttribute.instructionsAccept(clazz, method, subroutineStart, subroutineEnd, this);

    if (DEBUG) {
      System.out.println("    Appending label after inlined subroutine at [" + subroutineEnd + "]");
    }

    // Append a label just after the code.
    codeAttributeComposer.appendLabel(subroutineEnd);

    // Inline the subroutine exceptions.
    codeAttribute.exceptionsAccept(
        clazz, method, subroutineStart, subroutineEnd, subroutineExceptionInliner);

    // We can again inline exceptions that are applicable to this
    // subroutine invocation.
    subroutineExceptionInliner = oldSubroutineExceptionInliner;
    clipStart = oldClipStart;
    clipEnd = oldClipEnd;

    codeAttributeComposer.endCodeFragment();
  }
Beispiel #3
0
  public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute) {
    markAsUsed(codeAttribute);

    markConstant(clazz, codeAttribute.u2attributeNameIndex);

    // Mark the constant pool entries referenced by the instructions,
    // by the exceptions, and by the attributes.
    codeAttribute.instructionsAccept(clazz, method, this);
    codeAttribute.exceptionsAccept(clazz, method, this);
    codeAttribute.attributesAccept(clazz, method, this);
  }