Skip to content
  • 2 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
Commits on May 13, 2012
@nominolo Allocate special closures on the static heap.
Special closures like the UPDATE and STOP closures so far were static
objects which confused the garbage collector.  Instead of adding
special cases to the GC, these closures are now allocated on the
static heap during initialisation.
a45829f
@nominolo Coloured and more complete loader debug output. 3fe512f
Showing with 57 additions and 31 deletions.
  1. +2 −2 includes/MiscClosures.h
  2. +3 −3 rts/InterpThreaded.c
  3. +7 −2 rts/Loader.c
  4. +40 −18 rts/MiscClosures.c
  5. +2 −2 rts/Record.c
  6. +1 −2 rts/StorageManager.c
  7. +2 −2 rts/Thread.c
View
4 includes/MiscClosures.h
@@ -10,8 +10,8 @@ typedef struct _IntClosure {
} IntClosure;
extern ConInfoTable stg_IND_info;
-extern Closure stg_STOP_closure;
-extern Closure stg_UPD_closure;
+extern const Closure *stg_STOP_closure_addr;
+extern const Closure *stg_UPD_closure_addr;
extern BCIns* stg_UPD_return_pc;
extern IntClosure the_smallInt[256];
extern ConInfoTable stg_Izh_con_info;
View
6 rts/InterpThreaded.c
@@ -773,7 +773,7 @@ engine(Capability *cap)
// push update frame and enter thunk
top[0] = (Word)base;
top[1] = (Word)return_pc;
- top[2] = (Word)&stg_UPD_closure;
+ top[2] = (Word)stg_UPD_closure_addr;
top[3] = (Word)tnode; // reg0
top[4] = 1234; // reg1
top[5] = (Word)&top[3];
@@ -951,7 +951,7 @@ engine(Capability *cap)
base[-1] = (Word)ap_closure;
top[0] = (Word)base;
top[1] = (Word)ap_return_pc;
- top[2] = (Word)&stg_UPD_closure;
+ top[2] = (Word)stg_UPD_closure_addr;
top[3] = (Word)fnode;
top[4] = 0;
top[5] = (Word)&top[3];
@@ -1222,7 +1222,7 @@ engine(Capability *cap)
// Put UPDATE and EVAL frames on top
top[3 + nargs + 0] = (Word)&top[3];
top[3 + nargs + 1] = (Word)ap_return_pc;
- top[3 + nargs + 2] = (Word)&stg_UPD_closure;
+ top[3 + nargs + 2] = (Word)stg_UPD_closure_addr;
top[3 + nargs + 3] = (Word)fnode; // reg0
top[3 + nargs + 4] = 0; // reg1
top[3 + nargs + 5] = (Word)&top[3 + nargs + 3];
View
9 rts/Loader.c
@@ -524,7 +524,8 @@ loadId(FILE *f, const StringTabEntry *strings, const char* sep)
}
}
*p = '\0';
- LD_DBG_PR(3, "loadId: %lx, %s, %p\n", ftell(f), ident, ident);
+ LD_DBG_PR(3, "loadId: %lx, %s, " COLOURED(COL_BLUE, "%p") "\n",
+ ftell(f), ident, ident);
return ident;
}
@@ -620,6 +621,9 @@ loadInfoTable(const char *filename,
HashTable_update(itbls, itbl_name, new_itbl);
xfree(itbl_name);
} else {
+ LD_DBG_PR(2, "loadInfoTable: %s " COLOURED(COL_YELLOW, "%p") "\n",
+ itbl_name, new_itbl);
+
HashTable_insert(itbls, itbl_name, new_itbl);
}
@@ -751,7 +755,8 @@ loadClosure(const char *filename,
xfree(clos_name);
} else {
-
+ LD_DBG_PR(2, "loadClosure: %s " COLOURED(COL_GREEN, "%p") "\n",
+ clos_name, cl);
HashTable_insert(closures, clos_name, cl);
}
View
58 rts/MiscClosures.c
@@ -33,23 +33,8 @@ this should be changed to tell the scheduler to kill the thread.
*/
-static BCIns stop_code_insts[] =
- { BCINS_AD(BC_EVAL, 0, 0), // eval r0 ; no lives
- 8,
- BCINS_AD(BC__MAX, 0, 0), // stop
- 0x00010001 // r0 is live and a pointer
- };
+const Closure *stg_STOP_closure_addr = NULL;
-/* LcInfoTable stg_STOP_info = */
-/* DEF_INFO(FUN, 0, 0, stop_code_insts, 1, 1, "stg_STOP"); */
-
-ThunkInfoTable stg_STOP_info =
- { .i = DEF_INFO_TABLE(FUN, 0, 0, 0),
- .name = "stg_STOP",
- .code = DEF_CODE(stop_code_insts, 1, 1)
- };
-
-Closure stg_STOP_closure = DEF_CLOSURE(&stg_STOP_info, {});
/*
@@ -61,7 +46,8 @@ Update frames
// Both variables are initialized fully by initMiscClosures().
BCIns *stg_UPD_return_pc = NULL;
-Closure stg_UPD_closure = DEF_CLOSURE(NULL, {});
+
+const Closure *stg_UPD_closure_addr = NULL;
/*
@@ -298,7 +284,42 @@ initUpdateClosure(void)
bitmasks += encodeBitmask(bitmasks, 1); // reg 0 is live
stg_UPD_return_pc = &code[2];
- setInfo(&stg_UPD_closure, (InfoTable*)info);
+
+ Closure *stg_UPD_closure = allocStaticClosure(wordsof(Closure));
+ setInfo(stg_UPD_closure, (InfoTable*)info);
+ stg_UPD_closure_addr = stg_UPD_closure;
+}
+
+void initStopClosure()
+{
+ FuncInfoTable *info = allocInfoTable(wordsof(ThunkInfoTable));
+ info->i.type = FUN;
+ info->i.size = 1;
+ info->i.tagOrBitmap = 0;
+ info->i.layout.bitmap = 0;
+ info->name = "stg_STOP";
+ info->code.framesize = 2;
+ info->code.arity = 1;
+ info->code.sizecode = 3;
+ info->code.sizelits = 0;
+ info->code.sizebitmaps = 2;
+ info->code.lits = NULL;
+ info->code.littypes = NULL;
+ info->code.code = xmalloc(info->code.sizecode * sizeof(BCIns) +
+ info->code.sizebitmaps * sizeof(u2));
+ BCIns *code = info->code.code;
+ u2 *bitmasks = cast(u2*, code + info->code.sizecode);
+
+ code[0] = BCINS_AD(BC_EVAL, 0, 0), // eval r0 ; is r0 live here?
+ code[1] = cast(BCIns, byte_offset(&code[1], bitmasks));
+ code[2] = BCINS_AD(BC__MAX, 0, 0); // stop execution
+
+ bitmasks += encodeBitmask(bitmasks, 1); // reg 0 is a pointer
+ bitmasks += encodeBitmask(bitmasks, 1); // reg 0 is live
+
+ Closure *stg_STOP_closure = allocStaticClosure(wordsof(Closure));
+ setInfo(stg_STOP_closure, (InfoTable*)info);
+ stg_STOP_closure_addr = stg_STOP_closure;
}
void
@@ -307,6 +328,7 @@ initMiscClosures(void)
int i;
initUpdateClosure();
+ initStopClosure();
for (i = 0; i < sizeof(apk_info) / sizeof(APKInfo); i++) {
apk_info[i].clos = NULL;
View
4 rts/Record.c
@@ -488,11 +488,11 @@ recordBuildEvalFrame(JitState *J, TRef node, ThunkInfoTable *info,
}
const u2 *liveouts = getLivenessMask(return_pc);
- fprintf(stderr, "LIVES: %p %x\n", return_pc, (int)liveouts);
+ fprintf(stderr, "LIVES: %p %lx\n", return_pc, (long)liveouts);
setSlot(J, t + 0, emitKBaseOffset(J, b));
setSlot(J, t + 1, emitKWord(J, (Word)return_pc, LIT_PC));
- setSlot(J, t + 2, emitKWord(J, (Word)&stg_UPD_closure, LIT_CLOSURE));
+ setSlot(J, t + 2, emitKWord(J, (Word)stg_UPD_closure_addr, LIT_CLOSURE));
setSlot(J, t + 3, node); // the thing to update
setSlot(J, t + 4, 0); // undefined
setSlot(J, t + 5, emitKBaseOffset(J, b + t + 3));
View
3 rts/StorageManager.c
@@ -385,8 +385,7 @@ int looksLikeClosure(void *p)
return (isManagedMemory(p) &&
(PTR_TO_BLOCK_DESCR(p)->flags & BF_CONTENTS_MASK) ==
BF_CLOSURES)
- || looksLikeStaticClosure(p)
- || p == &stg_UPD_closure;
+ || looksLikeStaticClosure(p);
}
int looksLikeStaticClosure(void *p)
View
4 rts/Thread.c
@@ -27,11 +27,11 @@ createThread(Capability *cap, u4 size)
T->stack_size = stack_size;
T->stack[0] = (Word)NULL; // previous base
T->stack[1] = (Word)NULL; // previous PC
- T->stack[2] = (Word)&stg_STOP_closure;
+ T->stack[2] = (Word)stg_STOP_closure_addr;
T->stack[3] = (Word)NULL;
T->base = &T->stack[3];
T->top = &T->stack[4];
- T->pc = getFInfo(&stg_STOP_closure)->code.code;
+ T->pc = getFInfo(stg_STOP_closure_addr)->code.code;
return T;
}

No commit comments for this range

Something went wrong with that request. Please try again.