> There’s a catch worth knowing about here, though: flattened data has to be readable and writable atomically (otherwise it risks “tearing” under concurrent access). I really hope they give an escape hatch for this. It will make it really hard to extract a lot of the benefit of valhala if you can't make a thread unsafe value class. It's also one of those problems that will be quite hard to run into. You basically nee…
Project Valhalla, Explained: How a Decade of Work Arrives in JDK 28
351–360 of 464 posts
Re: Project Valhalla, Explained: How a Decade of Work Arrives in JDK 28
#352Does it FINALLY fix the "-Xmx" nonsense? Or do I still have to statically specify the max heap size, as if I'm still using MacOS 9?
-XX:MaxRamPercentage=70
But they are working on removing that: https://openjdk.org/jeps/8377305Re: Project Valhalla, Explained: How a Decade of Work Arrives in JDK 28
#353Earlier quoted context omitted.
It was neglected during its last few years at Sun. Oracle started moving it forward at never before seen pace, while mostly maintaining backward compatibility (unlike .NET that "did things right from the start", which is what .NET Framework/.NET Core/.NET split/rewrite is according to some in this very discussion. And .NET had Java to copy and learn from, but still fucked up.) Same with MySQL, btw. "Dead" according t…
I have no idea about MySQL, but what I always remind people is that HN is more GQ/Vogue than the NYT. It focuses on novelty and aspiration more than on coverage of what the industry is actually doing. Like others, I enjoy it because it's aspirational/inspirational, but I try not to confuse it with a reflection of reality. E.g. there's little correlation between programming languages that are discussed a lot on HN and…
Re: Project Valhalla, Explained: How a Decade of Work Arrives in JDK 28
#354Earlier quoted context omitted.
Could you actually explain/exemplify any of the gotchas and what's been made better (or is this just handwaving)?
Part of the reason Java hasn't reified generics is because C# did and it was a real big headache that also limited non-C# languages on the C# runtime (CLI?). Everything had to be recompiled to work with newer C# runtimes. While it's pretty easy to run a bunch of language on the JVM (Javascript, python, ruby, clojure) doing the same for C# is somewhat a nightmare, particularly for non-type aware languages. For example…
Re: Project Valhalla, Explained: How a Decade of Work Arrives in JDK 28
#355Earlier quoted context omitted.
.NET made different decisions. I was at a conference on scientific programming in Java very early on that Geoff Fox put on up at Syracuse and we had a list of requests from Sun that they didn't give us but Microsoft gave many of them right away. On the other hand I really like Java's all-virtual approach to inheritance because the .NET model gives programmers more ways to screw up and get confused. Both languages sli…
I think DotNet had a bit of benefit, in that the language was still new enough to do the hard breakage. It was only about 3.5 years between NET1.0 and 2.0 (Where generics were added.)
Thing was a lot of Microsoft APIs for GUIs and whatnot used the List and if you wanted to use the List you had to copy the list or make a wrapper or something. You might say, "just use the List" but at that point (circa 2008) I had to also use the List for some API so I always had to do some conversion.
Re: Project Valhalla, Explained: How a Decade of Work Arrives in JDK 28
#356Earlier quoted context omitted.
How would a non-nullable class field work in Java when it can be initiqlized by arbitrary imperative code that can read it while it's being initialized?
The type erasure version of this would look a lot like Hack [1]. So generic arguments would simply have a ? if they allow nulls eg List . The list itself couldn't be null unless it was ?List . Now, one can argue that this is just smoke and mirrors with type erasure and it is but you can already put a Date into a List if you're so inclined because the JVM doesn't know the difference, hence type erasure. So this is no…
And that's a massive problem that they're planing to solve with specialized generics.
> If I read the correctly, it means that if you have a Point value class then on the JVM level you'll be able to stuff any value class into there if you're so incline, just like with List.
I'm not sure what you mean. An L-type is an object reference. E.g. Ljava/lang/String, Lcom/org/CustomObject. The issue you're conflating is the erasure of List to List and it's L-type Ljava/util/List.
> I prefer the Hack version
Hack/HHVM didn't have to worry about backwards compatibility.
---
The blog post does a pretty high level overview of the implementation, but my understanding of it is the following:
1. They are adding a new bytecode class flag for value classes. Bytecode descriptor for value classes are exactly the same (L-type).
2. Primitive wrapper classes will become value classes.
The difference from the CLR is that the JVM implementation is backward compatible with linked legacy bytecode. As they can accept a value class instance into their methods due to the same L-type. It's just additional metadata added to allow the JVM to stack allocate the class.
---
Separately, to handle generics:
1. Parameterized container classes will be flagged with a new bytecode to enable parametric attributes on initialization with the additional data of the parameters in the Constant Pool. Bytecode descriptor for classes are exactly the same with type-erasure, e.g. List erased to Ljava/util/List.
2. Initialization of parameterized classes are done with the additional metadata of the type argument stored in the Constant Pool.
3. The runtime does monomorphization of the parameterized class.
It doesn't seem too different to what the CLR does, i.e. runtime monomorphization. The difference is the JVM implementation is backward compatible with older type-erased code, i.e. the restrictions in Java due to type-erasure are exactly the same as before and the L-types don't change. It's just additional metadata added to allow the JVM to monomorphize the classes for performance.
---
In summary, value objects and specialized generics are backwards compatible with legacy bytecode. The JVM handles the compatibility. Of course, the newer bytecode is not forward compatible with older JVMs.
Re: Project Valhalla, Explained: How a Decade of Work Arrives in JDK 28
#357I know its a faux pas in the Java world to acknowledge the existence of .NET, but how does this differ from .NET structs? Value types, generic specialization, boxing - a quick skim makes it looks like they picked the same choices.
The ramifications for backwards compatibility is that the JVM won't have CLR features such as stackalloc (allocation of blocks of memory on stack), ref parameters (pass-by-reference of stack allocated value types), and all the other low-level/high-performance programming features available in the CLR.
Re: Project Valhalla, Explained: How a Decade of Work Arrives in JDK 28
#358Earlier quoted context omitted.
I think DotNet had a bit of benefit, in that the language was still new enough to do the hard breakage. It was only about 3.5 years between NET1.0 and 2.0 (Where generics were added.)
I was annoyed by it back when I was doing Silverlight/ASP.NET Thing was a lot of Microsoft APIs for GUIs and whatnot used the List and if you wanted to use the List you had to copy the list or make a wrapper or something. You might say, "just use the List" but at that point (circa 2008) I had to also use the List for some API so I always had to do some conversion.
Re: Project Valhalla, Explained: How a Decade of Work Arrives in JDK 28
#359Earlier quoted context omitted.
> The whole attitude and process around this and the other topics gives me very little faith that Java can be steered in a sensible direction here. I agree. The stewardship of Java seems rather lacking - particularly when compared to that of .net, where MS etc. mostly seemed to make the correct decisions from the start. Does Java even have any value or mindshare at Oracle nowadays? The company seems to be a datacentr…
First, your parent comment misunderstood what the section they were critiquing is referring to. It's not about nullability (which is orthogonal) but about reference/value projections. Now, as a member of the Java team (although I'm not directly involved in Valhalla), I'm obviously biased so let me just say that both designers and fans of programming language features would do well to remember two things: 1. Opinions…
"All differences are opinions....except what .net did. Those are wrong!"
I personally think Java continues to to waste a lot of time and come to a slightly more verbose and worse solution again and again.
Structured concurrency is like c# async/await with less sugar. Streams are just LINQ but worse.
It's probably exactly because of the "not like .NET! We must be different to explain being late" mentality.
Re: Project Valhalla, Explained: How a Decade of Work Arrives in JDK 28
#360Earlier quoted context omitted.
The colorless functions approach has well-known disadvantages though, including providing less control and making interop a pain. It isn't like one approach is the correct one and another is a mistake.
> including providing less control and making interop a pain This is true in some languages but not in Java. The limitations (and performance cost) are not from the nature of continuations/stackful coroutines/"colourless functions", but from their interaction with other constraints and existing designs in the language. E.g. in Java, virtual threads have zero impact on FFI. In general, the costs and limitations associ…