| java.lang.Object org.apache.derby.impl.services.bytecode.BCMethod
BCMethod | class BCMethod implements MethodBuilder(Code) | | MethodBuilder is used to piece together a method when
building a java class definition.
When a method is first created, it has:
- a return type
- modifiers
- a name
- an empty parameter list
- an empty throws list
- an empty statement block
MethodBuilder implementations are required to supply a way for
Statements and Expressions to give them code. Most typically, they may have
a stream to which their contents writes the code that is of
the type to satisfy what the contents represent.
MethodBuilder implementations also have to have a way to supply
ClassBuilders with their code, that satisfies the type of class
builder they are implemented with. This is implementation-dependent,
so ClassBuilders, MethodBuilders, Statements, and Expressions all have
to be of the same implementation in order to interact to generate a class.
Method Builder implementation for generating bytecode.
|
Method Summary | |
public void | addThrownException(String exceptionClass) a throwable can be added to the end of
the list of thrownExceptions. | public int | callMethod(Object methodDescriptor) | public int | callMethod(short opcode, String declaringClass, String methodName, String returnType, int numArgs) | final void | callSubMethod(BCMethod subMethod) Call a sub-method created by getNewSubMethod handling parameters
correctly. | public void | callSuper() | public void | cast(String className) | public void | complete() when the method has had all of its parameters
and thrown exceptions defined, and its statement
block has been completed, it can be completed and
its class file information generated. | public void | completeConditional() | public void | conditionalIf() | public void | conditionalIfNull() | ClassHolder | constantPool() In their giveCode methods, the parts of the method body will want to get
to the constant pool to add their constants. | public Object | describeMethod(short opcode, String declaringClass, String methodName, String returnType) | public void | dup() | public void | endStatement() | public void | getArrayElement(int element) | public void | getField(LocalField field) | public void | getField(String declaringClass, String fieldName, String fieldType) | public String | getName() Return the logical name of the method. | final BCMethod | getNewSubMethod(String returnType, boolean withParameters) Create a sub-method from this method to allow the code builder to split a
single logical method into multiple methods to avoid the 64k per-method
code size limit. | public void | getParameter(int id) | public void | getStaticField(String declaringClass, String fieldName, String fieldType) | public void | isInstanceOf(String className) | public void | methodReturn() | public void | pop() | public void | push(byte value) | public void | push(boolean value) | public void | push(short value) | public void | push(int value) | public void | push(long value) Push a long value onto the stack.
For the values zero and one the LCONST_0 and
LCONST_1 instructions are used.
For values betwee Short.MIN_VALUE and Short.MAX_VALUE
inclusive an byte/short/int value is pushed
using push(int, Type) followed by an I2L instruction.
This saves using a constant pool entry for such values.
All other values use a constant pool entry. | public void | push(float value) | public void | push(double value) | public void | push(String value) | public void | pushNewArray(String className, int size) Create an array instance
Stack ... | public void | pushNewComplete(int numArgs) | public void | pushNewStart(String className) | public void | pushNull(String type) | public void | pushThis() | public void | putField(LocalField field) Upon entry the top word(s) on the stack is
the value to be put into the field. | public void | putField(String fieldName, String fieldType) Pop the top stack value and store it in the instance field of this class. | public void | putField(String declaringClass, String fieldName, String fieldType) Pop the top stack value and store it in the field. | public void | setArrayElement(int element) | public void | setField(LocalField field) Set the field but don't duplicate its value so
nothing is left on the stack after this call. | public void | startElseCode() | public boolean | statementNumHitLimit(int noStatementsAdded) Tell if statement number in this method builder hits limit. | public void | swap() | public void | upCast(String className) | protected void | writeExceptions() sets exceptionBytes to the attribute_info needed
for a method's Exceptions attribute. |
CODE_SPLIT_LENGTH | final static int CODE_SPLIT_LENGTH(Code) | | Code length at which to split into sub-methods.
Normally set to the maximim code length the
JVM can support, but for testing the split code
it can be reduced so that the standard tests
cause some splitting. Tested with value set to 2000.
|
T_BOOLEAN | final static byte T_BOOLEAN(Code) | | |
maxStack | int maxStack(Code) | | Maximum stack depth seen in this method, measured in words.
Corresponds to max_stack in the Code attribute of section 4.7.3
of the vm spec.
|
parameters | BCLocalField[] parameters(Code) | | Fast access for the parametes, will be null
if the method has no parameters.
|
addThrownException | public void addThrownException(String exceptionClass)(Code) | | a throwable can be added to the end of
the list of thrownExceptions.
|
callMethod | public int callMethod(Object methodDescriptor)(Code) | | |
callMethod | public int callMethod(short opcode, String declaringClass, String methodName, String returnType, int numArgs)(Code) | | |
callSubMethod | final void callSubMethod(BCMethod subMethod)(Code) | | Call a sub-method created by getNewSubMethod handling parameters
correctly.
|
callSuper | public void callSuper()(Code) | | |
complete | public void complete()(Code) | | when the method has had all of its parameters
and thrown exceptions defined, and its statement
block has been completed, it can be completed and
its class file information generated.
further alterations of the method will not be
reflected in the code generated for it.
|
completeConditional | public void completeConditional()(Code) | | |
conditionalIf | public void conditionalIf()(Code) | | |
conditionalIfNull | public void conditionalIfNull()(Code) | | |
constantPool | ClassHolder constantPool()(Code) | | In their giveCode methods, the parts of the method body will want to get
to the constant pool to add their constants. We really only want them
treating it like a constant pool inclusion mechanism, we could write a
wrapper to limit it to that.
|
endStatement | public void endStatement()(Code) | | |
getArrayElement | public void getArrayElement(int element)(Code) | | |
getName | public String getName()(Code) | | Return the logical name of the method. The current
myEntry refers to the sub method we are currently
overflowing to. Those sub-methods are hidden from any caller.
|
getNewSubMethod | final BCMethod getNewSubMethod(String returnType, boolean withParameters)(Code) | | Create a sub-method from this method to allow the code builder to split a
single logical method into multiple methods to avoid the 64k per-method
code size limit. The sub method with inherit the thrown exceptions of
this method.
Parameters: returnType - Return type of the new method Parameters: withParameters - True to define the method with matching parameters false todefine it with no parameters. A valid empty sub method. |
getParameter | public void getParameter(int id)(Code) | | |
getStaticField | public void getStaticField(String declaringClass, String fieldName, String fieldType)(Code) | | Push the contents of the described static field onto the stack.
|
isInstanceOf | public void isInstanceOf(String className)(Code) | | |
methodReturn | public void methodReturn()(Code) | | |
push | public void push(byte value)(Code) | | |
push | public void push(boolean value)(Code) | | |
push | public void push(short value)(Code) | | |
push | public void push(int value)(Code) | | |
push | public void push(long value)(Code) | | Push a long value onto the stack.
For the values zero and one the LCONST_0 and
LCONST_1 instructions are used.
For values betwee Short.MIN_VALUE and Short.MAX_VALUE
inclusive an byte/short/int value is pushed
using push(int, Type) followed by an I2L instruction.
This saves using a constant pool entry for such values.
All other values use a constant pool entry. For values
in the range of an Integer an integer constant pool
entry is created to allow sharing with integer constants
and to reduce constant pool slot entries.
|
push | public void push(float value)(Code) | | |
push | public void push(double value)(Code) | | |
pushNewArray | public void pushNewArray(String className, int size)(Code) | | Create an array instance
Stack ... =>
...,arrayref
|
pushNewComplete | public void pushNewComplete(int numArgs)(Code) | | |
pushNewStart | public void pushNewStart(String className)(Code) | | |
pushThis | public void pushThis()(Code) | | |
putField | public void putField(LocalField field)(Code) | | Upon entry the top word(s) on the stack is
the value to be put into the field. Ie.
we have
word
Before the call we need
word
this
word
word2,word1 -> word2, word1, word2
So that we are left with word after the put.
|
putField | public void putField(String fieldName, String fieldType)(Code) | | Pop the top stack value and store it in the instance field of this class.
|
putField | public void putField(String declaringClass, String fieldName, String fieldType)(Code) | | Pop the top stack value and store it in the field.
This call requires the instance to be pushed by the caller.
|
setArrayElement | public void setArrayElement(int element)(Code) | | |
setField | public void setField(LocalField field)(Code) | | Set the field but don't duplicate its value so
nothing is left on the stack after this call.
|
startElseCode | public void startElseCode()(Code) | | |
statementNumHitLimit | public boolean statementNumHitLimit(int noStatementsAdded)(Code) | | Tell if statement number in this method builder hits limit. This
method builder keeps a counter of how many statements are added to it.
Caller should call this function every time it tries to add a statement
to this method builder (counter is increased by 1), then the function
returns whether the accumulated statement number hits a limit.
The reason of doing this is that Java compiler has a limit of 64K code
size for each method. We might hit this limit if an extremely long
insert statement is issued, for example (see beetle 4293). Counting
statement number is an approximation without too much overhead.
|
writeExceptions | protected void writeExceptions()(Code) | | sets exceptionBytes to the attribute_info needed
for a method's Exceptions attribute.
The ClassUtilities take care of the header 6 bytes for us,
so they are not included here.
See The Java Virtual Machine Specification Section 4.7.5,
Exceptions attribute.
|
|
|