RFR: 8295486: Inconsistent constant field values observed during compilation

Jatin Bhateja jbhateja at openjdk.org
Fri Jan 6 08:07:51 UTC 2023


On Thu, 5 Jan 2023 13:26:11 GMT, Tobias Hartmann <thartmann at openjdk.org> wrote:

> We hit a "not monotonic" assert because the new type of a load from a stable final field is more narrow than the old type which contradicts the assumption that types should only go from TOP to BOTTOM during CCP:
> 
> old: `narrowoop: java/lang/Integer:BotPTR:exact *`
> new: `narrowoop: java/lang/Integer java.lang.Integer {0x000000062c41e548} ...`
> 
> or 
> 
> old: `narrowoop: java/lang/Integer java.lang.Integer {0x000000062c41e538} ...`
> new: `narrowoop: java/lang/Integer java.lang.Integer {0x000000062c41e548} ...`
> 
> The problem is that a stable field can be (re-)initialized during compilation and since the value is not cached, contradicting types can be observed. In `LoadNode::Value`, we re-read the field value each time: 
> 
> https://github.com/openjdk/jdk/blob/872384707e89d03ede655aad16f360dc94f10152/src/hotspot/share/opto/memnode.cpp#L1994-L1997
> 
> https://github.com/openjdk/jdk/blob/872384707e89d03ede655aad16f360dc94f10152/src/hotspot/share/opto/type.cpp#L332-L337
> 
> The same problem exists for loads from stable arrays:
> https://github.com/openjdk/jdk/blob/872384707e89d03ede655aad16f360dc94f10152/src/hotspot/share/opto/memnode.cpp#L1923
> 
> Caching the field value is not feasible as it would require a cache per ciInstance for all the fields and per ciArray for all the elements. Alternatively, we could keep track of the lookup and only do it once but that would also be lots of additional complexity for a benign issue.
> 
> Instead, I propose to skip verification during CCP when folding loads from stable fields. Non-stable, constant fields are not affected as `null` is a valid value for them and they would already be folded before CCP.
> 
> Thanks,
> Tobias

Nice test!, problem seems to be intermittent.

src/hotspot/share/opto/phaseX.cpp line 1770:

> 1768:       ((atp->field() != NULL && atp->field()->is_stable()) ||
> 1769:        (adr_type->isa_aryptr() && adr_type->is_aryptr()->is_stable()))) {
> 1770:     return;

As, [per specs](https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/jdk/internal/vm/annotation/Stable.java#L74) Semantics are not clear if a @stable annotated field's values are changed multiple times, in your test case update thread explicitly changes the values of static stable fields. Change looks correct to skip over monotonicity constraint for this corner case

src/hotspot/share/opto/phaseX.cpp line 1779:

> 1777:   }
> 1778:   assert(!told->isa_int() || !tnew->isa_int() || told->isa_int()->_widen <= tnew->isa_int()->_widen, "widen increases");
> 1779:   assert(!told->isa_long() || !tnew->isa_long() || told->isa_long()->_widen <= tnew->isa_long()->_widen, "widen increases");

Minor correction,  told->isa_int()->_widen <= tnew->isa_int()->_widen can be replaced by  told->is_int()->_widen <= tnew->is_int()->_widen, preceding expression makes sure types are ints

-------------

PR: https://git.openjdk.org/jdk/pull/11861


More information about the hotspot-compiler-dev mailing list