diff options
author | Ilya Zakharevich <ilya@math.berkeley.edu> | 1998-06-22 00:19:45 -0400 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 1998-06-23 06:06:23 +0000 |
commit | 8d6dde3e637be6ce74eec8ca77c5be73d19f769a (patch) | |
tree | eb37e8ea49be3485b48a74821f527ac1fde1a018 | |
parent | 276493cb78ba879defeed992c4543a6fe30f98ce (diff) | |
download | perl-8d6dde3e637be6ce74eec8ca77c5be73d19f769a.tar.gz |
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
-rw-r--r-- | ObjXSub.h | 2 | ||||
-rw-r--r-- | av.c | 11 | ||||
-rw-r--r-- | embed.h | 1 | ||||
-rw-r--r-- | global.sym | 1 | ||||
-rw-r--r-- | hv.c | 7 | ||||
-rw-r--r-- | malloc.c | 14 | ||||
-rw-r--r-- | objpp.h | 2 | ||||
-rw-r--r-- | perl.c | 2 | ||||
-rw-r--r-- | pp_sys.c | 2 | ||||
-rw-r--r-- | proto.h | 1 | ||||
-rw-r--r-- | sv.c | 10 | ||||
-rw-r--r-- | toke.c | 6 |
12 files changed, 45 insertions, 14 deletions
@@ -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 @@ -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; @@ -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 4a7c4b539a..ea5b20f3f0 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 @@ -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; @@ -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); } @@ -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 @@ -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)) { @@ -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; @@ -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)); @@ -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); @@ -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 */ |