???????Java??????????????
???????????? ???????[ 2013/3/15 10:47:52 ] ????????
??????????????
????????happens- before????????????????????????????????????????happens- before?????
????1??A happens- before B??
????2??B happens- before C??
????3??A happens- before C??
??????????3??happens- before??????????happens- before?????????????????
????????A happens- before B???????????B?????????A????У???????????????????????????????????????A happens- before B??JMM???????A??????B????С?JMM???????????????????е??????????????????????????????????????????????????????????A????н????????????B??????????????????A?????B?????н?????????A?????B??happens- before?????е?????????????????£?JMM??????????????????????not illegal????JMM??????????????
???????????У?????????????????????????????????????????н????????£??????????????ж??????????????????????????happens- before?????????????????JMM????????????
???????????????????
????????????????????????????????????????????н??????????????????
class ReorderExample {
int a = 0;
boolean flag = false;
public void writer() {
a = 1; //1
flag = true; //2
}
Public void reader() {
if (flag) { //3
int i = a * a; //4
……
}
}
}
????flag??????????????????????a??????д??????????????????A??B??A???????writer()?????????B?????????reader()?????????B????в???4???????????A?????1????????a??д??
?????????????????????
???????????1?????2???????????????????????????????????????????????????????????3?????4?????????????????????????????????????????????????????????????????????????1?????2???????????????????Ч???????????????????????
??????????????????1?????2???????????????????????A????д??????flag????????B????????????????????ж???棬???B?????????a???????????a????????б????Aд???????????????????屻????????????
?????? ??????????ú?????????????????????????????????????????????????
???????????????????????????3?????4??????????????Ч?????????????????????????????????????????????????3?????4?????????????????????
??????????У?????3?????4???????????????????????д?????????????????????????????е???ж???????????????????????ò2?Speculation??????????????????????ж??????????????2???????????????B???????????????????????a*a?????????????????浽?????????????壨reorder buffer ROB????????????С?????????????3???????ж?????????ü?????д?????i?С?
??????????????????????2?????????????3??4??????????????????????????????????????壡
??????????????У????????????????????????????????н?????????as-if-serial??????????????????????????????????????????????????У?????????????????????????????????????н????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11