Skip to content

Commit

Permalink
check_process_code/2: Quickly return 'false' if there is no old code
Browse files Browse the repository at this point in the history
There is no need to suspend the process if the module has no old
code. Measurements show that this change will make
erlang:check_process_code/2 in an SMP emulator about four times
faster if the module has no old code.
  • Loading branch information
bjorng committed Aug 25, 2011
1 parent d48eaa0 commit 1c40ae2
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions erts/emulator/beam/beam_bif_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ check_process_code_2(BIF_ALIST_2)
Eterm res;
if (internal_pid_index(BIF_ARG_1) >= erts_max_processes)
goto error;
modp = erts_get_module(BIF_ARG_2);
if (modp == NULL) { /* Doesn't exist. */
return am_false;
} else if (modp->old_code == NULL) { /* No old code. */
return am_false;
}

#ifdef ERTS_SMP
rp = erts_pid2proc_suspend(BIF_P, ERTS_PROC_LOCK_MAIN,
BIF_ARG_1, ERTS_PROC_LOCK_MAIN);
Expand All @@ -188,7 +195,6 @@ check_process_code_2(BIF_ALIST_2)
ERTS_BIF_YIELD2(bif_export[BIF_check_process_code_2], BIF_P,
BIF_ARG_1, BIF_ARG_2);
}
modp = erts_get_module(BIF_ARG_2);
res = check_process_code(rp, modp);
#ifdef ERTS_SMP
if (BIF_P != rp) {
Expand Down Expand Up @@ -412,11 +418,6 @@ check_process_code(Process* rp, Module* modp)
#endif

#define INSIDE(a) (start <= (a) && (a) < end)
if (modp == NULL) { /* Doesn't exist. */
return am_false;
} else if (modp->old_code == NULL) { /* No old code. */
return am_false;
}

/*
* Pick up limits for the module.
Expand Down

0 comments on commit 1c40ae2

Please sign in to comment.