Commit Graph

650 Commits

Author SHA1 Message Date
Avi Halachmi (:avih)
b5eccea611 gc: use proportional instead of fixed threshold
The problem with a fixed count value is that it result in varying
degrees of performance and memory impact proportions depending on
the usage pattern of each script.

E.g. if a script keeps using the same 1M objects, then a threshold of
10K objects will result in GC cycles which free only 1% of objects,
which is hugely wasteful in terms of performance. On the other hand,
if a script only uses 100 objects then a threshold of 10K means it
uses 100 times more memory than it actually needs before GC triggers.

Now the threshold is a target memory usage factor (of the minimum
needed memory) which GC tries to aim at. This makes the GC impact
have constant proportions.

The default aims at a memory usage factor of 5, i.e. 80% garbage
and 20% remaining on each GC cycle.

The factor is only a target/goal because the actual overhead is not
known until GC completes. However, most scripts exhibit consistent
enough behavior such that the real overhead is within 10% or less of
the goal even when the usage pattern changes over time.

Within the v8 bench test suite, the actual GC threshold count varies
between ~50K to ~500K, where only one test (raytrace.js) stabilizes on
less than 10K (the previous fixed default) - at about 9K and its score
decreases by ~5%.

The splay.js score increases about x12 fold (or x50 fold from the
previous commit which counts properties), other tests quite a bit
less or none at all, and the overall score increases by nearly 40%.

Also, change the count type from int to unsigned int to get twice the
range. Preferably we should make it even bigger, maybe uint64_t.

For instance the splay.js v8 bench test surpasses million non-garbage
allocations within few seconds (that's why its score increased so much
with a proportional overhead), and the default GC threshold is 5 times
that number.
2020-07-23 12:40:09 +02:00
Avi Halachmi (:avih)
c4c1524e97 gc: don't ignore property allocations count
They're not negligible in the overall count.

This decreases the performance of scripts which use objects with many
properties because the GC threshold remains the same (10K) but it's
reached quicker due to counting more allocations, so GC is more
frequent and wastes more overall time.

Good example of the performance impact is the splay.js v8 bench test,
where this commit reduces its score by a factor of 5.

We're not changing the threshold because it's arbitrary anyway, but the
next commit will change it in a way which allows more proportional
control of the GC overhead.
2020-07-23 12:40:09 +02:00
Avi Halachmi (:avih)
ed33bc01d5 gc: fix incorrect free of some objects
When scanning an iterator object, the iterated object was marked
unconditionally. Now it's marked only if it's not already marked - like
all other object markings.

This code was incorrect for some years, but wasn't really an issue
before commit 331c5ec because marking an object twice simply used some
more CPU cycles but otherwise without issues - unless there were cycles,
and apparently typically/always there never were cycles with iterators,
so it was hard/impossible to behave badly.

However, since 331c5ec, marking an object means inserting it into a
linked list where the list nodes are part of the object, therefore
marking the same object twice now creates a broken linked list.

A broken list means that some objects are skipped while scanned, which
means they don't get marked even when they should, and as a result
freed incorrectly while still referenced by other objects, resulting in
random errors related to use-after-free.
2020-07-06 11:04:32 +02:00
Tor Andersson
ad3817fcc3 Silence gcc warning about overflow. 2020-07-06 11:04:32 +02:00
Tor Andersson
9f3e141d80 Fix typo in lexlinecomment where it did not detect EOF properly. 2020-06-25 13:29:53 +02:00
Tor Andersson
ac25ac54fa Fix typo in comment. 2020-05-27 17:07:41 +02:00
Sebastian Rasmussen
02bdafb46c Fix a number of typos. 2020-05-27 12:32:32 +02:00
Tor Andersson
832e069049 Support 4-byte UTF-8 sequences.
The following functions are no longer restricted to 16-bit integer values:

	String.fromCharCode()
	String.prototype.charCodeAt()

repr() will not escape SMP characters, as doing so would require conversion to
surrogate pairs, but will encode these characters as UTF-8. Unicode characters
in the BMP will still be escaped with \uXXXX as before.

JSON.stringify() only escapes control characters, so will represent all non-ASCII
characters as UTF-8.

We do no automatic conversions to/from surrogate pairs. Code that worked with
surrogate pairs should not be affected by these changes.
2020-05-27 12:32:32 +02:00
Tor Andersson
0261579d78 Support embedded 0 in strings by using modified UTF-8. 2020-05-27 12:32:32 +02:00
Tor Andersson
331c5ecbac Issue 133: Eliminate recursion in GC scanning phase.
Use a queue instead of recursion to scan reachable objects.
2020-05-27 12:32:32 +02:00
Tor Andersson
8c5f2f24c7 Don't allow setting a property when the prototype's property is read-only. 2020-05-27 12:32:32 +02:00
Tor Andersson
90aca80865 Fix potential memory corruption when jsV_newmemstring fails to allocate.
Don't change the value until the allocation has succeeded.
1.0.7
2020-03-17 14:10:18 +01:00
Tor Andersson
8f12e045f6 Return "[object Iterator]" when running toString on an iterator value. 2020-03-17 14:10:18 +01:00
Tor Andersson
84752905b9 Document the expected behavior of js_Put correctly. 2020-03-17 13:11:18 +01:00
Tor Andersson
fe63f4cb3c Note that js_Report callback must not throw an exception.
Nor should it call any functions that may throw exceptions.
2020-03-17 13:11:18 +01:00
Tor Andersson
e3f04e7f96 Check for empty string in js_isarrayindex. 2020-02-19 10:24:33 +01:00
Tor Andersson
11c894d0c1 Tweak default recursion limit. 2020-01-23 12:06:06 +01:00
Tor Andersson
6f93cab7ff Fix enumerability of Error and Function properties.
The Error.message, Error.stackTrace, Function.prototype properties were
defined with the wrong attributes.

x
2020-01-23 12:06:06 +01:00
Tor Andersson
e082e6e61c Check for leading zero in js_isarrayindex that caused false positives.
We're supposed to check whether a string turned into an integer and back
is itself, while also returning the value of the integer. We were
unintentionally allowing integers with leading zero through.
2020-01-20 12:39:58 +01:00
Tor Andersson
fe71080c59 Bug 698496: Handle leap years correctly in the Date constructor.
InLeapYear expects the parameter to be a timestamp and not a year.
Use DaysInYear instead.

Thanks to Robert Rosendahl for spotting this.
2020-01-10 11:22:09 +01:00
Tor Andersson
8ee595bee7 Bug 701355: Fix separate compilation issues that have crept in.
We normally build as one compilation unit with "one.c" but we should
still be able to build each source file as a separate compilation unit
if desired.
2020-01-10 11:09:22 +01:00
Tor Andersson
d248b0ce18 Bug 701886: Always create new scope for eval().
Distinguish eval code from script code.
2020-01-02 14:37:05 +01:00
Tor Andersson
d0225981aa Update COPYING copyright year. 2020-01-02 14:37:05 +01:00
Tor Andersson
c695b53a75 Issue 117: Skip first line if it starts with a shebang when loading files.
A file that starts with #! is going to be a syntax error anyway, so we
won't be changing the behavior of any other valid source files with this
fix.
2020-01-02 14:30:43 +01:00
Tor Andersson
457f87b17b Issue 128: Support property list as replacer argument in JSON.stringify.
Also adds helper functions js_isstringobject and js_isnumberobject.
2020-01-02 14:22:00 +01:00
isRyven
d9f555652a Fix date setMonth and setUTCMonth processed wrong optional argument 2020-01-02 12:42:09 +01:00
isRyven
ddd1e5ebe6 Issue 126: accept String and Number objects as space parameter 2020-01-02 12:42:09 +01:00
Tor Andersson
e690d31ee3 Issue 122: Allow floating point return values from Array.sort callback. 2020-01-02 12:42:09 +01:00
Tor Andersson
b4484ab18a Issue 118: Add REG_ to limit defines, and use REG_MAXSUB in header. 2020-01-02 12:42:09 +01:00
gardhr
8c868344b2 Issue 114: Allow compile time limits to be configured. 2019-11-28 11:39:55 +01:00
Tor Andersson
6b522a0b1f Issue 115: Fix compilation of small floating point numbers.
The check for whether a number is an integer or not failed on number
too small because we were using an addition in the test.
2019-11-28 11:31:09 +01:00
Tor Andersson
6e62eb0923 Issue 113: Add a js_delglobal function. 2019-11-19 12:56:22 +01:00
Tor Andersson
3d3f473c39 Bug 701887: Create arguments if eval is present.
We can't know at compile time that the 'arguments' object will not be used
from the eval statement, so err on the side of caution and always create
the arguments object if eval can be called.
2019-11-19 12:53:28 +01:00
Tor Andersson
69b312d13b Fix coverity issue: memory corruption due to overlapping copy. 2019-09-06 12:15:31 +02:00
Tor Andersson
16049bbbdc Issue 107: Depend only on the exact files needed for install targets. 2019-07-03 20:25:19 +02:00
Tor Andersson
14dc9355bd Issue 102: Fix ASAN build when using GCC.
GCC's address sanitizer sets the __SANITIZE_ADDRESS__ macro instead.
1.0.6
2019-06-12 17:23:46 +02:00
Tor Andersson
e2b59201d5 Issue 105: Fix NULL dereferencing in regexp compiler.
"x(?:)" parses to Cat(Char(x), Empty), but the compiler couldn't handle
an empty right hand side of the Cat node.
2019-06-11 15:48:39 +02:00
Tor Andersson
eeea83a807 Issue 102: Workaround for address-sanitizer default realloc behavior. 2019-06-11 15:48:39 +02:00
Tor Andersson
bd79071a6f Add make uninstall target. 2019-05-27 11:19:26 +02:00
Tor Andersson
b9e14e53a0 Revert "Pacify valgrind: it doesn't know realloc(p, 0) is equivalent to free(p)."
This reverts commit 86feee5b7b.
2019-04-05 18:36:26 +02:00
Tor Andersson
00d4606c3b Bug 700937: Limit recursion in regexp matcher.
Also handle negative return code as an error in the JS bindings.
2019-04-04 12:41:04 +02:00
Tor Andersson
1e5479084b Bug 700947: Add missing ENDTRY opcode in try/catch/finally byte code.
In one of the code branches in handling exceptions in the catch block
we forgot to call the ENDTRY opcode to pop the inner hidden try.
This leads to an unbalanced exception stack which can cause a crash
due to us jumping to a stack frame that has already been exited.
2019-04-04 12:41:02 +02:00
Tor Andersson
da632ca08f Bug 700938: Fix stack overflow in numtostr as used by Number#toFixed().
32 is not enough to fit sprintf("%.20f", 1e20).
We need at least 43 bytes to fit that format.
Bump the static buffer size.
2019-04-02 10:55:22 +02:00
Tor Andersson
0c03f9c057 Add missing break statement. 2019-03-29 19:40:44 +01:00
Tor Andersson
52c22be9c4 Fix MSVC compile errors. 2019-03-25 21:00:59 +01:00
Tor Andersson
bb65f18fcc Set 'lightweight' and 'arguments' during compile pass.
Avoid doing a separate analysis pass by using the same bytecode for both
lightweight and non-lightweight functions.
2019-03-22 14:00:20 +01:00
Tor Andersson
f5de9d4d2e Remove line opcode in favor of storing the line for each instruction. 2019-03-22 14:00:20 +01:00
Tor Andersson
20d0fa04df Simplify opcodes: numbers and integer constants. 2019-03-22 14:00:20 +01:00
Tor Andersson
603977ae5b Add repr() function to shell, and use it in the REPL. 2019-03-22 14:00:20 +01:00
Tor Andersson
ffe0ca7d7f Issue 95: Improve error message when trying to call a non-callable. 2019-03-18 14:11:34 +01:00