本文介绍了反射如何影响Perm的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我理解perm大小用于存储元数据,包括字节代码,静态东西等。

I have the understanding that perm size is used to store meta data, that would include byte code, static stuff etc.

我的问题如何使用反射影响烫发尺寸,如果有的话。
我的意思是如果 Program-A 使用正常运行方式的方式而 Program-B 全部使用反射, perm-size将如何使用两个程序比较

My question how does usage of reflection affect the perm size, if it ever does.I mean if Program-A uses normal way of running objects and Program-B uses reflection all over, how will the perm-sizes of the two programs compare?

推荐答案

当你执行加载新类的代码时,perm空间会增长内化字符串。必须加载反射类,这是肯定的。我不确定反射API是否确实使用内化字符串,但不应该很难找到。

The perm space will grow when you execute code that will load new classes or internalize strings. The reflection classes have to be loaded that's for sure. I'm not sure if the reflection API does use internalized strings heavily but it should not be to hard to find out.

例如方法 getDeclaredMethod(String name,Class<?> ... parameterTypes) name参数将被内化。

For example for the method getDeclaredMethod(String name, Class<?>... parameterTypes) the name parameter will be internalized.

此片段将很好地填充烫发空间:

This snippet will nicely fills up the perm space:

Random random = new Random();
while(true){
    try {
        X.class.getDeclaredMethod(toBinaryString(random.nextLong()));
    } catch (Exception e) {
    }
}

在现实世界的应用程序中,它没有任何区别。

这篇关于反射如何影响Perm的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 14:45