public abstract class StackMapUtils extends Object
BCEL ought to automatically build and maintain the StackMapTable in a manner similar to the LineNumberTable and the LocalVariableTable. However, for historical reasons, it does not.
This class cannot be a set of static methods (like BcelUtil) as it maintains state
during the client's processing of a method that must be available on a per thread basis. Thus it
is an abstract class extended by InstructionListUtils. A client
would not normally extend this class directly.
| Modifier and Type | Field and Description |
|---|---|
protected SimpleLog |
debug_instrument
A log to which to print debugging information about program instrumentation.
|
protected int |
first_local_index
The index of the first 'true' local in the local variable table.
|
protected int |
initial_locals_count
The number of local variables in the current method prior to any modifications.
|
protected org.apache.bcel.classfile.StackMapType[] |
initial_type_list
Initial state of StackMapTypes for locals on method entry.
|
protected boolean |
needStackMap
Whether or not the current method needs a StackMap.
|
protected @NonNegative int |
number_active_locals
A number of methods in this class search and locate a particular StackMap within the current
method.
|
protected @Nullable org.apache.bcel.generic.ConstantPoolGen |
pool
The pool for the method currently being processed.
|
protected int |
running_offset
Offset into code that corresponds to the current StackMap of interest.
|
protected @Nullable org.apache.bcel.classfile.StackMap |
smta
Original stack map table attribute; set by set_current_stack_map_table.
|
protected org.apache.bcel.classfile.StackMapEntry[] |
stack_map_table
Working copy of StackMapTable; set by set_current_stack_map_table.
|
| Constructor and Description |
|---|
StackMapUtils() |
| Modifier and Type | Method and Description |
|---|---|
protected org.apache.bcel.generic.LocalVariableGen |
add_new_argument(org.apache.bcel.generic.MethodGen mgen,
String arg_name,
org.apache.bcel.generic.Type arg_type)
|
protected org.apache.bcel.generic.LocalVariableGen |
add_new_parameter(org.apache.bcel.generic.MethodGen mgen,
String arg_name,
org.apache.bcel.generic.Type arg_type)
Add a new parameter to the method.
|
protected String[] |
add_string(String[] arr,
String new_string)
Returns a String array with new_string added to the end of arr.
|
protected void |
adjust_code_for_locals_change(org.apache.bcel.generic.MethodGen mgen,
int index_first_moved_local,
int size)
Process the instruction list, adding size (1 or 2) to the index of each Instruction that
references a local that is equal or higher in the local map than index_first_moved_local.
|
protected StackTypes |
bcel_calc_stack_types(org.apache.bcel.generic.MethodGen mg)
Calculates the types on the stack for each instruction using the BCEL stack verification
routines.
|
protected void |
build_unitialized_NEW_map(org.apache.bcel.generic.InstructionList il)
We need to locate and remember any NEW instructions that create uninitialized objects.
|
protected org.apache.bcel.generic.LocalVariableGen |
create_method_scope_local(org.apache.bcel.generic.MethodGen mgen,
String local_name,
org.apache.bcel.generic.Type local_type)
Create a new local with a scope of the full method.
|
protected void |
create_new_stack_map_attribute(org.apache.bcel.generic.MethodGen mgen)
Create a new StackMap code attribute from stack_map_table.
|
protected void |
fetch_current_stack_map_table(org.apache.bcel.generic.MethodGen mgen,
int java_class_version)
|
protected org.apache.bcel.classfile.StackMapEntry |
find_stack_map_equal(int offset)
Find the StackMap entry whose offset matches the input argument.
|
protected @IndexOrLow(value="stack_map_table") int |
find_stack_map_index_after(int offset)
Find the index of the StackMap entry whose offset is the first one after the input argument.
|
protected int |
find_stack_map_index_before(int offset)
Find the index of the StackMap entry whose offset is the last one before the input argument.
|
protected void |
fix_local_variable_table(org.apache.bcel.generic.MethodGen mgen)
Under some circumstances, there may be problems with the local variable table.
|
protected int |
gen_temp_locals(org.apache.bcel.generic.MethodGen mgen,
int offset)
Find the live range of the compiler temp(s) at the given offset and create a LocalVariableGen
for each.
|
protected org.apache.bcel.classfile.StackMapType |
generate_StackMapType_from_Type(org.apache.bcel.generic.Type t)
Convert a Type to a StackMapType.
|
protected org.apache.bcel.generic.Type |
generate_Type_from_StackMapType(org.apache.bcel.classfile.StackMapType smt)
Convert a StackMapType to a Type.
|
protected String |
get_attribute_name(org.apache.bcel.classfile.Attribute a)
Return the attribute name for the specified attribute.
|
protected @Nullable org.apache.bcel.classfile.Attribute |
get_local_variable_type_table_attribute(org.apache.bcel.generic.MethodGen mgen)
Find the LocalVariableTypeTable attribute for a method.
|
protected @Nullable org.apache.bcel.classfile.Attribute |
get_stack_map_table_attribute(org.apache.bcel.generic.MethodGen mgen)
Find the StackMapTable attribute for a method.
|
protected int |
getSize(org.apache.bcel.classfile.StackMapType smt) |
protected boolean |
is_local_variable_type_table(org.apache.bcel.classfile.Attribute a)
Returns whether or not the specified attribute is a LocalVariableTypeTable.
|
protected boolean |
is_stack_map_table(org.apache.bcel.classfile.Attribute a)
Returns whether or not the specified attribute is a StackMapTable.
|
protected void |
modify_stack_maps_for_switches(org.apache.bcel.generic.InstructionHandle ih,
org.apache.bcel.generic.InstructionList il)
Check to see if (due to some instruction modifications) there have been any changes in a switch
statement's padding bytes.
|
protected void |
print_stack_map_table(String prefix)
Print the contents of the StackMapTable to the debug_instrument.log.
|
protected void |
remove_local_variable_type_table(org.apache.bcel.generic.MethodGen mgen)
Remove the local variable type table attribute (LVTT) from mgen.
|
protected void |
set_current_stack_map_table(org.apache.bcel.generic.MethodGen mgen,
int java_class_version)
Get existing StackMapTable from the MethodGen argument.
|
protected static @ClassGetName String |
typeToClassGetName(org.apache.bcel.generic.Type t)
Convert a Type name to a Class name.
|
protected void |
update_full_frame_stack_map_entries(int offset,
org.apache.bcel.generic.Type type_new_var,
org.apache.bcel.generic.LocalVariableGen[] locals)
Update any FULL_FRAME StackMap entries to include a new local var.
|
protected void |
update_stack_map_offset(int position,
int delta)
We have inserted additional byte(s) into the instruction list; update the StackMaps, if
required.
|
protected void |
update_uninitialized_NEW_offsets(org.apache.bcel.generic.InstructionList il)
Check to see if any of the uninitialized NEW instructions have moved.
|
protected @Nullable org.apache.bcel.generic.ConstantPoolGen pool
InstructionListUtils for when and how to set this value.protected SimpleLog debug_instrument
protected boolean needStackMap
protected org.apache.bcel.classfile.StackMapEntry[] stack_map_table
protected @Nullable org.apache.bcel.classfile.StackMap smta
protected org.apache.bcel.classfile.StackMapType[] initial_type_list
protected int initial_locals_count
protected @NonNegative int number_active_locals
protected int running_offset
protected int first_local_index
protected String[] add_string(String[] arr, String new_string)
arr - original string arraynew_string - string to be added@Pure protected final String get_attribute_name(org.apache.bcel.classfile.Attribute a)
a - the attribute@Pure protected final boolean is_local_variable_type_table(org.apache.bcel.classfile.Attribute a)
a - the attribute@Pure protected final boolean is_stack_map_table(org.apache.bcel.classfile.Attribute a)
a - the attribute@Pure protected final @Nullable org.apache.bcel.classfile.Attribute get_stack_map_table_attribute(org.apache.bcel.generic.MethodGen mgen)
mgen - the method@Pure protected final @Nullable org.apache.bcel.classfile.Attribute get_local_variable_type_table_attribute(org.apache.bcel.generic.MethodGen mgen)
mgen - the methodprotected final void remove_local_variable_type_table(org.apache.bcel.generic.MethodGen mgen)
mgen - the method to clear outprotected final void update_stack_map_offset(int position,
int delta)
position - the location of insertiondelta - the size of the insertionprotected final org.apache.bcel.classfile.StackMapEntry find_stack_map_equal(int offset)
offset - byte code offsetprotected final int find_stack_map_index_before(int offset)
offset - byte code offsetprotected final @IndexOrLow(value="stack_map_table") int find_stack_map_index_after(int offset)
offset - byte code offsetprotected final void modify_stack_maps_for_switches(org.apache.bcel.generic.InstructionHandle ih,
org.apache.bcel.generic.InstructionList il)
ih - where to start looking for a switch instructionil - instruction list to searchprotected final int gen_temp_locals(org.apache.bcel.generic.MethodGen mgen,
int offset)
mgen - the methodoffset - compiler assigned local offset of hidden tempprotected final void build_unitialized_NEW_map(org.apache.bcel.generic.InstructionList il)
il - instruction list to searchprotected final void update_uninitialized_NEW_offsets(org.apache.bcel.generic.InstructionList il)
il - instruction list to searchprotected final void adjust_code_for_locals_change(org.apache.bcel.generic.MethodGen mgen,
int index_first_moved_local,
int size)
mgen - MethodGen to be modifiedindex_first_moved_local - original index of first local moved "up"size - size of new local added (1 or 2)@Deprecated protected final void fetch_current_stack_map_table(org.apache.bcel.generic.MethodGen mgen, int java_class_version)
mgen - MethodGen to searchjava_class_version - Java version for the classfile; stack_map_table is optional before
Java 1.7 (= classfile version 51)@EnsuresNonNull(value="stack_map_table")
protected final void set_current_stack_map_table(org.apache.bcel.generic.MethodGen mgen,
int java_class_version)
mgen - MethodGen to searchjava_class_version - Java version for the classfile; stack_map_table is optional before
Java 1.7 (= classfile version 51)protected final void print_stack_map_table(String prefix)
prefix - label to display with tableprotected final void create_new_stack_map_attribute(org.apache.bcel.generic.MethodGen mgen)
throws IOException
mgen - MethodGen to add attribute toIOException - if cannot create the attributeprotected static @ClassGetName String typeToClassGetName(org.apache.bcel.generic.Type t)
t - type whose name is to be convertedprotected final org.apache.bcel.classfile.StackMapType generate_StackMapType_from_Type(org.apache.bcel.generic.Type t)
t - Type to be convertedprotected final org.apache.bcel.generic.Type generate_Type_from_StackMapType(org.apache.bcel.classfile.StackMapType smt)
smt - StackMapType to be convertedprotected final int getSize(org.apache.bcel.classfile.StackMapType smt)
smt - a StackMapType objectprotected final void update_full_frame_stack_map_entries(int offset,
org.apache.bcel.generic.Type type_new_var,
org.apache.bcel.generic.LocalVariableGen[] locals)
offset - offset into stack of the new variable we are addingtype_new_var - type of new variable we are addinglocals - a copy of the local variable table prior to this modification@Deprecated protected final org.apache.bcel.generic.LocalVariableGen add_new_argument(org.apache.bcel.generic.MethodGen mgen, String arg_name, org.apache.bcel.generic.Type arg_type)
add_new_parameter(org.apache.bcel.generic.MethodGen, java.lang.String, org.apache.bcel.generic.Type)Must call fix_local_variable_table (just once per method) before calling this routine.
mgen - MethodGen to be modifiedarg_name - name of new parameterarg_type - type of new parameterprotected final org.apache.bcel.generic.LocalVariableGen add_new_parameter(org.apache.bcel.generic.MethodGen mgen,
String arg_name,
org.apache.bcel.generic.Type arg_type)
Must call fix_local_variable_table (just once per method) before calling this routine.
mgen - MethodGen to be modifiedarg_name - name of new parameterarg_type - type of new parameterprotected final org.apache.bcel.generic.LocalVariableGen create_method_scope_local(org.apache.bcel.generic.MethodGen mgen,
String local_name,
org.apache.bcel.generic.Type local_type)
Must call fix_local_variable_table (just once per method) before calling this routine.
mgen - MethodGen to be modifiedlocal_name - name of new locallocal_type - type of new localprotected final void fix_local_variable_table(org.apache.bcel.generic.MethodGen mgen)
mgen - MethodGen to be modifiedprotected final StackTypes bcel_calc_stack_types(org.apache.bcel.generic.MethodGen mg)
mg - MethodGen for the method to be analyzed