On Wed, 15 Jun 2022 22:43:55 GMT, Paul Sandoz <psan...@openjdk.org> wrote:
>> src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java line >> 729: >> >>> 727: MethodHandle base = PREPEND_BASE; >>> 728: if (base == null) { >>> 729: base = PREPEND_BASE = MethodHandles.dropArguments( >> >> I'm curious about this idiom - couldn't this result in the `PREPEND_BASE` >> field being assigned twice, with objects that are morally identical, but >> could have different identities? (thus violating `@Stable` contract) > > It's not a violation, it's relying on behavior not discussed by the `@Stable` > doc, which refers to such behavior as "undefined". > > It's a carefully correlated dance between the code, interpreter, and C2 > relying on: > 1. safe publication of equivalent immutable structures with no dependence on > their identity when operating on them; > 2. the field being set in the interpreter; and > 3. by the time C2 inlines `prependBase` the field is no longer be updated, > thus C2 can replace the field access with its value. Thanks, I think I was missing (2) ------------- PR: https://git.openjdk.org/jdk/pull/9154