René's URL Explorer Experiment


Title: fix(DexFactory): GC before registering injected proxies by edusperoni · Pull Request #2110 · NativeScript/android · GitHub

Open Graph Title: fix(DexFactory): GC before registering injected proxies by edusperoni · Pull Request #2110 · NativeScript/android

X Title: fix(DexFactory): GC before registering injected proxies by edusperoni · Pull Request #2110 · NativeScript/android

Description: Description The crash. Apps intermittently die with a native crash when the main runtime generates a proxy class at runtime, i.e. an extend() the static binding generator didn't see: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x8 #00 libart.so art::mirror::String::ToModifiedUtf8()+16 #01 libart.so art::ClassLinker::RegisterDexFileLocked(...)+148 #02 libart.so art::ClassLinker::RegisterDexFile(...) #03 libart.so art::ClassLinker::DefineClass(...) #04 libart.so art::ClassLinker::FindClassInBaseDexClassLoader(...) #05 libart.so VMClassLoader_findLoadedClass java.lang.ClassLoader.loadClass ← com.tns.DexFactory.resolveClass ← MetadataNode::ExtendMethodCallback It shows up in our test suite on the API 36 emulator, a few times a day across runs. Cause: an ART GC bug. ClassLinker::AllocDexCache stores the dex location into the new DexCache, then RegisterDexFile waits in a ScopedGCCriticalSection for an in-flight collection. After that wait, DexCache::location_ reads back as null, while class_loader_ and dex_file_ (stored after the wait) are intact. RegisterDexFileLocked then dereferences the null location. The tombstone heap dumps show this directly, and in some crashes the location String is still on the heap right after the DexCache. What we found out: It reproduces in a plain Android app with no NativeScript code. It happens with ART's mark-compact collector (CMC), in generational mode (the default on this image) and, less often, in non-generational mode. It needs the dex to be registered with a long-lived class loader, which is what DexFactory does for main-runtime proxies since #1968 (addDexPath into the app's PathClassLoader, so Class.forName finds them). With a fresh DexClassLoader per jar it never crashed, but that would lose Class.forName visibility. It needs a burst of reference-heavy allocation right before registration. Proxy generation (ASMDEX) is exactly that. We're filing it with the ART team separately, with the standalone repro. The workaround. A blocking Runtime.getRuntime().gc() immediately before the injected dex is registered, so no collection is in flight when RegisterDexFile runs. Results: Setup Without With gc() Stress harness in the test app, realistic allocation 37/100 runs crashed 0/40 Stress harness, adversarial background allocator, n=800 7/30 0/20 Standalone repro app (no NativeScript), generational CMC 29/40 0/30 Standalone repro app, non-generational CMC 9/40 0/20 Stress harness, adversarial background allocator, n=3000 3/6 1/4 It isn't a guarantee. When another thread allocates non-stop, a background GC queued behind the explicit one can start right after it. That still cut crashes about tenfold (1 crash in ~27k registrations). Cost. One explicit GC, about 4–14 ms on test-suite-sized heaps and more on large heaps, on the first use of each runtime-generated proxy in a process. Since #2101 the prebuilt classes are found, so runtime generation only happens for extends the generator can't see: rare in production builds, but every extend in HMR dev mode. The full test suite ran in 116 s with the change, against 117–121 s without. Only where the collector may be mark-compact. ProxyRegistrationGc decides once per process, on the first injection, whether the collection is needed: Below API 31: skipped. ART only became updatable through Play system updates in Android 12, so these devices can't be running mark-compact. API 31+: skipped only when /proc/self/maps positively identifies the concurrent-copying collector. That means [anon:dalvik-...] mappings containing concurrent copying or (region space), and none containing mark-compact / Mark Compact. Both sets of names come from ART's collector setup; I checked them on API 33 (ART module 331711080) and API 36 (361153460) processes. Anything else collects: mark-compact (generational or not), an unrecognized collector, renamed mappings in a future ART, kernels without anonymous VMA names, or an unreadable maps file. Being wrong in that direction costs a few milliseconds; being wrong the other way would mean a crash. Does your commit message include the wording below to reference a specific issue in this repo? No issue. Related Pull Requests #1951 / #1968 added the injection into the app's PathClassLoader. #2101 made prebuilt classes load for anonymous extends, which keeps runtime generation rare. Does your pull request have unit tests? Yes, for the guard. testProxyRegistrationGc.js checks the decision on synthetic maps: mark-compact collects concurrent copying skips below API 31 skips unnamed mappings collect an unknown collector collects mixed names collect the live check: the decision matches the collector the test process is actually running The GC race itself needs hundreds of registrations under allocation pressure to show up, so it's covered by the stress numbers above rather than a suite spec. ./gradlew runtestsAndVerifyResults -Pabis=arm64-v8a, full suite: Emulator Collector Specs Failures Explicit GCs logged by the test app API 36 (ART 361153460) mark-compact 1552 0 134 API 33 (ART 331711080) concurrent copying 1552 0 20 (the tests' own System.gc() calls) Summary by CodeRabbit Bug Fixes Improved runtime reliability when loading generated classes in supported Android configurations by performing garbage collection before class-loader injection when required. Existing isolated class loading remains available when injection conditions are not met.

Open Graph Description: Description The crash. Apps intermittently die with a native crash when the main runtime generates a proxy class at runtime, i.e. an extend() the static binding generator didn't see: signal 11 ...

X Description: Description The crash. Apps intermittently die with a native crash when the main runtime generates a proxy class at runtime, i.e. an extend() the static binding generator didn't see: signal...

Opengraph URL: https://github.com/NativeScript/android/pull/2110

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:2ebdc4b8-9069-a872-1476-ba0fb11528cd
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id93AC:23CF06:2099D4A:298B7B8:6B015F7D
html-safe-nonce23883e180f57f3dce624e6b9484bc222983c4f0bb6515608e76ab07a7e661efc
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5M0FDOjIzQ0YwNjoyMDk5RDRBOjI5OEI3Qjg6NkIwMTVGN0QiLCJ2aXNpdG9yX2lkIjoiNjMxNjA0NTkzMDgxMDQwMDYzOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac518d4e7dbbd95ba2f7424e436cd3a9828adf2d6ad156119e9e6a590c3467a905
hovercard-subject-tagpull_request:5280852217
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/NativeScript/android/pull/2110/files
twitter:imagehttps://avatars.githubusercontent.com/u/4061767?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/4061767?s=400&v=4
og:image:altDescription The crash. Apps intermittently die with a native crash when the main runtime generates a proxy class at runtime, i.e. an extend() the static binding generator didn't see: signal 11 ...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/NativeScript/android git https://github.com/NativeScript/android.git
octolytics-dimension-user_id7392261
octolytics-dimension-user_loginNativeScript
octolytics-dimension-repository_id29137950
octolytics-dimension-repository_nwoNativeScript/android
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id29137950
octolytics-dimension-repository_network_root_nwoNativeScript/android
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/NativeScript/android/pull/2110/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FNativeScript%2Fandroid%2Fpull%2F2110%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FNativeScript%2Fandroid%2Fpull%2F2110%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=NativeScript%2Fandroid
Reloadhttps://github.com/NativeScript/android/pull/2110/files
Reloadhttps://github.com/NativeScript/android/pull/2110/files
Reloadhttps://github.com/NativeScript/android/pull/2110/files
NativeScripthttps://github.com/NativeScript
androidhttps://github.com/NativeScript/android
Codehttps://github.com/NativeScript/android
Issues106 (106)https://github.com/NativeScript/android/issues
Pull requests26 (26)https://github.com/NativeScript/android/pulls
Actionshttps://github.com/NativeScript/android/actions
Projectshttps://github.com/NativeScript/android/projects
Wikihttps://github.com/NativeScript/android/wiki
Security and qualityhttps://github.com/NativeScript/android/security
Insightshttps://github.com/NativeScript/android/insights
Sign up for GitHub https://github.com/signup?return_to=%2FNativeScript%2Fandroid%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2FNativeScript%2Fandroid%2Fissues%2Fnew%2Fchoose
edusperonihttps://github.com/edusperoni
mainhttps://github.com/NativeScript/android/tree/main
fix/dexfactory-gc-before-injecthttps://github.com/NativeScript/android/tree/fix/dexfactory-gc-before-inject
Conversation 1 https://github.com/NativeScript/android/pull/2110
Commits 2 https://github.com/NativeScript/android/pull/2110/commits
Checks 8 https://github.com/NativeScript/android/pull/2110/checks
Files changed https://github.com/NativeScript/android/pull/2110/files
Please reload this pagehttps://github.com/NativeScript/android/pull/2110/files
fix(DexFactory): GC before registering injected proxies https://github.com/NativeScript/android/pull/2110/files#top
Show all changes 2 commits https://github.com/NativeScript/android/pull/2110/files
3d60dfa fix(DexFactory): collect before registering a proxy with the app clas… edusperoni Nov 12, 2026 https://github.com/NativeScript/android/pull/2110/commits/3d60dfa6dd5b1b4fd8ff4da87c5324da31a9ea30
1fe902b fix(DexFactory): only collect when the collector may be mark-compact edusperoni Nov 12, 2026 https://github.com/NativeScript/android/pull/2110/commits/1fe902beeddf582189a5476fa28e49041673b291
Clear filters https://github.com/NativeScript/android/pull/2110/files
Please reload this pagehttps://github.com/NativeScript/android/pull/2110/files
Please reload this pagehttps://github.com/NativeScript/android/pull/2110/files
mainpage.js https://github.com/NativeScript/android/pull/2110/files#diff-b7fd6c22bfc29391e9e3ed935d6c6194b1ad595c7592690229952b5ddb99c0d5
testProxyRegistrationGc.js https://github.com/NativeScript/android/pull/2110/files#diff-39766a38cb03c72b09c693720912f23fc185787b1b056f6b2e629fb178a76a8a
DexFactory.java https://github.com/NativeScript/android/pull/2110/files#diff-7f8ef213b415ed89638d410cdc1813a95a7aafb2b6ae962e4862099ae1a8f95d
ProxyRegistrationGc.java https://github.com/NativeScript/android/pull/2110/files#diff-ad80272813dd4db0b4ba070e3a17d89c3f286308d03b7e84dd731b0877faa295
test-app/app/src/main/assets/app/mainpage.jshttps://github.com/NativeScript/android/pull/2110/files#diff-b7fd6c22bfc29391e9e3ed935d6c6194b1ad595c7592690229952b5ddb99c0d5
View file https://github.com/NativeScript/android/blob/1fe902beeddf582189a5476fa28e49041673b291/test-app/app/src/main/assets/app/mainpage.js
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/android/pull/2110/{{ revealButtonHref }}
https://github.com/NativeScript/android/pull/2110/files#diff-b7fd6c22bfc29391e9e3ed935d6c6194b1ad595c7592690229952b5ddb99c0d5
https://github.com/NativeScript/android/pull/2110/files#diff-b7fd6c22bfc29391e9e3ed935d6c6194b1ad595c7592690229952b5ddb99c0d5
test-app/app/src/main/assets/app/tests/testProxyRegistrationGc.jshttps://github.com/NativeScript/android/pull/2110/files#diff-39766a38cb03c72b09c693720912f23fc185787b1b056f6b2e629fb178a76a8a
View file https://github.com/NativeScript/android/blob/1fe902beeddf582189a5476fa28e49041673b291/test-app/app/src/main/assets/app/tests/testProxyRegistrationGc.js
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/android/pull/2110/{{ revealButtonHref }}
test-app/runtime/src/main/java/com/tns/DexFactory.javahttps://github.com/NativeScript/android/pull/2110/files#diff-7f8ef213b415ed89638d410cdc1813a95a7aafb2b6ae962e4862099ae1a8f95d
View file https://github.com/NativeScript/android/blob/1fe902beeddf582189a5476fa28e49041673b291/test-app/runtime/src/main/java/com/tns/DexFactory.java
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/android/pull/2110/{{ revealButtonHref }}
https://github.com/NativeScript/android/pull/2110/files#diff-7f8ef213b415ed89638d410cdc1813a95a7aafb2b6ae962e4862099ae1a8f95d
https://github.com/NativeScript/android/pull/2110/files#diff-7f8ef213b415ed89638d410cdc1813a95a7aafb2b6ae962e4862099ae1a8f95d
test-app/runtime/src/main/java/com/tns/ProxyRegistrationGc.javahttps://github.com/NativeScript/android/pull/2110/files#diff-ad80272813dd4db0b4ba070e3a17d89c3f286308d03b7e84dd731b0877faa295
View file https://github.com/NativeScript/android/blob/1fe902beeddf582189a5476fa28e49041673b291/test-app/runtime/src/main/java/com/tns/ProxyRegistrationGc.java
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/android/pull/2110/{{ revealButtonHref }}
Please reload this pagehttps://github.com/NativeScript/android/pull/2110/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.