Skip to content

Smoke me/davem/rc stack1 #20825

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 75 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
89eb402
perl -DsR: display PADMTPs as <P>
iabyn Jan 14, 2023
50c65e7
fix check order for filetest overload
iabyn Nov 10, 2022
b6b7004
NULL sv->sv_debug_file when freed
iabyn Jan 11, 2023
be8e4bf
don't call pp_pushmark() to push a mark
iabyn Nov 16, 2022
6f77ff8
simplify scope-exit empty scalar context
iabyn Jul 17, 2022
4a1c2c7
for loops: protect GV/LVREF from premature free
iabyn Nov 15, 2022
a5878be
add code comments concerning grep and map markstack usage
iabyn Nov 22, 2022
77b3be4
rationalise S_unwind_loop()
iabyn Nov 24, 2022
351b271
pp_sort(): add comments what the op flags mean
iabyn Dec 2, 2022
0255fae
pp_sort(): rename a duplicated variable
iabyn Dec 2, 2022
6ac33a5
move test out of fresh_perl.t into sub.t
iabyn Dec 6, 2022
a7f736d
call_sv, amagic_call: call pp_entersub via runops
iabyn Dec 31, 2022
a6e4e87
eval_sv(): call pp_entereval() via runops
iabyn Jan 19, 2023
89f4824
XS::APItest::test_EXTEND(): fixups
iabyn Jan 11, 2023
0d24fe8
ext/XS-APItest/t/magic.t: simplify recent test
iabyn Jan 23, 2023
3f74bb7
Perl_deb_stack_all() - handle empty CX stack
iabyn Jan 18, 2023
0013248
add PERL_RC_STACK define (not yet defined)
iabyn Jun 28, 2022
b1725b4
add Internals::stack_refcounted()
iabyn Dec 6, 2022
ead6ab6
ext/Devel-Peek/t/Peek.t: fixup top refcount
iabyn Jan 14, 2023
8cfd996
pp_dbstate: skip SAVESTACK_POS()
iabyn Dec 21, 2022
79a61cf
pp_mapwhile(): null out holes in stack
iabyn Nov 23, 2022
6cfeac7
Add av_remove_offset() core-only function
iabyn Dec 9, 2022
16d5429
create_eval_scope(): parameterise the stack pos
iabyn Dec 17, 2022
e08e7ce
Perl_call_sv(G_EVAL): set oldsp correctly
iabyn Jan 19, 2023
58ba0bd
assert that cxstack[i].oldsp are increasing
iabyn Dec 17, 2022
8252c5f
add rpp_foo() refcounted-stack manipulation fns
iabyn Nov 25, 2022
1af0215
use new rpp_is_lone() function
iabyn Jan 2, 2023
1a7df54
wrap normal non-RC-stack-aware pp functions
iabyn Jun 28, 2022
1350c36
pp_method*: fixup wrapping
iabyn Jan 13, 2023
3c3d93a
make RC-stack-aware: regcomp
iabyn Dec 4, 2022
51e5fc8
make RC-stack-aware: entersub
iabyn Dec 4, 2022
3f46af9
make RC-stack-aware: db/nextstate, unstack
iabyn Dec 4, 2022
e4eeccb
make RC-stack-aware: map and grep
iabyn Dec 4, 2022
6d580ef
make RC-stack-aware: enteriter, leaveloop
iabyn Dec 4, 2022
0be9a57
make RC-stack-aware: pp_leavefoo()
iabyn Dec 4, 2022
c989996
make RC-stack-aware: last
iabyn Dec 4, 2022
0f278e6
make RC-stack-aware: goto
iabyn Dec 4, 2022
a196750
make RC-stack-aware: require,eval
iabyn Feb 14, 2023
aebfe70
make RC-stack-aware: enter/leavegiven etc
iabyn Dec 4, 2022
d2180f6
make RC-stack-aware: enter/leavewrite
iabyn Dec 4, 2022
99b0dcf
make RC-stack-aware: pp_sort()
iabyn Dec 2, 2022
381256d
make RC-stack-aware: sort cmp function invokers
iabyn Dec 3, 2022
84abcf0
make RC-stack-aware: stat and filetest ops
iabyn Dec 4, 2022
b5fdf23
make RC-stack-aware: misc pp() functions
iabyn Dec 4, 2022
964080a
make RC-stack-aware: call_sv() and similar
iabyn Jan 19, 2023
5067f84
make RC-stack-aware: eval_sv()
iabyn Jan 19, 2023
2726c2f
make RC-stack-aware: defer
iabyn Jan 29, 2023
1534381
make RC-stack-aware: unwrap pp_add()
iabyn Dec 6, 2022
9eb4eca
make RC-stack-aware: unwrap pp_not()
iabyn Jan 2, 2023
5f49085
make RC-stack-aware: S_fold_constants()
iabyn Jan 5, 2023
761738c
make RC-stack-aware: Devel::Peek::Dump()
iabyn Jan 5, 2023
b17f033
make RC-stack-aware: perl_clone()
iabyn Jan 6, 2023
04afd8c
make RC-stack-aware: Perl_try_amagic_un() & _bin()
iabyn Jan 2, 2023
b334b64
make RC-stack-aware: threads.xs
iabyn Jan 16, 2023
2767bcd
make RC-stack-aware: t/cmd/for.t
iabyn Jan 2, 2023
0ec3acf
make RC-stack-aware: invoking DB::postponed()
iabyn Jan 15, 2023
f1403ef
make RC-stack-aware: ext/XS-APItest/
iabyn Jan 20, 2023
5de45d9
make shift(@a) leave old pointer
iabyn Dec 10, 2022
bd2428c
make @_ AvREAL() on RC-stack
iabyn Jan 23, 2023
8320688
add switch_argstack(), push/pop_stackinfo() fns
iabyn Dec 13, 2022
319ca01
allow argument stack to be AvREAL()
iabyn Dec 29, 2022
471f8ac
Allow argument stacks to be reference-counted
iabyn Jan 23, 2023
95cf821
add stack extend to Perl_die_unwind()
iabyn Jan 27, 2023
6e8288e
make RC-stack-aware: Perl_filter_read()
iabyn Jan 19, 2023
31f84d9
rpp_is_lone(): allow non-temp SV too
iabyn Jan 27, 2023
59a2512
Perl_debstack(): indicate stack refcount status
iabyn Dec 16, 2022
f3e3f88
disable PERL_XXX_TMP_NORC
iabyn Jan 2, 2023
fa90ad8
stack push/pops: assert rpp_stack_is_rc() state
iabyn Feb 17, 2023
1d8f13d
runops_debug(): add RC-stack assertions
iabyn Jan 26, 2023
ef22a78
pp_wrap(), xs_wrap(): extract some common code
iabyn Feb 3, 2023
dd3d818
tweak pp_wrap() and xs_wrap()
iabyn Feb 18, 2023
9aab567
add tests for XSPP_wrapped() macro
iabyn Feb 10, 2023
08e8719
XS::APItest::clone_with_stack(); check SI RC state
iabyn Feb 17, 2023
7bc62c6
Eliminate PERL_XXX_TMP_NORC
iabyn Feb 18, 2023
0665833
add perlguts section on a reference-counted stack
iabyn Feb 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -4731,6 +4731,7 @@ ext/XS-APItest/t/whichsig.t XS::APItest: tests for whichsig() and variants
ext/XS-APItest/t/win32.t Test Win32 specific APIs
ext/XS-APItest/t/xs_special_subs.t Test that XS BEGIN/CHECK/INIT/END work
ext/XS-APItest/t/xs_special_subs_require.t for require too
ext/XS-APItest/t/xsppwrap.t Tests for XSPP_wrapped() macro
ext/XS-APItest/t/xsub_h.t Tests for XSUB.h
ext/XS-APItest/typemap
ext/XS-APItest/XSUB-redefined-macros.xs XS code needing redefined macros.
Expand Down
11 changes: 10 additions & 1 deletion autodoc.pl
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
my $MRO_scn = 'MRO';
my $multicall_scn = 'Multicall Functions';
my $numeric_scn = 'Numeric Functions';
my $rpp_scn = 'Reference-counted stack manipulation';

# Now combined, as unclear which functions go where, but separate names kept
# to avoid 1) other code changes; 2) in case it seems better to split again
Expand Down Expand Up @@ -320,6 +321,14 @@
See L<perlform>.
EOT
},
$rpp_scn => {
header => <<~'EOT',
Functions for pushing and pulling items on the stack when the
stack is reference counted. They are intended as replacements
for the old PUSHs, POPi, EXTEND etc pp macros within pp
functions.
EOT
},
$signals_scn => {},
$site_scn => {
header => <<~'EOT',
Expand Down Expand Up @@ -1713,7 +1722,7 @@ sub output {

# We allow empty sections in perlintern.
if (! $section_info && $podname eq 'perlapi') {
warn "Empty section '$section_name'; skipped";
warn "Empty section '$section_name' for $podname; skipped";
next;
}

Expand Down
17 changes: 9 additions & 8 deletions av.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ Perl_av_reify(pTHX_ AV *av)
SvREFCNT_inc_simple_void(sv);
}
key = AvARRAY(av) - AvALLOC(av);
while (key)
AvALLOC(av)[--key] = NULL;
if (key)
Zero(AvALLOC(av), key, SV*);
AvREIFY_off(av);
AvREAL_on(av);
}
Expand Down Expand Up @@ -617,7 +617,6 @@ to it.
void
Perl_av_clear(pTHX_ AV *av)
{
SSize_t extra;
bool real;
SSize_t orig_ix = 0;

Expand Down Expand Up @@ -662,12 +661,9 @@ Perl_av_clear(pTHX_ AV *av)
SvREFCNT_dec(sv);
}
}
extra = AvARRAY(av) - AvALLOC(av);
if (extra) {
AvMAX(av) += extra;
AvARRAY(av) = AvALLOC(av);
}
AvFILLp(av) = -1;
av_remove_offset(av);

if (real) {
/* disarm av's premature free guard */
if (LIKELY(PL_tmps_ix == orig_ix))
Expand Down Expand Up @@ -886,6 +882,9 @@ Perl_av_unshift(pTHX_ AV *av, SSize_t num)
AvMAX(av) += i;
AvFILLp(av) += i;
AvARRAY(av) = AvARRAY(av) - i;
#ifdef PERL_RC_STACK
Zero(AvARRAY(av), i, SV*);
#endif
}
if (num) {
SV **ary;
Expand Down Expand Up @@ -939,8 +938,10 @@ Perl_av_shift(pTHX_ AV *av)
if (AvFILL(av) < 0)
return &PL_sv_undef;
retval = *AvARRAY(av);
#ifndef PERL_RC_STACK
if (AvREAL(av))
*AvARRAY(av) = NULL;
#endif
AvARRAY(av) = AvARRAY(av) + 1;
AvMAX(av)--;
AvFILLp(av)--;
Expand Down
68 changes: 28 additions & 40 deletions cop.h
Original file line number Diff line number Diff line change
Expand Up @@ -860,12 +860,14 @@ struct block_format {
} STMT_END

/* junk in @_ spells trouble when cloning CVs and in pp_caller(), so don't
* leave any (a fast av_clear(ary), basically) */
* leave any (a fast av_clear(ary), basically).
* New code should probably be using Perl_clear_defarray_simple()
* and/or Perl_clear_defarray()
*/
#define CLEAR_ARGARRAY(ary) \
STMT_START { \
AvMAX(ary) += AvARRAY(ary) - AvALLOC(ary); \
AvARRAY(ary) = AvALLOC(ary); \
AvFILLp(ary) = -1; \
av_remove_offset(ary); \
} STMT_END


Expand Down Expand Up @@ -1230,6 +1232,15 @@ struct stackinfo {
I32 si_markoff; /* offset where markstack begins for us.
* currently used only with DEBUGGING,
* but not #ifdef-ed for bincompat */

#ifdef PERL_RC_STACK
/* index of first entry in the argument
stack which is not ref-counted. If
set to 0 (default), all stack
elements are ref-counted */
I32 si_stack_nonrc_base;
#endif

#if defined DEBUGGING && !defined DEBUGGING_RE_ONLY
/* high water mark: for checking if the stack was correctly extended /
* tested for extension by each pp function */
Expand Down Expand Up @@ -1263,54 +1274,31 @@ typedef struct stackinfo PERL_SI;
# define PUSHSTACK_INIT_HWM(si) NOOP
#endif

/* for backcompat; use push_stackinfo() instead */

#define PUSHSTACKi(type) \
STMT_START { \
PERL_SI *next = PL_curstackinfo->si_next; \
DEBUG_l({ \
int i = 0; PERL_SI *p = PL_curstackinfo; \
while (p) { i++; p = p->si_prev; } \
Perl_deb(aTHX_ "push STACKINFO %d in %s at %s:%d\n", \
i, SAFE_FUNCTION__, __FILE__, __LINE__);}) \
if (!next) { \
next = new_stackinfo(32, 2048/sizeof(PERL_CONTEXT) - 1); \
next->si_prev = PL_curstackinfo; \
PL_curstackinfo->si_next = next; \
} \
next->si_type = type; \
next->si_cxix = -1; \
next->si_cxsubix = -1; \
PUSHSTACK_INIT_HWM(next); \
AvFILLp(next->si_stack) = 0; \
SWITCHSTACK(PL_curstack,next->si_stack); \
PL_curstackinfo = next; \
SET_MARK_OFFSET; \
STMT_START { \
PL_stack_sp = sp; \
push_stackinfo(type, 0);\
sp = PL_stack_sp ; \
} STMT_END

#define PUSHSTACK PUSHSTACKi(PERLSI_UNKNOWN)

/* POPSTACK works with PL_stack_sp, so it may need to be bracketed by

/* for backcompat; use pop_stackinfo() instead.
*
* POPSTACK works with PL_stack_sp, so it may need to be bracketed by
* PUTBACK/SPAGAIN to flush/refresh any local SP that may be active */
#define POPSTACK \
STMT_START { \
dSP; \
PERL_SI * const prev = PL_curstackinfo->si_prev; \
DEBUG_l({ \
int i = -1; PERL_SI *p = PL_curstackinfo; \
while (p) { i++; p = p->si_prev; } \
Perl_deb(aTHX_ "pop STACKINFO %d in %s at %s:%d\n", \
i, SAFE_FUNCTION__, __FILE__, __LINE__);}) \
if (!prev) { \
Perl_croak_popstack(); \
} \
SWITCHSTACK(PL_curstack,prev->si_stack); \
/* don't free prev here, free them all at the END{} */ \
PL_curstackinfo = prev; \
} STMT_END

#define POPSTACK pop_stackinfo()


#define POPSTACK_TO(s) \
STMT_START { \
while (PL_curstack != s) { \
dounwind(-1); \
rpp_obliterate_stack_to(0); \
POPSTACK; \
} \
} STMT_END
Expand Down
43 changes: 37 additions & 6 deletions deb.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,16 @@ Perl_debstackptrs(pTHX) /* Currently unused in cpan and core */
* and display the marks whose offsets are contained in addresses
* PL_markstack[mark_min+1 .. mark_max] and whose values are in the range
* of the stack values being displayed
* On PERL_RC_STACK builds, nonrc_base indicates the lowest
* non-reference-counted stack element (or 0 if none or not such a build).
* Display a vertical bar at this position.
*
* Only displays top 30 max
*/

STATIC void
S_deb_stack_n(pTHX_ SV** stack_base, I32 stack_min, I32 stack_max,
I32 mark_min, I32 mark_max)
I32 mark_min, I32 mark_max, I32 nonrc_base)
{
#ifdef DEBUGGING
I32 i = stack_max - 30;
Expand Down Expand Up @@ -171,7 +174,11 @@ S_deb_stack_n(pTHX_ SV** stack_base, I32 stack_min, I32 stack_max,
}
if (i > stack_max)
break;

PerlIO_printf(Perl_debug_log, "%-4s ", SvPEEK(stack_base[i]));

if (nonrc_base && nonrc_base == i + 1)
PerlIO_printf(Perl_debug_log, "| ");
}
while (1);
PerlIO_printf(Perl_debug_log, "\n");
Expand All @@ -182,6 +189,7 @@ S_deb_stack_n(pTHX_ SV** stack_base, I32 stack_min, I32 stack_max,
PERL_UNUSED_ARG(stack_max);
PERL_UNUSED_ARG(mark_min);
PERL_UNUSED_ARG(mark_max);
PERL_UNUSED_ARG(nonrc_base);
#endif /* DEBUGGING */
}

Expand All @@ -206,7 +214,13 @@ Perl_debstack(pTHX)
0,
PL_stack_sp - PL_stack_base,
PL_curstackinfo->si_markoff,
PL_markstack_ptr - PL_markstack);
PL_markstack_ptr - PL_markstack,
#ifdef PERL_RC_STACK
PL_curstackinfo->si_stack_nonrc_base
#else
0
#endif
);


#endif /* SKIP_DEBUGGING */
Expand Down Expand Up @@ -254,8 +268,16 @@ Perl_deb_stack_all(pTHX)
si_name_ix < C_ARRAY_LENGTH(si_names) ?
si_names[si_name_ix] : "????";
I32 ix;
PerlIO_printf(Perl_debug_log, "STACK %" IVdf ": %s\n",
(IV)si_ix, si_name);
PerlIO_printf(Perl_debug_log, "STACK %" IVdf ": %s%s\n",
(IV)si_ix, si_name,
#ifdef PERL_RC_STACK
AvREAL(si->si_stack)
? (si->si_stack_nonrc_base ? " (partial real)" : " (real)")
: ""
#else
""
#endif
);

for (ix=0; ix<=si->si_cxix; ix++) {

Expand Down Expand Up @@ -320,7 +342,10 @@ Perl_deb_stack_all(pTHX)
}
if (CxTYPE(&(si_n->si_cxstack[i])) == CXt_SUBST)
continue;
cx_n = &(si_n->si_cxstack[i]);
if (si_n->si_cxix >= 0)
cx_n = &(si_n->si_cxstack[i]);
else
cx_n = NULL;
break;
}

Expand All @@ -333,7 +358,13 @@ Perl_deb_stack_all(pTHX)
}

deb_stack_n(AvARRAY(si->si_stack),
stack_min, stack_max, mark_min, mark_max);
stack_min, stack_max, mark_min, mark_max,
#ifdef PERL_RC_STACK
si->si_stack_nonrc_base
#else
0
#endif
);

if (CxTYPE(cx) == CXt_EVAL || CxTYPE(cx) == CXt_SUB
|| CxTYPE(cx) == CXt_FORMAT)
Expand Down
4 changes: 2 additions & 2 deletions dist/threads/lib/threads.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use 5.008;
use strict;
use warnings;

our $VERSION = '2.34'; # remember to update version in POD!
our $VERSION = '2.35'; # remember to update version in POD below!
my $XS_VERSION = $VERSION;
$VERSION = eval $VERSION;

Expand Down Expand Up @@ -134,7 +134,7 @@ threads - Perl interpreter-based threads

=head1 VERSION

This document describes threads version 2.34
This document describes threads version 2.35

=head1 WARNING

Expand Down
16 changes: 10 additions & 6 deletions dist/threads/threads.xs
Original file line number Diff line number Diff line change
Expand Up @@ -611,16 +611,20 @@ S_ithread_run(void * arg)
int ii;
int jmp_rc;

dSP;
#ifdef PERL_RC_STACK
assert(rpp_stack_is_rc());
#endif

ENTER;
SAVETMPS;

/* Put args on the stack */
PUSHMARK(SP);
PUSHMARK(PL_stack_sp);
rpp_extend(len);
for (ii=0; ii < len; ii++) {
XPUSHs(av_shift(params));
SV *sv = av_shift(params);
rpp_push_1(sv);
}
PUTBACK;

jmp_rc = S_jmpenv_run(aTHX_ 0, thread, &len, &exit_app, &exit_code);

Expand All @@ -633,12 +637,12 @@ S_ithread_run(void * arg)
#endif

/* Remove args from stack and put back in params array */
SPAGAIN;
for (ii=len-1; ii >= 0; ii--) {
SV *sv = POPs;
SV *sv = *PL_stack_sp;
if (jmp_rc == 0 && (thread->gimme & G_WANT) != G_VOID) {
av_store(params, ii, SvREFCNT_inc(sv));
}
rpp_popfree_1();
}

FREETMPS;
Expand Down
6 changes: 2 additions & 4 deletions doio.c
Original file line number Diff line number Diff line change
Expand Up @@ -2225,7 +2225,6 @@ Perl_do_print(pTHX_ SV *sv, PerlIO *fp)
I32
Perl_my_stat_flags(pTHX_ const U32 flags)
{
dSP;
IO *io;
GV* gv;

Expand Down Expand Up @@ -2265,7 +2264,7 @@ Perl_my_stat_flags(pTHX_ const U32 flags)
== OPpFT_STACKED)
return PL_laststatval;
else {
SV* const sv = TOPs;
SV* const sv = *PL_stack_sp;
const char *s, *d;
STRLEN len;
if ((gv = MAYBE_DEREF_GV_flags(sv,flags))) {
Expand Down Expand Up @@ -2302,10 +2301,9 @@ I32
Perl_my_lstat_flags(pTHX_ const U32 flags)
{
static const char* const no_prev_lstat = "The stat preceding -l _ wasn't an lstat";
dSP;
const char *file;
STRLEN len;
SV* const sv = TOPs;
SV* const sv = *PL_stack_sp;
bool isio = FALSE;
if (PL_op->op_flags & OPf_REF) {
if (cGVOP_gv == PL_defgv) {
Expand Down
3 changes: 1 addition & 2 deletions doop.c
Original file line number Diff line number Diff line change
Expand Up @@ -1183,8 +1183,7 @@ Perl_do_vop(pTHX_ I32 optype, SV *sv, SV *left, SV *right)
* values, or key-value pairs, depending on PL_op.
*/

OP *
Perl_do_kv(pTHX)
PP_wrapped(do_kv, 1, 0)
{
dSP;
HV * const keys = MUTABLE_HV(POPs);
Expand Down
Loading