SP_OFFSET, jthreads, pthreads

Godmar Back gback at cs.utah.edu
Wed Aug 5 09:22:27 PDT 1998


> 
> > Basically, you'll have to determine SP_OFFSET for the alpha;
> 
> SP is the stack pointer?
> What does that offset signify?
> How much bytes a standard subroutine call puts on the stack?

 SP_OFFSET gives the offset in the jmpbuf buffer at which the stack
pointer is stored.

> 
> > you'll have to find out whether its frame pointer needs to be
> > manipulated too, and if so, define FP_OFFSET.  You can either look in
> > <setjmp.h>, or I can send you a test program that finds out what it
> > is.
> 
> Please do so!

I'll append sp_offset.c.

> 
> > The macro FRAMEOKAY() is only used by the version that uses jit AND
> > unix-internal.  For unix-jthreads, I felt that putting this macro in jit.h
> > would violate encapsulation, so I replaced it with jthread_on_current_stack.
> > It is only used from within the threading system, namely in TnextFrame.
> 
> Is there some FAQ or HOWTO about this?

It was discussed on this mailing list before, check the archives.

> What are jthreads and why would anyone want to use them in lieu of
> pthreads?

jthreads is the current Kaffe threading system, it is a simple preemptive
user-level threads package based on Kaffe's original non-preemptive
internal threads package (now called "internal").

A public pthreads port is not available.  There are some problems with
pthreads, too.  See Dan Lambright's mail about their pthreads port in the
archives.

> 
> > The other macros in jit.h, as far as I can see, are still needed and you must 
> > implement them properly for the alpha.
> 
> Mhh.
> If you give me a small program that uses them, I will try my best.
> 

 regression/NullPointerTest.java is about as small as it gets.
Try regression/TestNative.java also.

	- Godmar

---
sp_offset.c:

#include <setjmp.h>
#include <assert.h>
#include <stdio.h>
#include <signal.h>
#include <sys/wait.h>

#define STACK_SIZE      65536
#define STACK_COPY      128
#define GET_SP(E)       (((void**)(E))[SP_OFFSET])
#define SET_SP(E, V)    ((void**)(E))[SP_OFFSET] = (V)

int fork();

int  SP_OFFSET;
char new_stack[STACK_SIZE];
jmp_buf buf, buf2;

void alarm()
{
    longjmp(buf2, 1);
}

static void
check()
{
    char x;
    if (&x > new_stack && &new_stack[sizeof new_stack] > &x)
        printf("#define\tSP_OFFSET\t%d\n", SP_OFFSET);
    exit(0);
}

int
main(int ac, char *av[])
{
    int  stat;
    pid_t child;
    void *oldsp, *newsp;

    for (; SP_OFFSET < sizeof (buf) / sizeof (int); SP_OFFSET++) {

        if ((child = fork()) == 0) {    /* child */

            if (setjmp(buf)) 
                check();

            oldsp = GET_SP(buf);
            newsp = &new_stack[(sizeof new_stack)/2];
            SET_SP(buf, newsp);
            memcpy(newsp, oldsp, STACK_COPY);
            longjmp(buf, 1);
            exit(-1);

        } else {        /* parent */

            if (!setjmp(buf2)) {
                signal(SIGALRM, alarm);
                alarm(3);
                assert(child == wait(&stat));
                alarm(0);
            }
            /* else timed out, continue */
        }
    }
    return 0;
}



More information about the kaffe mailing list