aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/beam/erl_bif_binary.c
AgeCommit message (Collapse)Author
2019-08-09erts: Create heap binaries in binary:split/2-3John Högberg
2019-08-09erts: Create heap binaries in binary_part/2-3John Högberg
2019-02-14Merge branch 'maint'Kjell Winblad
2019-01-30Fix bug in binary:encode_unsigned causing a read of uninitialized memoryKjell Winblad
The bug could be seen by running the test that is added by this commit in a valgrind enabled emulator. Co-authored-by: John Högberg <[email protected]>
2018-12-13Simplify GC BIFsBjörn Gustavsson
Summary: This commit simplifies the implementation of the "GC BIFs" so that they no longer need to do a garbage collection, removing duplicate code for all GC BIFs in the runtime system, as well as potentially reducing the size of the loaded BEAM code by using shorter instructions calling those BIFs. A GC BIF is a guard BIF that will do a garbage collection if it needs to build anything on the heap. For example, `abs/1` is a GC BIF because it might need to allocate space on the heap (if the result is a floating point number or the resulting integer is a bignum). Before R12, a guard BIF (such as `abs/1`) that need to allocate heap space would allocate outside of process's main heap, in a heap fragment. GC BIFs were introduced in R12B to support literals. During garbage collection it become necessary to quickly test whether a term was a literal. To make the check simple, guards BIFs were no longer allowed to create heap fragments. Instead GC BIFs were introduced. In OTP 19, the implementation of literals was changed to support storing messages in heap fragments outside of the main heap for a process. That change again made it allowed for guard BIFs to create heap fragments when they need to build terms on the heap. It would even be possible for the guard BIFs to build directly on the main heap if there is room there, because the compiler assumes that a new `test_heap/2` instruction must be emitted when building anything after calling a GC BIF. (We don't do that in this commit; see below.) This commit simplifies the implementation of the GC BIFs in the runtime system. Each GC BIF had a dual implementation: one that was used when the GC BIF was called directly and one used when it was called via `apply/3`. For example, `abs/1` was implemented in `abs_1()` and `erts_gc_abs_1()`. This commit removes the GC version of each BIF. The other version that allocates heap space using `HAlloc()` is updated to use the new `HeapFragOnlyAlloc()` macro that will allocate heap space in a heap fragment outside of the main heap. Because the BIFs will allocate outside of the main heap, the same `bif` instructions used by nonbuilding BIFs can be used for the (former) GC BIFs. Those instructions don't use the macros that save and restore the heap and stack pointers (SWAPOUT/SWAPIN). If the former GC BIFs would build on the main heap, either new instructions would be needed, or SWAPOUT/SWAPIN instructions would need to be added to the `bif` instructions. Instructions that call the former GC BIFs don't need the operand that specifies the number of live X registers. Therefore, the instructions that call the BIFs are usually one word shorter.
2018-10-19erts: Fix compiler warning in erl_bif_binary.cSverker Eriksson
2018-10-03erts: Fix compiler warning in erl_bif_binary.cSverker Eriksson
2018-08-16Do not allocate good and bad shifts for single byte lookupsJosé Valim
The single byte lookups always rely on `memchr` and never really use the good and bad shifts arrays.
2018-08-16Merge branch 'josevalim/jv-sb/PR-1803/OTP-15238' into masterLukas Larsson
Optimize binary match from 10% up to 70x
2018-08-07Optimize binary matchJosé Valim
The idea is to use memchr on the first lookup for binary:match/2 and also after every match on binary:matches/2. We only use memchr in case of matches because benchmarks showed that using memchr even when we had false positives could negatively affect performance. This speeds up binary matching and binary splitting by 4x in some cases and by 70x in other scenarios (when the last character in the needle does not occur in the subject). The reason to use memchr is that it is highly specialized in most modern operating systems, often defaulting to SIMD operations. The implementation uses the reduction count to figure out how many bytes should be read with memchr. We could increase those numbers but they do not seem to make a large difference.
2018-06-18Update copyright yearHenrik Nord
2018-03-09Always use sys_memcpy/cmp/etc instead of plain memcpy/cmp/etcJohn Högberg
2018-02-26Replace binary:bin_to_list CIF implementation with binary_to_listJohn Högberg
binary:bin_to_list had a poor implementation that resulted in excessive garbage collection. binary_to_list is almost identical and has a generally better implementation, so I've replaced binary:bin_to_list's CIF with a thin wrapper around binary_to_list. Granted, binary_to_list has a deprecated indexing scheme, but we're unlikely to ever remote it entirely and it's somewhat easy to move it to the 'binary' module later on.
2018-01-16Merge branch 'sverker/build-proc-bin'Sverker Eriksson
2018-01-05erts: Refactor more usage of erts_build_proc_binSverker Eriksson
2017-09-13Merge branch 'potatosalad/erts/binary_find_bif_improved/PR-1480/OTP-14610'Lukas Larsson
* potatosalad/erts/binary_find_bif_improved/PR-1480/OTP-14610: stdlib: Improved BIF for binary matches and split.
2017-09-07Replace ad-hoc MIN/MAX macros with common onesJohn Högberg
Besides being noisy, they were already defined by a global Unix- specific header, causing the Windows build to fail if one forgot to define them.
2017-09-06stdlib: Improved BIF for binary matches and split.Andrew Bennett
2017-05-04Update copyright yearRaimo Niskanen
2017-04-11erts: Init refc=1 in erts_bin_nrml_allocSverker Eriksson
Only term_to_binary needed some extra attention as it used to initialize refc as 0 instead of 1.
2017-02-15Merge branch 'fix-source-typos'Björn Gustavsson
* fix-source-typos: (25 commits) Fixed typos in system/doc Fixed typos in lib/xmerl Fixed typos in lib/wx Fixed typos in lib/stdlib Fixed typos in lib/snmp Fixed typos in lib/ssl Fixed typos in lib/ssh Fixed typos in PKCS-8.asn1 file Fixed typos in lib/parsetools Fixed typos in lib/orber Fixed typos in lib/mnesia Fixed typos in lib/megaco Fixed typos in lib/kernel Fixed typos in lib/jinterface Fixed typos in lib/inets Fixed typos in lib/hipe Fixed typos in lib/eunit Fixed typos in lib/erl_interface Fixed typos in lib/eldap Fixed typos in lib/edoc ...
2017-02-14erts: Add deallocation veto for magic destructorsSverker Eriksson
A magic destructor can return 0 and thereby take control and prolong the lifetime of a magic binary.
2017-02-14Fixed typos in ertsAndrew Dryga
2017-02-06Use magic refs for binary compile patternsRickard Green
2016-03-15update copyright-yearHenrik Nord
2015-11-13stdlib: Fix bug in binary:split for empty binarySverker Eriksson
Bug introduced om master branch at b93e9b611056828a and reported in ERL-43.
2015-11-04Merge branch 'sverk/binary_split_bif'Sverker Eriksson
OTP-13082 * sverk/binary_split_bif: erts: Minor refactor for binary find BIF backend erts: Refactor BIF for binary:match,matches,split erts: Refactor backend of binary:split erts: Replace 0 with THE_NON_VALUE stdlib: Add BIF option 'trim_all' to binary:split/3 stdlib: Add BIF binary:split/2 and binary:split/3 Conflicts: bootstrap/lib/stdlib/ebin/binary.beam
2015-11-04erts: Minor refactor for binary find BIF backendAndrew Bennett
* Use NULL instead of THE_NON_VALUE for non-Eterm variable. * Add BinaryFindState_bignum struct to avoid unnecessary type casting.
2015-11-04erts: Refactor BIF for binary:match,matches,splitAndrew Bennett
with an common do_binary_find() used by match, matches and split.
2015-11-04erts: Refactor backend of binary:splitSverker Eriksson
to reduce code volume.
2015-11-04erts: Replace 0 with THE_NON_VALUESverker Eriksson
2015-11-04stdlib: Add BIF option 'trim_all' to binary:split/3Andrew Bennett
2015-11-04stdlib: Add BIF binary:split/2 and binary:split/3Andrew Bennett
2015-06-24erts: Remove HALFWORD_HEAP definitionBjörn-Egil Dahlberg
2015-06-18Change license text to APLv2Bruce Yinhe
2015-03-20Merge branch 'rickard/time_api/OTP-11997'Rickard Green
* rickard/time_api/OTP-11997: (22 commits) Update primary bootstrap inets: Suppress deprecated warning on erlang:now/0 inets: Cleanup of multiple copies of functions Add inets_lib with common functions used by multiple modules inets: Update comments Suppress deprecated warning on erlang:now/0 Use new time API and be back-compatible in inets Remove unused functions and removed redundant test asn1 test SUITE: Eliminate use of now/0 Disable deprecated warning on erlang:now/0 in diameter_lib Use new time API and be back-compatible in ssh Replace all calls to now/0 in CT with new time API functions test_server: Replace usage of erlang:now() with usage of new API Replace usage of erlang:now() with usage of new API Replace usage of erlang:now() with usage of new API Replace usage of erlang:now() with usage of new API Replace usage of erlang:now() with usage of new API otp_SUITE: Warn for calls to erlang:now/0 Replace usage of erlang:now() with usage of new API Multiple timer wheels Erlang based BIF timer implementation for scalability Implement ethread events with timeout ... Conflicts: bootstrap/bin/start.boot bootstrap/bin/start_clean.boot bootstrap/lib/compiler/ebin/beam_asm.beam bootstrap/lib/compiler/ebin/compile.beam bootstrap/lib/kernel/ebin/auth.beam bootstrap/lib/kernel/ebin/dist_util.beam bootstrap/lib/kernel/ebin/global.beam bootstrap/lib/kernel/ebin/hipe_unified_loader.beam bootstrap/lib/kernel/ebin/inet_db.beam bootstrap/lib/kernel/ebin/inet_dns.beam bootstrap/lib/kernel/ebin/inet_res.beam bootstrap/lib/kernel/ebin/os.beam bootstrap/lib/kernel/ebin/pg2.beam bootstrap/lib/stdlib/ebin/dets.beam bootstrap/lib/stdlib/ebin/dets_utils.beam bootstrap/lib/stdlib/ebin/erl_tar.beam bootstrap/lib/stdlib/ebin/escript.beam bootstrap/lib/stdlib/ebin/file_sorter.beam bootstrap/lib/stdlib/ebin/otp_internal.beam bootstrap/lib/stdlib/ebin/qlc.beam bootstrap/lib/stdlib/ebin/random.beam bootstrap/lib/stdlib/ebin/supervisor.beam bootstrap/lib/stdlib/ebin/timer.beam erts/aclocal.m4 erts/emulator/beam/bif.c erts/emulator/beam/erl_bif_info.c erts/emulator/beam/erl_db_hash.c erts/emulator/beam/erl_init.c erts/emulator/beam/erl_process.h erts/emulator/beam/erl_thr_progress.c erts/emulator/beam/utils.c erts/emulator/sys/unix/sys.c erts/preloaded/ebin/erlang.beam erts/preloaded/ebin/erts_internal.beam erts/preloaded/ebin/init.beam erts/preloaded/src/erts_internal.erl lib/common_test/test/ct_hooks_SUITE_data/cth/tests/empty_cth.erl lib/diameter/src/base/diameter_lib.erl lib/kernel/src/os.erl lib/ssh/test/ssh_basic_SUITE.erl system/doc/efficiency_guide/advanced.xml
2015-03-20Introduce a new time APIRickard Green
The old time API is based on erlang:now/0. The major issue with erlang:now/0 is that it was intended to be used for so many unrelated things. This tied these unrelated operations together and unnecessarily caused performance, scalability as well as accuracy, and precision issues for operations that do not need to have such issues. The new API spreads different functionality over multiple functions in order to improve on this. The new API consists of a number of new BIFs: - erlang:convert_time_unit/3 - erlang:monotonic_time/0 - erlang:monotonic_time/1 - erlang:system_time/0 - erlang:system_time/1 - erlang:time_offset/0 - erlang:time_offset/1 - erlang:timestamp/0 - erlang:unique_integer/0 - erlang:unique_integer/1 - os:system_time/0 - os:system_time/1 and a number of extensions of existing BIFs: - erlang:monitor(time_offset, clock_service) - erlang:system_flag(time_offset, finalize) - erlang:system_info(os_monotonic_time_source) - erlang:system_info(time_offset) - erlang:system_info(time_warp_mode) - erlang:system_info(time_correction) - erlang:system_info(start_time) See the "Time and Time Correction in Erlang" chapter of the ERTS User's Guide for more information.
2014-10-24Merge branch 'sverk/hipe-inline-reserve-trap-frame'Sverker Eriksson
* sverk/hipe-inline-reserve-trap-frame: erts: Extend usage of ASM macro to avoid including asm macros in C code erts: Make hipe_{un}reserve_beam_trap_frame INLINE
2014-10-24erts: Make hipe_{un}reserve_beam_trap_frame INLINESverker Eriksson
2014-09-04erts: Refactor binary allocation interface to also initialize BinarySverker Eriksson
except the reference counter 'refc', as different callers have different strategies regarding the lifetime of the binary.
2014-08-08erts: Fix neg int overflow when sint is min sizeLukas Larsson
When INT64_MIN is the value of a Sint64 we have to first cast it to an Uint64 before negating it. Otherwise we get an integer overflow which is undefined behaviour and in gcc 4.9 this results in -0 instead of -9223372036854775808 in gcc 4.8.
2014-05-22Make binary BIFs converting from lists yield on large inputRickard Green
- erlang:list_to_binary/1 - erlang:iolist_to_binary/1 - erlang:list_to_bitstring/1 - binary:list_to_bin/1
2013-09-20Check all pattern arguments passed to binary:matches/2Mike Sassak
Including an empty binary as one of multiple patterns passed to binary:matches/2 would crash BEAM with: "Cannot reallocate 1342177280 bytes of memory (of type "tmp")". This ensures each pattern is valid before trying to match.
2013-01-25Update copyright yearsBjörn-Egil Dahlberg
2012-02-21erts: Refactor new helper function erts_init_trap_exportSverker Eriksson
2011-12-09Update copyright yearsBjörn-Egil Dahlberg
2011-11-16Remove GCC 4.6 set-but-not-used warning from erl_bif_binaryPatrik Nyblom
2011-11-16Make binary:match with scope return correct valuesPatrik Nyblom
2011-10-26Use the proper macros in all BIFsBjörn Gustavsson
As a preparation for changing the calling convention for BIFs, make sure that all BIFs use the macros. Also, eliminate all calls from one BIF to another, since that also breaks the calling convention abstraction.
2010-11-29Teach binary:matches not to return 'nomatch' on empty inputPatrik Nyblom