public abstract class StackMapUtils
extends java.lang.Object
BCEL should automatically build and maintain the StackMapTable in a manner similar to the LineNumberTable and the LocalVariableTable. However, for historical reasons, it does not.
| Modifier and Type | Field and Description |
|---|---|
protected plume.SimpleLog |
debug_instrument |
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 this 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 int |
number_active_locals
The number of live local variables according to the current StackMap of interest.
|
protected 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 org.apache.bcel.classfile.StackMap |
smta
Original stack map table attribute; set by fetch_current_stack_map_table.
|
protected org.apache.bcel.classfile.StackMapEntry[] |
stack_map_table
Working copy of StackMapTable; set by fetch_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,
java.lang.String arg_name,
org.apache.bcel.generic.Type arg_type)
Add a new argument to the method.
|
protected java.lang.String[] |
add_string(java.lang.String[] arr,
java.lang.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,
java.lang.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)
Get existing StackMapTable from the MethodGen arguments.
|
protected org.apache.bcel.classfile.StackMapEntry |
find_stack_map_equal(int offset)
Find the StackMap entry whose offset matches the input argument.
|
protected 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 java.lang.String |
get_attribute_name(org.apache.bcel.classfile.Attribute a)
Return the attribute name for the specified attribute.
|
protected 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 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(java.lang.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 static java.lang.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 has moved.
|
protected org.apache.bcel.generic.ConstantPoolGen pool
protected plume.SimpleLog debug_instrument
protected boolean needStackMap
protected org.apache.bcel.classfile.StackMapEntry[] stack_map_table
protected org.apache.bcel.classfile.StackMap smta
protected org.apache.bcel.classfile.StackMapType[] initial_type_list
protected int initial_locals_count
protected int number_active_locals
protected int running_offset
protected int first_local_index
protected java.lang.String[] add_string(java.lang.String[] arr,
java.lang.String new_string)
arr - original string arraynew_string - string to be addedprotected final java.lang.String get_attribute_name(org.apache.bcel.classfile.Attribute a)
a - the attributeprotected final boolean is_local_variable_type_table(org.apache.bcel.classfile.Attribute a)
a - the attributeprotected final boolean is_stack_map_table(org.apache.bcel.classfile.Attribute a)
a - the attributeprotected final org.apache.bcel.classfile.Attribute get_stack_map_table_attribute(org.apache.bcel.generic.MethodGen mgen)
mgen - the methodprotected final 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 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)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)protected final void print_stack_map_table(java.lang.String prefix)
prefix - label to display with tableprotected final void create_new_stack_map_attribute(org.apache.bcel.generic.MethodGen mgen)
throws java.io.IOException
mgen - MethodGen to add attribute tojava.io.IOException - if cannot create the attributeprotected static java.lang.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 modificationprotected final org.apache.bcel.generic.LocalVariableGen add_new_argument(org.apache.bcel.generic.MethodGen mgen,
java.lang.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 argumentarg_type - type of new argumentprotected final org.apache.bcel.generic.LocalVariableGen create_method_scope_local(org.apache.bcel.generic.MethodGen mgen,
java.lang.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