Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8159747

4.10.1.9: Clarify that putfield can early-assign to fields of 'this'

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 8
    • Fix Version/s: 9
    • Component/s: specification
    • Labels:
    • Subcomponent:
      vm

      Description

      JVMS2 4.8.2 (== JVMS7 4.9.2) had a narrative rule that allows early assignment of instance fields of 'this' within an instance initialization method. This rule was not formalized in the Prolog type checking rules by JSR 202, despite HotSpot allowing such assignment in its implementation of the type checking verifier. The Prolog rule for putfield should be augmented to allow such assignment.

      The code below says that if the assignment is to a field in class FieldClassName, and the putfield occurs in an <init> method of the same class FieldClassName, then it's OK if the incoming type state has uninitializedThis for the receiver (which indicates the putfield occurs before another <init> method has been called). Since the field being assigned is so close by, there's no need for passesProtectedCheck.

      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),
          canPop(StackFrame, [FieldType, uninitializedThis], NextStackFrame),
          exceptionStackFrame(StackFrame, ExceptionStackFrame).

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                abuckley Alex Buckley
                Reporter:
                abuckley Alex Buckley
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: