[m-dev.] Re: About to abandon .par grades... (fwd)

Julien Fischer juliensf at cs.mu.OZ.AU
Wed Oct 20 02:26:37 AEST 2004

---------- Forwarded message ----------
Date: Tue, 19 Oct 2004 09:42:50 +1000
From: Ralph Becket <rafe at cs.mu.OZ.AU>
To: Fergus Henderson <fjh007 at galois.com>
Cc: Ralph Becket <rafe at cs.mu.OZ.AU>, Julien Fischer <juliensf at cs.mu.OZ.AU>,
     Zoltan Somogyi <zs at cs.mu.OZ.AU>
Subject: Re: About to abandon .par grades...

Fergus Henderson, Monday, 18 October 2004:
> Well, I don't understand the fix either.
> Your diagnosis that without it "the Mercury engine is not initialized"
> doesn't make much sense to me, since there are calls to
> "MR_init_thread(MR_use_now)" immediately after the call to
> MR_init_memory() and the code to initialize the trail.
> Those calls should initialize the Mercury engine.

If you put GRADE=hlc.par.gc in Mmake.params and do
$ cd runtime
$ mmake mercury_wrapper.i
(.i is the pre-processed version of .c) and examine mercury_wrapper.i,
you'll find that no calls to MR_init_thread() are present after
pre-processing.  (MR_init_thread() is the only place where
MR_create_engine() is called, but I think this may only be part of the
problem - see below.)

> Perhaps the problem is that there is some code inside
> MR_init_memory() and/or the code to initialize the trail
> which requires the Mercury engine to have already been initialized.
> Where does it actually crash?

The code crashes in mercury_wrapper.c:mercury_runtime_init() when it
executes the macro MR_save_registers().  In order to see what's going on
there we've tried replacing the contents of mercury_wrapper.c with
mercury_wrapper.i, but that seems to make every version of gcc we have
either crash or generate code that doesn't work!

The part of the .i file showing the expansion of MR_save_registers is

do {
	((void) 0);
	(((((MercuryEngine *) ((MercuryEngine *)
		MR_eng_fake_reg))[((32 + 6) + 3) ]) = (MR_Word) (MR_sol_hp_var);
	(((((MercuryEngine *) ((MercuryEngine *)
		MR_eng_fake_reg))[((32 + 6) + 4) ]) = (MR_Word) (MR_min_hp_rec_var);
	(((((MercuryEngine *) ((MercuryEngine *)
		MR_eng_fake_reg))[((32 + 6) + 5) ]) = (MR_Word) (MR_min_sol_hp_rec_var);
	(((((MercuryEngine *) ((MercuryEngine *)
		MR_eng_fake_reg))[((32 + 6) + 6) ]) = (MR_Word) (MR_global_hp_var);

	((void) 0);
	((void) 0);
} while (0);

I've traced the problem under gdb to
pthread_getspecific(MR_engine_base_key) returning NULL.  The only place
where pthread_setspecific(MR_engine_base_key, eng) is executed is in

So I know (a) what is causing the crash and (b) why inserting the call
MR_init_thread(MR_use_now) before MR_save_registers() solves the
problem.  What I don't understand is why this code ever worked before!
Trawling through the CVS diffs for mercury_wrapper.c, mercury_thread.c,
mercury_context.c etc. doesn't show anything that looks relevant.

> > The Mercury engine is, oddly, initialised by calling
> > MR_init_thread in runtime/mercury_thread.c.
> That's because there is one Mercury engine per Posix thread.

Ahh, right.

-- Ralph
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au

More information about the developers mailing list