News for hackers. Stuff that matters.
Re:Garbage Collectors Are Scary by stingraycharles on Sunday May 12, 2024 @08:17AM (#40333827)
How is that possible? Which language was this in?
Re:Garbage Collectors Are Scary by rwmj on Sunday May 12, 2024 @09:03AM (#40334114)
I don't know, but we had a similar bug in OCaml, although in reverse.

Linux/x86-64 expects the stack to always be 16 byte aligned (although the ABI documentation at the time didn't make this assumption very clear). OCaml called into C with a non-aligned stack. GCC-generated code, assuming the stack was 16 byte aligned, used some strange Intel AVX instruction that only works on aligned data, unlike every other Intel instruction ever that can work on any alignment (albeit maybe more slowly).

This manifested itself as rare and totally unreproducible crashes (because stack alignment differed between runs). It was a bit of a nightmare to solve.

Re:Garbage Collectors Are Scary by jbosh on Sunday May 12, 2024 @10:16AM (#40334680)
The fact that msvc generates the unaligned loads for every avx instruction but gcc didn't gave me so many headaches. Most people worked on PC or Xbox and I was on the Playstation team. "oh boy, another one of these..."
Re:Garbage Collectors Are Scary by rwmj on Sunday May 12, 2024 @10:38AM (#40334821)
Yes! It's one of those cases where when you've seen it before and know the catch with the instruction (probably vmovdqa) then you'll immediately recognise it. If you don't know it, it's very very mysterious. Why on earth Intel decided to make a handful of instructions require alignment is also a mystery to me.
Re:Garbage Collectors Are Scary by jbosh on Sunday May 12, 2024 @11:44AM (#40335339)
Sweet mama speed. Although from what I understand it is more legacy speed cause you're losing all your time to fetching the memory anyway. But when processors were slower it was a meaningful amount.
Re:Garbage Collectors Are Scary by immibis on Sunday May 12, 2024 @12:12PM (#40335531)
The instruction wants to access one cache line, not two.
Re:Garbage Collectors Are Scary by fweimer on Sunday May 12, 2024 @11:53AM (#40335410)
It makes more sense now that Intel and AMD retconned naturally-aligned 128-bit atomic loads into the ISA: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104688 (AMD's confirmation is in comment 10.)
Re:Garbage Collectors Are Scary by johnnyanmac on Monday May 13, 2024 @04:57AM (#40341115)
I hear these stories of black magic bugs and I look back at my 8 year career wondering if I'm even progressing as an engineer. Thrown from one studio to the next and never truly staying long enough to be trusted to investigate such issues.

I have no idea how engineers that started in the 10's or 20's are going to rise up to take over those fro the 90's/00's. So much is abstracted, but games specifically need to understand what's under the hood. Because they can and will hit some of the nastiest edge cases.

Re:Garbage Collectors Are Scary by qweqwe14 on Sunday May 12, 2024 @10:30AM (#40334765)
AFAIK you should only need 16-byte stack alignment if you use vector instructions, so Linux/x86-64 doesn't mandate it in all cases
Re:Garbage Collectors Are Scary by professoretc on Sunday May 12, 2024 @03:09PM (#40336712)
The problem is that if you call another function, you won't know whether that function is uses any instructions that require alignment. So in practice, only leaf functions can skip stack alignment. The ABI states that the stack pointer must be aligned to a multiple of 16, plus 8, before any `call` instruction.
Re:Garbage Collectors Are Scary by jbosh on Sunday May 12, 2024 @10:14AM (#40334662)
C++, it was an in house engine to make everything fit in memory on PS3. Removing fragmentation gave ~10% of usable memory back.
Re:Garbage Collectors Are Scary by stingraycharles on Sunday May 12, 2024 @10:37PM (#40339321)
That makes a lot of sense, I figured this would be impossible with a higher level language.
Re:Garbage Collectors Are Scary by taspeotis on Sunday May 12, 2024 @08:18AM (#40333832)
AAA game is likely C++
Re:Garbage Collectors Are Scary by npalli on Sunday May 12, 2024 @08:40AM (#40333958)
GC and AAA probably C#.
Re:Garbage Collectors Are Scary by mike_hearn on Sunday May 12, 2024 @09:16AM (#40334200)
If C# they'd have been using the MS authored GC. It was probably a custom GC for C++ heaps. Quite a few games do this, it's a smart productivity hack. Unreal uses a simple form of mark/sweep GC for its C++ game state heap.

https://unrealcommunity.wiki/garbage-collection-36d1da

It works fine because most RAM in games is consumed by assets that don't need to be scanned.

Re:Garbage Collectors Are Scary by 60654 on Sunday May 12, 2024 @12:25PM (#40335617)
Interesting fact: Unity doesn't use a Microsoft GC, or the Microsoft implementation of CLR.

They had integrated the competing Mono implementation early on, and it came with its own "stop the world" Boehm GC.

They've been trying to move to Microsoft runtime for years but it's slow going.

Re:Garbage Collectors Are Scary by neonsunset on Sunday May 12, 2024 @10:00AM (#40334560)
Unlikely. Though in the case of Unity, this can happen if you fail to uphold memory layout expectations when writing C/C++ code (or if you do something really bad in C#).

There would also be a debugger allowing to reproduce and catch this in an easier way.

Re:Garbage Collectors Are Scary by packetlost on Sunday May 12, 2024 @08:22PM (#40338604)
Probably a custom one built for an in-house engine in C++ if it's a AAA studio. Alternatively one of the various off-the-shell ones you can #include, though my money is on the former. Note: I am not GP, I'm making educated guesses about what may have happened :)