【JVM】【01】内存模型

https://docs.oracle.com/javase/8/docs/index.html

1.jdk、jre、jvm的架构图

【JVM】【01】内存模型_第1张图片

2.jdk跨平台特性,不同系统使用不同版本的jdk包

一个class文件可以再不同的平台执行得到相同的结果

3.jvm由三部分组成

类加载系统
运行时数据区(内存模型)
字节码执行引擎

4.jvm的内存模型

https://docs.oracle.com/javase/specs/jvms/se8/html/index.html
https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-2.html#jvms-2.5

**堆、栈、方法区、程序计数器,本地方法栈、运行时常量池**

   **堆**
   Eden区、S0、S1、Old

​​ ​​
栈 stacks
https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-2.html#jvms-2.6
栈帧 :局部变量、操作数栈、动态链接、方法返回地址

  **方法区**
   类元信息、类变量、常量

  **gcroots**
   线程栈的栈帧中的局部变量中、类变量指向堆内存的对象、本地方法栈中指向堆的对象

5.jvm 堆、栈、方法区 参数设置

https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html

-Xmssize
Sets the initial size (in bytes) of the heap. This value must be a multiple of 1024 and greater than 1 MB. Append the letter k or K to indicate kilobytes, m or M to indicate megabytes, g or G to indicate gigabytes.
The following examples show how to set the size of allocated memory to 6 MB using various units:

-Xms6291456
-Xms6144k
-Xms6m
If you do not set this option, then the initial size will be set as the sum of the sizes allocated for the old generation and the young generation. The initial size of the heap for the young generation can be set using the -Xmn option or the -XX:NewSize option.-Xmxsize
Specifies the maximum size (in bytes) of the memory allocation pool in bytes. This value must be a multiple of 1024 and greater than 2 MB. Append the letter k or K to indicate kilobytes, m or M to indicate megabytes, g or G to indicate gigabytes. The default value is chosen at runtime based on system configuration. For server deployments, -Xms and -Xmx are often set to the same value. See the section "Ergonomics" in Java SE HotSpot Virtual Machine Garbage Collection Tuning Guide at [http://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/index.html](http://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/index.html).
The following examples show how to set the maximum allowed size of allocated memory to 80 MB using various units:

-Xmx83886080
-Xmx81920k
-Xmx80m
The -Xmx option is equivalent to -XX:MaxHeapSize.
-Xsssize

Sets the thread stack size (in bytes). Append the letter k or K to indicate KB, m or M to indicate MB, g or G to indicate GB. The default value depends on the platform:
	* 
Linux/ARM (32-bit): 320 KB
	* 
Linux/i386 (32-bit): 320 KB
	* 
Linux/x64 (64-bit): 1024 KB
	* 
OS X (64-bit): 1024 KB
	* 
Oracle Solaris/i386 (32-bit): 320 KB
	* 
Oracle Solaris/x64 (64-bit): 1024 KB


The following examples set the thread stack size to 1024 KB in different units:

-Xss1m
-Xss1024k
-Xss1048576
This option is equivalent to -XX:ThreadStackSize.
-XX:MetaspaceSize=size
Sets the size of the allocated class metadata space that will trigger a garbage collection the first time it is exceeded. This threshold for a garbage collection is increased or decreased depending on the amount of metadata used. The default size depends on the platform.

-XX:MaxMetaspaceSize=size
Sets the maximum amount of native memory that can be allocated for class metadata. By default, the size is not limited. The amount of metadata for an application depends on the application itself, other running applications, and the amount of memory available on the system.
The following example shows how to set the maximum class metadata size to 256 MB:
-XX:MaxMetaspaceSize=256m
-XX:MaxDirectMemorySize=size
Sets the maximum total size (in bytes) of the New I/O (the java.nio package) direct-buffer allocations. Append the letter k or K to indicate kilobytes, m or M to indicate megabytes, g or G to indicate gigabytes. By default, the size is set to 0, meaning that the JVM chooses the size for NIO direct-buffer allocations automatically.
The following examples illustrate how to set the NIO size to 1024 KB in different units:

-XX:MaxDirectMemorySize=1m
-XX:MaxDirectMemorySize=1024k
-XX:MaxDirectMemorySize=1048576

你可能感兴趣的:(jvm)