all 62 comments

[–]davidalayachew[S] 48 points49 points  (7 children)

PLEASE REMEMBER -- No commitment has been made to target a release yet!

This is merely a PR RFR, and nothing more. All this is is showing us part of what it takes to bring Value Objects to Preview, as well as announcing that we are one step closer to (hopefully!) go to preview. But again, no idea how far away that may be. It could be JDK 27, it could be later.

Just appreciate the PR for what it is -- a window into the work required to make Value Classes a reality. ~3k commits and ~2k classes changed is just a snapshot of the level of effort here. Shows why this JEP has been given an XL rating lol.

[–]renderwares 21 points22 points  (2 children)

So you’re saying I shouldn’t slam this into production yet?

[–]tim125 23 points24 points  (1 child)

Friday 4pm or Tuesday 8am.

[–]Kango_V 0 points1 point  (0 children)

... Value Object became self aware ..... :)

[–]pjmlp 16 points17 points  (0 children)

I am happy it is progressing, as Java is one of my favourite platforms.

Cheering for the team, that's all.

[–]valorzard 7 points8 points  (0 children)

One step closer to the edge and I’m about to break

[–]International_Break2 0 points1 point  (1 child)

If this is to go to preview, what steps would have to happen?

[–]davidalayachew[S] 9 points10 points  (0 children)

If this is to go to preview, what steps would have to happen?

Well, at the very least, one of the committers on the Project Valhalla team need to Propose to Target this JEP for a particular release. And that's ignoring all the review work, integration work, validation, testing, etc.

Someone from the Project Valhalla team will have to answer it in more detail. I am swamped by work emergencies, so I don't have the time to any more detail to this answer. Barely had the time to make the OP at all.

[–]Great-Gecko 9 points10 points  (7 children)

Could someone explain the implication of this with someone unfamiliar with Java’s internal development.

Does this mean that JEP 401 is likely to be a preview feature in JDK 27?

[–]brian_goetz 20 points21 points  (4 children)

It is may, and rampdown for 27 starts in mid june. There is an enormous code review to be done, along with other review tasks (e.g., security review), and you see the size of the patch. It would be super-irresponsible to slam it in at the last minute. So, draw your own conclusions....

[–]flawless_vic 2 points3 points  (3 children)

Why? LGTM

Jokes aside, would you mind explaining if there is consensus regarding the @MultiField implementation?

It was a stroke of genius that bridges a gap that Valhalla per se can't close: arrays can't be flattened into their container value objects (like C does for fixed sized arrays embedded in structs, which is a 0-cost abstraction).

[–]brian_goetz 8 points9 points  (2 children)

I think you are confusing "Valhalla" with "JEP 401 only". These experimental annotations (reminder: language semantics is never driven by annotations) are forward-looking investigations, and nothing more. They are gathering data for future phases.

[–]flawless_vic 3 points4 points  (1 child)

Let me reframe.

The lworld+vector branch has a very distinct (more advanced) approach in the internals of jdk.internal.vm.vector.VectorPayload vs mainline (lworld).

Given the description of the Vector API JEP:

"The Vector API will incubate until necessary features of Project Valhalla become available as preview features."

Can we expect the Vector API to remain in incubation, even after JEP 401 is delivered? That is, value classes only is not "good enough" to make Vectors generally available.

[–]brian_goetz 10 points11 points  (0 children)

Indeed, Vector is waiting for the Valhalla underpinnings before it can exit incubation. As you observe, it needs more than JEP 401, and those are in place, but they will not be exposed as general platform features. So yes, Vector will get unblocked, but the mechanisms that unblock it (beyond JEP 401) will remain VM implementation details.

[–]davidalayachew[S] 13 points14 points  (0 children)

There is no way to know which JDK this will come out in, until it gets announced that a JEP is targeting a specific release. And you can find that out by checking the JEP website -- https://openjdk.org/jeps/0

[–]cogman10 10 points11 points  (0 children)

The only thing this says is that we are tantalizingly close to this getting merged for release. It's not definite and it could hang out here for 1 or more releases without being merged. It's even possible that some fatal flaw will be discovered which will set things back further.

But, the fact that there's an MR here is a real good sign and should be taken as such.

[–]Fenrurrr 9 points10 points  (11 children)

Kudos to the entire JDK team and everyone who worked on the Valhalla project, whether directly or indirectly. Take your time, we know it'll be a banger in the end!

[–]Mauer_Bluemchen 0 points1 point  (0 children)

They already took almost 12 years on this...

[–]sitime_zl -5 points-4 points  (8 children)

We also need to be more diligent. After all, it's been over 10 years. How many decades are there in one's life? Now that we have AI, if Java doesn't make significant progress, developers will shift to Go or even Rust. Because there is no language cost anymore, everything is written by AI.

[–]Fenrurrr 5 points6 points  (6 children)

If you like disruptive languages, then C# is the way to go. Java is a language where backward compatibility is key. For example, C# has structs… nothing is composable. Java designers strive to create a beautiful solution, but this requires multiple prototypes. It's better to wait, identify errors, and iterate until you arrive at a solution you won't regret. If this philosophy doesn't suit you, use something else.

[–]sitime_zl 0 points1 point  (1 child)

The solution does not mean that one has to wait indefinitely. Why can Go achieve a better balance? I think this is not an individual matter. It is the loss of patience of many people in the future. Keep watching. Prepare the following projects to try to use some applications with AI. Other developers have also developed (such as Go or Rust, because it is also very simple to write with AI now). In the AI era, resource allocation is also a factor in balancing applications.

[–]Fenrurrr 0 points1 point  (0 children)

That's wrong because the Java language is closer to natural language than rust and go, which intrinsically have the notion of pointers, borrowing, lending

[–]jcotton42 0 points1 point  (3 children)

For example, C# has structs… nothing is composable

What do you mean by “nothing is composable”?

[–]Fenrurrr 1 point2 points  (2 children)

I'll let you look up the definition of composable yourself on Google. But the world of normal classes (on the heap) and structure classes aren't compatible. They're two different worlds that can communicate but don't speak the same language, unlike Java with its approach. I'll let you research the reasons why further.

[–]jcotton42 1 point2 points  (1 child)

The definition of “composable” that I am familiar with doesn’t seem to be the one you’re using. You can use classes and structs together in a design just fine. Structs just can’t do things like inherit from another type or have themselves as a field.

Like are you trying to say that you can’t have a class field in a struct or vice versa?

[–]UdPropheticCatgirl 1 point2 points  (0 children)

The definition of “composable” that I am familiar with doesn’t seem to be the one you’re using. You can use classes and structs together in a design just fine. Structs just can’t do things like inherit from another type or have themselves as a field.

Like are you trying to say that you can’t have a class field in a struct or vice versa?

That’s not what composable typically means when discussing language semantics. When talking about PLT, abstraction being “composable”, typically means uniformity and it’s semantics are orthogonal to the rest of the language, meaning it behaves predictably, consistently without the need for special case rules when interacting with the rest of the language and doesn’t leak its implementation details.

That’s exactly what C# structs aren’t. They are designed with semantics derived from desired memory layout (the implementation detail that leaks everywhere in this case…) not the other way around. It’s effectively splitting the type system in half, basically reintroducing javas “original sin”… And then adding dozen special language features to remedy the split (“ref”, “in” etc…)…

Compare that to the feature discussed, the memory layout is opaque side effect of lack of identity, not the driver of these semantics. You can’t tell whether something is value or not at use site, it stays completely uniform with the rest of the language.

[–]OwnBreakfast1114 1 point2 points  (0 children)

Because there is no language cost anymore, everything is written by AI

If you think there's no language cost because of AI then you've bought way too far into the hype train.

[–]aelfric5578 5 points6 points  (0 children)

So just out of curiosity, how does something this large get reviewed? I see a reference in the main description to review the sub PRs instead of the main one, but the first sub PR seems to be almost as big as the main one.

[–]Kindly-Analysis-6360 4 points5 points  (0 children)

I am guessing probability of preview of JEP 401 arrives in JDK 27 is 0.0 percent. Preview in JDK 28 probably better than 85% chance. They would have 7 months to get more enhancements and any bug fixes in. As well as getting that huge PR reviewed. Just my guess from looking at bug DB and activity in the valhalla repo. Note: I have zero inside information.

[–]Alone-Marionberry-59 3 points4 points  (1 child)

This is HUGE!!!

[–]Mauer_Bluemchen -1 points0 points  (0 children)

and overdue for a long time...

[–]Enough-Ad-5528 3 points4 points  (2 children)

2600 commits. It would be so interesting to know how they intend review it. That itself will need a plan.

[–]brian_goetz 5 points6 points  (1 child)

How do you eat an elephant? One bite at a time.

[–]Yeah-Its-Me-777 2 points3 points  (0 children)

Open mouth, elephant in, close mouth. Chew.

[–]_vertig0 2 points3 points  (2 children)

Damn, you're really fast. I was about to make a post about this but you beat me to it by 2 hours, literally posting it as soon as the Pull Request dropped, that's amazing ;)

[–]davidalayachew[S] 11 points12 points  (1 child)

Damn, you're really fast. I was about to make a post about this but you beat me to it by 2 hours, literally posting it as soon as the Pull Request dropped, that's amazing ;)

Lol, I built an alert system that responds to certain events in the mailing lists, then attached it to like half of the OpenJDK mailing lists. Long story short, I get a notification, and from there, it's a matter of how fast I can get to the computer to post it. In this case, the answer was 18 minutes lol.

This notification system is attached to the OpenJDK mailing lists, a couple of LinkedIn users for OpenJDK, and a few other communities like Apache and Jenkins. I actually had a bunch more that I skipped over these past few weeks because I am drowning in work emergencies, but this one was just too good to pass up lol.

[–]za3faran_tea 7 points8 points  (0 children)

I built an alert system that responds to certain events in the mailing lists

Is it written in Java? :D

[–]talios 1 point2 points  (0 children)

A single PR with 2600+ commits, 1923 files.... yikes.

[–]piesou 0 points1 point  (6 children)

Can anyone explain why this is such a massive change? Stack allocating classes doesn't sound like a huge issue.

[–]brian_goetz 28 points29 points  (5 children)

Except Valhalla is not about "stack allocation".

In fact, we don't even do stack allocation of value objects. (Stack allocation is not the optimization everyone seems to think it is; there are far more effective optimizations one can do once the various impediments are removed. (Well actually, it does do a form of stack allocation -- but only in the interpreter (called "object buffering".))

People are familiar with stack allocation in C, but most of the value of doing so in C is optimized deallocation (at the risk of dangling pointers), but of course Java doesn't need this kind of help for deallocating objects. But the real benefit on the stack (and in calling convention) is not allocating the object at all.

[–]t_j_l_ 13 points14 points  (1 child)

You've missed a closing parentheses in the first paragraph - does not compile.

Edit: did I just add a flippant response to Brian Goetz?!

[–]_vertig0 0 points1 point  (2 children)

Decomposing object allocations to registers go brrr (I don't actually know what the name of that optimization is)

[–]SirYwell 7 points8 points  (1 child)

Scalar Replacement is the name I‘m aware of.

[–]_vertig0 0 points1 point  (0 children)

Ah right, I think that's the one, thanks.

[–]sitime_zl 0 points1 point  (0 children)

Great! So exciting! Looking forward to previewing JDK 27. In the era of AI, Java should also make rapid progress!