com.android.dx.cf.code
Class BaseMachine

java.lang.Object
  extended by com.android.dx.cf.code.BaseMachine
All Implemented Interfaces:
Machine
Direct Known Subclasses:
ValueAwareMachine

public abstract class BaseMachine
extends Object
implements Machine

Base implementation of Machine.

Note: For the most part, the documentation for this class ignores the distinction between Type and TypeBearer.


Constructor Summary
BaseMachine(Prototype prototype)
          Constructs an instance.
 
Method Summary
protected  void addResult(TypeBearer result)
          Adds an additional element to the list of results.
protected  TypeBearer arg(int n)
          Gets the nth primary argument.
protected  int argCount()
          Gets the number of primary arguments.
protected  int argWidth()
          Gets the width of the arguments (where a category-2 value counts as two).
 void auxCstArg(Constant cst)
          Indicates that there is an auxiliary (inline, not stack) object argument, with the value based on the given constant.
 void auxInitValues(ArrayList<Constant> initValues)
          Indicates that there is an auxiliary (inline, not stack) argument consisting of a list of initial values for a newly created array.
 void auxIntArg(int value)
          Indicates that there is an auxiliary (inline, not stack) argument of type int, with the given value.
 void auxSwitchArg(SwitchList cases)
          Indicates that there is an auxiliary (inline, not stack) argument consisting of a switch* table.
 void auxTargetArg(int target)
          Indicates that there is an auxiliary (inline, not stack) argument indicating a branch target.
 void auxType(Type type)
          Indicates that the salient type of this operation is as given.
 void clearArgs()
          Clears the regular and auxiliary arguments area.
protected  void clearResult()
          Clears the results.
protected  SwitchList getAuxCases()
          Gets the switch cases auxiliary argument.
protected  Constant getAuxCst()
          Gets the constant auxiliary argument.
protected  int getAuxInt()
          Gets the int auxiliary argument.
protected  int getAuxTarget()
          Gets the branch target auxiliary argument.
protected  Type getAuxType()
          Gets the type auxiliary argument.
protected  ArrayList<Constant> getInitValues()
          Gets the init values auxiliary argument.
protected  int getLocalIndex()
          Gets the last local index accessed.
protected  boolean getLocalInfo()
          Gets whether the loaded local has info in the local variable table.
protected  RegisterSpec getLocalTarget(boolean isMove)
          Gets the target local register spec of the current operation, if any.
 Prototype getPrototype()
          Gets the effective prototype of the method that this instance is being used for.
 void localArg(Frame frame, int idx)
          Loads the local variable with the given index as the sole argument in the arguments area.
 void localInfo(boolean local)
          Used to specify if a loaded local variable has info in the local variable table.
 void localTarget(int idx, Type type, LocalItem local)
          Indicates that the target of this operation is the given local.
 void popArgs(Frame frame, int count)
          Pops the given number of values from the stack (of either category), and store them in the arguments area, indicating that there are now that many arguments.
 void popArgs(Frame frame, Prototype prototype)
          Pops values from the stack of the types indicated by the given Prototype (popped in reverse of the argument order, so the first prototype argument type is for the deepest element of the stack), and store them in the arguments area, indicating that there are now that many arguments.
 void popArgs(Frame frame, Type type)
          Pops a value from the stack of the indicated type, and store it in the arguments area, indicating that there are now that many arguments.
 void popArgs(Frame frame, Type type1, Type type2)
          Pops values from the stack of the indicated types (popped in reverse argument order, so the first indicated type is for the deepest element of the stack), and store them in the arguments area, indicating that there are now that many arguments.
 void popArgs(Frame frame, Type type1, Type type2, Type type3)
          Pops values from the stack of the indicated types (popped in reverse argument order, so the first indicated type is for the deepest element of the stack), and store them in the arguments area, indicating that there are now that many arguments.
protected  TypeBearer result(int n)
          Gets the nth result value.
protected  int resultCount()
          Gets the count of results.
protected  int resultWidth()
          Gets the width of the results (where a category-2 value counts as two).
protected  void setResult(TypeBearer result)
          Sets the results list to be the given single value.
protected  void storeResults(Frame frame)
          Stores the results of the latest operation into the given frame.
static void throwLocalMismatch(TypeBearer found, TypeBearer local)
          Throws an exception that indicates a mismatch in local variable types.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.android.dx.cf.code.Machine
run
 

Constructor Detail

BaseMachine

public BaseMachine(Prototype prototype)
Constructs an instance.

Parameters:
prototype - non-null; the prototype for the associated method
Method Detail

getPrototype

public Prototype getPrototype()
Gets the effective prototype of the method that this instance is being used for. The effective prototype includes an initial this argument for instance methods.

Specified by:
getPrototype in interface Machine
Returns:
non-null; the method prototype

clearArgs

public final void clearArgs()
Clears the regular and auxiliary arguments area.

Specified by:
clearArgs in interface Machine

popArgs

public final void popArgs(Frame frame,
                          int count)
Pops the given number of values from the stack (of either category), and store them in the arguments area, indicating that there are now that many arguments. Also, clear the auxiliary arguments.

Specified by:
popArgs in interface Machine
Parameters:
frame - non-null; frame to operate on
count - >= 0; number of values to pop

popArgs

public void popArgs(Frame frame,
                    Prototype prototype)
Pops values from the stack of the types indicated by the given Prototype (popped in reverse of the argument order, so the first prototype argument type is for the deepest element of the stack), and store them in the arguments area, indicating that there are now that many arguments. Also, clear the auxiliary arguments.

Specified by:
popArgs in interface Machine
Parameters:
frame - non-null; frame to operate on
prototype - non-null; prototype indicating arguments to pop

popArgs

public final void popArgs(Frame frame,
                          Type type)
Description copied from interface: Machine
Pops a value from the stack of the indicated type, and store it in the arguments area, indicating that there are now that many arguments. Also, clear the auxiliary arguments.

Specified by:
popArgs in interface Machine
Parameters:
frame - non-null; frame to operate on
type - non-null; type of the argument

popArgs

public final void popArgs(Frame frame,
                          Type type1,
                          Type type2)
Pops values from the stack of the indicated types (popped in reverse argument order, so the first indicated type is for the deepest element of the stack), and store them in the arguments area, indicating that there are now that many arguments. Also, clear the auxiliary arguments.

Specified by:
popArgs in interface Machine
Parameters:
frame - non-null; frame to operate on
type1 - non-null; type of the first argument
type2 - non-null; type of the second argument

popArgs

public final void popArgs(Frame frame,
                          Type type1,
                          Type type2,
                          Type type3)
Pops values from the stack of the indicated types (popped in reverse argument order, so the first indicated type is for the deepest element of the stack), and store them in the arguments area, indicating that there are now that many arguments. Also, clear the auxiliary arguments.

Specified by:
popArgs in interface Machine
Parameters:
frame - non-null; frame to operate on
type1 - non-null; type of the first argument
type2 - non-null; type of the second argument
type3 - non-null; type of the third argument

localArg

public final void localArg(Frame frame,
                           int idx)
Loads the local variable with the given index as the sole argument in the arguments area. Also, clear the auxiliary arguments.

Specified by:
localArg in interface Machine
Parameters:
frame - non-null; frame to operate on
idx - >= 0; the local variable index

localInfo

public final void localInfo(boolean local)
Used to specify if a loaded local variable has info in the local variable table.

Specified by:
localInfo in interface Machine
Parameters:
local - true if local arg has info in local variable table

auxType

public final void auxType(Type type)
Indicates that the salient type of this operation is as given. This differentiates between, for example, the various arithmetic opcodes, which, by the time they hit a Machine are collapsed to the int variant. (See BytecodeArray.parseInstruction(int, com.android.dx.cf.code.BytecodeArray.Visitor) for details.)

Specified by:
auxType in interface Machine
Parameters:
type - non-null; the salient type of the upcoming operation

auxIntArg

public final void auxIntArg(int value)
Indicates that there is an auxiliary (inline, not stack) argument of type int, with the given value.

Note: Perhaps unintuitively, the stack manipulation ops (e.g., dup and swap) use this to indicate the result stack pattern with a straightforward hex encoding of the push order starting with least-significant nibbles getting pushed first). For example, an all-category-1 dup2_x1 sets this to 0x12312, and the other form of that op sets this to 0x121.

Also Note: For switch* instructions, this is used to indicate the padding value (which is only useful for verification).

Specified by:
auxIntArg in interface Machine
Parameters:
value - the argument value

auxCstArg

public final void auxCstArg(Constant cst)
Indicates that there is an auxiliary (inline, not stack) object argument, with the value based on the given constant.

Note: Some opcodes use both int and constant auxiliary arguments.

Specified by:
auxCstArg in interface Machine
Parameters:
cst - non-null; the constant containing / referencing the value

auxTargetArg

public final void auxTargetArg(int target)
Indicates that there is an auxiliary (inline, not stack) argument indicating a branch target.

Specified by:
auxTargetArg in interface Machine
Parameters:
target - the argument value

auxSwitchArg

public final void auxSwitchArg(SwitchList cases)
Indicates that there is an auxiliary (inline, not stack) argument consisting of a switch* table.

Note: This is generally used in conjunction with Machine.auxIntArg(int) (which holds the padding).

Specified by:
auxSwitchArg in interface Machine
Parameters:
cases - non-null; the list of key-target pairs, plus the default target

auxInitValues

public final void auxInitValues(ArrayList<Constant> initValues)
Indicates that there is an auxiliary (inline, not stack) argument consisting of a list of initial values for a newly created array.

Specified by:
auxInitValues in interface Machine
Parameters:
initValues - non-null; the list of constant values to initialize the array

localTarget

public final void localTarget(int idx,
                              Type type,
                              LocalItem local)
Indicates that the target of this operation is the given local.

Specified by:
localTarget in interface Machine
Parameters:
idx - >= 0; the local variable index
type - non-null; the type of the local
local - null-ok; the name and signature of the local, if known

argCount

protected final int argCount()
Gets the number of primary arguments.

Returns:
>= 0; the number of primary arguments

argWidth

protected final int argWidth()
Gets the width of the arguments (where a category-2 value counts as two).

Returns:
>= 0; the argument width

arg

protected final TypeBearer arg(int n)
Gets the nth primary argument.

Parameters:
n - >= 0, < argCount(); which argument
Returns:
non-null; the indicated argument

getAuxType

protected final Type getAuxType()
Gets the type auxiliary argument.

Returns:
null-ok; the salient type

getAuxInt

protected final int getAuxInt()
Gets the int auxiliary argument.

Returns:
the argument value

getAuxCst

protected final Constant getAuxCst()
Gets the constant auxiliary argument.

Returns:
null-ok; the argument value

getAuxTarget

protected final int getAuxTarget()
Gets the branch target auxiliary argument.

Returns:
the argument value

getAuxCases

protected final SwitchList getAuxCases()
Gets the switch cases auxiliary argument.

Returns:
null-ok; the argument value

getInitValues

protected final ArrayList<Constant> getInitValues()
Gets the init values auxiliary argument.

Returns:
null-ok; the argument value

getLocalIndex

protected final int getLocalIndex()
Gets the last local index accessed.

Returns:
>= -1; the salient local index or -1 if none was set since the last time clearArgs() was called

getLocalInfo

protected final boolean getLocalInfo()
Gets whether the loaded local has info in the local variable table.

Returns:
true if local arg has info in the local variable table

getLocalTarget

protected final RegisterSpec getLocalTarget(boolean isMove)
Gets the target local register spec of the current operation, if any. The local target spec is the combination of the values indicated by a previous call to localTarget with the type of what should be the sole result set by a call to setResult(com.android.dx.rop.type.TypeBearer) (or the combination clearResult() then addResult(com.android.dx.rop.type.TypeBearer).

Parameters:
isMove - true if the operation being performed on the local is a move. This will cause constant values to be propagated to the returned local
Returns:
null-ok; the salient register spec or null if no local target was set since the last time clearArgs() was called

clearResult

protected final void clearResult()
Clears the results.


setResult

protected final void setResult(TypeBearer result)
Sets the results list to be the given single value.

Note: If there is more than one result value, the others may be added by using addResult(com.android.dx.rop.type.TypeBearer).

Parameters:
result - non-null; result value

addResult

protected final void addResult(TypeBearer result)
Adds an additional element to the list of results.

Parameters:
result - non-null; result value
See Also:
setResult(com.android.dx.rop.type.TypeBearer)

resultCount

protected final int resultCount()
Gets the count of results. This throws an exception if results were never set. (Explicitly clearing the results counts as setting them.)

Returns:
>= 0; the count

resultWidth

protected final int resultWidth()
Gets the width of the results (where a category-2 value counts as two).

Returns:
>= 0; the result width

result

protected final TypeBearer result(int n)
Gets the nth result value.

Parameters:
n - >= 0, < resultCount(); which result
Returns:
non-null; the indicated result value

storeResults

protected final void storeResults(Frame frame)
Stores the results of the latest operation into the given frame. If there is a local target (see localTarget), then the sole result is stored to that target; otherwise any results are pushed onto the stack.

Parameters:
frame - non-null; frame to operate on

throwLocalMismatch

public static void throwLocalMismatch(TypeBearer found,
                                      TypeBearer local)
Throws an exception that indicates a mismatch in local variable types.

Parameters:
found - non-null; the encountered type
local - non-null; the local variable's claimed type


Copyright © 2015. All rights reserved.