28 ms·
JDK 20 G1/Parallel/Serial GC Changes
- gigatexal 4y agoOff-topic but about Java generally: Java is such a storied and long-running and used-almost-everywhere language especially in Data Engineering (see all the Apache Data Eng projects like Calcite, Hudi, etc) but I just find it soooooo verbose and everything being a class and having to override things ugh .. it's all the things I hate about OOP in the forefront.
- carimura 4y agoOne of the goals of Project Amber [1][2] is to move the language towards a more data-oriented programming model. With Records, patterns, sealed classes, etc., it should feel much less verbose over time. And unrelated to your concern but addressing some of the learning overhead, see Paving the Onramp. [3] [1] https://openjdk.org/projects/amber/ https://openjdk.org/projects/amber/ [2] https://inside.java/tag/amber https://inside.java/tag/amber [3] https://openjdk.org/projects/amber/design-notes/on-ramp https://openjdk.org/projects/amber/design-notes/on-ramp
- halfmatthalfcat 4y agoSo...Scala?
- carimura 4y agoSure, but you could refer to the lineage of a dozen languages. Most of the world runs Java and evolving it takes care and consideration not to alienate a massive user base and ensuring that it evolves in the right way, not quick responses to fashions and trends.
- eternalban 4y agoIsn't there natural interop between Java and Scala? Why needlessly enlarge the language.
- vips7L 4y agoScala is super complex, introduces breaking changes all the time, is super slow to compile, multi-language projects are also complex, and the decisions that are right for Scala may not be right for Java.
- oweiler 4y agoScala is also on the way out, adoption is steadily decreasing.
- halfmatthalfcat 4y agoI'm not sure I would characterize it as "steadily". I think it's leveled off but I would agree it's not gaining any market share currently.
- hf_twink 4y agoYep, we’re migrating away from it at work too, too many problems, too slow to work with, and too much breaking.
- bcrosby95 4y agoI wish Scala leaned into being a Haskell-like (opinionated statically typed functional language) for the JVM rather than a kitchen sink.
- suresk 4y agoThere was definitely a large and vocal part of the community that wanted that, but I think early on there was a lot of tension between Scala being "better Java" and "Haskell for the JVM", and that probably hindered a lot of adoption.
- 4y ago
- srparish 4y agoAny word on when some of project amber features will come out of preview? I get excited each JVM release for some of those features, but it seems like most of the releases the preview count just gets bumped, and a few more get added to the preview holding pattern.
- pron 4y agoText blocks, var, records, sealed classes, and pattern matching in instanceof have been out of preview for some time, but two more features -- record patterns (https://openjdk.org/jeps/440 https://openjdk.org/jeps/440) and pattern matching in switch (https://openjdk.org/jeps/441 https://openjdk.org/jeps/441) -- are about to come out of preview.
- gigatexal 4y agoVery cool!
- marwis 4y agoIs there any work to make records actually usable out of the box? Things like copying or creating derived records are a huge pain (or slight pain with code generators) while other languages have solved this long ago (even JS and C#).
- kaba0 4y agohttps://github.com/openjdk/amber-docs/blob/master/eg-drafts/reconstruction-records-and-classes.md https://github.com/openjdk/amber-docs/blob/master/eg-drafts/... This is the vague plan.
- dgf49 4y agoSo your (general) complaints are all you do add to this when others try to create things to help others?
- the_gipsy 4y agoJust try something else.
- re-thc 4y agoAnd then you'll hear of it being "verbose" and "boring" too. Grass is always greener...
- ludovicianul 4y agoAs the classic saying says: there are languages everyone complains about and languages that are not (actually) used. Verbosity is usually a _good_ think especially in large code bases with large number of people (where every successful startup will eventually get)
- oweiler 4y agoIf verbosity would be a good thing Java wouldn't introduce language features/ library enhancements to cut down the noise (var, collection factories, switch expressions, records).
- ludovicianul 4y agoThose features are being released to please a larger set of people. People were relying on 3rd party libraries anyway for similar capabilities.
- alfalfasprout 4y agoThe longstanding lack of generics (which has been remedied aside) who really complains about golang? The reality is Java truly shows its age. Its dogmatic insistance on pure OOP and the enormous numbers of horrifyingly unintuitive design patterns adopted by the community cause even the most well intentioned engineering culture to eventually produce ugly codebases. At this point if you're stuck in the JVM ecosystem you're almost certainly better off with Scala (which indeed is actually used) or the newer Kotlin. In a way, for all the shit people give C++ modern C++ codebases are actually quite pleasant and the language is very flexible. Would I encourage its use for general production systems? Not really. That crowns is Golang's.
- seanw444 4y agoAgreed. Reading and writing Java code just really annoys me. It's so ugly, in my opinion.
- dboreham 4y agoJust for balance: after writing much Java years ago, then moving on to mostly JS/TS, Scala and Kotlin, going back and looking at old Java I forget writing, it looks very nice and easy to understand.
- dahfizz 4y ago>> It's so ugly > nice and easy to understand Java is definitely more practical than pretty. This frustrates the trendy crowd, but I think its important for tools to be practical. Shiny, pretty languages are never as long-lived as practical "ugly" languages.
- 5e92cb50239222b 4y agoIf it scares away the "let's rewrite it in language/framework of the day" crowd, that's a plus in my book.
- seanw444 4y agoI'm certainly not a member of the "trendy crowd." I say Java is ugly as a fan of Lisp and C. There's just so much boilerplate to implement something basic.
- therealdrag0 4y agoGoing from Java 8 to Scala was mind melting. Would never want to go back. Though I’ve heard later versions of Java are better. And katlin seems like an in between.
- usrusr 4y agoOr stick to kotlin and keep the mind conveniently solid ;) I was one of the Bored Scala Crowd in the audience of a presentation by jetbrains people that must have been not too long after 1.0, took me half a decade to accept that a "poor man's scala" is actually the language that I want.
- therealdrag0 4y agoYa I’d love to give it a try. Probably will prioritize it for next job Switch.
- lmm 4y agoI found just the opposite. Kotlin would rather add 10 special cases than one higher-order abstraction; I'd rather learn one slightly fancy concept than a laundry list of ad-hoc cases.
- usrusr 4y agoThat's actually a quite accurate description of my own feelings. "Why emulate parts of scala on syntax level when you can have the real thing?". But that "real thing" is the one that drives people to lose themselves in cats vs scalaz debates and the like, there's clearly something in scala that causes a very strong "if you use it to write java without semicolons you're doing it wrong" undercurrent. "java without semicolons" kotlin isn't considered good either, but the distance from there to "kotlin as intended" isn't big at all.
- GregarianChild 4y agoAgreed! Regardless of programming language, every substantial software development needs to make serious architectural choices, otherwise things will become messy. I learned this the hard in my first programming job out of university. We were a C/C++ shop doing distributed software and one question to decide right upfront is: shared memory vs message passing. Both have advantages and disadvantages, but don't mix well. We started out with message passing, but over time somebody added POSIX shared memory as a performance hack (which two processes happen to run on the same machine). Over time, we added a second, non-POSIX shared memory layer for performance reasons under Windows. It was an unmaintainable mess. The core problem was that the CTO didn't understand distributed programming well enough to push back against those performance hacks. "How do you handle software architectural leadership?" used to be one of my replies to the inevitable "have you got questions for us?" in job interviews, when I was being interviewed. Now that I am making architectural decisions myself, I put a lot of efforts into this, for example building suitable linters that flag violations in code reviews. If your team fights over cats vs scalaz or over Scala-as-OO vs Scala-as-FP then that's a sign that the technical / architectural leadership is weak. Choices like pure-OO vs pure-FP vs mixing them require care, and are hard to change in-flight. If you have strong modularisation, you can successfully use different paradigms in different modules, but strong modularisation needs care and architectural discipline, too. Part of the problem is that the style of programming that libraries like cats require (monads, functors, applicative, type-classes, HKTs) is not yet widely understood. This approach to programming needs its 'map/reduce moment' and become part of the mainstream introduction-to-programming curriculum. We'll get there, maybe in about a decade.
- nogridbag 4y agoI've returned to Java after using Clojure and Groovy for several years. I appreciate the fact that Java's just plain boring and slightly verbose. Most of the time the complexity in my code has little to do with Java being verbose and more due to the business problem. There are areas to improve and Java's been making great strides recently. For example, in Java 21 we may finally have methods like getFirst() and getLast() for lists (via JEP 431) instead of the incredibly clunky list.get(list.size() - 1). Java also recently added multi-line Strings and templating is coming shortly. Streams and Optionals also reduce quite a bit of boilerplate, e.g. Optional's map and ifPresent methods are often elegant. Really I can't think of many other areas where Java gets in the way. Our team is incredibly productive with modern Java. I think most developers actually write overly verbose code regardless of the language. And it seems little to do with years experience. This youtube channel covers most of the basics: https://www.youtube.com/@CodeAesthetic https://www.youtube.com/@CodeAesthetic To me I just follow these recommendations naturally but in most PRs I review there's often huge amounts of overly nested code, poorly named methods, etc.
- ithrow 4y agoWhat do you miss from Clojure? BTW, is that your channel?
- nogridbag 4y agoNot my youtube channel. It just showed up in my recommended videos and it seemed like good advice (common sense). It's helpful to point devs to those videos when I see them making those types of mistakes. I miss the data oriented approach Clojure libraries take. I remember having an issue with Ring and I just dove into the Ring source code and it was so simple and clear and I found the solution to my issue in minutes. I've never had that experience with Java and instead resort to forums, stackoverflow, etc. Most Java libraries would have several layers of abstraction and they're often intimidating. I consider myself an amateur Clojure dev and yet still contributed some PRs to some projects. With that said, I've written some internal tools in Clojure and it was a nightmare whenever I had to modify them. They were pretty simple CLI tools that only needed updates every 6 months or so. I usually have to spin up the project with a repl just to understand the inputs and outputs to functions. I've ported all internal tools I created at my current company from Clojure to Java and I personally find them so much easier to maintain.
- ordx 4y agoIs there a good decision flowchart on how to chose GC for a particular task/application?
- brucethemoose2 4y agoI think generational ZGC is going to be the "sane default" soon.
- re-thc 4y agoWould be good to have more benchmarks and articles on G1 vs ZGC once that happens.
- marginalia_nu 4y agoEh, there's probably always going to be a different answer depending on whether you prioritize latency vs throughput.
- popfalushi 4y agoDefault gc depends on how many cpus and ram vm has. With 1 core it is always serialgc, for example. 2 cores and less than 4 gb - concurrent mark and sweep IIRC. G1GC starts a bit later.
- brucethemoose2 4y agoYeah but you dont necessarily want to use those defaults. They strike me as kind of archaic. For low resource use cases, you probably want Graal AOT above all else... which means G1GC or serial, I think.
- agilob 4y agoGraalAOT, do you mean native image or C2 compiler? Neither of these tuning is applicable in a discussion about GCs
- lkorinth 4y ago
- yupyup54133 4y agoLove Java. Very much looking forward to LTS Java 21. <3
- ithrow 4y agoIn the world of web development why would one pick Java(or Kotlin) over TS/node.js ?
- boomskats 4y agoJava's superior G1/Parallel/Serial GC that they're changing?
- pphysch 4y agoI'd wager TS/node/etc going the way of PHP and JQuery in the next decade. SPA will go full WASM (which you could technically use Java for) and non-SPA will be built off better browsers (e.g. WebKit adding nested CSS) and HTMX-style solutions. Note that it doesn't mean everyone will be rolling their own WASM-based engine, but that there will be a bunch of public WASM-based engines (like PyScript/Pyodide stuff) that are tailored for specific domains than one-size-fits-all React. This leaves "full stack JS" in an awkward middle ground. Sure, you could still use it on your backend (like PHP), but why? We use JS because there were literally no other practical options, but better browsers and WASM are providing new options.
- cbm-vic-20 4y agoJava has really good runtime monitoring capability. Being able to get a thread dump from a production system, or generating Flight Recorder logs for offline analysis is incredibly useful. Is there something similar in the Node ecosystem?
- winrid 4y agoNope. You can get a heap dump which gives you object allocation stats by "object shape" which is incredibly less useful than stats by ClassPath.
- 4y ago
- throw0101b 4y agoDo people follow GC research at all 'for fun'? Any places/sites/people to pay attention to for the latest and greatest goings-on that may show up in production x years from now?
- carimura 4y agoWe try and aggregate content from the GC team here [1]. [1] https://inside.java/tag/gc https://inside.java/tag/gc
- BenoitP 4y agoI do follow Loom 'for fun', lurking the mailing list archives [1]. You can definitely do the same for GC implementation [2] (general topic list here [3]); but it may not talk a lot about external initiatives like Shenandoah. Beware that you're gonna have to filter a lot! There's patch merging and very low detail implementation conversations. For example, you'd be pleased to know that G1 can now skip a guard in card-table clearing [4]. Don't ask me what is the card table and guards and why do you need to clear it, though. One thing I'm looking for in GC advances is new hardware support for it in RISC-V J extension. There's gonna be memory tagging (helping security and memory management in GCs), and pointer masking (hardware support for what ZGC does under the hood)[5]. But we're probably a good 5 years away from seeing that in real life, if ever. [1] https://mail.openjdk.org/pipermail/loom-dev/ https://mail.openjdk.org/pipermail/loom-dev/ [2] https://mail.openjdk.org/pipermail/hotspot-gc-dev/ https://mail.openjdk.org/pipermail/hotspot-gc-dev/ [3] https://mail.openjdk.org/mailman/listinfo https://mail.openjdk.org/mailman/listinfo [4] https://mail.openjdk.org/pipermail/hotspot-gc-dev/2023-March/041586.html https://mail.openjdk.org/pipermail/hotspot-gc-dev/2023-March... [5] https://github.com/riscv/riscv-j-extension/blob/master/pointer-masking-proposal.adoc https://github.com/riscv/riscv-j-extension/blob/master/point...
- suresk 4y agoI am interested in this area too, but I don't know of any single place to follow it all. I have found that there isn't an avalanche of "new" stuff, but a lot of different ideas with different tradeoffs that change in relevance based on usage patterns, languages/runtimes, and hardware characteristics. Besides the JVM resources linked by others, I found Richard Jones's "Garbage Collection Handbook" to be a decent introduction for background [1]. The Go team has written a bunch about their GC approach [2] - it is really interesting to see how it compares to the various options in the JVM and under which scenario you might prefer one or the other. And occasionally there are interesting articles on arxiv. 1. http://gchandbook.org/ http://gchandbook.org/ 2. https://go.dev/doc/gc-guide https://go.dev/doc/gc-guide
- fulafel 4y agoHas anyone ever tried to port OpenJDK's fancy garbage collectors other runtimes? 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, but still, would be interesting to hear about attempts.
- titzer 4y agoAFAIK, no. The opposite is true with MMtk (https://www.mmtk.io https://www.mmtk.io), which is a toolkit with many GC algorithms implemented that has been plugged into other runtimes, including, as it happens, OpenJDK.
- mike_hearn 4y agoThat would be difficult. The GCs share a lot of code, and have a lot of code to deal with Java specific things like class unloading and soft/weak/phantom references. It's easier to run other languages on top of the JVM runtime, which is what projects like Truffle and JRuby do.
- 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.
- twic 4y ago> thread-local allocation buffers (PLABs) :-/
- ok_dad 4y agoIs there a good guide to learning modern Java? At my workplace, we’re thinking about using it for a few things from Python. I’m not looking for a “Java for Python developers” but more like “Java for people who already know about the basic structures of programming languages”. I would love to hear about variable instantiating and for loops as little as possible to grok the Java model of programming, then drive right into the meaty bits of how Java programmers think today. I did Java 20 years ago in college.
- dxxvi 4y agoHave you ever heard of the book Core Java for the Impatient?
- mikmoila 4y agohttps://dev.java/ https://dev.java/
- znpy 4y agothis looks awesome, thank you!
- xdavidliu 4y agoI recommend The Core Java pair of books by Cay Horstmann, supplemented by Effective Java by Bloch. Those are probably the two most authoritative sources on Java out there, and both highly readable. I heard not so good things about Herb Schildt's book.
- deleted 4y ago[deleted]
- ptx 4y agoI second this recommendation! I read Horstmann's books recently and they were excellent. He really puts things in context – any time I was thinking "WTF? Why would they do things this way?" he had an explanation coming up (or in some cases an acknowledgment that it is indeed a WTF).
- corpMaverick 4y agoHow much memory can you use for a Java app? My java/kotlin app needs to keep a big table fully in memory. (~10 million records). And it is reloaded about 3 times a day. In C, I would just malloc the whole table in one chunk. Perhaps there is a specialized GC for this usage ?
- slantedview 4y agoIt depends if your VM is native or not. Ex: https://www.graalvm.org/ https://www.graalvm.org/
- jsyolo 4y agoHow much memory? ZGC is made for multi-terabyte heaps.
- jayd16 4y agoWhat's wrong with newing the whole thing? Or even the fully naïve solution of newing as needed?
- vbezhenar 4y agoThere's no particular limit to JVM, you can use all available memory if you like. For best performance you can decompose your structure to primitive fields (int, float, char, etc) and create array for every field. So you have, say, 10 arrays with million items each. Instead of creating one array which holds pointers to another 10 million objects on the heap. It gets tricky with strings (you need to flatten all strings into a giant char[] array and keep two arrays with index and length data, but doable. Though 10 million of records might be OK for JVM. Measure your GC times. I'd suggest to hide implementation details behind API, start with ArrayList<MyRecord> and refactor it later if needed.
- sacnoradhq 4y agoFor a better GC experience, stop stopping the world and stop sharing mutable state. ORCA (and Pony language) solved this while allowing selective mutability and zero-copy message passing improving on Erlang HiPE/BEAM by tying objects to a tiny heap with individual actors (cooperative async threads). There is no global locking in Pony except in limited circumstances. Zulu C4 is an improvement. Schism and Metronome are less pausey but slower overall. https://www.azul.com/products/components/azul-zulu-prime-builds-of-openjdk/ https://www.azul.com/products/components/azul-zulu-prime-bui... https://dl.acm.org/doi/10.1145/1809028.1806615 https://dl.acm.org/doi/10.1145/1809028.1806615 https://researcher.ibm.com/researcher/view_group_subpage.php?id=206 https://researcher.ibm.com/researcher/view_group_subpage.php...