How much memory is used for function references in a Java object?

泄露秘密 提交于 2019-12-11 15:35:23

问题


Is it 32-bit / 64-bit depending on the JVM, or is it less as do we really need that many possibilities for addresses when addressing functions?

Surely we would never need that many possibilities as the number of types, and resulting number of functions would never reach these numbers?


回答1:


The by far simplest implementation uses the "real"/full address of the function, whatever that may be on the architecture in question (e.g. the virtual address of the first instruction of the function prologue). So yeah, such a function pointer will probably be a word large. And this is a good thing!

Size is not anywhere as important as for object references or object headers, because there is only one such pointer in the whole process per method, regardless of how many instances there are. Moreover, any scheme for shrinking the address means you need additional operations to call the function pointed to (either some indirection, or some arithmetic). That would be bad, because it has to happen every time a virtual method (which is all of them prior to optimizations, and still quite a few afterwards) is called.



来源:https://stackoverflow.com/questions/19323060/how-much-memory-is-used-for-function-references-in-a-java-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!