Repository navigation
fix(android): synchronize ArgConverter's per-runtime long cache - #96
Open
NathanWalker wants to merge 1 commit into
Open
NathanWalker wants to merge 1 commit into
NathanWalker wants to merge 1 commit into
Conversation
s_type_long_operations_cache is process-wide, but each runtime inserts its entry on init and erases it on dispose from its own thread. Make it a tns::ConcurrentMap, as MetadataNode's per-runtime cache already is, in both the napi and jsi trees. Fixes #93
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
This was referenced Oct 26, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #93.
Summary
ArgConverter::s_type_long_operations_cacheis process-wide, but each runtime touches its own entry from its own thread:ArgConverter::Init→GetTypeLongCache(), when the runtime starts;GetTypeLongCache(), for eachlongoutside ±2^53 and in theNativeScriptLongNumberconstructor;onDisposeEnv()/onDisposeRuntime(), when the runtime is disposed.robin_hood's flat map moves entries when it rehashes or erases, so a worker that starts or stops can move another runtime's entry while that runtime is reading it.Get/Insert/Removepattern asMetadataNode's per-runtime cache. Mirrored in the napi and jsi trees.NativeScriptLongNumberconstruction, and atInit. Small longs never reach it.Evidence
Emulator (API 36, arm64), V8. HWASan was enabled locally by uncommenting the
-fsanitize=hwaddresslines inruntime/CMakeLists.txt.Long.parseLong,Long.MAX_VALUE,longValue()), allocates Java objects, and forces JS and Java GC. The main runtime forces GC every 25 ms. The runs include fix(android): deliver GC notifications under a per-runtime lock #91, so its GC-thread crash doesn't hide this one.ArgConverter::ConvertFromJavaLong, reading a cache entry that held string bytes (",9007199")ConvertFromJavaLong; one was an HWASan tag-mismatch insideGetTypeLongCacheConsole::s_rtToConsoleTimersMapraces increateConsole. It crashed every jsi run until it was locked for the test.JSR::env_to_jsr_cacheinnapi/v8/jsr.cpp.Constants::APP_ROOT_FOLDER_PATH, which every worker writes inRuntime::Init.MetadataNode::s_arrayObjectsand theGlobalHelperssmart-stringify map.Merge Danger
Door: two-way
Blast Radius: Java
long↔ JS conversion for values outside ±2^53, on every Android runtime (main and workers, both binding layers)It adds a spin lock around a map that had no synchronization. There is no new lock ordering, because the lock is never held while calling into JS or JNI.