Questions about "flagThisUninit"

Johannes Spangenberg johannes.spangenberg at hotmail.de
Wed Jul 29 19:11:38 UTC 2020


Hello, I have two related questions about flagThisUninit.

(1)

I noticed that the JVM of OpenJDK does not allow to put// try-catch 
blocks around the this() or super() call. I found [JDK-8172282] which is 
related to this topic. The verification works by using the 
flagThisUninit flag. I could not find this limitation in the [JVM 
specification] yet. Is it specified somewhere or is it a deviation from 
the specification?

(2)

I fond flagThisUninit mentioned multiple times in [section 4.10.1.].

> If any local variable in Locals has the type uninitializedThis, then 
> Flags has the single element flagThisUninit, otherwise Flags is an 
> empty list.
The same is also described in Prolog. Moreover, the return instruction 
is described to be type safe when flagThisUninit is not set.

> instructionIsTypeSafe(return, Environment, _Offset, StackFrame,
>                        afterGoto, ExceptionStackFrame) :-
>      thisMethodReturnType(Environment, void),
>      StackFrame = frame(_Locals, _OperandStack, Flags),
>      notMember(flagThisUninit, Flags),
>      exceptionStackFrame(StackFrame, ExceptionStackFrame).
Wouldn't it mean that the following constructor is actually valid 
despite it does neither call super() nor this()?

     // access flags 0x1
     public <init>()V
       ICONST_0
       ISTORE 0
       RETURN
       MAXSTACK = 1
       MAXLOCALS = 1

Overwriting variable 0 removes uninitializedThis from the local 
variables and thus also clears flagThisUninit. This is obviously not 
intended and the OpenJDK actually rejects such methods. Do I miss 
something or is it actually a "bug" in the specification?

[JDK-8172282]:
<https://bugs.openjdk.java.net/browse/JDK-8172282>
"Inconsistent class verification of initializers"
[JVM specification]:
<https://docs.oracle.com/javase/specs/jvms/se11/html/index.html>
"The Java® Virtual Machine Specification"
[section 4.10.1.]
<https://docs.oracle.com/javase/specs/jvms/se11/html/jvms-4.html#jvms-4.10.1>
"4.10.1. Verification by Type Checking"



More information about the java-se-spec-comments mailing list