summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Zakharevich <ilya@math.berkeley.edu>1998-06-22 00:19:45 -0400
committerGurusamy Sarathy <gsar@cpan.org>1998-06-23 06:06:23 +0000
commit8d6dde3e637be6ce74eec8ca77c5be73d19f769a (patch)
treeeb37e8ea49be3485b48a74821f527ac1fde1a018
parent276493cb78ba879defeed992c4543a6fe30f98ce (diff)
downloadperl-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.h2
-rw-r--r--av.c11
-rw-r--r--embed.h1
-rw-r--r--global.sym1
-rw-r--r--hv.c7
-rw-r--r--malloc.c14
-rw-r--r--objpp.h2
-rw-r--r--perl.c2
-rw-r--r--pp_sys.c2
-rw-r--r--proto.h1
-rw-r--r--sv.c10
-rw-r--r--toke.c6
12 files changed, 45 insertions, 14 deletions
diff --git a/ObjXSub.h b/ObjXSub.h
index e1a266edf1..53796dffdd 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 3ced5bef3b..36bfa9cc7e 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 352bbfbc2b..c367ac74f5 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 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
diff --git a/hv.c b/hv.c
index 6fd6f2f3b0..6d6c3ce2a1 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 6abd4502c3..ea00e5a5e5 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 bba19d1a08..98dd95126f 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 7e2d562101..af74ddb859 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 1814a59e15..df2b7ae596 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 c8f6a43426..fe8b6387f8 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 245c4a50d4..cc3e37a723 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 f8b31bd692..4aa96d3821 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 */