Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
f5f961f
Clear a moved object's start bit in the block it left
dimensionscape Nov 19, 2026
e6b8c2a
Write cppia array elements where they are
dimensionscape Nov 19, 2026
27cb34e
Catch and check exceptions from every JIT helper that can throw
dimensionscape Nov 19, 2026
aef2d3b
Let a finalizer take a Mutex
dimensionscape Nov 19, 2026
0cac760
Write to stdout, and close a child's stdin, in a GC-free zone
dimensionscape Nov 19, 2026
9ea3b48
Make Haxe 4's AtomicInt a safe point
dimensionscape Nov 19, 2026
c9d3e68
Number a script's interface slots after the host's
dimensionscape Nov 19, 2026
c4dd289
Keep two new tests' own races out of ThreadSanitizer's reports
dimensionscape Nov 19, 2026
3ef572f
Read and set the mark byte atomically in the generational barrier
dimensionscape Nov 19, 2026
d21501c
Do nothing at a safe point on a thread the collector does not know
dimensionscape Nov 21, 2026
5a8c8cb
Require a partly emptied block in GcMovedStartBits
dimensionscape Nov 21, 2026
af8a3f6
Keep the caller's GC-free zone in Sys.sleep, command and getch
dimensionscape Nov 19, 2026
acf2b60
Look up the Windows thread description functions when used
dimensionscape Nov 19, 2026
b119809
Read TLS slots of 64 and up through TlsGetValue on 32-bit Windows
dimensionscape Nov 19, 2026
bf67882
Wait for ever on tryAcquire(-1) only
dimensionscape Nov 19, 2026
5da0ac1
Look up cppia's shared maps without inserting
dimensionscape Nov 19, 2026
178fcef
Keep what a cpp.Pointer field points into wherever it points
dimensionscape Nov 19, 2026
c6e84ec
Count live bytes and Gc.trace right with an incremental cycle
dimensionscape Nov 19, 2026
b256c7b
Make cppia's interpreter and JIT agree on array builtins
dimensionscape Nov 19, 2026
86036f3
Refuse the malformed cppia files that crashed the host
dimensionscape Nov 19, 2026
7a454f4
Move instances in adoptInstances only when old and new code agree
dimensionscape Nov 19, 2026
7c475ba
Fail and end the build cleanly on compile thread errors
dimensionscape Nov 19, 2026
f701d8d
Rebuild when a define that changes compile flags changes
dimensionscape Nov 19, 2026
929ebec
Fix per-file cxx_standard with a PCH, nvcc groups and NDKV20 and up
dimensionscape Nov 19, 2026
c2c90dc
Depend on every header hxcpp.h and the runtime include
dimensionscape Nov 19, 2026
2f7679b
Trim the compile cache at most once in ten minutes
dimensionscape Nov 19, 2026
ae9dd78
Set a thread's error outside the log lock when a process cannot start
dimensionscape Nov 21, 2026
c02c8db
Use an ANDROID_NDK_ROOT that is the NDK version requested
dimensionscape Nov 21, 2026
185eea6
Check that each compile error test fails for its own reason
dimensionscape Nov 21, 2026
7fbdaef
Wait for another thread's cppia link in a GC-free zone
dimensionscape Nov 21, 2026
9ec5317
Mark nothing for a pointer field holding a block's base address
dimensionscape Nov 21, 2026
7a51344
Keep a cppia instance whose class retyped a method
dimensionscape Nov 21, 2026
51106e6
Read cppia enum parameters inline, checking the value's own count
dimensionscape Nov 21, 2026
5cfc876
Put GcPointerFieldBlockBase's helper in Main's file
dimensionscape Nov 21, 2026
aff282f
Close each regression test's process in the runner
dimensionscape Nov 21, 2026
cdf1cd9
libhxcpp 6.0.0
dimensionscape Nov 21, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ jobs:
include
name: Check public headers

# Every header hxcpp.h and the runtime include must be in haxe-target.xml's
# depend lists, or editing it rebuilds nothing (libhxcpp #469)
- name: Check the build tool's depend lists
run: python3 tools/check-depends.py

check-gc-defines:
name: Check GC defines
runs-on: ubuntu-latest
Expand Down
14 changes: 11 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ jobs:
run: |
haxelib run hxcpp xml/Build.xml -options options.txt
test "$(./value | tr -d '\r')" = 42
- name: build tool errors on compile threads
continue-on-error: ${{ inputs.warn_only }}
if: ${{ !cancelled() && steps.setup.outcome == 'success' }}
shell: bash
run: bash test/compile_errors/check.sh
- name: build tool MSVC setup scripts with ! in the Visual Studio path
continue-on-error: ${{ inputs.warn_only }}
if: ${{ !cancelled() && steps.setup.outcome == 'success' && runner.os == 'Windows' }}
Expand Down Expand Up @@ -495,11 +500,14 @@ jobs:
working-directory: test/regression
run: |
failed=""
for test in GcMutationRoots GcContainerMutation IncrementalGcSlices IncrementalGcContainers IncrementalGcArrayChunks IncrementalGcDequeMoves IncrementalGcPacing IncrementalGcStartSweep IncrementalGcStats IncrementalGcFinishBoundary IncrementalGcVerifier IncrementalWindowsHeaders GcWeakMapChain GcWeakMapWalkCollect GenerationalFinalizerLifecycle GenerationalLargeBufferLifecycle; do
for test in GcMutationRoots GcContainerMutation IncrementalGcSlices IncrementalGcContainers IncrementalGcArrayChunks IncrementalGcDequeMoves IncrementalGcPacing IncrementalGcStartSweep IncrementalGcStats IncrementalGcFinishBoundary IncrementalGcVerifier IncrementalGcCounts IncrementalWindowsHeaders GcWeakMapChain GcWeakMapWalkCollect GenerationalFinalizerLifecycle GenerationalLargeBufferLifecycle; do
echo "::group::incremental gc: $test"
# The lifecycle fixtures' hxml selects generational mode; compile
# the same Main with incremental mode here instead.
if ! (cd "$test" && haxe -main Main -cpp bin -lib hxcpp -D HXCPP_GC_INCREMENTAL -D HXCPP_GC_INCREMENTAL_VERIFY -D HXCPP_GC_INCREMENTAL_TEST -D $HXCPP_ARCH_FLAG && bin/Main > out.txt && diff <(tr -d '\r' < stdout.txt) <(tr -d '\r' < out.txt)); then
# the same Main with incremental mode here instead. Gc.trace, which
# IncrementalGcCounts checks, counts in debug builds only.
extra=""
[ "$test" = IncrementalGcCounts ] && extra="-debug -D DEBUGSUFFIX="
if ! (cd "$test" && haxe -main Main -cpp bin -lib hxcpp -D HXCPP_GC_INCREMENTAL -D HXCPP_GC_INCREMENTAL_VERIFY -D HXCPP_GC_INCREMENTAL_TEST -D $HXCPP_ARCH_FLAG $extra && bin/Main > out.txt && diff <(tr -d '\r' < stdout.txt) <(tr -d '\r' < out.txt)); then
failed="$failed $test"
echo "::error::incremental gc failed: $test"
fi
Expand Down
26 changes: 25 additions & 1 deletion Changes.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@

libhxcpp 6.0.0 (unreleased)
libhxcpp 6.0.0
------------------------------------------------------------

* Builds with the compile cache no longer size the whole cache each time: with 29792 files that took 98 ms to over a second before every build, even one with nothing to compile, and takes 3 to 14 ms now. The cache is trimmed to HXCPP_CACHE_MB at most once in ten minutes (libhxcpp #473)
* Fixed an edit to some of the runtime's headers rebuilding nothing, as when a haxelib git or dev checkout updates: hxcpp.h includes headers, hx/Functions.h and cpp/FastIterator.h among them, that the build tool's depend lists did not name, so neither the objects compiled with them nor the compile cache were checked against them, and a stale precompiled header stopped clang builds. Every header hxcpp.h and the runtime include is listed now, and CI checks that it stays so (libhxcpp #469)
* Fixed three build tool settings that did nothing or failed: a file with its own cxx_standard in a group with a precompiled header failed to compile (C2855 on MSVC), an <nvcc/> group was given the host compiler's flags because its tag was compared instead of set, and -DNDKV20 and up were ignored, so the newest NDK was used instead. An NDK without meta/platforms.json no longer stops the build with "Invalid field access : toString" (libhxcpp #472)
* Fixed the build tool reusing stale objects when a define that changes how files compile was switched without the compile cache: only defines containing hxcpp, and a few others, were compared, so adding -D CPPIA_NO_JIT to a scriptable build failed to link, removing it linked a host without its JIT, and ABI, OBJC_ARC, STDLIBCPP and the others like them did nothing until the objects changed. Each now rebuilds what it affects (libhxcpp #470)
* Fixed the build tool linking a stale object and exiting 0 when a compile failed and its old object could not be deleted, as when it is read-only or another process has it open, and hanging when a compile thread exited, as with HXCPP_EXIT_ON_ERROR on a compile error, or with an error such as two optimisation tags on one file. Both fail the build now, and HXCPP_EXIT_ON_ERROR works as a -D define, not only from the environment (libhxcpp #471)
* Fixed cppia's adoptInstances moving instances that code then used with the wrong layout: a class whose methods changed order or number moved, so old code still running called its moved instances by the old vtable slots, reaching another method or crashing, and a class moved while a field could hold an instance of a class that stayed, which new code read past its end. Such classes keep their instances now, and the report says why: methods must be the same, in the same slots, and so must the script interfaces a class implements, fields compare their types by name, and a class stays with the classes its fields can hold (libhxcpp #464)
* Fixed malformed cppia files crashing the host instead of failing to load: a MAIN in a module with no types, an unknown script enum constructor or one called with the wrong number of arguments, two classes with one type id, a string constant or file id past the string table, which grew the table to it, an enum parameter index past the value, break or continue outside a loop under the JIT, and a super constructor call to a class other than the super class. Each fails to load, or is read safely (libhxcpp #467)
* Fixed cppia's interpreter and JIT giving different results for array builtins, both of them now matching C++: under the JIT, a[i] += x and the other compound assignments on an Array<Dynamic> stored x alone, a[i]++, insert and toString on one did nothing, a Bool stored in an Array<Any> became an Int, bitwise compound assignments on an Array<Null<Int>> did nothing, an Int array read out of range as a String gave "null", and ++d[i] on a Dynamic as a statement decremented. Interpreted, a typed indexOf or lastIndexOf used as a Float gave 0, and join, toString and the iterators used as a statement did not run (libhxcpp #468)
* Fixed two counts with HXCPP_GC_INCREMENTAL: Gc.memInfo64(MEM_INFO_LIVE) after an incremental cycle reported every used row as live, several times the bytes really live, where it is meant to report the last full reclaim, and Gc.trace with a cycle part done counted only the objects the cycle had not marked yet. MEM_INFO_LIVE changes only with a full reclaim now, and Gc.trace starts the cycle again, as __hxcpp_gc_census does (libhxcpp #453)
* Fixed a cpp.Pointer field, or a pointer boxed in a Dynamic, letting what it points into be freed when it points further in than 64 bytes, or 32 on 32-bit, as cpp.Pointer.arrayElem(a, 100) does: the fix for Haxe 4's AtomicInt kept only what a stack word would keep. A pointer field keeps its whole allocation now, large ones included, and pins it under HXCPP_GC_MOVING (libhxcpp #451)
* Fixed cppia hanging or crashing when several threads asked Std.isOfType about script objects, or cast them to host interfaces, at once: each question about an interface a class did not implement inserted into that class's table, unlocked, while other threads searched it. Loading modules on several threads at once could likewise fail with "No base defined for non-interface", or hang, as each load inserted the host class names it missed into a map the others walked. Both are only read after they are filled now (libhxcpp #466)
* Fixed Semaphore.tryAcquire with a negative timeout waiting for ever, as tryAcquire(deadline - now) does once the deadline has passed: since the fix for Haxe 5's Lock.wait() (libhxcpp #420), any negative timeout meant no limit. Only -1, which Haxe 5.0.0-preview.1's Lock.wait() passes for no timeout, waits with no limit now, and any other negative timeout returns at once, as 0 does (libhxcpp #461)
* Fixed 32-bit Windows programs stopping with "Bad local allocator - requesting memory from unregistered thread!" when the process had used 64 TLS slots before the runtime started, as a host with many DLLs, or a late-loaded hxcpp DLL, can: the collector read its per-thread context from the thread's inline TLS slots, of which there are only 64. Later slots are read with TlsGetValue, as on x64 (libhxcpp #458)
* Fixed Windows programs not starting on Windows 8.1, Server 2012 R2 and Windows 10 before 1607 with a missing entry point, HXCPP_WINXP_COMPAT or not: every program imported GetThreadDescription and SetThreadDescription, which those lack. They are looked up when used now, and where they are missing a thread's name is null and setting it does nothing (libhxcpp #456)
* Fixed Sys.sleep, Sys.command and Sys.getch ending the process with "GCFree Zone mismatch" when called inside a GC-free zone the caller had entered, as with cpp.vm.Gc.enterGCFreeZone around a blocking call: they left that zone themselves, so the caller's own exit failed. They keep the caller's zone, as Mutex, Lock and Semaphore do. CFFI's gc_safe_point, between gc_enter_blocking and gc_exit_blocking, no longer pauses as if outside the zone, which ended the process with "Bad Allocation while collecting" or waited for ever (libhxcpp #457)
* Fixed a data race in the HXCPP_GC_GENERATIONAL write barrier, which ThreadSanitizer reported when two threads stored into one old array at once: the barrier read an object's mark byte while another thread set the remembered bit in it, and the young log's count was shared the same way. Both are atomic accesses now, as cheap as before where they compile to plain loads
* Fixed a cppia class that implements both a script interface and a host interface, such as haxe.Constraints.IMap, calling the wrong method or crashing: the script interface's first method that the host does not know got the slot of the host's last interface method, so both were stored in one slot. Script interface methods are numbered after the host's now (libhxcpp #462)
* Fixed a thread spinning on Haxe 4's haxe.atomic.AtomicInt, as in while (flag.load() == 0) {}, stopping every collection, and so every other thread, for as long as it spun: the atomic operations were not safe points, so a collection waited for it, and it waited for a flag the collecting thread would set afterwards. They stop for a pending collection now, as Haxe 5's AtomicInt and Mutex.tryAcquire do, and so do the AtomicObject operations (libhxcpp #455)
* Fixed trace, Sys.print and Sys.println stopping every thread when stdout blocked, as it does for a pipe nobody reads, a slow log reader or a Windows console with text selected: they wrote outside a GC-free zone, so the next collection on any thread waited for the blocked write, and every other thread waited for the collection. On Windows, Process.stdin.close() did the same while another thread was blocked writing to the child, and waited itself until the child exited. They write in a zone now, and stdin.close() cancels the writes in progress before it closes, as Process.close() does (libhxcpp #454)
* Fixed a finalizer set with cpp.vm.Gc.setFinalizer that takes a Mutex ending the process with "Bad Allocation while collecting - from finalizer?", even with the lock free: finalizers run on the collecting thread inside the collection, and Mutex's uncontended path stopped there for the collection as if it were another thread. The collecting thread passes that stop now, so a finalizer can take a Mutex, as with stock hxcpp. A finalizer still must not allocate (libhxcpp #452)
* Fixed exceptions under the cppia JIT running on past the throw, or skipping the script's catch, when they came from a native helper of the jitted code: a Dynamic field or index updated with +=, -= and the others, Dynamic + Dynamic, ++ and -- on a Dynamic, a Dynamic or host ArrayAccess index, the typed array setters and increments, Array<Any> stores, string iterators and enum construction. Some of these caught the exception and the jitted code never looked, so it ran on and, if it allocated, could free the exception before the catch got it, crashing the next call; the rest let it unwind through the jitted frames, past the script's catch to the host's, or out of the process. Each now catches, the jitted code checks after each call, and the collector keeps a caught exception until it is handled. MSVC builds now compile with -bigobj, as debug builds already did (libhxcpp #465)
* Fixed three cppia array builtins writing to the wrong memory: under the JIT, a[i]++ or --a[i] whose result was used as a Float stored that result through whatever the third argument register held, corrupting the array or memory near it, and a typed push made room before running its argument, so an argument that grew the same array had the value stored past its buffer. Interpreted, a[i] = rhs and a[i] += rhs found the element before running rhs, so an rhs that grew the array stored into the old buffer, and a[a.length] = a.length stored the length after the store. The interpreter and the JIT now agree, and match the other targets (libhxcpp #463)
* Fixed HXCPP_GC_MOVING, and HXCPP_GC_DEBUG_ALWAYS_MOVE without generational, corrupting live objects after a collection that ran out of blocks to move into: the block it was emptying kept, in part, the start bits of the objects it had moved out, and a stale stack word holding one of their old addresses had a later collection take the moved header for an object of 254 rows and mark rows past the block's row table, over the objects in its first rows. The start bits go as the objects move, and a moved header is never taken for an object (libhxcpp #450)

libhxcpp 6.0.0-rc.3
------------------------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions docs/CppiaModuleRelease.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ untyped previous.release();

- `name`, the class's name.
- `moved`, how many of its instances moved.
- `reason`, null when they could move, otherwise why not, naming the first field that differs.
- `reason`, null when they could move, otherwise why not, naming the first field or method that differs, or the field that can hold an instance that stays.

The rule is strict, as an instance stays where it is, at its size. Both classes must extend the same host class, through super classes of the same names, implement the same interfaces, and have the same fields, dynamic functions included, with the same names, storage types and offsets. Methods can differ in any way, so editing method bodies, the usual case, is covered. A class that adds, removes, retypes or reorders a field keeps its instances, which keep the old module loaded until they go.
The rule is strict, as an instance stays where it is, at its size, and old code still running calls it by the slots its calls linked with. Both classes must extend the same host class, through super classes of the same names, implement the same interfaces, and have the same fields, dynamic functions included, with the same names, types and offsets. They must have the same methods, their super classes' included, in the same order, so that each keeps its slot, and so must the script interfaces they implement. Method bodies can differ in any way, so editing them, the usual case, is covered. A class that adds, removes, retypes or reorders a field or a method keeps its instances, which keep the old module loaded until they go. So does a class with a field that can hold an instance of a class that stays, since the new code would read that instance with the new layout.

What does not move:

Expand Down
17 changes: 17 additions & 0 deletions include/cpp/Pointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -574,4 +574,21 @@ T *StarOf(T &x) { return &x; }
}


// Haxe 4's haxe.atomic.AtomicInt is a cpp.Pointer<Int>, and its methods call
// these. A thread spinning on one never otherwise reached a safe point, so a
// collection on another thread waited for it for ever, as Haxe 5's
// hx::atomic::AtomicInt does not (libhxcpp #455). The runtime's own spinlocks
// call the volatile int * forms, which do not stop.
#define HX_ATOMIC_SAFE_POINT if (::hx::gPauseForCollect) __hxcpp_gc_safe_point();
inline int _hx_atomic_add(::cpp::Pointer<int> a, int b) { HX_ATOMIC_SAFE_POINT return _hx_atomic_add((volatile int *)a.ptr, b); }
inline int _hx_atomic_sub(::cpp::Pointer<int> a, int b) { HX_ATOMIC_SAFE_POINT return _hx_atomic_sub((volatile int *)a.ptr, b); }
inline int _hx_atomic_and(::cpp::Pointer<int> a, int b) { HX_ATOMIC_SAFE_POINT return _hx_atomic_and((volatile int *)a.ptr, b); }
inline int _hx_atomic_or(::cpp::Pointer<int> a, int b) { HX_ATOMIC_SAFE_POINT return _hx_atomic_or((volatile int *)a.ptr, b); }
inline int _hx_atomic_xor(::cpp::Pointer<int> a, int b) { HX_ATOMIC_SAFE_POINT return _hx_atomic_xor((int *)a.ptr, b); }
inline int _hx_atomic_compare_exchange(::cpp::Pointer<int> a, int expected, int replacement) { HX_ATOMIC_SAFE_POINT return _hx_atomic_compare_exchange((volatile int *)a.ptr, expected, replacement); }
inline int _hx_atomic_exchange(::cpp::Pointer<int> a, int replacement) { HX_ATOMIC_SAFE_POINT return _hx_atomic_exchange((volatile int *)a.ptr, replacement); }
inline int _hx_atomic_load(::cpp::Pointer<int> a) { HX_ATOMIC_SAFE_POINT return _hx_atomic_load((volatile int *)a.ptr); }
inline int _hx_atomic_store(::cpp::Pointer<int> a, int value) { HX_ATOMIC_SAFE_POINT return _hx_atomic_store((volatile int *)a.ptr, value); }
#undef HX_ATOMIC_SAFE_POINT

#endif
Loading
Loading