29 ms·
> I guess often GCs are quite intimately tied to other details of the runtime and specialized to code patterns and use cases of particular languages This is wh
by throwaway894345 4y ago
> I guess often GCs are quite intimately tied to other details of the runtime and specialized to code patterns and use cases of particular languages
This is why I don't understand the WASM GC proposal, which I understand to be an attempt to make a GC that works for all languages. Can you really write a GC that performantly supports both Java and Go given the different tradeoffs/approaches each makes with respect to memory management, layout semantics, etc?
- fulafel 4y agoI agree somewhat. But still JVM GC works ok for several other languages (Clojure, JRuby, Scala, Kotlin etc).
- throwaway894345 4y agoSure, but all of those languages "look like Java" from a memory management perspective. Namely, programs written in those languages idiomatically assume that allocations are dirt cheap (bump allocator) and thus they allocate a lot of garbage. A language like Go tends to assume allocations are more expensive (tradeoff for a simple/non-moving, low latency GC) and consequently makes fewer, larger allocations. It's not obvious to me that a single GC can support both extremes performantly.
- entropicdrifter 4y ago>Can you really write a GC that performantly supports both Java and Go given the different tradeoffs/approaches each makes with respect to memory management, layout semantics, etc? I mean, the Graal JVM GC supports a ton of languages, especially if you include their LLVM support. Many of them are quite high performance. Truffle Ruby I believe is still (one of if not) the fastest Ruby implementation(s).
- throwaway894345 4y agoSure, 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.
- mike_hearn 4y agoGo 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'.
- fweimer 4y agoGo 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.
- NobleExpress 4y agoC# 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.
- fweimer 4y agoOh, 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.
- NobleExpress 4y agoEhh 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.
- fweimer 4y agoIf machine code is generated on (or close to) deployment, the implementation can choose a suitable collector. Hopefully, the proposed protocol will not require that implementations somehow optimize away interior object pointers for languages like Java that do not really need them, but make that obvious directly from the opcodes being used (or some other easily observed property). Likewise for the requirement to support pointer tagging for fixnums. Then the implementation can choose the appropriate collector based on what is being compiled (and the most general one for inter-language unification). Keep in mind that typical builds of Hotspot support four or five garbage collectors, and most of them with two different pointer sizes. The required read and write barriers differ widely between collectors and in some cases even collector modes. I'm not saying that it's going to be easy (an incredible amount of effort went into Hotspot over the years). But it's definitely possible to support wildly different GC strategies efficiently with sufficiently late code generation.
- vbezhenar 4y agoIf you need ultimate performance, you need native implementation, end of story. Webassembly, as I see it, is about creating VM which provides acceptable performance with ultimate sandboxing. It's a replacement for JavaScript transpilation, not for JVM. Of course it's tempting to do it all without sacrificing anything, but I guess you can't have a cake and eat it too.
- pjmlp 4y agoExcept for VC sponsored startups trying the 2nd. coming of application servers.
- FullyFunctional 4y agoCertainly not for lazy FP language like Haskell. Its GC is highly specialized for that, including performing some non-allocating reductions during GC, having special support for detecting looping computation (holes), etc.
- NobleExpress 4y ago[dead]