René's URL Explorer Experiment


Title: fix: keep the base class of runtime-resolved types in large apps by edusperoni · Pull Request #2111 · NativeScript/android · GitHub

Open Graph Title: fix: keep the base class of runtime-resolved types in large apps by edusperoni · Pull Request #2111 · NativeScript/android

X Title: fix: keep the base class of runtime-resolved types in large apps by edusperoni · Pull Request #2111 · NativeScript/android

Description: Description The symptom. In a large app, iterating Java collections from JS stops working: const it = map.entrySet().iterator(); while (it.hasNext()) { … } // TypeError: it.hasNext is not a function jsonObject.keys().hasNext(); // TypeError: … hasNext is not a function unmodifiableList.iterator(); // TypeError: … iterator is not a function ArrayList.iterator() keeps working, and so does everything else in the app, which makes it look like something specific to iterators. Cause. These objects are instances of private JDK classes (java.util.HashMap$EntryIterator, java.util.LinkedHashMap$LinkedKeyIterator, java.util.Collections$UnmodifiableRandomAccessList, …) that are not in the static metadata, so the runtime resolves them on first use and appends a node for each to the metadata node table. For such a type the base class was stored as a 16-bit node id, the same slot a static class record uses. But appended nodes sit after the static nodes plus a 1000-slot gap, so once the static tree has more than about 64.5k nodes their ids no longer fit: the id wraps and the type is linked to an unrelated node as its base. The JS wrapper then has the members the class itself declares and nothing from its real base class: Runtime class Real base (also runtime-resolved) Member lost HashMap$KeyIterator / ValueIterator / EntryIterator HashMap$HashIterator hasNext() LinkedHashMap$Linked*Iterator (also JSONObject.keys()) LinkedHashMap$LinkedHashIterator hasNext() TreeMap$*Iterator, ConcurrentHashMap$*Iterator their private base iterators hasNext() Collections$UnmodifiableList, $SynchronizedList, List.of(…) their private base collections iterator() A type whose base class is in the static metadata (ArrayList$Itr extends Object) is linked correctly, which is why only some collections break. Nothing in this path changed recently; it is a size cliff. An app gets there by growing: a newer compile SDK (android-36 alone has 246 more classes than android-35) or more dependencies. The fix. A runtime-resolved type holds its base class as a node pointer (MetadataTreeNode::runtimeBaseClass), and GetBaseClassNode returns it. The value record keeps its layout, with the id slot unused. Node ids are 32-bit wherever a runtime-created node can appear. The other place is the element type of an array (ARRAY_OFFSET + id), which was narrowed to 16 bits the same way. Runtime-created nodes are numbered from 65536 in every app, in their own vector, instead of right after the static ones. Static ids are 16-bit by format, so the two ranges never overlap, and the wide-id path now runs in a small app too. That is what lets the test app cover this. The unused 1000-slot gap in the static table is gone. Thread safety. The metadata tree is shared by every runtime in the process, and auditing it for this change turned up two existing races around runtime-resolved nodes: A runtime-resolved type was appended to its parent's children vector under the reader's state lock, but MetadataNode walks those vectors with no lock in four places: building a package object, defining a class's inner types, looking up a package member, and creating the top-level namespaces. A worker resolving HashMap$KeyIterator while another runtime materializes java.util.HashMap could reallocate the vector mid-iteration. Two runtimes resolving the same unknown type at once could each publish a node for it: resolving the base class can release the lock, after the only re-check. That was benign (a duplicate node). Both are closed without adding a lock to any MetadataNode path: Nodes created at run time go into a table the reader owns, keyed by parent, and are never appended to MetadataTreeNode::children. The static tree is written only while it is built at startup, so walking it unlocked is safe, and MetadataNode.cpp ends up unchanged by this PR. (An intermediate commit guarded those walks with the state lock and a copy of the list; the last commit replaces that, because those paths run under the isolate lock.) The base class is resolved first, and the lookup is repeated right before the node is created and published, with no unlock in between. The base class link is written before its node is published and never changes, and the reader's node vectors and table are only touched under the state lock. Interface records. ReadInterfaceImplementationTypeName reads a prefix flag and a name offset that follow the type byte and base class id in a static interface record. A type resolved at run time only gets the type byte and the id slot, so for a runtime-resolved interface that read would take whatever bytes come next in the value buffer and use them as an offset into the names. Before this PR that was reachable by name, in the same timing-dependent way described under the behavior change below; with runtime nodes out of the static tree, tracing its two callers turned up none that can still get there. The function now returns an empty name for a runtime-resolved node, so it stays safe if a path to it is ever added. Behavior change. A type resolved at run time is no longer reachable by name from its parent package or class. It used to be, but only in a runtime that had not yet materialized that parent when the type was first seen, so it depended on timing. Such types are still wrapped normally when Java hands one to JS. Cost. Nothing is added to method calls, wrapper creation, or class and package materialization, apart from one branch when an interface's node is first created (the check above). Resolving a type that is in the static metadata looks it up in the static child list first, as before; the reader's own table is consulted only on a miss, which previously went straight to a Java call. Resolving a runtime type no longer does a linear search of the whole node table for its base class id. MetadataTreeNode stays at 64 bytes on 64-bit ABIs (the new pointer fits after reordering its members; a static_assert holds it), and there is one per metadata node. All of this state is process-wide, not per isolate. Not covered here. The static tree itself is limited to 65,535 nodes by the metadata format. The generator fails the build past that ("Metadata is too big and has overflown our current limit"), and this change does not raise the limit; it removes the cliff about 1,000 nodes below it. Does your commit message include the wording below to reference a specific issue in this repo? No issue. Related Pull Requests None. Does your pull request have unit tests? Yes. testJavaIterators.js (46 specs) drains iterators with hasNext()/next() over the JDK list, set and map implementations (key sets, values and entry sets), List.of, unmodifiable and synchronized wrappers, org.json.JSONObject.keys(), android.os.Bundle.keySet(), android.util.ArrayMap, an Enumeration, Kotlin collections, and app-defined iterator classes: package-private, private nested, anonymous, lambda-backed, one whose hasNext() is inherited from a non-public base class, and an array of a private class. There were no iterator specs before. Runs, all on an API 36 arm64 emulator: Build Result main, node table padded so runtime nodes start past 65535 (simulates a large app) 26 of these specs fail, everything else passes This branch 1598 / 1598 pass This branch with the 16-bit base id read restored the same 26 specs fail ./gradlew runtestsAndVerifyResults on the final tree: 1598 / 1598. The two races have no spec: each needs a runtime to resolve a type in the same instant another one walks its parent, and a type is only resolved once per process, so a test could not hit the window reliably. They were found by reading the accesses to the tree's child lists; BuildTree is now their only writer. The interface record read has no spec either: no path to it with a runtime-resolved interface was found to test. The array spec passes in all three: a wrapped element-type id still resolves to an object type, which is enough to read elements, so that narrowing is fixed by inspection rather than by a failing spec. Summary by CodeRabbit Bug Fixes Improved runtime handling of dynamically resolved Java types, including classes, interfaces, and array types. Improved compatibility with Java iterators and enumerations across collections and map views, including implementations with inherited or non-public methods. Tests Expanded coverage for Java and Kotlin collections, JSON objects, bundles, iterator exhaustion, and JavaScript-wrapped iterators. Added checks for iterator behavior across additional Java collection and iterable implementations.

Open Graph Description: Description The symptom. In a large app, iterating Java collections from JS stops working: const it = map.entrySet().iterator(); while (it.hasNext()) { … } // TypeError: it.hasNext is not ...

X Description: Description The symptom. In a large app, iterating Java collections from JS stops working: const it = map.entrySet().iterator(); while (it.hasNext()) { … } // TypeError: it.hasNext is not ...

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

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:d641346b-9890-4fb0-973f-e64bbe8f8fd4
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idAF64:1EC9BC:19847CA:208795B:6B014AE7
html-safe-nonce77769ebfd724d6c388b2383b23ad73d65f217d4a857b9c9bdb46e48642b51dd6
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRjY0OjFFQzlCQzoxOTg0N0NBOjIwODc5NUI6NkIwMTRBRTciLCJ2aXNpdG9yX2lkIjoiNjI5NzUwNzYyNjg3MjUzMjIzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac6044cc21749739f139b5e08e69c28a0b37877566d47c2cbea2da43e48b378a3c
hovercard-subject-tagpull_request:5340359192
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/2111/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 symptom. In a large app, iterating Java collections from JS stops working: const it = map.entrySet().iterator(); while (it.hasNext()) { … } // TypeError: it.hasNext is not ...
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/2111/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FNativeScript%2Fandroid%2Fpull%2F2111%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%2F2111%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/2111/files
Reloadhttps://github.com/NativeScript/android/pull/2111/files
Reloadhttps://github.com/NativeScript/android/pull/2111/files
NativeScripthttps://github.com/NativeScript
androidhttps://github.com/NativeScript/android
Codehttps://github.com/NativeScript/android
Issues106 (106)https://github.com/NativeScript/android/issues
Pull requests24 (24)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/runtime-type-node-idshttps://github.com/NativeScript/android/tree/fix/runtime-type-node-ids
Conversation 1 https://github.com/NativeScript/android/pull/2111
Commits 5 https://github.com/NativeScript/android/pull/2111/commits
Checks 8 https://github.com/NativeScript/android/pull/2111/checks
Files changed https://github.com/NativeScript/android/pull/2111/files
Please reload this pagehttps://github.com/NativeScript/android/pull/2111/files
fix: keep the base class of runtime-resolved types in large apps https://github.com/NativeScript/android/pull/2111/files#top
Show all changes 5 commits https://github.com/NativeScript/android/pull/2111/files
cc3b290 fix: keep the base class of runtime-resolved types in large apps edusperoni Nov 16, 2026 https://github.com/NativeScript/android/pull/2111/commits/cc3b290ef4b464718b9e0c27a76b806211700959
06bce7c fix: guard the metadata tree's child lists across isolates edusperoni Nov 16, 2026 https://github.com/NativeScript/android/pull/2111/commits/06bce7c62161ecfb25ccb6edc39c5a0558b30162
a281219 perf: keep MetadataTreeNode at 64 bytes edusperoni Nov 16, 2026 https://github.com/NativeScript/android/pull/2111/commits/a2812198b4f702f3888411e5f4b3c58d3a520bdd
46e5b16 fix: keep runtime-created nodes out of the static metadata tree edusperoni Nov 16, 2026 https://github.com/NativeScript/android/pull/2111/commits/46e5b16e9147368ee54a84b75c5abc086eab78e0
27210e8 fix: don't read an implementation type name off a runtime-resolved in… edusperoni Nov 16, 2026 https://github.com/NativeScript/android/pull/2111/commits/27210e8b9f628800c2348ac9d06f946e20eda37e
Clear filters https://github.com/NativeScript/android/pull/2111/files
Please reload this pagehttps://github.com/NativeScript/android/pull/2111/files
Please reload this pagehttps://github.com/NativeScript/android/pull/2111/files
mainpage.js https://github.com/NativeScript/android/pull/2111/files#diff-b7fd6c22bfc29391e9e3ed935d6c6194b1ad595c7592690229952b5ddb99c0d5
testJavaIterators.js https://github.com/NativeScript/android/pull/2111/files#diff-6685afcaf988b10707eb4bce3f326d5c3618471770a3297a3a958f3c637a8848
IteratorFixtures.java https://github.com/NativeScript/android/pull/2111/files#diff-c316ddf2362991c4bd63a7b5632fc3f49501ecab697a0f0293e3c1d675d3890f
MetadataReader.cpp https://github.com/NativeScript/android/pull/2111/files#diff-c10689703cc3f34ede1d9fe01cad25579a071758c828e86ad0cad3d9e179bb1e
MetadataReader.h https://github.com/NativeScript/android/pull/2111/files#diff-4fda5fc04e9fe4f5478ca473515ea8d2af62f9187b876614daaa2d023c459104
MetadataTreeNode.cpp https://github.com/NativeScript/android/pull/2111/files#diff-0aed18287c251c7be775a47729cd3a5d350c988cd6c712714712a3e39ec59dd3
MetadataTreeNode.h https://github.com/NativeScript/android/pull/2111/files#diff-32e749c6e2ad676917cd98a97040c945ca2eca5f9dcb91eeb7eb3754621b4151
test-app/app/src/main/assets/app/mainpage.jshttps://github.com/NativeScript/android/pull/2111/files#diff-b7fd6c22bfc29391e9e3ed935d6c6194b1ad595c7592690229952b5ddb99c0d5
View file https://github.com/NativeScript/android/blob/27210e8b9f628800c2348ac9d06f946e20eda37e/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/2111/{{ revealButtonHref }}
https://github.com/NativeScript/android/pull/2111/files#diff-b7fd6c22bfc29391e9e3ed935d6c6194b1ad595c7592690229952b5ddb99c0d5
https://github.com/NativeScript/android/pull/2111/files#diff-b7fd6c22bfc29391e9e3ed935d6c6194b1ad595c7592690229952b5ddb99c0d5
test-app/app/src/main/assets/app/tests/testJavaIterators.jshttps://github.com/NativeScript/android/pull/2111/files#diff-6685afcaf988b10707eb4bce3f326d5c3618471770a3297a3a958f3c637a8848
View file https://github.com/NativeScript/android/blob/27210e8b9f628800c2348ac9d06f946e20eda37e/test-app/app/src/main/assets/app/tests/testJavaIterators.js
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/android/pull/2111/{{ revealButtonHref }}
test-app/app/src/main/java/com/tns/tests/IteratorFixtures.javahttps://github.com/NativeScript/android/pull/2111/files#diff-c316ddf2362991c4bd63a7b5632fc3f49501ecab697a0f0293e3c1d675d3890f
View file https://github.com/NativeScript/android/blob/27210e8b9f628800c2348ac9d06f946e20eda37e/test-app/app/src/main/java/com/tns/tests/IteratorFixtures.java
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/android/pull/2111/{{ revealButtonHref }}
Please reload this pagehttps://github.com/NativeScript/android/pull/2111/files
Please reload this pagehttps://github.com/NativeScript/android/pull/2111/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.