当前位置:网站首页>Describe your understanding of the evolution process and internal structure of the method area
Describe your understanding of the evolution process and internal structure of the method area
2022-06-25 15:50:00 【InfoQ】

brief introduction


Forever 、 Meta space
Direct memory
The size of the method area
jdk7 And before
-XX:PermSize=N // Method area ( Forever ) Initial allocation space , The default value is 20.75M
-XX:MaxPermSize=N // Method area ( Forever ) Maximum allocable space .32 Bit machine default is 64M,64 Bit machine default is 82M
jdk8 And later
-XX:MetaspaceSize=N // Method area ( Meta space ) Initial allocation space , If this flag is not specified , Then the meta space will be dynamically resized according to the application requirements of the runtime .
-XX:MaxMetaspaceSize=N // Method area ( Meta space ) Maximum allocable space , The default value is -1, There is no limit
- Forever :OutOfMemoryError:PermGen space
- Meta space :OutOfMemoryError:Metaspace
jvisualvm
public class MethodAreaDemo1 {
public static void main(String[] args) {
System.out.println("start...");
try {
Thread.sleep(1000000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("end...");
}
}

High water level
XX:MetaspaceSize=21- If you don't have enough free space , Then not more than MaxMetaspaceSize when , Increase the value properly ;
- If you release too much space , Then lower the value appropriately .
-XX :MetaspaceSizeinternal structure

Type information
- The full valid name of this type ( full name = Package name . Class name )
- The fully valid name of the direct parent of this type ( about interface or java. lang.Object , None of them has a parent )
- This type of modifier ( public , abstract, final Some subset of )
- This type of direct interface has a sequence table
Domain (Field) Information
- JVM All fields of type must be saved in the method area (field, Also known as attribute ) And the declaration order of the domain ;
- Domain related information includes : Domain name 、 Domain type 、 Domain modifier (public, private,protected, static, final, volatile, transient Some subset of )
Method (Method) Information
- Method name
- Return type of method ( or void)
- Number and type of method parameters ( According to the order )
- Method modifier (public, private, protected, static, final,synchronized, native , abstract A subset of )
- Bytecode of method (bytecodes)、 The stack of operands 、 Local variable table and size ( abstract and native Methods except )
- Anomaly table ( abstract and native Methods except ) Where each exception begins 、 End position 、 The code deals with the offset address in the program counter 、 Constant pool index of the caught exception class
non-final Class variables
- Static variables are associated with classes , Load as class loads , They become a logical part of class data
- Class variables are shared by all instances of the class , Even if there is no class instance, you can access it .
public class MethodAreaDemo2 {
public static void main(String[] args) {
Order order = null;
order.hello();
System.out.println(order.count);
}
}
class Order {
public static int count = 1;
public static final int number = 2;
public static void hello() {
System.out.println("hello!");
}
}
hello!
1
javap -v -p MethodAreaDemo2.class
Runtime constant pool
Constant pool table

Why do bytecode files need constant pools ?
Runtime constant pool
Runtime Constant PoolString.intern()Evolution details
- jdk1.6 And before : YesForever, Static variables are stored on permanent generations ;
- jdk1.7: YesForever, But gradually “ To the eternal generation ”, String constant pool 、 Static variable removal , Keep it in the pile ;
- jdk1.8 And after : There is no permanent generation , Type information 、 Field 、 Method 、 Constants are stored in local memoryMeta space, But string constant pool 、 Static variables are still in the heap ;
Evolution example diagram



Why replace permanent substitution with meta space ?
- The permanent substitute is JVM Of memory , suffer JVM Set the memory size limit ; Meta space uses local direct memory , Its maximum allocable space is the available memory space of the system . Because what is stored in the meta space is classMetadata, So as the memory space increases , There are more classes that can be loaded , The corresponding overflow probability will be greatly reduced .
- stay JDK8, Merge HotSpot and JRockit When the code ,JRockit There has never been a thing called the permanent generation , After the merger, there is no need to set up such a permanent place .
- Tuning permanent generations is difficult .
StringTable Why adjust
StringTableGarbage collection
- The amount of words is close to Java The concept of constant at the language level , Such as text string 、 Be declared final Constant value of .
- Symbolic references are concepts of compilation principles , Include fully qualified names of classes and interfaces 、 Name and descriptor of the field 、 The name and descriptor of the method .
Type determination
- All of theseexampleThey have been recycled , That is to say Java There are no instances of this class and any of its derived subclasses in the heap ;
- Load the classClass loaderHas been recovered , This condition is unless it is a well-designed alternative class loader scenario , Such as OSGi、JSP And so on , Otherwise, it's usually hard to achieve ;
- Corresponding to this class java.lang.Class The object is not referenced anywhere , The methods of the class cannot be accessed anywhere by reflection .
边栏推荐
猜你喜欢

免费送书啦!火遍全网的AI给老照片上色,这里有一份详细教程!

Programmer vs hacker thinking | daily anecdotes

不要再「外包」AI 模型了!最新研究发现:有些破坏机器学习模型安全的「后门」无法被检测到
After the project is pushed to the remote warehouse, Baota webhook automatically publishes it

TFIDF与BM25
Gold three silver four, an article to solve the resume and interview

中国高校首次!全球唯一!同济学子斩获国际大奖

Optimization of lazyagg query rewriting in parsing data warehouse

Generic - learning notes

异步处理容易出错的点
随机推荐
Write one file to the marked location of another file
Finally, we can figure out whether the binding event in the tag is bracketed or not
Joseph Ring - formula method (recursive formula)
揭秘GaussDB(for Redis):全面对比Codis
剑指 Offer 05. 替换空格
Optimization of lazyagg query rewriting in parsing data warehouse
B站付费视频使up主掉粉过万
Differences between = = and = = = in JS (detailed explanation)
Programmer vs hacker thinking | daily anecdotes
js 给元素添加自定义属性
李飞飞团队将ViT用在机器人身上,规划推理最高提速512倍,还cue了何恺明的MAE
Principle and implementation of MySQL master-slave replication (docker Implementation)
Binocular 3D perception (I): preliminary understanding of binocular
Summary of common methods of ArrayList, LinkedList and vector, and analysis of source code learning
Startup and shutdown of appium service
What is the safest app for stock account opening? Tell me what you know
Why is it said that restarting can solve 90% of the problems
Architecture evolution of high-performance servers -- Suggestions
镁光256Gb NAND Flash芯片介绍
Yadali brick playing game based on deep Q-learning