Repository navigation
Move live cppia instances onto a reloaded module's classes (#265) - #442
Merged
Merged
Conversation
Instances made before a reload kept their class and its code, so code reloaded into a running process only reached objects made after it (libhxcpp #265). A loaded module's adoptInstances(previous), called after it boots and before the previous module is released, runs a census collection and gives each live instance of a previous class the class of the same name in this module. An instance finds everything about its class through slot -1 of its script vtable, so the move replaces that one pointer. The instance stays where it is, at its size, so the classes must extend the same host class through super classes of the same names, implement the same interfaces, and have the same fields and dynamic functions with the same names, storage and offsets. Methods can differ in any way. It returns a row for each previous class with live instances: its name, how many moved, and for one that could not, the first difference. Bound methods and closures made before keep the old code and the old module. The census visitor is a single global, so the retained-module report and this take turns at it. CppiaAdoptInstances loads two versions of a script and checks the moved instances, a subclass, a host interface, Type.getClass, a class whose fields changed, a bound method, and that the old module is freed once what stayed goes, interpreted and with the JIT.
On Linux, musl and 32-bit Linux the JIT pass listed the first pass's new module as still loaded, with its two instances and four closures: the main thread had called its code through Dynamic, and the stale values those calls left on its stack kept it. Windows happened to overwrite them. Every call into script code now runs on a joined worker, and the main thread only collects and prints. CppiaAdoptInstances needs threads, which Emscripten does not have, so it is on its skip list.
dimensionscape
added a commit
that referenced
this pull request
Nov 13, 2026
The input from #442's fuzz run. Replayed with run.sh --replay cppia, main's loader segfaults on it and this branch's loads all ten cppia inputs.
# Conflicts: # Changes.md
28 of 34 tasks
HomuHomu833
pushed a commit
to ShadowEngineTeam/libhxcpp
that referenced
this pull request
Nov 14, 2026
The fuzz job's cppia target stopped in CallStatic::link with "member call on null pointer of type 'hx::HaxeNativeClass'", on openfl#442's run. A static call whose type had a host class looked the function up in that class's script glue, haxeBase, which a host interface does not have. Haxe gives an interface no statics, so only a malformed file makes such a call. It goes on to the field lookup the other host classes fall back to, and the file fails to load as for any other static that is not there.
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.
Builds #265 as agreed there. It was first written on the
cppia-bugs-1106branch and is picked from there onto current main.A loaded cppia module gets
adoptInstances(previous). A host calls it after the new module boots and before the old one is released:It runs a census collection and gives each live instance of an old class the class of the same name in the new module, so calls on objects made before the reload run the new code, through the instance, its interfaces and dynamic calls, and
Type.getClassgives the new class. An instance finds everything about its class through slot -1 of its script vtable, so the move replaces that one pointer, and the instance stays where it is.That makes the rule strict. Both classes must extend the same host class through super classes of the same names, implement the same interfaces, and have the same fields and dynamic functions, with the same names, storage and offsets. Methods can differ in any way, which covers the usual edit. The result has one row per old class with live instances:
name,moved, andreason, which names the first difference when they couldn't move. Bound methods and closures made before keep the old code, and keep the old module loaded until they go. Statics aren't copied. A host that doesn't call it sees no change.The census visitor is a single global, so the retained-module report and this now take turns at it.
CppiaAdoptInstancesloads two versions of a script and checks the moved instances, a subclass, a host interface,Type.getClass, a class whose fields changed, a bound method, and that the old module is freed once what stayed goes, interpreted and with the JIT. Every call into script code runs on a joined worker, since on Linux the main thread's stack kept stale values that held the old module. It's on the Emscripten skip list, as it needs threads. docs/CppiaModuleRelease.md describes the call.Tested here on Windows x64:
CppiaAdoptInstanceswith Haxe 4.3.7, and with the Haxe nightly together with #441, which that build needs forCondition.CppiaModuleFree,CppiaModuleReleaseandCppiaModuleRetainedstill pass.Fixes #265.