summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Stakenvicius <axs@gentoo.org>2017-02-27 17:35:15 -0500
committerIan Stakenvicius <axs@gentoo.org>2017-02-27 18:39:01 -0500
commitc6b9e11e5e556f1eb6a1446b9f789b97af743e19 (patch)
tree04a87c2296adc7713ec8f9387baa3eabc585c796 /dev-lang/spidermonkey
parentx11-base/xorg-server: Drop dependency on media-libs/freetype. (diff)
downloadgentoo-c6b9e11e5e556f1eb6a1446b9f789b97af743e19.tar.gz
gentoo-c6b9e11e5e556f1eb6a1446b9f789b97af743e19.tar.bz2
gentoo-c6b9e11e5e556f1eb6a1446b9f789b97af743e19.zip
dev-lang/spidermonkey: add mozjs38 release for gnome-3.23
Package-Manager: portage-2.3.3
Diffstat (limited to 'dev-lang/spidermonkey')
-rw-r--r--dev-lang/spidermonkey/Manifest1
-rw-r--r--dev-lang/spidermonkey/files/mozjs38-1269317.patch124
-rw-r--r--dev-lang/spidermonkey/files/mozjs38-fix-tracelogger.patch605
-rw-r--r--dev-lang/spidermonkey/files/spidermonkey-38-jsapi-tests.patch16
-rw-r--r--dev-lang/spidermonkey/metadata.xml4
-rw-r--r--dev-lang/spidermonkey/spidermonkey-38.2.1_rc0.ebuild145
6 files changed, 894 insertions, 1 deletions
diff --git a/dev-lang/spidermonkey/Manifest b/dev-lang/spidermonkey/Manifest
index 45577ad65370..d6a76976d6e4 100644
--- a/dev-lang/spidermonkey/Manifest
+++ b/dev-lang/spidermonkey/Manifest
@@ -1,4 +1,5 @@
DIST js-1.7.0.tar.gz 1165607 SHA256 44363f0f3895800ee6010763eae90c0d15ed28e07d783bc7b3c607ce98d8668b SHA512 9d9fbd9c1dae969ca19ddb0f977ac56f3e0479ec393b859de252fcdd8b7fc325e80399073540884ed365ce56a3219be34c0db9300d5e50f32969660c90527e51 WHIRLPOOL 8044b306b3a1f0abed5ac8a6bf4f9ed70e1ebc6f83f44934a6306d9ed68cd73124f82e40430d764f158377031f5ee986595e58fdb52259ab6a3a8674eaf4eed1
DIST js185-1.0.0.tar.gz 6164605 SHA256 5d12f7e1f5b4a99436685d97b9b7b75f094d33580227aa998c406bbae6f2a687 SHA512 2af7122a7c7007fd7b6668776fe1222515a810b3e43bbf0f76b8f94e1ef406ffd3fb5ccec393021b00274c05b38a77235bc8d6886994c56762fcaf0aa7cf6718 WHIRLPOOL 58b372713275874d3ae3c6b58c12c56bf8d17d024d591e321538bcdd8e615332e41655954368ce86b90e970209e3fd650c39d931000880f5ec22cb044b5d7a4e
DIST mozjs-24.2.0.tar.bz2 15624530 SHA256 e62f3f331ddd90df1e238c09d61a505c516fe9fd8c5c95336611d191d18437d8 SHA512 49805e256f6fa797505c01b7596d5bb941ed7a2454862c52ed42ad48b5ae4540b777e77ed8da1b98c89f8622ed2c76052187983687008a4ff53594addb328df4 WHIRLPOOL ea74d19c79b1a0fe407e2803900c49c23e8b76444fb4e20995072c3c59427e8df1895df04f2f4de779a1c58cd1166dd97aeaf7564350832011efe89dbcf9583e
+DIST mozjs-38.2.1.rc0.tar.bz2 25012381 SHA256 01994c758174bc173bcf4960f05ecb4da21014f09641a63b2952bbf9eeaa8b5c SHA512 60262c7619cc418569aec81775a671105acbc5bf372273828868f2fbbbc4ea33f78380f7455710816bfcdae828fb4115a08234d599cb30d0db859fcba17f019d WHIRLPOOL b1661859dc41a61317a48a8ee34cab53a369f37067c6565db2c890c596411e51981e0e64f81c5f5bd2bc2ff943493d972b00a5984b99de6e07ce16c07f784cb7
DIST mozjs17.0.0.tar.gz 6778934 SHA256 321e964fe9386785d3bf80870640f2fa1c683e32fe988eeb201b04471c172fba SHA512 39b68aeb9f712f146778d8b68ee795709a1372c8ab893a222af4eb34882427d6f5cf877e743d6cb2f1b4348c194d8f3774f00cb775b03515b34b49560b748be4 WHIRLPOOL 4df7b51577787194065162b09d2c3dda849c13fa901305f9925d4ca5d38bb7f8e2daa943099e003fb9d11f9264ae2d77ccf04e5eea11e3ddcb624b504b99d52f
diff --git a/dev-lang/spidermonkey/files/mozjs38-1269317.patch b/dev-lang/spidermonkey/files/mozjs38-1269317.patch
new file mode 100644
index 000000000000..39cc6809af57
--- /dev/null
+++ b/dev-lang/spidermonkey/files/mozjs38-1269317.patch
@@ -0,0 +1,124 @@
+from https://github.com/GNOME/jhbuild/blob/master/patches/mozjs38-1269317.patch
+
+--- a/js/src/jit/RegisterSets.h 2017-02-10 17:33:06.210702431 -0800
++++ b/js/src/jit/RegisterSets.h 2017-02-10 17:43:52.877514146 -0800
+@@ -7,7 +7,6 @@
+ #ifndef jit_RegisterSets_h
+ #define jit_RegisterSets_h
+
+-#include "mozilla/Alignment.h"
+ #include "mozilla/MathAlgorithms.h"
+
+ #include "jit/JitAllocPolicy.h"
+@@ -26,8 +25,8 @@
+ Code code_;
+
+ public:
+- AnyRegister()
+- { }
++ AnyRegister() = default;
++
+ explicit AnyRegister(Register gpr) {
+ code_ = gpr.code();
+ }
+@@ -156,7 +155,7 @@
+ }
+ #endif
+
+- ValueOperand() {}
++ ValueOperand() = default;
+ };
+
+ // Registers to hold either either a typed or untyped value.
+@@ -165,46 +164,25 @@
+ // Type of value being stored.
+ MIRType type_;
+
+- // Space to hold either an AnyRegister or a ValueOperand.
+ union U {
+- mozilla::AlignedStorage2<AnyRegister> typed;
+- mozilla::AlignedStorage2<ValueOperand> value;
++ AnyRegister typed;
++ ValueOperand value;
+ } data;
+
+- AnyRegister& dataTyped() {
+- MOZ_ASSERT(hasTyped());
+- return *data.typed.addr();
+- }
+- ValueOperand& dataValue() {
+- MOZ_ASSERT(hasValue());
+- return *data.value.addr();
+- }
+-
+- AnyRegister dataTyped() const {
+- MOZ_ASSERT(hasTyped());
+- return *data.typed.addr();
+- }
+- const ValueOperand& dataValue() const {
+- MOZ_ASSERT(hasValue());
+- return *data.value.addr();
+- }
+-
+ public:
+
+- TypedOrValueRegister()
+- : type_(MIRType_None)
+- {}
++ TypedOrValueRegister() = default;
+
+ TypedOrValueRegister(MIRType type, AnyRegister reg)
+ : type_(type)
+ {
+- dataTyped() = reg;
++ data.typed = reg;
+ }
+
+ MOZ_IMPLICIT TypedOrValueRegister(ValueOperand value)
+ : type_(MIRType_Value)
+ {
+- dataValue() = value;
++ data.value = value;
+ }
+
+ MIRType type() const {
+@@ -220,11 +198,13 @@
+ }
+
+ AnyRegister typedReg() const {
+- return dataTyped();
++ MOZ_ASSERT(hasTyped());
++ return data.typed;
+ }
+
+ ValueOperand valueReg() const {
+- return dataValue();
++ MOZ_ASSERT(hasValue());
++ return data.value;
+ }
+
+ AnyRegister scratchReg() {
+@@ -240,19 +220,18 @@
+ // Whether a constant value is being stored.
+ bool constant_;
+
+- // Space to hold either a Value or a TypedOrValueRegister.
+ union U {
+- mozilla::AlignedStorage2<Value> constant;
+- mozilla::AlignedStorage2<TypedOrValueRegister> reg;
++ Value constant;
++ TypedOrValueRegister reg;
+ } data;
+
+ Value& dataValue() {
+ MOZ_ASSERT(constant());
+- return *data.constant.addr();
++ return data.constant;
+ }
+ TypedOrValueRegister& dataReg() {
+ MOZ_ASSERT(!constant());
+- return *data.reg.addr();
++ return data.reg;
+ }
+
+ public:
diff --git a/dev-lang/spidermonkey/files/mozjs38-fix-tracelogger.patch b/dev-lang/spidermonkey/files/mozjs38-fix-tracelogger.patch
new file mode 100644
index 000000000000..2197f617a043
--- /dev/null
+++ b/dev-lang/spidermonkey/files/mozjs38-fix-tracelogger.patch
@@ -0,0 +1,605 @@
+from https://github.com/GNOME/jhbuild/blob/master/patches/mozjs38-fix-tracelogger.patch
+
+# === Fix the SM38 tracelogger ===
+# This patch is a squashed version of several patches that were adapted
+# to fix failing hunks.
+#
+# Applied in the following order, they are:
+# * https://bugzilla.mozilla.org/show_bug.cgi?id=1223767
+# Assertion failure: i < size_, at js/src/vm/TraceLoggingTypes.h:210
+# Also fix stop-information to make reduce.py work correctly.
+# * https://bugzilla.mozilla.org/show_bug.cgi?id=1227914
+# Limit the memory tracelogger can take.
+# This causes tracelogger to flush data to the disk regularly and prevents out of
+# memory issues if a lot of data gets logged.
+# * https://bugzilla.mozilla.org/show_bug.cgi?id=1155618
+# Fix tracelogger destructor that touches possibly uninitialised hash table.
+# * https://bugzilla.mozilla.org/show_bug.cgi?id=1223636
+# Don't treat extraTextId as containing only extra ids.
+# This fixes an assertion failure: id == nextTextId at js/src/vm/TraceLoggingGraph.cpp
+# * https://bugzilla.mozilla.org/show_bug.cgi?id=1227028
+# Fix when to keep the payload of a TraceLogger event.
+# This fixes an assertion failure: textId < uint32_t(1 << 31) at js/src/vm/TraceLoggingGraph.h
+# * https://bugzilla.mozilla.org/show_bug.cgi?id=1266649
+# Handle failing to add to pointermap gracefully.
+# * https://bugzilla.mozilla.org/show_bug.cgi?id=1280648
+# Don't cache based on pointers to movable GC things.
+# * https://bugzilla.mozilla.org/show_bug.cgi?id=1224123
+# Fix the use of LastEntryId in tracelogger.h.
+# * https://bugzilla.mozilla.org/show_bug.cgi?id=1231170
+# Use size in debugger instead of the current id to track last logged item.
+# * https://bugzilla.mozilla.org/show_bug.cgi?id=1221844
+# Move TraceLogger_Invalidation to LOG_ITEM.
+# Add some debug checks to logTimestamp.
+# * https://bugzilla.mozilla.org/show_bug.cgi?id=1255766
+# Also mark resizing of memory.
+# * https://bugzilla.mozilla.org/show_bug.cgi?id=1259403
+# Only increase capacity by multiples of 2.
+# Always make sure there are 3 free slots for events.
+# ===
+
+diff --git a/js/src/jit-test/tests/tracelogger/bug1231170.js b/js/src/jit-test/tests/tracelogger/bug1231170.js
+new file mode 100644
+index 0000000..023e93e
+--- /dev/null
++++ b/js/src/jit-test/tests/tracelogger/bug1231170.js
+@@ -0,0 +1,3 @@
++var du = new Debugger();
++if (typeof du.drainTraceLogger === "function")
++ du.drainTraceLogger();
+diff --git a/js/src/jit-test/tests/tracelogger/bug1266649.js b/js/src/jit-test/tests/tracelogger/bug1266649.js
+new file mode 100644
+index 0000000..81ae7ad
+--- /dev/null
++++ b/js/src/jit-test/tests/tracelogger/bug1266649.js
+@@ -0,0 +1,10 @@
++
++var du = new Debugger();
++if (typeof du.setupTraceLogger === "function" &&
++ typeof oomTest === 'function')
++{
++ du.setupTraceLogger({
++ Scripts: true
++ })
++ oomTest(() => function(){});
++}
+diff --git a/js/src/jit/Ion.cpp b/js/src/jit/Ion.cpp
+index 93e2fda..09049d6 100644
+--- a/js/src/jit/Ion.cpp
++++ b/js/src/jit/Ion.cpp
+@@ -1055,6 +1055,8 @@ IonScript::Destroy(FreeOp* fop, IonScript* script)
+
+ script->destroyCaches();
+ script->unlinkFromRuntime(fop);
++ // Frees the potential event we have set.
++ script->traceLoggerScriptEvent_ = TraceLoggerEvent();
+ fop->free_(script);
+ }
+
+diff --git a/js/src/vm/Debugger.cpp b/js/src/vm/Debugger.cpp
+index 26262fd..af7f313 100644
+--- a/js/src/vm/Debugger.cpp
++++ b/js/src/vm/Debugger.cpp
+@@ -369,10 +369,10 @@ Debugger::Debugger(JSContext* cx, NativeObject* dbg)
+ objects(cx),
+ environments(cx),
+ #ifdef NIGHTLY_BUILD
+- traceLoggerLastDrainedId(0),
++ traceLoggerLastDrainedSize(0),
+ traceLoggerLastDrainedIteration(0),
+ #endif
+- traceLoggerScriptedCallsLastDrainedId(0),
++ traceLoggerScriptedCallsLastDrainedSize(0),
+ traceLoggerScriptedCallsLastDrainedIteration(0)
+ {
+ assertSameCompartment(cx, dbg);
+@@ -3907,9 +3907,9 @@ Debugger::drainTraceLogger(JSContext* cx, unsigned argc, Value* vp)
+ size_t num;
+ TraceLoggerThread* logger = TraceLoggerForMainThread(cx->runtime());
+ bool lostEvents = logger->lostEvents(dbg->traceLoggerLastDrainedIteration,
+- dbg->traceLoggerLastDrainedId);
++ dbg->traceLoggerLastDrainedSize);
+ EventEntry* events = logger->getEventsStartingAt(&dbg->traceLoggerLastDrainedIteration,
+- &dbg->traceLoggerLastDrainedId,
++ &dbg->traceLoggerLastDrainedSize,
+ &num);
+
+ RootedObject array(cx, NewDenseEmptyArray(cx));
+@@ -4002,10 +4002,10 @@ Debugger::drainTraceLoggerScriptCalls(JSContext* cx, unsigned argc, Value* vp)
+ size_t num;
+ TraceLoggerThread* logger = TraceLoggerForMainThread(cx->runtime());
+ bool lostEvents = logger->lostEvents(dbg->traceLoggerScriptedCallsLastDrainedIteration,
+- dbg->traceLoggerScriptedCallsLastDrainedId);
++ dbg->traceLoggerScriptedCallsLastDrainedSize);
+ EventEntry* events = logger->getEventsStartingAt(
+ &dbg->traceLoggerScriptedCallsLastDrainedIteration,
+- &dbg->traceLoggerScriptedCallsLastDrainedId,
++ &dbg->traceLoggerScriptedCallsLastDrainedSize,
+ &num);
+
+ RootedObject array(cx, NewDenseEmptyArray(cx));
+diff --git a/js/src/vm/Debugger.h b/js/src/vm/Debugger.h
+index 8cac36a..c92d685 100644
+--- a/js/src/vm/Debugger.h
++++ b/js/src/vm/Debugger.h
+@@ -314,10 +314,10 @@ class Debugger : private mozilla::LinkedListElement<Debugger>
+ * lost events.
+ */
+ #ifdef NIGHTLY_BUILD
+- uint32_t traceLoggerLastDrainedId;
++ uint32_t traceLoggerLastDrainedSize;
+ uint32_t traceLoggerLastDrainedIteration;
+ #endif
+- uint32_t traceLoggerScriptedCallsLastDrainedId;
++ uint32_t traceLoggerScriptedCallsLastDrainedSize;
+ uint32_t traceLoggerScriptedCallsLastDrainedIteration;
+
+ class FrameRange;
+diff --git a/js/src/vm/TraceLogging.cpp b/js/src/vm/TraceLogging.cpp
+index 6715b36..9766a6f 100644
+--- a/js/src/vm/TraceLogging.cpp
++++ b/js/src/vm/TraceLogging.cpp
+@@ -131,7 +131,7 @@ TraceLoggerThread::init()
+ {
+ if (!pointerMap.init())
+ return false;
+- if (!extraTextId.init())
++ if (!textIdPayloads.init())
+ return false;
+ if (!events.init())
+ return false;
+@@ -185,10 +185,10 @@ TraceLoggerThread::~TraceLoggerThread()
+ graph = nullptr;
+ }
+
+- for (TextIdHashMap::Range r = extraTextId.all(); !r.empty(); r.popFront())
+- js_delete(r.front().value());
+- extraTextId.finish();
+- pointerMap.finish();
++ if (textIdPayloads.initialized()) {
++ for (TextIdHashMap::Range r = textIdPayloads.all(); !r.empty(); r.popFront())
++ js_delete(r.front().value());
++ }
+ }
+
+ bool
+@@ -287,7 +287,7 @@ TraceLoggerThread::eventText(uint32_t id)
+ if (id < TraceLogger_Last)
+ return TLTextIdString(static_cast<TraceLoggerTextId>(id));
+
+- TextIdHashMap::Ptr p = extraTextId.lookup(id);
++ TextIdHashMap::Ptr p = textIdPayloads.lookup(id);
+ MOZ_ASSERT(p);
+
+ return p->value()->string();
+@@ -341,13 +341,15 @@ TraceLoggerThread::extractScriptDetails(uint32_t textId, const char** filename,
+ TraceLoggerEventPayload*
+ TraceLoggerThread::getOrCreateEventPayload(TraceLoggerTextId textId)
+ {
+- TextIdHashMap::AddPtr p = extraTextId.lookupForAdd(textId);
+- if (p)
++ TextIdHashMap::AddPtr p = textIdPayloads.lookupForAdd(textId);
++ if (p) {
++ MOZ_ASSERT(p->value()->textId() == textId); // Sanity check.
+ return p->value();
++ }
+
+ TraceLoggerEventPayload* payload = js_new<TraceLoggerEventPayload>(textId, (char*)nullptr);
+
+- if (!extraTextId.add(p, textId, payload))
++ if (!textIdPayloads.add(p, textId, payload))
+ return nullptr;
+
+ return payload;
+@@ -357,8 +359,10 @@ TraceLoggerEventPayload*
+ TraceLoggerThread::getOrCreateEventPayload(const char* text)
+ {
+ PointerHashMap::AddPtr p = pointerMap.lookupForAdd((const void*)text);
+- if (p)
++ if (p) {
++ MOZ_ASSERT(p->value()->textId() < nextTextId); // Sanity check.
+ return p->value();
++ }
+
+ size_t len = strlen(text);
+ char* str = js_pod_malloc<char>(len + 1);
+@@ -369,7 +373,7 @@ TraceLoggerThread::getOrCreateEventPayload(const char* text)
+ MOZ_ASSERT(ret == len);
+ MOZ_ASSERT(strlen(str) == len);
+
+- uint32_t textId = extraTextId.count() + TraceLogger_Last;
++ uint32_t textId = nextTextId;
+
+ TraceLoggerEventPayload* payload = js_new<TraceLoggerEventPayload>(textId, str);
+ if (!payload) {
+@@ -377,17 +381,19 @@ TraceLoggerThread::getOrCreateEventPayload(const char* text)
+ return nullptr;
+ }
+
+- if (!extraTextId.putNew(textId, payload)) {
++ if (!textIdPayloads.putNew(textId, payload)) {
+ js_delete(payload);
+ return nullptr;
+ }
+
+- if (!pointerMap.add(p, text, payload))
+- return nullptr;
+-
+ if (graph.get())
+ graph->addTextId(textId, str);
+
++ nextTextId++;
++
++ if (!pointerMap.add(p, text, payload))
++ return nullptr;
++
+ return payload;
+ }
+
+@@ -407,9 +413,14 @@ TraceLoggerThread::getOrCreateEventPayload(TraceLoggerTextId type, const char* f
+ if (!traceLoggerState->isTextIdEnabled(type))
+ return getOrCreateEventPayload(type);
+
+- PointerHashMap::AddPtr p = pointerMap.lookupForAdd(ptr);
+- if (p)
+- return p->value();
++ PointerHashMap::AddPtr p;
++ if (ptr) {
++ p = pointerMap.lookupForAdd(ptr);
++ if (p) {
++ MOZ_ASSERT(p->value()->textId() < nextTextId); // Sanity check.
++ return p->value();
++ }
++ }
+
+ // Compute the length of the string to create.
+ size_t lenFilename = strlen(filename);
+@@ -428,24 +439,28 @@ TraceLoggerThread::getOrCreateEventPayload(TraceLoggerTextId type, const char* f
+ MOZ_ASSERT(ret == len);
+ MOZ_ASSERT(strlen(str) == len);
+
+- uint32_t textId = extraTextId.count() + TraceLogger_Last;
++ uint32_t textId = nextTextId;
+ TraceLoggerEventPayload* payload = js_new<TraceLoggerEventPayload>(textId, str);
+ if (!payload) {
+ js_free(str);
+ return nullptr;
+ }
+
+- if (!extraTextId.putNew(textId, payload)) {
++ if (!textIdPayloads.putNew(textId, payload)) {
+ js_delete(payload);
+ return nullptr;
+ }
+
+- if (!pointerMap.add(p, ptr, payload))
+- return nullptr;
+-
+ if (graph.get())
+ graph->addTextId(textId, str);
+
++ nextTextId++;
++
++ if (ptr) {
++ if (!pointerMap.add(p, ptr, payload))
++ return nullptr;
++ }
++
+ return payload;
+ }
+
+@@ -453,14 +468,14 @@ TraceLoggerEventPayload*
+ TraceLoggerThread::getOrCreateEventPayload(TraceLoggerTextId type, JSScript* script)
+ {
+ return getOrCreateEventPayload(type, script->filename(), script->lineno(), script->column(),
+- script);
++ nullptr);
+ }
+
+ TraceLoggerEventPayload*
+ TraceLoggerThread::getOrCreateEventPayload(TraceLoggerTextId type,
+ const JS::ReadOnlyCompileOptions& script)
+ {
+- return getOrCreateEventPayload(type, script.filename(), script.lineno, script.column, &script);
++ return getOrCreateEventPayload(type, script.filename(), script.lineno, script.column, nullptr);
+ }
+
+ void
+@@ -485,7 +500,7 @@ TraceLoggerThread::startEvent(uint32_t id)
+ if (!traceLoggerState->isTextIdEnabled(id))
+ return;
+
+- logTimestamp(id);
++ log(id);
+ }
+
+ void
+@@ -510,7 +525,7 @@ TraceLoggerThread::stopEvent(uint32_t id)
+ if (!traceLoggerState->isTextIdEnabled(id))
+ return;
+
+- logTimestamp(TraceLogger_Stop);
++ log(TraceLogger_Stop);
+ }
+
+ void
+@@ -522,23 +537,57 @@ TraceLoggerThread::logTimestamp(TraceLoggerTextId id)
+ void
+ TraceLoggerThread::logTimestamp(uint32_t id)
+ {
++ MOZ_ASSERT(id > TraceLogger_LastTreeItem && id < TraceLogger_Last);
++ log(id);
++}
++
++void
++TraceLoggerThread::log(uint32_t id)
++{
+ if (enabled == 0)
+ return;
+
+ MOZ_ASSERT(traceLoggerState);
+- if (!events.ensureSpaceBeforeAdd()) {
++
++ // We request for 3 items to add, since if we don't have enough room
++ // we record the time it took to make more place. To log this information
++ // we need 2 extra free entries.
++ if (!events.hasSpaceForAdd(3)) {
+ uint64_t start = rdtsc() - traceLoggerState->startupTime;
+
+- if (graph.get())
+- graph->log(events);
++ if (!events.ensureSpaceBeforeAdd(3)) {
++ if (graph.get())
++ graph->log(events);
++
++ iteration_++;
++ events.clear();
++
++ // Remove the item in the pointerMap for which the payloads
++ // have no uses anymore
++ for (PointerHashMap::Enum e(pointerMap); !e.empty(); e.popFront()) {
++ if (e.front().value()->uses() != 0)
++ continue;
++
++ TextIdHashMap::Ptr p = textIdPayloads.lookup(e.front().value()->textId());
++ MOZ_ASSERT(p);
++ textIdPayloads.remove(p);
++
++ e.removeFront();
++ }
+
+- iteration_++;
+- events.clear();
++ // Free all payloads that have no uses anymore.
++ for (TextIdHashMap::Enum e(textIdPayloads); !e.empty(); e.popFront()) {
++ if (e.front().value()->uses() == 0) {
++ js_delete(e.front().value());
++ e.removeFront();
++ }
++ }
++ }
+
+ // Log the time it took to flush the events as being from the
+ // Tracelogger.
+ if (graph.get()) {
+- MOZ_ASSERT(events.capacity() > 2);
++ MOZ_ASSERT(events.hasSpaceForAdd(2));
+ EventEntry& entryStart = events.pushUninitialized();
+ entryStart.time = start;
+ entryStart.textId = TraceLogger_Internal;
+@@ -548,13 +597,6 @@ TraceLoggerThread::logTimestamp(uint32_t id)
+ entryStop.textId = TraceLogger_Stop;
+ }
+
+- // Free all TextEvents that have no uses anymore.
+- for (TextIdHashMap::Enum e(extraTextId); !e.empty(); e.popFront()) {
+- if (e.front().value()->uses() == 0) {
+- js_delete(e.front().value());
+- e.removeFront();
+- }
+- }
+ }
+
+ uint64_t time = rdtsc() - traceLoggerState->startupTime;
+@@ -956,3 +998,16 @@ TraceLoggerEvent::~TraceLoggerEvent()
+ if (payload_)
+ payload_->release();
+ }
++
++TraceLoggerEvent&
++TraceLoggerEvent::operator=(const TraceLoggerEvent& other)
++{
++ if (hasPayload())
++ payload()->release();
++ if (other.hasPayload())
++ other.payload()->use();
++
++ payload_ = other.payload_;
++
++ return *this;
++}
+diff --git a/js/src/vm/TraceLogging.h b/js/src/vm/TraceLogging.h
+index a124dcb..91a1eb0 100644
+--- a/js/src/vm/TraceLogging.h
++++ b/js/src/vm/TraceLogging.h
+@@ -110,6 +110,9 @@ class TraceLoggerEvent {
+ bool hasPayload() const {
+ return !!payload_;
+ }
++
++ TraceLoggerEvent& operator=(const TraceLoggerEvent& other);
++ TraceLoggerEvent(const TraceLoggerEvent& event) = delete;
+ };
+
+ /**
+@@ -130,6 +133,10 @@ class TraceLoggerEventPayload {
+ uses_(0)
+ { }
+
++ ~TraceLoggerEventPayload() {
++ MOZ_ASSERT(uses_ == 0);
++ }
++
+ uint32_t textId() {
+ return textId_;
+ }
+@@ -166,7 +173,8 @@ class TraceLoggerThread
+ mozilla::UniquePtr<TraceLoggerGraph> graph;
+
+ PointerHashMap pointerMap;
+- TextIdHashMap extraTextId;
++ TextIdHashMap textIdPayloads;
++ uint32_t nextTextId;
+
+ ContinuousSpace<EventEntry> events;
+
+@@ -181,6 +189,7 @@ class TraceLoggerThread
+ : enabled(0),
+ failed(false),
+ graph(),
++ nextTextId(TraceLogger_Last),
+ iteration_(0),
+ top(nullptr)
+ { }
+@@ -195,22 +204,22 @@ class TraceLoggerThread
+ bool enable(JSContext* cx);
+ bool disable();
+
+- // Given the previous iteration and lastEntryId, return an array of events
++ // Given the previous iteration and size, return an array of events
+ // (there could be lost events). At the same time update the iteration and
+- // lastEntry and gives back how many events there are.
+- EventEntry* getEventsStartingAt(uint32_t* lastIteration, uint32_t* lastEntryId, size_t* num) {
++ // size and gives back how many events there are.
++ EventEntry* getEventsStartingAt(uint32_t* lastIteration, uint32_t* lastSize, size_t* num) {
+ EventEntry* start;
+ if (iteration_ == *lastIteration) {
+- MOZ_ASSERT(events.lastEntryId() >= *lastEntryId);
+- *num = events.lastEntryId() - *lastEntryId;
+- start = events.data() + *lastEntryId + 1;
++ MOZ_ASSERT(*lastSize <= events.size());
++ *num = events.size() - *lastSize;
++ start = events.data() + *lastSize;
+ } else {
+- *num = events.lastEntryId() + 1;
++ *num = events.size();
+ start = events.data();
+ }
+
+ *lastIteration = iteration_;
+- *lastEntryId = events.lastEntryId();
++ *lastSize = events.size();
+ return start;
+ }
+
+@@ -220,16 +229,16 @@ class TraceLoggerThread
+ const char** lineno, size_t* lineno_len, const char** colno,
+ size_t* colno_len);
+
+- bool lostEvents(uint32_t lastIteration, uint32_t lastEntryId) {
++ bool lostEvents(uint32_t lastIteration, uint32_t lastSize) {
+ // If still logging in the same iteration, there are no lost events.
+ if (lastIteration == iteration_) {
+- MOZ_ASSERT(lastEntryId <= events.lastEntryId());
++ MOZ_ASSERT(lastSize <= events.size());
+ return false;
+ }
+
+- // When proceeded to the next iteration and lastEntryId points to
+- // the maximum capacity there are no logs that are lost.
+- if (lastIteration + 1 == iteration_ && lastEntryId == events.capacity())
++ // If we are in a consecutive iteration we are only sure we didn't lose any events,
++ // when the lastSize equals the maximum size 'events' can get.
++ if (lastIteration == iteration_ - 1 && lastSize == events.maxSize())
+ return false;
+
+ return true;
+@@ -268,6 +277,7 @@ class TraceLoggerThread
+ void stopEvent(uint32_t id);
+ private:
+ void stopEvent();
++ void log(uint32_t id);
+
+ public:
+ static unsigned offsetOfEnabled() {
+diff --git a/js/src/vm/TraceLoggingGraph.cpp b/js/src/vm/TraceLoggingGraph.cpp
+index d1b7f2e..a4eb273 100644
+--- a/js/src/vm/TraceLoggingGraph.cpp
++++ b/js/src/vm/TraceLoggingGraph.cpp
+@@ -276,7 +276,7 @@ TraceLoggerGraph::flush()
+ if (bytesWritten < tree.size())
+ return false;
+
+- treeOffset += tree.lastEntryId();
++ treeOffset += tree.size();
+ tree.clear();
+ }
+
+@@ -359,7 +359,7 @@ TraceLoggerGraph::startEventInternal(uint32_t id, uint64_t timestamp)
+
+ if (parent.lastChildId() == 0) {
+ MOZ_ASSERT(!entry.hasChildren());
+- MOZ_ASSERT(parent.treeId() == tree.lastEntryId() + treeOffset);
++ MOZ_ASSERT(parent.treeId() == treeOffset + tree.size() - 1);
+
+ if (!updateHasChildren(parent.treeId()))
+ return false;
+diff --git a/js/src/vm/TraceLoggingTypes.h b/js/src/vm/TraceLoggingTypes.h
+index f1c9d0c..10b76d6 100644
+--- a/js/src/vm/TraceLoggingTypes.h
++++ b/js/src/vm/TraceLoggingTypes.h
+@@ -21,7 +21,6 @@
+ _(Internal) \
+ _(Interpreter) \
+ _(InlinedScripts) \
+- _(Invalidation) \
+ _(IonCompilation) \
+ _(IonCompilationPaused) \
+ _(IonLinking) \
+@@ -60,6 +59,7 @@
+
+ #define TRACELOGGER_LOG_ITEMS(_) \
+ _(Bailout) \
++ _(Invalidation) \
+ _(Disable) \
+ _(Enable) \
+ _(Stop)
+@@ -130,6 +130,9 @@ class ContinuousSpace {
+ uint32_t size_;
+ uint32_t capacity_;
+
++ // The maximum amount of ram memory a continuous space structure can take (in bytes).
++ static const uint32_t LIMIT = 200 * 1024 * 1024;
++
+ public:
+ ContinuousSpace ()
+ : data_(nullptr)
+@@ -151,6 +154,10 @@ class ContinuousSpace {
+ data_ = nullptr;
+ }
+
++ static uint32_t maxSize() {
++ return LIMIT / sizeof(T);
++ }
++
+ T* data() {
+ return data_;
+ }
+@@ -187,11 +194,14 @@ class ContinuousSpace {
+ if (hasSpaceForAdd(count))
+ return true;
+
++ // Limit the size of a continuous buffer.
++ if (size_ + count > maxSize())
++ return false;
++
+ uint32_t nCapacity = capacity_ * 2;
+- if (size_ + count > nCapacity)
+- nCapacity = size_ + count;
+- T* entries = (T*) js_realloc(data_, nCapacity * sizeof(T));
++ nCapacity = (nCapacity < maxSize()) ? nCapacity : maxSize();
+
++ T* entries = (T*) js_realloc(data_, nCapacity * sizeof(T));
+ if (!entries)
+ return false;
+
diff --git a/dev-lang/spidermonkey/files/spidermonkey-38-jsapi-tests.patch b/dev-lang/spidermonkey/files/spidermonkey-38-jsapi-tests.patch
new file mode 100644
index 000000000000..8b023fd31807
--- /dev/null
+++ b/dev-lang/spidermonkey/files/spidermonkey-38-jsapi-tests.patch
@@ -0,0 +1,16 @@
+--- a/js/src/jsapi-tests/testPreserveJitCode.cpp 2015-09-17 16:12:22.000000000 -0400
++++ b/js/src/jsapi-tests/testPreserveJitCode.cpp 2017-02-27 16:30:28.899191525 -0500
+@@ -16,8 +16,12 @@
+
+ BEGIN_TEST(test_PreserveJitCode)
+ {
++#ifndef JS_CODEGEN_NONE
+ CHECK(testPreserveJitCode(false, 0));
+ CHECK(testPreserveJitCode(true, 1));
++#else
++ printf("*JIT is disabled, therefore CANNOT preserve jit code - skipping.\n");
++#endif
+ return true;
+ }
+
+
diff --git a/dev-lang/spidermonkey/metadata.xml b/dev-lang/spidermonkey/metadata.xml
index 564a0ee48130..83c60ddc3f4d 100644
--- a/dev-lang/spidermonkey/metadata.xml
+++ b/dev-lang/spidermonkey/metadata.xml
@@ -6,9 +6,11 @@
<name>Gentoo Mozilla Team</name>
</maintainer>
<longdescription lang="en">
- Stand-alone JavaScript C library
+ Stand-alone JavaScript C++ library
</longdescription>
<use>
+ <flag name="custom-optimization">Build with user-specified compiler optimizations
+ (-Os, -O0, -O1, -O2, -O3) from CFLAGS (unsupported)</flag>
<flag name="debug">Enable assertions to allow for easier debugging of programs that link to spidermonkey -- note this will often crash software on regular end-user systems</flag>
<flag name="threadsafe">Build a threadsafe version of spidermonkey</flag>
<flag name="system-icu">Use the system-wide <pkg>dev-libs/icu</pkg> instead of bundled -- note, only takes effect when icu flag is enabled</flag>
diff --git a/dev-lang/spidermonkey/spidermonkey-38.2.1_rc0.ebuild b/dev-lang/spidermonkey/spidermonkey-38.2.1_rc0.ebuild
new file mode 100644
index 000000000000..667393195666
--- /dev/null
+++ b/dev-lang/spidermonkey/spidermonkey-38.2.1_rc0.ebuild
@@ -0,0 +1,145 @@
+# Copyright 1999-2017 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+EAPI=6
+WANT_AUTOCONF="2.1"
+PYTHON_COMPAT=( python2_7 )
+PYTHON_REQ_USE="threads"
+inherit autotools toolchain-funcs multilib python-any-r1 versionator pax-utils mozcoreconf-v4
+
+MY_PN="mozjs"
+MY_P="${MY_PN}-${PV/_/.}"
+DESCRIPTION="Stand-alone JavaScript C library"
+HOMEPAGE="https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey"
+SRC_URI="https://people.mozilla.org/~sstangl/${MY_P}.tar.bz2"
+
+LICENSE="NPL-1.1"
+SLOT="38"
+KEYWORDS="~alpha ~amd64 ~arm ~hppa ~ia64 ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~x86-fbsd"
+IUSE="debug +jit minimal static-libs +system-icu test"
+
+RESTRICT="ia64? ( test )"
+
+#S="${WORKDIR}/${MY_P%.rc*}"
+S="${WORKDIR}/mozjs-38.0.0"
+BUILDDIR="${S}/js/src"
+
+RDEPEND=">=dev-libs/nspr-4.10.10
+ virtual/libffi
+ sys-libs/readline:0=
+ >=sys-libs/zlib-1.2.3
+ system-icu? ( >=dev-libs/icu-51.1:= )"
+DEPEND="${RDEPEND}
+ ${PYTHON_DEPS}
+ app-arch/zip
+ virtual/pkgconfig"
+
+pkg_setup(){
+ if [[ ${MERGE_TYPE} != "binary" ]]; then
+ moz_pkgsetup
+ fi
+}
+
+src_prepare() {
+ eapply "${FILESDIR}"/${PN}-38-jsapi-tests-makefile.patch \
+ "${FILESDIR}"/mozjs38-1269317.patch \
+ "${FILESDIR}"/mozjs38-fix-tracelogger.patch
+
+ eapply_user
+
+ if [[ ${CHOST} == *-freebsd* ]]; then
+ # Don't try to be smart, this does not work in cross-compile anyway
+ ln -sfn "${BUILDDIR}/config/Linux_All.mk" "${S}/config/$(uname -s)$(uname -r).mk" || die
+ fi
+
+ cd "${BUILDDIR}" || die
+ eautoconf
+}
+
+src_configure() {
+ export SHELL=/bin/sh
+ cd "${BUILDDIR}" || die
+
+ econf \
+ --enable-jemalloc \
+ --enable-readline \
+ --enable-threadsafe \
+ --with-system-nspr \
+ --enable-system-ffi \
+ --disable-optimize \
+ --with-intl-api \
+ $(use_with system-icu) \
+ $(use_enable debug) \
+ $(use_enable jit yarr-jit) \
+ $(use_enable jit ion) \
+ $(use_enable static-libs static) \
+ $(use_enable test tests)
+}
+
+cross_make() {
+ emake \
+ CFLAGS="${BUILD_CFLAGS}" \
+ CXXFLAGS="${BUILD_CXXFLAGS}" \
+ AR="${BUILD_AR}" \
+ CC="${BUILD_CC}" \
+ CXX="${BUILD_CXX}" \
+ RANLIB="${BUILD_RANLIB}" \
+ "$@"
+}
+src_compile() {
+ cd "${BUILDDIR}" || die
+ if tc-is-cross-compiler; then
+ tc-export_build_env BUILD_{AR,CC,CXX,RANLIB}
+ cross_make \
+ MOZ_OPTIMIZE_FLAGS="" MOZ_DEBUG_FLAGS="" \
+ HOST_OPTIMIZE_FLAGS="" MODULE_OPTIMIZE_FLAGS="" \
+ MOZ_PGO_OPTIMIZE_FLAGS="" \
+ host_jsoplengen host_jskwgen
+ cross_make \
+ MOZ_OPTIMIZE_FLAGS="" MOZ_DEBUG_FLAGS="" HOST_OPTIMIZE_FLAGS="" \
+ -C config nsinstall
+ mv {,native-}host_jskwgen || die
+ mv {,native-}host_jsoplengen || die
+ mv config/{,native-}nsinstall || die
+ sed -i \
+ -e 's@./host_jskwgen@./native-host_jskwgen@' \
+ -e 's@./host_jsoplengen@./native-host_jsoplengen@' \
+ Makefile || die
+ sed -i -e 's@/nsinstall@/native-nsinstall@' config/config.mk || die
+ rm -f config/host_nsinstall.o \
+ config/host_pathsub.o \
+ host_jskwgen.o \
+ host_jsoplengen.o || die
+ fi
+
+ MOZ_MAKE_FLAGS="${MAKEOPTS}" SHELL="${SHELL:-${EPREFIX%/}/bin/bash}" \
+ emake \
+ MOZ_OPTIMIZE_FLAGS="" MOZ_DEBUG_FLAGS="" \
+ HOST_OPTIMIZE_FLAGS="" MODULE_OPTIMIZE_FLAGS="" \
+ MOZ_PGO_OPTIMIZE_FLAGS=""
+}
+
+src_test() {
+ cd "${BUILDDIR}/js/src/jsapi-tests" || die
+ ./jsapi-tests || die
+}
+
+src_install() {
+ cd "${BUILDDIR}" || die
+ emake DESTDIR="${D}" install
+
+ if ! use minimal; then
+ if use jit; then
+ pax-mark m "${ED}/usr/bin/js${SLOT}"
+ fi
+ else
+ rm -f "${ED}/usr/bin/js${SLOT}"
+ fi
+
+ if ! use static-libs; then
+ # We can't actually disable building of static libraries
+ # They're used by the tests and in a few other places
+ find "${D}" -iname '*.a' -delete || die
+ fi
+}