aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/beam/module.c
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2016-10-17 11:53:18 +0200
committerSverker Eriksson <[email protected]>2016-10-17 11:53:18 +0200
commit32729cab75325de58bf127e6e8836348071b8682 (patch)
tree6084efc6883c937d9321ec6373f8ba7ac51ced3a /erts/emulator/beam/module.c
parentadd49d36f93c03fc2edbf17663a4e7ddd982a5f0 (diff)
parenta28149b2500a4db9b3c56b168dcd18effca87a3a (diff)
downloadotp-32729cab75325de58bf127e6e8836348071b8682.tar.gz
otp-32729cab75325de58bf127e6e8836348071b8682.tar.bz2
otp-32729cab75325de58bf127e6e8836348071b8682.zip
Merge branch 'sverker/hipe-code-loadnpurge/OTP-13968'
* sverker/hipe-code-loadnpurge: (35 commits) erts: Cleanup dead code kernel,hipe: Fix dialyzer warnings erts: Replace unsafe Module.first_hipe_ref erts: Disable DBG_TRACE_MFA for debug build kernel: Fix code_SUITE:upgrade for non-hipe erts: Cleanup hipe trampoline code erts: Remove dead alloc stats in hipe_amd64.c erts: Remove code_SUITE:make_stub and make_stub_many_funs erts: Let code:make_stub_module raise 'notsup' erts: Fix bug in stack walk on risc erts: Fix old leak for ppc hipe code erts: Fix old leak for arm hipe code erts: Fix old leak of sparc hipe code erts: Fix old leak of hipe code on x86 32-bit erts: Enable exec_alloc for all hipe architectures erts: Remove debug printout for hipe loader state erts: Free hipe_refs and hipe_sdesc of a failed load erts: Refactor out hipe_purge_refs/sdesc erts: Refactor hipe_loader_state_dtor into a true destructor hipe: TRY fix llvm external calls to own module ...
Diffstat (limited to 'erts/emulator/beam/module.c')
-rw-r--r--erts/emulator/beam/module.c61
1 files changed, 37 insertions, 24 deletions
diff --git a/erts/emulator/beam/module.c b/erts/emulator/beam/module.c
index 4f36377450..705dd1d43f 100644
--- a/erts/emulator/beam/module.c
+++ b/erts/emulator/beam/module.c
@@ -26,6 +26,7 @@
#include "erl_vm.h"
#include "global.h"
#include "module.h"
+#include "beam_catches.h"
#ifdef DEBUG
# define IF_DEBUG(x) x
@@ -67,6 +68,18 @@ static int module_cmp(Module* tmpl, Module* obj)
return tmpl->module != obj->module;
}
+void erts_module_instance_init(struct erl_module_instance* modi)
+{
+ modi->code_hdr = 0;
+ modi->code_length = 0;
+ modi->catches = BEAM_CATCHES_NIL;
+ modi->nif = NULL;
+ modi->num_breakpoints = 0;
+ modi->num_traced_exports = 0;
+#ifdef HIPE
+ modi->hipe_code = NULL;
+#endif
+}
static Module* module_alloc(Module* tmpl)
{
@@ -74,18 +87,11 @@ static Module* module_alloc(Module* tmpl)
erts_smp_atomic_add_nob(&tot_module_bytes, sizeof(Module));
obj->module = tmpl->module;
- obj->curr.code_hdr = 0;
- obj->old.code_hdr = 0;
- obj->curr.code_length = 0;
- obj->old.code_length = 0;
obj->slot.index = -1;
- obj->curr.nif = NULL;
- obj->old.nif = NULL;
- obj->curr.num_breakpoints = 0;
- obj->old.num_breakpoints = 0;
- obj->curr.num_traced_exports = 0;
- obj->old.num_traced_exports = 0;
+ erts_module_instance_init(&obj->curr);
+ erts_module_instance_init(&obj->old);
obj->on_load = 0;
+ DBG_TRACE_MFA(make_atom(obj->module), 0, 0, "module_alloc");
return obj;
}
@@ -119,6 +125,7 @@ void init_module_table(void)
erts_smp_atomic_init_nob(&tot_module_bytes, 0);
}
+
Module*
erts_get_module(Eterm mod, ErtsCodeIndex code_ix)
{
@@ -139,19 +146,14 @@ erts_get_module(Eterm mod, ErtsCodeIndex code_ix)
}
}
-Module*
-erts_put_module(Eterm mod)
+
+static Module* put_module(Eterm mod, IndexTable* mod_tab)
{
Module e;
- IndexTable* mod_tab;
int oldsz, newsz;
Module* res;
ASSERT(is_atom(mod));
- ERTS_SMP_LC_ASSERT(erts_initialized == 0
- || erts_has_code_write_permission());
-
- mod_tab = &module_tables[erts_staging_code_ix()];
e.module = atom_val(mod);
oldsz = index_table_sz(mod_tab);
res = (Module*) index_put_entry(mod_tab, (void*) &e);
@@ -160,6 +162,15 @@ erts_put_module(Eterm mod)
return res;
}
+Module*
+erts_put_module(Eterm mod)
+{
+ ERTS_SMP_LC_ASSERT(erts_initialized == 0
+ || erts_has_code_write_permission());
+
+ return put_module(mod, &module_tables[erts_staging_code_ix()]);
+}
+
Module *module_code(int i, ErtsCodeIndex code_ix)
{
return (Module*) erts_index_lookup(&module_tables[code_ix], i);
@@ -181,6 +192,13 @@ static ErtsCodeIndex dbg_load_code_ix = 0;
static int entries_at_start_staging = 0;
+static ERTS_INLINE void copy_module(Module* dst_mod, Module* src_mod)
+{
+ dst_mod->curr = src_mod->curr;
+ dst_mod->old = src_mod->old;
+ dst_mod->on_load = src_mod->on_load;
+}
+
void module_start_staging(void)
{
IndexTable* src = &module_tables[erts_active_code_ix()];
@@ -199,10 +217,7 @@ void module_start_staging(void)
src_mod = (Module*) erts_index_lookup(src, i);
dst_mod = (Module*) erts_index_lookup(dst, i);
ASSERT(src_mod->module == dst_mod->module);
-
- dst_mod->curr = src_mod->curr;
- dst_mod->old = src_mod->old;
- dst_mod->on_load = src_mod->on_load;
+ copy_module(dst_mod, src_mod);
}
/*
@@ -214,9 +229,7 @@ void module_start_staging(void)
dst_mod = (Module*) index_put_entry(dst, src_mod);
ASSERT(dst_mod != src_mod);
- dst_mod->curr = src_mod->curr;
- dst_mod->old = src_mod->old;
- dst_mod->on_load = src_mod->on_load;
+ copy_module(dst_mod, src_mod);
}
newsz = index_table_sz(dst);
erts_smp_atomic_add_nob(&tot_module_bytes, (newsz - oldsz));