// If the `ThreadLocalRandom` class is not yet initialized, do the `VarHandle` operation // without creating a managed `MethodType` object. This avoids a circular initialization // issue when `ThreadLocalRandom.<clinit>` indirectly calls `AtomicLong.compareAndSet()` // (implemented with a `VarHandle`) and the `MethodType` caching circles back to the // `ThreadLocalRandom` with uninitialized `seeder` and throws NPE. // // Do a quick test for "visibly initialized" without a read barrier and, if that fails, // do a thorough test for "initialized" (including load acquire) with the read barrier. if (LIKELY(WellKnownClasses::java_util_concurrent_ThreadLocalRandom
.Get<kWithoutReadBarrier>()
->IsVisiblyInitialized()) ||
WellKnownClasses::java_util_concurrent_ThreadLocalRandom->IsInitialized()) {
Handle<mirror::MethodType> callsite_type(hs.NewHandle(
class_linker->ResolveMethodType(self, callsite_type_id, dex_cache, class_loader)));
if (LIKELY(callsite_type != nullptr)) { return VarHandleInvokeAccessor(self,
shadow_frame,
var_handle,
callsite_type,
access_mode,
operands,
result);
} // This implies we couldn't resolve one or more types in this VarHandle, // or we could not allocate the `MethodType` object.
CHECK(self->IsExceptionPending()); if (self->GetException()->GetClass() != WellKnownClasses::java_lang_OutOfMemoryError.Get()) { returnfalse;
} // Clear the OOME and retry without creating an actual `MethodType` object. // This prevents unexpected OOME for trivial `VarHandle` operations. // It also prevents odd situations where a `VarHandle` operation succeeds but the same // operation fails later because the `MethodType` object was evicted from the `DexCache` // and we suddenly run out of memory to allocate a new one. // // We have previously seen OOMEs in the run-test `183-rmw-stress-test` with // `--optimizng --no-image` (boot class path methods run in interpreter without JIT) // but it probably happened on the first execution of a trivial `VarHandle` operation // and not due to the `DexCache` eviction mentioned above.
self->ClearException();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.