Hacker News new | past | comments | ask | show | jobs | submit login

Sure, but are the languages that Graal supports diverse from the perspective of the assumptions they make? E.g., it's not surprising to me that any JVM GC would work for Java, Ruby, Python, etc since all of these languages idiomatically allocate lots of garbage like allocations are cheap (they all "look like Java" from a memory management perspective). On the other hand, Go assumes allocations are expensive and it tends to make fewer, larger allocations (the tradeoff is that it can have a relatively simple, low latency GC). It's not clear to me that a single general purpose GC (i.e., it's performant for all cases, not just the things-that-look-like-Java case) can exist, but I'm also not a GC expert.



Go doesn't differ that much from other GC languages. GC cost/complexity doesn't really change much with average allocation size. Go putting less load on the GC just means the JVM GCs would be playing on 'easy mode'.


Go has interior pointers. All byte arrays support word-sized pointers to any of their array elements. I think that's somewhat unusual for a language implementation with a precise garbage collector. Usually, pointers always point to the start of the object they reference, and not at some arbitrary offset somewhere inside the object.


C# has interior pointers as well and it is a language with a precise, moving garbage collector. The deal with Go is that is has a concurrent mark-sweep collector, so it is non-moving. Given the non-moving collector, it is significantly easier to reason with than a moving collector. Hence, you would have a lot of unstated assumptions (about whether the collector moves objects or not) baked into the runtime that would need to be fixed. You probably can't use a moving collector in Go like G1 or ZGC or LXR without non-trivial refactoring.


Oh, interesting. It's the & type in the CLI (I.12.1.1.2 in ECMA-335).

It makes Java's GCs quite Java-specific in practice because there aren't that languages that even moderately widely used which are both statically typed (to the degree that it's possible to tell pointers apart before generating code) and restrict pointers to point to the start of the object.


Ehh yes and no. Many languages indeed use conservative GCs, but that is because it is significantly easier to implement than precise GCs which require stack maps etc. I don't think it's exactly a question about languages and static types/generating code, it's more of an implementation detail. Conservative GCs can be fast, but they are inherently less space-efficient as you retain more objects than a precise GC would. Of course in some cases a conservative GC _is_ required, for example if your language has heavy interop with C/C++ land.

Also supporting interior pointers is not too cumbersome even with a "Java-style GC" (whatever that exactly means). It requires an additional bit per smallest aligned object size to denote if an object is allocated or not. If you need to check if a pointer is an interior pointer to an object, you walk back in the bitmap and find the last object with a bit set to 1 (i.e. find the allocated object which was right before the pointer you have), get the size of that object and check that the pointer you have is within the range of the start and end of the object.

EDIT: The big issue you would face with directly porting a Java GC into other languages is the weak reference processing semantics. Each language has their own subtle differences which would make it a pain.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: