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/hipe/hipe_native_bif.c | |
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/hipe/hipe_native_bif.c')
-rw-r--r-- | erts/emulator/hipe/hipe_native_bif.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/erts/emulator/hipe/hipe_native_bif.c b/erts/emulator/hipe/hipe_native_bif.c index ac1480d2ed..498b43ac6b 100644 --- a/erts/emulator/hipe/hipe_native_bif.c +++ b/erts/emulator/hipe/hipe_native_bif.c @@ -314,6 +314,32 @@ BIF_RETTYPE nbif_impl_hipe_rethrow(NBIF_ALIST_2) } } +/* Called via standard_bif_interface_3 */ +BIF_RETTYPE nbif_impl_hipe_raw_raise(NBIF_ALIST_3) +{ + Process *c_p = BIF_P; + Eterm class = BIF_ARG_1; + Eterm value = BIF_ARG_2; + Eterm stacktrace = BIF_ARG_3; + Eterm reason; + + if (class == am_error) { + c_p->fvalue = value; + reason = EXC_ERROR; + } else if (class == am_exit) { + c_p->fvalue = value; + reason = EXC_EXIT; + } else if (class == am_throw) { + c_p->fvalue = value; + reason = EXC_THROWN; + } else { + return am_badarg; + } + reason &= ~EXF_SAVETRACE; + c_p->ftrace = stacktrace; + BIF_ERROR(c_p, reason); +} + /* * Support for compiled binary syntax operations. */ |