8157181: Compilers accept modification of final fields outside initializer methods

Track initialized final field updates; disable constant folding if an update is detected. Enforce final field update rules introduced by JVMS-7 (but only for JDK 9).

Reviewed-by: vlivanov, dnsimon, forax, never, kvn, coleenp
This commit is contained in:
Zoltan Majo 2016-06-15 14:27:58 +02:00
parent 2ade029123
commit cdc436922a
32 changed files with 284 additions and 75 deletions

View file

@ -759,10 +759,10 @@ static Klass* resolve_field_return_klass(methodHandle caller, int bci, TRAPS) {
// This can be static or non-static field access
Bytecodes::Code code = field_access.code();
// We must load class, initialize class and resolvethe field
// We must load class, initialize class and resolve the field
fieldDescriptor result; // initialize class if needed
constantPoolHandle constants(THREAD, caller->constants());
LinkResolver::resolve_field_access(result, constants, field_access.index(), Bytecodes::java_code(code), CHECK_NULL);
LinkResolver::resolve_field_access(result, constants, field_access.index(), caller, Bytecodes::java_code(code), CHECK_NULL);
return result.field_holder();
}
@ -879,7 +879,7 @@ JRT_ENTRY(void, Runtime1::patch_code(JavaThread* thread, Runtime1::StubID stub_i
fieldDescriptor result; // initialize class if needed
Bytecodes::Code code = field_access.code();
constantPoolHandle constants(THREAD, caller_method->constants());
LinkResolver::resolve_field_access(result, constants, field_access.index(), Bytecodes::java_code(code), CHECK);
LinkResolver::resolve_field_access(result, constants, field_access.index(), caller_method, Bytecodes::java_code(code), CHECK);
patch_field_offset = result.offset();
// If we're patching a field which is volatile then at compile it