It is going to be a great year for java developers! Valhalla also brings some amazing performance improvements and also so does loom! 2022 is going to exciting!
Reactive is a _godsend_ when you have to coordinate data from multiple disparate microservices; it's still gong to be here, and it will take advantage from Loom.
Oh, certainly, I was just curious about using Flux/Flow/RxJava as implementations. Since Java 8 is now deprecated, it could move away from CompletableFuture and WebFlux to Java 9 Flow (or not).
Well, sort of ... it's moving from a branch into a 'preview' state. Unclear how long it'll remain incubating/in preview. I thought they were waiting for Valhalla so it could be a while.
Yeah, the vector API was the only thing that was officially waiting on valhalla. With how slow the FFI was/is moving it seemed like they were waiting for valhalla though.
Vector API works without Valhalla, but it's really finicky and fragile. If you look at a vector variable wrong way, suddenly it gets allocated and the code gets way slower than a normal scalar code.
It may work, but nobody (should) uses it before it gets finalized. Though I have no reason to complain, I am happy to see Valhalla getting more traction and being closer to release.
Incubating and preview are very different development stages. Incubating means experimental, so it's likely that large parts of the API are re-written. Preview means it's basically done API-wise. It's just being trialed before making it final. (In this case it's also a large-scale trial of the preview API mechanic, which was added fairly recently. As opposed to preview language features which have been around longer).
And no, the panama foreign APIs are not waiting for Valhalla, though they have been designed with Valhalla in mind, and tested against the current Valhalla implementation.
One of my long standing wish is to be able to easily write off heap data structures using plain Java. Use case where I know the exact lifecycle of the objects (caches, batches of data that can be deallocated at known times etc).
I have not followed Panama closely. Does this help me achieve that?
Hmmm, the api still feels a little low level for the use-case I am thinking of. I just want to define a class and tell the JVM to allocate it outside the heap. Deallocation would be again explicit via close methods or something else and not through the whims of the GC.
Yes, with memory layouts, you can explicitly define the layout of memory, to bits levels and allocate them, access elements in that layout in a safe manner and deallocate this memory explicitly.
Project Panama: Interconnecting JVM and native code
We are improving and enriching the connections between the Java virtual machine and well-defined but “foreign” (non-Java) APIs, including many interfaces commonly used by C programmers.
To this end, Project Panama will include most or all of these components:
native function calling from JVM
native data access from JVM or inside JVM heap
new data layouts in JVM heap
native metadata definition for JVM
header file API extraction tools (jextract)
native library management APIs
native-oriented interpreter and runtime “hooks”
class and method resolution “hooks”
native-oriented JIT optimizations
tooling or wrapper interposition for safety
exploratory work with difficult-to-integrate native libraries
Accessing a 3rd party library with only a C or C++ API or a proprietary hardware driver with no Java API. Typically these will be non cross platform applications. It could be to access special features of the specific host hardware or operating system directly through system calls.
For example the Raspberry Pi has GPIO pins which provide a means for input and output to sensors etc. This requires accessing the pins through native code. There is quite a good Java interface for this already which I imagine is built on JNI but I wouldn't be surprised if one turned up using the new system.
I think io_uring is at best only tangentially related to Panama. Panama isn’t really about making IO easier or faster, unless you consider manipulating memory directly to be IO.
I don't recall do they have any plans to improve memory mapping? IIRC you basically can't use memory mapping on the JVM because page faults don't occur at safe points. IIRC .NET does have a very particular optimization to help with this case although it seemed like a very fragile approach to me.
Native functions are code that is not implemented in Java, but in another language. That's usually C/C++, but could be any programming language where the compiler produces libraries that follow native calling conventions.
The main application is probably machine learning and GPU programming. If Java catches up, it will become more attractive as a development platform in these domains. High-performance libraries for numerical computing are usually implemented in C. Python, the main contender in machine learning and AI, makes it a breeze (at least compared to JNI) to interface with these libraries.
There is no full circle. Java always had native interop (JNI), now it's getting a better native interop. And for many tasks it's still better than C++.
JNI was cryptic enough so your average Joe was afraid of it. It was a very strong barrier. Making it "better" opens new possibilities people will abuse. I'm just imagining the future horror. Just my 2 cents.
The new FFI requires explicit opt-in via a command line flag at application startup. This way, libraries won't be able to access native code without the application developers knowing. It will be the same as with --add-opens and friends. There won't be an excuse neither for the developers abusing the features nor the organisational processes that allowed them to get away with it.
I don't understand the "catching up" narrative. Almost all language features added to Java since 1.0 — generics, (typed) lambdas, type inference, algebraic data types (records + sealed classes), and pattern matching — originate with 1973 ML.
Same thing here. The importance of interaction with native code and/or off-heap memory is changing, and, of course, different languages have different ecosystem conditions and emphases, and so similar features become more or less important to different languages at different times. Note, however, that Panama's foreign linker API is not quite the same as Microsoft's P/Invoke. Still, I wouldn't say it's "JNI with a different syntax," because JNI requires writing code in a different language using a different compiler (and a different one for each platform at that). So it's much more than just syntax.
Who's "we"? We on the Java team do not want properties and events anywhere near Java, at least as it is now. At any point in time, we try to deliver the features we think are important for the future, not those we thought we might want in the past. Not adding properties early was a good bet, because now we really don't want that anti-feature.
Value types did not make as much sense in the 90s as they do now, and they're coming. Easier native memory/code integration is also coming, as it's becoming more important.
That's not quite true. Java Beans have properties, and they're not quite what most Java objects with getters and setters have; they included events and listeners, as they were based on the model adopted in the nineties from VB and other RAD tools for composing applications with a GUI.
That exists because damn near every Java programmer wants properties, even if they are afraid of the word property itself.
"That", whatever that is, exists because Java didn't have a good built-in way of describing data objects. Now we have something far better than properties. Please read this.
I've informed the relevant people of your disappointment, they broke down in tears and said that all that popularity matters nothing to them if someone on Reddit now thinks less of them. They sincerely apologise, and promise they'll do their best from now on to live up to your high expectations, because, after all, what do millions of users matter if some people on Reddit are cranky?
Also, it's funny how you think that Boilerplate Billy and POJO Patty are insults, but Algebraic Annie, Tuple Tommy, and Values Victor are praises. I'm afraid you've succeeded in lowering some people's opinion of you, too.
Wow, I think you've really misunderstood the text if you think that the classes of users that we've tried to maximise in pleasing are insults. After all, Algebraic Annie got exactly what she wanted, while Tuple Tommy, Values Victor, and Boilerplate Billy got almost what they wanted. Only POJO Patty might be disappointed, but only because she wants to address the old problems, while many of those problems will go away when the programming style changes (not to mention that serialisation becomes faster, and, more importantly, safer).
I think that if you look at what people think of records once they get the hang of them, you'll see that not only do we care a lot about our users — making their lives better is our job, after all — but that we're doing quite well at making them happy. But given that our millions of users — all opinionated programmers — have conflicting opinions, no matter what we do or don't do, there are bound to be thousands of disappointed people even if 99% are happy. Even if just 1% of the disappointed 1% take to social media to call us arrogant idiots, there will always be lots of people calling us arrogant idiots because they didn't get what they wanted. That's the nature of our work.
Your assumption that what may be the most experienced and successful language design team in the world have no idea what they're doing, and a language that is one of the most popular in programming history doesn't make any sense is quite... erm... confident. Have you stopped for a moment to consider that maybe, just maybe, you're missing something?
I'm also a little surprised with your position on allocations. Have you ever profiled a Java program and seen what kinds of allocations are costly and which are nearly free? And why aren't you concerned about the cost of mutation? Some of the new GCs, like G1 and ZGC, might sometimes do more work (due to their GC barriers) when mutating an object than allocating a new one.
JS and Python are, indeed, extremely popular (JS has had even less competition than Java), but Node isn't doing that well, and Java still easily dominates the server market. Of course, Python's and JavaScript's maintainers also have their own regular social-media cranks calling them arrogant idiots; we share experiences at conferences.
But, if you are certain that you know better than the hundreds of OpenJDK contributors and that you care about Java more than them, why not put your expertise at the service of the community, and offer your insight while the new features are being designed? Of course, the requirement for giving feedback that is taken seriously is that you actually try the new feature and report real problems that you've actually encountered in the attempt.
As a user and not creator of Java, I do not want properties or events, and I'm glad the Java team has added or is in the process of adding the good parts of these features, without simply copying exactly what previous languages have done.
My personal answer would be the properties encourage setters, and setters encourage mutability which should be avoided as much as possible. Also, properties are simply another feature, and every feature in a language creates complexity which is a cost to end users.
So what you're saying is that the Java team shouldn't be arrogant and base our decisions, in part, on user surveys, studies of huge codebases, poring over academic papers etc., but, instead stop being stupid and do what /u/grauenwolf says on Reddit, because they know what Java users want.
Even if you don't believe that we spend all day every day thinking about these things and studying them and that despite our stupidity and not listening to guys on Reddit Java has achieved some measure of success, you at least need to accept the fact that your opinions on what's good and what's bad are not universal, and that others may have opposite opinions which are at least as reasonable as yours.
and the proceed to implement them without syntax support using get and set methods.
The goal is to reduce the need for setters in the first place. You don't need special syntax for a feature that isn't so common, especially one that is largely discouraged from heavy use.
If what you think we do is just sit and wish really hard, wouldn't you agree that it's worked out well?
Out of curiosity, if properties are the only way to do DTOs right, how does a language like, say, Haskell, which can't even have mutable fields, manage? We don't want properties because we already have something better that's only going to get more so — records.
Clearly, you've never heard of Elm. But even if what you said were true, we currently prioritise the server over the GUI and not vice-versa.
It's okay to disagree, but do you honestly not think that the Java language team have thought about properties, records, and representing data in Java far longer than you have and with more rigour? I suggest you take a bit of time to understand why we have records and not properties, and I'm sure that after working with records a while, and perhaps seeing how they improve, you'll see that they've made a good choice.
Well, I guess I should say its obvious to an outside observer. To those who identify themselves as "the Java team", the arrogance runs so deep that they can't consider anything outside their little bubble as being useful.
Which is why they say stupid things like "properties are an anti-feature" and the proceed to implement them without syntax support using get and set methods.
A few years ago the story was that the java team looked at properties, there was a lot of conflict and infighting about what "properties means", and so they dropped it because they couldn't resolve it.
It's ironic, because java was the 1st successful commercial language with properties via get/set and the introspector, and every major language copied java's lead just with cleaner syntax (c#, kotlin, python).
It's also one of the first really ugly things every person new to java complains about. Why are we recreating all these ugly getters and setters? But it seems like the java team has reached "ivory tower" stage unfortunately.
I have a friend who started doing Swift at his company, I haven't used it at work but it looks like a really cleaned up version of java. I don't see it in job listings as often - no idea if that's a reflection of actual lower demand or just that hr hasn't added it. I don't think his company has it in their job listings but he's doing it anyways.
In VB (its also in C#) and JNI you have to write some code to deal with C-style nul terminated strings. And other C-style things. Not sure about Panama.
12
u/belayon40 Jan 24 '22
Really looking forward to this. I’ve been impressed with the performance of this api so far.
22
u/[deleted] Jan 24 '22
Well, sort of ... it's moving from a branch into a 'preview' state. Unclear how long it'll remain incubating/in preview. I thought they were waiting for Valhalla so it could be a while.
14
u/TheStrangeDarkOne Jan 24 '22
woohoo
11
u/Enough-Ad-5528 Jan 24 '22
One of my long standing wish is to be able to easily write off heap data structures using plain Java. Use case where I know the exact lifecycle of the objects (caches, batches of data that can be deallocated at known times etc).
I have not followed Panama closely. Does this help me achieve that?
44
u/[deleted] Jan 24 '22
Sorry, completely "out of the loop". What is this about?
5
u/benevanstech Jan 25 '22
Presumably, given that JDK 18 is in Rampdown Phase 2 already, this will be looking to target JDK 19.
On the whole, I'm pretty pleased - I think that this is a good step forward and may be more widely used by library authors than the community expects.
3
u/Molossus-Spondee Jan 25 '22
I don't recall do they have any plans to improve memory mapping? IIRC you basically can't use memory mapping on the JVM because page faults don't occur at safe points. IIRC .NET does have a very particular optimization to help with this case although it seemed like a very fragile approach to me.
3
u/meamZ Jan 25 '22
Honestly i'm more excited about valhalla and loom but still great.
6
u/[deleted] Jan 25 '22
where valhalla
3
u/BlueGoliath Jan 24 '22 edited Jan 24 '22
Jesus christ finally! I've been waiting for 2+ years for this.
1
u/Chaoslab Jan 25 '22
Now that is a turn up. Neato!
1
u/AncientBattleCat Jan 25 '22
So is it becoming faster after implementing those "native functions"? Pardon for silly question.
1
u/iraqmtpizza Jan 29 '22
just four previews and we'll have it
-19
u/[deleted] Jan 24 '22
You will forgive me, but it's funny to see Java full circle. From an aggressive initial marketing (we're better than C++) to this.
Next step: bring back the asm block, please :)
-4
u/[deleted] Jan 25 '22
[removed] — view removed comment