简体   繁体   English

如何在OpenJDK中禁用垃圾回收线程?

[英]How to disable garbage collection threads in OpenJDK?

I'm working on a JVM project where I need to disable garbage collection in JVM and get the out of memory error. 我正在一个JVM项目上,我需要在JVM中禁用垃圾收集并获取内存不足错误。

When we call system.gc(), GC gets called after sometime and I also wrote a program which invokes GC without calling system.gc(). 当我们调用system.gc()时,GC会在一段时间后被调用,我还编写了一个调用GC而不调用system.gc()的程序。 And it seems like they both follow the different call stacks while invoking GC. 似乎它们在调用GC时都遵循不同的调用堆栈。

I need to disable the GC for my research project purpose and how can I do that. 我需要出于研究项目目的而禁用GC,以及如何执行此操作。

Where do GC threads get scheduled in the OpenJDK code for the program which doesn't call system.gc() explicitly. 在未明确调用system.gc()的程序的OpenJDK代码中,GC线程在何处进行调度。

I'm using OpenJDK 11. 我正在使用OpenJDK 11。

There is no way to disable garbage collection entirely. 无法完全禁用垃圾收集。 Java 11 comes with an Epsilon (no-op garbage collector). Java 11带有Epsilon (无操作垃圾收集器)。 In JEP 318: 在JEP 318中:

Develop a GC that handles memory allocation but does not implement any actual memory reclamation mechanism. 开发一个可以处理内存分配但不实现任何实际内存回收机制的GC。 Once the available Java heap is exhausted, the JVM will shut down. 一旦可用的Java堆耗尽,JVM将关闭。

So, after a while will see the out of memory error. 因此,过一会儿就会看到内存不足错误。 It can be enabled by the -XX:+UseEpsilonGC option at JVM start. 可以在JVM启动时通过-XX:+UseEpsilonGC选项启用它。

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

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