47 |
#include "jsdhash.h" |
#include "jsdhash.h" |
48 |
#include "jsbit.h" |
#include "jsbit.h" |
49 |
#include "jsutil.h" |
#include "jsutil.h" |
50 |
|
#include "jstask.h" |
51 |
|
|
52 |
JS_BEGIN_EXTERN_C |
JS_BEGIN_EXTERN_C |
53 |
|
|
111 |
#define GC_POKE(cx, oldval) ((cx)->runtime->gcPoke = JSVAL_IS_GCTHING(oldval)) |
#define GC_POKE(cx, oldval) ((cx)->runtime->gcPoke = JSVAL_IS_GCTHING(oldval)) |
112 |
#endif |
#endif |
113 |
|
|
|
/* |
|
|
* Write barrier macro monitoring property update from oldval to newval in |
|
|
* scope->object. |
|
|
* |
|
|
* Since oldval is used only for the branded scope case, and the oldval actual |
|
|
* argument expression is typically not used otherwise by callers, performance |
|
|
* benefits if oldval is *not* evaluated into a callsite temporary variable, |
|
|
* and instead passed to GC_WRITE_BARRIER for conditional evaluation (we rely |
|
|
* on modern compilers to do a good CSE job). Yay, C macros. |
|
|
*/ |
|
|
#define GC_WRITE_BARRIER(cx,scope,oldval,newval) \ |
|
|
JS_BEGIN_MACRO \ |
|
|
if (SCOPE_IS_BRANDED(scope) && \ |
|
|
(oldval) != (newval) && \ |
|
|
(VALUE_IS_FUNCTION(cx,oldval) || VALUE_IS_FUNCTION(cx,newval))) { \ |
|
|
js_MakeScopeShapeUnique(cx, scope); \ |
|
|
} \ |
|
|
GC_POKE(cx, oldval); \ |
|
|
JS_END_MACRO |
|
|
|
|
114 |
extern JSBool |
extern JSBool |
115 |
js_InitGC(JSRuntime *rt, uint32 maxbytes); |
js_InitGC(JSRuntime *rt, uint32 maxbytes); |
116 |
|
|
168 |
* can potentially trigger GC. This will ensure that GC tracing never sees junk |
* can potentially trigger GC. This will ensure that GC tracing never sees junk |
169 |
* values stored in the partially initialized thing. |
* values stored in the partially initialized thing. |
170 |
*/ |
*/ |
171 |
extern void * |
extern JSObject* |
172 |
js_NewGCThing(JSContext *cx, uintN flags, size_t nbytes); |
js_NewGCObject(JSContext *cx, uintN flags); |
173 |
|
|
174 |
|
extern JSString* |
175 |
|
js_NewGCString(JSContext *cx, uintN flags); |
176 |
|
|
177 |
|
extern JSFunction* |
178 |
|
js_NewGCFunction(JSContext *cx, uintN flags); |
179 |
|
|
180 |
|
extern JSXML* |
181 |
|
js_NewGCXML(JSContext *cx, uintN flags); |
182 |
|
|
183 |
/* |
/* |
184 |
* Allocate a new double jsval and store the result in *vp. vp must be a root. |
* Allocate a new double jsval and store the result in *vp. vp must be a root. |
221 |
#endif |
#endif |
222 |
|
|
223 |
/* |
/* |
224 |
* Trace jsval when JSVAL_IS_OBJECT(v) can be an arbitrary GC thing casted as |
* Trace jsval when JSVAL_IS_OBJECT(v) can be a GC thing pointer tagged as a |
225 |
* JSVAL_OBJECT and js_GetGCThingTraceKind has to be used to find the real |
* jsval. NB: punning an arbitrary JSString * as an untagged (object-tagged) |
226 |
* type behind v. |
* jsval no longer works due to static int and unit strings! |
227 |
*/ |
*/ |
228 |
extern void |
extern void |
229 |
js_CallValueTracerIfGCThing(JSTracer *trc, jsval v); |
js_CallValueTracerIfGCThing(JSTracer *trc, jsval v); |
284 |
extern void |
extern void |
285 |
js_GC(JSContext *cx, JSGCInvocationKind gckind); |
js_GC(JSContext *cx, JSGCInvocationKind gckind); |
286 |
|
|
|
/* Call this after succesful malloc of memory for GC-related things. */ |
|
|
extern void |
|
|
js_UpdateMallocCounter(JSContext *cx, size_t nbytes); |
|
|
|
|
287 |
typedef struct JSGCArenaInfo JSGCArenaInfo; |
typedef struct JSGCArenaInfo JSGCArenaInfo; |
288 |
typedef struct JSGCArenaList JSGCArenaList; |
typedef struct JSGCArenaList JSGCArenaList; |
289 |
typedef struct JSGCChunkInfo JSGCChunkInfo; |
typedef struct JSGCChunkInfo JSGCChunkInfo; |
290 |
|
|
291 |
struct JSGCArenaList { |
struct JSGCArenaList { |
292 |
JSGCArenaInfo *last; /* last allocated GC arena */ |
JSGCArenaInfo *last; /* last allocated GC arena */ |
293 |
uint16 lastCount; /* number of allocated things in the last |
uint32 lastCount; /* number of allocated things in the last |
294 |
arena */ |
arena */ |
295 |
uint16 thingSize; /* size of things to allocate on this list |
uint32 thingSize; /* size of things to allocate on this list |
296 |
*/ |
*/ |
297 |
JSGCThing *freeList; /* list of free GC things */ |
JSGCThing *freeList; /* list of free GC things */ |
298 |
}; |
}; |
310 |
things */ |
things */ |
311 |
} JSGCDoubleArenaList; |
} JSGCDoubleArenaList; |
312 |
|
|
|
typedef struct JSGCFreeListSet JSGCFreeListSet; |
|
|
|
|
|
struct JSGCFreeListSet { |
|
|
JSGCThing *array[GC_NUM_FREELISTS]; |
|
|
JSGCFreeListSet *link; |
|
|
}; |
|
|
|
|
|
extern const JSGCFreeListSet js_GCEmptyFreeListSet; |
|
|
|
|
|
extern void |
|
|
js_RevokeGCLocalFreeLists(JSContext *cx); |
|
|
|
|
313 |
extern void |
extern void |
314 |
js_DestroyScriptsToGC(JSContext *cx, JSThreadData *data); |
js_DestroyScriptsToGC(JSContext *cx, JSThreadData *data); |
315 |
|
|
326 |
|
|
327 |
#define JS_CLEAR_WEAK_ROOTS(wr) (memset((wr), 0, sizeof(JSWeakRoots))) |
#define JS_CLEAR_WEAK_ROOTS(wr) (memset((wr), 0, sizeof(JSWeakRoots))) |
328 |
|
|
329 |
|
#ifdef __cplusplus /* Allow inclusion from LiveConnect C files. */ |
330 |
|
#ifdef JS_THREADSAFE |
331 |
|
class JSFreePointerListTask : public JSBackgroundTask { |
332 |
|
void *head; |
333 |
|
public: |
334 |
|
JSFreePointerListTask() : head(NULL) {} |
335 |
|
|
336 |
|
void add(void* ptr) { |
337 |
|
*(void**)ptr = head; |
338 |
|
head = ptr; |
339 |
|
} |
340 |
|
|
341 |
|
void run() { |
342 |
|
void *ptr = head; |
343 |
|
while (ptr) { |
344 |
|
void *next = *(void **)ptr; |
345 |
|
js_free(ptr); |
346 |
|
ptr = next; |
347 |
|
} |
348 |
|
} |
349 |
|
}; |
350 |
|
#endif |
351 |
|
#endif /* __cplusplus */ |
352 |
|
|
353 |
/* |
/* |
354 |
* Increase runtime->gcBytes by sz bytes to account for an allocation outside |
* Free the chars held by str when it is finalized by the GC. When type is |
355 |
* the GC that will be freed only after the GC is run. The function may run |
* less then zero, it denotes an internal string. Otherwise it denotes the |
356 |
* the last ditch GC to ensure that gcBytes does not exceed gcMaxBytes. It will |
* type of the external string allocated with JS_NewExternalString. |
|
* fail if the latter is not possible. |
|
357 |
* |
* |
358 |
* This function requires that runtime->gcLock is held on entry. On successful |
* This function always needs rt but can live with null cx. |
|
* return the lock is still held and on failure it will be released with |
|
|
* the error reported. |
|
359 |
*/ |
*/ |
|
extern JSBool |
|
|
js_AddAsGCBytes(JSContext *cx, size_t sz); |
|
|
|
|
360 |
extern void |
extern void |
361 |
js_RemoveAsGCBytes(JSRuntime* rt, size_t sz); |
js_FinalizeStringRT(JSRuntime *rt, JSString *str, intN type, JSContext *cx); |
362 |
|
|
363 |
#ifdef DEBUG_notme |
#ifdef DEBUG_notme |
364 |
#define JS_GCMETER 1 |
#define JS_GCMETER 1 |