add js to tree

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3693 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Brian West
2006-12-18 15:53:47 +00:00
parent 855c7b9a77
commit fff98f6316
1137 changed files with 386873 additions and 0 deletions

View File

@@ -0,0 +1 @@
Makefile

View File

@@ -0,0 +1,3 @@
/.cvsignore/1.2/Sat May 12 06:14:33 2001//
/Makefile.in/1.8/Sun Apr 25 15:00:36 2004//
D

View File

@@ -0,0 +1,3 @@
A D/include////
A D/src////
A D/tests////

View File

@@ -0,0 +1 @@
mozilla/nsprpub/lib/msgc

View File

@@ -0,0 +1 @@
:pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot

View File

@@ -0,0 +1,52 @@
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is the Netscape Portable Runtime (NSPR).
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998-2000
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
MOD_DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(MOD_DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
DIRS = include src tests
include $(topsrcdir)/config/rules.mk
export:: $(TARGETS)

View File

@@ -0,0 +1 @@
Makefile

View File

@@ -0,0 +1,6 @@
/.cvsignore/1.2/Sat May 12 06:15:53 2001//
/MANIFEST/1.1/Thu Jun 4 22:48:12 1998//
/Makefile.in/1.10/Sun Apr 25 15:00:36 2004//
/gcint.h/3.6/Sun Apr 25 15:00:36 2004//
/prgc.h/3.7/Tue Nov 23 00:54:05 2004//
D

View File

@@ -0,0 +1 @@
mozilla/nsprpub/lib/msgc/include

View File

@@ -0,0 +1 @@
:pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot

View File

@@ -0,0 +1,5 @@
#
# This is a list of local files which get copied to the mozilla:dist directory
#
prgc.h

View File

@@ -0,0 +1,61 @@
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is the Netscape Portable Runtime (NSPR).
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998-2000
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
#! gmake
MOD_DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(MOD_DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
EXPORT_HEADERS = prgc.h
HEADERS = $(EXPORT_HEADERS) gcint.h
RELEASE_HEADERS = $(EXPORT_HEADERS)
RELEASE_HEADERS_DEST = $(RELEASE_INCLUDE_DIR)
include $(topsrcdir)/config/rules.mk
export:: $(EXPORT_HEADERS)
$(INSTALL) -m 444 $(EXPORT_HEADERS) $(dist_includedir)
ifeq ($(MOZ_BITS),16)
$(INSTALL) -m 444 $(EXPORT_HEADERS) $(MOZ_INCL)
endif

View File

@@ -0,0 +1,129 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Netscape Portable Runtime (NSPR).
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998-2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef gcint_h___
#define gcint_h___
#include "prmon.h"
#include "prgc.h"
extern PRLogModuleInfo *_pr_msgc_lm;
extern GCInfo _pr_gcData;
#if defined(_WIN32) && !defined(DEBUG)
#undef INLINE_LOCK
#endif
#ifdef INLINE_LOCK
#define LOCK_GC() EnterCriticalSection(&_pr_gcData.lock->mutexHandle)
#define UNLOCK_GC() LeaveCriticalSection(&_pr_gcData.lock->mutexHandle)
#else
#define LOCK_GC() PR_EnterMonitor(_pr_gcData.lock)
#define UNLOCK_GC() PR_ExitMonitor (_pr_gcData.lock)
#define GC_IS_LOCKED() (PR_GetMonitorEntryCount(_pr_gcData.lock)!=0)
#endif
#ifdef DEBUG
#define _GCTRACE(x, y) if (_pr_gcData.flags & x) GCTrace y
#else
#define _GCTRACE(x, y)
#endif
extern GCBeginGCHook *_pr_beginGCHook;
extern void *_pr_beginGCHookArg;
extern GCBeginGCHook *_pr_endGCHook;
extern void *_pr_endGCHookArg;
extern GCBeginFinalizeHook *_pr_beginFinalizeHook;
extern void *_pr_beginFinalizeHookArg;
extern GCBeginFinalizeHook *_pr_endFinalizeHook;
extern void *_pr_endFinalizeHookArg;
extern int _pr_do_a_dump;
extern FILE *_pr_dump_file;
extern PRLogModuleInfo *_pr_gc_lm;
/*
** Root finders. Root finders are used by the GC to find pointers into
** the GC heap that are not contained in the GC heap.
*/
typedef struct RootFinderStr RootFinder;
struct RootFinderStr {
RootFinder *next;
GCRootFinder *func;
char *name;
void *arg;
};
extern RootFinder *_pr_rootFinders;
typedef struct CollectorTypeStr {
GCType gctype;
PRUint32 flags;
} CollectorType;
#define GC_MAX_TYPES 256
extern CollectorType *_pr_collectorTypes;
#define _GC_TYPE_BUSY 0x1
#define _GC_TYPE_FINAL 0x2
#define _GC_TYPE_WEAK 0x4
/* Slot in _pr_gcTypes used for free memory */
#define FREE_MEMORY_TYPEIX 255
extern void _PR_InitGC(PRWord flags);
extern void _MD_InitGC(void);
extern void PR_CALLBACK _PR_ScanFinalQueue(void *notused);
/*
** Grow the GC Heap.
*/
extern void *_MD_GrowGCHeap(PRUint32 *sizep);
/*
** Extend the GC Heap.
*/
extern PRBool _MD_ExtendGCHeap(char *base, PRInt32 oldSize, PRInt32 newSize);
/*
** Free a GC segment.
*/
extern void _MD_FreeGCSegment(void *base, PRInt32 len);
#endif /* gcint_h___ */

View File

@@ -0,0 +1,419 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Netscape Portable Runtime (NSPR).
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998-2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef prgc_h___
#define prgc_h___
/*
** API to NSPR gc memory system.
*/
#include "prtypes.h"
#include "prmon.h"
#include "prthread.h"
#include <stdio.h>
#if defined(WIN16)
#define GCPTR __far
#else
#define GCPTR
#endif
PR_BEGIN_EXTERN_C
/*
** Initialize the garbage collector.
** "flags" is the trace flags (see below).
** "initialHeapSize" is the initial size of the heap and may be zero
** if the default is desired.
** "segmentSize" is the size of each segment of memory added to the
** heap when the heap is grown.
*/
PR_EXTERN(void) PR_InitGC(
PRWord flags, PRInt32 initialHeapSize, PRInt32 segmentSize, PRThreadScope scope);
/*
** Shuts down gc and frees up all memory associated with it.
*/
PR_EXTERN(void) PR_ShutdownGC(PRBool finalizeOnExit);
/*
** This walk function will be called for every gc object in the
** heap as it is walked. If it returns non-zero, the walk is terminated.
*/
typedef PRInt32 (*PRWalkFun)(void GCPTR* obj, void* data);
/*
** GC Type record. This defines all of the GC operations used on a
** particular object type. These structures are passed to
** PR_RegisterType.
*/
typedef struct GCType {
/*
** Scan an object that is in the GC heap and call GCInfo.livePointer
** on all of the pointers in it. If this slot is null then the object
** won't be scanned (i.e. it has no embedded pointers).
*/
void (PR_CALLBACK *scan)(void GCPTR *obj);
/*
** Finalize an object that has no references. This is called by the
** GC after it has determined where the object debris is but before
** it has moved the debris to the logical "free list". The object is
** marked alive for this call and removed from the list of objects
** that need finalization (finalization only happens once for an
** object). If this slot is null then the object doesn't need
** finalization.
*/
void (PR_CALLBACK *finalize)(void GCPTR *obj);
/*
** Dump out an object during a PR_DumpGCHeap(). This is used as a
** debugging tool.
*/
void (PR_CALLBACK *dump)(FILE *out, void GCPTR *obj, PRBool detailed, PRIntn indentLevel);
/*
** Add object to summary table.
*/
void (PR_CALLBACK *summarize)(void GCPTR *obj, PRUint32 bytes);
/*
** Free hook called by GC when the object is being freed.
*/
void (PR_CALLBACK *free)(void *obj);
/* Weak pointer support: If the object has a weak pointer (Note:
at most one), this function is used to get the weak link's
offset from the start of the body of a gc object */
PRUint32 (PR_CALLBACK *getWeakLinkOffset)(void *obj);
/* Descriptive character for dumping this GCType */
char kindChar;
/*
** Walker routine. This routine should apply fun(obj->ptr, data)
** for every gc pointer within the object.
*/
PRInt32 (PR_CALLBACK *walk)(void GCPTR *obj, PRWalkFun fun, void* data);
} GCType;
/*
** This data structure must be added as the hash table passed to
** the summarize method of GCType.
*/
typedef struct PRSummaryEntry {
void* clazz;
PRInt32 instancesCount;
PRInt32 totalSize;
} PRSummaryEntry;
/*
** This function pointer must be registered by users of nspr
** to produce the finally summary after all object in the
** heap have been visited.
*/
typedef void (PR_CALLBACK *PRSummaryPrinter)(FILE *out, void* closure);
PR_EXTERN(void) PR_CALLBACK PR_RegisterSummaryPrinter(PRSummaryPrinter fun, void* closure);
typedef void PR_CALLBACK GCRootFinder(void *arg);
typedef void PR_CALLBACK GCBeginFinalizeHook(void *arg);
typedef void PR_CALLBACK GCEndFinalizeHook(void *arg);
typedef void PR_CALLBACK GCBeginGCHook(void *arg);
typedef void PR_CALLBACK GCEndGCHook(void *arg);
typedef enum { PR_GCBEGIN, PR_GCEND } GCLockHookArg;
typedef void PR_CALLBACK GCLockHookFunc(GCLockHookArg arg1, void *arg2);
typedef struct GCLockHook GCLockHook;
struct GCLockHook {
GCLockHookFunc* func;
void* arg;
GCLockHook* next;
GCLockHook* prev;
};
/*
** Hooks which are called at the beginning and end of the GC process.
** The begin hooks are called before the root finding step. The hooks are
** called with threading disabled, so it is now allowed to re-enter the
** kernel. The end hooks are called after the gc has finished but before
** the finalizer has run.
*/
PR_EXTERN(void) PR_CALLBACK PR_SetBeginGCHook(GCBeginGCHook *hook, void *arg);
PR_EXTERN(void) PR_CALLBACK PR_GetBeginGCHook(GCBeginGCHook **hook, void **arg);
PR_EXTERN(void) PR_CALLBACK PR_SetEndGCHook(GCBeginGCHook *hook, void *arg);
PR_EXTERN(void) PR_CALLBACK PR_GetEndGCHook(GCEndGCHook **hook, void **arg);
/*
** Called before SuspendAll is called by dogc, so that GC thread can hold
** all the locks before hand to avoid any deadlocks
*/
/*
PR_EXTERN(void) PR_SetGCLockHook(GCLockHook *hook, void *arg);
PR_EXTERN(void) PR_GetGCLockHook(GCLockHook **hook, void **arg);
*/
PR_EXTERN(int) PR_RegisterGCLockHook(GCLockHookFunc *hook, void *arg);
/*
** Hooks which are called at the beginning and end of the GC finalization
** process. After the GC has identified all of the dead objects in the
** heap, it looks for objects that need finalization. Before it calls the
** first finalization proc (see the GCType structure above) it calls the
** begin hook. When it has finalized the last object it calls the end
** hook.
*/
PR_EXTERN(void) PR_SetBeginFinalizeHook(GCBeginFinalizeHook *hook, void *arg);
PR_EXTERN(void) PR_GetBeginFinalizeHook(GCBeginFinalizeHook **hook, void **arg);
PR_EXTERN(void) PR_SetEndFinalizeHook(GCBeginFinalizeHook *hook, void *arg);
PR_EXTERN(void) PR_GetEndFinalizeHook(GCEndFinalizeHook **hook, void **arg);
/*
** Register a GC type. Return's the index into the GC internal type
** table. The returned value is passed to PR_AllocMemory. After the call,
** the "type" memory belongs to the GC (the caller must not free it or
** change it).
*/
PR_EXTERN(PRInt32) PR_RegisterType(GCType *type);
/*
** Register a root finder with the collector. The collector will call
** these functions to identify all of the roots before collection
** proceeds. "arg" is passed to the function when it is called.
*/
PR_EXTERN(PRStatus) PR_RegisterRootFinder(GCRootFinder func, char *name, void *arg);
/*
** Allocate some GC'able memory. The object must be at least bytes in
** size. The type index function for the object is specified. "flags"
** specifies some control flags. If PR_ALLOC_CLEAN is set then the memory
** is zero'd before being returned. If PR_ALLOC_DOUBLE is set then the
** allocated memory is double aligned.
**
** Any memory cell that you store a pointer to something allocated by
** this call must be findable by the GC. Use the PR_RegisterRootFinder to
** register new places where the GC will look for pointers into the heap.
** The GC already knows how to scan any NSPR threads or monitors.
*/
PR_EXTERN(PRWord GCPTR *)PR_AllocMemory(
PRWord bytes, PRInt32 typeIndex, PRWord flags);
PR_EXTERN(PRWord GCPTR *)PR_AllocSimpleMemory(
PRWord bytes, PRInt32 typeIndex);
/*
** This function can be used to cause PR_AllocMemory to always return
** NULL. This may be useful in low memory situations when we're trying to
** shutdown applets.
*/
PR_EXTERN(void) PR_EnableAllocation(PRBool yesOrNo);
/* flags bits */
#define PR_ALLOC_CLEAN 0x1
#define PR_ALLOC_DOUBLE 0x2
#define PR_ALLOC_ZERO_HANDLE 0x4 /* XXX yes, it's a hack */
/*
** Force a garbage collection right now. Return when it completes.
*/
PR_EXTERN(void) PR_GC(void);
/*
** Force a finalization right now. Return when finalization has
** completed. Finalization completes when there are no more objects
** pending finalization. This does not mean there are no objects in the
** gc heap that will need finalization should a collection be done after
** this call.
*/
PR_EXTERN(void) PR_ForceFinalize(void);
/*
** Dump the GC heap out to the given file. This will stop the system dead
** in its tracks while it is occuring.
*/
PR_EXTERN(void) PR_DumpGCHeap(FILE *out, PRBool detailed);
/*
** Wrapper for PR_DumpGCHeap
*/
PR_EXTERN(void) PR_DumpMemory(PRBool detailed);
/*
** Dump summary of objects allocated.
*/
PR_EXTERN(void) PR_DumpMemorySummary(void);
/*
** Dump the application heaps.
*/
PR_EXTERN(void) PR_DumpApplicationHeaps(void);
/*
** Helper function used by dump routines to do the indentation in a
** consistent fashion.
*/
PR_EXTERN(void) PR_DumpIndent(FILE *out, PRIntn indent);
/*
** The GCInfo structure contains all of the GC state...
**
** busyMemory:
** The amount of GC heap memory that is busy at this instant. Busy
** doesn't mean alive, it just means that it has been
** allocated. Immediately after a collection busy means how much is
** alive.
**
** freeMemory:
** The amount of GC heap memory that is as yet unallocated.
**
** allocMemory:
** The sum of free and busy memory in the GC heap.
**
** maxMemory:
** The maximum size that the GC heap is allowed to grow.
**
** lowSeg:
** The lowest segment currently used in the GC heap.
**
** highSeg:
** The highest segment currently used in the GC heap.
** The lowSeg and highSeg members are used for a "quick test" of whether
** a pointer falls within the GC heap. [ see GC_IN_HEAP(...) ]
**
** lock:
** Monitor used for synchronization within the GC.
**
** finalizer:
** Thread in which the GC finalizer is running.
**
** liveBlock:
** Object scanning functions call through this function pointer to
** register a potential block of pointers with the collector. (This is
** currently not at all different than processRoot.)
**
** livePointer:
** Object scanning functions call through this function pointer to
** register a single pointer with the collector.
**
** processRootBlock:
** When a root finder identifies a root it should call through this
** function pointer so that the GC can process the root. The call takes
** a base address and count which the gc will examine for valid heap
** pointers.
**
** processRootPointer:
** When a root finder identifies a root it should call through this
** function pointer so that the GC can process the root. The call takes
** a single pointer value.
*/
typedef struct GCInfoStr {
PRWord flags; /* trace flags (see below) */
PRWord busyMemory; /* memory in use right now */
PRWord freeMemory; /* memory free right now */
PRWord allocMemory; /* sum of busy & free memory */
PRWord maxMemory; /* max memory we are allowed to allocate */
PRWord *lowSeg; /* lowest segment in the GC heap */
PRWord *highSeg; /* highest segment in the GC heap */
PRMonitor *lock;
PRThread *finalizer;
void (PR_CALLBACK *liveBlock)(void **base, PRInt32 count);
void (PR_CALLBACK *livePointer)(void *ptr);
void (PR_CALLBACK *processRootBlock)(void **base, PRInt32 count);
void (PR_CALLBACK *processRootPointer)(void *ptr);
FILE* dumpOutput;
#ifdef GCTIMINGHOOK
void (*gcTimingHook)(int32 gcTime);
#endif
} GCInfo;
PR_EXTERN(GCInfo *) PR_GetGCInfo(void);
PR_EXTERN(PRBool) PR_GC_In_Heap(void GCPTR *object);
/*
** Simple bounds check to see if a pointer is anywhere near the GC heap.
** Used to avoid calls to PR_ProcessRoot and GCInfo.livePointer by object
** scanning code.
*/
#if !defined(XP_PC) || defined(_WIN32)
#define GC_IN_HEAP(_info, _p) (((PRWord*)(_p) >= (_info)->lowSeg) && \
((PRWord*)(_p) < (_info)->highSeg))
#else
/*
** The simple bounds check, above, doesn't work in Win16, because we don't
** maintain: lowSeg == MIN(all segments) and highSeg == MAX(all segments).
** So we have to do a little better.
*/
#define GC_IN_HEAP(_info, _p) PR_GC_In_Heap(_p)
#endif
PR_EXTERN(PRWord) PR_GetObjectHeader(void *ptr);
PR_EXTERN(PRWord) PR_SetObjectHeader(void *ptr, PRWord newUserBits);
/************************************************************************/
/* Trace flags (passed to PR_InitGC or in environment GCLOG) */
#define GC_TRACE 0x0001
#define GC_ROOTS 0x0002
#define GC_LIVE 0x0004
#define GC_ALLOC 0x0008
#define GC_MARK 0x0010
#define GC_SWEEP 0x0020
#define GC_DEBUG 0x0040
#define GC_FINAL 0x0080
#if defined(DEBUG_kipp) || defined(DEBUG_warren)
#define GC_CHECK 0x0100
#endif
#ifdef DEBUG
#define GCTRACE(x, y) if (PR_GetGCInfo()->flags & x) GCTrace y
PR_EXTERN(void) GCTrace(char *fmt, ...);
#else
#define GCTRACE(x, y)
#endif
PR_END_EXTERN_C
#endif /* prgc_h___ */

View File

@@ -0,0 +1 @@
Makefile

View File

@@ -0,0 +1,10 @@
/.cvsignore/1.2/Sat May 12 06:22:03 2001//
/Makefile.in/1.13/Wed Jun 1 14:28:27 2005//
/macgc.c/3.5/Sun Apr 25 15:00:36 2004//
/os2gc.c/3.6/Sun Apr 25 15:00:36 2004//
/prgcapi.c/3.6/Sun Apr 25 15:00:36 2004//
/prmsgc.c/3.10/Mon Nov 7 22:39:00 2005//
/unixgc.c/3.6/Sun Apr 25 15:00:36 2004//
/win16gc.c/3.5/Sun Apr 25 15:00:36 2004//
/win32gc.c/3.5/Sun Apr 25 15:00:36 2004//
D

View File

@@ -0,0 +1 @@
mozilla/nsprpub/lib/msgc/src

View File

@@ -0,0 +1 @@
:pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot

View File

@@ -0,0 +1,103 @@
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is the Netscape Portable Runtime (NSPR).
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998-2000
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
#! gmake
MOD_DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(MOD_DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
INCLUDES = -I$(dist_includedir) -I../include
CSRCS = prgcapi.c prmsgc.c
ifeq ($(OS_ARCH),WINNT)
CSRCS += win32gc.c
else
ifeq ($(OS_ARCH),OS2)
CSRCS += os2gc.c
else
CSRCS += unixgc.c
endif
endif
NSPR_VERSION = $(MOD_MAJOR_VERSION)
EXTRA_LIBS = $(LIBNSPR)
ifdef RESOLVE_LINK_SYMBOLS
EXTRA_LIBS += $(OS_LIBS)
endif
ifeq ($(OS_ARCH), WINNT)
ifdef NS_USE_GCC
DLLBASE=-Wl,--image-base -Wl,0x30000000
else
DLLBASE=-BASE:0x30000000
endif # GCC
#RES=$(OBJDIR)/ds.res
#RESNAME=$(MOD_DEPTH)/pr/src/nspr.rc
#OS_LIBS = user32.lib
endif # WINNT
LIBRARY_NAME = msgc
LIBRARY_VERSION = $(MOD_MAJOR_VERSION)
RELEASE_LIBS = $(TARGETS)
include $(topsrcdir)/config/rules.mk
#
# The Client build wants the shared libraries in $(dist_bindir),
# so we also install them there.
#
export:: $(TARGETS)
$(INSTALL) -m 444 $(TARGETS) $(dist_libdir)
ifdef SHARED_LIBRARY
$(INSTALL) -m 444 $(SHARED_LIBRARY) $(dist_bindir)
endif
ifeq ($(MOZ_BITS),16)
$(INSTALL) -m 444 $(TARGETS) $(MOZ_DIST)/lib
$(INSTALL) -m 444 $(TARGETS) $(MOZ_DIST)/bin
endif

View File

@@ -0,0 +1,75 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Netscape Portable Runtime (NSPR).
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998-2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "primpl.h"
#include "MacMemAllocator.h"
void _MD_InitGC() {}
void *_MD_GrowGCHeap(size_t *sizep)
{
void *heapPtr = NULL;
size_t heapSize = *sizep;
// In previous versions of this code we tried to allocate GC heaps from the application
// heap. In the 4.0 application, we try to keep our app heap allications to a minimum
// and instead go through our own memory allocation routines.
heapPtr = malloc(heapSize);
if (heapPtr == NULL) {
FreeMemoryStats stats;
memtotal(heapSize, &stats); // How much can we allcoate?
if (stats.maxBlockSize < heapSize)
heapSize = stats.maxBlockSize;
heapPtr = malloc(heapSize);
if (heapPtr == NULL) // Now we're hurting
heapSize = 0;
}
*sizep = heapSize;
return heapPtr;
}
void _MD_FreeGCSegment(void *base, int32 /* len */)
{
free(base);
}

View File

@@ -0,0 +1,83 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Netscape Portable Runtime (NSPR).
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998-2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* GC related routines
*
*/
#include "prlog.h"
#include <stdlib.h>
/* Leave a bit of room for any malloc header bytes... */
#define MAX_SEGMENT_SIZE (65536L - 4096L)
/************************************************************************/
/*
** Machine dependent GC Heap management routines:
** _MD_GrowGCHeap
*/
/************************************************************************/
void _MD_InitGC() {}
void *_MD_GrowGCHeap(PRUint32 *sizep)
{
void *addr;
if ( *sizep > MAX_SEGMENT_SIZE )
{
*sizep = MAX_SEGMENT_SIZE;
}
addr = malloc((size_t)*sizep);
return addr;
}
PRBool _MD_ExtendGCHeap(char *base, PRInt32 oldSize, PRInt32 newSize) {
/* Not sure about this. Todd? */
return PR_FALSE;
}
void _MD_FreeGCSegment(void *base, PRInt32 len)
{
if (base)
{
free(base);
}
}

View File

@@ -0,0 +1,351 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Netscape Portable Runtime (NSPR).
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998-2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#include "prenv.h"
#include "prmem.h"
#include "prmon.h"
#include "prlog.h"
#include "prthread.h"
#if defined(XP_MAC)
#include "pprthred.h"
#else
#include "private/pprthred.h"
#endif
#include "gcint.h"
/*
** Generic GC implementation independent code for the NSPR GC
*/
RootFinder *_pr_rootFinders;
CollectorType *_pr_collectorTypes;
/* GC State information */
GCInfo _pr_gcData;
GCBeginGCHook *_pr_beginGCHook;
void *_pr_beginGCHookArg;
GCBeginGCHook *_pr_endGCHook;
void *_pr_endGCHookArg;
GCBeginFinalizeHook *_pr_beginFinalizeHook;
void *_pr_beginFinalizeHookArg;
GCBeginFinalizeHook *_pr_endFinalizeHook;
void *_pr_endFinalizeHookArg;
FILE *_pr_dump_file;
int _pr_do_a_dump;
GCLockHook *_pr_GCLockHook;
extern PRLogModuleInfo *_pr_msgc_lm;
/************************************************************************/
static PRStatus PR_CALLBACK
pr_ScanOneThread(PRThread* t, void** addr, PRUword count, void* closure)
{
#if defined(XP_MAC)
#pragma unused (t, closure)
#endif
_pr_gcData.processRootBlock(addr, count);
return PR_SUCCESS;
}
/*
** Scan all of the threads C stack's and registers, looking for "root"
** pointers into the GC heap. These are the objects that the GC cannot
** move and are considered "live" by the GC. Caller has stopped all of
** the threads from running.
*/
static void PR_CALLBACK ScanThreads(void *arg)
{
PR_ScanStackPointers(pr_ScanOneThread, arg);
}
/************************************************************************/
PR_IMPLEMENT(GCInfo *) PR_GetGCInfo(void)
{
return &_pr_gcData;
}
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;
}
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;
}
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(void) PR_SetGCLockHook(GCLockHook *hook, void *arg)
{
LOCK_GC();
_pr_GCLockHook = hook;
_pr_GCLockHookArg2 = arg;
UNLOCK_GC();
}
PR_IMPLEMENT(void) PR_GetGCLockHook(GCLockHook **hook, void **arg)
{
LOCK_GC();
*hook = _pr_GCLockHook;
*arg = _pr_GCLockHookArg2;
UNLOCK_GC();
}
*/
PR_IMPLEMENT(void) PR_SetBeginGCHook(GCBeginGCHook *hook, void *arg)
{
LOCK_GC();
_pr_beginGCHook = hook;
_pr_beginGCHookArg = arg;
UNLOCK_GC();
}
PR_IMPLEMENT(void) PR_GetBeginGCHook(GCBeginGCHook **hook, void **arg)
{
LOCK_GC();
*hook = _pr_beginGCHook;
*arg = _pr_beginGCHookArg;
UNLOCK_GC();
}
PR_IMPLEMENT(void) PR_SetEndGCHook(GCEndGCHook *hook, void *arg)
{
LOCK_GC();
_pr_endGCHook = hook;
_pr_endGCHookArg = arg;
UNLOCK_GC();
}
PR_IMPLEMENT(void) PR_GetEndGCHook(GCEndGCHook **hook, void **arg)
{
LOCK_GC();
*hook = _pr_endGCHook;
*arg = _pr_endGCHookArg;
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_GetBeginFinalizeHook(GCBeginFinalizeHook **hook,
void **arg)
{
LOCK_GC();
*hook = _pr_beginFinalizeHook;
*arg = _pr_beginFinalizeHookArg;
UNLOCK_GC();
}
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();
}
#ifdef DEBUG
#include "prprf.h"
#if defined(WIN16)
static FILE *tracefile = 0;
#endif
PR_IMPLEMENT(void) GCTrace(char *fmt, ...)
{
va_list ap;
char buf[400];
va_start(ap, fmt);
PR_vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
#if defined(WIN16)
if ( tracefile == 0 )
{
tracefile = fopen( "xxxGCtr", "w" );
}
fprintf(tracefile, "%s\n", buf );
fflush(tracefile);
#else
PR_LOG(_pr_msgc_lm, PR_LOG_ALWAYS, ("%s", buf));
#endif
}
#endif
void _PR_InitGC(PRWord flags)
{
static char firstTime = 1;
if (!firstTime) return;
firstTime = 0;
_MD_InitGC();
if (flags == 0) {
char *ev = PR_GetEnv("GCLOG");
if (ev && ev[0]) {
flags = atoi(ev);
}
}
_pr_gcData.flags = flags;
_pr_gcData.lock = PR_NewMonitor();
_pr_collectorTypes = (CollectorType*) PR_CALLOC(256 * sizeof(CollectorType));
PR_RegisterRootFinder(ScanThreads, "scan threads", 0);
PR_RegisterRootFinder(_PR_ScanFinalQueue, "scan final queue", 0);
}
extern void pr_FinalizeOnExit(void);
#ifdef DEBUG
#ifdef GC_STATS
PR_PUBLIC_API(void) PR_PrintGCAllocStats(void);
#endif
#endif
PR_IMPLEMENT(void)
PR_ShutdownGC(PRBool finalizeOnExit)
{
/* first finalize all the objects in the heap */
if (finalizeOnExit) {
pr_FinalizeOnExit();
}
#ifdef DEBUG
#ifdef GC_STATS
PR_PrintGCAllocStats();
#endif /* GC_STATS */
#endif /* DEBUG */
/* then the chance for any future allocations */
/* finally delete the gc heap */
/* write me */
}
/******************************************************************************/

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,155 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Netscape Portable Runtime (NSPR).
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998-2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "prlock.h"
#include "prlog.h"
#include "prmem.h"
#include "gcint.h"
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#define _PR_GC_VMBASE 0x40000000
#if defined(SOLARIS)
#define _MD_MMAP_FLAGS MAP_SHARED
#elif defined(RELIANTUNIX)
#define _MD_MMAP_FLAGS MAP_PRIVATE|MAP_FIXED
#else
#define _MD_MMAP_FLAGS MAP_PRIVATE
#endif
static PRInt32 zero_fd = -1;
static PRLock *zero_fd_lock = NULL;
void _MD_InitGC(void)
{
#ifdef DEBUG
/*
* Disable using mmap(2) if NSPR_NO_MMAP is set
*/
if (getenv("NSPR_NO_MMAP")) {
zero_fd = -2;
return;
}
#endif
zero_fd = open("/dev/zero",O_RDWR , 0);
zero_fd_lock = PR_NewLock();
}
/* This static variable is used by _MD_GrowGCHeap and _MD_ExtendGCHeap */
static void *lastaddr = (void*) _PR_GC_VMBASE;
void *_MD_GrowGCHeap(PRUint32 *sizep)
{
void *addr;
PRUint32 size;
size = *sizep;
PR_Lock(zero_fd_lock);
if (zero_fd < 0) {
goto mmap_loses;
}
/* Extend the mapping */
addr = mmap(lastaddr, size, PROT_READ|PROT_WRITE|PROT_EXEC,
_MD_MMAP_FLAGS,
zero_fd, 0);
if (addr == (void*)-1) {
zero_fd = -1;
goto mmap_loses;
}
lastaddr = ((char*)addr + size);
#ifdef DEBUG
PR_LOG(_pr_msgc_lm, PR_LOG_WARNING,
("GC: heap extends from %08x to %08x\n",
_PR_GC_VMBASE,
_PR_GC_VMBASE + (char*)lastaddr - (char*)_PR_GC_VMBASE));
#endif
PR_Unlock(zero_fd_lock);
return addr;
mmap_loses:
PR_Unlock(zero_fd_lock);
return PR_MALLOC(size);
}
/* XXX - This is disabled. MAP_FIXED just does not work. */
#if 0
PRBool _MD_ExtendGCHeap(char *base, PRInt32 oldSize, PRInt32 newSize) {
PRBool rv = PR_FALSE;
void* addr;
PRInt32 allocSize = newSize - oldSize;
PR_Lock(zero_fd_lock);
addr = mmap(base + oldSize, allocSize, PROT_READ|PROT_WRITE|PROT_EXEC,
_MD_MMAP_FLAGS | MAP_FIXED, zero_fd, 0);
if (addr == (void*)-1) {
goto loser;
}
if (addr != (void*) (base + oldSize)) {
munmap(base + oldSize, allocSize);
goto loser;
}
lastaddr = ((char*)base + newSize);
PR_LOG(_pr_msgc_lm, PR_LOG_ALWAYS,
("GC: heap now extends from %p to %p",
base, base + newSize));
rv = PR_TRUE;
loser:
PR_Unlock(zero_fd_lock);
return rv;
}
#else
PRBool _MD_ExtendGCHeap(char *base, PRInt32 oldSize, PRInt32 newSize) {
return PR_FALSE;
}
#endif
void _MD_FreeGCSegment(void *base, PRInt32 len)
{
if (zero_fd < 0) {
PR_DELETE(base);
} else {
(void) munmap(base, len);
}
}

View File

@@ -0,0 +1,77 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Netscape Portable Runtime (NSPR).
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998-2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#if defined(WIN16)
#include <windows.h>
#endif
#include "prtypes.h"
#include <stdlib.h>
#define MAX_SEGMENT_SIZE (65536l - 4096l)
/************************************************************************/
/*
** Machine dependent GC Heap management routines:
** _MD_GrowGCHeap
*/
/************************************************************************/
void _MD_InitGC(void) {}
extern void *
_MD_GrowGCHeap(PRUint32 *sizep)
{
void *addr;
if( *sizep > MAX_SEGMENT_SIZE ) {
*sizep = MAX_SEGMENT_SIZE;
}
addr = malloc((size_t)*sizep);
return addr;
}
HINSTANCE _pr_hInstance;
int CALLBACK LibMain( HINSTANCE hInst, WORD wDataSeg,
WORD cbHeapSize, LPSTR lpszCmdLine )
{
_pr_hInstance = hInst;
return TRUE;
}

View File

@@ -0,0 +1,129 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Netscape Portable Runtime (NSPR).
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998-2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* GC related routines
*
*/
#include <windows.h>
#include "prlog.h"
extern PRLogModuleInfo* _pr_msgc_lm;
#define GC_VMBASE 0x40000000
#define GC_VMLIMIT 0x00FFFFFF
/************************************************************************/
/*
** Machine dependent GC Heap management routines:
** _MD_GrowGCHeap
*/
/************************************************************************/
void *baseaddr = (void*) GC_VMBASE;
void *lastaddr = (void*) GC_VMBASE;
void _MD_InitGC() {}
void *_MD_GrowGCHeap(PRUint32 *sizep)
{
void *addr;
size_t size;
/* Reserve a block of memory for the GC */
if( lastaddr == baseaddr ) {
addr = VirtualAlloc( (void *)GC_VMBASE, GC_VMLIMIT, MEM_RESERVE, PAGE_READWRITE );
/*
** If the GC_VMBASE address is already mapped, then let the OS choose a
** base address that is available...
*/
if (addr == NULL) {
addr = VirtualAlloc( NULL, GC_VMLIMIT, MEM_RESERVE, PAGE_READWRITE );
baseaddr = lastaddr = addr;
if (addr == NULL) {
PR_LOG(_pr_msgc_lm, PR_LOG_ALWAYS, ("GC: unable to allocate heap: LastError=%ld",
GetLastError()));
return 0;
}
}
}
size = *sizep;
/* Extend the mapping */
addr = VirtualAlloc( lastaddr, size, MEM_COMMIT, PAGE_READWRITE );
if (addr == NULL) {
return 0;
}
lastaddr = ((char*)addr + size);
PR_LOG(_pr_msgc_lm, PR_LOG_ALWAYS,
("GC: heap extends from %08x to %08x",
baseaddr, (long)baseaddr + (char*)lastaddr - (char*)baseaddr));
return addr;
}
PRBool _MD_ExtendGCHeap(char *base, PRInt32 oldSize, PRInt32 newSize) {
void* addr;
addr = VirtualAlloc( base + oldSize, newSize - oldSize,
MEM_COMMIT, PAGE_READWRITE );
if (NULL == addr) {
PR_LOG(_pr_msgc_lm, PR_LOG_ALWAYS, ("GC: unable to extend heap: LastError=%ld",
GetLastError()));
return PR_FALSE;
}
if (base + oldSize != (char*)addr) {
PR_LOG(_pr_msgc_lm, PR_LOG_ALWAYS, ("GC: segment extension returned %x instead of %x",
addr, base + oldSize));
VirtualFree(addr, newSize - oldSize, MEM_DECOMMIT);
return PR_FALSE;
}
lastaddr = base + newSize;
PR_LOG(_pr_msgc_lm, PR_LOG_ALWAYS,
("GC: heap now extends from %p to %p",
base, base + newSize));
return PR_TRUE;
}
void _MD_FreeGCSegment(void *base, PRInt32 len)
{
(void)VirtualFree(base, 0, MEM_RELEASE);
}

View File

@@ -0,0 +1 @@
Makefile

View File

@@ -0,0 +1,5 @@
/.cvsignore/1.2/Sat May 12 06:26:43 2001//
/Makefile.in/1.13/Wed Nov 23 06:35:19 2005//
/gc1.c/3.6/Sun Apr 25 15:00:45 2004//
/thrashgc.c/3.5/Sun Apr 25 15:00:45 2004//
D

View File

@@ -0,0 +1 @@
mozilla/nsprpub/lib/msgc/tests

View File

@@ -0,0 +1 @@
:pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot

View File

@@ -0,0 +1,314 @@
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is the Netscape Portable Runtime (NSPR).
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998-2000
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
#! gmake
MOD_DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(MOD_DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
ifeq ($(OS_TARGET), WIN16)
OS_CFLAGS = $(OS_EXE_CFLAGS)
W16STDIO = $(MOD_DEPTH)/pr/src/md/windows/$(OBJDIR)/w16stdio.$(OBJ_SUFFIX)
endif
ifeq ($(OS_TARGET), OS2)
OS_CFLAGS = $(OS_EXE_CFLAGS)
endif
CSRCS = gc1.c thrashgc.c
ifeq (,$(filter-out WINNT OS2,$(OS_ARCH)))
PROG_SUFFIX = .exe
else
PROG_SUFFIX =
endif
PROGS = $(addprefix $(OBJDIR)/, $(CSRCS:.c=$(PROG_SUFFIX)))
TARGETS = $(PROGS) $(OBJS)
INCLUDES = -I$(dist_includedir)
# Setting the variables LDOPTS and LIBPR. We first initialize
# them to the default values, then adjust them for some platforms.
LDOPTS = -L$(dist_libdir)
NSPR_VERSION = $(MOD_MAJOR_VERSION)
GC_VERSION = $(MOD_MAJOR_VERSION)
LIBPR = -lnspr$(NSPR_VERSION)
LIBPLC = -lplc$(NSPR_VERSION)
LIBGC = -lmsgc$(GC_VERSION)
ifeq ($(OS_ARCH), WINNT)
ifeq ($(OS_TARGET), WIN16)
LIBPR = $(dist_libdir)/nspr$(NSPR_VERSION).lib
LIBPLC = $(dist_libdir)/plc$(NSPR_VERSION).lib
LIBGC= $(dist_libdir)/msgc$(GC_VERSION).lib
else
LDOPTS = -NOLOGO -DEBUG -INCREMENTAL:NO
LIBPR = $(dist_libdir)/libnspr$(NSPR_VERSION).$(LIB_SUFFIX)
LIBPLC = $(dist_libdir)/libplc$(NSPR_VERSION).$(LIB_SUFFIX)
LIBGC= $(dist_libdir)/libmsgc$(GC_VERSION).$(LIB_SUFFIX)
endif
endif
ifeq ($(OS_ARCH),OS2)
ifeq ($(MOZ_OS2_TOOLS),VACPP)
LDOPTS = -NOE -DEBUG -nologo -PMTYPE:VIO
LIBPR = $(dist_libdir)/nspr$(NSPR_VERSION).lib
LIBPLC = $(dist_libdir)/plc$(NSPR_VERSION).lib
LIBGC= $(dist_libdir)/msgc$(GC_VERSION).lib
else
LDOPTS += -Zomf -Zlinker /PM:VIO
endif
endif
ifneq ($(OS_ARCH), WINNT)
PWD = $(shell pwd)
endif
ifeq ($(OS_ARCH), IRIX)
LDOPTS += -rpath $(PWD)/$(dist_libdir) -rdata_shared
# For 6.x machines, include this flag
ifeq ($(basename $(OS_RELEASE)),6)
ifeq ($(USE_N32),1)
LDOPTS += -n32
else
LDOPTS += -32
endif
endif
endif
ifeq ($(OS_ARCH), OSF1)
# I haven't figured out how to pass -rpath to cc on OSF1 V3.2, so
# we do static linking.
ifeq ($(OS_RELEASE), V3.2)
LIBPR = $(dist_libdir)/libnspr$(NSPR_VERSION).a
LIBPLC = $(dist_libdir)/libplc$(NSPR_VERSION).a
LIBGC = $(dist_libdir)/libmsgc$(GC_VERSION).a
EXTRA_LIBS = -lc_r
else
LDOPTS += -rpath $(PWD)/$(dist_libdir)
endif
endif
ifeq ($(OS_ARCH), HP-UX)
LDOPTS += -z -Wl,+s,+b,$(PWD)/$(dist_libdir)
endif
# AIX
ifeq ($(OS_ARCH),AIX)
LDOPTS += -blibpath:$(PWD)/$(dist_libdir):/usr/lib:/lib
ifeq ($(OS_ARCH)$(OS_RELEASE),AIX4.1)
LIBPR = -lnspr$(NSPR_VERSION)_shr
LIBPLC = -lplc$(NSPR_VERSION)_shr
LIBGC = -lmsgc$(GC_VERSION)_shr
else
LDOPTS += -brtl
EXTRA_LIBS = -ldl
endif
endif
# Solaris
ifeq ($(OS_ARCH), SunOS)
ifneq ($(OS_RELEASE), 4.1.3_U1)
ifdef NS_USE_GCC
LDOPTS += -Xlinker -R -Xlinker $(PWD)/$(dist_libdir)
else
LDOPTS += -R $(PWD)/$(dist_libdir)
endif
endif
ifneq ($(LOCAL_THREADS_ONLY),1)
# SunOS 5.4 and 5.5 need to link with -lthread or -lpthread,
# even though we already linked with these system libraries
# when we built libnspr.so.
ifeq ($(OS_RELEASE), 5.4)
EXTRA_LIBS = -lthread
endif
ifeq ($(OS_RELEASE), 5.5)
ifdef USE_PTHREADS
EXTRA_LIBS = -lpthread
else
EXTRA_LIBS = -lthread
endif
endif
endif # LOCAL_THREADS_ONLY
endif # SunOS
ifeq ($(OS_ARCH),NEC)
EXTRA_LIBS = $(OS_LIBS)
# This hardcodes in the executable programs the directory to find
# libnspr.so etc. at program startup. Equivalent to the -R or -rpath
# option for ld on other platforms.
export LD_RUN_PATH = $(PWD)/$(dist_libdir)
endif
ifeq ($(OS_ARCH), NCR)
# XXX: We see some strange problems when we link with libnspr.so.
# So for now we use static libraries on NCR. The shared library
# stuff below is commented out.
LIBPR = $(dist_libdir)/libnspr$(NSPR_VERSION).a
LIBPLC = $(dist_libdir)/libplc$(NSPR_VERSION).a
LIBGC = $(dist_libdir)/libmsgc$(GC_VERSION).a
EXTRA_LIBS = -lsocket -lnsl -ldl
# NCR needs to link against -lsocket -lnsl (and -lc, which is linked
# implicitly by $(CC)) again even though we already linked with these
# system libraries when we built libnspr.so.
#EXTRA_LIBS = -lsocket -lnsl
# This hardcodes in the executable programs the directory to find
# libnspr.so etc. at program startup. Equivalent to the -R or -rpath
# option for ld on other platforms.
#export LD_RUN_PATH = $(PWD)/$(dist_libdir)
endif
ifeq ($(OS_ARCH), Linux)
ifeq ($(OS_RELEASE), 1.2)
EXTRA_LIBS = -ldl
endif
endif
ifeq ($(OS_ARCH), SCOOS)
# SCO Unix needs to link against -lsocket again even though we
# already linked with these system libraries when we built libnspr.so.
EXTRA_LIBS = -lsocket
# This hardcodes in the executable programs the directory to find
# libnspr.so etc. at program startup. Equivalent to the -R or -rpath
# option for ld on other platforms.
export LD_RUN_PATH = $(PWD)/$(dist_libdir)
endif
ifeq ($(OS_ARCH),SINIX)
EXTRA_LIBS = -lsocket -lnsl -lresolv -ldl
# This hardcodes in the executable programs the directory to find
# libnspr.so etc. at program startup. Equivalent to the -R or -rpath
# option for ld on other platforms.
export LD_RUN_PATH = $(PWD)/$(dist_libdir)
endif
ifeq ($(OS_ARCH), UNIXWARE)
export LD_RUN_PATH = $(PWD)/$(dist_libdir)
endif
ifeq ($(OS_ARCH),BSD_OS)
EXTRA_LIBS = -ldl
endif
ifeq ($(OS_ARCH),DGUX)
EXTRA_LIBS = -lsocket -lnsl -ldl
endif
#####################################################
#
# The rules
#
#####################################################
include $(topsrcdir)/config/rules.mk
AIX_PRE_4_2 = 0
ifeq ($(OS_ARCH),AIX)
ifneq ($(OS_RELEASE),4.2)
ifneq ($(USE_PTHREADS), 1)
#AIX_PRE_4_2 = 1
endif
endif
endif
ifeq ($(AIX_PRE_4_2),1)
# AIX releases prior to 4.2 need a special two-step linking hack
# in order to both override the system select() and be able to
# get at the original system select().
#
# We use a pattern rule in ns/nspr20/config/rules.mk to generate
# the .$(OBJ_SUFFIX) file from the .c source file, then do the
# two-step linking hack below.
$(OBJDIR)/%: $(OBJDIR)/%.$(OBJ_SUFFIX)
@$(MAKE_OBJDIR)
rm -f $@ $(AIX_TMP)
$(CC) $(AIX_LINK_OPTS) -o $(AIX_TMP) $< $(dist_libdir)/libnspr$(NSPR_VERSION).a
$(CC) -o $@ $(AIX_TMP) $(AIX_WRAP)
rm -f $(AIX_TMP)
else
# All platforms that are not AIX pre-4.2.
$(OBJDIR)/%$(PROG_SUFFIX): $(OBJDIR)/%.$(OBJ_SUFFIX)
@$(MAKE_OBJDIR)
ifeq ($(OS_ARCH), WINNT)
ifeq ($(OS_TARGET),WIN16)
echo system windows >w16link
echo name $@ >>w16link
echo option map >>w16link
# echo option CASEEXACT >>w16link
echo option stack=16K >>w16link
echo debug $(DEBUGTYPE) all >>w16link
echo file >>w16link
echo $< , >>w16link
echo $(W16STDIO) >>w16link
echo library >>w16link
echo $(LIBPR), >>w16link
echo $(LIBPLC), >>w16link
echo $(LIBGC), >>w16link
echo winsock.lib >>w16link
wlink @w16link.
else
link $(LDOPTS) $< $(LIBGC) $(LIBPLC) $(LIBPR) wsock32.lib -out:$@
else
ifeq ($(OS_ARCH),OS2)
$(LINK) $(LDOPTS) $< $(LIBGC) $(LIBPLC) $(LIBPR) $(OS_LIBS) $(EXTRA_LIBS) -o $@
else
$(CC) $(XCFLAGS) $< $(LDOPTS) $(LIBGC) $(LIBPLC) $(LIBPR) $(EXTRA_LIBS) -o $@
endif
endif
endif
export:: $(TARGETS)
clean::
rm -f $(TARGETS)

View File

@@ -0,0 +1,257 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Netscape Portable Runtime (NSPR).
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998-2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/***********************************************************************
** Includes
***********************************************************************/
/* Used to get the command line option */
#include "plgetopt.h"
#include "prgc.h"
#include "prinit.h"
#include "prmon.h"
#include "prinrval.h"
#ifndef XP_MAC
#include "private/pprthred.h"
#else
#include "pprthred.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#ifdef XP_MAC
#include "prlog.h"
#define printf PR_LogPrint
extern void SetupMacPrintfLog(char *logFile);
#endif
static PRMonitor *mon;
static PRInt32 threads, waiting, iterations;
static PRInt32 scanCount, finalizeCount, freeCount;
PRIntn failed_already=0;
PRIntn debug_mode;
typedef struct Array {
PRUintn size;
void *body[1];
} Array;
int arrayTypeIndex;
static void PR_CALLBACK ScanArray(void *a)
{
/* printf ("In ScanArray a = %X size = %d \n", a, a->size); */
scanCount++;
}
static void PR_CALLBACK FinalizeArray(void *a)
{
/* printf ("In FinalizeArray a = %X size = %d \n", a, a->size); */
finalizeCount++;
}
static void PR_CALLBACK FreeArray(void *a)
{
/* printf ("In FreeArray\n"); */
freeCount++;
}
static Array *NewArray(PRUintn size)
{
Array *a;
a = (Array *)PR_AllocMemory(sizeof(Array) + size*sizeof(void*) - 1*sizeof(void*),
arrayTypeIndex, PR_ALLOC_CLEAN);
/* printf ("In NewArray a = %X \n", a); */
if (a)
a->size = size;
return a;
}
GCType arrayType = {
ScanArray,
FinalizeArray,
0,
0,
FreeArray,
0
};
static void Initialize(void)
{
PR_InitGC(0, 0, 0, PR_GLOBAL_THREAD);
arrayTypeIndex = PR_RegisterType(&arrayType);
}
static void PR_CALLBACK AllocateLikeMad(void *arg)
{
Array *prev;
PRInt32 i;
PRInt32 count;
count = (PRInt32)arg;
prev = 0;
for (i = 0; i < count; i++) {
Array *leak = NewArray(i & 511);
if ((i & 1023) == 0) {
prev = 0; /* forget */
} else {
if (i & 1) {
prev = leak; /* remember */
}
}
}
PR_EnterMonitor(mon);
waiting++;
PR_Notify(mon);
PR_ExitMonitor(mon);
}
int main(int argc, char **argv)
{
PRIntervalTime start, stop, usec;
double d;
PRIntn i, totalIterations;
/* The command line argument: -d is used to determine if the test is being run
in debug mode. The regress tool requires only one line output:PASS or FAIL.
All of the printfs associated with this test has been handled with a if (debug_mode)
test.
Usage: test_name -d
*/
PLOptStatus os;
PLOptState *opt = PL_CreateOptState(argc, argv, "dt:c:");
threads = 10;
iterations = 100;
while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
{
if (PL_OPT_BAD == os) {
fprintf(stderr, "Invalid command-line option\n");
exit(1);
}
switch (opt->option)
{
case 'd': /* debug mode */
debug_mode = 1;
break;
case 't': /* number of threads */
threads = atoi(opt->value);
break;
case 'c': /* iteration count */
iterations = atoi(opt->value);
break;
default:
break;
}
}
PL_DestroyOptState(opt);
fprintf(stderr, "t is %ld, i is %ld\n", (long) threads, (long) iterations);
/* main test */
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 5);
PR_STDIO_INIT();
Initialize();
#ifdef XP_MAC
SetupMacPrintfLog("gc1.log");
debug_mode = 1;
#endif
/* Spin all of the allocator threads and then wait for them to exit */
start = PR_IntervalNow();
mon = PR_NewMonitor();
PR_EnterMonitor(mon);
waiting = 0;
for (i = 0; i < threads; i++) {
(void) PR_CreateThreadGCAble(PR_USER_THREAD,
AllocateLikeMad, (void*)iterations,
PR_PRIORITY_NORMAL,
PR_LOCAL_THREAD,
PR_UNJOINABLE_THREAD,
0);
}
while (waiting != threads) {
PR_Wait(mon, PR_INTERVAL_NO_TIMEOUT);
}
PR_ExitMonitor(mon);
PR_GC();
PR_ForceFinalize();
totalIterations = iterations * threads;
/*
if (scanCount != totalIterations)
printf ("scanCount discrepancy scanCount = %d totalIterations = %d \n",
scanCount, totalIterations);
if (freeCount != totalIterations)
printf ("freeCount discrepancy freeCount = %d totalIterations = %d \n",
freeCount, totalIterations);
if ((finalizeCount != totalIterations) && (finalizeCount != (totalIterations-1)))
printf ("finalizeCount discrepancy finalizeCount = %d totalIterations = %d \n",
finalizeCount,totalIterations);
*/
stop = PR_IntervalNow();
usec = stop = stop - start;
d = (double)usec;
if (debug_mode) printf("%40s: %6.2f usec\n", "GC allocation", d / (iterations * threads));
else {
if (d == 0.0) failed_already = PR_TRUE;
}
PR_Cleanup();
if(failed_already)
{
printf("FAIL\n");
return 1;
}
else
{
printf("PASS\n");
return 0;
}
}

View File

@@ -0,0 +1,274 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Netscape Portable Runtime (NSPR).
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998-2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/***********************************************************************
** Name: thrashgc
**
** Description: test garbace collection functions.
**
** Modification History:
** 19-May-97 AGarcia- Converted the test to accomodate the debug_mode flag.
** The debug mode will print all of the printfs associated with this test.
** The regress mode will be the default mode. Since the regress tool limits
** the output to a one line status:PASS or FAIL,all of the printf statements
** have been handled with an if (debug_mode) statement.
** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to
** recognize the return code from tha main program.
***********************************************************************/
/***********************************************************************
** Includes
***********************************************************************/
#include "prthread.h"
#include "prgc.h"
#include "prprf.h"
#include "prinrval.h"
#include "prlock.h"
#include "prinit.h"
#include "prcvar.h"
#ifndef XP_MAC
#include "private/pprthred.h"
#else
#include "pprthred.h"
#endif
#include <stdio.h>
#include <memory.h>
#include <string.h>
#ifdef XP_MAC
#include "prlog.h"
#define printf PR_LogPrint
extern void SetupMacPrintfLog(char *logFile);
#endif
PRIntn failed_already=0;
PRIntn debug_mode;
static char* progname;
static PRInt32 loops = 1000;
static int tix1, tix2, tix3;
static GCInfo* gcInfo;
static PRLock* stderrLock;
typedef struct Type1 Type1;
typedef struct Type2 Type2;
struct Type1 {
Type2* atwo;
Type1* next;
};
struct Type2 {
void* buf;
};
static void PR_CALLBACK ScanType1(void *obj) {
gcInfo->livePointer(((Type1 *)obj)->atwo);
gcInfo->livePointer(((Type1 *)obj)->next);
}
static void PR_CALLBACK ScanType2(void *obj) {
gcInfo->livePointer(((Type2 *)obj)->buf);
}
static GCType type1 = {
ScanType1
};
static GCType type2 = {
ScanType2
/* (void (*)(void*)) ScanType2 */
};
static GCType type3 = {
0
};
Type1* NewType1(void) {
Type1* p = (Type1*) PR_AllocMemory(sizeof(Type1), tix1, PR_ALLOC_DOUBLE);
PR_ASSERT(p != NULL);
return p;
}
Type2* NewType2(void) {
Type2* p = (Type2*) PR_AllocMemory(sizeof(Type2), tix2, PR_ALLOC_DOUBLE);
PR_ASSERT(p != NULL);
return p;
}
void* NewBuffer(PRInt32 size) {
void* p = PR_AllocMemory(size, tix3, PR_ALLOC_DOUBLE);
PR_ASSERT(p != NULL);
return p;
}
/* Allocate alot of garbage */
static void PR_CALLBACK AllocStuff(void *unused) {
PRInt32 i;
void* danglingRefs[50];
PRIntervalTime start, end;
char msg[100];
start = PR_IntervalNow();
for (i = 0; i < loops; i++) {
void* p;
if (i & 1) {
Type1* t1 = NewType1();
t1->atwo = NewType2();
t1->next = NewType1();
t1->atwo->buf = NewBuffer(100);
p = t1;
} else {
Type2* t2 = NewType2();
t2->buf = NewBuffer(i & 16383);
p = t2;
}
if ((i % 10) == 0) {
memmove(&danglingRefs[0], &danglingRefs[1], 49*sizeof(void*));
danglingRefs[49] = p;
}
}
end = PR_IntervalNow();
if (debug_mode) PR_snprintf(msg, sizeof(msg), "Thread %p: %ld allocations took %ld ms",
PR_GetCurrentThread(), loops,
PR_IntervalToMilliseconds((PRIntervalTime) (end - start)));
PR_Lock(stderrLock);
#ifndef XP_MAC
fprintf(stderr, "%s\n", msg);
#else
if (debug_mode) printf("%s\n", msg);
#endif
PR_Unlock(stderrLock);
}
static void usage(char *progname) {
#ifndef XP_MAC
fprintf(stderr, "Usage: %s [-t threads] [-l loops]\n", progname);
#else
printf("Usage: %s [-t threads] [-l loops]\n", progname);
#endif
exit(-1);
}
static int realMain(int argc, char **argv, char *notused) {
int i;
int threads = 0;
#ifndef XP_MAC
progname = strrchr(argv[0], '/');
if (progname == 0) progname = argv[0];
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-t") == 0) {
if (i == argc - 1) {
usage(progname);
}
threads = atoi(argv[++i]);
if (threads < 0) threads = 0;
if (threads > 10000) threads = 10000;
continue;
}
if (strcmp(argv[i], "-l") == 0) {
if (i == argc - 1) {
usage(progname);
}
loops = atoi(argv[++i]);
continue;
}
usage(progname);
}
#else
threads = 50;
#endif
for (i = 0; i < threads; i++) {
PRThread* thread;
/* XXXXX */
thread = PR_CreateThreadGCAble(PR_USER_THREAD, /* thread type */
AllocStuff, /* start function */
NULL, /* arg */
PR_PRIORITY_NORMAL, /* priority */
PR_LOCAL_THREAD, /* thread scope */
PR_UNJOINABLE_THREAD, /* thread state */
0); /* stack size */
if (thread == 0) {
#ifndef XP_MAC
fprintf(stderr, "%s: no more threads (only %d were created)\n",
progname, i);
#else
printf("%s: no more threads (only %d were created)\n",
progname, i);
#endif
break;
}
}
AllocStuff(NULL);
return 0;
}
static int padMain(int argc, char **argv) {
char pad[512];
return realMain(argc, argv, pad);
}
int main(int argc, char **argv) {
int rv;
debug_mode = 1;
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
PR_SetThreadGCAble();
#ifdef XP_MAC
SetupMacPrintfLog("thrashgc.log");
debug_mode = 1;
#endif
PR_InitGC(0, 0, 0, PR_GLOBAL_THREAD);
PR_STDIO_INIT();
stderrLock = PR_NewLock();
tix1 = PR_RegisterType(&type1);
tix2 = PR_RegisterType(&type2);
tix3 = PR_RegisterType(&type3);
gcInfo = PR_GetGCInfo();
rv = padMain(argc, argv);
printf("PASS\n");
PR_Cleanup();
return rv;
}