mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-01-28 07:50:48 -08:00
Getting dylan format working
Copied from Perforce Change: 15226 ServerID: perforce.ravenbrook.com
This commit is contained in:
parent
fa51d36541
commit
e643acfef6
1 changed files with 61 additions and 253 deletions
314
mps/src/amcss.c
314
mps/src/amcss.c
|
|
@ -1,298 +1,110 @@
|
|||
/* ==== POOL CLASS AMC TEST ====
|
||||
/* impl.c.amcss: POOL CLASS AMC STRESS TEST
|
||||
*
|
||||
* $HopeName: MMsrc!amcss.c(trunk.3) $
|
||||
*
|
||||
* Copyright (C) 1995 Harlequin Group, all rights reserved
|
||||
*
|
||||
* This is a unit stress test for the AMC pool class. It uses a simple
|
||||
* object format to do a few collections. It's a bit of a hack at the
|
||||
* moment.
|
||||
* $HopeName: MMsrc!amcss.c(trunk.4) $
|
||||
* Copyright (C) 1996 Harlequin Group, all rights reserved
|
||||
*/
|
||||
|
||||
#include "std.h"
|
||||
#include "mps.h"
|
||||
#include "lib.h"
|
||||
#include "deque.h"
|
||||
#include "space.h"
|
||||
#include "root.h"
|
||||
#include "trace.h"
|
||||
#include "format.h"
|
||||
#include "pool.h"
|
||||
#include "amc.h"
|
||||
#include "buffer.h"
|
||||
#include "prot.h"
|
||||
#include "mpscamc.h"
|
||||
#include "fmtdy.h"
|
||||
#include "testlib.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
SRCID("$HopeName$");
|
||||
|
||||
|
||||
#define NR_EXACT_ROOTS 50
|
||||
#define NR_AMBIG_ROOTS 50
|
||||
#define FIELDS_MAX 2000
|
||||
#define OBJECTS 4000
|
||||
#define OBJECT_ALIGN sizeof(mps_addr_t *)
|
||||
|
||||
#define NR_EXACT_ROOTS 50
|
||||
#define NR_AMBIG_ROOTS 50
|
||||
#define FIELDS_MAX 2000
|
||||
#define OBJECTS 4000
|
||||
#define OBJNULL ((mps_addr_t)0xDECEA5ED)
|
||||
|
||||
static mps_pool_t pool;
|
||||
static mps_ap_t buffer;
|
||||
static mps_addr_t exactRoots[NR_EXACT_ROOTS];
|
||||
static mps_addr_t ambigRoots[NR_AMBIG_ROOTS];
|
||||
static mps_word_t name = 0xA << (ADDRWIDTH-4);
|
||||
|
||||
|
||||
#define OBJHERE(object) (((object)[0] & 1uL) == 1uL)
|
||||
#define OBJHEAD(object) ((object)[0])
|
||||
#define OBJFIELDS(object) ((object)[0] >> 1)
|
||||
#define OBJFIELD(object, n) ((object)[2+(n)])
|
||||
#define OBJNAME(object) ((object)[1])
|
||||
#define OBJSUM(object) checksum(object, OBJFIELDS(object)+2)
|
||||
|
||||
|
||||
static unsigned long invrnd(unsigned long n)
|
||||
{
|
||||
return n/((rnd()%n)+1)-1;
|
||||
}
|
||||
|
||||
|
||||
static mps_word_t checksum(mps_word_t *base, mps_word_t size)
|
||||
{
|
||||
mps_word_t sum = 0xBA5E5EED;
|
||||
|
||||
while(size--)
|
||||
sum += (mps_word_t)*base++;
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
||||
static mps_bool_t probe(mps_addr_t where)
|
||||
{
|
||||
mps_word_t *object;
|
||||
mps_word_t fields, i;
|
||||
|
||||
if(PoolHasAddr((Pool)pool, (Addr)where) &&
|
||||
IsAligned(OBJECT_ALIGN, (Addr)where))
|
||||
{
|
||||
object = (mps_word_t *)where;
|
||||
if(OBJHERE(object))
|
||||
{
|
||||
fields = OBJFIELDS(object);
|
||||
if(fields <= FIELDS_MAX &&
|
||||
PoolHasAddr((Pool)pool, (Addr)&OBJFIELD(object, fields)))
|
||||
{
|
||||
for(i=0; i<fields; ++i)
|
||||
if(OBJFIELD(object, i) != 0xDECEA5ED)
|
||||
if(!PoolHasAddr((Pool)pool, OBJFIELD(object, i)))
|
||||
return FALSE;
|
||||
|
||||
if(OBJFIELD(object, i) == OBJSUM(object))
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
static mps_res_t scan(mps_ss_t ss, mps_addr_t base, mps_addr_t limit)
|
||||
{
|
||||
Error e;
|
||||
mps_word_t *object;
|
||||
mps_word_t i;
|
||||
mps_word_t fields;
|
||||
|
||||
AVER(base < limit);
|
||||
|
||||
while(base < limit)
|
||||
{
|
||||
AVER(probe(base));
|
||||
|
||||
object = (Addr *)base;
|
||||
|
||||
fields = OBJFIELDS(object);
|
||||
|
||||
for(i=0; i<fields; ++i) {
|
||||
e = mps_fix(ss, (mps_addr_t)&OBJFIELD(object, i));
|
||||
if(e != ErrSUCCESS) return e;
|
||||
}
|
||||
|
||||
OBJFIELD(object, i) = OBJSUM(object);
|
||||
|
||||
base = (mps_addr_t)(&OBJFIELD(object, fields) + 1);
|
||||
}
|
||||
return ErrSUCCESS;
|
||||
}
|
||||
|
||||
static mps_addr_t skip(mps_addr_t where)
|
||||
{
|
||||
mps_word_t *object;
|
||||
|
||||
AVER(probe(where));
|
||||
object = (mps_word_t *)where;
|
||||
return (&OBJFIELD(object, OBJFIELDS(object)) + 1);
|
||||
}
|
||||
|
||||
static mps_word_t length(mps_addr_t where)
|
||||
{
|
||||
return (mps_word_t)skip(where) - (mps_word_t)where;
|
||||
}
|
||||
|
||||
/* A broken heart is the new address of the object, which */
|
||||
/* has the LSB clear. */
|
||||
|
||||
static mps_addr_t isfwd(mps_addr_t where)
|
||||
{
|
||||
mps_word_t *object;
|
||||
|
||||
AVER(PoolHasAddr((Pool)pool, (Addr)where));
|
||||
AVER(IsAligned(OBJECT_ALIGN, (Addr)where));
|
||||
|
||||
object = (Addr *)where;
|
||||
|
||||
if(OBJHERE(object)) {
|
||||
return NULL;
|
||||
} else {
|
||||
return (mps_addr_t)object[0];
|
||||
}
|
||||
}
|
||||
|
||||
static void copy(mps_addr_t from, mps_addr_t to)
|
||||
{
|
||||
mps_word_t l;
|
||||
|
||||
AVER(IsAligned(OBJECT_ALIGN, (Addr)to));
|
||||
AVER(probe(from));
|
||||
|
||||
l = length(from);
|
||||
memcpy((void *)to, (void *)from, l);
|
||||
AVER(probe(to));
|
||||
}
|
||||
|
||||
static void fwd(mps_addr_t from, mps_addr_t to)
|
||||
{
|
||||
mps_word_t l;
|
||||
|
||||
AVER(IsAligned(OBJECT_ALIGN, (Addr)to));
|
||||
AVER(probe(from));
|
||||
AVER(probe(to));
|
||||
|
||||
l = length(from);
|
||||
memset((void *)from, (char)0xEE, (size_t)l);
|
||||
*(mps_addr_t *)from = to;
|
||||
}
|
||||
|
||||
|
||||
/* make an object with random length. The header is the length */
|
||||
/* shifted left one with the LSB set. */
|
||||
static mps_ap_t ap;
|
||||
static mps_addr_t exact_roots[NR_EXACT_ROOTS];
|
||||
static mps_addr_t ambig_roots[NR_AMBIG_ROOTS];
|
||||
|
||||
static mps_addr_t make(void)
|
||||
{
|
||||
mps_addr_t new;
|
||||
mps_word_t *object;
|
||||
mps_word_t fields = invrnd(FIELDS_MAX);
|
||||
mps_word_t i;
|
||||
mps_word_t size = sizeof(mps_addr_t) * (fields + 3);
|
||||
|
||||
size_t length = rnd() % 20, size = (length+2)*sizeof(mps_word_t);
|
||||
mps_addr_t p;
|
||||
mps_res_t res;
|
||||
|
||||
do {
|
||||
die(mps_reserve(&new, buffer, size), "reserve");
|
||||
object = (mps_word_t *)new;
|
||||
OBJHEAD(object) = (fields << 1) | 1;
|
||||
OBJNAME(object) = (mps_word_t)name++;
|
||||
for(i=0; i<fields; ++i)
|
||||
OBJFIELD(object, i) = (mps_word_t)exactRoots[rnd() % NR_EXACT_ROOTS];
|
||||
OBJFIELD(object, i) = OBJSUM(object);
|
||||
AVER(probe(new));
|
||||
AVER(length(new) == size);
|
||||
} while(!mps_commit(buffer, new, size));
|
||||
MPS_RESERVE_BLOCK(res, p, ap, size);
|
||||
if(res) die(res, "MPS_RESERVE_BLOCK");
|
||||
res = dylan_init(p, size, exact_roots, NR_EXACT_ROOTS);
|
||||
if(res) die(res, "dylan_init");
|
||||
} while(!mps_commit(ap, p, size));
|
||||
|
||||
return new;
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
static void *test(void *arg, size_t s)
|
||||
{
|
||||
mps_space_t space;
|
||||
mps_form_t format;
|
||||
mps_root_t exactRoot, ambigRoot;
|
||||
mps_word_t i, j;
|
||||
mps_fmt_t format;
|
||||
mps_root_t exact_root, ambig_root;
|
||||
mps_word_t i;
|
||||
unsigned collections;
|
||||
mps_form_A_s f;
|
||||
|
||||
space = (mps_space_t)arg;
|
||||
UNUSED(s);
|
||||
|
||||
f.align = OBJECT_ALIGN;
|
||||
f.scan = scan;
|
||||
f.skip = skip;
|
||||
f.fwd = fwd;
|
||||
f.isfwd = isfwd;
|
||||
f.copy = copy;
|
||||
die(mps_fmt_create_A(&format, space, dylan_fmt_A()), "fmt_create");
|
||||
|
||||
die(mps_form_create_A(&format, space, &f), "FormatCreate");
|
||||
die(mps_pool_create(&pool, space, mps_class_amc(), format),
|
||||
"pool_create(amc)");
|
||||
|
||||
die(mps_pool_create(&pool, space, (mps_class_t)PoolClassAMC(),
|
||||
format), "PoolCreate");
|
||||
die(mps_ap_create(&buffer, pool), "BufferCreate");
|
||||
die(mps_ap_create(&ap, pool), "BufferCreate");
|
||||
|
||||
die(mps_root_create_table(&exactRoot, space,
|
||||
MPS_RANK_EXACT, (mps_rm_t)0,
|
||||
&exactRoots[0], NR_EXACT_ROOTS),
|
||||
"RootCreateTable");
|
||||
die(mps_root_create_table(&exact_root, space,
|
||||
MPS_RANK_EXACT, (mps_rm_t)0,
|
||||
&exact_roots[0], NR_EXACT_ROOTS),
|
||||
"root_create_table(exact)");
|
||||
|
||||
die(mps_root_create_table(&ambigRoot, space,
|
||||
RefRankAMBIG, (mps_rm_t)0,
|
||||
&ambigRoots[0], NR_AMBIG_ROOTS),
|
||||
"RootCreateTable");
|
||||
die(mps_root_create_table(&ambig_root, space,
|
||||
MPS_RANK_AMBIG, (mps_rm_t)0,
|
||||
&ambig_roots[0], NR_AMBIG_ROOTS),
|
||||
"root_create_table(ambig)");
|
||||
|
||||
for(i=0; i<NR_EXACT_ROOTS; ++i)
|
||||
exactRoots[i] = (mps_addr_t)0xDECEA5ED;
|
||||
exact_roots[i] = OBJNULL;
|
||||
|
||||
for(i=0; i<NR_AMBIG_ROOTS; ++i)
|
||||
ambigRoots[i] = (mps_addr_t)rnd();
|
||||
ambig_roots[i] = (mps_addr_t)rnd();
|
||||
|
||||
collections = 0;
|
||||
|
||||
for(i=0; i<OBJECTS; ++i)
|
||||
{
|
||||
for(i=0; i<OBJECTS; ++i) {
|
||||
unsigned c;
|
||||
size_t r;
|
||||
|
||||
c = AMCCollections((Pool)pool);
|
||||
c = mps_amc_collections((mps_pool_t)pool);
|
||||
|
||||
if(collections != c)
|
||||
{
|
||||
if(collections != c) {
|
||||
collections = c;
|
||||
|
||||
printf("\nCollection %u, %lu objects.\n",
|
||||
c, (unsigned long)i);
|
||||
|
||||
/* PoolDescribe(pool, LibStreamOut()); */
|
||||
SpaceDescribe((Space)space, LibStreamOut());
|
||||
|
||||
for(j=0; j<NR_EXACT_ROOTS; ++j)
|
||||
if((mps_word_t)exactRoots[j] != 0xDECEA5ED)
|
||||
AVER(probe(exactRoots[j]));
|
||||
for(i=0; i<NR_EXACT_ROOTS; ++i)
|
||||
assert(dylan_check(exact_roots[i]));
|
||||
}
|
||||
|
||||
if(rnd() & 1) {
|
||||
exactRoots[invrnd(NR_EXACT_ROOTS)] = make();
|
||||
probe(exactRoots[invrnd(NR_EXACT_ROOTS)]);
|
||||
} else {
|
||||
ambigRoots[invrnd(NR_AMBIG_ROOTS)] = make();
|
||||
probe(ambigRoots[invrnd(NR_AMBIG_ROOTS)]);
|
||||
}
|
||||
if(rnd() & 1)
|
||||
exact_roots[rnd() % NR_EXACT_ROOTS] = make();
|
||||
else
|
||||
ambig_roots[rnd() % NR_AMBIG_ROOTS] = make();
|
||||
|
||||
/* roots[invrnd(NR_ROOTS)] = 0xDECEA5ED; */
|
||||
r = rnd() % NR_EXACT_ROOTS;
|
||||
if(exact_roots[r] != OBJNULL)
|
||||
assert(dylan_check(exact_roots[r]));
|
||||
}
|
||||
|
||||
mps_ap_destroy(buffer);
|
||||
mps_root_destroy(exactRoot);
|
||||
mps_root_destroy(ambigRoot);
|
||||
mps_ap_destroy(ap);
|
||||
mps_root_destroy(exact_root);
|
||||
mps_root_destroy(ambig_root);
|
||||
mps_pool_destroy(pool);
|
||||
|
||||
return NULL;
|
||||
|
|
@ -301,17 +113,13 @@ static void *test(void *arg, size_t s)
|
|||
int main(void)
|
||||
{
|
||||
mps_space_t space;
|
||||
/* mps_thr_t thread; */
|
||||
mps_thr_t thread;
|
||||
void *r;
|
||||
|
||||
die(mps_space_create(&space), "SpaceCreate");
|
||||
|
||||
/* die(mps_thread_reg(&thread, space), "ThreadReg"); */
|
||||
|
||||
die(mps_space_create(&space), "space_create");
|
||||
die(mps_thread_reg(&thread, space), "thread_reg");
|
||||
mps_tramp(&r, test, space, 0);
|
||||
|
||||
/* mps_thread_dereg(thread); */
|
||||
|
||||
mps_thread_dereg(thread);
|
||||
mps_space_destroy(space);
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue