Annotation of sbbs/javascript/include/mozilla/js/jsgc.h, revision 1.1.1.1

1.1       root        1: /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
                      2:  *
                      3:  * The contents of this file are subject to the Netscape Public
                      4:  * License Version 1.1 (the "License"); you may not use this file
                      5:  * except in compliance with the License. You may obtain a copy of
                      6:  * the License at http://www.mozilla.org/NPL/
                      7:  *
                      8:  * Software distributed under the License is distributed on an "AS
                      9:  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
                     10:  * implied. See the License for the specific language governing
                     11:  * rights and limitations under the License.
                     12:  *
                     13:  * The Original Code is Mozilla Communicator client code, released
                     14:  * March 31, 1998.
                     15:  *
                     16:  * The Initial Developer of the Original Code is Netscape
                     17:  * Communications Corporation.  Portions created by Netscape are
                     18:  * Copyright (C) 1998 Netscape Communications Corporation. All
                     19:  * Rights Reserved.
                     20:  *
                     21:  * Contributor(s):
                     22:  *
                     23:  * Alternatively, the contents of this file may be used under the
                     24:  * terms of the GNU Public License (the "GPL"), in which case the
                     25:  * provisions of the GPL are applicable instead of those above.
                     26:  * If you wish to allow use of your version of this file only
                     27:  * under the terms of the GPL and not to allow others to use your
                     28:  * version of this file under the NPL, indicate your decision by
                     29:  * deleting the provisions above and replace them with the notice
                     30:  * and other provisions required by the GPL.  If you do not delete
                     31:  * the provisions above, a recipient may use your version of this
                     32:  * file under either the NPL or the GPL.
                     33:  */
                     34: 
                     35: #ifndef jsgc_h___
                     36: #define jsgc_h___
                     37: /*
                     38:  * JS Garbage Collector.
                     39:  */
                     40: #include "jsprvtd.h"
                     41: #include "jspubtd.h"
                     42: #include "jsdhash.h"
                     43: 
                     44: JS_BEGIN_EXTERN_C
                     45: 
                     46: /* GC thing type indexes. */
                     47: #define GCX_OBJECT              0               /* JSObject */
                     48: #define GCX_STRING              1               /* JSString */
                     49: #define GCX_DOUBLE              2               /* jsdouble */
                     50: #define GCX_MUTABLE_STRING      3               /* JSString that's mutable --
                     51:                                                    single-threaded only! */
                     52: #define GCX_EXTERNAL_STRING     4               /* JSString w/ external chars */
                     53: #define GCX_NTYPES_LOG2         3               /* type index bits */
                     54: #define GCX_NTYPES              JS_BIT(GCX_NTYPES_LOG2)
                     55: 
                     56: /* GC flag definitions, must fit in 8 bits (type index goes in the low bits). */
                     57: #define GCF_TYPEMASK    JS_BITMASK(GCX_NTYPES_LOG2)
                     58: #define GCF_MARK        JS_BIT(GCX_NTYPES_LOG2)
                     59: #define GCF_FINAL       JS_BIT(GCX_NTYPES_LOG2 + 1)
                     60: #define GCF_LOCKSHIFT   (GCX_NTYPES_LOG2 + 2)   /* lock bit shift and mask */
                     61: #define GCF_LOCKMASK    (JS_BITMASK(8 - GCF_LOCKSHIFT) << GCF_LOCKSHIFT)
                     62: #define GCF_LOCK        JS_BIT(GCF_LOCKSHIFT)   /* lock request bit in API */
                     63: 
                     64: /* Pseudo-flag that modifies GCX_STRING to make GCX_MUTABLE_STRING. */
                     65: #define GCF_MUTABLE     2
                     66: 
                     67: #if (GCX_STRING | GCF_MUTABLE) != GCX_MUTABLE_STRING
                     68: # error "mutable string type index botch!"
                     69: #endif
                     70: 
                     71: extern uint8 *
                     72: js_GetGCThingFlags(void *thing);
                     73: 
                     74: /* These are compatible with JSDHashEntryStub. */
                     75: struct JSGCRootHashEntry {
                     76:     JSDHashEntryHdr hdr;
                     77:     void            *root;
                     78:     const char      *name;
                     79: };
                     80: 
                     81: struct JSGCLockHashEntry {
                     82:     JSDHashEntryHdr hdr;
                     83:     const JSGCThing *thing;
                     84:     uint32          count;
                     85: };
                     86: 
                     87: #if 1
                     88: /*
                     89:  * Since we're forcing a GC from JS_GC anyway, don't bother wasting cycles
                     90:  * loading oldval.  XXX remove implied force, fix jsinterp.c's "second arg
                     91:  * ignored", etc.
                     92:  */
                     93: #define GC_POKE(cx, oldval) ((cx)->runtime->gcPoke = JS_TRUE)
                     94: #else
                     95: #define GC_POKE(cx, oldval) ((cx)->runtime->gcPoke = JSVAL_IS_GCTHING(oldval))
                     96: #endif
                     97: 
                     98: extern intN
                     99: js_ChangeExternalStringFinalizer(JSStringFinalizeOp oldop,
                    100:                                  JSStringFinalizeOp newop);
                    101: 
                    102: extern JSBool
                    103: js_InitGC(JSRuntime *rt, uint32 maxbytes);
                    104: 
                    105: extern void
                    106: js_FinishGC(JSRuntime *rt);
                    107: 
                    108: extern JSBool
                    109: js_AddRoot(JSContext *cx, void *rp, const char *name);
                    110: 
                    111: extern JSBool
                    112: js_AddRootRT(JSRuntime *rt, void *rp, const char *name);
                    113: 
                    114: extern JSBool
                    115: js_RemoveRoot(JSRuntime *rt, void *rp);
                    116: 
                    117: extern void *
                    118: js_AllocGCThing(JSContext *cx, uintN flags);
                    119: 
                    120: extern JSBool
                    121: js_LockGCThing(JSContext *cx, void *thing);
                    122: 
                    123: extern JSBool
                    124: js_LockGCThingRT(JSRuntime *rt, void *thing);
                    125: 
                    126: extern JSBool
                    127: js_UnlockGCThingRT(JSRuntime *rt, void *thing);
                    128: 
                    129: extern JSBool 
                    130: js_IsAboutToBeFinalized(JSContext *cx, void *thing);
                    131: 
                    132: extern void
                    133: js_MarkAtom(JSContext *cx, JSAtom *atom, void *arg);
                    134: 
                    135: /* We avoid a large number of unnecessary calls by doing the flag check first */
                    136: #define GC_MARK_ATOM(cx, atom, arg)                                           \
                    137:     JS_BEGIN_MACRO                                                            \
                    138:         if (!((atom)->flags & ATOM_MARK))                                     \
                    139:             js_MarkAtom(cx, atom, arg);                                       \
                    140:     JS_END_MACRO
                    141: 
                    142: extern void
                    143: js_MarkGCThing(JSContext *cx, void *thing, void *arg);
                    144: 
                    145: #ifdef GC_MARK_DEBUG
                    146: 
                    147: typedef struct GCMarkNode GCMarkNode;
                    148: 
                    149: struct GCMarkNode {
                    150:     void        *thing;
                    151:     const char  *name;
                    152:     GCMarkNode  *next;
                    153:     GCMarkNode  *prev;
                    154: };
                    155: 
                    156: #define GC_MARK(_cx, _thing, _name, _prev)                                    \
                    157:     JS_BEGIN_MACRO                                                            \
                    158:         GCMarkNode _node;                                                     \
                    159:         _node.thing = _thing;                                                 \
                    160:         _node.name  = _name;                                                  \
                    161:         _node.next  = NULL;                                                   \
                    162:         _node.prev  = _prev;                                                  \
                    163:         if (_prev) ((GCMarkNode *)(_prev))->next = &_node;                    \
                    164:         js_MarkGCThing(_cx, _thing, &_node);                                  \
                    165:     JS_END_MACRO
                    166: 
                    167: #else  /* !GC_MARK_DEBUG */
                    168: 
                    169: #define GC_MARK(cx, thing, name, prev)   js_MarkGCThing(cx, thing, NULL)
                    170: 
                    171: #endif /* !GC_MARK_DEBUG */
                    172: 
                    173: /*
                    174:  * Flags to modify how a GC marks and sweeps:
                    175:  *   GC_KEEP_ATOMS      Don't sweep unmarked atoms, they may be in use by the
                    176:  *                      compiler, or by an API function that calls js_Atomize,
                    177:  *                      when the GC is called from js_AllocGCThing, due to a
                    178:  *                      malloc failure or runtime GC-thing limit.
                    179:  *   GC_LAST_CONTEXT    Called from js_DestroyContext for last JSContext in a
                    180:  *                      JSRuntime, when it is imperative that rt->gcPoke gets
                    181:  *                      cleared early in js_GC, if it is set.
                    182:  *   GC_ALREADY_LOCKED  rt->gcLock is already held on entry to js_GC, and kept
                    183:  *                      on return to its caller.
                    184:  */
                    185: #define GC_KEEP_ATOMS       0x1
                    186: #define GC_LAST_CONTEXT     0x2
                    187: #define GC_ALREADY_LOCKED   0x4
                    188: 
                    189: extern void
                    190: js_ForceGC(JSContext *cx, uintN gcflags);
                    191: 
                    192: extern void
                    193: js_GC(JSContext *cx, uintN gcflags);
                    194: 
                    195: #ifdef JS_GCMETER
                    196: 
                    197: typedef struct JSGCStats {
                    198:     uint32  alloc;      /* number of allocation attempts */
                    199:     uint32  freelen;    /* gcFreeList length */
                    200:     uint32  recycle;    /* number of things recycled through gcFreeList */
                    201:     uint32  retry;      /* allocation attempt retries after running the GC */
                    202:     uint32  fail;       /* allocation failures */
                    203:     uint32  finalfail;  /* finalizer calls allocator failures */
                    204:     uint32  lock;       /* valid lock calls */
                    205:     uint32  unlock;     /* valid unlock calls */
                    206:     uint32  stuck;      /* stuck reference counts seen by lock calls */
                    207:     uint32  unstuck;    /* unlock calls that saw a stuck lock count */
                    208:     uint32  depth;      /* mark recursion depth */
                    209:     uint32  maxdepth;   /* maximum mark recursion depth */
                    210:     uint32  maxlevel;   /* maximum GC nesting (indirect recursion) level */
                    211:     uint32  poke;       /* number of potentially useful GC calls */
                    212:     uint32  nopoke;     /* useless GC calls where js_PokeGC was not set */
                    213:     uint32  afree;      /* thing arenas freed so far */
                    214:     uint32  stackseg;   /* total extraordinary stack segments scanned */
                    215:     uint32  segslots;   /* total stack segment jsval slots scanned */
                    216: } JSGCStats;
                    217: 
                    218: extern void
                    219: js_DumpGCStats(JSRuntime *rt, FILE *fp);
                    220: 
                    221: #endif /* JS_GCMETER */
                    222: 
                    223: JS_END_EXTERN_C
                    224: 
                    225: #endif /* jsgc_h___ */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.