Earlier quoted context omitted.
While continuations and coroutines are often used interchangeably (continuations are usually one-shot delimited continuations), Loom's continuations are very different from Kotlin's coroutines, which are more similar to C#'s async/await (they are stackless ), while the fibers built on top of Loom continuations are more like Erlang's processes or Go's goroutines. The difference is very big from the programmer's perspe…
Any idea how these fibers compare to the ones used by D as well? I also wonder if this means Kotlin will adopt Fibers since it does build on top of JVM capabilities.
Why Continuations Are Coming to Java
161–170 of 185 posts
Re: Why Continuations Are Coming to Java
#162Earlier quoted context omitted.
This is demonstrably not true. That address space isn’t allocated until it is used. Even with initial allocations of 4kB pages, there’s plenty more space than you’re estimating.
Even 4k is a lot, and whatever memory is committed stays committed (and worse, it may even be paged). Perhaps it would be possible for the kernel to uncommit unused stack pages, but I don't think kernels want to assume threads never access memory below their stack pointer.
Re: Why Continuations Are Coming to Java
#163Honest question, maybe obvious: Why is the java-scheduler/ thread model so much better than the OS-level one? What does the java one do, or better what does it not do? And why can't the principles which make java-scheduling fast be applied to OS-threads?
Re: Why Continuations Are Coming to Java
#164Honest question, maybe obvious: Why is the java-scheduler/ thread model so much better than the OS-level one? What does the java one do, or better what does it not do? And why can't the principles which make java-scheduling fast be applied to OS-threads?
Re: Why Continuations Are Coming to Java
#165Earlier quoted context omitted.
This is demonstrably not true. That address space isn’t allocated until it is used. Even with initial allocations of 4kB pages, there’s plenty more space than you’re estimating.
No you have it backwards - the address space is always allocated. The physical memory is not allocated (we say committed ) until it is used. But allocating the address space even if it is not committed still consumes finite resources and still limits the number of threads you can create.
Re: Why Continuations Are Coming to Java
#166Earlier quoted context omitted.
No you have it backwards - the address space is always allocated. The physical memory is not allocated (we say committed ) until it is used. But allocating the address space even if it is not committed still consumes finite resources and still limits the number of threads you can create.
Yeah, but there’s plenty of space to put 2MB stacks in 48 bits (that’s 256 TBs) of address space.
Re: Why Continuations Are Coming to Java
#167The bits about multi-node computation reminds me of Racket's Places [0]. Have any other mainstream languages (Racket doesn't count) tried this technique before? [0] https://docs.racket-lang.org/distributed-places/index.html
Re: Why Continuations Are Coming to Java
#168Re: Why Continuations Are Coming to Java
#169Earlier quoted context omitted.
pron, isn't it simpler to just allocate everything on heap, than reallocating coroutine stacks? Or is allocating on heap significantly less performant than managing coroutine stacks (stack need to be copied, while heap allocated object can stay the same). Also, is there any timeline or estimate when Loom will be released with official JDK?
In the current Loom implementation, continuation stacks are allocated on the heap; they can grow and shrink as ArrayLists do -- the object stays the same, but the backing array needs to be reallocated.
Re: Why Continuations Are Coming to Java
#170Earlier quoted context omitted.
Yeah, but there’s plenty of space to put 2MB stacks in 48 bits (that’s 256 TBs) of address space.
Again, there's plenty of address space in 48 bits, but you need to commit physical memory in order to allocate the space for the page table for that address space. And that's per-process, and it's going to thrash the TLB.
Handling memory allocation lazily like this is necessary to handle a number of edge cases, such as spinning up a massive number of short-lived threads. It also prevents thrashing of the TLB cache.
In practice, real operating systems finely tune their behavior here. I would not be surprised at all if a 4kB allocation is made for a thread's stack upon creation in modern operating systems. But I would be very surprised if, e.g., Linux allocated a full 1MB of memory at thread creation time instead of handling the vast majority of it lazily.
EDIT: Oh wait, I think you were mostly agreeing with me :) Yes, my original comment did mess up address allocation vs physical page allocation due to a brain fart. I meant it the other way around and I think we're saying nearly the same thing.
The one major point of difference is that to make an address allocation in the page table doesn't require a physical allocation. The OS can either leave that allocated space unconfigured, or assign it a protected page table. In either case it faults on access and the OS knows that before killing the process with core exception to first look in its internal lazy delayed-allocation tables to see if it the access was to an allocated area of the address space with deferred allocation.