News for hackers. Stuff that matters.
Re:A large crash spike affecting Firefox users on Linux by im3w1l on Saturday June 24, 2023 @01:58AM (#36455977)
This sounds like blameshifting to me. Javascript is untrusted code, so it's on Firefox to make sure to handle any craziness gracefully.

Stack probing is kind of a weird thing though. I'm kind of surprised C++ compiler isn't doing that properly. Are they using inline assembly for speed?

Re:A large crash spike affecting Firefox users on Linux by db48x on Saturday June 24, 2023 @02:22AM (#36456107)
It would only be shifting the blame if they weren’t going to work around the problem in Firefox itself.

The C++ compiler may or may not implement stack probing correctly, but this bug is in the Javascript JIT compiler. The fix is to make the JIT compiler update the stack pointer register each time through the loop so that if a page fault happens the kernel won’t see a huge amount of stack get allocated all in one go. Instead it’ll see several page faults each asking for a smaller amount which it is happy to grant.

See https://phabricator.services.mozilla.com/rMOZILLACENTRAL304d...

Re:A large crash spike affecting Firefox users on Linux by fathyb on Saturday June 24, 2023 @02:15AM (#36456073)
Agreed that the problem here is Firefox, untrusted JS code should not cause a crash.

For the probing, according to the code:

    // Can't push large frames blindly on windows, so we must touch frame memory
    // incrementally, with no more than 4096 - 1 bytes between touches.
    //
    // This is used across all platforms for simplicity.
https://searchfox.org/mozilla-central/rev/c936f47f3a629ae49a...
Re:A large crash spike affecting Firefox users on Linux by im3w1l on Saturday June 24, 2023 @02:33AM (#36456161)
Yeah I got that far but then I wasn't sure what exactly that was doing. Normal C++ doesn't directly move stack pointers around and do manual probing, so I was idly wondering whether those calls hid some inline assembly or how they worked.
Re:A large crash spike affecting Firefox users on Linux by fathyb on Saturday June 24, 2023 @03:08AM (#36456328)
It does hide some assembly. Those calls are calling an assembler to generate native code at runtime for JIT compilation. The C++ compiler compiles an assembler, but this assembler runs at runtime. `MacroAssembler` itself is architecture independent, and calls into functions implemented in back-ends such as `MacroAssemblerARM` and `MacroAssemblerX64`.

So the code in this function is not performing the stack-probing, it generates code to perform it instead.

Re:A large crash spike affecting Firefox users on Linux by IainIreland on Saturday June 24, 2023 @03:28AM (#36456421)
In general, there's no difference between the stack of the C++ program and the stack of the JS program. When SpiderMonkey just-in-time compiles a JS function, the result is native code that creates a stack frame on the same stack as the C++ code that implements SpiderMonkey. JS code and C++ code can be semi-arbitrarily interleaved on the stack: JS calls C++ calls JS calls C++...

The one exception about sharing the same stack is that the first few iterations of a function run in an interpreter implemented in C++, and that interpreter has its own stack that we heap-allocate. This particular bug occurred during the transition from the C++ interpreter to JIT code.

Re:A large crash spike affecting Firefox users on Linux by usr1106 on Saturday June 24, 2023 @02:51AM (#36456239)
Technically of course Firefox failed to live with an old kernel and insane JS code.

Morally it's Google. Google is like Bitcoin. A huge natural ressource hog for a questionable benefit. Here the benefit is tracking users to make advertising billions. For that goal a billion of smart phones need several extra GB of memory an significantly larger batteries. What is the ecological footprint of that?

Typing on a seven year old smart phone with 2 GB (SailfishOS, so yes it is maintained. Maybe not perfectly, but better than many Androids half as old). It works quite well on reasonable pages even without add blocking. Of course super heavy pages won't work and for Google search I haven't even consented. Occasionally I get reminded of that when some site embeds it. Well, a good reminder for me not to use them.

Re:A large crash spike affecting Firefox users on Linux by fathyb on Saturday June 24, 2023 @03:38AM (#36456471)
This does not appear that crazy to me. In fact, today it's almost a recommended practice for large web applications and it's called "tree shaking". ECMAScript modules are inlined into the same scope. It makes the JIT work easier because it now works with symbols instead of `require(foo).bar` calls to speculate on. It makes most web apps run better, both in bandwidth and compute.

It's very likely to have affected users on other websites, but Google is a common denominator for debugging.

My uneducated guess: they're using the Google Closure Compiler to make smaller JavaScript bundles. It saves some bandwidth and allows for better optimizations. It seems like a reasonable engineering decision to ensure product decisions don't affect the user experience too negatively, something a lot of us are familiar with..

Re:A large crash spike affecting Firefox users on Linux by usr1106 on Saturday June 24, 2023 @03:51AM (#36456540)
Right, optimization is good.

But first building insanely heavy functionality and then optimizing it is not sustainable approach.

The background is of course that increasingly heavy function is moved into the client. Technically and especially economically this makes sense for Google. But the environmental footprint is outsourced to client devices. Greenwashing in a way. Avoidance of computing is a better solution than all types of optimizations. Not everything that is technically feasible is good for the planet and mankind.

Re:A large crash spike affecting Firefox users on Linux by Izkata on Saturday June 24, 2023 @04:18AM (#36456663)
> In fact, today it's almost a recommended practice for large web applications and it's called "tree shaking". ECMAScript modules are inlined into the same scope. It makes the JIT work easier because it now works with symbols instead of `require(foo).bar` calls to speculate on. It makes most web apps run better, both in bandwidth and compute.

That's bundling, not tree shaking. Tree shaking is an optional additional process during bundling where unreachable code is automatically removed.

Re:A large crash spike affecting Firefox users on Linux by fathyb on Saturday June 24, 2023 @04:33AM (#36456732)
Bundling does not inline all symbols into a single scope, tree shaking does. I was one of the people implementing tree shaking in the first Parcel bundler. https://github.com/parcel-bundler/parcel/pull/1135
Re:A large crash spike affecting Firefox users on Linux by uhryks on Saturday June 24, 2023 @09:31AM (#36458548)
Scope hoisting is the technique used there (it's in the title of your link) to simplify tree shaking a.k.a dead code elimination. Also yeah it's unlikely to be what's happening in that bug due to Google using Closure compiler.
Re:A large crash spike affecting Firefox users on Linux by veave on Saturday June 24, 2023 @06:49AM (#36457463)
Nice rant. Absolutely unrelated to the technical article at hand, but nice rant.
Re:A large crash spike affecting Firefox users on Linux by jandrese on Saturday June 24, 2023 @02:20AM (#36456100)
I'm curious what Firefox could have done in this case beyond just killing off the tab. The issue was a check in old kernels that was being triggered by some insane code.

This example had me remembering the discussion from earlier today about why modern code is so slow even though the machines are so fast. I doubt there were many Win32 programs that attempted to pass in 20,000 parameters to a function.