aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/beam
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2012-02-07 19:43:31 +0100
committerSverker Eriksson <[email protected]>2012-02-21 12:23:06 +0100
commitfa5213fd7590c6a9ade13af1375c363b958927f1 (patch)
treed1cb53979ff22779fbd83eccc22f4e5fb33d3ac4 /erts/emulator/beam
parentc2f62a3813c5c2bd2bb691df816d5fc2fb17206a (diff)
downloadotp-fa5213fd7590c6a9ade13af1375c363b958927f1.tar.gz
otp-fa5213fd7590c6a9ade13af1375c363b958927f1.tar.bz2
otp-fa5213fd7590c6a9ade13af1375c363b958927f1.zip
erts: Cleanup non-blocking load
Diffstat (limited to 'erts/emulator/beam')
-rw-r--r--erts/emulator/beam/beam_bif_load.c33
-rw-r--r--erts/emulator/beam/beam_catches.c34
-rw-r--r--erts/emulator/beam/export.c12
-rw-r--r--erts/emulator/beam/export.h18
4 files changed, 39 insertions, 58 deletions
diff --git a/erts/emulator/beam/beam_bif_load.c b/erts/emulator/beam/beam_bif_load.c
index d241bec441..995b16c376 100644
--- a/erts/emulator/beam/beam_bif_load.c
+++ b/erts/emulator/beam/beam_bif_load.c
@@ -139,18 +139,8 @@ BIF_RETTYPE purge_module_1(BIF_ALIST_1)
BIF_ERROR(BIF_P, BADARG);
}
- /*SVERK
- erts_smp_proc_unlock(BIF_P, ERTS_PROC_LOCK_MAIN);
- erts_smp_thr_progress_block();
-
- erts_export_consolidate(erts_active_code_ix());*/
-
purge_res = purge_module(BIF_P, atom_val(BIF_ARG_1));
- /*SVERK
- erts_smp_thr_progress_unblock();
- erts_smp_proc_lock(BIF_P, ERTS_PROC_LOCK_MAIN);*/
-
if (purge_res < 0) {
BIF_ERROR(BIF_P, BADARG);
}
@@ -306,10 +296,6 @@ BIF_RETTYPE delete_module_1(BIF_ALIST_1)
if (is_not_atom(BIF_ARG_1))
goto badarg;
- /*SVERK
- erts_smp_proc_unlock(BIF_P, ERTS_PROC_LOCK_MAIN);
- erts_smp_thr_progress_block();*/
-
erts_lock_code_ix();
do {
erts_start_staging_code_ix();
@@ -361,10 +347,6 @@ BIF_RETTYPE delete_module_1(BIF_ALIST_1)
erts_unlock_code_ix();
}
- /*SVERK
- erts_smp_thr_progress_unblock();
- erts_smp_proc_lock(BIF_P, ERTS_PROC_LOCK_MAIN);*/
-
if (res == am_badarg) {
badarg:
BIF_ERROR(BIF_P, BADARG);
@@ -429,17 +411,10 @@ BIF_RETTYPE loaded_0(BIF_ALIST_0)
BIF_RETTYPE call_on_load_function_1(BIF_ALIST_1)
{
- ErtsCodeIndex code_ix = erts_active_code_ix(); /*SVERK ?? on_load ?? */
- Module* modp = erts_get_module(BIF_ARG_1, code_ix);
- Eterm on_load = 0;
+ Module* modp = erts_get_module(BIF_ARG_1, erts_active_code_ix());
- if (modp) {
- if (modp->curr.code) {
- on_load = modp->curr.code[MI_ON_LOAD_FUNCTION_PTR];
- }
- }
- if (on_load) {
- BIF_TRAP_CODE_PTR_0(BIF_P, on_load);
+ if (modp && modp->curr.code) {
+ BIF_TRAP_CODE_PTR_0(BIF_P, modp->curr.code[MI_ON_LOAD_FUNCTION_PTR]);
}
else {
BIF_ERROR(BIF_P, BADARG);
@@ -793,7 +768,7 @@ retry:
*/
if (modp->old.nif != NULL) {
if (!is_blocking) {
- /*SVERK Do unload nif without blocking */
+ /* ToDo: Do unload nif without blocking */
erts_rwunlock_old_code(code_ix);
erts_unlock_code_ix();
erts_smp_proc_unlock(c_p, ERTS_PROC_LOCK_MAIN);
diff --git a/erts/emulator/beam/beam_catches.c b/erts/emulator/beam/beam_catches.c
index 548c10fa94..92f7ffe5a2 100644
--- a/erts/emulator/beam/beam_catches.c
+++ b/erts/emulator/beam/beam_catches.c
@@ -37,16 +37,21 @@ typedef struct {
# define IF_DEBUG(x)
#endif
-struct bc_code_ix { /*SVERK A better name maybe... */
+struct bc_pool {
int free_list;
unsigned high_mark;
unsigned tabsize;
beam_catch_t *beam_catches;
+ /*
+ * Note that the 'beam_catches' area is shared by pools. Used slots
+ * are readonly as long as the module is not purgable. The free-list is
+ * protected by the code_ix lock.
+ */
- IF_DEBUG(int is_prepared;)
+ IF_DEBUG(int is_staging;)
};
-static struct bc_code_ix bccix[ERTS_NUM_CODE_IX];
+static struct bc_pool bccix[ERTS_NUM_CODE_IX];
void beam_catches_init(void)
{
@@ -57,12 +62,12 @@ void beam_catches_init(void)
bccix[0].high_mark = 0;
bccix[0].beam_catches = erts_alloc(ERTS_ALC_T_CODE,
sizeof(beam_catch_t)*DEFAULT_TABSIZE);
- IF_DEBUG(bccix[0].is_prepared = 0);
+ IF_DEBUG(bccix[0].is_staging = 0);
for (i=1; i<ERTS_NUM_CODE_IX; i++) {
bccix[i] = bccix[i-1];
}
/* For initial load: */
- IF_DEBUG(bccix[erts_staging_code_ix()].is_prepared = 1);
+ IF_DEBUG(bccix[erts_staging_code_ix()].is_staging = 1);
}
@@ -84,30 +89,27 @@ void beam_catches_start_staging(void)
ErtsCodeIndex src = erts_active_code_ix();
beam_catch_t* prev_vec = bccix[dst].beam_catches;
- ASSERT(!bccix[src].is_prepared && !bccix[dst].is_prepared);
+ ASSERT(!bccix[src].is_staging && !bccix[dst].is_staging);
bccix[dst] = bccix[src];
gc_old_vec(prev_vec);
- IF_DEBUG(bccix[dst].is_prepared = 1);
+ IF_DEBUG(bccix[dst].is_staging = 1);
}
void beam_catches_end_staging(int commit)
{
- IF_DEBUG(bccix[erts_staging_code_ix()].is_prepared = 0);
+ IF_DEBUG(bccix[erts_staging_code_ix()].is_staging = 0);
}
unsigned beam_catches_cons(BeamInstr *cp, unsigned cdr)
{
int i;
- struct bc_code_ix* p = &bccix[erts_staging_code_ix()];
+ struct bc_pool* p = &bccix[erts_staging_code_ix()];
- ASSERT(p->is_prepared);
+ ASSERT(p->is_staging);
/*
* Allocate from free_list while it is non-empty.
* If free_list is empty, allocate at high_mark.
- *
- * This avoids the need to initialise the free list in
- * beam_catches_init(), which would cost O(TABSIZ) time.
*/
if (p->free_list >= 0) {
i = p->free_list;
@@ -137,7 +139,7 @@ unsigned beam_catches_cons(BeamInstr *cp, unsigned cdr)
BeamInstr *beam_catches_car(unsigned i)
{
- struct bc_code_ix* p = &bccix[erts_active_code_ix()];
+ struct bc_pool* p = &bccix[erts_active_code_ix()];
if (i >= p->tabsize ) {
erl_exit(1, "beam_catches_delmod: index %#x is out of range\r\n", i);
@@ -148,10 +150,10 @@ BeamInstr *beam_catches_car(unsigned i)
void beam_catches_delmod(unsigned head, BeamInstr *code, unsigned code_bytes,
ErtsCodeIndex code_ix)
{
- struct bc_code_ix* p = &bccix[code_ix];
+ struct bc_pool* p = &bccix[code_ix];
unsigned i, cdr;
- ASSERT((code_ix == erts_active_code_ix()) != bccix[erts_staging_code_ix()].is_prepared);
+ ASSERT((code_ix == erts_active_code_ix()) != bccix[erts_staging_code_ix()].is_staging);
for(i = head; i != (unsigned)-1;) {
if (i >= p->tabsize) {
erl_exit(1, "beam_catches_delmod: index %#x is out of range\r\n", i);
diff --git a/erts/emulator/beam/export.c b/erts/emulator/beam/export.c
index 9656a67a4a..78a0b7d269 100644
--- a/erts/emulator/beam/export.c
+++ b/erts/emulator/beam/export.c
@@ -206,16 +206,11 @@ init_export_table(void)
* called through such an export entry.
* 3) This function is suitable for the implementation of erlang:apply/3.
*/
+extern Export* /* inline-helper */
+erts_find_export_entry(Eterm m, Eterm f, unsigned int a,ErtsCodeIndex code_ix);
Export*
-erts_active_export_entry(Eterm m, Eterm f, unsigned int a)
-{
- return erts_find_export_entry(m, f, a, erts_active_code_ix());
-}
-
-Export*
-erts_find_export_entry(Eterm m, Eterm f, unsigned int a,
- ErtsCodeIndex code_ix)
+erts_find_export_entry(Eterm m, Eterm f, unsigned int a, ErtsCodeIndex code_ix)
{
HashValue hval = EXPORT_HASH((BeamInstr) m, (BeamInstr) f, (BeamInstr) a);
int ix;
@@ -401,7 +396,6 @@ void export_start_staging(void)
/*
* Insert all entries in src into dst table
*/
- /*SVERK Room for optimization to only insert the new ones */
for (i = 0; i < src->entries; i++) {
src_entry = (struct export_entry*) erts_index_lookup(src, i);
src_entry->ep->addressv[dst_ix] = src_entry->ep->addressv[src_ix];
diff --git a/erts/emulator/beam/export.h b/erts/emulator/beam/export.h
index ef9c1d2680..45c98d6bbb 100644
--- a/erts/emulator/beam/export.h
+++ b/erts/emulator/beam/export.h
@@ -61,11 +61,9 @@ typedef struct export
void init_export_table(void);
void export_info(int, void *);
-Export* erts_find_export_entry(Eterm m, Eterm f, unsigned int a, ErtsCodeIndex);
-Export* erts_active_export_entry(Eterm m, Eterm f, unsigned int a); /*SVERK inline? */
+ERTS_GLB_INLINE Export* erts_active_export_entry(Eterm m, Eterm f, unsigned a);
Export* erts_export_put(Eterm mod, Eterm func, unsigned int arity);
-
Export* erts_export_get_or_make_stub(Eterm, Eterm, unsigned);
Export *export_list(int,ErtsCodeIndex);
@@ -85,4 +83,16 @@ extern erts_smp_rwmtx_t export_staging_lock;
(((EntryPtr)->addressv[erts_active_code_ix()] == (EntryPtr)->code + 3) && \
((EntryPtr)->code[3] == (BeamInstr) em_apply_bif))
-#endif
+#if ERTS_GLB_INLINE_INCL_FUNC_DEF
+
+ERTS_GLB_INLINE Export*
+erts_active_export_entry(Eterm m, Eterm f, unsigned int a)
+{
+ extern Export* erts_find_export_entry(Eterm m, Eterm f, unsigned a, ErtsCodeIndex);
+ return erts_find_export_entry(m, f, a, erts_active_code_ix());
+}
+
+#endif /* ERTS_GLB_INLINE_INCL_FUNC_DEF */
+
+#endif /* __EXPORT_H__ */
+