虚拟机的作用,jdk在不同系统上是用不同的jdk的
jvm包括
栈(线程栈):一般用于放局部变量的地方,可以有多个“栈帧”,遵循栈的先进后出原则,跟数据结构的“栈”类似,数据结构“first in last out”。操作数栈:临时存储计算数据
堆(调优主要调堆):对用变量存放到堆中,比如对象,栈中是放某个地址或者说是指针
分代年龄15时候(存储在对象头),进入老年期。
jdk有个调试工具 jvisualvm ,可以查看调式看堆内存:dos下直接运行就行了,可以看到堆内存变化,执行如下代码可以观察:
如果启动多个main方法,则有多个可观察,难道说是虚拟机会运行多个?如图:
gc RootS 根:
方法区(元空间):存放常量,静态变量,类元信息()
本地方法栈:调用的c语言库函数的实现,比如Threat().start();方法,jdk中源码 (native修饰start0()方法):
public synchronized void start() {
/**
* This method is not invoked for the main method thread or "system"
* group threads created/set up by the VM. Any new functionality added
* to this method in the future may have to also be added to the VM.
*
* A zero status value corresponds to state "NEW".
*/
if (threadStatus != 0)
throw new IllegalThreadStateException();
/* Notify the group that this thread is about to be started
* so that it can be added to the group's list of threads
* and the group's unstarted count can be decremented. */
group.add(this);
boolean started = false;
try {
start0();
started = true;
} finally {
try {
if (!started) {
group.threadStartFailed(this);
}
} catch (Throwable ignore) {
/* do nothing. If start0 threw a Throwable then
it will be passed up the call stack */
}
}
}
private native void start0();
/**
* If this thread was constructed using a separate
* <code>Runnable</code> run object, then that
* <code>Runnable</code> object's <code>run</code> method is called;
* otherwise, this method does nothing and returns.
* <p>
* Subclasses of <code>Thread</code> should override this method.
*
* @see #start()
* @see #stop()
* @see #Thread(ThreadGroup, Runnable, String)
*/
现在已经很少用了,主要用于和c语言交互!(了解即可)
类装载子系统
执行引擎:
程序计数器:每个线程是都有程序计数器
javap 命令可以将class文件转化成txt,方便查看底层执行的命令
如图:
执行代码:
class Math{
public static final Interger CONSTANT =66;
public in compute(){
int a =1;
int b = 2;
int c = (a+b)*10;
return c;
}
public static void main(String[] args){
Math math = new Math();
math.compute();
Math math2 = new Math();
math2.compute();
}
}