home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / js / src / jsgc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  3.7 KB  |  114 lines

  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 License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #ifndef jsgc_h___
  20. #define jsgc_h___
  21. /*
  22.  * JS Garbage Collector.
  23.  */
  24. #include "jspubtd.h"
  25.  
  26. PR_BEGIN_EXTERN_C
  27.  
  28. /* GC thing type indexes. */
  29. #define GCX_OBJECT    0            /* JSObject */
  30. #define GCX_STRING    1            /* JSString */
  31. #define GCX_DOUBLE    2            /* jsdouble */
  32. #define GCX_DECIMAL     3                       /* JSDecimal */
  33. #define GCX_NTYPES      4
  34.  
  35. /* GC flag definitions (type index goes in low bits). */
  36. #define GCF_TYPEMASK    PR_BITMASK(2)        /* use low bits for type */
  37. #define GCF_MARK    PR_BIT(2)        /* mark bit */
  38. #define GCF_FINAL    PR_BIT(3)        /* in finalization bit */
  39. #define GCF_LOCKBIT    4            /* lock bit shift and mask */
  40. #define GCF_LOCKMASK    (PR_BITMASK(4) << GCF_LOCKBIT)
  41. #define GCF_LOCK    PR_BIT(GCF_LOCKBIT)    /* lock request bit in API */
  42.  
  43. #if 1
  44. /*
  45.  * Since we're forcing a GC from JS_GC anyway, don't bother wasting cycles
  46.  * loading oldval.  XXX remove implied force, poke in addroot/removeroot, &c
  47.  */
  48. #define GC_POKE(cx, oldval) ((cx)->runtime->gcPoke = JS_TRUE)
  49. #else
  50. #define GC_POKE(cx, oldval) ((cx)->runtime->gcPoke = JSVAL_IS_GCTHING(oldval))
  51. #endif
  52.  
  53. extern JSBool
  54. js_InitGC(JSRuntime *rt, uint32 maxbytes);
  55.  
  56. extern void
  57. js_FinishGC(JSRuntime *rt);
  58.  
  59. extern JSBool
  60. js_AddRoot(JSContext *cx, void *rp);
  61.  
  62. extern JSBool
  63. js_AddNamedRoot(JSContext *cx, void *rp, const char *name);
  64.  
  65. extern JSBool
  66. js_RemoveRoot(JSContext *cx, void *rp);
  67.  
  68. extern void *
  69. js_AllocGCThing(JSContext *cx, uintN flags);
  70.  
  71. extern JSBool
  72. js_LockGCThing(JSContext *cx, void *thing);
  73.  
  74. extern JSBool
  75. js_UnlockGCThing(JSContext *cx, void *thing);
  76.  
  77. extern void
  78. js_ForceGC(JSContext *cx);
  79.  
  80. extern void
  81. js_GC(JSContext *cx);
  82.  
  83. #ifdef JS_GCMETER
  84.  
  85. typedef struct JSGCStats {
  86.     uint32  alloc;      /* number of allocation attempts */
  87.     uint32  freelen;    /* gcFreeList length */
  88.     uint32  recycle;    /* number of things recycled through gcFreeList */
  89.     uint32  retry;      /* allocation attempt retries after running the GC */
  90.     uint32  fail;       /* allocation failures */
  91.     uint32  lock;       /* valid lock calls */
  92.     uint32  unlock;     /* valid unlock calls */
  93.     uint32  stuck;      /* stuck reference counts seen by lock calls */
  94.     uint32  unstuck;    /* unlock calls that saw a stuck lock count */
  95.     uint32  depth;      /* mark recursion depth */
  96.     uint32  maxdepth;   /* maximum mark recursion depth */
  97.     uint32  maxlevel;   /* maximum GC nesting (indirect recursion) level */
  98.     uint32  poke;       /* number of potentially useful GC calls */
  99.     uint32  nopoke;     /* useless GC calls where js_PokeGC was not set */
  100.     uint32  badarena;   /* thing arena corruption */
  101.     uint32  badflag;    /* flags arena corruption */
  102.     uint32  afree;      /* thing arenas freed so far */
  103.     uint32  fafree;     /* flags arenas freed so far */
  104. } JSGCStats;
  105.  
  106. extern void
  107. js_DumpGCStats(JSRuntime *rt, FILE *fp);
  108.  
  109. #endif /* JS_GCMETER */
  110.  
  111. PR_END_EXTERN_C
  112.  
  113. #endif /* jsgc_h___ */
  114.