/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache BCEL" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache BCEL", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
*/
/**
* This class represents a chunk of Java byte code contained in a
* method. It is instantiated by the
* <em>Attribute.readAttribute()</em> method. A <em>Code</em>
* attribute contains informations about operand stack, local
* variables, byte code and the exceptions handled within this
* method.
*
* This attribute has attributes itself, namely <em>LineNumberTable</em> which
* is used for debugging purposes and <em>LocalVariableTable</em> which
* contains information about the local variables.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Attribute
* @see CodeException
* @see LineNumberTable
* @see LocalVariableTable
*/
private int exception_table_length;
/**
* Initialize from another object. Note that both objects use the same
* references (shallow copy). Use copy() for a physical copy.
*/
c.getConstantPool());
}
/**
* @param name_index Index pointing to the name <em>Code</em>
* @param length Content length in bytes
* @param file Input stream
* @param constant_pool Array of constants
*/
{
// Initialize with some default values which will be overwritten later
this(name_index, length,
/* Read exception table that contains all regions where an exception
* handler is active, i.e., a try { ... } catch() block.
*/
for(int i=0; i < exception_table_length; i++)
/* Read all attributes, currently `LineNumberTable' and
* `LocalVariableTable'
*/
for(int i=0; i < attributes_count; i++)
/* Adjust length, because of setAttributes in this(), s.b. length
* is incorrect, because it didn't take the internal attributes
* into account yet! Very subtle bug, fixed in 3.1.1.
*/
}
/**
* @param name_index Index pointing to the name <em>Code</em>
* @param length Content length in bytes
* @param max_stack Maximum size of stack
* @param max_locals Number of local variables
* @param code Actual byte code
* @param exception_table Table of handled exceptions
* @param attributes Attributes of code: LineNumber or LocalVariable
* @param constant_pool Array of constants
*/
int max_stack, int max_locals,
byte[] code,
{
this.max_locals = max_locals;
}
/**
* Called by objects that are traversing the nodes of the tree implicitely
* defined by the contents of a Java class. I.e., the hierarchy of methods,
* fields, attributes, etc. spawns a tree of objects.
*
* @param v Visitor object
*/
v.visitCode(this);
}
/**
* Dump code attribute to file stream in binary format.
*
* @param file Output file stream
* @throws IOException
*/
{
for(int i=0; i < exception_table_length; i++)
for(int i=0; i < attributes_count; i++)
}
/**
* @return Collection of code attributes.
* @see Attribute
*/
/**
* @return LineNumberTable of Code, if it has one
*/
for(int i=0; i < attributes_count; i++)
if(attributes[i] instanceof LineNumberTable)
return (LineNumberTable)attributes[i];
return null;
}
/**
* @return LocalVariableTable of Code, if it has one
*/
for(int i=0; i < attributes_count; i++)
if(attributes[i] instanceof LocalVariableTable)
return (LocalVariableTable)attributes[i];
return null;
}
/**
* @return Actual byte code of the method.
*/
/**
* @return Table of handled exceptions.
* @see CodeException
*/
/**
* @return Number of local variables.
*/
/**
* @return Maximum size of stack used by this method.
*/
/**
* @return the internal length of this code attribute (minus the first 6 bytes)
* and excluding all its attributes
*/
private final int getInternalLength() {
return 2 /*max_stack*/ + 2 /*max_locals*/ + 4 /*code length*/
+ code_length /*byte-code*/
+ 2 /*exception-table length*/
+ 2 /* attributes count */;
}
/**
* @return the full size of this code attribute, minus its first 6 bytes,
* including the size of all its contained attributes
*/
private final int calculateLength() {
int len = 0;
for(int i=0; i < attributes_count; i++)
return len + getInternalLength();
}
/**
* @param attributes.
*/
this.attributes = attributes;
}
/**
* @param code byte code
*/
}
/**
* @param exception_table exception table
*/
this.exception_table = exception_table;
}
/**
* @param max_locals maximum number of local variables
*/
this.max_locals = max_locals;
}
/**
* @param max_stack maximum stack size
*/
}
/**
* @return String representation of code chunk.
*/
", max_locals = " + max_locals +
if(exception_table_length > 0) {
for(int i=0; i < exception_table_length; i++)
}
if(attributes_count > 0) {
for(int i=0; i < attributes_count; i++)
}
}
/**
* @return String representation of code chunk.
*/
return toString(true);
}
/**
* @return deep copy of this attribute
*/
for(int i=0; i < exception_table_length; i++)
for(int i=0; i < attributes_count; i++)
return c;
}
}