|
Packit |
d28291 |
/*
|
|
Packit |
d28291 |
* Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
|
|
Packit |
d28291 |
*
|
|
Packit |
d28291 |
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
|
|
Packit |
d28291 |
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
|
|
Packit |
d28291 |
*
|
|
Packit |
d28291 |
* Permission is hereby granted to use or copy this program
|
|
Packit |
d28291 |
* for any purpose, provided the above notices are retained on all copies.
|
|
Packit |
d28291 |
* Permission to modify the code and to distribute modified code is granted,
|
|
Packit |
d28291 |
* provided the above notices are retained, and a notice that the code was
|
|
Packit |
d28291 |
* modified is included with the above copyright notice.
|
|
Packit |
d28291 |
*/
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
/* Check whether setjmp actually saves registers in jmp_buf. */
|
|
Packit |
d28291 |
/* If it doesn't, the generic mark_regs code won't work. */
|
|
Packit |
d28291 |
/* Compilers vary as to whether they will put x in a */
|
|
Packit |
d28291 |
/* (callee-save) register without -O. The code is */
|
|
Packit |
d28291 |
/* contrived such that any decent compiler should put x in */
|
|
Packit |
d28291 |
/* a callee-save register with -O. Thus it is */
|
|
Packit |
d28291 |
/* recommended that this be run optimized. (If the machine */
|
|
Packit |
d28291 |
/* has no callee-save registers, then the generic code is */
|
|
Packit |
d28291 |
/* safe, but this will not be noticed by this piece of */
|
|
Packit |
d28291 |
/* code.) This test appears to be far from perfect. */
|
|
Packit |
d28291 |
#include <stdio.h>
|
|
Packit |
d28291 |
#include <setjmp.h>
|
|
Packit |
d28291 |
#include <string.h>
|
|
Packit |
d28291 |
#include "private/gc_priv.h"
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
#ifdef OS2
|
|
Packit |
d28291 |
/* GETPAGESIZE() is set to getpagesize() by default, but that */
|
|
Packit |
d28291 |
/* doesn't really exist, and the collector doesn't need it. */
|
|
Packit |
d28291 |
#define INCL_DOSFILEMGR
|
|
Packit |
d28291 |
#define INCL_DOSMISC
|
|
Packit |
d28291 |
#define INCL_DOSERRORS
|
|
Packit |
d28291 |
#include <os2.h>
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
int getpagesize(void)
|
|
Packit |
d28291 |
{
|
|
Packit |
d28291 |
ULONG result[1];
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
if (DosQuerySysInfo(QSV_PAGE_SIZE, QSV_PAGE_SIZE,
|
|
Packit |
d28291 |
(void *)result, sizeof(ULONG)) != NO_ERROR) {
|
|
Packit |
d28291 |
fprintf(stderr, "DosQuerySysInfo failed\n");
|
|
Packit |
d28291 |
result[0] = 4096;
|
|
Packit |
d28291 |
}
|
|
Packit |
d28291 |
return((int)(result[0]));
|
|
Packit |
d28291 |
}
|
|
Packit |
d28291 |
#elif defined(MSWIN32) || defined(MSWINCE) || defined(CYGWIN32)
|
|
Packit |
d28291 |
# include <windows.h>
|
|
Packit |
d28291 |
int getpagesize(void)
|
|
Packit |
d28291 |
{
|
|
Packit |
d28291 |
SYSTEM_INFO sysinfo;
|
|
Packit |
d28291 |
GetSystemInfo(&sysinfo);
|
|
Packit |
d28291 |
return sysinfo.dwPageSize;
|
|
Packit |
d28291 |
}
|
|
Packit |
d28291 |
#endif
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
struct {
|
|
Packit |
d28291 |
char a_a;
|
|
Packit |
d28291 |
char * a_b;
|
|
Packit |
d28291 |
} a;
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
word nested_sp(void)
|
|
Packit |
d28291 |
{
|
|
Packit |
d28291 |
# if defined(__GNUC__) && (__GNUC__ >= 4)
|
|
Packit |
d28291 |
return (word)__builtin_frame_address(0);
|
|
Packit |
d28291 |
# else
|
|
Packit |
d28291 |
volatile word sp;
|
|
Packit |
d28291 |
sp = (word)(&sp);
|
|
Packit |
d28291 |
return sp;
|
|
Packit |
d28291 |
# endif
|
|
Packit |
d28291 |
}
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
/* To prevent nested_sp inlining. */
|
|
Packit |
d28291 |
word (*volatile nested_sp_fn)(void) = nested_sp;
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
int g(int x);
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
int main(void)
|
|
Packit |
d28291 |
{
|
|
Packit |
d28291 |
volatile word sp;
|
|
Packit |
d28291 |
unsigned ps = GETPAGESIZE();
|
|
Packit |
d28291 |
jmp_buf b;
|
|
Packit |
d28291 |
register int x = (int)strlen("a"); /* 1, slightly disguised */
|
|
Packit |
d28291 |
static volatile int y = 0;
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
sp = (word)(&sp);
|
|
Packit |
d28291 |
printf("This appears to be a %s running %s\n", MACH_TYPE, OS_TYPE);
|
|
Packit |
d28291 |
if (nested_sp_fn() < sp) {
|
|
Packit |
d28291 |
printf("Stack appears to grow down, which is the default.\n");
|
|
Packit |
d28291 |
printf("A good guess for STACKBOTTOM on this machine is 0x%lx.\n",
|
|
Packit |
d28291 |
((unsigned long)sp + ps) & ~(ps-1));
|
|
Packit |
d28291 |
} else {
|
|
Packit |
d28291 |
printf("Stack appears to grow up.\n");
|
|
Packit |
d28291 |
printf("Define STACK_GROWS_UP in gc_private.h\n");
|
|
Packit |
d28291 |
printf("A good guess for STACKBOTTOM on this machine is 0x%lx.\n",
|
|
Packit |
d28291 |
((unsigned long)sp + ps) & ~(ps-1));
|
|
Packit |
d28291 |
}
|
|
Packit |
d28291 |
printf("Note that this may vary between machines of ostensibly\n");
|
|
Packit |
d28291 |
printf("the same architecture (e.g. Sun 3/50s and 3/80s).\n");
|
|
Packit |
d28291 |
printf("On many machines the value is not fixed.\n");
|
|
Packit |
d28291 |
printf("A good guess for ALIGNMENT on this machine is %lu.\n",
|
|
Packit |
d28291 |
(unsigned long)((word)(&(a.a_b)) - (word)(&a)));
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
printf("The following is a very dubious test of one root marking"
|
|
Packit |
d28291 |
" strategy.\n");
|
|
Packit |
d28291 |
printf("Results may not be accurate/useful:\n");
|
|
Packit |
d28291 |
/* Encourage the compiler to keep x in a callee-save register */
|
|
Packit |
d28291 |
x = 2*x-1;
|
|
Packit |
d28291 |
printf("\n");
|
|
Packit |
d28291 |
x = 2*x-1;
|
|
Packit |
d28291 |
setjmp(b);
|
|
Packit |
d28291 |
if (y == 1) {
|
|
Packit |
d28291 |
if (x == 2) {
|
|
Packit |
d28291 |
printf("Setjmp-based generic mark_regs code probably won't work.\n");
|
|
Packit |
d28291 |
printf("But we rarely try that anymore. If you have getcontect()\n");
|
|
Packit |
d28291 |
printf("this probably doesn't matter.\n");
|
|
Packit |
d28291 |
} else if (x == 1) {
|
|
Packit |
d28291 |
printf("Setjmp-based register marking code may work.\n");
|
|
Packit |
d28291 |
} else {
|
|
Packit |
d28291 |
printf("Very strange setjmp implementation.\n");
|
|
Packit |
d28291 |
}
|
|
Packit |
d28291 |
}
|
|
Packit |
d28291 |
y++;
|
|
Packit |
d28291 |
x = 2;
|
|
Packit |
d28291 |
if (y == 1) longjmp(b,1);
|
|
Packit |
d28291 |
printf("Some GC internal configuration stuff: \n");
|
|
Packit |
d28291 |
printf("\tWORDSZ = %lu, ALIGNMENT = %d, GC_GRANULE_BYTES = %d\n",
|
|
Packit |
d28291 |
(unsigned long)WORDSZ, ALIGNMENT, GC_GRANULE_BYTES);
|
|
Packit |
d28291 |
printf("\tUsing one mark ");
|
|
Packit |
d28291 |
# if defined(USE_MARK_BYTES)
|
|
Packit |
d28291 |
printf("byte");
|
|
Packit |
d28291 |
# else
|
|
Packit |
d28291 |
printf("bit");
|
|
Packit |
d28291 |
# endif
|
|
Packit |
d28291 |
printf(" per ");
|
|
Packit |
d28291 |
# if defined(MARK_BIT_PER_OBJ)
|
|
Packit |
d28291 |
printf("object.\n");
|
|
Packit |
d28291 |
# elif defined(MARK_BIT_PER_GRANULE)
|
|
Packit |
d28291 |
printf("granule.\n");
|
|
Packit |
d28291 |
# endif
|
|
Packit |
d28291 |
# ifdef THREAD_LOCAL_ALLOC
|
|
Packit |
d28291 |
printf("Thread local allocation enabled.\n");
|
|
Packit |
d28291 |
# endif
|
|
Packit |
d28291 |
# ifdef PARALLEL_MARK
|
|
Packit |
d28291 |
printf("Parallel marking enabled.\n");
|
|
Packit |
d28291 |
# endif
|
|
Packit |
d28291 |
(void)g(x);
|
|
Packit |
d28291 |
return(0);
|
|
Packit |
d28291 |
}
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
int g(int x)
|
|
Packit |
d28291 |
{
|
|
Packit |
d28291 |
return(x);
|
|
Packit |
d28291 |
}
|