A putfield instruction with operand CP is type safe iff all of the following are true:
-
Its first operand,
CP, refers to a constant pool entry denoting a field whose declared type isFieldTypethat is a member of a classFieldClassName.FieldClassNamemust not be an array type. -
Either:
- One can validly pop types matching
FieldTypeandFieldClassNameoff the incoming operand stack yielding the outgoing type state. protectedfields are subject to additional checks (§4.10.1.8).
- One can validly pop types matching
instructionIsTypeSafe(putfield(CP), Environment, _Offset, StackFrame,
NextStackFrame, ExceptionStackFrame) :-
CP = field(FieldClassName, FieldName, FieldDescriptor),
parseFieldDescriptor(FieldDescriptor, FieldType),
canPop(StackFrame, [FieldType], PoppedFrame),
passesProtectedCheck(Environment, FieldClassName, FieldName,
FieldDescriptor, PoppedFrame),
currentClassLoader(Environment, CurrentLoader),
canPop(StackFrame, [FieldType, class(FieldClassName, CurrentLoader)],
NextStackFrame),
exceptionStackFrame(StackFrame, ExceptionStackFrame).
-
Or:
- If the instruction occurs in an instance initialization method of the class
FieldClassNameand assigns to a field declared by the class, then one can validly pop types matchingFieldTypeanduninitializedThisoff the incoming operand stack yielding the outgoing type state. This allows instance fields ofthisthat are declared in the current class to be assigned prior to complete initialization ofthis.
- If the instruction occurs in an instance initialization method of the class
instructionIsTypeSafe(putfield(CP), Environment, _Offset, StackFrame,
NextStackFrame, ExceptionStackFrame) :-
CP = field(FieldClassName, FieldName, FieldDescriptor),
parseFieldDescriptor(FieldDescriptor, FieldType),
Environment = environment(CurrentClass, CurrentMethod, _, _, _, _),
CurrentClass = class(FieldClassName, _),
isInit(CurrentMethod),
classDeclaresMember(CurrentClass, FieldName, FieldDescriptor),
canPop(StackFrame, [FieldType, uninitializedThis], NextStackFrame),
exceptionStackFrame(StackFrame, ExceptionStackFrame).