-
Bug
-
Resolution: Fixed
-
P2
-
17.0.5
Extracted from: https://github.com/eclipse-openj9/openj9/issues/16524
public class AcceptInvalid01 {
public AcceptInvalid01() {
this.field = new InputMethodEvent((Component)null, -100, (TextHitInfo)null, (TextHitInfo)null);
super();
}
public static void main(String[] var0) {
}
}
The above decompiled class is an invalid class (per the JLS), which was generated by a jasm file. IBM J9 VM accepts this "invalid" classfile while hotspot rejects it with:
Caused by: java.lang.VerifyError: Bad type on operand stack in putfield
Exception Details:
Location:
AcceptInvalid01.<init>()V @22: putfield
Reason:
Type uninitializedThis (current frame, stack[0]) is not assignable to 'AcceptInvalid01' (constant pool 4)
Current Frame:
bci: @22
flags: { flagThisUninit }
locals: { uninitializedThis }
stack: { uninitializedThis, 'java/awt/event/InputMethodEvent' }
Bytecode:
0000000: 2abb 0003 5901 c000 0110 9c01 c000 0601
0000010: c000 06b7 0005 b500 042a b700 02b1
However the JVMS states:
4.9.2 Structural Constraints
...
each instance initialization method, except for the instance initialization method
derived from the constructor of class Object, must call either another instance
initialization method of this or an instance initialization method of its direct
superclass super before its instance members are accessed.
However, instance fields of this that are declared in the current class may be
assigned by putfield before calling any instance initialization method. <--------
4.10 Verification of class Files
...
putfield
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 is FieldType, declared in a class FieldClassName.
FieldClassName must not be an array type
If the instruction occurs in an instance initialization method of the class
FieldClassName, then one can validly pop types matching FieldType and
uninitializedThis off the incoming operand stack yielding the outgoing
type state. This allows instance fields of this that are declared in the current
class to be assigned prior to complete initialization of this. <---------
Based on the JVM Spec above, my understand is that this behavior shouldn't be captured as the assignment via putfield is totally valid & allowed before completing the initialization of this in the instance initialization method of the current class.
public class AcceptInvalid01 {
public AcceptInvalid01() {
this.field = new InputMethodEvent((Component)null, -100, (TextHitInfo)null, (TextHitInfo)null);
super();
}
public static void main(String[] var0) {
}
}
The above decompiled class is an invalid class (per the JLS), which was generated by a jasm file. IBM J9 VM accepts this "invalid" classfile while hotspot rejects it with:
Caused by: java.lang.VerifyError: Bad type on operand stack in putfield
Exception Details:
Location:
AcceptInvalid01.<init>()V @22: putfield
Reason:
Type uninitializedThis (current frame, stack[0]) is not assignable to 'AcceptInvalid01' (constant pool 4)
Current Frame:
bci: @22
flags: { flagThisUninit }
locals: { uninitializedThis }
stack: { uninitializedThis, 'java/awt/event/InputMethodEvent' }
Bytecode:
0000000: 2abb 0003 5901 c000 0110 9c01 c000 0601
0000010: c000 06b7 0005 b500 042a b700 02b1
However the JVMS states:
4.9.2 Structural Constraints
...
each instance initialization method, except for the instance initialization method
derived from the constructor of class Object, must call either another instance
initialization method of this or an instance initialization method of its direct
superclass super before its instance members are accessed.
However, instance fields of this that are declared in the current class may be
assigned by putfield before calling any instance initialization method. <--------
4.10 Verification of class Files
...
putfield
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 is FieldType, declared in a class FieldClassName.
FieldClassName must not be an array type
If the instruction occurs in an instance initialization method of the class
FieldClassName, then one can validly pop types matching FieldType and
uninitializedThis off the incoming operand stack yielding the outgoing
type state. This allows instance fields of this that are declared in the current
class to be assigned prior to complete initialization of this. <---------
Based on the JVM Spec above, my understand is that this behavior shouldn't be captured as the assignment via putfield is totally valid & allowed before completing the initialization of this in the instance initialization method of the current class.
- duplicates
-
JDK-8301601 Hotspot caught an error that should not have been caught according to the spec
-
- Closed
-
- relates to
-
JDK-8159747 4.10.1.9: Clarify that putfield can early-assign to fields of 'this'
-
- Closed
-