Bug 1167883 - Avoid huge stack frames and stack overflow issues with MSVC PGO builds. r=nbp, a=kglazko
authorJan de Mooij <jdemooij@mozilla.com>
Thu, 09 Jul 2015 11:12:04 +0200
changeset 275312 7f9a9ca8f435b7a60471f4f011a8621870724930
parent 275311 e3ba0f07cffacdb03afc235355898eeed7afd8fd
child 275313 d2684ca58fccabca0e050e11dddf80a58cb9ff21
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnbp, kglazko
bugs1167883
milestone40.0
Bug 1167883 - Avoid huge stack frames and stack overflow issues with MSVC PGO builds. r=nbp, a=kglazko
js/src/jsexn.cpp
js/src/vm/Interpreter.cpp
--- a/js/src/jsexn.cpp
+++ b/js/src/jsexn.cpp
@@ -625,18 +625,20 @@ js::ErrorReportToString(JSContext* cx, J
 
 bool
 js::ReportUncaughtException(JSContext* cx)
 {
     if (!cx->isExceptionPending())
         return true;
 
     RootedValue exn(cx);
-    if (!cx->getPendingException(&exn))
+    if (!cx->getPendingException(&exn)) {
+        cx->clearPendingException();
         return false;
+    }
 
     cx->clearPendingException();
 
     ErrorReport err(cx);
     if (!err.init(cx, exn)) {
         cx->clearPendingException();
         return false;
     }
--- a/js/src/vm/Interpreter.cpp
+++ b/js/src/vm/Interpreter.cpp
@@ -631,16 +631,22 @@ struct AutoStopwatch final
     uint64_t systemTimeStart_;
     uint64_t CPOWTimeStart_;
 
     MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
 };
 
 }
 
+// MSVC with PGO inlines a lot of functions in RunScript, resulting in large
+// stack frames and stack overflow issues, see bug 1167883. Turn off PGO to
+// avoid this.
+#ifdef _MSC_VER
+# pragma optimize("g", off)
+#endif
 bool
 js::RunScript(JSContext* cx, RunState& state)
 {
     JS_CHECK_RECURSION(cx, return false);
 
 #if defined(NIGHTLY_BUILD)
     js::AutoStopwatch stopwatch(cx);
 #endif // defined(NIGHTLY_BUILD)
@@ -671,16 +677,19 @@ js::RunScript(JSContext* cx, RunState& s
 
     if (state.isInvoke()) {
         InvokeState& invoke = *state.asInvoke();
         TypeMonitorCall(cx, invoke.args(), invoke.constructing());
     }
 
     return Interpret(cx, state);
 }
+#ifdef _MSC_VER
+# pragma optimize("", on)
+#endif
 
 struct AutoGCIfRequested
 {
     JSRuntime* runtime;
     explicit AutoGCIfRequested(JSRuntime* rt) : runtime(rt) {}
     ~AutoGCIfRequested() { runtime->gc.gcIfRequested(); }
 };
 
@@ -729,20 +738,18 @@ js::Invoke(JSContext* cx, CallArgs args,
     if (!fun->getOrCreateScript(cx))
         return false;
 
     /* Run function until JSOP_RETRVAL, JSOP_RETURN or error. */
     InvokeState state(cx, args, initial);
 
     // Check to see if createSingleton flag should be set for this frame.
     if (construct) {
-        FrameIter iter(cx);
-        if (!iter.done() && iter.hasScript()) {
-            JSScript* script = iter.script();
-            jsbytecode* pc = iter.pc();
+        jsbytecode* pc;
+        if (JSScript* script = cx->currentScript(&pc)) {
             if (ObjectGroup::useSingletonForNewObject(cx, script, pc))
                 state.setCreateSingleton();
         }
     }
 
     bool ok = RunScript(cx, state);
 
     MOZ_ASSERT_IF(ok && construct, args.rval().isObject());