diff options
author | Björn Gustavsson <[email protected]> | 2017-11-28 07:28:25 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2018-01-22 14:23:52 +0100 |
commit | 9b0122b65bdcafbae2a3cfd3299903da0948acab (patch) | |
tree | 59405671dad4d8240978faaf4ea8e3dcdff289b5 /erts/emulator/beam/instrs.tab | |
parent | b7ff9c0d76372f16d14ecaac04c6fbbbadaf9435 (diff) | |
download | otp-9b0122b65bdcafbae2a3cfd3299903da0948acab.tar.gz otp-9b0122b65bdcafbae2a3cfd3299903da0948acab.tar.bz2 otp-9b0122b65bdcafbae2a3cfd3299903da0948acab.zip |
Don't build a stacktrace if it's only passed to erlang:raise/3
Consider the following function:
function({function,Name,Arity,CLabel,Is0}, Lc0) ->
try
%% Optimize the code for the function.
catch
Class:Error:Stack ->
io:format("Function: ~w/~w\n", [Name,Arity]),
erlang:raise(Class, Error, Stack)
end.
The stacktrace is retrieved, but it is only used in the call
to erlang:raise/3. There is no need to build a stacktrace
in this function. We can avoid the building if we introduce
an instruction called raw_raise/3 that works exactly like
the erlang:raise/3 BIF except that its third argument must
be a raw stacktrace.
Diffstat (limited to 'erts/emulator/beam/instrs.tab')
-rw-r--r-- | erts/emulator/beam/instrs.tab | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/erts/emulator/beam/instrs.tab b/erts/emulator/beam/instrs.tab index b92152238e..f19027b1ec 100644 --- a/erts/emulator/beam/instrs.tab +++ b/erts/emulator/beam/instrs.tab @@ -936,3 +936,28 @@ build_stacktrace() { x(0) = build_stacktrace(c_p, x(0)); SWAPIN; } + +raw_raise() { + Eterm class = x(0); + Eterm value = x(1); + Eterm stacktrace = x(2); + + if (class == am_error) { + c_p->freason = EXC_ERROR & ~EXF_SAVETRACE; + c_p->fvalue = value; + c_p->ftrace = stacktrace; + goto find_func_info; + } else if (class == am_exit) { + c_p->freason = EXC_EXIT & ~EXF_SAVETRACE; + c_p->fvalue = value; + c_p->ftrace = stacktrace; + goto find_func_info; + } else if (class == am_throw) { + c_p->freason = EXC_THROWN & ~EXF_SAVETRACE; + c_p->fvalue = value; + c_p->ftrace = stacktrace; + goto find_func_info; + } else { + x(0) = am_badarg; + } +} |