Re:A Case for Properties: Programming Language Design
by Someone on Sunday November 15, 2020 @04:20PM
(#25104982)
All public non-final methods in Java are virtual, so it is not _that_ trivial. You would have to check all subclasses that might get passed as an argument and check that again whenever new classes are loaded into the JVM.
Re:A Case for Properties: Programming Language Design
by wging on Sunday November 15, 2020 @04:52PM
(#25105268)
JVMs are quite smart about this sort of thing, and a nonfinal method can still be inlined, even though the JVM has to safely undo that optimization if a class is loaded. I'm not sure where I learned this originally, but Aleksey Shipilev has a post on method dispatch that should explain it. https://shipilev.net/blog/2015/black-magic-method-dispatch/
Re:A Case for Properties: Programming Language Design
by _old_dude_ on Sunday November 15, 2020 @05:24PM
(#25105528)
It's exactly what the JVM does, it's called Class Hierarchy Analysis (CHA). The VM checks if a method is actually overridden or not.
When a new class is loaded, the analysis checks which codes are no longer valid and mark them for deoptimization.
Surely these would be trivially inlined?