Live data from Hacker News

Inside the JVM: Arrays and how they differ from other objects

blogs.oracle.com

41–50 of 133 posts

Re: Inside the JVM: Arrays and how they differ from other objects

#41
post #36
post #24

Earlier quoted context omitted.

This choice probably pre-dates Oracle?

I think he's saying "how could he write that 0 length array is a surprising feature".

And the use of "primarily", when there is a much more common use case, so common that it's baked right into the standard libraries.

Re: Inside the JVM: Arrays and how they differ from other objects

#42
post #40
post #29

Earlier quoted context omitted.

I cannot for my life remember the argument order, so I write the manual code and let IntelliJ convert it.

Doesn't autocomplete show the arguments? I usually use Netbeans when I write Java, so no idea if InelliJ is just that bad.

IntelliJ definitely shows the arguments lol

Re: Inside the JVM: Arrays and how they differ from other objects

#43
post #35
post #18

Earlier quoted context omitted.

For that you need an Inside Hotspot, Inside OpenJ9, Inside GraalVM, Inside Azul, Inside ART, Inside microEJ, Inside PTC, Inside JamaicaVM, Inside.... Otherwise is like trying to discuss what does a C compiler do, when only looking through the lens of the C abstract machine in ISO C.

As far as I know, all those distributions use OpenJDK for that kind of stuff and don't really do much more than apply a few patches here and there, not change stuff like how the JVM packs bytes in memory. Would be happy to be proven wrong.

IBM OpenJ9 uses a mix of OpenJDK and their J9 toolchain.

Azul uses parts of OpenJDK, alongside their JIT Falcon infrastructure.

Microsoft OpenJDK based distribution has better escape analysis than regular one, although OpenJDK 22 should have those improvements merged.

And no, not all of them use OpenJDk, it is an urban myth, as usual.

Re: Inside the JVM: Arrays and how they differ from other objects

#45
post #30
post #19

Earlier quoted context omitted.

I cringe every single time I see a for loop for what System.arraycopy () has been providing since early days. For better or worse, it shows me that the author isn't that into Java.

Or it might be that the person has used multiple programming languages, across which the order/meaning of copy arguments varies a lot, and thus prefer to not remember the decision of each language (if not for writing (at which point the IDE could help), then for reading). Whereas a loop is always easy to read and write equally in all languages, and it's really not unreasonable to expect it to perform well enough (if…

Given that I have programed dozen of languages since 1986, and have to jump between C#, Java, C++, Typescript, Transact SQL and PL/SQL for work, plus whatever is needed to keep the customer happy, isn't an argument I would sympathise with in code reviews.

Re: Inside the JVM: Arrays and how they differ from other objects

#46
post #4

In my experience, just a little bit of insider knowledge goes a long ways to making better code. Arrays are fun things, especially when you do a deep dive into the System.arraycopy() function. But the same goes for all Collections in Java. For instance, most of them have a default size (mostly 10), and growing them is a costly operation. So knowing beforehand how large your collection can or may be, can benefit code.…

> For instance, most of them have a default size (mostly 10), and growing them is a costly operation. So knowing beforehand how large your collection can or may be, can benefit code. It's really a tricky balance. Over-allocating collections "just in case" can quite often be very expensive as well, since large array allocations tend to be fairly slow (since e.g. they typically won't fit in the TLAB).

> TLAB

TLB?

Re: Inside the JVM: Arrays and how they differ from other objects

#47
post #9

I was pretty disappointed that, for a blog called "Inside the JVM", very little in the blog entry discussed goings on inside the JVM. For example, when does the JVM typically optimize away bounds or null checks? How are arrays of booleans packed and what is their efficiency compared to arrays of bytes or words?

You want something like https://shipilev.net/jvm/anatomy-quarks/ (the author is a jvm maintainer, formerly at redhat now at aws).

Thanks for the link, that's an amazing resource!

Re: Inside the JVM: Arrays and how they differ from other objects

#49

Things I learned by reading this post * Java arrays can have 0 dimensions * When declaring arrays, trailing comma is allowed after the last element * In multi-dimensional arrays, only the last dimension contains actual values. Other dimensions are just pointers to arrays. Good read.

> Java arrays can have 0 dimensions The way you've phrased it is a bit ambiguous. Having 0 dimension sounds like x = new int[7][5]; // 2 dimensions y = new int[9]; // 1 dimension z = new int; // no dimensions, not an array, not allowed The phrasing you mean is "dimensions can have zero size".

Unfortunately the article author uses the exact same terminology:

> (It’s somewhat counterintuitive that the zero dimension is not the first one in the array.)

Re: Inside the JVM: Arrays and how they differ from other objects

#50
post #4

In my experience, just a little bit of insider knowledge goes a long ways to making better code. Arrays are fun things, especially when you do a deep dive into the System.arraycopy() function. But the same goes for all Collections in Java. For instance, most of them have a default size (mostly 10), and growing them is a costly operation. So knowing beforehand how large your collection can or may be, can benefit code.…

Does anyone have any good book recommendations or links for insider knowledge of the JVM/Java? If Clojure focused all the better :)
Post reply on HN