diff options
author | Rickard Green <[email protected]> | 2016-05-27 10:21:30 +0200 |
---|---|---|
committer | Rickard Green <[email protected]> | 2016-05-27 10:21:30 +0200 |
commit | a390d27f5c39d5a120db1f3e8e7185f85a05debd (patch) | |
tree | 3bd2a5e996576f5d07213f298e67b5a947b68ccf /erts/emulator/beam/erl_nif.c | |
parent | 48d0c9844b1d205683dd3ef2ab6719e3f0f14aba (diff) | |
parent | 20383144c26512fe33e72f49dff52dc628666923 (diff) | |
download | otp-a390d27f5c39d5a120db1f3e8e7185f85a05debd.tar.gz otp-a390d27f5c39d5a120db1f3e8e7185f85a05debd.tar.bz2 otp-a390d27f5c39d5a120db1f3e8e7185f85a05debd.zip |
Merge branch 'rickard/on_heap-fix/OTP-13366'
* rickard/on_heap-fix/OTP-13366:
Improve message allocation in enif_send()
Fix message queue update on replacement and removal of message
Diffstat (limited to 'erts/emulator/beam/erl_nif.c')
-rw-r--r-- | erts/emulator/beam/erl_nif.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/erts/emulator/beam/erl_nif.c b/erts/emulator/beam/erl_nif.c index 606b73c7b5..2bbb8e3c91 100644 --- a/erts/emulator/beam/erl_nif.c +++ b/erts/emulator/beam/erl_nif.c @@ -623,10 +623,28 @@ int enif_send(ErlNifEnv* env, const ErlNifPid* to_pid, } } else { Uint sz = size_object(msg); + ErlOffHeap *ohp; Eterm *hp; - mp = erts_alloc_message(sz, &hp); - msg = copy_struct(msg, sz, &hp, &mp->hfrag.off_heap); - ASSERT(hp == mp->hfrag.mem+mp->hfrag.used_size); + if (env && !env->tracee) { + flush_env(env); + mp = erts_alloc_message_heap(rp, &rp_locks, sz, &hp, &ohp); + cache_env(env); + } + else { + erts_aint_t state = erts_smp_atomic32_read_nob(&rp->state); + if (state & ERTS_PSFLG_OFF_HEAP_MSGQ) { + mp = erts_alloc_message(sz, &hp); + ohp = sz == 0 ? NULL : &mp->hfrag.off_heap; + } + else { + ErlHeapFragment *bp = new_message_buffer(sz); + mp = erts_alloc_message(0, NULL); + mp->data.heap_frag = bp; + hp = bp->mem; + ohp = &bp->off_heap; + } + } + msg = copy_struct(msg, sz, &hp, ohp); } ERL_MESSAGE_TERM(mp) = msg; |