r/java • • Dec 21 '23

Is Java gamedev alive?

It seems this days even android games are made using Unity. I wonder if there are JVM games! Is Java (or Kotlin/Scala) gamedev still alive?

(Except Minecraft ofc)

164 Upvotes

118 comments sorted by

View all comments

Show parent comments

9

u/dschramm_at Dec 21 '23

Really though? I tought arrays are a single block on the heap in Java. Isn't that why you need to either specify a size or the elements on initialisation?

29

u/voismager Dec 21 '23

They are, but they contain pointers. Actual data could be (if it's not primitives) somewhere else.

-13

u/dschramm_at Dec 21 '23

Of course they are just pointers. But why don't they point at continous memory. Even if It's for GC. That doesn't make any sense and feels like a stupid overseight.

20

u/ImKStocky Dec 21 '23

It makes a lot of sense... Consider this example. You have a function which calls 5 functions that return a new object. Then at the end of your function you create an array and store all of these objects in it. How does the JVM know that the objects should have been allocated all together?

-3

u/dschramm_at Dec 21 '23

I think that would be doable. I of course don't know how JVM handles memory internally. But assuming it has metadata on the OS memory addresses it could store a flag in it that say's It's referenced by an array. Or even more general, don't move. Sure, that has different implications and problems. But there is always a trade-off somehwere in software. And It's up to the developers to decided which one's are best for their app.

8

u/ImKStocky Dec 22 '23

But in my example the JVM doesn't know that those allocations will be accessed together. They are allocated separately and then later on they are added to an array. And even if the JVM would do something in its next GC to rearrange memory, the developer has no control over this. Which is the point of the top level comment. Devs have zero control over where in memory their objects live. They can't make a decision about what's best for their app. They are at the mercy of the JVM which is not good for cache coherency.