Package com.tonic.analysis.verifier.type
Class TypeConstraint
- java.lang.Object
-
- com.tonic.analysis.verifier.type.TypeConstraint
-
public class TypeConstraint extends Object
Assignability and category rules over verification types.
-
-
Constructor Summary
Constructors Constructor Description TypeConstraint(ClassPool classPool)Creates a constraint checker.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanisArrayLoadValid(VerificationType arrayType, VerificationType expectedElement)Checks an array load: the operand must be a reference, and when its element type is known it must satisfy what the load opcode expects.booleanisAssignableTo(VerificationType source, VerificationType target)Decides whether a value of one type may be stored where another is expected.booleanisCategory1(VerificationType type)booleanisCategory2(VerificationType type)booleanisDouble(VerificationType type)booleanisFloat(VerificationType type)booleanisInteger(VerificationType type)booleanisLong(VerificationType type)booleanisPrimitiveType(VerificationType type)booleanisReceiverValid(VerificationType receiver, String expectedOwner)Checks an invocation receiver, accepting null and uninitialized references.booleanisReferenceType(VerificationType type)booleanisThrowable(VerificationType type)Decides whether a value may be thrown, walking to Throwable when a class pool is available and accepting the type otherwise.
-
-
-
Constructor Detail
-
TypeConstraint
public TypeConstraint(ClassPool classPool)
Creates a constraint checker.- Parameters:
classPool- the pool used to walk superclass chains, or null to assume every reference relation holds
-
-
Method Detail
-
isAssignableTo
public boolean isAssignableTo(VerificationType source, VerificationType target)
Decides whether a value of one type may be stored where another is expected.- Parameters:
source- the type being suppliedtarget- the type being expected- Returns:
- true if the assignment is allowed, false if either type is null
-
isArrayLoadValid
public boolean isArrayLoadValid(VerificationType arrayType, VerificationType expectedElement)
Checks an array load: the operand must be a reference, and when its element type is known it must satisfy what the load opcode expects. An operand whose element type cannot be read is accepted, so an unresolvable type never fails verification.- Parameters:
arrayType- the type of the array operandexpectedElement- the element type the load opcode expects, or null to check only the operand- Returns:
- true if the load is allowed
-
isReceiverValid
public boolean isReceiverValid(VerificationType receiver, String expectedOwner)
Checks an invocation receiver, accepting null and uninitialized references. A receiver of known class is required to be the owner or a subclass of it; an interface owner is not constrained, matching the verifier's own treatment of interface calls, and an unresolvable owner is accepted.- Parameters:
receiver- the type on the stack in receiver positionexpectedOwner- internal name of the class declaring the callee, or null to check only the receiver- Returns:
- true if the receiver is allowed
-
isThrowable
public boolean isThrowable(VerificationType type)
Decides whether a value may be thrown, walking to Throwable when a class pool is available and accepting the type otherwise.- Parameters:
type- the type on the stack- Returns:
- true if the value may be thrown
-
isInteger
public boolean isInteger(VerificationType type)
- Parameters:
type- the type to test- Returns:
- true if the type is int
-
isLong
public boolean isLong(VerificationType type)
- Parameters:
type- the type to test- Returns:
- true if the type is long
-
isFloat
public boolean isFloat(VerificationType type)
- Parameters:
type- the type to test- Returns:
- true if the type is float
-
isDouble
public boolean isDouble(VerificationType type)
- Parameters:
type- the type to test- Returns:
- true if the type is double
-
isCategory1
public boolean isCategory1(VerificationType type)
- Parameters:
type- the type to test- Returns:
- true if the type takes one stack slot
-
isCategory2
public boolean isCategory2(VerificationType type)
- Parameters:
type- the type to test- Returns:
- true if the type takes two stack slots
-
isReferenceType
public boolean isReferenceType(VerificationType type)
- Parameters:
type- the type to test- Returns:
- true if the type is a reference, including null and uninitialized ones
-
isPrimitiveType
public boolean isPrimitiveType(VerificationType type)
- Parameters:
type- the type to test- Returns:
- true for int, long, float, double or top
-
-