Closed Bug 1271854 Opened 8 years ago Closed 8 years ago

Allow setting multiple gc zeal values in GCRuntime::parseAndSetZeal

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla49
Tracking Status
firefox49 --- fixed

People

(Reporter: ehsan.akhgari, Assigned: ehsan.akhgari)

Details

Attachments

(3 files)

Right now we only support one gc zeal value there, but there's no good reason for that.  Can we extend that to support a syntax like |NN[,MM](;LL[,OO])*|?
Flags: needinfo?(terrence)
(In reply to :Ehsan Akhgari (busy, don't ask for review please) from comment #0)
> Right now we only support one gc zeal value there, but there's no good
> reason for that.  Can we extend that to support a syntax like
> |NN[,MM](;LL[,OO])*|?

I had a patch for this like 4 years ago; we decided it wasn't worth the extra parsing code at the time. I think it's definitely worth resurrecting now that it's seeing much wider usage.

The requested syntax looks perfectly reasonable. Additionally, I'd like to give each of the numbers a proper name so that it's not just a pile of ints and can be read and remembered by a mere human.
Flags: needinfo?(terrence)
I'll take a stab at this.
Assignee: nobody → ehsan
FWIW as I was implementing these changes I realized that my proposed format string is stupid since there is only one frequency number.  I implemented the simpler |level(;level)*[,freq]| syntax.
This affects both the environment variable JS_GC_ZEAL, and the --gc-zeal
argument to the JS shell.
Attachment #8751886 - Flags: review?(terrence)
This will ensure that the GC zeal argument won't get truncated needlessly.
Attachment #8751888 - Flags: review?(terrence)
Comment on attachment 8751886 [details] [diff] [review]
Part 1: Allow specifying multiple GC zeal levels

Review of attachment 8751886 [details] [diff] [review]:
-----------------------------------------------------------------

::: js/src/jsgc.cpp
@@ +1267,5 @@
>  
> +            size_t offset = strspn(str, "0123456789");
> +            const char* p = str + offset;
> +            if (!*p || *p == ';')
> +                frequency = JS_DEFAULT_ZEAL_FREQ;

Add braces here: braces are required around all blocks in an if/else chain if any block in the chain requires braces.

@@ +1285,5 @@
> +            return false;
> +        }
> +    } while (!foundFrequency &&
> +             (str = strchr(str, ';')) != nullptr &&
> +             str++);

Parsing in C is the scariest thing ever. If this were enabled in non-DEBUG builds I would demand *so many* tests. As is, it's probably not worth the time.

@@ +1289,5 @@
> +             str++);
> +
> +    for (auto z : zeals) {
> +        setZeal(z, frequency);
> +    }

No braces on this for loop.
Attachment #8751886 - Flags: review?(terrence) → review+
Comment on attachment 8751887 [details] [diff] [review]
Part 2: Allow specifying zeal modes by name as well

Review of attachment 8751887 [details] [diff] [review]:
-----------------------------------------------------------------

Awesome!

::: js/src/jsgc.cpp
@@ +277,5 @@
> +#define CHECK_ZEAL(name, value)                                                \
> +    static_assert(ZealMode::Limit >= ZealMode::name,                           \
> +                  "ZealMode::Limit shouldn't be smaller than " #name);
> +JS_FOR_EACH_ZEAL_MODE(CHECK_ZEAL)
> +#undef CHECK_ZEAL

Nice!

::: js/src/jsgc.h
@@ +1218,5 @@
> +            _(IncrementalMultipleSlices, 10)   \
> +            _(IncrementalMarkingValidator, 11) \
> +            _(ElementsBarrier, 12)             \
> +            _(CheckHashTablesOnMinorGC, 13)    \
> +            _(Compact, 14)

It is traditional in SpiderMonkey to use the name |D| for the callable here instead of |_|. I've been using |_| for parameters that I'm not expanding. This use should be hygenic, but let's stick with D for now regardless.
Attachment #8751887 - Flags: review?(terrence) → review+
Comment on attachment 8751888 [details] [diff] [review]
Part 3: Avoid saving the GC zeal string inside the JS shell

Review of attachment 8751888 [details] [diff] [review]:
-----------------------------------------------------------------

::: js/src/shell/js.cpp
@@ +7057,5 @@
>      rt->profilingScripts = enableCodeCoverage || enableDisassemblyDumps;
>  
>  #ifdef JS_GC_ZEAL
> +    if (gZealBits && gZealFrequency) {
> +#define ZEAL_MODE(name, value)                     \

Use |_| instead of |name|, since you're not using it.
Attachment #8751888 - Flags: review?(terrence) → review+
(In reply to Terrence Cole [:terrence] from comment #7)
> @@ +1285,5 @@
> > +            return false;
> > +        }
> > +    } while (!foundFrequency &&
> > +             (str = strchr(str, ';')) != nullptr &&
> > +             str++);
> 
> Parsing in C is the scariest thing ever. If this were enabled in non-DEBUG
> builds I would demand *so many* tests. As is, it's probably not worth the
> time.

My hands were shaking so much that I could barely type when I was writing this. :-)

FWIW I did test everything that I could think of manually, but wasn't sure how I'd add tests for them.  I'd still be happy to maybe write a C++ tests verifying this if you'd like me to!
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: