You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Steve Peters <st...@fisharerojo.org> on 2005/05/27 16:14:21 UTC

Build of mod_perl 2.0.0 fails on bleadperl - no more HvPMROOT()

As of about a week ago, PMROOT was removed from the HV struct and 
moved off to magic.  Unfortunately, mod_perl seems to be using
the HvPMROOT() macro to store away the modperl_interp_t 
pointer in modperl_interp.h.  The comments seem to indicate that
mod_perl isn't using PMROOT for its intended purpose, but instead
as a quick place to store the interp pointer.

So, mod_perl is going to need a new place to put the interp
pointer.  I'm guessing that it could use PMROOT's new place in
magic.  Code like the following would probably work get the
magic.  I haven't tested it, but the code for MP_THX_INTERP_SET
would look like...

#define MP_THX_INTERP_SET(thx, interp) \
# ifndef(HvPMROOT)
    MAGIC *mg = mg_find((SV*)thx, PERL_MAGIC_symtab); \ 
    mg->mg_obj = (SV*)interp    
# else
 <current code>

Of course, there may be a much better place or way of doing it
which I don't know about.  I'm just hoping to start some discussion
instead of it being a surprise when 5.9.3 is released.

Steve Peters
steve@fisharerojo.org

Re: Build of mod_perl 2.0.0 fails on bleadperl - no more HvPMROOT()

Posted by Stas Bekman <st...@stason.org>.
Stas Bekman wrote:
[...]
>> If you really really feel the need to cheat then you have the choice 
>> of these:
>>
>> #define xhv_keys xiv_u.xivu_iv
>>
>> typedef struct {
>>     STRLEN    xhv_fill;    /* how full xhv_array currently is */
>>     STRLEN    xhv_max;    /* subscript of last element of xhv_array */
>>     union {
>>     IV    xivu_iv;    /* integer value or pv offset */
>>     UV    xivu_uv;
>>     void *    xivu_p1;
>>     }        xiv_u;
>>     MAGIC*    xmg_magic;    /* magic for scalar array */
>>     HV*        xmg_stash;    /* class package */
>> } xpvhv_allocated;
>>
>>
>> Only xmg_magic and xmg_stash aren't needed for the operation of a 
>> regular hash.
>> I've no idea what modglobal_ptr gets used for throughout the perl 
>> codebase,
>> but hanging something that isn't MAGIC* from xmg_magic feels like a 
>> bad plan.

While using xmg_magic or xmg_stash works most of the time, it fails 
perl_clone at run time, where it tries to clone the member which is not of 
a proper type (just a pointer cast into MAGIC*), resulting in a segfault:

#7  0xb7aaac57 in Perl_sv_dup (my_perl=0xba9bc88, sstr=0x5, param=0xb685ada0)
     at sv.c:10287
#8  0xb7aaa36a in Perl_mg_dup (my_perl=0xba9bc88, mg=0xadb9608, 
param=0xb685ada0)
     at sv.c:10056
#9  0xb7aab3bc in Perl_sv_dup (my_perl=0xba9bc88, sstr=0xb2b20c0, 
param=0xb685ada0)
     at sv.c:10477
#10 0xb7aaf785 in perl_clone (proto_perl=0xaa16dd8, flags=2) at sv.c:11531
#11 0xb7895a8a in Perl_ithread_create (my_perl=0xaa16dd8, obj=0x0,
     classname=0xba98910 "threads", init_function=0xbd412d8, params=0xbc551b8)
     at threads.xs:426

Besides the speed that I have mentioned before, there is another 
requirement: the get/set should work w/o needing aTHX, therefore using a 
real magic won't work.

More ideas?

Really, what we are after is the set/get mechanism used by ithreads.xs 
itself, but it needs to be faster and require no aTHX. If we find one we 
will be able to speed up ithreads as well. At the moment ithreads.xs does:

void Perl_ithread_set (pTHX_ ithread* thread)
{
   SV* thread_sv = newSViv(PTR2IV(thread));
   if(!hv_store(PL_modglobal, "threads::self", 12, thread_sv,0)) {
     croak("%s\n","Internal error, couldn't set TLS");
   }
}

ithread* Perl_ithread_get (pTHX) {
   SV** thread_sv = hv_fetch(PL_modglobal, "threads::self",12,0);
   if(!thread_sv) {
     croak("%s\n","Internal error, couldn't get TLS");
   }
   return INT2PTR(ithread*,SvIV(*thread_sv));
}


-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: Build of mod_perl 2.0.0 fails on bleadperl - no more HvPMROOT()

Posted by Stas Bekman <st...@stason.org>.
Apologies for not replying earlier. I'm now back to work on this issue.

Nicholas Clark wrote:
> On Sun, Jun 12, 2005 at 07:29:02PM +1000, Stas Bekman wrote:
> 
> 
>>Thanks Steve for the suggestion, but this is not good since it requires 
>>aTHX + PERL_SET_CONTEXT which creates a chicken and an egg problem. Any 
>>other more suitable candidates to use instead of:
>>
>> HvPMROOT(*Perl_Imodglobal_ptr(thx)) = (PMOP*)interp
>>
>>?
>>
>>It needs to be really quick, as we already have a way too many context 
>>switch overheads in the perl-core.

> Is all this messing around with hiding things in HvPMROOT because really
> mod_perl 2 would like a private pointer of its own in the perl interpreter
> structure?

No, it wants to have a reference from the current perl interpreter to
modperl_interp_t which is needed to be able to put the perl interpreter 
back to the pool of interpreters and such.

struct modperl_interp_t {
     modperl_interp_pool_t *mip;
     PerlInterpreter *perl;
     int num_requests;
     U8 flags;
     request_rec *request;
     int refcnt;
#ifdef MP_TRACE
     unsigned long tid;
#endif
};

Of course we could have created a special entry in modglobal and store it 
there, but since the operation of reading and setting of modperl_interp_t 
is very frequent, it must be very fast. I suppose Doug has chosen
HvPMROOT(*Perl_Imodglobal_ptr(thx)) as the quickest possible way to 
accomplish that.

> If you really really feel the need to cheat then you have the choice of these:
> 
> #define xhv_keys xiv_u.xivu_iv
> 
> typedef struct {
>     STRLEN	xhv_fill;	/* how full xhv_array currently is */
>     STRLEN	xhv_max;	/* subscript of last element of xhv_array */
>     union {
> 	IV	xivu_iv;	/* integer value or pv offset */
> 	UV	xivu_uv;
> 	void *	xivu_p1;
>     }		xiv_u;
>     MAGIC*	xmg_magic;	/* magic for scalar array */
>     HV*		xmg_stash;	/* class package */
> } xpvhv_allocated;
> 
> 
> Only xmg_magic and xmg_stash aren't needed for the operation of a regular hash.
> I've no idea what modglobal_ptr gets used for throughout the perl codebase,
> but hanging something that isn't MAGIC* from xmg_magic feels like a bad plan.

You mean because it might be used later on for some purpose? If so any 
other ideas for a quick stash inside the interpreter that is not used by 
perl itself? May be something else besides modglobal?

-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org