1

I was reading the JEP doc about Value Objects in Java and came across a line in the motivation section in context of scalarization of objects that read like this:

There are optimizations which can eliminate object allocation in some regions of code. For example, objects can sometimes be "scalarized" into their component fields, if an escape analysis can be successfully carried out. However, such optimizations are limited in scope and applicability. For out-of-line calls, objects must still be boxed into memory, as long as existing Java reference semantics are enforced

I got the idea about the optimization that is spoken about here from the answer to this post.

The part that I am unable to understand is in the JEP, what does the author means by out-of-line calls? What can be a good example?

To keep it short, I understood the fact that Hotspot will unfold the fields of an Object and allocate them in the method stack if the object's scope doesn't leave the method.
What kind of code will look like out-of-line call?

Shankha057
  • 1,296
  • 1
  • 20
  • 38
  • 2
    Out-of-line means the opposite of in-line ... I think. The code doesn't look any different at the bytecode level. It is all about whether the JIT compiler has inlined it or not. – Stephen C Oct 04 '21 at 03:22
  • @StephenC If the bytecode looks exactly the same for let's say two (slightly) different kinds of human-readable code, how will JIT figure out the in-lining policy? Seems a bit counterintuitive to me. – Shankha057 Oct 04 '21 at 03:29
  • The JIT compiler decides whether to inline or not according to things like how large the method is. The thresholds are tuned and tunable. I recommend that you research this for yourself. – Stephen C Oct 04 '21 at 03:38
  • Yes, that is true. Let's say that I have two methods that are 30 lines long each in terms of bytecode. How would JIT know which one to inline and which one to not? Basically, what are the signs that JIT looks at beside method size, object scope and the other ones mentioned in the attached SO post? Basically, how would something like an out-of-line call look like in terms of Java code in terms of a very simple example? – Shankha057 Oct 04 '21 at 03:46
  • 1
    See https://stackoverflow.com/a/67797688/3448419 – apangin Oct 04 '21 at 08:46

0 Answers0