[9] RFR (S): 8157181: Compilers accept modification of final fields outside initializer methods
Zoltán Majó
zoltan.majo at oracle.com
Wed May 18 08:54:05 UTC 2016
Hi,
please review the patch for 8157181.
https://bugs.openjdk.java.net/browse/JDK-8157181
Problem: According to the Java VM Specification, the putstatic bytecode
is allowed to modify a final field only
- (1) if the field is declared in the current class (the class that
declares the current method) and
- (2) if the putstatic instruction appears in the class or interface
initializer method <clinit> of the current class.
If any of the conditions above does not hold, an IllegalAccessError must
be thrown. Similar conditions apply for putfield bytecodes targeting
final fields.
Currently, HotSpot checks only condition (1) but not (2) [1]. Methods
that do not satisfy condition (2) violate the assumptions of the
compilers (e.g., at [2]). Compiling such methods results in different
behavior of compiled and interpreted code. The bug report describes such
a case in detail.
Solution: Bail out compilation of methods that do not satisfy condition (2).
Webrev:
http://cr.openjdk.java.net/~zmajo/8157181/webrev.00/
Testing:
- JPRT
- local testing with reproducer.
It seems to me that the interpeter is affected by a related problem
(i.e., the interpreter does not throw an IllegalAccessError if (2) does
not hold). I'd prefer to file a separate bug for that problem.
Thank you!
Best regards,
Zoltan
[1]:
http://hg.openjdk.java.net/jdk9/hs-comp/hotspot/file/07a5eceac654/src/share/vm/interpreter/linkResolver.cpp#l910
[2]:
http://hg.openjdk.java.net/jdk9/hs-comp/hotspot/file/07a5eceac654/src/share/vm/opto/parse3.cpp#l303
More information about the hotspot-compiler-dev
mailing list