【这个是宋红康老师原版JVM视频:https://www.bilibili.com/video/BV1PJ411n7xZ?from=search&seid=4195758496847595856】
【来自B站宋红康老师的JVM视频:https://www.bilibili.com/video/BV1BJ41177cp?p=27】
JMM:java内存模型。
【宋红康老师的Process站点:https://www.processon.com/view/5df48fb2e4b06f5f145ab78a】
【工具下载站点:https://shimo.im/docs/yx8J3qywWWWKdgyH/】
【如下是阿里手册中的图】
【OracleJDK的官方文档:
java文档:https://docs.oracle.com/javase/specs/jls/se8/html/index.html、
JVM文档:https://docs.oracle.com/javase/specs/jvms/se8/html/index.html】
【java虚拟机规范:https://docs.oracle.com/javase/specs/jvms/se8/html/index.html】
【JVM参数:http://docs.oracle.com/javase】
注意:有些书籍中,把动态链接、方法返回地址、一些附加信息 统称为【桢数据区】。
package com.atguigu.java2;
/**
* 说明早期绑定和晚期绑定的例子
*/
class Animal{
public void eat(){
System.out.println("动物进食");
}
}
interface Huntable{
void hunt();
}
class Dog extends Animal implements Huntable{
@Override
public void eat() {
System.out.println("狗吃骨头");
}
@Override
public void hunt() {
System.out.println("捕食耗子,多管闲事");
}
}
class Cat extends Animal implements Huntable{
public Cat(){
super();//表现为:早期绑定
}
public Cat(String name){
this();//表现为:早期绑定
}
@Override
public void eat() {
super.eat();//表现为:早期绑定
System.out.println("猫吃鱼");
}
@Override
public void hunt() {
System.out.println("捕食耗子,天经地义");
}
}
public class AnimalTest {
public void showAnimal(Animal animal){
animal.eat();//表现为:晚期绑定
}
public void showHunt(Huntable h){
h.hunt();//表现为:晚期绑定
}
}
package com.atguigu.java2;
/**
* 解析调用中非虚方法、虚方法的测试
* invokestatic指令和invokespecial指令调用的方法称为非虚方法
*/
class Father {
public Father() {
System.out.println("father的构造器");
}
public static void showStatic(String str) {
System.out.println("father " + str);
}
public final void showFinal() {
System.out.println("father show final");
}
public void showCommon() {
System.out.println("father 普通方法");
}
}
public class Son extends Father {
public Son() {
//invokespecial
super();
}
public Son(int age) {
//invokespecial
this();
}
//不是重写的父类的静态方法,因为静态方法不能被重写!
public static void showStatic(String str) {
System.out.println("son " + str);
}
private void showPrivate(String str) {
System.out.println("son private" + str);
}
public void show() {
//invokestatic
showStatic("atguigu.com");
//invokestatic
super.showStatic("good!");
//invokespecial
showPrivate("hello!");
//invokespecial:编译期间确定下来了
super.showCommon();
//invokevirtual
showFinal();//因为此方法声明有final,不能被子类重写,所以也认为此方法是非虚方法。
//虚方法如下:
//invokevirtual:它可以被子类重写,编译期间确定不下来,需要在运行期间确定下来
showCommon();
info();
MethodInterface in = null;
//invokeinterface
in.methodA();
}
public void info(){ }
public void display(Father f){
f.showCommon();
}
public static void main(String[] args) {
Son so = new Son();
so.show();
}
}
interface MethodInterface{
void methodA();
}
【PC寄存器:存储的是“该方法要执行的下一条指令的地址”。】
【-Xss:https://www.cnblogs.com/leeego-123/p/11572786.html】
package com.atguigu.java3;
/**
* 面试题:
* 方法中定义的局部变量是否线程安全?具体情况具体分析
* 何为线程安全?
* 如果只有一个线程才可以操作此数据,则必是线程安全的。
* 如果有多个线程操作此数据,则此数据是共享数据。如果不考虑同步机制的话,会存在线程安全问题。
*/
public class StringBuilderTest {
int num = 10;
//s1的声明方式是线程安全的
public static void method1(){
//StringBuilder:线程不安全
StringBuilder s1 = new StringBuilder();
s1.append("a");
s1.append("b");
//...
}
//sBuilder的操作过程:是线程不安全的
public static void method2(StringBuilder sBuilder){
sBuilder.append("a");
sBuilder.append("b");
//...
}
//s1的操作:是线程不安全的
public static StringBuilder method3(){
StringBuilder s1 = new StringBuilder();
s1.append("a");
s1.append("b");
return s1;
}
//s1的操作:是线程安全的
public static String method4(){
StringBuilder s1 = new StringBuilder();
s1.append("a");
s1.append("b");
return s1.toString();
}
public static void main(String[] args) {
StringBuilder s = new StringBuilder();
new Thread(() -> {
s.append("a");
s.append("b");
}).start();
method2(s);
}
}
【1995年java诞生,1996年java语言的1.0版本发布】
【java虚拟机规范官网:https://docs.oracle.com/javase/specs/jvms/se8/html/index.html】