PR_IMPLEMENT(void) PR_SetEndFinalizeHook(GCEndFinalizeHook *hook, void *arg) { LOCK_GC(); _pr_endFinalizeHook = hook; _pr_endFinalizeHookArg = arg; UNLOCK_GC(); }
PR_IMPLEMENT(void) PR_GetEndFinalizeHook(GCEndFinalizeHook **hook, void **arg) { LOCK_GC(); *hook = _pr_endFinalizeHook; *arg = _pr_endFinalizeHookArg; UNLOCK_GC(); }
PR_IMPLEMENT(void) PR_SetBeginFinalizeHook(GCBeginFinalizeHook *hook, void *arg) { LOCK_GC(); _pr_beginFinalizeHook = hook; _pr_beginFinalizeHookArg = arg; UNLOCK_GC(); }
PR_IMPLEMENT(void) PR_GetBeginGCHook(GCBeginGCHook **hook, void **arg) { LOCK_GC(); *hook = _pr_beginGCHook; *arg = _pr_beginGCHookArg; UNLOCK_GC(); }
PR_IMPLEMENT(int) PR_RegisterGCLockHook(GCLockHookFunc* f, void *arg) { GCLockHook *rf = 0; rf = (GCLockHook*) calloc(1, sizeof(GCLockHook)); if (rf) { rf->func = f; rf->arg = arg; LOCK_GC(); /* first dummy node */ if (! _pr_GCLockHook) { _pr_GCLockHook = (GCLockHook*) calloc(1, sizeof(GCLockHook)); _pr_GCLockHook->next = _pr_GCLockHook; _pr_GCLockHook->prev = _pr_GCLockHook; } rf->next = _pr_GCLockHook; rf->prev = _pr_GCLockHook->prev; _pr_GCLockHook->prev->next = rf; _pr_GCLockHook->prev = rf; UNLOCK_GC(); return 0; } return -1; }
PR_IMPLEMENT(PRInt32) PR_RegisterType(GCType *t) { CollectorType *ct, *ect; int rv = -1; LOCK_GC(); ct = &_pr_collectorTypes[0]; ect = &_pr_collectorTypes[FREE_MEMORY_TYPEIX]; for (; ct < ect; ct++) { if (ct->flags == 0) { ct->gctype = *t; ct->flags = _GC_TYPE_BUSY; if (0 != ct->gctype.finalize) { ct->flags |= _GC_TYPE_FINAL; } if (0 != ct->gctype.getWeakLinkOffset) { ct->flags |= _GC_TYPE_WEAK; } rv = ct - &_pr_collectorTypes[0]; break; } } UNLOCK_GC(); return rv; }
static PageInfo* find_page_and_cell(GCObjectPtr ptr, uint32_t *cell_idx) { Arena *arena = find_arena(ptr); if (EJS_LIKELY (arena != NULL)) { SANITY(verify_arena(arena)); int page_index = PTR_TO_ARENA_PAGE_INDEX(ptr); if (page_index < 0 || page_index > arena->num_pages) { return NULL; } PageInfo *page = arena->page_infos[page_index]; if (!IS_ALIGNED_TO(ptr, page->cell_size)) { return NULL; // can't possibly point to allocated cells. } if (cell_idx) { *cell_idx = PTR_TO_CELL(ptr, page); EJS_ASSERT(*cell_idx >= 0 && *cell_idx < CELLS_IN_PAGE(page)); } return page; } // check if it's in the LOS LOCK_GC(); for (LargeObjectInfo *lobj = los_list; lobj; lobj = lobj->next) { if (lobj->page_info.page_start == ptr) { if (cell_idx) { *cell_idx = 0; } UNLOCK_GC(); return &lobj->page_info; } } UNLOCK_GC(); return NULL; }
PR_IMPLEMENT(PRStatus) PR_RegisterRootFinder( GCRootFinder f, char *name, void *arg) { RootFinder *rf = PR_NEWZAP(RootFinder); if (rf) { rf->func = f; rf->name = name; rf->arg = arg; LOCK_GC(); rf->next = _pr_rootFinders; _pr_rootFinders = rf; UNLOCK_GC(); return PR_SUCCESS; } return PR_FAILURE; }