简体   繁体   English

java类住在哪里?

[英]Where do java class live?

I know Java objects, instance variables are created and live in the heap, while the local variables and object references are created and live in the stack. 我知道Java对象,实例变量已创建并存在于堆中,而局部变量和对象引用已创建并存在于堆栈中。

What about the "class" itself where does it live? 那么“阶级”本身在哪里生活呢?

Am asking this because when you create static variables you call them using the class name, eg 我之所以这样问是因为,当您创建静态变量时,会使用类名来调用它们,例如

Math.round()

When Math class is created, where does it live in memory (heap or stack) 创建Math类时,它在内存中的位置(堆或堆栈)

Gath 迦特

堆的Permgen(永久代)区域...

Java classes lives in Permanent Generation heap .Also the interned string pool is stored here. Java类位于Permanent Generation heap 。内部字符串池也存储在此处。

Permanent Generation heap contains: 永久世代堆包含:

  • Methods of a class (including the bytecodes) 类的方法(包括字节码)
  • Names of the classes (in the form of an object that points to a string also in the permanent generation) 类的名称(在永久代中也以指向字符串的对象的形式)
  • Constant pool information (data read from the class file, see chapter 4 of the JVM specification for all the details). 常量池信息(从类文件中读取数据,有关所有详细信息,请参阅JVM规范的第4章)。
  • Object arrays and type arrays associated with a class (eg, an object array containing references to methods). 与类关联的对象数组和类型数组(例如,包含对方法的引用的对象数组)。
  • Internal objects created by the JVM (java/lang/Object or java/lang/exception for instance) JVM创建的内部对象(例如,java / lang / Object或java / lang / exception)
  • Information used for optimization by the compilers (JITs) 编译器(JIT)用于优化的信息

类在PermGen空间(即堆)中加载

所有类都加载在PermGen空间中

You can read more about the Permanent Generation (where classes, methods, etc are stored) here: 您可以在此处阅读有关永久代(存储类,方法等的更多信息)的更多信息:

http://blogs.oracle.com/jonthecollector/entry/presenting_the_permanent_generation http://blogs.oracle.com/jonthecollector/entry/presenting_the_permanent_generation

Note however, that when you call a static method Java is actually making an internal instance of the object behind the scenes, so you are really calling the method on a "behind-the-scenes" global instance of the object. 但是请注意,当您调用静态方法时,Java实际上是在幕后创建对象的内部实例,因此您实际上是在对象的“幕后”全局实例上调用该方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM