aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/hipe/hipe_bif0.c
diff options
context:
space:
mode:
authorMikael Pettersson <[email protected]>2010-08-11 19:31:43 +0200
committerBjörn Gustavsson <[email protected]>2010-08-13 11:03:44 +0200
commit6b8733b2b7e240bbda505b10e6e443f9278451b8 (patch)
treeaac9d8a2daa0e74751a416f5cfe13110a8f45c6e /erts/emulator/hipe/hipe_bif0.c
parent871fdb232d7facc58c202ef81634a12fbdcfefb4 (diff)
downloadotp-6b8733b2b7e240bbda505b10e6e443f9278451b8.tar.gz
otp-6b8733b2b7e240bbda505b10e6e443f9278451b8.tar.bz2
otp-6b8733b2b7e240bbda505b10e6e443f9278451b8.zip
fix hipe_bifs_alloc_data_2 to avoid "Yikes!" warning
It's been reported that HiPE-enabled Erlang VMs running on BSD systems sometimes generate messages like Yikes! erts_alloc() returned misaligned address 0x8016a512c These originate from hipe_bif0.c:hipe_bifs_alloc_data_2(). A native code module has an associated data area of some size and alignment. In the case where the size is zero, the alignment is irrelevant, but the allocation BIF checks it anyway. The warning then triggers on systems where malloc(0) returns blocks with less alignment than we (erroneously) expected. The fix is to simply skip the allocation in this case and return NULL. The loader won't actually use the address in this case so that's safe. This is also an optimization since it avoids allocating memory that cannot be used, and it avoids fragmenting the system heap with useless tiny blocks. A second problem is that the warning message failed to identify its origin. Fixed by prefixing the message by the BIF's name rather than the silly Yikes! string. Tested and confirmed to solve the original reporter's problem.
Diffstat (limited to 'erts/emulator/hipe/hipe_bif0.c')
-rw-r--r--erts/emulator/hipe/hipe_bif0.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/erts/emulator/hipe/hipe_bif0.c b/erts/emulator/hipe/hipe_bif0.c
index b0abfd2310..2a877d8ace 100644
--- a/erts/emulator/hipe/hipe_bif0.c
+++ b/erts/emulator/hipe/hipe_bif0.c
@@ -440,9 +440,12 @@ BIF_RETTYPE hipe_bifs_alloc_data_2(BIF_ALIST_2)
align != sizeof(long) && align != sizeof(double)))
BIF_ERROR(BIF_P, BADARG);
nrbytes = unsigned_val(BIF_ARG_2);
+ if (nrbytes == 0)
+ BIF_RET(make_small(0));
block = erts_alloc(ERTS_ALC_T_HIPE, nrbytes);
if ((unsigned long)block & (align-1))
- fprintf(stderr, "Yikes! erts_alloc() returned misaligned address %p\r\n", block);
+ fprintf(stderr, "%s: erts_alloc(%lu) returned %p which is not %lu-byte aligned\r\n",
+ __FUNCTION__, (unsigned long)nrbytes, block, (unsigned long)align);
BIF_RET(address_to_term(block, BIF_P));
}