Java 7 cannot collect persistent code collected by Java 5
•
Java
Does anyone know why Java 7 can't collect permanent generation applications, resulting in Java Lang. outofmemoryerror: permgen, while the Java 5 collection and application run well?
The application executes the evaluation of Jython expression in the loop, and one iteration is about The body of the 5-second ring looks like:
PythonInterpreter py = new PythonInterpreter(); py.set("AI",1); ((PyInteger)py.eval(expr)).getValue()
Screenshots of jvisual VM are used for applications running in Java 7 and Java 5
In both cases, the same parameters are used:
-Xmx700m -XX:MaxPermSize=100m -XX:+HeapDumpOnOutOfMemoryError -Xloggc:"C:\Temp\gc.log" -XX:+PrintGCDetails -XX:-TraceClassUnloading -XX:+PrintClassHistogram
Solution
There is a small example to reproduce the problem. I found that programs running in Java 7 outside eclipse will not encounter memory leakage in the permanent generation
import org.python.core.PySystemState; import org.python.util.PythonInterpreter; public class Test01 { public static void main(String[] args) throws Exception { PySystemState.initialize(); long startNanos = System.nanoTime(); for(int i = 0; i < 450000; i++) { PythonInterpreter pi = new PythonInterpreter(); long elapsedNanos = System.nanoTime() - startNanos; int avgStepInMicros = (int)((elapsedNanos / 1000) / (i+1)); final String code = String.format( "stepNo = %d + 1\n" + "if stepNo %% 100 == 0:\n" + " print 'stepNo: %%d,elapsedMillis: %%d,avgStepInMicros: %%d' %% (stepNo,%d,%d)",i,elapsedNanos/1000000,avgStepInMicros); pi.exec(code); } } }
Mat displays a debugger thread as the garbage collector root
Strangely, debugging applications in Java 5 do not have this problem
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码