summaryrefslogtreecommitdiff
path: root/erts/emulator/beam
diff options
context:
space:
mode:
authorBjörn Gustavsson <bjorn@erlang.org>2023-01-18 16:18:25 +0100
committerBjörn Gustavsson <bjorn@erlang.org>2023-01-19 06:27:42 +0100
commit03323f3959006332d6ba8d82dc4f1ad41e9e8725 (patch)
tree3ed607fe58d2f76942ef17bd577b34c2e370b7bf /erts/emulator/beam
parent6fe1996af121986b6f402d1c0282387c3d8a4b8f (diff)
downloaderlang-03323f3959006332d6ba8d82dc4f1ad41e9e8725.tar.gz
non-JIT BEAM: Avoid redundant GC in binary syntax
In the binary syntax, avoid doing a garbage collection when matching out an integer if the match is known to fail because the binary is too short. This test is already done in the JIT.
Diffstat (limited to 'erts/emulator/beam')
-rw-r--r--erts/emulator/beam/emu/bs_instrs.tab11
1 files changed, 10 insertions, 1 deletions
diff --git a/erts/emulator/beam/emu/bs_instrs.tab b/erts/emulator/beam/emu/bs_instrs.tab
index c8bba1e70a..846e4b6f2c 100644
--- a/erts/emulator/beam/emu/bs_instrs.tab
+++ b/erts/emulator/beam/emu/bs_instrs.tab
@@ -1404,10 +1404,19 @@ bs_get_integer.head() {
bs_get_integer.fetch(Ctx, Size, Live) {
Uint wordsneeded;
+ ErlBinMatchBuffer* mb;
Ms = $Ctx;
Sz = $Size;
wordsneeded = 1+WSIZE(NBYTES(Sz));
- $GC_TEST_PRESERVE(wordsneeded, $Live, Ms);
+
+ /* Check bits size before potential GC. We do not want a GC
+ * and then realize we don't need the allocated space (if the
+ * op fails).
+ */
+ mb = ms_matchbuffer(Ms);
+ if (mb->size - mb->offset >= Sz) {
+ $GC_TEST_PRESERVE(wordsneeded, $Live, Ms);
+ }
}
bs_get_integer.fetch_small(Ctx, Size) {