1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Mozilla Public License Version
6
* 1.1 (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/MPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is the Netscape Portable Runtime (NSPR).
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1998-2000
20
* the Initial Developer. All Rights Reserved.
24
* Alternatively, the contents of this file may be used under the terms of
25
* either the GNU General Public License Version 2 or later (the "GPL"), or
26
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
* in which case the provisions of the GPL or the LGPL are applicable instead
28
* of those above. If you wish to allow use of your version of this file only
29
* under the terms of either the GPL or the LGPL, and not to allow others to
30
* use your version of this file under the terms of the MPL, indicate your
31
* decision by deleting the provisions above and replace them with the notice
32
* and other provisions required by the GPL or the LGPL. If you do not delete
33
* the provisions above, a recipient may use your version of this file under
34
* the terms of any one of the MPL, the GPL or the LGPL.
36
* ***** END LICENSE BLOCK ***** */
38
/***********************************************************************
40
***********************************************************************/
41
/* Used to get the command line option */
48
#include "private/pprthred.h"
53
static PRMonitor *mon;
54
static PRInt32 threads, waiting, iterations;
55
static PRInt32 scanCount, finalizeCount, freeCount;
57
PRIntn failed_already=0;
61
typedef struct Array {
68
static void PR_CALLBACK ScanArray(void *a)
70
/* printf ("In ScanArray a = %X size = %d \n", a, a->size); */
74
static void PR_CALLBACK FinalizeArray(void *a)
76
/* printf ("In FinalizeArray a = %X size = %d \n", a, a->size); */
80
static void PR_CALLBACK FreeArray(void *a)
82
/* printf ("In FreeArray\n"); */
86
static Array *NewArray(PRUintn size)
90
a = (Array *)PR_AllocMemory(sizeof(Array) + size*sizeof(void*) - 1*sizeof(void*),
91
arrayTypeIndex, PR_ALLOC_CLEAN);
93
/* printf ("In NewArray a = %X \n", a); */
109
static void Initialize(void)
111
PR_InitGC(0, 0, 0, PR_GLOBAL_THREAD);
112
arrayTypeIndex = PR_RegisterType(&arrayType);
115
static void PR_CALLBACK AllocateLikeMad(void *arg)
121
count = (PRInt32)arg;
123
for (i = 0; i < count; i++) {
124
Array *leak = NewArray(i & 511);
125
if ((i & 1023) == 0) {
126
prev = 0; /* forget */
129
prev = leak; /* remember */
133
PR_EnterMonitor(mon);
139
int main(int argc, char **argv)
141
PRIntervalTime start, stop, usec;
143
PRIntn i, totalIterations;
144
/* The command line argument: -d is used to determine if the test is being run
145
in debug mode. The regress tool requires only one line output:PASS or FAIL.
146
All of the printfs associated with this test has been handled with a if (debug_mode)
151
PLOptState *opt = PL_CreateOptState(argc, argv, "dt:c:");
156
while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
158
if (PL_OPT_BAD == os) {
159
fprintf(stderr, "Invalid command-line option\n");
164
case 'd': /* debug mode */
167
case 't': /* number of threads */
168
threads = atoi(opt->value);
170
case 'c': /* iteration count */
171
iterations = atoi(opt->value);
177
PL_DestroyOptState(opt);
179
fprintf(stderr, "t is %ld, i is %ld\n", (long) threads, (long) iterations);
182
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 5);
186
/* Spin all of the allocator threads and then wait for them to exit */
187
start = PR_IntervalNow();
188
mon = PR_NewMonitor();
189
PR_EnterMonitor(mon);
191
for (i = 0; i < threads; i++) {
192
(void) PR_CreateThreadGCAble(PR_USER_THREAD,
193
AllocateLikeMad, (void*)iterations,
196
PR_UNJOINABLE_THREAD,
199
while (waiting != threads) {
200
PR_Wait(mon, PR_INTERVAL_NO_TIMEOUT);
207
totalIterations = iterations * threads;
209
if (scanCount != totalIterations)
210
printf ("scanCount discrepancy scanCount = %d totalIterations = %d \n",
211
scanCount, totalIterations);
212
if (freeCount != totalIterations)
213
printf ("freeCount discrepancy freeCount = %d totalIterations = %d \n",
214
freeCount, totalIterations);
215
if ((finalizeCount != totalIterations) && (finalizeCount != (totalIterations-1)))
216
printf ("finalizeCount discrepancy finalizeCount = %d totalIterations = %d \n",
217
finalizeCount,totalIterations);
220
stop = PR_IntervalNow();
222
usec = stop = stop - start;
225
if (debug_mode) printf("%40s: %6.2f usec\n", "GC allocation", d / (iterations * threads));
227
if (d == 0.0) failed_already = PR_TRUE;