Currently wasm ignores GCs triggered by allocation, which can lead to unbounded
memory growth when running purely in wasm. Making the GC interrupt also
interrupt wasm fixes this.
Differential Revision: https://phabricator.services.mozilla.com/D190669
The refactored assertions were actually slightly more strict that the original
ones and it turns out that we can pass start == end here.
Differential Revision: https://phabricator.services.mozilla.com/D190447
Sorry this is not a particularly easy patch to review. But it should be
mostly straight-forward.
I kept Document::Dispatch mostly for convenience, but could be
cleaned-up too / changed by SchedulerGroup::Dispatch. Similarly maybe
that can just be NS_DispatchToMainThread if we add an NS_IsMainThread
check there or something (to preserve shutdown semantics).
Differential Revision: https://phabricator.services.mozilla.com/D190450
For objects with dynamic slots allocations, NativeObject::slots_ stores a
pointer that points just past the end of the slots header. For zero-capacity
allocations this pointer points outside the allocation itself.
Currently this causes valgrind to think that the slots allocation is leaked. To
fix this the patch adds an extra unused slot to zero capacity slots allocations
on valgrind builds only.
Differential Revision: https://phabricator.services.mozilla.com/D190274
Bug 1846474 added a mechanism to detect incorrectly placed TrapSites. This
was complete for x86_{32,64} and arm64, but was incomplete and disabled for
arm32.
This patch completes and enables support for arm32. Most of the work --
instruction recognition for arm32 -- was already done in bug 1846474, so this
patch merely changes the return type of a few arm32 MacroAssembler routines
from `void` to `FaultingCodeOffset`, hence completing the required plumbing.
Differential Revision: https://phabricator.services.mozilla.com/D190148
mmap with PROT_EXEC fails on some Android devices, and is not required
for simpleperf to function, so avoid using that flag on Android.
Depends on D190289
Differential Revision: https://phabricator.services.mozilla.com/D190290
In `NewMaybeExternalString` we have a fast path for short Latin1 strings. This case is
very common.
Changing the cache to handle these too is very effective: the `lookupInline` method
has a hit rate of at least 90% on Speedometer 3.
Differential Revision: https://phabricator.services.mozilla.com/D190206
Reading this code I found I did not know what the position the start was being
set to. The patch renames this to make it clear that it's being set to the
current position.
Differential Revision: https://phabricator.services.mozilla.com/D190191
These members specify the start of the nursery (usually they are zero, but can
be different in generational zeal mode). They are constant between collections.
Calling them 'current' implies that they change often and this could lead to
confusion with currentChunk, which does change between collections. It's
simpler to remove the 'current'.
Differential Revision: https://phabricator.services.mozilla.com/D190189
This is a pure refactoring that just moves the inline string logic out into NewDependentString so that all *String::new_ creation functions are low-level and return a string of the class they are called on.
Differential Revision: https://phabricator.services.mozilla.com/D190127
This doesn't cover all the page loads, need to run some more performance tests before using this everywhere.
Depends on D189917
Differential Revision: https://phabricator.services.mozilla.com/D189918
This assertion is unnecessary and doesn't hold. It was added to replace a check
for permanent atoms which is now handled by the mark check, since permanent
atoms are now always marked.
Differential Revision: https://phabricator.services.mozilla.com/D190021
In the previous patches, Sprinter was given the ability to generate JS strings,
in order to avoid some of the use case where Sprinter allocated a buffer, just
to see it being copied once more to make a JSString out of the generated
content. Except that when compiling against jemalloc, we allocate JSString in a
different arena than the default one.
This patch is a follow up, which rename Sprinter to StringPrinter and create 2
variants named Sprinter (String allocation) and JSSprinter (JSString
allocation).
In addition to the renaming, we can now specialize the JSSprinter to use the
StringBufferArena as well as enforcing the use of a JSContext and the reporting
of out-of-memory. As opposed to the Sprinter interface which keeps the old
flexibility.
Differential Revision: https://phabricator.services.mozilla.com/D189150
`putAsciiPrintable` was added temporarily as a substitute for externalizing the
logic done by `QuoteString`, while providing an interface which is as efficient.
Now, `EscapePrinter` is used to replace the content of `QuoteString` while
providing the same implementation, except that it is based on `put` instead of
`putAsciiPrintable`. The `EscapePrinter` already provides the guarantees that
are asserted by `putAsciiPrintable`, thus there is no longer any need for it.
As this patch set introduced `putAsciiPrintable`, there is not yet any external
consumer of it, and `EscapePrinter` should cover all use cases where non-ascii
inputs are provided.
Differential Revision: https://phabricator.services.mozilla.com/D183760
The previous patch reimplemented QuoteString to use a `StringSegmentRange`,
which should avoid mutating the inner parts of `JSRope`, while remaining fast on
`JSAtom`-s.
As the StringSegmentRange does not need to allocate with `ensureLinear`, then
all the failures are reported by the `put` functions using the `GenericPrinter`
mechanism, and the `release` functions of `Sprinter` would report the failure if
any.
Thus, there is no need for retuning a boolean value anymore from `QuoteString`
and `JSONQuoteString`, while this is still necessary to check the returned value
variant of `QuoteString` which returns `UniqueChars` by using the `release`
function of `Sprinter`.
Differential Revision: https://phabricator.services.mozilla.com/D183759
When reporting failure, we have to prevent continuation iterating over the
string segments, and stop early, as well as not ignoring the errors.
Differential Revision: https://phabricator.services.mozilla.com/D188248
`QuoteString` is today only available as a mean to serialize a `JSString` to a
`Sprinter`, or by making an extra temporary allocation whch is most likely
discarded once the serialized content has been used once.
This implementation provide a generic escaping mechanism, named `EscapePrinter`,
which can be used on top of any existing Printer class, and with any escaping
logic such as different quotes, or different quotation marks if needed. The
different quoting strategies are implemented using a class which provides
`isSafeChar` and `convertInto` to normalize the `JSString` input characters into
characters which are properly encoded for the Printer.
This change keep the original `QuoteString` behavior, while replacing its
fallible implementation by an infallible implementation. `QuoteString` had an
undocummented side-effect of linearizing the strings while reading them, which
causes memory allocation and potential GC failures. This change replaces the
`ensureLinear` call by the new `GenericPrinter::putString` function which relies
on `StringSegmentRange` to iterate over the string fragments and serialize the
content which does not have the same side-effects.
If performance issue arise from this modification, calls to `ensureLinear`
should be added before the `QuoteString` calls.
Differential Revision: https://phabricator.services.mozilla.com/D183758
`putString` requires a JSContext, and it is taken out of Sprinter, which does
not make much sense. Making it explicit that a JSContext is required to print
JSString would make things simpler for users instead of failing during the
execution.
Differential Revision: https://phabricator.services.mozilla.com/D187202
Sprinter::jsprintf is nowadays the same as GenericPrinter::printf which Sprinter
inherit from. This patch removes all calls to Sprinter::jsprintf and replaces
them by Sprinter::printf.
The advantage of using GenericPrinter::printf is that this reduce the dependency
on Sprinter-specific interface and moves us toward being able to move more
consumers over to the GenericPrinter.
Differential Revision: https://phabricator.services.mozilla.com/D181500
Now that Sprinter::put and Sprinter::jsprintf functions are infallible, there is
no need to return a boolean from Nursery::printProfileDurations and
Statistics::printProfileTimes functions.
Differential Revision: https://phabricator.services.mozilla.com/D181499
Remove the boolean returned value of printing functions of the GenericPrinter
and all descendant classes.
The goal being that error checking is the responsibility of the wrapping
function in charge of the GenericPrinter, and that functions in charge of
providing content should assume that everything is always written successfully.
This patch only look at the GenericPrinter methods, consumers of these functions
would be updated in subsequent patches.
Differential Revision: https://phabricator.services.mozilla.com/D181498
As we are going to remove the returned value, and to be extra cautious, we skip
future re-entry in case of previous failures.
Differential Revision: https://phabricator.services.mozilla.com/D181497
As functions are made infallible, only the 2 release functions are reporting
errors. The advantage of this approach is that the error reporting and checking
would only happen in the release functions calls in the future. This enables
the upcoming set of patches to change the return type of put functions to make
them infallible, reduce the number of visible branches in debugging code.
This makes the Sprinter class more like a "Sink allocator", where the smell of
allocation failures does not propagate immediatly through the sinking water until
all the water has been through.
Differential Revision: https://phabricator.services.mozilla.com/D181496
When using Sprinter::string, one assumes that out-of-memory errors have been
reported earlier. As the code is being converted to be infallible, the
out-of-memory is thus needed when the release function is called. This change
replaces all Sprinter::string by Sprinter::release and explicit the error
checking code path which would be relevant when the Sprinter::put function would
become infallible in follow-up patches.
Differential Revision: https://phabricator.services.mozilla.com/D181495
Sprinter::releaseJS centralize a mechanism which used in many places across the
JS engine, and replaces it with a single function call as well as democratising
the proper handling of UTF8 which might be added to Sprinter allocated strings.
Differential Revision: https://phabricator.services.mozilla.com/D181494
Sprinter already create strings, and the ExpressionDecompiler duplicates this
logic to copy the content of the Sprinter buffer. While there is a benefit in
case we over-allocated ahead using Sprinter, this should still reduce the peak
memory allocation.
Differential Revision: https://phabricator.services.mozilla.com/D181489
QuoteString is currently specialized with a Sprinter argument, but to do that it
relies on the `operator[]`, which implies being able to read the bytes. While
there is no issue today, this goes against making the *Printers infallible.
Thus, this change moves the append logic to a dedicated `putAsciiPrintable`,
removing the `getOffset()` and `operator[]` usage from `QuoteString`.
Differential Revision: https://phabricator.services.mozilla.com/D181488
The `GenericPrinterPrintTarget` uses the same `GenericPrinter`, which already
handles the out-of-memory reporting. Thus, there is no need to report it once
more in `GenericPrinter::vprintf`.
Differential Revision: https://phabricator.services.mozilla.com/D181487