JVM(HotSpot):所有方法都去哪儿了?方法区?本机方法堆栈? [英] JVM (HotSpot) : Where do all the methods go ? method area ? native method stack?

查看:188
本文介绍了JVM(HotSpot):所有方法都去哪儿了?方法区?本机方法堆栈?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是JVM(HotSpot)的新手,并尝试了解它的架构及其工作原理,所以我的问题是所有方法(静态和非静态)都被转换为字节码吗?当JVM加载类文件时,它是否将所有方法加载到某个地方?像方法区?或本机方法堆栈?

I am new to JVM (HotSpot), and try to understand the architecture of it and how it works, so my question is that do all the methods (both static and non-static) get translated into byte-code ? and when JVM loads the class files, does it load all the methods into somewhere ? like method area ? or native method stacks ?

推荐答案

它依赖于JVM实现 - 不同的JVM可能会选择以不同的方式处理这个问题(因为它们符合Java规范)。所以你没有绝对的保证。

It's dependent on the JVM implementation - different JVMs may choose to handle this in different ways (as long as they conform to the Java spec). So you have no absolute guarantees.

在Sun / Oracle JVM中,方法数据被加载到一个名为Permanent Generation的特殊内存区域,这是一个垃圾收集器为类等长期对象保留的内存。

In the Sun/Oracle JVM the method data gets loaded into a special memory area called the "Permanent Generation", which is an area of memory reserved by the garbage collector for long-lived objects such as classes.

大多数其他工业级JVM可能会做类似的事情。

Most other "industrial-strength" JVMs are likely do something similar.

参见:

  • https://blogs.oracle.com/jonthecollector/entry/presenting_the_permanent_generation
  • How is the java memory pool divided?
  • http://www.oracle.com/technetwork/java/gc-tuning-5-138395.html

PS

这是非常高级的东西 - 你肯定不需要知道任何关于这一点的东西来充分利用Java和/或者JVM。您通常应该假设JVM代表您进行内存管理,并且会有效地进行内存管理 - 它需要专家多年的调优。

This is all quite advanced stuff - you definitely don't need to know anything about this to make good use of Java and/or the JVM. You should generally assume that the JVM does memory management on your behalf and will do so efficiently - it's had many years of tuning by experts.

JVM的重点是毕竟......允许你从具体平台的实现细节中抽象出来......

The whole point of the JVM is to allow you to abstract away from the implementation details of the specific platform, after all......

这篇关于JVM(HotSpot):所有方法都去哪儿了?方法区?本机方法堆栈?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆