Why defining class as final improves JVM performance?

后端 未结 5 1601
情书的邮戳
情书的邮戳 2020-11-29 01:41

Quoting from http://sites.google.com/site/gson/gson-design-document:

Why are most classes in Gson marked as final?

While Gson provides a

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-29 02:03

    Not knowing the implementation of every particular JVM, I would theoretically say that if a JVM knows that a pointer to an object is a pointer to a type that is final, it can do non-virtual function calls (i.e., direct vs. indirect) to a member functions (i.e., no indirection through a function pointer), which may result in faster execution. This may also in turn lead to inlinining possibilities.

提交回复
热议问题