JDK-6527033 : ACC_SUPER option should be clarified
  • Type: Bug
  • Component: specification
  • Sub-Component: vm
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2007-02-21
  • Updated: 2012-11-05
  • Resolved: 2007-03-22
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 1.6Fixed
Related Reports
Relates :  
Description
Class flag ACC_SUPER is mentioned in 2 places of JVMS 2ed:

Section 4.1 The ClassFile Structure:

"The setting of the ACC_SUPER flag indicates which of two alternative semantics for its invokespecial instruction the Java virtual machine is to express; the ACC_SUPER flag exists for backward compatibility for code compiled by Sun's older compilers for the Java programming language. All new implementations of the Java virtual machine should implement the semantics for invokespecial documented in this specification. All new compilers to the instruction set of the Java virtual machine should set the ACC_SUPER flag. Sun's older compilers generated ClassFile flags with ACC_SUPER unset. Sun's older Java virtual machine implementations ignore the flag if it is set."

Section 6 The Java Virtual Machine Instruction Set 
Description of invokespecial:

"Next, the resolved method is selected for invocation unless all of the following conditions are true: invokespecial001 

    * The ACC_SUPER flag (see Table 4.1, "Class access and property modifiers") is set for the current class.

    * The class of the resolved method is a superclass of the current class.

    * The resolved method is not an instance initialization method (��3.9). 
......
"



There are following confusions:
1. Phrase "ACC_SUPER flag indicates which of two alternative semantics for its invokespecial instruction the Java virtual machine is to express" looks like requirement to be able to implement any of two possible semantics and make choice depending on this flag.
By other hand there is another phrase: "All new implementations of the Java virtual machine should implement the semantics for invokespecial documented in this specification."

There are two options of interpretation of this phrase:
* this specification provides some semantic of invokespecial instruction, such new semantic should be implemented and value of ACC_SUPER flag should be ignored. Howerver, such interpretation contadicts with above mentioned phrase "ACC_SUPER flag indicates which of two alternative semantic..."
* this specification provides provides semantic for both cases - for ACC_SUPER set to 1 as well as for ACC_SUPER set to 0. Contents of invokespecial part of section 6 implies that such interpretation is correct however there are a couple of issues here:
** such contents is not visible from section 4.1 making interpretation harder
** phrase "All new implementations of the Java virtual machine should implement the semantics for invokespecial documented in this specification." look redundant in such case because such phrase is applicable to any semantics of any instruction documented in this specification. Why should we claim such requirement for one specific piece of spec ? 
Such redundant claim may imply idea that first option of interpretation more relevant (in other words "let's ignore value of ACC_SUPER and implement what is described here").

I think it would be nice provide some general description of differences between old and new semantics in section 4.1. Another option is to add special section describing such differences with sevral examples at the end of chapter 4 with hyperlink to it located in section 4.1.


2. What does mean new/old compilers and VMs ?  (precise versions of specification and Sun's JDK shoul be specified)

3. Construction of description in invokespecial part of Section 6 is not clear because condition involing ACC_SUPER flag is mixed with another conditions. It would be better to write something like this:

"Semantic of invokespecial depends on value of flag ACC_SUPER. If it is set then new semantics is applied. It means that special method lookup procedure is used if following conditions are both true:

# The class of the resolved method is a superclass of the current class.

# The resolved method is not an instance initialization method (��3.9).

"
then description of lookup procedure and phrase

"if ACC_SUPER is clear then lookup procedure is not applied"

It would be better because it will emphasize meaning of ACC_SUPER flag.

Comments
EVALUATION There are evidently two semantics for invokespecial: 1) the semantic in JVMS 2ed (do X unless ACC_SUPER is set, in which case do Y) 2) an old semantic implemented by "older" VMs (do Z regardless of ACC_SUPER is set or unset) Even JVMS 1ed, which documents JDK 1.0.2, understands ACC_SUPER being set, so (2) must be REALLY old and I don't want to say anymore about it. Exactly which pre-1.0.2 javac/JVM didn't use ACC_SUPER is lost to history. I will rearrange JVMS 3ed 4.1 to make it slightly less twisty: "The ACC_SUPER flag exists for backward compatibility for code compiled by Sun���s older compilers for the Java programming language. The setting of the flag indicates which of two alternative semantics for its invokespecial instruction the Java virtual machine is to express. Compilers to the instruction set of the Java virtual machine should set the ACC_SUPER flag." (plus a footnote about pre-1.0.2 compilers and VMs not setting ACC_SUPER) Adding examples to ��4.1 and rewording ��6 could happen, but won't.
2007-02-21