jvm - Are objects prefetched from an array of references in Java? -
imagine have 1000 objects of same type scattered across memory (they created @ different times , other objects have been created in between).
we have array holds references each of 1000 objects.
question
if iterate on array sequentially, prefetched cache of cpu? references array holds or references dereferenced , objects loaded cache well?
does java (the jvm) implement kind of software prefetching? if not, there libraries provide software prefetching?
after research, common jvm implementation (hotspot) used to support prefetching. has been removed, since there no practicle use them. @apangin link bug report.
as @markspace mentioned, objects re-arranged easier access during collections - called "compacting", , present in default gc used hotspot. shouldn't need worry such underlying details, vm handles you.
a little deeper compacting..
you've heard of "stop-the-world" - occurs when object graph in inconsistent state. objects being moved around, thread might access object thats no longer there. there gc implementations considered "pauseless", such shenandoah gc, use forwarding pointer allow thread access object moved.
the point being, don't need worry object may located in memory, or how far location object. vm designed take care of these decisions you.
the final answer
so, objects prefetched array of reference? you shouldn't worry it. use java not have care these underlying details.
if you're interested in such details (maybe there's strange bug you're encountering), i've mentioned before, it's implementation specific, , you'd have specific implementation you're referring to.
although, said before, it's java; stop worrying things don't need worry about. can't emphasize enough.
Comments
Post a Comment