Java- Where does the variable name or Identifier gets stored, Stack or Heap?

南笙酒味 提交于 2020-06-22 12:46:07

问题


Where does the identifiers or variable name gets stored in java? I understand that objects get stored in heap and variable gets store in heap or stack depending on the type and scope of variable. Can we debug or write any program to confirm it?

Thanks & Regards


回答1:


Names of fields are stored as part of the class metadata, in formerly-PermGen now-Metaspace.

Array elements don't have names, only numbers. (Cue Patrick McGoohan.)

Names of method and constructor parameters and local variables and handler parameters are stored only in the debug-symbols info in the classfile, if that option is selected. They aren't needed by the JVM because the compiler has mapped them to stack-frame slot numbers used in the bytecode.




回答2:


Variable names are stored in "method area" (which is part of the permgen.) along with other class meta-data.

There is a special area to hold class meta-data called method area. This is part of permgen (which was in heap before java 8) now it has been moved to metaspace




回答3:


Variable names are stored in method area of permanent generation. Object are always stored in the Heap, but object reference stored in the stack.



来源:https://stackoverflow.com/questions/37189211/java-where-does-the-variable-name-or-identifier-gets-stored-stack-or-heap

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