当前位置:网站首页>JVM方法区
JVM方法区
2022-06-11 20:54:00 【只是六号z】
方法区的理解
《Java虚拟机规范》中明确说明:"尽管所有的方法区在逻辑上是属于堆的一部分,但一些简单的实现可能不会选择去进行垃圾收集或者进行压缩。”但对于HotSpotJVM而言,方法区还有一个别名叫做Non-Heap (非堆),目的就是要和堆分开。
所以,方法区看作是一块独立于Java堆的内存空间。
我们可以通过测试代码来查看方法区的存在。
/** * @author zal * @date 2022年02月19日 20:49 * @Description 测试设置方法区大小参数的默认值,设置JVM参数为 -Xms600m -Xmx600m */
public class MethodAreaDemo {
public static void main(String[] args) {
System.out.println("start。。");
try{
Thread.sleep(100000);
}catch (InterruptedException e){
e.printStackTrace();
}
System.out.println("end...");
}
}
运行程序之后可以通过javaVisualVM查看内存分布。

所以可以说方法区是堆的一块独立空间。
- 方法区(Method Area)与Java堆一样,是各个线程共享的内存区域。
- 方法区在JVM启动的时候被创建,并且它的实际的物理内存空间中和Java堆区一样都可以是不连续的。
- 方法区的大小,跟堆空间一样,可以选择固定大小或者可扩展。
- 方法区的大小决定了系统可以保存多少个类,如果系统定义了太多的类,导致方法区溢出,虚拟机同样会抛出内存溢出错误: java.lang.outOfMemoryError:PermGen space或者 java.lang.outOfMemoryError: Metaspace
- 关闭JVM就会释放这个区域的内存。
设置方法区大小
jdk7以前,永久代大小可以使用
-XX:Permsize和-XX:MaxPermsizejdk8以后,元空间大小可以使用
-XX:MetaspaceSize和-XXMaxMatespaceSize指定
方法区的内部结构
1)类型信息
- 类型的完整全类名
- 类型的直接父类的完整有效名
- 类型的修饰符
- 类型直接接口的一个有序列表
2)域信息
- JVM必须在方法区中保存类型的所有域的相关信息以及域的声明顺序
- 相关信息包括:域名称、域类型、域修饰符
3)方法信息
- 方法名称
- 方法的返回类型
- 方法参数的数量和类型
- 方法的修饰符
- 方法的字节码
- 异常表
4)non-final的类变量
- 静态变量和类关联在一起,随着类的加载而加载
- 类变量被类的所有实例共享,即时没有类实例,也可以访问
边栏推荐
- 第二部分 数据链路层
- Object storage of CEPH distributed storage
- Pyqt5 technical part - cause of the problem that setting the top of the window does not take effect. Setwindowflags() does not take effect after setting the parameters. Solution
- Compilation process of program
- Docker installing MySQL
- 【指标体系】最新数仓指标体系建模方法
- 重投农业,加码技术服务,拼多多底盘进一步夯实
- How to add text on the border in bar code software
- unity package manager starting server stuck(Unity啟動卡在starting server,然後報錯)
- Implement AOP and interface caching on WPF client
猜你喜欢
随机推荐
应用场景:现场直播节目制作NDI技术中PoE网卡的广泛应用
Current situation and future development trend of hot isostatic pressing service market in the world and China from 2022 to 2028
27. this pointing problem
成长的12条黄金法则
Lr-link Lianrui makes its debut at the digital Expo with new products - helping the construction of new infrastructure data center
11 r create random number
Final examination of Dialectics of nature 1
Compilation process of program
Weekly 02 | to tell you the truth, I am actually a student of MIT
Current situation and future development trend of global and Chinese cogeneration system market from 2022 to 2028
Chrome V8 source code 48 The secret of weak type addition,'+'source code analysis
moderlarts第一次培训
修改本地微信小程序的AppID
Force buckle 6 Zigzag transformation
Docker installation redis
Interviewer: what is the event flow and event model in JS?
为什么100G网络传输要使用iWARP、RoCE v2、NVMe-oF等协议
In idea, run the yarn command to show that the file cannot be loaded because running scripts is disabled on this system
2022-2028 global and Chinese thermocouple sensor market status and future development trend
【数据可视化】Apache Superset 1.2.0教程 (三)—— 图表功能详解









