JDK-4475252 : constant expr limits neglected by vmspec/ 4.10 Limitations
  • Type: Enhancement
  • Component: specification
  • Sub-Component: vm
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2001-06-27
  • Updated: 2012-10-09
  • Resolved: 2007-06-20
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 :  
Relates :  
Description

Name: bsC130419			Date: 06/27/2001


E:\j>java -version
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

> http://java.sun.com/docs/books/vmspec/2nd-edition/html/VMSpecTOC.doc.html
> http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html
> 4.10 Limitations of the Java Virtual Machine

> The following limitations of the Java virtual machine
> are implicit in the class file format:
> [1] ...
> [2] ...
> ...
> [11] The length of ... constant string values is limited ...

Please complete the misleading beginning quoted above.  How about some
additional text along the lines of:

[12] For the field_info to show that a particular static field is initialised
by assignment of an evaluated constant expression even before <clinit> or
<init> runs, the evaluation of that constant expression has to completely
normally at compile-time and then produce a value of primitive type or a not-
null value of String type whose UTF8 length does not exceed xFFFF.

I believe the vmspec/2nd-edition/ nowhere mentions this exquisitely implicit
limitation nor the two viciously troublesome examples of initialising fields
with null and initialising fields with integral division by zero.

> ... constant ... a not-null value ...

I have failed to imagine a rationale for refusing to accept a null as a fully
constant expression - so I'm guessing the exclusion of null was an unconscious
oversight?

> ... constant ... UTF8 length does not exceed xFFFF ...

I do appreciate seeing mentioned already the troublesome example of
initialising a field with a String whose UTF8 length exceeds xFFFF.

I can imagine a practical rationale for refusing to accept long strings as
fully constant expressions ... yet, this rationale seems to collide with the
JLS chapter 3 attitude of rejecting out-of-hand any attempt to guess of which
maximum String length is enough forever?

> ... viciously troublesome ...

  To this very day we see posted without annotation at the end of
<http://java.sun.com/docs/books/jls/clarify.html> an incorrect clarification of
the JLS that erroneously claims that a null literal can be a fully constant
expression, merely because it is a literal expression.

> ... viciously troublesome ...

jls/second_edition/ 15.28 Constant Expression likewise does not mention these
issues.

Searching at:

http://developer.java.sun.com/developer/bugParade/index.jshtml

for:

+4.10 +vmspec limitations
+4.10 +specification limitations
+constant +null
+long +String

suggests the list of related bugs includes at least:

  Synopsis = JLS should define null as a compile time constant
  Category = java:specification
http://developer.java.sun.com/developer/bugParade/bugs/4083093.html

  Synopsis = JLS doesnt specify behavior for 1/0 as a constant
expression
  Category = java:specification
http://developer.java.sun.com/developer/bugParade/bugs/4178182.html

  Synopsis = ... very long String in my program ...
  Category = java:compiler
http://developer.java.sun.com/developer/bugParade/bugs/4353007.html

  Synopsis = Compiler silently generates bytecode that exceeds VM limits
  Category = java:compiler
http://developer.java.sun.com/developer/bugParade/bugs/4309152.html

  Synopsis = misleadingly incomplete xref in JLS2 15.28 Constant
Expression
  Category = java:specification
http://developer.java.sun.com/developer/bugParade/bugs/4396260.html

Thanks in advance.    Pat LaVarre

P.S. I'll here spell out "Java Virtual Machine Specification" to let searches
for that string hit here no matter that til now I spoke only of the vmspec/2nd-
edition/.
(Review ID: 127462) 
======================================================================

Comments
EVALUATION The "limit" in [12] is essentially that a compile-time constant expression must evaluate without error at compile-time. That is not a JVMS issue. At most, it's an issue for a compiler spec. There was a time when null and divides-by-zero were legal compile-time constant expressions - so could be stored in ConstantValue and screw up class initialization - but not anymore, so no change in limitations is justified there. Compile-time constant expressions which are strings >65536 chars in length are already outlawed in the limitations, but I will add a note about ConstantValue attributes being affected.
20-06-2007

WORK AROUND Name: bsC130419 Date: 06/27/2001 Read and understand in depth how to compile Java for the JVM before you involve yourself in compiling Java for any other target machine, for example before you try to write an unsigned applet to compile Java to run on a java.lang.reflect platform. ======================================================================
11-06-2004

EVALUATION Yes. A lot of this has been corrected in the 3rd edition draft of the JLS, but the JVM sections have not. ###@###.### 2001-10-25 I think some of the suggested additions are not entirely appropriate: The suggested 4.10[12], for example, attempts to put language definition into the VM specification. null is not a constant expression because its value cannot be expressed in the VM's constant pool. ###@###.### 2001-11-01
01-11-2001