1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
3
* The contents of this file are subject to the Mozilla Public
4
* License Version 1.1 (the "License"); you may not use this file
5
* except in compliance with the License. You may obtain a copy of
6
* the License at http://www.mozilla.org/MPL/
8
* Software distributed under the License is distributed on an "AS
9
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10
* implied. See the License for the specific language governing
11
* rights and limitations under the License.
13
* The Original Code is the Netscape Portable Runtime (NSPR).
15
* The Initial Developer of the Original Code is Netscape
16
* Communications Corporation. Portions created by Netscape are
17
* Copyright (C) 1998-2000 Netscape Communications Corporation. All
22
* Alternatively, the contents of this file may be used under the
23
* terms of the GNU General Public License Version 2 or later (the
24
* "GPL"), in which case the provisions of the GPL are applicable
25
* instead of those above. If you wish to allow use of your
26
* version of this file only under the terms of the GPL and not to
27
* allow others to use your version of this file under the MPL,
28
* indicate your decision by deleting the provisions above and
29
* replace them with the notice and other provisions required by
30
* the GPL. If you do not delete the provisions above, a recipient
31
* may use your version of this file under either the MPL or the
35
/***********************************************************************
37
***********************************************************************/
38
/* Used to get the command line option */
46
#include "private/pprthred.h"
56
#define printf PR_LogPrint
57
extern void SetupMacPrintfLog(char *logFile);
60
static PRMonitor *mon;
61
static PRInt32 threads, waiting, iterations;
62
static PRInt32 scanCount, finalizeCount, freeCount;
64
PRIntn failed_already=0;
68
typedef struct Array {
75
static void PR_CALLBACK ScanArray(void *a)
77
/* printf ("In ScanArray a = %X size = %d \n", a, a->size); */
81
static void PR_CALLBACK FinalizeArray(void *a)
83
/* printf ("In FinalizeArray a = %X size = %d \n", a, a->size); */
87
static void PR_CALLBACK FreeArray(void *a)
89
/* printf ("In FreeArray\n"); */
93
static Array *NewArray(PRUintn size)
97
a = (Array *)PR_AllocMemory(sizeof(Array) + size*sizeof(void*) - 1*sizeof(void*),
98
arrayTypeIndex, PR_ALLOC_CLEAN);
100
/* printf ("In NewArray a = %X \n", a); */
116
static void Initialize(void)
118
PR_InitGC(0, 0, 0, PR_GLOBAL_THREAD);
119
arrayTypeIndex = PR_RegisterType(&arrayType);
122
static void PR_CALLBACK AllocateLikeMad(void *arg)
128
count = (PRInt32)arg;
130
for (i = 0; i < count; i++) {
131
Array *leak = NewArray(i & 511);
132
if ((i & 1023) == 0) {
133
prev = 0; /* forget */
136
prev = leak; /* remember */
140
PR_EnterMonitor(mon);
146
int main(int argc, char **argv)
148
PRIntervalTime start, stop, usec;
150
PRIntn i, totalIterations;
151
/* The command line argument: -d is used to determine if the test is being run
152
in debug mode. The regress tool requires only one line output:PASS or FAIL.
153
All of the printfs associated with this test has been handled with a if (debug_mode)
158
PLOptState *opt = PL_CreateOptState(argc, argv, "dt:c:");
163
while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
165
if (PL_OPT_BAD == os) {
166
fprintf(stderr, "Invalid command-line option\n");
171
case 'd': /* debug mode */
174
case 't': /* number of threads */
175
threads = atoi(opt->value);
177
case 'c': /* iteration count */
178
iterations = atoi(opt->value);
184
PL_DestroyOptState(opt);
186
fprintf(stderr, "t is %ld, i is %ld\n", (long) threads, (long) iterations);
189
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 5);
194
SetupMacPrintfLog("gc1.log");
198
/* Spin all of the allocator threads and then wait for them to exit */
199
start = PR_IntervalNow();
200
mon = PR_NewMonitor();
201
PR_EnterMonitor(mon);
203
for (i = 0; i < threads; i++) {
204
(void) PR_CreateThreadGCAble(PR_USER_THREAD,
205
AllocateLikeMad, (void*)iterations,
208
PR_UNJOINABLE_THREAD,
211
while (waiting != threads) {
212
PR_Wait(mon, PR_INTERVAL_NO_TIMEOUT);
219
totalIterations = iterations * threads;
221
if (scanCount != totalIterations)
222
printf ("scanCount discrepancy scanCount = %d totalIterations = %d \n",
223
scanCount, totalIterations);
224
if (freeCount != totalIterations)
225
printf ("freeCount discrepancy freeCount = %d totalIterations = %d \n",
226
freeCount, totalIterations);
227
if ((finalizeCount != totalIterations) && (finalizeCount != (totalIterations-1)))
228
printf ("finalizeCount discrepancy finalizeCount = %d totalIterations = %d \n",
229
finalizeCount,totalIterations);
232
stop = PR_IntervalNow();
234
usec = stop = stop - start;
237
if (debug_mode) printf("%40s: %6.2f usec\n", "GC allocation", d / (iterations * threads));
239
if (d == 0.0) failed_already = PR_TRUE;