An invokevirtual instruction is type safe iff all of the following are true:
- Its first operand,
CP, refers to a constant pool entry denoting a method namedMethodNamewith descriptorDescriptorthat is a member of a typeMethodClassType. MethodNameis not<init>.MethodNameis not<clinit>.- One can validly replace types matching
MethodClassTypeand the argument types given inDescriptoron the incoming operand stack with the return type given inDescriptor, yielding the outgoing type state. - If the method is
protected, the usage conforms to the special rules governing access toprotectedmembers (§4.10.1.8).
instructionIsTypeSafe(invokevirtual(CP), Environment, _Offset, StackFrame,
NextStackFrame, ExceptionStackFrame) :-
CP = method(MethodClassType, MethodName, Descriptor),
MethodName \= '<init>',
MethodName \= '<clinit>',
parseMethodDescriptor(Descriptor, OperandArgList, ReturnType),
reverse(OperandArgList, ArgList),
reverse([MethodClassType | OperandArgList], StackArgList),
validTypeTransition(Environment, StackArgList, ReturnType,
StackFrame, NextStackFrame),
canPop(StackFrame, ArgList, PoppedFrame),
passesProtectedCheck(Environment, MethodClassType, MethodName,
Descriptor, PoppedFrame),
exceptionStackFrame(StackFrame, ExceptionStackFrame).