Skip to content

Commit 98f59c7

Browse files
authored
[emmalloc] Fix verbose output (#23069)
toString() was undeclared. Fixes a regression introduced in commit 04a0cad.
1 parent 5c5f5a1 commit 98f59c7

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

system/lib/emmalloc.c

+16-18
Original file line numberDiff line numberDiff line change
@@ -358,16 +358,16 @@ static void dump_memory_regions() {
358358
Region *r = (Region*)root;
359359
assert(debug_region_is_consistent(r));
360360
uint8_t *lastRegionEnd = root->endPtr;
361-
MAIN_THREAD_ASYNC_EM_ASM(out('Region block '+ptrToString($0)+' - '+ptrToString($1)+ ' ('+toString(Number($2))+' bytes):'),
361+
MAIN_THREAD_ASYNC_EM_ASM(out('Region block '+ptrToString($0)+' - '+ptrToString($1)+ ' ('+Number($2)+' bytes):'),
362362
r, lastRegionEnd, lastRegionEnd-(uint8_t*)r);
363363
while ((uint8_t*)r < lastRegionEnd) {
364-
MAIN_THREAD_ASYNC_EM_ASM(out('Region '+ptrToString($0)+', size: '+toString(Number($1))+' ('+($2?"used":"--FREE--")+')'),
364+
MAIN_THREAD_ASYNC_EM_ASM(out('Region '+ptrToString($0)+', size: '+Number($1)+' ('+($2?"used":"--FREE--")+')'),
365365
r, r->size, region_ceiling_size(r) == r->size);
366366

367367
assert(debug_region_is_consistent(r));
368368
size_t sizeFromCeiling = size_of_region_from_ceiling(r);
369369
if (sizeFromCeiling != r->size) {
370-
MAIN_THREAD_ASYNC_EM_ASM(out('Corrupt region! Size marker at the end of the region does not match: '+toString(Number($0))), sizeFromCeiling);
370+
MAIN_THREAD_ASYNC_EM_ASM(out('Corrupt region! Size marker at the end of the region does not match: '+Number($0)), sizeFromCeiling);
371371
}
372372
if (r->size == 0) {
373373
break;
@@ -382,7 +382,7 @@ static void dump_memory_regions() {
382382
Region *prev = &freeRegionBuckets[i];
383383
Region *fr = freeRegionBuckets[i].next;
384384
while (fr != &freeRegionBuckets[i]) {
385-
MAIN_THREAD_ASYNC_EM_ASM(out('In bucket '+$0+', free region '+ptrToString($1)+', size: ' + toString(Number($2)) + ' (size at ceiling: '+toString(Number($3))+'), prev: ' + ptrToString($4) + ', next: ' + ptrToString($5)),
385+
MAIN_THREAD_ASYNC_EM_ASM(out('In bucket '+$0+', free region '+ptrToString($1)+', size: ' + Number($2) + ' (size at ceiling: '+Number($3)+'), prev: ' + ptrToString($4) + ', next: ' + ptrToString($5)),
386386
i, fr, fr->size, size_of_region_from_ceiling(fr), fr->prev, fr->next);
387387
assert(debug_region_is_consistent(fr));
388388
assert(region_is_free(fr));
@@ -393,7 +393,7 @@ static void dump_memory_regions() {
393393
fr = fr->next;
394394
}
395395
}
396-
MAIN_THREAD_ASYNC_EM_ASM(out('Free bucket index map: ' + toString(Number($0)).toString(2) + ' ' + toString(Number($1)).toString(2)), (uint32_t)(freeRegionBucketsUsed >> 32), (uint32_t)freeRegionBucketsUsed);
396+
MAIN_THREAD_ASYNC_EM_ASM(out('Free bucket index map: ' + Number($0).toString(2) + ' ' + Number($1).toString(2)), (uint32_t)(freeRegionBucketsUsed >> 32), (uint32_t)freeRegionBucketsUsed);
397397
MAIN_THREAD_ASYNC_EM_ASM(out(""));
398398
}
399399

@@ -409,14 +409,14 @@ static int validate_memory_regions() {
409409
while (root) {
410410
Region *r = (Region*)root;
411411
if (!debug_region_is_consistent(r)) {
412-
MAIN_THREAD_ASYNC_EM_ASM(err('Used region '+ptrToString($0)+', size: '+toString(Number($1))+' ('+($2?"used":"--FREE--")+') is corrupt (size markers in the beginning and at the end of the region do not match!)'),
412+
MAIN_THREAD_ASYNC_EM_ASM(err('Used region '+ptrToString($0)+', size: '+Number($1)+' ('+($2?"used":"--FREE--")+') is corrupt (size markers in the beginning and at the end of the region do not match!)'),
413413
r, r->size, region_ceiling_size(r) == r->size);
414414
return 1;
415415
}
416416
uint8_t *lastRegionEnd = root->endPtr;
417417
while ((uint8_t*)r < lastRegionEnd) {
418418
if (!debug_region_is_consistent(r)) {
419-
MAIN_THREAD_ASYNC_EM_ASM(err('Used region '+ptrToString($0)+', size: '+toString(Number($1))+' ('+($2?"used":"--FREE--")+') is corrupt (size markers in the beginning and at the end of the region do not match!)'),
419+
MAIN_THREAD_ASYNC_EM_ASM(err('Used region '+ptrToString($0)+', size: '+Number($1)+' ('+($2?"used":"--FREE--")+') is corrupt (size markers in the beginning and at the end of the region do not match!)'),
420420
r, r->size, region_ceiling_size(r) == r->size);
421421
return 1;
422422
}
@@ -432,7 +432,7 @@ static int validate_memory_regions() {
432432
Region *fr = freeRegionBuckets[i].next;
433433
while (fr != &freeRegionBuckets[i]) {
434434
if (!debug_region_is_consistent(fr) || !region_is_free(fr) || fr->prev != prev || fr->next == fr || fr->prev == fr) {
435-
MAIN_THREAD_ASYNC_EM_ASM(out('In bucket '+$0+', free region '+ptrToString($1)+', size: ' + toString(Number($2)) + ' (size at ceiling: '+toString(Number($3))+'), prev: ' + ptrToString($4) + ', next: 0x' + ptrToString($5) + ' is corrupt!'),
435+
MAIN_THREAD_ASYNC_EM_ASM(out('In bucket '+$0+', free region '+ptrToString($1)+', size: ' + Number($2) + ' (size at ceiling: '+Number($3)+'), prev: ' + ptrToString($4) + ', next: 0x' + ptrToString($5) + ' is corrupt!'),
436436
i, fr, fr->size, size_of_region_from_ceiling(fr), fr->prev, fr->next);
437437
return 1;
438438
}
@@ -629,7 +629,7 @@ static void *attempt_allocate(Region *freeRegion, size_t alignment, size_t size)
629629
#endif
630630

631631
#ifdef EMMALLOC_VERBOSE
632-
MAIN_THREAD_ASYNC_EM_ASM(out('attempt_allocate - succeeded allocating memory, region ptr=' + ptrToString($0) + ', align=' + $1 + ', payload size=' + toString(Number($2)) + ' bytes)'), freeRegion, alignment, size);
632+
MAIN_THREAD_ASYNC_EM_ASM(out('attempt_allocate - succeeded allocating memory, region ptr=' + ptrToString($0) + ', align=' + $1 + ', payload size=' + Number($2) + ' bytes)'), freeRegion, alignment, size);
633633
#endif
634634

635635
return (uint8_t*)freeRegion + sizeof(size_t);
@@ -651,15 +651,13 @@ static size_t validate_alloc_size(size_t size) {
651651
return validatedSize;
652652
}
653653

654-
#ifdef EMMALLOC_VERBOSE
655654
EM_JS_DEPS(deps, "$ptrToString");
656-
#endif
657655

658656
static void *allocate_memory(size_t alignment, size_t size) {
659657
ASSERT_MALLOC_IS_ACQUIRED();
660658

661659
#ifdef EMMALLOC_VERBOSE
662-
MAIN_THREAD_ASYNC_EM_ASM(out('allocate_memory(align=' + $0 + ', size=' + toString(Number($1)) + ' bytes)'), alignment, size);
660+
MAIN_THREAD_ASYNC_EM_ASM(out('allocate_memory(align=' + $0 + ', size=' + Number($1) + ' bytes)'), alignment, size);
663661
#endif
664662

665663
#ifdef EMMALLOC_MEMVALIDATE
@@ -675,7 +673,7 @@ static void *allocate_memory(size_t alignment, size_t size) {
675673

676674
if (size > MAX_ALLOC_SIZE) {
677675
#ifdef EMMALLOC_VERBOSE
678-
MAIN_THREAD_ASYNC_EM_ASM(out('Allocation failed: attempted allocation size is too large: ' + toString(Number($0)) + 'bytes! (negative integer wraparound?)'), size);
676+
MAIN_THREAD_ASYNC_EM_ASM(out('Allocation failed: attempted allocation size is too large: ' + Number($0) + 'bytes! (negative integer wraparound?)'), size);
679677
#endif
680678
return 0;
681679
}
@@ -930,7 +928,7 @@ static int attempt_region_resize(Region *region, size_t size) {
930928
assert(HAS_ALIGNMENT(size, sizeof(size_t)));
931929

932930
#ifdef EMMALLOC_VERBOSE
933-
MAIN_THREAD_ASYNC_EM_ASM(out('attempt_region_resize(region=' + ptrToString($0) + ', size=' + toString(Number($1)) + ' bytes)'), region, size);
931+
MAIN_THREAD_ASYNC_EM_ASM(out('attempt_region_resize(region=' + ptrToString($0) + ', size=' + Number($1) + ' bytes)'), region, size);
934932
#endif
935933

936934
// First attempt to resize this region, if the next region that follows this one
@@ -988,7 +986,7 @@ static int acquire_and_attempt_region_resize(Region *region, size_t size) {
988986

989987
void *emmalloc_aligned_realloc(void *ptr, size_t alignment, size_t size) {
990988
#ifdef EMMALLOC_VERBOSE
991-
MAIN_THREAD_ASYNC_EM_ASM(out('aligned_realloc(ptr=' + ptrToString($0) + ', alignment=' + $1 + ', size=' + toString(Number($2))), ptr, alignment, size);
989+
MAIN_THREAD_ASYNC_EM_ASM(out('aligned_realloc(ptr=' + ptrToString($0) + ', alignment=' + $1 + ', size=' + Number($2)), ptr, alignment, size);
992990
#endif
993991

994992
if (!ptr) {
@@ -1002,7 +1000,7 @@ void *emmalloc_aligned_realloc(void *ptr, size_t alignment, size_t size) {
10021000

10031001
if (size > MAX_ALLOC_SIZE) {
10041002
#ifdef EMMALLOC_VERBOSE
1005-
MAIN_THREAD_ASYNC_EM_ASM(out('Allocation failed: attempted allocation size is too large: ' + toString(Number($0)) + 'bytes! (negative integer wraparound?)'), size);
1003+
MAIN_THREAD_ASYNC_EM_ASM(out('Allocation failed: attempted allocation size is too large: ' + Number($0) + 'bytes! (negative integer wraparound?)'), size);
10061004
#endif
10071005
return 0;
10081006
}
@@ -1052,7 +1050,7 @@ void *emmalloc_realloc_try(void *ptr, size_t size) {
10521050

10531051
if (size > MAX_ALLOC_SIZE) {
10541052
#ifdef EMMALLOC_VERBOSE
1055-
MAIN_THREAD_ASYNC_EM_ASM(out('Allocation failed: attempted allocation size is too large: ' + toString(Number($0)) + 'bytes! (negative integer wraparound?)'), size);
1053+
MAIN_THREAD_ASYNC_EM_ASM(out('Allocation failed: attempted allocation size is too large: ' + Number($0) + 'bytes! (negative integer wraparound?)'), size);
10561054
#endif
10571055
return 0;
10581056
}
@@ -1086,7 +1084,7 @@ void *emmalloc_aligned_realloc_uninitialized(void *ptr, size_t alignment, size_t
10861084

10871085
if (size > MAX_ALLOC_SIZE) {
10881086
#ifdef EMMALLOC_VERBOSE
1089-
MAIN_THREAD_ASYNC_EM_ASM(out('Allocation failed: attempted allocation size is too large: ' + toString(Number($0)) + 'bytes! (negative integer wraparound?)'), size);
1087+
MAIN_THREAD_ASYNC_EM_ASM(out('Allocation failed: attempted allocation size is too large: ' + Number($0) + 'bytes! (negative integer wraparound?)'), size);
10901088
#endif
10911089
return 0;
10921090
}

test/test_core.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -797,8 +797,7 @@ def test_mainenv(self):
797797
'memvalidate_verbose': ['-DEMMALLOC_MEMVALIDATE', '-DEMMALLOC_VERBOSE', '-DRANDOM_ITERS=130'],
798798
})
799799
def test_emmalloc(self, *args):
800-
if '-DEMMALLOC_VERBOSE' in args and self.is_wasm64():
801-
self.skipTest('EMMALLOC_VERBOSE is not compatible with wasm64')
800+
self.maybe_closure()
802801
# in newer clang+llvm, the internal calls to malloc in emmalloc may be optimized under
803802
# the assumption that they are external, so like in system_libs.py where we build
804803
# malloc, we need to disable builtin here too

0 commit comments

Comments
 (0)