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,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;
}