Repository navigation
Commit 35cede7
authored
Fix seven runtime problems found in stock hxcpp's recent reports (#499)
Erase a moved object's old id entry before inserting its new address
When the moving collector moves an object that has an id, MoveSpecial
found its entry in sObjectIdMap, inserted the new address with
operator[], and then erased the old entry through the iterator it had
found. The insert can rehash the unordered_map, and a rehash invalidates
every iterator, so the erase was undefined behaviour. Any id'd object
can be moved, ObjectMap keys among them, since under HXCPP_GC_MOVING
they all take their hash from __hxcpp_obj_id.
The id is now read out, the old entry erased, and the new one inserted,
as the finalizer and zombie maps just above already do.
No test can fail before this: libstdc++, libc++ and MSVC all keep a
node's iterator valid through a rehash, even in their debug modes.
Issue679 moves 20,000 ObjectMap keys through compactions and still
finds every one.
HaxeFoundation/hxcpp#1468
Tests: Issue679
Check the length of an IPv6 address array before reading it
host_to_string_ipv6, socket_connect_ipv6 and socket_bind_ipv6 read 16
bytes from &host[0] whatever the array's length. An empty array grew to
one element and was read 15 bytes past it, a shorter one was read past
its end, and a null one crashed. So host_to_string_ipv6 of four 0xff
bytes gave "ffff:ffff::106:8010", and connect and bind went to whatever
address followed the array in memory. host_reverse_ipv6 already checked
for 16 bytes and copied them out first.
The four functions share one helper now, which copies the address out
of the array and refuses a null array or one of any length but 16.
host_to_string_ipv6 gives null for such an array, as host_reverse_ipv6
does, and connect and bind throw "Invalid IPv6 address". sys.net.Host
always passes the 16 bytes host_resolve_ipv6 made, so only direct
cpp.NativeSocket callers could reach this.
HaxeFoundation/hxcpp@a8a5724f, which swapped &a[0] for Pointer() in
these functions, does not check the length either.
Tests: SocketIpv6AddressLength
Run a cppia var statement with no declarations without indexing it
TVars reads its declaration count from the file, and checkCount accepts
0. runVoid then started from &vars[0] on the empty vector, which is
undefined behaviour: a standard library that checks indexing, such as
libstdc++ with _GLIBCXX_ASSERTIONS or MSVC's checked iterators, stops
the program there. The Haxe compiler never writes an empty one, so only
a malformed or hand-made file reaches it. BlockExpr guards the same
pattern with a size check.
runVoid walks the declarations by index now, as genCode already did.
CppiaEmptyVars loads hand-written modules whose main is an empty var
statement, alone and twice in a block, and runs them interpreted and
under the JIT. No build here checks indexing, so it passed before too.
HaxeFoundation/hxcpp@a8a5724f
Tests: CppiaEmptyVars
Stop for a collection in the atomic operations on a plain int *
libhxcpp #455 made Haxe 4's haxe.atomic.AtomicInt operations safe
points, through cpp::Pointer<int> overloads of the _hx_atomic_*
functions. Haxe 5.0.0-preview.1's AtomicInt is a class with an Int
field instead, and calls _hx_atomic_add(&{0}, ...) on that field, so it
passes a plain int *. That binds to the runtime's volatile int * forms,
which never stop, so a thread spinning on flag.load() still held up
every collection, and every other thread with it. AtomicBool wraps
AtomicInt and had the same gap. AtomicSpinSafePoint has failed this
way on the preview.1 jobs, where failures are warnings.
The stopping forms take an int * now, and the cpp::Pointer<int> ones
call them. The runtime's own spinlocks pass a volatile int *, so they
keep the forms that do not stop. _hx_atomic_xor was the one runtime
form that took an int *; it takes a volatile int * like the others.
AtomicFieldSpinSafePoint does what preview.1's AtomicInt does on any
Haxe: a thread spins on each of the nine operations in turn, called on
the address of an Int field, while the main thread collects. Before
this, the first collection never finished and its watchdog ended the
test after 60 s; it passes in under a second now, and with
HXCPP_GC_MOVING.
HaxeFoundation/hxcpp#1443
Tests: AtomicFieldSpinSafePoint, AtomicSpinSafePoint
Say an Int is not an Int64
haxe.Int64.isInt64(100) was true on C++ and false on the other targets,
and so was isInt64(1.0), because a whole Float boxes as an Int. Haxe 4.2
implements isInt64 with cpp::Int64Struct::is, which asks Int64Handler,
and Haxe 4.3 and 5.0.0-preview.1 with Std.isOfType(val, cpp.Int64),
which asks the cpp::Int64 class's IsInt64 in Dynamic.cpp. Both took a
boxed Int as well as a boxed Int64.
They took Ints because small Int64 values, -1 to 255, used to come out
of the boxed Int cache. Since 6.0.0 they have a cache of their own, so
every boxed Int64 is an Int64Data and reports vtInt64, and both checks
now take only that. This changes behaviour for code that used isInt64
to accept any integer. Std.isOfType(int64, Int) stays true for a value
that fits, as for a whole Float.
Int64IsInt64 checks isInt64 on Ints, a whole Float, null, a String and
Int64 values on both sides of the box cache, asks the handler and the
class directly so each is covered whichever Haxe builds it, and asks
again from a cppia script, interpreted and under the JIT. Before this,
the Int, 0 and 1.0 cases were all true.
HaxeFoundation/hxcpp#1461
Tests: Int64IsInt64
Report a thread that allocates in a GC-free zone during a collection
A thread in a GC-free zone that allocates, or collects, while another
thread collects reaches PauseForCollect and waits there for the
collection to finish. The collector neither waits for a thread in a
zone nor releases it at the end, so in a release build that thread
waited for ever, with nothing to say why. Native code that misses an
ExitGCFreeZone is the usual way there. Debug builds report any
allocation or collection in a zone, before it gets that far.
PauseForCollect now ends the program with a critical error that names
the misuse when its thread is in a zone. No correct caller gets there:
safe points return first in a zone, as do the Mutex and Condition fast
paths that call them, and ExitGCFreeZone waits out a collection on the
state lock instead.
GcFreeZoneAllocationReported runs the misuse in a child process: one
thread enters a zone and allocates once a collection is pending, while
another keeps it pending by reaching no safe point for half a second.
Before this the allocation never returned and the child said so after
5 s; now the child prints the error and ends, and a debug build's own
message is accepted too.
HaxeFoundation/hxcpp#1468
Tests: GcFreeZoneAllocationReported
Say how many certificates did not parse instead of a wrong mbedTLS error
mbedtls_x509_crt_parse_file and mbedtls_x509_crt_parse_path return a
negative error code, or, when they parsed something, a positive count
of the certificates they could not parse. cert_load_file and
cert_load_path passed any non-zero result to ssl_error, and
mbedtls_strerror negates a positive value and looks it up: one bad
certificate threw "ERROR - Generic error", two "BIGNUM - An error
occurred while reading from or writing to a file", and so on.
A negative result still goes to ssl_error. A positive one throws "Could
not parse 1 certificate in <file>", or "certificates" for more. For a
directory the message says "certificates or files", because
parse_path also counts each file it could not read a certificate from.
Both still throw, as before; whether a directory or bundle that partly
parsed should be kept instead is left for its own change.
SslCertificateParseCount writes a good certificate, the same with one
corrupt certificate after it, and one between two corrupt ones, loads
each, and loads a directory with a certificate and a text file. Before
this, the three messages were the mbedTLS ones.
HaxeFoundation/hxcpp@45adede6
Tests: SslCertificateParseCount
Link a cppia script's host static object fields directly below API 500
HaxeFoundation/hxcpp#1047, to keep typed callables working at API level
500, stopped cppia linking a host class's static object fields to a
direct reference: a script closure stored through an hx::Object pointer
into a typed function slot is not callable as one. The exclusion had no
API level guard, so in Haxe 4 builds, and Haxe 5.0.0-preview.1 ones,
which build against the 430 runtime, every script read or write of a
host static object, a singleton, a static Array or a static function,
was a __GetStatic or __SetStatic by name, interpreted and jitted.
c653b13 restored direct access for object members the same way and
left statics out.
The exclusion applies at API level 500 only now, as for members, and
below that an object static gets the same MemReference an Int or String
static already had. Statics are roots, marked at the start of every
collection, so the direct store needs no write barrier, as a compiled
store into a static has none.
A new host_statics workload in bench/cppia reads one host static Array
and stores another on each pass. Against f0622380, with --base:
interpreter 13.2M -> 23.4M iterations/s (14.3M -> 25.8M rerun)
JIT 31.5M -> 386M iterations/s (35.6M -> 542M rerun)
native_call, which this cannot reach, read 8% slower under the JIT in
both runs (287M against 312M). Keeping only Script.main's store to
CppiaBridge.workload on the named path brought it to 296M against 301M,
within the spread: the JIT compiles lazily, so main's smaller code moved
every function compiled after it.
CppiaHostStaticObjects has a script store young objects, an Array and
a closure into host statics that alone hold them, through minor and full
collections with HXCPP_GC_GENERATIONAL, then read them back in the
script and in the host, interpreted and under the JIT. It passed before
too, through the named path.
HaxeFoundation/hxcpp#1365
Tests: CppiaHostStaticObjects, CppiaObjectFields1 parent 7a45d8c commit 35cede7
39 files changed
Lines changed: 626 additions & 39 deletions
File tree
- bench
- cppia
- src
- include
- cpp
- hx
- src
- hx
- cppia
- gc
- libs
- ssl
- std
- test/regression
- AtomicFieldSpinSafePoint
- CppiaEmptyVars
- CppiaHostStaticObjects
- GcFreeZoneAllocationReported
- Int64IsInt64
- SocketIpv6AddressLength
- SslCertificateParseCount
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
9 | 17 | | |
10 | 18 | | |
11 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
147 | 148 | | |
148 | 149 | | |
149 | 150 | | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
8 | 11 | | |
9 | 12 | | |
10 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
35 | 37 | | |
36 | | - | |
37 | | - | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
574 | 574 | | |
575 | 575 | | |
576 | 576 | | |
577 | | - | |
578 | | - | |
579 | | - | |
580 | | - | |
581 | | - | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
582 | 584 | | |
583 | | - | |
584 | | - | |
585 | | - | |
586 | | - | |
587 | | - | |
588 | | - | |
589 | | - | |
590 | | - | |
591 | | - | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
592 | 594 | | |
593 | 595 | | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
594 | 606 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
427 | 427 | | |
428 | 428 | | |
429 | 429 | | |
430 | | - | |
| 430 | + | |
431 | 431 | | |
432 | 432 | | |
433 | 433 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
636 | 636 | | |
637 | 637 | | |
638 | 638 | | |
| 639 | + | |
| 640 | + | |
639 | 641 | | |
640 | 642 | | |
641 | | - | |
| 643 | + | |
642 | 644 | | |
643 | 645 | | |
644 | 646 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3272 | 3272 | | |
3273 | 3273 | | |
3274 | 3274 | | |
| 3275 | + | |
| 3276 | + | |
| 3277 | + | |
| 3278 | + | |
| 3279 | + | |
| 3280 | + | |
| 3281 | + | |
| 3282 | + | |
| 3283 | + | |
| 3284 | + | |
| 3285 | + | |
| 3286 | + | |
3275 | 3287 | | |
3276 | | - | |
3277 | | - | |
3278 | | - | |
3279 | | - | |
| 3288 | + | |
3280 | 3289 | | |
3281 | 3290 | | |
3282 | 3291 | | |
| |||
6632 | 6641 | | |
6633 | 6642 | | |
6634 | 6643 | | |
| 6644 | + | |
| 6645 | + | |
6635 | 6646 | | |
6636 | 6647 | | |
6637 | | - | |
6638 | | - | |
6639 | | - | |
6640 | | - | |
| 6648 | + | |
| 6649 | + | |
6641 | 6650 | | |
6642 | 6651 | | |
6643 | 6652 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4998 | 4998 | | |
4999 | 4999 | | |
5000 | 5000 | | |
| 5001 | + | |
| 5002 | + | |
5001 | 5003 | | |
5002 | 5004 | | |
5003 | 5005 | | |
5004 | | - | |
5005 | | - | |
| 5006 | + | |
5006 | 5007 | | |
| 5008 | + | |
| 5009 | + | |
5007 | 5010 | | |
5008 | 5011 | | |
5009 | 5012 | | |
| |||
8358 | 8361 | | |
8359 | 8362 | | |
8360 | 8363 | | |
| 8364 | + | |
| 8365 | + | |
| 8366 | + | |
| 8367 | + | |
| 8368 | + | |
| 8369 | + | |
| 8370 | + | |
8361 | 8371 | | |
8362 | 8372 | | |
8363 | 8373 | | |
| |||
0 commit comments