From 19713d214462b863def874385844521f00a2bac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Thu, 31 Mar 2011 08:19:21 +0200 Subject: Delay saving of the stack in exit_info when an exception occurs When an exception occurs, the entire stack will be converted to the external term format and kept in the exit_info variable in the process dictionary. But the exit_info variable will only be needed if the exception causes the process to terminate (not if it is caught). Delay the conversion of the stack to external format. That can save significant amounts of time (e.g. in bs_construct:mem_leak/1). --- lib/debugger/src/dbg_ieval.erl | 11 +++++++---- lib/debugger/src/dbg_istk.erl | 7 ++++--- 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/debugger/src/dbg_ieval.erl b/lib/debugger/src/dbg_ieval.erl index a9a5e171f7..9b6919074f 100644 --- a/lib/debugger/src/dbg_ieval.erl +++ b/lib/debugger/src/dbg_ieval.erl @@ -140,12 +140,12 @@ check_exit_msg({'DOWN',_,_,_,Reason}, Bs, undefined when Le =:= 1 -> % died outside interpreted code {}; undefined when Le > 1 -> - StackExternal = dbg_istk:to_external(), + StackExternal = (dbg_istk:delayed_to_external())(), {{Mod, Li}, Bs, StackExternal}; %% Debugged has terminated due to an exception - ExitInfo0 -> - ExitInfo0 + ExitInfo0 when is_function(ExitInfo0, 0) -> + ExitInfo0() end, dbg_iserver:cast(get(int), {set_exit_info,self(),ExitInfo}), @@ -180,7 +180,10 @@ exception(Class, Reason, Bs, Ieval, true) -> Bs, Ieval). do_exception(Class, Reason, Stacktrace, Bs, #ieval{module=M, line=Line}) -> - ExitInfo = {{M,Line}, Bs, dbg_istk:to_external()}, + StackFun = dbg_istk:delayed_to_external(), + ExitInfo = fun() -> + {{M,Line},Bs,StackFun()} + end, put(exit_info, ExitInfo), put(stacktrace, Stacktrace), erlang:Class(Reason). diff --git a/lib/debugger/src/dbg_istk.erl b/lib/debugger/src/dbg_istk.erl index 34070aa8f2..a0d3069d50 100644 --- a/lib/debugger/src/dbg_istk.erl +++ b/lib/debugger/src/dbg_istk.erl @@ -17,7 +17,7 @@ %% %CopyrightEnd% %% -module(dbg_istk). --export([init/0,to_external/0,from_external/1, +-export([init/0,delayed_to_external/0,from_external/1, push/2,pop/0,pop/1,stack_level/0, delayed_stacktrace/0,delayed_stacktrace/2, bindings/1,stack_frame/2,backtrace/2, @@ -37,8 +37,9 @@ init() -> init([]). -to_external() -> - {stack,term_to_binary(get(?STACK))}. +delayed_to_external() -> + Stack = get(?STACK), + fun() -> {stack,term_to_binary(Stack)} end. from_external({stack,Stk}) -> put(?STACK, binary_to_term(Stk)). -- cgit v1.2.3