diff -r 2251ba078bec -r eb7ce841ccec src/share/vm/c1/c1_GraphBuilder.cpp --- a/src/share/vm/c1/c1_GraphBuilder.cpp Sat Oct 24 16:18:50 2020 +0800 +++ b/src/share/vm/c1/c1_GraphBuilder.cpp Sat Oct 24 16:43:47 2020 +0800 @@ -1705,6 +1705,23 @@ Value replacement = !needs_patching ? _memory->load(load) : load; if (replacement != load) { assert(replacement->is_linked() || !replacement->can_be_linked(), "should already by linked"); + // Writing an (integer) value to a boolean, byte, char or short field includes an implicit narrowing + // conversion. Emit an explicit conversion here to get the correct field value after the write. + BasicType bt = field->type()->basic_type(); + switch (bt) { + case T_BOOLEAN: + case T_BYTE: + replacement = append(new Convert(Bytecodes::_i2b, replacement, as_ValueType(bt))); + break; + case T_CHAR: + replacement = append(new Convert(Bytecodes::_i2c, replacement, as_ValueType(bt))); + break; + case T_SHORT: + replacement = append(new Convert(Bytecodes::_i2s, replacement, as_ValueType(bt))); + break; + default: + break; + } push(type, replacement); } else { push(type, append(load)); @@ -2376,7 +2393,7 @@ if (!has_handler() && (!instruction->needs_exception_state() || instruction->exception_state() != NULL)) { assert(instruction->exception_state() == NULL || instruction->exception_state()->kind() == ValueStack::EmptyExceptionState - || (instruction->exception_state()->kind() == ValueStack::ExceptionState && _compilation->env()->jvmti_can_access_local_variables()), + || (instruction->exception_state()->kind() == ValueStack::ExceptionState && _compilation->env()->should_retain_local_variables()), "exception_state should be of exception kind"); return new XHandlers(); } @@ -2467,7 +2484,7 @@ // This scope and all callees do not handle exceptions, so the local // variables of this scope are not needed. However, the scope itself is // required for a correct exception stack trace -> clear out the locals. - if (_compilation->env()->jvmti_can_access_local_variables()) { + if (_compilation->env()->should_retain_local_variables()) { cur_state = cur_state->copy(ValueStack::ExceptionState, cur_state->bci()); } else { cur_state = cur_state->copy(ValueStack::EmptyExceptionState, cur_state->bci()); @@ -3353,7 +3370,7 @@ ValueStack* GraphBuilder::copy_state_for_exception_with_bci(int bci) { ValueStack* s = copy_state_exhandling_with_bci(bci); if (s == NULL) { - if (_compilation->env()->jvmti_can_access_local_variables()) { + if (_compilation->env()->should_retain_local_variables()) { s = state()->copy(ValueStack::ExceptionState, bci); } else { s = state()->copy(ValueStack::EmptyExceptionState, bci);