Top Description Fields Constructors Methods
org.apache.derby.impl.services.bytecode

pack-priv Class BCMethod

extends Object
implements MethodBuilder
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.services.compiler.MethodBuilder
Imports
org.apache.derby.iapi.services.compiler.ClassBuilder, .MethodBuilder, .LocalField, org.apache.derby.iapi.services.classfile.ClassFormatOutput, .ClassHolder, .ClassMember, .VMDescriptor, .VMOpcode, org.apache.derby.shared.common.sanity.SanityManager, java.lang.reflect.Modifier, java.util.Vector, java.io.IOException

MethodBuilder is used to piece together a method when building a java class definition.

When a method is first created, it has:

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.

Field Summary

Modifier and TypeField and Description
pack-priv final BCClass
pack-priv static final int
CODE_SPLIT_LENGTH

Code length at which to split into sub-methods.

private Conditional
private int
private boolean
handlingOverflow

True if we are currently switching control over to a sub method to avoid hitting the code generation limit of 65535 bytes per method.

pack-priv int
maxStack

Maximum stack depth seen in this method, measured in words.

protected final ClassHolder
pack-priv CodeChunk
protected ClassMember
private final String
myName

The original name of the method, this represents how any user would call this method.

pack-priv final String
private static final byte[]
newArrayElementTypeMap

this array maps the BCExpr vm_* constants 0..6 to the expected VM type constants for the newarray instruction.

pack-priv BCLocalField[]
parameters

Fast access for the parametes, will be null if the method has no parameters.

private final String[]
parameterTypes

List of parameter types with java language class names.

private int
stackDepth

Current stack depth in this method, measured in words.

private int
stackTypeOffset

Points to the next array offset in stackTypes to be used.

private Type[]
stackTypes

Array of the current types of the values on the stack.

private int
private int
subMethodCount

How many sub-methods we have overflowed to.

pack-priv static final byte
pack-priv Vector<String>

Constructor Summary

AccessConstructor and Description
pack-priv
BCMethod(ClassBuilder cb, String returnType, String methodName, int modifiers, String[] parms, BCJava factory)

Method Summary

Modifier and TypeMethod and Description
private void
addInstrCPE(short opcode, int cpe)

Write a instruction that uses a constant pool entry as an operand, add a limit exceeded message if the number of constant pool entries has exceeded the limit.

public void
addThrownException(String exceptionClass)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.addThrownException.

a throwable can be added to the end of the list of thrownExceptions.

public int
callMethod(Object methodDescriptor)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.callMethod.

Call a method previously described by describeMethod().

public int
callMethod(short
type of method invocation
opcode
,
String
Class or interface the method is declared in. If it is a non-static method call then if declaringClass is null, the declared type is taken to be the type of the reference that will be popped.
declaringClass
,
String
name of the method
methodName
,
String
class name or primitive type (including "void") of the return type of the method, can not be null.
returnType
,
int
number of arguments to the method (can be 0).
numArgs
)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.callMethod.

Call a method.

pack-priv final void
callSubMethod(BCMethod subMethod)

Call a sub-method created by getNewSubMethod handling parameters correctly.

public void
public void
cast(String
type (primitive, interface or class) to cast to.
className
)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.cast.

Cast the top stack value.

public void
complete()

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.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()

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.completeConditional.

Complete a conditional which completes the false code path.

public void
private void
conditionalIf(short opcode)

public void
pack-priv ClassHolder
constantPool()

In their giveCode methods, the parts of the method body will want to get to the constant pool to add their constants.

private Type[]
public Object
describeMethod(short opcode, String declaringClass, String methodName, String returnType)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.describeMethod.

Return an object that efficiently (to the implementation) describes a zero-argument method and can be used with the single argument callMethod().

public void
dup()

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.dup.

Duplicate the top value on the stack.

public void
public void
getArrayElement(int
Offset into the array (zero based)
element
)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.getArrayElement.

Pop an array refrence off the stack and push an element from that array.

public void
getField(LocalField field)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.getField.

Push the contents of the local field onto the stack.

public void
getField(String declaringClass, String fieldName, String fieldType)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.getField.

Push the contents of the described field onto the stack.

private void
getField(short opcode, String declaringClass, String fieldName, String fieldType)

public String
getName()

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.getName.

Return the logical name of the method.

pack-priv final BCMethod

Returns:

A valid empty sub method.
getNewSubMethod
(String
Return type of the new method
returnType
,
boolean
True to define the method with matching parameters false to define it with no parameters.
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
position of the parameter (zero based).
id
)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.getParameter.

Push a parameter value.

public void
getStaticField(String declaringClass, String fieldName, String fieldType)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.getStaticField.

Push the contents of the described static field onto the stack.

private void
growStack(int size, Type type)

private void
public void
isInstanceOf(String className)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.isInstanceOf.

Pop the top stack value and push a boolean that is the result of an instanceof check on the popped reference.

public void
methodReturn()

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.methodReturn.

Return from a method, optionally with a value.

private void
overflowMethodCheck()

Check to see if the current method byte code is nearing the limit of 65535.

public void
pop()

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.pop.

Pop the top value off the stack

Stack ..., value =>
      ...
private Type
public void
push(byte value)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.push.

Push a byte constant onto the stack

Stack ...
public void
push(boolean value)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.push.

Push a boolean constant onto the stack

Stack ...
public void
push(short value)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.push.

Push a short constant onto the stack

Stack ...
public void
push(int value)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.push.

Push a int constant onto the stack

Stack ...
private void
push(int
Value to be pushed
value
,
Type
Final type of the value.
type
)

Push an integer value.

public void
push(long value)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.push.

Push a long value onto the stack.

public void
push(float value)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.push.

Push a float constant onto the stack

Stack ...
public void
push(double value)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.push.

Push a double constant onto the stack

Stack ...
public void
push(String value)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.push.

Push a String constant onto the stack

Stack ...
public void
pushNewArray(String
- type of array.
className
,
int
- number of elements in the array
size
)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.pushNewArray.

Create an array instance Stack ...

public void
pushNewComplete(int
number of arguments to the constructor (can be 0).
numArgs
)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.pushNewComplete.

Complete the sequence that was started with pushNewStart().

public void
pushNewStart(String
class name of object to be created.
className
)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.pushNewStart.

Initiate a sequence that calls a constructor, equivalent to the new operator in Java.

public void
pushNull(String type)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.pushNull.

Push a typed null onto the stack

Stack ...
public void
public void
putField(LocalField field)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.putField.

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)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.putField.

Pop the top stack value and store it in the instance field of this class.

private void
putField(Type fieldType, int cpi, boolean dup)

public void
putField(String declaringClass, String fieldName, String fieldType)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.putField.

Pop the top stack value and store it in the field.

public void
setArrayElement(int
Offset into the array (zero based)
element
)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.setArrayElement.

Pop an array reference off the stack, store a value in the array at the passed in offset.

public void
setField(LocalField field)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.setField.

Set the field but don't duplicate its value so nothing is left on the stack after this call.

private void
splitMethod()

Attempt to split a large method by pushing code out to several sub-methods.

public void
startElseCode()

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.startElseCode.

Complete the true code path of a conditional.

public boolean
statementNumHitLimit(int noStatementsAdded)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.statementNumHitLimit.

Tell if statement number in this method builder hits limit.

public void
swap()

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.swap.

Swap the top two values on the stack.

public void
upCast(String className)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.upCast.

Upcast the top stack value.

private Type
vmNameDeclaringClass(String declaringClass)

protected void
writeExceptions()

sets exceptionBytes to the attribute_info needed for a method's Exceptions attribute.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cbback to summary
pack-priv final BCClass cb
CODE_SPLIT_LENGTHback to summary
pack-priv static final int CODE_SPLIT_LENGTH

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.

conditionback to summary
private Conditional condition
currentVarNumback to summary
private int currentVarNum
handlingOverflowback to summary
private boolean handlingOverflow

True if we are currently switching control over to a sub method to avoid hitting the code generation limit of 65535 bytes per method.

maxStackback to summary
pack-priv int maxStack

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.

modClassback to summary
protected final ClassHolder modClass
myCodeback to summary
pack-priv CodeChunk myCode
myEntryback to summary
protected ClassMember myEntry
myNameback to summary
private final String myName

The original name of the method, this represents how any user would call this method.

myReturnTypeback to summary
pack-priv final String myReturnType
newArrayElementTypeMapback to summary
private static final byte[] newArrayElementTypeMap

this array maps the BCExpr vm_* constants 0..6 to the expected VM type constants for the newarray instruction.

Because boolean was mapped to integer for general instructions, it will have to be specially matched and mapped to its value directly (4).

parametersback to summary
pack-priv BCLocalField[] parameters

Fast access for the parametes, will be null if the method has no parameters.

parameterTypesback to summary
private final String[] parameterTypes

List of parameter types with java language class names. Can be null or zero length for no parameters.

stackDepthback to summary
private int stackDepth

Current stack depth in this method, measured in words.

stackTypeOffsetback to summary
private int stackTypeOffset

Points to the next array offset in stackTypes to be used. Really it's the number of valid entries in stackTypes.

stackTypesback to summary
private Type[] stackTypes

Array of the current types of the values on the stack. A type that types up two words on the stack, e.g. double will only occupy one element in this array. This array is dynamically re-sized as needed.

statementNumback to summary
private int statementNum
subMethodCountback to summary
private int subMethodCount

How many sub-methods we have overflowed to.

T_BOOLEANback to summary
pack-priv static final byte T_BOOLEAN
thrownExceptionsback to summary
pack-priv Vector<String> thrownExceptions

Constructor Detail

BCMethodback to summary
pack-priv BCMethod(ClassBuilder cb, String returnType, String methodName, int modifiers, String[] parms, BCJava factory)

Method Detail

addInstrCPEback to summary
private void addInstrCPE(short opcode, int cpe)

Write a instruction that uses a constant pool entry as an operand, add a limit exceeded message if the number of constant pool entries has exceeded the limit.

addThrownExceptionback to summary
public void addThrownException(String exceptionClass)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.addThrownException.

a throwable can be added to the end of the list of thrownExceptions.

callMethodback to summary
public int callMethod(Object methodDescriptor)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.callMethod.

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.callMethod.

Call a method previously described by describeMethod().

static methods

Stack ...,value* => [numArgs number of values will be popped]
      ...,return_value [void methods will not push a value]

non-static methods

Stack ...,ref,value* => [numArgs number of values will be popped]
      ...,return_value [void methods will not push a value]
callMethodback to summary
public int callMethod(short opcode, String declaringClass, String methodName, String returnType, int numArgs)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.callMethod.

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.callMethod.

Call a method. The instance (receiver or reference) for non-static methods must be pushed by the caller. The instance (for non-static) and the arguments are popped of the stack, and the return value (if any) is pushed onto the stack.
The type needs to be one of:

  • VMOpcode.INVOKESTATIC - call a static method
  • VMOpcode.INVOKEVIRTUAL - call method declared in the class or super-class.
  • VMOpcode.INVOKEINTERFACE - call a method declared in an interface
static methods

Stack ...,value* => [numArgs number of values will be popped]
      ...,return_value [void methods will not push a value]

non-static methods

Stack ...,ref,value* => [numArgs number of values will be popped]
      ...,return_value [void methods will not push a value]

The type of the arguments to the methods must exactly match the declared types of the parameters to the methods. If a argument is of the incorrect type the caller must up cast it or down cast it.
Parameters
opcode:short

type of method invocation

declaringClass:String

Class or interface the method is declared in. If it is a non-static method call then if declaringClass is null, the declared type is taken to be the type of the reference that will be popped.

methodName:String

name of the method

returnType:String

class name or primitive type (including "void") of the return type of the method, can not be null.

numArgs:int

number of arguments to the method (can be 0).

callSubMethodback to summary
pack-priv final void callSubMethod(BCMethod subMethod)

Call a sub-method created by getNewSubMethod handling parameters correctly.

callSuperback to summary
public void callSuper()

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.callSuper.

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.callSuper.

Call super(). Caller must only add this to a constructor.


Stack ... =>
      ... 
castback to summary
public void cast(String className)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.cast.

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.cast.

Cast the top stack value. Correctly down-casts a reference or casts a primitive type (e.g. int to short).

Stack ...,value =>
      ...,cast_value
Parameters
className:String

type (primitive, interface or class) to cast to.

completeback to summary
public void complete()

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.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.

further alterations of the method will not be reflected in the code generated for it.

completeConditionalback to summary
public void completeConditional()

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.completeConditional.

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.completeConditional.

Complete a conditional which completes the false code path.

conditionalIfback to summary
public void conditionalIf()

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.conditionalIf.

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.conditionalIf.

Initiate a conditional sequence. The top value on the stack must be a boolean and will be popped. If it is true then the code following this call until the startElseCode() will be executed at runtime, otherwise the code following startElseCode() until the completeConditional() is called. See conditionalIfNull() for example and restrictions.

Stack ...,boolean_value =>
      ...
.
conditionalIfback to summary
private void conditionalIf(short opcode)
conditionalIfNullback to summary
public void conditionalIfNull()

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.conditionalIfNull.

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.conditionalIfNull.

Initiate a conditional sequence. The top value on the stack (a reference) is popped and compared to 'null'. If the value is null then the code following this call until the startElseCode() will be executed at runtime, otherwise the code following startElseCode() until the completeConditional() is called.
E.g.

mb.callMethod(...); // pushes an object onto the stack
mb.conditionalIfNull();
  mb.push(3);
mb.startElseCode();
  mb.push(5);
mb.completeConditional();
// at this point 3 or 5 will be on the stack
Each path through the ?: statement must leave the stack at the same depth as the other.
If the if or else code pops values from the stack that were before the conditional value, then they must use the same number of values from the stack.
Stack ...,ref =>
      ...
.
constantPoolback to summary
pack-priv ClassHolder constantPool()

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.

copyStackback to summary
private Type[] copyStack()
describeMethodback to summary
public Object describeMethod(short opcode, String declaringClass, String methodName, String returnType)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.describeMethod.

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.describeMethod.

Return an object that efficiently (to the implementation) describes a zero-argument method and can be used with the single argument callMethod(). Descriptions for the parameters to this method are the same as the five argument callMethod(). This allows the caller to cache frequently used methods. The returned object is only valid for use by this MethodBuilder.
This call does not affect the Stack.

dupback to summary
public void dup()

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.dup.

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.dup.

Duplicate the top value on the stack.

Stack ...,value =>
      ...,value,value
endStatementback to summary
public void endStatement()

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.endStatement.

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.endStatement.

End a statement. Pops the top-word of the stack, if any. Must only be called if zero or one item exists on the stack.

Stack value =>
      :empty:
or

Stack :empty: =>
      :empty:

.
getArrayElementback to summary
public void getArrayElement(int element)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.getArrayElement.

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.getArrayElement.

Pop an array refrence off the stack and push an element from that array.

Stack ...,array_ref =>
      ...,value
Parameters
element:int

Offset into the array (zero based)

getFieldback to summary
public void getField(LocalField field)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.getField.

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.getField.

Push the contents of the local field onto the stack. This call pushes the this instance required to access the field itself.

Stack ...  =>
      ...,field_value
getFieldback to summary
public void getField(String declaringClass, String fieldName, String fieldType)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.getField.

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.getField.

Push the contents of the described field onto the stack. This call requires the instance (reference) to be pushed by the caller.

Stack ...,field_ref  =>
      ...,field_value
getFieldback to summary
private void getField(short opcode, String declaringClass, String fieldName, String fieldType)
getNameback to summary
public String getName()

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.getName.

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.

getNewSubMethodback to summary
pack-priv 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. The sub method with inherit the thrown exceptions of this method.

Parameters
returnType:String

Return type of the new method

withParameters:boolean

True to define the method with matching parameters false to define it with no parameters.

Returns:BCMethod

A valid empty sub method.

getParameterback to summary
public void getParameter(int id)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.getParameter.

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.getParameter.

Push a parameter value.

Stack ...  =>
      ...,param_value
Parameters
id:int

position of the parameter (zero based).

getStaticFieldback to summary
public void getStaticField(String declaringClass, String fieldName, String fieldType)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.getStaticField.

Push the contents of the described static field onto the stack.

growStackback to summary
private void growStack(int size, Type type)
growStackback to summary
private void growStack(Type type)
isInstanceOfback to summary
public void isInstanceOf(String className)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.isInstanceOf.

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.isInstanceOf.

Pop the top stack value and push a boolean that is the result of an instanceof check on the popped reference.

Stack ...,ref =>
      ...,boolean_value
.
methodReturnback to summary
public void methodReturn()

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.methodReturn.

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.methodReturn.

Return from a method, optionally with a value. Must only be called if zero or one item exists on the stack. If the stack contains a single value then that is popped and used as the returned value.

Stack value =>
      :empty:
or

Stack :empty: =>
      :empty:

.
overflowMethodCheckback to summary
private void overflowMethodCheck()

Check to see if the current method byte code is nearing the limit of 65535. If it is start overflowing to a new method.

Overflow is handled for a method named e23 as: public Object e23() { ... existing code // split point return e23_0(); } private Object e23_0() { ... first set overflowed code // split point return e23_1(); } private Object e23_1() { ... second set overflowed code // method complete return result; }

These overflow methods are hidden from the code using this MethodBuilder, it continues to think that it is building a single method with the original name.
Restrictions:

  • Only handles methods with no arguments
  • Stack depth must be zero
popback to summary
public void pop()

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.pop.

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.pop.

Pop the top value off the stack

Stack ..., value =>
      ...
.
popStackback to summary
private Type popStack()
pushback to summary
public void push(byte value)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.push.

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.push.

Push a byte constant onto the stack

Stack ...  =>
      ...,byte_value
pushback to summary
public void push(boolean value)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.push.

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.push.

Push a boolean constant onto the stack

Stack ...  =>
      ...,boolean_value
pushback to summary
public void push(short value)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.push.

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.push.

Push a short constant onto the stack

Stack ...  =>
      ...,short_value
pushback to summary
public void push(int value)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.push.

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.push.

Push a int constant onto the stack

Stack ...  =>
      ...,int_value
pushback to summary
private void push(int value, Type type)

Push an integer value. Uses the special integer opcodes for the constants -1 to 5, BIPUSH for values that fit in a byte and SIPUSH for values that fit in a short. Otherwise uses LDC with a constant pool entry.

Parameters
value:int

Value to be pushed

type:Type

Final type of the value.

pushback to summary
public void push(long value)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.push.

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.

pushback to summary
public void push(float value)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.push.

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.push.

Push a float constant onto the stack

Stack ...  =>
      ...,float_value
pushback to summary
public void push(double value)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.push.

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.push.

Push a double constant onto the stack

Stack ...  =>
      ...,double_value
pushback to summary
public void push(String value)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.push.

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.push.

Push a String constant onto the stack

Stack ...  =>
      ...,String_value
pushNewArrayback to summary
public void pushNewArray(String className, int size)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.pushNewArray.

Create an array instance Stack ... => ...,arrayref

Parameters
className:String

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.pushNewArray.

- type of array.

size:int

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.pushNewArray.

- number of elements in the array

pushNewCompleteback to summary
public void pushNewComplete(int numArgs)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.pushNewComplete.

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.pushNewComplete.

Complete the sequence that was started with pushNewStart(). Pop the arguments to the constructor and push the reference to the newly created object.

Stack ...,value* => [numArgs number of values will be popped]
      ...,new_ref
Parameters
numArgs:int

number of arguments to the constructor (can be 0).

pushNewStartback to summary
public void pushNewStart(String className)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.pushNewStart.

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.pushNewStart.

Initiate a sequence that calls a constructor, equivalent to the new operator in Java. After this call, the caller must push any arguments and then complete the construction with a call to pushNewComplete(). Only arguments to the constructor can be pushed onto the stack between the pushNewStart() and pushNewComplete() method calls.

Stack ... => [unchanged]
      ...
Parameters
className:String

class name of object to be created.

pushNullback to summary
public void pushNull(String type)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.pushNull.

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.pushNull.

Push a typed null onto the stack

Stack ...  =>
      ...,null
pushThisback to summary
public void pushThis()

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.pushThis.

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.pushThis.

Push this onto the stack.

Stack ...  =>
      ...,this_ref
putFieldback to summary
public void putField(LocalField field)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.putField.

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.
putFieldback to summary
public void putField(String fieldName, String fieldType)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.putField.

Pop the top stack value and store it in the instance field of this class.

putFieldback to summary
private void putField(Type fieldType, int cpi, boolean dup)
putFieldback to summary
public void putField(String declaringClass, String fieldName, String fieldType)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.putField.

Pop the top stack value and store it in the field. This call requires the instance to be pushed by the caller.

setArrayElementback to summary
public void setArrayElement(int element)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.setArrayElement.

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.setArrayElement.

Pop an array reference off the stack, store a value in the array at the passed in offset.

Stack ...,array_ref, value =>
      ...
Parameters
element:int

Offset into the array (zero based)

setFieldback to summary
public void setField(LocalField field)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.setField.

Set the field but don't duplicate its value so nothing is left on the stack after this call.

splitMethodback to summary
private void splitMethod()

Attempt to split a large method by pushing code out to several sub-methods. Performs a number of steps.

  1. Split at zero stack depth.
  2. Split at non-zero stack depth (FUTURE)
If the class has already exceeded some limit in building the class file format structures then don't attempt to split. Most likely the number of constant pool entries has been exceeded and thus the built class file no longer has integrity. The split code relies on being able to read the in-memory version of the class file in order to determine descriptors for methods and fields.
startElseCodeback to summary
public void startElseCode()

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.startElseCode.

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.startElseCode.

Complete the true code path of a conditional.

statementNumHitLimitback to summary
public boolean statementNumHitLimit(int noStatementsAdded)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.statementNumHitLimit.

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.

swapback to summary
public void swap()

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.swap.

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.swap.

Swap the top two values on the stack.

Stack ...,valueA,valueB =>
      ...,valueB,valueA
upCastback to summary
public void upCast(String className)

Implements org.apache.derby.iapi.services.compiler.MethodBuilder.upCast.

Doc from org.apache.derby.iapi.services.compiler.MethodBuilder.upCast.

Upcast the top stack value. This is used for correct method resolution by upcasting method parameters. It does not put any casting code into the byte code stream. Can only be used for refrences.

Stack ...,ref =>
      ...,ref
vmNameDeclaringClassback to summary
private Type vmNameDeclaringClass(String declaringClass)
writeExceptionsback to summary
protected void writeExceptions()

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.