Spring 可缓存对象存储在哪里?
Where are Spring cacheable objects stored?
我在我的项目中使用 Spring 缓存,我想使用 visualVm 分析 java 内存,我想知道缓存对象在哪里
- 真的存储在堆中吗?
- 是存储在eden还是old内存中?
谢谢。
不可能知道 任何 对象的存储位置,而不仅仅是 Spring 对象。对象可能处于伊甸园、幸存者 space 或终身制。在 JDK 7 或更早版本中,类 等某些内容存储在 perm gen 中(根据 this Oracle blog post:“ 永久生成已在 JDK 中完全删除8".).
垃圾收集器可以并且将会在幕后四处移动对象。发生这种情况的时间和方式取决于您使用的特定垃圾收集器、您使用哪些标志来指定 GC 行为,以及应用程序的其余部分对内存执行的操作(读取和写入)。
Eden、survivor 和 tenured 都在堆上。对于较旧的 JVM,一些东西将分配在堆外的 perm gen 中。查看 this document on JConsole usage 中的“监控内存消耗”以获得更多详细信息。
同样来自该文档,这是堆与非堆的一个很好的总结:
Heap and Non-Heap Memory
The Java VM manages two kinds of memory: heap and non-heap memory, both of which are created when the Java VM starts.
Heap memory is the runtime data area from which the Java VM allocates memory for all class instances and arrays. The heap may be of a fixed or variable size. The garbage collector is an automatic memory management system that reclaims heap memory for objects.
Non-heap memory includes a method area shared among all threads and memory required for the internal processing or optimization for the Java VM. It stores per-class structures such as a runtime constant pool, field and method data, and the code for methods and constructors. The method area is logically part of the heap but, depending on the implementation, a Java VM may not garbage collect or compact it. Like the heap memory, the method area may be of a fixed or variable size. The memory for the method area does not need to be contiguous.
我在我的项目中使用 Spring 缓存,我想使用 visualVm 分析 java 内存,我想知道缓存对象在哪里
- 真的存储在堆中吗?
- 是存储在eden还是old内存中?
谢谢。
不可能知道 任何 对象的存储位置,而不仅仅是 Spring 对象。对象可能处于伊甸园、幸存者 space 或终身制。在 JDK 7 或更早版本中,类 等某些内容存储在 perm gen 中(根据 this Oracle blog post:“ 永久生成已在 JDK 中完全删除8".).
垃圾收集器可以并且将会在幕后四处移动对象。发生这种情况的时间和方式取决于您使用的特定垃圾收集器、您使用哪些标志来指定 GC 行为,以及应用程序的其余部分对内存执行的操作(读取和写入)。
Eden、survivor 和 tenured 都在堆上。对于较旧的 JVM,一些东西将分配在堆外的 perm gen 中。查看 this document on JConsole usage 中的“监控内存消耗”以获得更多详细信息。
同样来自该文档,这是堆与非堆的一个很好的总结:
Heap and Non-Heap Memory
The Java VM manages two kinds of memory: heap and non-heap memory, both of which are created when the Java VM starts.
Heap memory is the runtime data area from which the Java VM allocates memory for all class instances and arrays. The heap may be of a fixed or variable size. The garbage collector is an automatic memory management system that reclaims heap memory for objects.
Non-heap memory includes a method area shared among all threads and memory required for the internal processing or optimization for the Java VM. It stores per-class structures such as a runtime constant pool, field and method data, and the code for methods and constructors. The method area is logically part of the heap but, depending on the implementation, a Java VM may not garbage collect or compact it. Like the heap memory, the method area may be of a fixed or variable size. The memory for the method area does not need to be contiguous.