Skip to content

Architecture pass fixes for 6.0.0 - #481

Merged
dimensionscape merged 36 commits into
mainfrom
integrate/6.0.0-final
Nov 21, 2026
Merged

dimensionscape merged 36 commits into
mainfrom
integrate/6.0.0-final

Conversation

@dimensionscape

Copy link
Copy Markdown
Member

The architecture pass fixes for 6.0.0, in one branch so they share one CI run before the release. It stacks #474, #475, #477 and #478, rebased onto main, and #479, which fixes a race #474's TSan run found. Each commit is as it was in its PR, with its Changes.md line moved from the released 6.0.0-rc.3 section to 6.0.0 (unreleased).

Each PR was reviewed again before this, and what the reviews found is fixed here in commits of its own:

Fixes #450
Fixes #451
Fixes #452
Fixes #453
Fixes #454
Fixes #455
Fixes #456
Fixes #457
Fixes #458
Fixes #461
Fixes #462
Fixes #463
Fixes #464
Fixes #465
Fixes #466
Fixes #467
Fixes #468
Fixes #469
Fixes #470
Fixes #471
Fixes #472
Fixes #473

#459 and #460 wait on Haxe and are not part of this.

MoveBlocks walked each source block's start bits through a local copy,
so the block kept every bit. When the blocks to move into ran out part
way through one, that block was kept with the start bits of the objects
it had moved out, whose headers are IMMIX_OBJECT_HAS_MOVED. A stale
stack word holding one of those addresses then reached
GetAllocTypeChecked, which took the header's mark byte of 0 for the
previous mark one collection in 16, and MarkAllocUnchecked marked 0xfe
rows from there, past the 256 bytes of the row table and into the
block's first data rows. Once marked, the header looked live on every
later collection.

The block's own bit is cleared as each object moves, and
GetAllocTypeChecked refuses a moved header outright.

Test: GcMovedStartBits, under HXCPP_GC_MOVING, finds a block emptied in
part and puts 407 of its moved-out addresses on the stack: the
collector marked all 407 as objects before and none now, 3 of 3 runs
on Windows x64.

Fixes #450
Three array builtins wrote to the wrong memory on valid code:

- The JIT's a[i]++ with a Float result called runFloatCrement, which
  takes a double * for the result, with two arguments, so it stored 8
  bytes through whatever the third argument register held. It passes
  the result's address now.
- The JIT's typed push checked the capacity and expanded before it ran
  its argument, so an argument that grew the same array to its
  capacity left the store past the buffer. The argument runs first.
- The interpreter's ArraySetter took a reference to the element before
  running the right-hand side, so a right-hand side that grew or
  reallocated the array stored into the old buffer. It works on a copy
  of the element and finds the element after, which also stores
  a[a.length] = a.length as the JIT and the other targets do.

Test: CppiaArrayWrites, interpreted and under the JIT. Before, the JIT
corrupted the Int array and its neighbour, and the interpreter stored
1 for 42 and 43 and appended 4 for 3; both engines print the expected
output now, on Windows x64.

Fixes #463
#404 fixed three typed-array helpers. Many other native helpers of
jitted code had the same problem, in two forms:

- getFieldVariant, addVariantObject, addVariantString,
  setFieldVariant(V), createEnum and others caught into
  StackContext::exception, but the jitted code had no checkException
  after calling them, so it ran on past the throw. The exception was
  then held only by StackContext::exception, which the collector did
  not mark, so code that allocated before the next check could free
  it and crash the catch or the next call.
- dynamicCatDynamic, the Variant arithmetic helpers, the obj*Inc and
  obj*Dec helpers, getItem to setDynamicI and the DynIndex helpers,
  jitGet, jitSet and jitUpdate, the typed array setters and
  increments, array_expand(_size), the Array<Any> stores and the
  string iterator did not catch at all, so the exception unwound
  through jitted frames, which have no unwind information, past the
  script's catch.

Each of these helpers catches now, every call to one is followed by
checkException, and the collector marks a pending exception when it
scans a thread's script stack, pinned, as a stack word is.

The try blocks in the templated array helpers take ArrayBuiltin.cpp
past MSVC's default limit on sections in an object file, so MSVC
compiles with -bigobj always, as debug and sanitizer builds already
did.

Test: CppiaJitHelperExceptions. Before, the JIT let toString's
exception from d.s += t escape the script to the host's catch; now
each case is caught in its own function, interpreted and under the
JIT, and nothing runs after a throw, on Windows x64.

Fixes #465
Finalizers run on the collecting thread, inside the collection, with
gPauseForCollect still set. The uncontended paths of Mutex, Condition,
Semaphore, Deque and Lock call __hxcpp_gc_safe_point when a collection
is pending, which went to SafePoint and PauseForCollect, and that ends
the process when the collection is under way. Stock hxcpp took these
locks in a GC-free zone, which the collecting thread can enter.

sgIsCollecting is set only once every other thread is stopped or in a
zone, so a thread outside a zone that reaches SafePoint while it is set
is the collecting thread, and SafePoint returns for it.

Test: GcFinalizerTakesMutex, 1000 finalizers that take and try a
Mutex. Before, the process ended at the first; now all but those the
stack scan keeps run, 3 of 3 runs on Windows x64. A finalizer that
allocates, as Deque.add does, still ends the process, as it should.

Fixes #452
__trace, __hxcpp_print_string and __hxcpp_println_string wrote to
stdout outside a zone. When stdout blocks (a pipe nobody reads, a slow
reader, a Windows console with text selected), the writing thread
blocked outside the zone, so the next collection on any thread waited
for it, and every other thread for the collection. They make their
text first, since nothing may allocate in a zone, and write in one,
through OutputZone, which enters none on a thread the collector does
not know.

On Windows, _hx_std_process_stdin_close called CloseHandle outside a
zone, and CloseHandle waits for a WriteFile in progress on the pipe,
for as long as the child does not read. Writes to stdin are now counted
apart, as PipeCall counts every pipe call for destroy, and stdin_close
refuses new ones and cancels those in progress before it closes, in a
zone.

Test: GcStdoutBlocked, a child whose stdout fills while it collects:
println and trace never collected before, and now all three modes do.
ProcessStdinCloseCollects: the collection and the close finished only
when the child exited before, and while it runs now, on Windows x64.

Fixes #454
Haxe 4's haxe.atomic.AtomicInt is a cpp.Pointer<Int>, and its methods
call the _hx_atomic_* functions, none of which polled gPauseForCollect.
A thread spinning on load() waiting for a flag the main thread sets
after a collection kept that collection waiting for ever. Haxe 5's
hx::atomic::AtomicInt calls __hxcpp_gc_safe_point in each operation,
and #119 did the same for Mutex.tryAcquire.

Overloads of the _hx_atomic_* functions that take ::cpp::Pointer<int>,
which is what Haxe 4 passes, now stop for a pending collection and call
the volatile int * forms, which the runtime's own spinlocks keep using
unchanged. The __hxcpp_atomic_object_* operations stop too.

Test: AtomicSpinSafePoint, with a native watchdog. Before, the
collection never finished; now it does, and the spinning thread sees
the flag, on Windows x64.

Fixes #455
The module constructor gives the host's interface method names slots 2
to sgNativeNameSlotCount-1, which is sgNativeNameSlotCount-2 entries,
and getInterfaceSlot gave a new name interfaceSlots.size()+1, which
for the first is sgNativeNameSlotCount-1: the host's last slot. A class
implementing a script interface and a host interface whose method has
that slot (IMap's clear, in the test host) stored both methods in one
slot of its interface table.

New names now count from sgNativeNameSlotCount, or from 1 as before
when the host registers no names.

Test: CppiaInterfaceSlots, a class implementing two script interfaces
and haxe.Constraints.IMap. Before, both engines crashed; now each call
reaches its own method, interpreted and under the JIT, on Windows x64.

Fixes #462
The TSan job reported races that are the tests' own, not the runtime's:

- GcMovedStartBits reads the headers of moved-out objects on purpose,
  in blocks the collector's zeroing thread may be clearing. Its
  header read is not instrumented now.
- ProcessStdinCloseCollects closes a pipe while another thread writes
  to it. On Windows that is the case #454 fixed, and close waits for
  the write; elsewhere close does not wait, so the test only checks
  Windows and prints the same lines elsewhere.
Under HXCPP_GC_GENERATIONAL the write barrier reads an object's mark
byte, and its slow path sets the remembered bit in it. Two threads
storing into one old array at once did both with plain accesses, so
one could set the bit while the other read the byte: ThreadSanitizer
reported it in GenerationalArrayYoungLog, between YoungStore and the
barrier inlined into the test's generated code. Either value read is
handled, and both threads only set the same bit, but it was a data
race all the same. So was the young log's count, ioLogged, which the
code already says may lose updates between threads.

hx::BarrierMarkByte reads the byte with a relaxed atomic load, a plain
byte load where it compiles to one, and hx::BarrierRemember sets the
bit with an atomic or. The barrier macros, YoungStore, the hash maps'
barrier and the cppia JIT's pushWriteBarrier use them, and the count
is read and written with relaxed atomics.

Test: the TSan job, which reported the race in
GenerationalArrayYoungLog; and the Generational regression tests, a
cppia JIT test and gc stress, all built generational, on Windows x64.
Haxe 4's AtomicInt operations now stop at a pending collection through
__hxcpp_gc_safe_point, which asked for the thread's allocator and ended
the process with "Bad local allocator" when it had none. A native
thread the collector never registered, such as an audio callback thread
reading an atomic flag, did that while another thread collected. Such a
thread is not one the collector waits for, so the safe point now does
nothing there, for the thread primitives that call it too.

Test: AtomicSafePointUnregisteredThread reads a Haxe 4 AtomicInt from a
std::thread the collector never registered through 50 collections.
Before the change the process ended with "Bad local allocator" 3 of 3,
after it the reads go on, 3 of 3, Windows x64.
The test counts moved-out locations marked as objects in a block a moving
collection only partly emptied, and printed the number of such blocks to
stderr only. On a heap layout that never left one, every count was 0 and
the test passed without testing anything. It now prints whether it found
one, so it fails there instead.

Test: it finds one and passes 3 of 3 at 64 and 32 bits on Windows.
Sys.sleep, Sys.command and Sys.getch entered and left a zone with plain
EnterGCFreeZone and ExitGCFreeZone. Called in a zone the caller had
entered, as with cpp.vm.Gc.enterGCFreeZone around a blocking call, which
docs/ThreadsAndStacks.md suggests, their exit ended the caller's zone,
and the caller's own exit then stopped the process with "GCFree Zone
mismatch". Mutex, Lock and Semaphore were made safe for this in
603fd03 and c3a9ee4. These three allocate nothing between entering
and leaving, so they use AutoGCFreeZone, which keeps a zone the caller
entered.

CFFI's gc_safe_point was a copy of the old __hxcpp_gc_safe_point,
calling PauseForCollect even in a zone, so an extension calling it
between gc_enter_blocking and gc_exit_blocking ended the process or
waited for a release that never came. It calls __hxcpp_gc_safe_point
now.

Test: GcFreeZoneLeafNatives. Before, the process stopped at the first
Sys.sleep; now Sys.sleep and Sys.command work in a zone, and a thread
calling gc_safe_point in one lets 100 collections through, 3 of 3 runs
on Windows x64.

Fixes #457
ThreadImpl.win32.cpp called GetThreadDescription and
SetThreadDescription directly, and it is always linked, since
Thread_obj::current() runs in InitAlloc. So every Windows program
imported both from KERNEL32.dll at load time, and they only exist from
Windows 10 1607: on Windows 8.1, Server 2012 R2 and early Windows 10,
the program did not start, HXCPP_WINXP_COMPAT or not.

They are looked up once with GetProcAddress. Where they are missing,
a thread's name is null and setting it does nothing. UWP builds, which
need Windows 10 and cannot use GetModuleHandle, call them directly.

Test: WindowsThreadNameImports reads the program's own import table:
KERNEL32.dll's entries named both before and neither now, on Windows
x64.

Fixes #456
TLSData with FAST set, which the collector's tlsStackContext is, read
fs:[0xE10 + slot*4] for any slot on 32-bit Windows. Only the first 64
slots are inline in the thread environment block; the others are in
TlsExpansionSlots, so for a slot of 64 or more the read landed on other
fields of the block. In a process that had used 64 TLS slots before
the runtime started, as a host with many DLLs can, every thread looked
unregistered and the first allocation stopped the process.

Slots of 64 and up go through TlsGetValue, as on x64. Reading the
expansion array directly is not safe either, since a thread that never
set such a slot has no array yet.

Test: TlsHighSlot, where an MSVC CRT initializer takes TLS slots up to
70 before the runtime starts, and a second thread allocates too. The
32-bit build stopped with "Bad local allocator" before and runs now;
the 64-bit build runs either way.

Fixes #458
Since #420, CountingSemaphore::tryAcquire waited with no limit for any
negative timeout, so that Haxe 5.0.0-preview.1's Lock.wait(), which
passes -1 when given no timeout, would block. But a timeout computed
as tryAcquire(deadline - now) goes negative once the deadline has
passed, and then waited for ever, where Haxe documents tryAcquire as
giving up when the timeout runs out. The Haxe nightly's Lock.wait
calls acquire() when given no timeout, so only preview.1 needs the
special case.

Exactly -1 still waits with no limit, on every backend. Any other
negative timeout returns at once, as 0 and NaN do.

Test: ThreadWaitTimeouts checks -1 and -0.5 apart now. tryAcquire(-0.5)
on an empty semaphore waited until the watchdog stopped the test
before, and returns false at once now, on Windows x64.

Fixes #461
hx::Object::_hx_getInterface read a script class's
interfaceScriptTables with std::map::operator[], so Std.isOfType on a
script object, or an interface cast, inserted an entry for each host
interface the class did not implement, from whichever thread asked,
with no lock, while other threads searched the same map. Threads
asking about the same classes hung or crashed.

HaxeNativeClass::findClass, hxObject, link's super class lookup and
HaxeNativeInterface::findInterface inserted the names they missed into
the host's class maps the same way, while loading a module on another
thread walked them in link(), so loads failed with "No base defined for
non-interface" or hung.

The maps are filled when classes link or the host starts and only read
after, with find(). link(), which sets the shared super classes on
every load, takes a lock, and the module id counter is atomic.

Test: CppiaThreadedLookups, 8 threads asking Std.isOfType about the
same 2000 script objects, then 8 threads loading one module at once,
with a watchdog. Before, 3 of 4 runs hung; now 5 of 5 pass, on Windows
x64.

Fixes #466
e1f6ac0 made a cpp.Pointer field, and a pointer boxed in a Dynamic,
keep what it points into, through MarkConservativePointer. That went
through the stack scan, which accepts a pointer only within
sgCheckInternalOffset of an allocation's start: 64 bytes, or 32 on
32-bit. Right for a stack word, which is usually also held from the
start somewhere, but a field may be all that holds it, and a pointer
from cpp.Pointer.arrayElem(a, 100), 400 bytes in, kept nothing.

MarkConservative's body takes the reach as a parameter now, and passes
it to GetMemType, GetEnclosingAllocType and GetEnclosingNurseryType.
A stack word keeps sgCheckInternalOffset; MarkConservativePointer
reaches back to the start of the block, and a large allocation is
checked against its own size. The walk back in a block stops at the
block's start, and the large allocation bounds check no longer adds
the reach to the highest base, which a large reach overflowed.

Test: GcPointerFieldInterior, 2000 fields 40 and 400 bytes into Int
arrays and one 200 KB into a large array. Before, 1999 of the 400-byte
fields and the large one read freed memory, and on 32-bit all 4000 did;
now none do, in the default, HXCPP_GC_MOVING and 32-bit builds on
Windows.

Fixes #451
With HXCPP_GC_INCREMENTAL:

- A finished cycle that is not a full reclaim only runs countRows,
  whose bytesInUse is whole rows, and Collect stored that as
  mLiveBytes because the cycle had finished. MEM_INFO_LIVE, the bytes
  of the objects that survived the last full reclaim, then reported
  every used row as live, seven times the real figure in the test. It
  is set by full reclaims only.
- Gc.trace counts what its collection marks. With a cycle part done,
  the collection finished it, and the objects its earlier slices had
  marked were not counted. A census already fails the partial cycle
  for this reason; Gc.trace does too now.

Test: IncrementalGcCounts, which the incremental gc job builds in
debug, as Gc.trace needs. Before, MEM_INFO_LIVE changed after the
cycle, and Gc.trace counted 90668 and 108653 of 200000; now both are
right, on Windows x64.

Fixes #453
Compared with the same code built as C++, which both now match:

JIT:
- Array<Dynamic> and Array<Any> compound assignment stored the right
  hand side alone, and ++, --, insert and toString had no JIT code at
  all, so they did nothing ("Unknown ArrayBuiltinAny"). They call
  helpers sharing the interpreter's arithmetic, which catch, and the
  jitted code checks after each.
- A Bool pushed, unshifted or set into an Array<Any> was stored as an
  Int. It goes in boxed.
- Bitwise compound operators on an Array<Null<Int>> did nothing: the
  bitwise cases fell through to the element's type for lack of a break.
- An Int array's element read out of range as a String was "null", not
  "0". It reads the element type's zero.
- ++d[i] on a Dynamic used as a statement decremented: the test was
  crement==coPostInc || crement==coPostInc.

Interpreter:
- A typed indexOf or lastIndexOf used as a Float returned 0 without
  running.
- join and toString used as a statement, and iterator and
  keyValueIterator, were skipped, receiver and element toString calls
  with them.

Test: CppiaArrayEngines, twelve lines, each wrong in one engine before
and right in both now, interpreted and under the JIT on Windows x64.

Fixes #468
SECURITY.md promises a load error for a malformed .cppia file, but
these crashed the host, interpreted, under the JIT, or both:

- MAIN in a module with no types: ScriptCallable::link read the type
  of its return, 0, from an empty table. Return type ids are checked.
- An unknown script enum constructor left a null value that was
  dereferenced, and a call with the wrong number of arguments wrote
  past the enum value under the JIT. Both fail to link.
- Two classes with one type id: the second overwrote the first's and
  wrote outside the vtable made for it. It fails to load.
- A string constant id, and the text format's file id, were read
  unchecked, and the string table grew to them: by 100000000 entries,
  1.4 GB, for a file id, and the JIT's addresses of its strings were
  left dangling. They are checked as other string ids are.
- An enum parameter index past the value read past it. A script enum's
  constructors bound it at link, and otherwise the interpreter and the
  JIT check the value's own parameter count.
- break or continue outside a loop made sljit assert under the JIT,
  ending the process. The function fails to compile instead, checked
  on the pass that emits code, since the measuring pass has no labels.
- A super constructor call to a script class other than the super
  class ran that constructor on an instance laid out for this one. It
  fails to link, after the check for a class with no constructor.
  CppiaMalformedConstructors' control, such a call from a static main,
  is refused now too.

Test: CppiaMalformedLoads, ten such files, loaded and run interpreted
and with the JIT compiling as it loads. Before, the host crashed on
the first; now each fails to load or runs safely. The cppia suite and
the 60 Cppia regression tests pass, interpreted and under the JIT, on
Windows x64.

Fixes #467
adoptInstances compared only field names, storage types and offsets,
and docs/CppiaModuleRelease.md said methods could differ in any way.
But a call's vtable slot is fixed when its code links, so old code
still running, which the docs say finishes normally, called a moved
instance by the old slots: with a method added first, foo.b() ran the
new a(), and foo.a() reached x(), whose Int was read as a String,
crashing the interpreter and giving the JIT a String of garbage. And a
moved class's field could hold an instance of a class that stayed,
since its layout changed, which new code then read with the new layout,
past the object.

Now:
- methods, their super classes' included, must have the same names in
  the same slots, and so must the script interfaces the class
  implements;
- fields compare their type names, so a retyped field within one
  storage type, Array<Int> to Array<Float>, keeps its instances, as the
  docs said it did;
- a class with a field that can hold an instance of a class that stays
  stays too, to a fixed point.

The report says which rule kept a class, and the docs describe the
rule.

Test: CppiaAdoptLayouts, the two cases, interpreted and under the JIT.
Before, the first crashed the interpreter and the second read past the
object; now neither class moves and old code keeps its own results.
CppiaAdoptInstances, whose classes change only method bodies, still
moves them, on Windows x64.

Fixes #464
Two ways a parallel compile went wrong when something on a compile
thread threw or exited:

- When a compile failed, Compiler deleted the old object before calling
  setThreadError. If the delete threw, as it does for a read-only object
  or one another process has open on Windows, the error was never
  recorded, and the thread's catch only warned when no error had been
  recorded, so the build linked the old object and exited 0. The error
  is recorded first, the delete is guarded, and the catch records an
  error for anything thrown.
- Tools.exit on a compile thread ran the exit hooks there, and
  ThreadPool's hook waits on the calling thread's own queue, which
  never fills, while the main thread waited for that thread: the build
  hung. HXCPP_EXIT_ON_ERROR on a compile error and any Log.error on a
  compile thread did this. On a compile thread, Tools.exit records the
  code and ends the job, and the main thread exits when the jobs have.

HXCPP_EXIT_ON_ERROR is also read once the arguments and Options.txt
are in, not only from the environment.

Test: test/compile_errors/check.sh, run in CI, builds three projects
that must fail: HXCPP_EXIT_ON_ERROR with a compile error and two
optimisation tags on one file, which hung before, and on Windows a
compile error over a read-only old object, which exited 0 before. All
three fail within seconds now, on Windows x64.

Fixes #471
Without the compile cache, the copy of Options.txt the build tool keeps
in the obj folder is all that tells it the compile flags changed, and
filterOptions keeps only defines containing "hxcpp" and a few others.
Defines the toolchains compile by, or choose files by, were dropped:
switching one reused objects built without it. Adding CPPIA_NO_JIT to
a -D scriptable build recompiled only Main.cpp and failed to link
against the old Cppia.obj (unresolved hx::getJitType), and removing it
linked a host without its JIT, saying nothing.

The defines the toolchain files test or use in flags, and which no obj
folder or other kept define already covers, are kept too: CPPIA_NO_JIT,
CPPIA_JIT, ABI, objc, OBJC_ARC, STDLIBCPP, exe_link, O3,
LEGACY_MACOSX_SDK, armv6, rpi, winrt, noM32, noM64 and
no_shared_libs.

Test: a -D scriptable build, then the same with -D CPPIA_NO_JIT,
compiled the cppia sources again and linked, then without it again,
on Windows x64.

Fixes #470
- A file with its own cxx_standard, which docs/build_xml/Files.md
  documents, in a group with a precompiled header was given both the
  file's standard and the PCH built with the group's. MSVC refused
  (C2855) and clang refuses a PCH built with other language options.
  Such a file compiles without the PCH.
- group.mTags=="nvcc"; compared instead of assigning, so an <nvcc/>
  group kept the tags haxe,static and was given the host compiler's
  flags, which nvcc takes only through -Xcompiler. The tag is set.
- Setup looked for NDKV6 to NDKV19 only, so -DNDKV25 was ignored and
  the newest NDK under ANDROID_NDK_DIR used. Any NDKV<n> is read, the
  lowest if several are given. An NDK without meta/platforms.json then
  stopped the build with "Invalid field access : toString" while
  warning about it; the warning prints now.

Test, on Windows x64: a file with cxx_standard='17' in a PCH group
compiles and runs; a stand-in nvcc.exe that prints its arguments gets
no host flags; with fake NDKs 25 and 28, -DNDKV25 picks 25 and
-DNDKV28 picks 28.

Fixes #472
The build tool decides what to rebuild by comparing files against
haxe-target.xml's depend lists, and the compile cache key hashes only
the files listed. Headers hxcpp.h includes, directly or not, were
missing from hxcpp-depends (hx/Functions.h, hx/FieldRef.h,
hx/ErrorCodes.h, hx/Boot.h, hx/Undefine.h, cpp/CppInt32__.h,
cpp/FastIterator.h, cpp/marshal/RootHandle.hpp and hx/Invoker.h), and
headers the runtime's sources include were missing from its group
(hx/DynamicImpl.h, hx/Memory.h, hx/NekoFunc.h, hx/CFFIJsPrime.h,
hx/CFFINekoLoader.h, hx/TelemetryTracy.h and src/hx/FastMutex.h). So
editing one, as an update of a haxelib git or dev checkout does,
rebuilt nothing, and the cache relinked objects built before it.

They are listed, and tools/check-depends.py, run in the Check headers
job, fails when a header either reaches is missing again.

Test: #error appended to include/hx/Functions.h now fails the next
build, where it rebuilt nothing and exited 0 before; check-depends.py
passes, and failed on main.

Fixes #469
Before every build with the compile cache, the build tool stat'ed
every file in it to keep it under HXCPP_CACHE_MB, even when the build
had nothing to compile. With tens of thousands of files that took up
to seconds a build. It trims when the cache's .trimmed stamp is older
than ten minutes, and writes the stamp when it does.

Measured with HXCPP_TIMES, a build with nothing to compile and a cache
of 29792 files, three runs each on Windows x64: "setup cache" took
1138, 142 and 98 ms before, and 162 (the trim), 14 and 3 ms after.

The other fixed cost in #473, running the MSVC setup script on every
build (2.7 to 9.4 s in the same runs), is not changed here.

Part of #473
When a compile thread could not start its command, as when clang-cl is
not on PATH, it set the build's error while holding the log lock. With
HXCPP_EXIT_ON_ERROR that ends the thread, which left the lock held, and
every other compile thread then waited for it for ever. The error is now
set after the lock is released.
Since NDKV20 and up are read, any NDKV define searched for the NDK and
ignored ANDROID_NDK_ROOT. The search through ANDROID_SDK finds only the
newest NDK there, so a build with ANDROID_NDK_ROOT at NDK 25, NDKs 25 and
28 installed and a leftover -DNDKV25 stopped with "does not contain
requested NDK 25", where it used to build with the configured root. A
configured root that is the requested version is now used as it is.
check.sh passed any build that failed, so one failing for an unrelated
reason, such as a missing tool or a Haxe setup problem, passed too. Each
case now also needs the error it is about in its log: the undefined
function the error test calls, or the build tool's message about two
optimisation tags.
link() takes a lock that every module load shares, and allocates while
holding it: resolving each host class makes a String. A thread blocked
on that lock was outside a GC-free zone, so a collection the linking
thread reached waited for it, while it waited for the linking thread.
Two threads loading modules at once could hang the process. A thread
that finds the lock taken now waits for it in a GC-free zone.
A cpp.Pointer field is marked by searching back from where it points for
the allocation's start, and since its reach covers the whole block, a
field holding exactly a block's base address, such as one past the end
of an array whose buffer ends where its block does, made the offset wrap
and the search walk for hours. A block's base holds no object, so such
a field now marks nothing.

Test: GcPointerFieldBlockBase points 100 cpp.Pointer fields at the base
of the block their arrays are in and collects 5 times.
adoptInstances moved an instance when its class's methods kept their
names and vtable slots, but a call site keeps the types it linked with:
change only a():String to a():Int, and old code calling a() on a moved
instance read the Int as a String. A method's return and argument types
must now match too, for script interfaces as well.

Test: CppiaAdoptLayouts has a scenario that retypes a method's return,
which now keeps its instances, interpreted and under the JIT.
Haxe 4.3.7 types almost every enum parameter read as Dynamic, so the
JIT's new bounds check sent nearly every read through a native call that
boxed the value, an allocation for a Float, a String or most Ints on a
hot path of pattern matching. A script enum's reads stayed inline, bound
only by its largest constructor, so a malformed file could still read
past a value with fewer parameters. Every read now compares the index
with the value's own count inline and reads the parameter there, and
only a null value or an index past the count takes the call.

A super constructor call is also checked against every class the linking
class extends: a class with no constructor of its own links the one it
inherits, and a valid file whose inherited constructor calls its own
super class failed to load.
The C++ helper was attached to Holder, so it went to Holder.cpp and
Main.cpp, which calls it, did not build.
The runner never closed a test's process, so the pipes to it stayed open
and every later test inherited them. By SocketSelectHighDescriptors,
some 290 tests in, its 80 sockets were past macOS's FD_SETSIZE of 1024,
select failed, and the test exited 255 on macOS arm64 once the suite had
grown by a few tests. Run alone it passes there.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment