From 8d6dde3e637be6ce74eec8ca77c5be73d19f769a Mon Sep 17 00:00:00 2001 From: Ilya Zakharevich Date: Mon, 22 Jun 1998 00:19:45 -0400 Subject: [PATCH] applied patch, regen headers Message-Id: <199806220819.EAA03295@monk.mps.ohio-state.edu> Subject: [PATCH 5.004_67] Malloc size feedback p4raw-id: //depot/perl@1201 --- ObjXSub.h | 2 ++ av.c | 11 +++++++++-- embed.h | 1 + global.sym | 1 + hv.c | 7 +++---- malloc.c | 14 ++++++++++++-- objpp.h | 2 ++ perl.c | 2 +- pp_sys.c | 2 +- proto.h | 1 + sv.c | 10 +++++++++- toke.c | 6 +++--- 12 files changed, 45 insertions(+), 14 deletions(-) diff --git a/ObjXSub.h b/ObjXSub.h index e1a266e..53796df 100644 --- a/ObjXSub.h +++ b/ObjXSub.h @@ -1197,6 +1197,8 @@ #define magic_wipepack pPerl->Perl_magic_wipepack #undef magicname #define magicname pPerl->Perl_magicname +#undef malloced_size +#define malloced_size pPerl->Perl_malloced_size #undef markstack_grow #define markstack_grow pPerl->Perl_markstack_grow #undef mem_collxfrm diff --git a/av.c b/av.c index 3ced5be..36bfa9c 100644 --- a/av.c +++ b/av.c @@ -92,9 +92,15 @@ av_extend(AV *av, I32 key) U32 bytes; #endif +#ifdef MYMALLOC + newmax = malloced_size((void*)AvALLOC(av))/sizeof(SV*) - 1; + + if (key <= newmax) + goto resized; +#endif newmax = key + AvMAX(av) / 5; resize: -#ifdef STRANGE_MALLOC +#if defined(STRANGE_MALLOC) || defined(MYMALLOC) Renew(AvALLOC(av),newmax+1, SV*); #else bytes = (newmax + 1) * sizeof(SV*); @@ -114,6 +120,7 @@ av_extend(AV *av, I32 key) Safefree(AvALLOC(av)); AvALLOC(av) = ary; #endif + resized: ary = AvALLOC(av) + AvMAX(av) + 1; tmp = newmax - AvMAX(av); if (av == curstack) { /* Oops, grew stack (via av_store()?) */ @@ -123,7 +130,7 @@ av_extend(AV *av, I32 key) } } else { - newmax = key < 4 ? 4 : key; + newmax = key < 3 ? 3 : key; New(2,AvALLOC(av), newmax+1, SV*); ary = AvALLOC(av) + 1; tmp = newmax; diff --git a/embed.h b/embed.h index 352bbfb..c367ac7 100644 --- a/embed.h +++ b/embed.h @@ -326,6 +326,7 @@ #define magic_sizepack Perl_magic_sizepack #define magic_wipepack Perl_magic_wipepack #define magicname Perl_magicname +#define malloced_size Perl_malloced_size #define markstack_grow Perl_markstack_grow #define mem_collxfrm Perl_mem_collxfrm #define mess Perl_mess diff --git a/global.sym b/global.sym index 4a7c4b5..ea5b20f 100644 --- a/global.sym +++ b/global.sym @@ -426,6 +426,7 @@ magic_setvec magic_sizepack magic_wipepack magicname +malloced_size markstack_grow mem_collxfrm mess diff --git a/hv.c b/hv.c index 6fd6f2f..6d6c3ce 100644 --- a/hv.c +++ b/hv.c @@ -665,7 +665,7 @@ hsplit(HV *hv) I32 oldsize = (I32) xhv->xhv_max + 1; /* sic(k) */ register I32 newsize = oldsize * 2; register I32 i; - register HE **a; + register HE **a = (HE**)xhv->xhv_array; register HE **b; register HE *entry; register HE **oentry; @@ -673,9 +673,8 @@ hsplit(HV *hv) I32 tmp; #endif - a = (HE**)xhv->xhv_array; nomemok = TRUE; -#ifdef STRANGE_MALLOC +#if defined(STRANGE_MALLOC) || defined(MYMALLOC) Renew(a, newsize, HE*); if (!a) { nomemok = FALSE; @@ -756,7 +755,7 @@ hv_ksplit(HV *hv, IV newmax) a = (HE**)xhv->xhv_array; if (a) { nomemok = TRUE; -#ifdef STRANGE_MALLOC +#if defined(STRANGE_MALLOC) || defined(MYMALLOC) Renew(a, newsize, HE*); if (!a) { nomemok = FALSE; diff --git a/malloc.c b/malloc.c index 6abd450..ea00e5a 100644 --- a/malloc.c +++ b/malloc.c @@ -1430,8 +1430,18 @@ calloc(register size_t elements, register size_t size) MEM_SIZE malloced_size(void *p) { - int bucket = OV_INDEX((union overhead *)p); - + union overhead *ovp = (union overhead *) + ((caddr_t)p - sizeof (union overhead) * CHUNK_SHIFT); + int bucket = OV_INDEX(ovp); +#ifdef RCHECK + /* The caller wants to have a complete control over the chunk, + disable the memory checking inside the chunk. */ + if (bucket <= MAX_SHORT_BUCKET) { + MEM_SIZE size = BUCKET_SIZE_REAL(bucket); + ovp->ov_size = size + M_OVERHEAD - 1; + *((u_int *)((caddr_t)ovp + size + M_OVERHEAD - RSLOP)) = RMAGIC; + } +#endif return BUCKET_SIZE_REAL(bucket); } diff --git a/objpp.h b/objpp.h index bba19d1..98dd951 100644 --- a/objpp.h +++ b/objpp.h @@ -649,6 +649,8 @@ #define magic_wipepack CPerlObj::Perl_magic_wipepack #undef magicname #define magicname CPerlObj::Perl_magicname +#undef malloced_size +#define malloced_size CPerlObj::Perl_malloced_size #undef markstack_grow #define markstack_grow CPerlObj::Perl_markstack_grow #undef markstack_ptr diff --git a/perl.c b/perl.c index 7e2d562..af74ddb 100644 --- a/perl.c +++ b/perl.c @@ -170,7 +170,7 @@ perl_construct(register PerlInterpreter *sv_interp) thr = init_main_thread(); #endif /* USE_THREADS */ - linestr = NEWSV(65,80); + linestr = NEWSV(65,79); sv_upgrade(linestr,SVt_PVIV); if (!SvREADONLY(&sv_undef)) { diff --git a/pp_sys.c b/pp_sys.c index 1814a59..df2b7ae 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -207,7 +207,7 @@ PP(pp_backtick) SV *sv; for (;;) { - sv = NEWSV(56, 80); + sv = NEWSV(56, 79); if (sv_gets(sv, fp, 0) == Nullch) { SvREFCNT_dec(sv); break; diff --git a/proto.h b/proto.h index c8f6a43..fe8b638 100644 --- a/proto.h +++ b/proto.h @@ -264,6 +264,7 @@ VIRTUAL U32 magic_sizepack _((SV* sv, MAGIC* mg)); VIRTUAL int magic_wipepack _((SV* sv, MAGIC* mg)); VIRTUAL void magicname _((char* sym, char* name, I32 namlen)); int main _((int argc, char** argv, char** env)); +VIRTUAL MEM_SIZE malloced_size _((void *p)); VIRTUAL void markstack_grow _((void)); #ifdef USE_LOCALE_COLLATE VIRTUAL char* mem_collxfrm _((const char* s, STRLEN len, STRLEN* xlen)); diff --git a/sv.c b/sv.c index 245c4a5..cc3e37a 100644 --- a/sv.c +++ b/sv.c @@ -1118,8 +1118,16 @@ sv_grow(SV* sv, unsigned long newlen) else s = SvPVX(sv); if (newlen > SvLEN(sv)) { /* need more room? */ - if (SvLEN(sv) && s) + if (SvLEN(sv) && s) { +#ifdef MYMALLOC + STRLEN l = malloced_size((void*)SvPVX(sv)); + if (newlen <= l) { + SvLEN_set(sv, l); + return s; + } else +#endif Renew(s,newlen,char); + } else New(703,s,newlen,char); SvPV_set(sv, s); diff --git a/toke.c b/toke.c index f8b31bd..4aa96d3 100644 --- a/toke.c +++ b/toke.c @@ -5049,7 +5049,7 @@ scan_heredoc(register char *s) s--, herewas = newSVpv(s,d-s); s += SvCUR(herewas); - tmpstr = NEWSV(87,80); + tmpstr = NEWSV(87,79); sv_upgrade(tmpstr, SVt_PVIV); if (term == '\'') { op_type = OP_CONST; @@ -5307,8 +5307,8 @@ scan_str(char *start) multi_close = term; /* create a new SV to hold the contents. 87 is leak category, I'm - assuming. 80 is the SV's initial length. What a random number. */ - sv = NEWSV(87,80); + assuming. 79 is the SV's initial length. What a random number. */ + sv = NEWSV(87,79); sv_upgrade(sv, SVt_PVIV); SvIVX(sv) = term; (void)SvPOK_only(sv); /* validate pointer */ -- 1.8.3.1