可以将JVM的方法区域垃圾收集?

时间:2022-10-29 23:55:35

so I was reading the JVM specification, and encountered the following section:

所以我正在阅读JVM规范,并遇到以下部分:

Although the method area is logically part of the heap, simple implementations may choose not to either garbage collect or compact it.

虽然方法区域在逻辑上是堆的一部分,但是简单的实现可能选择不垃圾收集或压缩它。

I am not sure that I get that, is this saying that the text segments in JVM could be garbage collected ? how should I understand that ?

我不确定我是否会这样说,这是说JVM中的文本段可能是垃圾收集的吗?我该怎么理解?

2 个解决方案

#1


3  

I am not sure that I get that, is this saying that the text segments in JVM could be garbage collected ?

我不确定我是否会这样说,这是说JVM中的文本段可能是垃圾收集的吗?

This is not typically referring to "text" (words) or to the "text segment" in the Unix/Linux sense. It is referring to the dynamically allocated regions of memory that contains a method's bytecode and/or JIT compiled native code. It is saying that those memory segments could be garbage collected ... depending on the JVM implementation, etcetera ... but this is NOT a requirement of the JVM specification.

这通常不是指“文本”(单词)或Unix / Linux意义上的“文本段”。它指的是动态分配的内存区域,其中包含方法的字节码和/或JIT编译的本机代码。这是说那些内存段可以被垃圾收集......取决于JVM实现,等等......但这不是JVM规范的要求。


In a JVM implementation where Java bytecodes are compiled to native code and linked into an executable image ahead of time, you will have "text segments", and those text segments won't be subject to garbage collection. (They can't be, because they are read only, and possibly shared with other instances of the application executing at the same time.)

在JVM实现中,Java字节码被编译为本机代码并提前链接到可执行映像,您将拥有“文本段”,并且这些文本段不会受到垃圾回收的影响。 (它们不能,因为它们是只读的,并且可能与同时执行的应用程序的其他实例共享。)

#2


2  

When a method executes, local variables live on the stack.

方法执行时,局部变量存在于堆栈中。

It is conceivable that The JVM may chose to not collect local variables and re-use the same memory for the next execution of the method. Such a choice would only be sane in single-threaded runtime environments.

可以想象,JVM可以选择不收集局部变量并重新使用相同的存储器以用于下一次执行该方法。这样的选择只会在单线程运行时环境中得到理解。

#1


3  

I am not sure that I get that, is this saying that the text segments in JVM could be garbage collected ?

我不确定我是否会这样说,这是说JVM中的文本段可能是垃圾收集的吗?

This is not typically referring to "text" (words) or to the "text segment" in the Unix/Linux sense. It is referring to the dynamically allocated regions of memory that contains a method's bytecode and/or JIT compiled native code. It is saying that those memory segments could be garbage collected ... depending on the JVM implementation, etcetera ... but this is NOT a requirement of the JVM specification.

这通常不是指“文本”(单词)或Unix / Linux意义上的“文本段”。它指的是动态分配的内存区域,其中包含方法的字节码和/或JIT编译的本机代码。这是说那些内存段可以被垃圾收集......取决于JVM实现,等等......但这不是JVM规范的要求。


In a JVM implementation where Java bytecodes are compiled to native code and linked into an executable image ahead of time, you will have "text segments", and those text segments won't be subject to garbage collection. (They can't be, because they are read only, and possibly shared with other instances of the application executing at the same time.)

在JVM实现中,Java字节码被编译为本机代码并提前链接到可执行映像,您将拥有“文本段”,并且这些文本段不会受到垃圾回收的影响。 (它们不能,因为它们是只读的,并且可能与同时执行的应用程序的其他实例共享。)

#2


2  

When a method executes, local variables live on the stack.

方法执行时,局部变量存在于堆栈中。

It is conceivable that The JVM may chose to not collect local variables and re-use the same memory for the next execution of the method. Such a choice would only be sane in single-threaded runtime environments.

可以想象,JVM可以选择不收集局部变量并重新使用相同的存储器以用于下一次执行该方法。这样的选择只会在单线程运行时环境中得到理解。