1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
|
diff --git a/src/share/vm/ci/ciObjectFactory.cpp b/src/share/vm/ci/ciObjectFactory.cpp
index d257e8a..6adcbbf 100644
--- a/src/share/vm/ci/ciObjectFactory.cpp
+++ b/src/share/vm/ci/ciObjectFactory.cpp
@@ -750,3 +750,27 @@
_unloaded_instances->length(),
_unloaded_klasses->length());
}
+
+int ciObjectFactory::compare_cimetadata(ciMetadata** a, ciMetadata** b) {
+ Metadata* am = (*a)->constant_encoding();
+ Metadata* bm = (*b)->constant_encoding();
+ return ((am > bm) ? 1 : ((am == bm) ? 0 : -1));
+}
+
+// (DCEVM) Resoring the ciObject arrays after class redefinition
+void ciObjectFactory::resort_shared_ci_metadata() {
+ if (_shared_ci_metadata == NULL) return;
+ _shared_ci_metadata->sort(ciObjectFactory::compare_cimetadata);
+
+#ifdef ASSERT
+ if (CIObjectFactoryVerify) {
+ Metadata* last = NULL;
+ for (int j = 0; j< _shared_ci_metadata->length(); j++) {
+ Metadata* o = _shared_ci_metadata->at(j)->constant_encoding();
+ assert(last < o, "out of order");
+ last = o;
+ }
+ }
+#endif // ASSERT
+}
+
diff --git a/src/share/vm/ci/ciObjectFactory.hpp b/src/share/vm/ci/ciObjectFactory.hpp
index c1baca0..dfe0adc 100644
--- a/src/share/vm/ci/ciObjectFactory.hpp
+++ b/src/share/vm/ci/ciObjectFactory.hpp
@@ -90,6 +90,7 @@
ciInstance* get_unloaded_instance(ciInstanceKlass* klass);
+ static int compare_cimetadata(ciMetadata** a, ciMetadata** b);
public:
static bool is_initialized() { return _initialized; }
@@ -145,6 +146,8 @@
void print_contents();
void print();
+
+ static void resort_shared_ci_metadata();
};
#endif // SHARE_VM_CI_CIOBJECTFACTORY_HPP
diff --git a/src/share/vm/classfile/classFileParser.cpp b/src/share/vm/classfile/classFileParser.cpp
index 3eee41d..70dac6d 100644
--- a/src/share/vm/classfile/classFileParser.cpp
+++ b/src/share/vm/classfile/classFileParser.cpp
@@ -759,6 +759,7 @@
Array<Klass*>* ClassFileParser::parse_interfaces(int length,
Handle protection_domain,
Symbol* class_name,
+ bool pick_newest,
bool* has_default_methods,
TRAPS) {
if (length == 0) {
@@ -777,7 +778,11 @@
"Interface name has bad constant pool index %u in class file %s",
interface_index, CHECK_NULL);
if (_cp->tag_at(interface_index).is_klass()) {
- interf = KlassHandle(THREAD, _cp->resolved_klass_at(interface_index));
+ Klass* resolved_klass = _cp->resolved_klass_at(interface_index);
+ if (pick_newest) {
+ resolved_klass = resolved_klass->newest_version();
+ }
+ interf = KlassHandle(THREAD, resolved_klass);
} else {
Symbol* unresolved_klass = _cp->klass_name_at(interface_index);
@@ -791,6 +796,9 @@
Klass* k = SystemDictionary::resolve_super_or_fail(class_name,
unresolved_klass, class_loader, protection_domain,
false, CHECK_NULL);
+ if (pick_newest) {
+ k = k->newest_version();
+ }
interf = KlassHandle(THREAD, k);
}
@@ -3093,6 +3101,7 @@
}
instanceKlassHandle ClassFileParser::parse_super_class(int super_class_index,
+ bool pick_newest,
TRAPS) {
instanceKlassHandle super_klass;
if (super_class_index == 0) {
@@ -3109,7 +3118,11 @@
// However, make sure it is not an array type.
bool is_array = false;
if (_cp->tag_at(super_class_index).is_klass()) {
- super_klass = instanceKlassHandle(THREAD, _cp->resolved_klass_at(super_class_index));
+ Klass* resolved_klass = _cp->resolved_klass_at(super_class_index);
+ if (pick_newest) {
+ resolved_klass = resolved_klass->newest_version();
+ }
+ super_klass = instanceKlassHandle(THREAD, resolved_klass);
if (_need_verify)
is_array = super_klass->oop_is_array();
} else if (_need_verify) {
@@ -3658,8 +3671,10 @@
instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name,
ClassLoaderData* loader_data,
Handle protection_domain,
+ KlassHandle old_klass,
KlassHandle host_klass,
GrowableArray<Handle>* cp_patches,
+ GrowableArray<Symbol*>* parsed_super_symbols,
TempNewSymbol& parsed_name,
bool verify,
TRAPS) {
@@ -3672,6 +3687,7 @@
JvmtiCachedClassFileData *cached_class_file = NULL;
Handle class_loader(THREAD, loader_data->class_loader());
bool has_default_methods = false;
+ bool pick_newest = !old_klass.is_null();
ResourceMark rm(THREAD);
ClassFileStream* cfs = stream();
@@ -3688,7 +3704,7 @@
init_parsed_class_attributes(loader_data);
- if (JvmtiExport::should_post_class_file_load_hook()) {
+ if (parsed_super_symbols == NULL && JvmtiExport::should_post_class_file_load_hook()) {
// Get the cached class file bytes (if any) from the class that
// is being redefined or retransformed. We use jvmti_thread_state()
// instead of JvmtiThreadState::state_for(jt) so we don't allocate
@@ -3829,6 +3845,26 @@
CHECK_(nullHandle));
}
+ // (DCEVM) Do not parse full class file, only get super symbols and return.
+ if (parsed_super_symbols != NULL) {
+ u2 super_class_index = cfs->get_u2_fast();
+
+ if (super_class_index != 0) {
+ parsed_super_symbols->append(cp->klass_name_at(super_class_index));
+ }
+
+ // Interfaces
+ u2 itfs_len = cfs->get_u2_fast();
+ Array<Klass*>* local_interfaces =
+ parse_interfaces(itfs_len, protection_domain, _class_name, pick_newest, &has_default_methods, CHECK_NULL);
+
+ for (int i = 0; i < local_interfaces->length(); i++) {
+ Klass* o = local_interfaces->at(i);
+ parsed_super_symbols->append(o->name());
+ }
+ return NULL;
+ }
+
Klass* preserve_this_klass; // for storing result across HandleMark
// release all handles when parsing is done
@@ -3855,13 +3891,14 @@
u2 super_class_index = cfs->get_u2_fast();
instanceKlassHandle super_klass = parse_super_class(super_class_index,
+ pick_newest,
CHECK_NULL);
// Interfaces
u2 itfs_len = cfs->get_u2_fast();
Array<Klass*>* local_interfaces =
parse_interfaces(itfs_len, protection_domain, _class_name,
- &has_default_methods, CHECK_(nullHandle));
+ pick_newest, &has_default_methods, CHECK_(nullHandle));
u2 java_fields_count = 0;
// Fields (offsets are filled in later)
@@ -3903,6 +3940,9 @@
true,
CHECK_(nullHandle));
+ if (pick_newest) {
+ k = k->newest_version();
+ }
KlassHandle kh (THREAD, k);
super_klass = instanceKlassHandle(THREAD, kh());
}
@@ -4067,7 +4107,7 @@
fill_oop_maps(this_klass, info.nonstatic_oop_map_count, info.nonstatic_oop_offsets, info.nonstatic_oop_counts);
// Fill in has_finalizer, has_vanilla_constructor, and layout_helper
- set_precomputed_flags(this_klass);
+ set_precomputed_flags(this_klass, old_klass);
// reinitialize modifiers, using the InnerClasses attribute
int computed_modifiers = this_klass->compute_modifier_flags(CHECK_(nullHandle));
@@ -4298,7 +4338,7 @@
}
-void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
+void ClassFileParser::set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass) {
Klass* super = k->super();
// Check if this klass has an empty finalize method (i.e. one with return bytecode only),
@@ -4306,7 +4346,9 @@
if (!_has_empty_finalizer) {
if (_has_finalizer ||
(super != NULL && super->has_finalizer())) {
- k->set_has_finalizer();
+ if (old_klass.is_null() || old_klass->has_finalizer()) {
+ k->set_has_finalizer();
+ }
}
}
@@ -4322,7 +4364,7 @@
// Check if this klass supports the java.lang.Cloneable interface
if (SystemDictionary::Cloneable_klass_loaded()) {
- if (k->is_subtype_of(SystemDictionary::Cloneable_klass())) {
+ if (k->is_subtype_of(SystemDictionary::Cloneable_klass()) || k->is_subtype_of(SystemDictionary::Cloneable_klass()->newest_version())) {
k->set_is_cloneable();
}
}
diff --git a/src/share/vm/classfile/classFileParser.hpp b/src/share/vm/classfile/classFileParser.hpp
index 8421bb5..7516110 100644
--- a/src/share/vm/classfile/classFileParser.hpp
+++ b/src/share/vm/classfile/classFileParser.hpp
@@ -214,11 +214,12 @@
Array<Klass*>* parse_interfaces(int length,
Handle protection_domain,
Symbol* class_name,
+ bool pick_newest,
bool* has_default_methods,
TRAPS);
void record_defined_class_dependencies(instanceKlassHandle defined_klass, TRAPS);
- instanceKlassHandle parse_super_class(int super_class_index, TRAPS);
+ instanceKlassHandle parse_super_class(int super_class_index, bool pick_newest, TRAPS);
// Field parsing
void parse_field_attributes(u2 attributes_count,
bool is_static, u2 signature_index,
@@ -299,7 +300,7 @@
unsigned int nonstatic_oop_map_count,
int* nonstatic_oop_offsets,
unsigned int* nonstatic_oop_counts);
- void set_precomputed_flags(instanceKlassHandle k);
+ void set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass);
Array<Klass*>* compute_transitive_interfaces(instanceKlassHandle super,
Array<Klass*>* local_ifs, TRAPS);
@@ -464,17 +465,20 @@
instanceKlassHandle parseClassFile(Symbol* name,
ClassLoaderData* loader_data,
Handle protection_domain,
+ KlassHandle old_klass,
TempNewSymbol& parsed_name,
bool verify,
TRAPS) {
KlassHandle no_host_klass;
- return parseClassFile(name, loader_data, protection_domain, no_host_klass, NULL, parsed_name, verify, THREAD);
+ return parseClassFile(name, loader_data, protection_domain, old_klass, no_host_klass, NULL, NULL, parsed_name, verify, THREAD);
}
instanceKlassHandle parseClassFile(Symbol* name,
ClassLoaderData* loader_data,
Handle protection_domain,
+ KlassHandle old_klass,
KlassHandle host_klass,
GrowableArray<Handle>* cp_patches,
+ GrowableArray<Symbol*>* parsed_super_symbols,
TempNewSymbol& parsed_name,
bool verify,
TRAPS);
diff --git a/src/share/vm/classfile/classLoader.cpp b/src/share/vm/classfile/classLoader.cpp
index 8366c8f..1e07485 100644
--- a/src/share/vm/classfile/classLoader.cpp
+++ b/src/share/vm/classfile/classLoader.cpp
@@ -929,6 +929,7 @@
instanceKlassHandle result = parser.parseClassFile(h_name,
loader_data,
protection_domain,
+ KlassHandle(),
parsed_name,
false,
CHECK_(h));
diff --git a/src/share/vm/classfile/dictionary.cpp b/src/share/vm/classfile/dictionary.cpp
index b7b4f35..b2b1d73 100644
--- a/src/share/vm/classfile/dictionary.cpp
+++ b/src/share/vm/classfile/dictionary.cpp
@@ -146,7 +146,7 @@
InstanceKlass* ik = InstanceKlass::cast(e);
// Non-unloadable classes were handled in always_strong_oops_do
- if (!is_strongly_reachable(loader_data, e)) {
+ if (!ik->is_redefining() && !is_strongly_reachable(loader_data, e)) {
// Entry was not visited in phase1 (negated test from phase1)
assert(!loader_data->is_the_null_class_loader_data(), "unloading entry with null class loader");
ClassLoaderData* k_def_class_loader_data = ik->class_loader_data();
@@ -337,6 +337,32 @@
add_entry(index, entry);
}
+// (DCEVM) Updates the klass entry to point to the new Klass*. Necessary only for class redefinition.
+bool Dictionary::update_klass(int index, unsigned int hash, Symbol* name, ClassLoaderData* loader_data, KlassHandle k, KlassHandle old_class) {
+
+ // There are several entries for the same class in the dictionary: One extra entry for each parent classloader of the classloader of the class.
+ bool found = false;
+ for (int index = 0; index < table_size(); index++) {
+ for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
+ if (entry->klass() == old_class()) {
+ entry->set_literal(k());
+ found = true;
+ }
+ }
+ }
+ return found;
+}
+
+// (DCEVM) Undo previous updates to the system dictionary
+void Dictionary::rollback_redefinition() {
+ for (int index = 0; index < table_size(); index++) {
+ for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
+ if (entry->klass()->is_redefining()) {
+ entry->set_literal(entry->klass()->old_version());
+ }
+ }
+ }
+}
// This routine does not lock the system dictionary.
//
@@ -367,7 +393,7 @@
ClassLoaderData* loader_data, Handle protection_domain, TRAPS) {
DictionaryEntry* entry = get_entry(index, hash, name, loader_data);
if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) {
- return entry->klass();
+ return intercept_for_version(entry->klass());
} else {
return NULL;
}
@@ -380,7 +406,7 @@
assert (index == index_for(name, loader_data), "incorrect index?");
DictionaryEntry* entry = get_entry(index, hash, name, loader_data);
- return (entry != NULL) ? entry->klass() : (Klass*)NULL;
+ return intercept_for_version((entry != NULL) ? entry->klass() : (Klass*)NULL);
}
@@ -392,7 +418,7 @@
assert (index == index_for(name, NULL), "incorrect index?");
DictionaryEntry* entry = get_entry(index, hash, name, NULL);
- return (entry != NULL) ? entry->klass() : (Klass*)NULL;
+ return intercept_for_version((entry != NULL) ? entry->klass() : (Klass*)NULL);
}
diff --git a/src/share/vm/classfile/dictionary.hpp b/src/share/vm/classfile/dictionary.hpp
index bc25c81..15eb762 100644
--- a/src/share/vm/classfile/dictionary.hpp
+++ b/src/share/vm/classfile/dictionary.hpp
@@ -78,6 +78,10 @@
void add_klass(Symbol* class_name, ClassLoaderData* loader_data,KlassHandle obj);
+ bool update_klass(int index, unsigned int hash, Symbol* name, ClassLoaderData* loader_data, KlassHandle k, KlassHandle old_class);
+
+ void rollback_redefinition();
+
Klass* find_class(int index, unsigned int hash,
Symbol* name, ClassLoaderData* loader_data);
@@ -107,6 +111,11 @@
return (loader_data->is_the_null_class_loader_data() || !ClassUnloading);
}
+ // (DCEVM) During enhanced class redefinition we want old version if new is being redefined
+ static Klass* intercept_for_version(Klass* k) {
+ return (k != NULL && k->is_redefining()) ? k->old_version() : k;
+ }
+
// Unload (that is, break root links to) all unmarked classes and
// loaders. Returns "true" iff something was unloaded.
bool do_unloading();
diff --git a/src/share/vm/classfile/javaClasses.cpp b/src/share/vm/classfile/javaClasses.cpp
index 34cb2c3..efe4c4a 100644
--- a/src/share/vm/classfile/javaClasses.cpp
+++ b/src/share/vm/classfile/javaClasses.cpp
@@ -1656,6 +1656,8 @@
skip_throwableInit_check = true;
}
}
+ // (DCEVM): Line numbers from newest version must be used for EMCP-swapped methods
+ method = method->newest_version();
if (method->is_hidden()) {
if (skip_hidden) continue;
}
diff --git a/src/share/vm/classfile/loaderConstraints.cpp b/src/share/vm/classfile/loaderConstraints.cpp
index 8d59c00..5651e6d 100644
--- a/src/share/vm/classfile/loaderConstraints.cpp
+++ b/src/share/vm/classfile/loaderConstraints.cpp
@@ -446,7 +446,7 @@
if (k != NULL) {
// We found the class in the system dictionary, so we should
// make sure that the Klass* matches what we already have.
- guarantee(k == probe->klass(), "klass should be in dictionary");
+ guarantee(k == probe->klass()->newest_version(), "klass should be in dictionary");
} else {
// If we don't find the class in the system dictionary, it
// has to be in the placeholders table.
diff --git a/src/share/vm/classfile/systemDictionary.cpp b/src/share/vm/classfile/systemDictionary.cpp
index 3b0cf3c..56c1085 100644
--- a/src/share/vm/classfile/systemDictionary.cpp
+++ b/src/share/vm/classfile/systemDictionary.cpp
@@ -174,6 +174,7 @@
// can return a null klass
klass = handle_resolution_exception(class_name, class_loader, protection_domain, throw_error, k_h, THREAD);
}
+ assert(klass == NULL || klass->is_newest_version() || klass->newest_version()->is_redefining(), "must be");
return klass;
}
@@ -216,7 +217,7 @@
// Forwards to resolve_instance_class_or_null
Klass* SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
- assert(!THREAD->is_Compiler_thread(),
+ assert(!THREAD->is_Compiler_thread() || JvmtiThreadState::state_for(JavaThread::current())->get_class_being_redefined() != NULL,
err_msg("can not load classes with compiler thread: class=%s, classloader=%s",
class_name->as_C_string(),
class_loader.is_null() ? "null" : class_loader->klass()->name()->as_C_string()));
@@ -988,8 +989,10 @@
instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
loader_data,
protection_domain,
+ KlassHandle(),
host_klass,
cp_patches,
+ NULL,
parsed_name,
true,
THREAD);
@@ -1043,6 +1046,7 @@
Handle protection_domain,
ClassFileStream* st,
bool verify,
+ KlassHandle old_class,
TRAPS) {
// Classloaders that support parallelism, e.g. bootstrap classloader,
@@ -1070,9 +1074,15 @@
instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
loader_data,
protection_domain,
+ old_class,
parsed_name,
verify,
THREAD);
+ // (DCEVM) During enhanced class redefinition, mark loaded class as being redefined
+ if (!old_class.is_null() && !k.is_null()) {
+ k->set_redefining(true);
+ k->set_old_version(old_class());
+ }
const char* pkg = "java/";
if (!HAS_PENDING_EXCEPTION &&
@@ -1107,10 +1117,11 @@
// Add class just loaded
// If a class loader supports parallel classloading handle parallel define requests
// find_or_define_instance_class may return a different InstanceKlass
- if (is_parallelCapable(class_loader)) {
+ // (DCEVM) TODO: for class redefinition the parallel version does not work, check if this is a problem?
+ if (is_parallelCapable(class_loader) && old_class.is_null()) {
k = find_or_define_instance_class(class_name, class_loader, k, THREAD);
} else {
- define_instance_class(k, THREAD);
+ define_instance_class(k, old_class, THREAD);
}
}
@@ -1124,7 +1135,7 @@
MutexLocker mu(SystemDictionary_lock, THREAD);
Klass* check = find_class(parsed_name, loader_data);
- assert(check == k(), "should be present in the dictionary");
+ assert((check == k() && !k->is_redefining()) || (k->is_redefining() && check == k->old_version()), "should be present in the dictionary");
Klass* check2 = find_class(h_name, defining_loader_data);
assert(check == check2, "name inconsistancy in SystemDictionary");
@@ -1331,7 +1342,11 @@
}
}
-void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
+void SystemDictionary::rollback_redefinition() {
+ dictionary()->rollback_redefinition();
+}
+
+void SystemDictionary::define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS) {
ClassLoaderData* loader_data = k->class_loader_data();
Handle class_loader_h(THREAD, loader_data->class_loader());
@@ -1361,7 +1376,17 @@
Symbol* name_h = k->name();
unsigned int d_hash = dictionary()->compute_hash(name_h, loader_data);
int d_index = dictionary()->hash_to_index(d_hash);
- check_constraints(d_index, d_hash, k, class_loader_h, true, CHECK);
+
+ // (DCEVM) Update version of the Klass* in the system dictionary
+ // TODO: Check for thread safety!
+ if (!old_class.is_null()) {
+ bool ok = dictionary()->update_klass(d_index, d_hash, name_h, loader_data, k, old_class);
+ assert (ok, "must have found old class and updated!");
+ }
+ check_constraints(d_index, d_hash, k, class_loader_h, old_class.is_null(), CHECK);
+
+ // FIXME: (DCEVM) clean this...
+ if(!old_class.is_null() && TraceRedefineClasses >= 3){ tty->print_cr("Class has been updated!"); }
// Register class just loaded with class loader (placed in Vector)
// Note we do this before updating the dictionary, as this can
@@ -1394,8 +1419,9 @@
}
k->eager_initialize(THREAD);
+ // (DCEVM) Only notify jvmti if not redefining a class.
// notify jvmti
- if (JvmtiExport::should_post_class_load()) {
+ if (JvmtiExport::should_post_class_load() && old_class.is_null()) {
assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
JvmtiExport::post_class_load((JavaThread *) THREAD, k());
@@ -1469,7 +1495,7 @@
}
}
- define_instance_class(k, THREAD);
+ define_instance_class(k, KlassHandle(), THREAD);
Handle linkage_exception = Handle(); // null handle
@@ -1599,6 +1625,14 @@
Universe::flush_dependents_on(k);
}
+// (DCEVM) Remove from hierarchy - Undo add_to_hierarchy.
+void SystemDictionary::remove_from_hierarchy(instanceKlassHandle k) {
+ assert(k.not_null(), "just checking");
+
+ // remove receiver from sibling list
+ k->remove_from_sibling_list();
+ // TODO (DCEVM): Remove from interfaces.
+}
// ----------------------------------------------------------------------------
// GC support
@@ -1945,7 +1979,7 @@
// also holds array classes
assert(check->oop_is_instance(), "noninstance in systemdictionary");
- if ((defining == true) || (k() != check)) {
+ if ((defining == true) && ((k() != check) && k->old_version() != check)) {
linkage_error = "loader (instance of %s): attempted duplicate class "
"definition for name: \"%s\"";
} else {
diff --git a/src/share/vm/classfile/systemDictionary.hpp b/src/share/vm/classfile/systemDictionary.hpp
index 1e4e819..e1b0608 100644
--- a/src/share/vm/classfile/systemDictionary.hpp
+++ b/src/share/vm/classfile/systemDictionary.hpp
@@ -271,7 +271,7 @@
// Resolve from stream (called by jni_DefineClass and JVM_DefineClass)
static Klass* resolve_from_stream(Symbol* class_name, Handle class_loader,
Handle protection_domain,
- ClassFileStream* st, bool verify, TRAPS);
+ ClassFileStream* st, bool verify, KlassHandle old_class, TRAPS);
// Lookup an already loaded class. If not found NULL is returned.
static Klass* find(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
@@ -341,6 +341,8 @@
// System loader lock
static oop system_loader_lock() { return _system_loader_lock_obj; }
+ // (DCEVM) Remove link to hierarchy
+ static void remove_from_hierarchy(instanceKlassHandle k);
private:
// Extended Redefine classes support (tbi)
static void preloaded_classes_do(KlassClosure* f);
@@ -405,6 +407,9 @@
int limit = (int)end_id + 1;
initialize_wk_klasses_until((WKID) limit, start_id, THREAD);
}
+
+ // (DCEVM) rollback class redefinition
+ static void rollback_redefinition();
public:
#define WK_KLASS_DECLARE(name, symbol, option) \
@@ -611,7 +616,7 @@
// after waiting, but before reentering SystemDictionary_lock
// to preserve lock order semantics.
static void double_lock_wait(Handle lockObject, TRAPS);
- static void define_instance_class(instanceKlassHandle k, TRAPS);
+ static void define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS);
static instanceKlassHandle find_or_define_instance_class(Symbol* class_name,
Handle class_loader,
instanceKlassHandle k, TRAPS);
diff --git a/src/share/vm/classfile/verifier.cpp b/src/share/vm/classfile/verifier.cpp
index 6ddf936..a5ae054 100644
--- a/src/share/vm/classfile/verifier.cpp
+++ b/src/share/vm/classfile/verifier.cpp
@@ -189,7 +189,7 @@
Symbol* name = klass->name();
Klass* refl_magic_klass = SystemDictionary::reflect_MagicAccessorImpl_klass();
- bool is_reflect = refl_magic_klass != NULL && klass->is_subtype_of(refl_magic_klass);
+ bool is_reflect = refl_magic_klass != NULL && (klass->is_subtype_of(refl_magic_klass) || klass->is_subtype_of(refl_magic_klass->newest_version()));
return (should_verify_for(klass->class_loader(), should_verify_class) &&
// return if the class is a bootstrapping class
@@ -518,7 +518,7 @@
ClassVerifier::ClassVerifier(
instanceKlassHandle klass, TRAPS)
- : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass) {
+ : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass->newest_version()), _klass_to_verify(klass) {
_this_type = VerificationType::reference_type(klass->name());
// Create list to hold symbols in reference area.
_symbols = new GrowableArray<Symbol*>(100, 0, NULL);
@@ -548,7 +548,7 @@
_klass->external_name());
}
- Array<Method*>* methods = _klass->methods();
+ Array<Method*>* methods = _klass_to_verify->methods();
int num_methods = methods->length();
for (int index = 0; index < num_methods; index++) {
diff --git a/src/share/vm/classfile/verifier.hpp b/src/share/vm/classfile/verifier.hpp
index 557f567..1fb473a 100644
--- a/src/share/vm/classfile/verifier.hpp
+++ b/src/share/vm/classfile/verifier.hpp
@@ -331,6 +331,7 @@
VerificationType object_type() const;
+ instanceKlassHandle _klass_to_verify;
instanceKlassHandle _klass; // the class being verified
methodHandle _method; // current method being verified
VerificationType _this_type; // the verification type of the current class
diff --git a/src/share/vm/interpreter/linkResolver.cpp b/src/share/vm/interpreter/linkResolver.cpp
index ef7e428..898427b 100644
--- a/src/share/vm/interpreter/linkResolver.cpp
+++ b/src/share/vm/interpreter/linkResolver.cpp
@@ -215,8 +215,8 @@
// Klass resolution
void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) {
- if (!Reflection::verify_class_access(ref_klass(),
- sel_klass(),
+ if (!Reflection::verify_class_access(ref_klass()->newest_version(),
+ sel_klass()->newest_version(),
true)) {
ResourceMark rm(THREAD);
Exceptions::fthrow(
@@ -451,7 +451,7 @@
// We'll check for the method name first, as that's most likely
// to be false (so we'll short-circuit out of these tests).
if (sel_method->name() == vmSymbols::clone_name() &&
- sel_klass() == SystemDictionary::Object_klass() &&
+ sel_klass()->newest_version() == SystemDictionary::Object_klass()->newest_version() &&
resolved_klass->oop_is_array()) {
// We need to change "protected" to "public".
assert(flags.is_protected(), "clone not protected?");
@@ -799,7 +799,7 @@
}
// Final fields can only be accessed from its own class.
- if (is_put && fd.access_flags().is_final() && sel_klass() != current_klass()) {
+ if (is_put && fd.access_flags().is_final() && sel_klass() != current_klass() && sel_klass() != current_klass()->active_version()) {
THROW(vmSymbols::java_lang_IllegalAccessError());
}
@@ -1196,6 +1196,8 @@
// recv_klass might be an arrayKlassOop but all vtables start at
// the same place. The cast is to avoid virtual call and assertion.
InstanceKlass* inst = (InstanceKlass*)recv_klass();
+ // (DCEVM) Check that the receiver is a subtype of the holder of the resolved method.
+ assert(inst->is_subtype_of(resolved_method->method_holder()), "receiver and resolved method holder are inconsistent");
selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
}
}
diff --git a/src/share/vm/memory/universe.cpp b/src/share/vm/memory/universe.cpp
index b13e4f3..279e1d3 100644
--- a/src/share/vm/memory/universe.cpp
+++ b/src/share/vm/memory/universe.cpp
@@ -161,6 +161,42 @@
f(doubleArrayKlassObj());
}
+// (DCEVM) This method should iterate all pointers that are not within heap objects.
+void Universe::root_oops_do(OopClosure *oopClosure) {
+
+ class AlwaysTrueClosure: public BoolObjectClosure {
+ public:
+ void do_object(oop p) { ShouldNotReachHere(); }
+ bool do_object_b(oop p) { return true; }
+ };
+ AlwaysTrueClosure always_true;
+
+ Universe::oops_do(oopClosure);
+// ReferenceProcessor::oops_do(oopClosure); (tw) check why no longer there
+ JNIHandles::oops_do(oopClosure); // Global (strong) JNI handles
+ Threads::oops_do(oopClosure, NULL, NULL);
+ ObjectSynchronizer::oops_do(oopClosure);
+ FlatProfiler::oops_do(oopClosure);
+ JvmtiExport::oops_do(oopClosure);
+
+ // Now adjust pointers in remaining weak roots. (All of which should
+ // have been cleared if they pointed to non-surviving objects.)
+ // Global (weak) JNI handles
+ JNIHandles::weak_oops_do(&always_true, oopClosure);
+
+ CodeCache::oops_do(oopClosure);
+ StringTable::oops_do(oopClosure);
+
+ // (DCEVM) TODO: Check if this is correct?
+ //CodeCache::scavenge_root_nmethods_oops_do(oopClosure);
+ //Management::oops_do(oopClosure);
+ //ref_processor()->weak_oops_do(&oopClosure);
+ //PSScavenge::reference_processor()->weak_oops_do(&oopClosure);
+
+ // SO_AllClasses
+ SystemDictionary::oops_do(oopClosure);
+}
+
void Universe::oops_do(OopClosure* f, bool do_all) {
f->do_oop((oop*) &_int_mirror);
diff --git a/src/share/vm/memory/universe.hpp b/src/share/vm/memory/universe.hpp
index d80a263..bf75fe0 100644
--- a/src/share/vm/memory/universe.hpp
+++ b/src/share/vm/memory/universe.hpp
@@ -407,6 +407,7 @@
static void run_finalizers_on_exit();
// Iteration
+ static void root_oops_do(OopClosure *f);
// Apply "f" to the addresses of all the direct heap pointers maintained
// as static fields of "Universe".
diff --git a/src/share/vm/oops/cpCache.cpp b/src/share/vm/oops/cpCache.cpp
index 482c3ff..d644aac 100644
--- a/src/share/vm/oops/cpCache.cpp
+++ b/src/share/vm/oops/cpCache.cpp
@@ -337,7 +337,8 @@
if (has_appendix) {
const int appendix_index = f2_as_index() + _indy_resolved_references_appendix_offset;
assert(appendix_index >= 0 && appendix_index < resolved_references->length(), "oob");
- assert(resolved_references->obj_at(appendix_index) == NULL, "init just once");
+ // FIXME (DCEVM) relaxing for now...
+ //assert(resolved_references->obj_at(appendix_index) == NULL, "init just once");
resolved_references->obj_at_put(appendix_index, appendix());
}
@@ -345,7 +346,8 @@
if (has_method_type) {
const int method_type_index = f2_as_index() + _indy_resolved_references_method_type_offset;
assert(method_type_index >= 0 && method_type_index < resolved_references->length(), "oob");
- assert(resolved_references->obj_at(method_type_index) == NULL, "init just once");
+ // FIXME (DCEVM) relaxing for now...
+ //assert(resolved_references->obj_at(method_type_index) == NULL, "init just once");
resolved_references->obj_at_put(method_type_index, method_type());
}
@@ -533,6 +535,27 @@
// the method is in the interesting class so the entry is interesting
return true;
}
+
+// Enhanced RedefineClasses() API support (DCEVM):
+// Clear cached entry, let it be re-resolved
+void ConstantPoolCacheEntry::clear_entry() {
+ if (_indices == constant_pool_index() ||
+ bytecode_1() == Bytecodes::_invokehandle ||
+ bytecode_1() == Bytecodes::_invokedynamic) {
+ // Entry wasn't initialized yet or was initialized for invokehandle/invokedynamic.
+ // Don't clear it since f2 will not be reset during entry re-resolution.
+ return;
+ }
+ _indices = constant_pool_index();
+ _f1 = NULL;
+ _f2 = 0;
+
+ // FIXME: (DCEVM) we want to clear flags, but parameter size is actually used
+ // after we return from the method, before entry is re-initialized. So let's
+ // keep parameter size the same.
+ // For example, it's used in TemplateInterpreterGenerator::generate_return_entry_for
+ _flags &= 0x0000000f;
+}
#endif // INCLUDE_JVMTI
void ConstantPoolCacheEntry::print(outputStream* st, int index) const {
@@ -661,6 +684,14 @@
}
}
}
+
+// Enhanced RedefineClasses() API support (DCEVM):
+// Clear all entries
+void ConstantPoolCache::clear_entries() {
+ for (int i = 0; i < length(); i++) {
+ entry_at(i)->clear_entry();
+ }
+}
#endif // INCLUDE_JVMTI
diff --git a/src/share/vm/oops/cpCache.hpp b/src/share/vm/oops/cpCache.hpp
index dda5e89..3f84087 100644
--- a/src/share/vm/oops/cpCache.hpp
+++ b/src/share/vm/oops/cpCache.hpp
@@ -380,6 +380,10 @@
bool * trace_name_printed);
bool check_no_old_or_obsolete_entries();
bool is_interesting_method_entry(Klass* k);
+
+ // Enhanced RedefineClasses() API support (DCEVM):
+ // Clear cached entry, let it be re-resolved
+ void clear_entry();
#endif // INCLUDE_JVMTI
// Debugging & Printing
@@ -479,6 +483,10 @@
int methods_length, bool * trace_name_printed);
bool check_no_old_or_obsolete_entries();
void dump_cache();
+
+ // Enhanced RedefineClasses() API support (DCEVM):
+ // Clear all entries
+ void clear_entries();
#endif // INCLUDE_JVMTI
// Deallocate - no fields to deallocate
diff --git a/src/share/vm/oops/instanceKlass.cpp b/src/share/vm/oops/instanceKlass.cpp
index db0e0a5..abd79ce 100644
--- a/src/share/vm/oops/instanceKlass.cpp
+++ b/src/share/vm/oops/instanceKlass.cpp
@@ -720,7 +720,8 @@
}
#endif
this_oop->set_init_state(linked);
- if (JvmtiExport::should_post_class_prepare()) {
+ // (DCEVM) Must check for old version in order to prevent infinite loops.
+ if (JvmtiExport::should_post_class_prepare() && this_oop->old_version() == NULL /* JVMTI deadlock otherwise */) {
Thread *thread = THREAD;
assert(thread->is_Java_thread(), "thread->is_Java_thread()");
JvmtiExport::post_class_prepare((JavaThread *) thread, this_oop());
@@ -797,7 +798,9 @@
// If we were to use wait() instead of waitInterruptibly() then
// we might end up throwing IE from link/symbol resolution sites
// that aren't expected to throw. This would wreak havoc. See 6320309.
- while(this_oop->is_being_initialized() && !this_oop->is_reentrant_initialization(self)) {
+ // (DCEVM) Wait also for the old class version to be fully initialized.
+ while((this_oop->is_being_initialized() && !this_oop->is_reentrant_initialization(self))
+ || (this_oop->old_version() != NULL && InstanceKlass::cast(this_oop->old_version())->is_being_initialized())) {
wait = true;
ol.waitUninterruptibly(CHECK);
}
@@ -1047,6 +1050,18 @@
assert(k->is_interface(), "should be an interface class");
for (int i = 0; i < transitive_interfaces()->length(); i++) {
if (transitive_interfaces()->at(i) == k) {
+ return true;
+ }
+ }
+ return false;
+}
+
+bool InstanceKlass::implements_interface_any_version(Klass* k) const {
+ k = k->newest_version();
+ if (this->newest_version() == k) return true;
+ assert(k->is_interface(), "should be an interface class");
+ for (int i = 0; i < transitive_interfaces()->length(); i++) {
+ if (transitive_interfaces()->at(i)->newest_version() == k) {
return true;
}
}
@@ -1320,6 +1335,18 @@
}
}
+void InstanceKlass::store_update_information(GrowableArray<int> &values) {
+ int *arr = NEW_C_HEAP_ARRAY(int, values.length(), mtClass);
+ for (int i=0; i<values.length(); i++) {
+ arr[i] = values.at(i);
+ }
+ set_update_information(arr);
+}
+
+void InstanceKlass::clear_update_information() {
+ FREE_C_HEAP_ARRAY(int, update_information(), mtClass);
+ set_update_information(NULL);
+}
void InstanceKlass::do_local_static_fields(FieldClosure* cl) {
for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
@@ -1817,6 +1844,18 @@
return id;
}
+bool InstanceKlass::update_jmethod_id(Method* method, jmethodID newMethodID) {
+ size_t idnum = (size_t)method->method_idnum();
+ jmethodID* jmeths = methods_jmethod_ids_acquire();
+ size_t length; // length assigned as debugging crumb
+ jmethodID id = NULL;
+ if (jmeths != NULL && // If there is a cache
+ (length = (size_t)jmeths[0]) > idnum) { // and if it is long enough,
+ jmeths[idnum+1] = newMethodID; // Set method id (may be NULL)
+ return true;
+ }
+ return false;
+}
//
// Walk the list of dependent nmethods searching for nmethods which
@@ -1895,6 +1934,13 @@
last = b;
b = b->next();
}
+
+ // (DCEVM) Hack as dependencies get wrong version of Klass*
+ if (this->old_version() != NULL) {
+ InstanceKlass::cast(this->old_version())->remove_dependent_nmethod(nm);
+ return;
+ }
+
#ifdef ASSERT
tty->print_cr("### %s can't find dependent nmethod:", this->external_name());
nm->print();
@@ -2896,6 +2942,24 @@
assert(is_klass(), "must be klass");
Klass::print_on(st);
+ // (DCEVM) Output revision number and revision numbers of older / newer and oldest / newest version of this class.
+ if (AllowEnhancedClassRedefinition) {
+ st->print(BULLET"revision: %d", revision_number());
+ if (new_version() != NULL) {
+ st->print(" (newer=%d)", new_version()->revision_number());
+ }
+ if (newest_version() != new_version() && newest_version() != this) {
+ st->print(" (newest=%d)", newest_version()->revision_number());
+ }
+ if (old_version() != NULL) {
+ st->print(" (old=%d)", old_version()->revision_number());
+ }
+ if (oldest_version() != old_version() && oldest_version() != this) {
+ st->print(" (oldest=%d)", oldest_version()->revision_number());
+ }
+ st->cr();
+ }
+
st->print(BULLET"instance size: %d", size_helper()); st->cr();
st->print(BULLET"klass size: %d", size()); st->cr();
st->print(BULLET"access: "); access_flags().print_on(st); st->cr();
@@ -3228,7 +3292,7 @@
}
guarantee(sib->is_klass(), "should be klass");
- guarantee(sib->super() == super, "siblings should have same superklass");
+ guarantee(sib->super() == super || super->newest_version() == SystemDictionary::Object_klass(), "siblings should have same superklass");
}
// Verify implementor fields
@@ -3393,6 +3457,7 @@
// Purge previous versions
static void purge_previous_versions_internal(InstanceKlass* ik, int emcp_method_count) {
+ // FIXME: (DCEVM) Should we purge something?
if (ik->previous_versions() != NULL) {
// This klass has previous versions so see what we can cleanup
// while it is safe to do so.
@@ -3630,7 +3695,7 @@
// Determine if InstanceKlass has a previous version.
bool InstanceKlass::has_previous_version() const {
- return (_previous_versions != NULL && _previous_versions->length() > 0);
+ return _old_version != NULL || (_previous_versions != NULL && _previous_versions->length() > 0);
} // end has_previous_version()
diff --git a/src/share/vm/oops/instanceKlass.hpp b/src/share/vm/oops/instanceKlass.hpp
index 31e5acc..8d9689e 100644
--- a/src/share/vm/oops/instanceKlass.hpp
+++ b/src/share/vm/oops/instanceKlass.hpp
@@ -139,6 +139,7 @@
friend class VMStructs;
friend class ClassFileParser;
friend class CompileReplay;
+ friend class VM_EnhancedRedefineClasses;
protected:
// Constructor
@@ -638,7 +639,7 @@
// If the _previous_versions array is non-NULL, then this klass
// has been redefined at least once even if we aren't currently
// tracking a previous version.
- bool has_been_redefined() const { return _previous_versions != NULL; }
+ bool has_been_redefined() const { return _old_version != NULL || _previous_versions != NULL; }
bool has_previous_version() const;
void init_previous_versions() {
_previous_versions = NULL;
@@ -712,6 +713,7 @@
static void get_jmethod_id_length_value(jmethodID* cache, size_t idnum,
size_t *length_p, jmethodID* id_p);
jmethodID jmethod_id_or_null(Method* method);
+ bool update_jmethod_id(Method* method, jmethodID newMethodID);
// annotations support
Annotations* annotations() const { return _annotations; }
@@ -781,6 +783,7 @@
// subclass/subinterface checks
bool implements_interface(Klass* k) const;
bool is_same_or_direct_interface(Klass* k) const;
+ bool implements_interface_any_version(Klass* k) const;
// Access to the implementor of an interface.
Klass* implementor() const
@@ -832,6 +835,10 @@
void do_nonstatic_fields(FieldClosure* cl); // including inherited fields
void do_local_static_fields(void f(fieldDescriptor*, Handle, TRAPS), Handle, TRAPS);
+ // (DCEVM) instance update information to be used in GC run
+ void store_update_information(GrowableArray<int> &values);
+ void clear_update_information();
+
void methods_do(void f(Method* method));
void array_klasses_do(void f(Klass* k));
void array_klasses_do(void f(Klass* k, TRAPS), TRAPS);
diff --git a/src/share/vm/oops/klass.cpp b/src/share/vm/oops/klass.cpp
index 27dc20c..90e017e 100644
--- a/src/share/vm/oops/klass.cpp
+++ b/src/share/vm/oops/klass.cpp
@@ -170,6 +170,13 @@
set_next_link(NULL);
TRACE_INIT_ID(this);
+ set_redefinition_flags(Klass::NoRedefinition);
+ set_redefining(false);
+ set_new_version(NULL);
+ set_old_version(NULL);
+ set_redefinition_index(-1);
+ set_revision_number(-1);
+
set_prototype_header(markOopDesc::prototype());
set_biased_lock_revocation_count(0);
set_last_biased_lock_bulk_revocation_time(0);
@@ -375,6 +382,24 @@
debug_only(verify();)
}
+// (DCEVM)
+void Klass::remove_from_sibling_list() {
+ debug_only(verify();)
+ // remove ourselves to superklass' subklass list
+ InstanceKlass* super = superklass();
+ assert(super != NULL, "should have super");
+ if (super->subklass() == this) {
+ // first subklass
+ super->set_subklass(next_sibling());
+ } else {
+ Klass* sib = super->subklass();
+ while (sib->next_sibling() != this) {
+ sib = sib->next_sibling();
+ };
+ sib->set_next_sibling(next_sibling());
+ }
+}
+
bool Klass::is_loader_alive(BoolObjectClosure* is_alive) {
#ifdef ASSERT
// The class is alive iff the class loader is alive.
diff --git a/src/share/vm/oops/klass.hpp b/src/share/vm/oops/klass.hpp
index 0d9dbce..e0da996 100644
--- a/src/share/vm/oops/klass.hpp
+++ b/src/share/vm/oops/klass.hpp
@@ -149,6 +149,10 @@
oop _java_mirror;
// Superclass
Klass* _super;
+ // Old class
+ Klass* _old_version;
+ // New class
+ Klass* _new_version;
// First subclass (NULL if none); _subklass->next_sibling() is next one
Klass* _subklass;
// Sibling link (or NULL); links all subklasses of a klass
@@ -163,6 +167,16 @@
jint _modifier_flags; // Processed access flags, for use by Class.getModifiers.
AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here.
+
+ // (DCEVM) fields for enhanced class redefinition
+ jint _revision_number; // The revision number for redefined classes
+ jint _redefinition_index; // Index of this class when performing the redefinition
+ bool _subtype_changed;
+ int _redefinition_flags; // Level of class redefinition
+ bool _is_copying_backwards; // Does the class need to copy fields backwards? => possibly overwrite itself?
+ bool _original_field_offsets_changed; // Did the original field offsets of this class change during class redefinition?
+ int * _update_information; // Update information
+ bool _is_redefining;
// Biased locking implementation and statistics
// (the 64-bit chunk goes first, to avoid some fragmentation)
@@ -209,6 +223,53 @@
Array<Klass*>* secondary_supers() const { return _secondary_supers; }
void set_secondary_supers(Array<Klass*>* k) { _secondary_supers = k; }
+
+ // BEGIN class redefinition utilities
+
+ // double links between new and old version of a class
+ Klass* old_version() const { return _old_version; }
+ void set_old_version(Klass* klass) { assert(_old_version == NULL || klass == NULL, "Can only be set once!"); _old_version = klass; }
+ Klass* new_version() const { return _new_version; }
+ void set_new_version(Klass* klass) { assert(_new_version == NULL || klass == NULL, "Can only be set once!"); _new_version = klass; }
+
+ // A subtype of this class is no longer a subtype
+ bool has_subtype_changed() const { return _subtype_changed; }
+ void set_subtype_changed(bool b) { assert(is_newest_version() || new_version()->is_newest_version(), "must be newest or second newest version");
+ _subtype_changed = b; }
+ // state of being redefined
+ int redefinition_index() const { return _redefinition_index; }
+ void set_redefinition_index(int index) { _redefinition_index = index; }
+ void set_redefining(bool b) { _is_redefining = b; }
+ bool is_redefining() const { return _is_redefining; }
+ int redefinition_flags() const { return _redefinition_flags; }
+ bool check_redefinition_flag(int flags) const { return (_redefinition_flags & flags) != 0; }
+ void set_redefinition_flags(int flags) { _redefinition_flags = flags; }
+ void set_redefinition_flag(int flag) { _redefinition_flags |= flag; }
+ void clear_redefinition_flag(int flag) { _redefinition_flags &= ~flag; }
+ bool is_copying_backwards() const { return _is_copying_backwards; }
+ void set_copying_backwards(bool b) { _is_copying_backwards = b; }
+
+ // update information
+ int *update_information() const { return _update_information; }
+ void set_update_information(int *info) { _update_information = info; }
+
+ // Revision number for redefined classes, -1 for originally loaded classes
+ bool was_redefined() const { return _revision_number != -1; }
+ jint revision_number() const { return _revision_number; }
+ void set_revision_number(jint number) { _revision_number = number; }
+
+ const Klass* oldest_version() const { return _old_version == NULL ? this : _old_version->oldest_version(); }
+ Klass* oldest_version() { return _old_version == NULL ? this : _old_version->oldest_version(); }
+
+ const Klass* newest_version() const { return _new_version == NULL ? this : _new_version->newest_version(); }
+ Klass* newest_version() { return _new_version == NULL ? this : _new_version->newest_version(); }
+
+ const Klass* active_version() const { return _new_version == NULL || _new_version->is_redefining() ? this : _new_version->active_version(); }
+ Klass* active_version() { return _new_version == NULL || _new_version->is_redefining() ? this : _new_version->active_version(); }
+
+ bool is_newest_version() const { return _new_version == NULL; }
+
+ // END class redefinition utilities
// Return the element of the _super chain of the given depth.
// If there is no such element, return either NULL or this.
@@ -263,6 +324,7 @@
Klass* subklass() const;
Klass* next_sibling() const;
void append_to_sibling_list(); // add newly created receiver to superklass' subklass list
+ void remove_from_sibling_list(); // (DCEVM) remove receiver from sibling list
void set_next_link(Klass* k) { _next_link = k; }
Klass* next_link() const { return _next_link; } // The next klass defined by the class loader.
@@ -289,6 +351,16 @@
void set_next_sibling(Klass* s);
public:
+ // (DCEVM) Different class redefinition flags of code evolution.
+ enum RedefinitionFlags {
+ NoRedefinition, // This class is not redefined at all!
+ ModifyClass = 1, // There are changes to the class meta data.
+ ModifyClassSize = ModifyClass << 1, // The size of the class meta data changes.
+ ModifyInstances = ModifyClassSize << 1, // There are change to the instance format.
+ ModifyInstanceSize = ModifyInstances << 1, // The size of instances changes.
+ RemoveSuperType = ModifyInstanceSize << 1, // A super type of this class is removed.
+ MarkedAsAffected = RemoveSuperType << 1 // This class has been marked as an affected class.
+ };
// Compiler support
static ByteSize super_offset() { return in_ByteSize(offset_of(Klass, _super)); }
diff --git a/src/share/vm/oops/klassVtable.cpp b/src/share/vm/oops/klassVtable.cpp
index 6d122de..77c7e95 100644
--- a/src/share/vm/oops/klassVtable.cpp
+++ b/src/share/vm/oops/klassVtable.cpp
@@ -1411,6 +1411,8 @@
void klassVtable::verify_against(outputStream* st, klassVtable* vt, int index) {
vtableEntry* vte = &vt->table()[index];
+ // (DCEVM) FIXME-isd: do we need the following line?
+ if (vte->method() == NULL || table()[index].method() == NULL) return;
if (vte->method()->name() != table()[index].method()->name() ||
vte->method()->signature() != table()[index].method()->signature()) {
fatal("mismatched name/signature of vtable entries");
@@ -1430,6 +1432,8 @@
void vtableEntry::verify(klassVtable* vt, outputStream* st) {
NOT_PRODUCT(FlagSetting fs(IgnoreLockingAssertions, true));
+ // FIXME: (DCEVM) does not hold?
+ if (method() != NULL) {
assert(method() != NULL, "must have set method");
method()->verify();
// we sub_type, because it could be a miranda method
@@ -1437,7 +1441,9 @@
#ifndef PRODUCT
print();
#endif
- fatal(err_msg("vtableEntry " PTR_FORMAT ": method is from subclass", this));
+ // (DCEVM) the following fatal does not work for old versions of classes
+ //fatal(err_msg("vtableEntry " PTR_FORMAT ": method is from subclass", this));
+ }
}
}
diff --git a/src/share/vm/oops/method.cpp b/src/share/vm/oops/method.cpp
index 15aeae7..aaf5d5c 100644
--- a/src/share/vm/oops/method.cpp
+++ b/src/share/vm/oops/method.cpp
@@ -1199,6 +1199,8 @@
// Reset correct method/const method, method size, and parameter info
newm->set_constMethod(newcm);
+ newm->set_new_version(newm->new_version());
+ newm->set_old_version(newm->old_version());
newm->constMethod()->set_code_size(new_code_length);
newm->constMethod()->set_constMethod_size(new_const_method_size);
newm->set_method_size(new_method_size);
@@ -1802,6 +1804,10 @@
// Add a method id to the jmethod_ids
jmethodID Method::make_jmethod_id(ClassLoaderData* loader_data, Method* m) {
+ // FIXME: (DCEVM) ???
+ if (m != m->newest_version()) {
+ m = m->newest_version();
+ }
ClassLoaderData* cld = loader_data;
if (!SafepointSynchronize::is_at_safepoint()) {
diff --git a/src/share/vm/oops/method.hpp b/src/share/vm/oops/method.hpp
index a23176e..82e8ade 100644
--- a/src/share/vm/oops/method.hpp
+++ b/src/share/vm/oops/method.hpp
@@ -105,6 +105,10 @@
AccessFlags _access_flags; // Access flags
int _vtable_index; // vtable index of this method (see VtableIndexFlag)
// note: can have vtables with >2**16 elements (because of inheritance)
+ // (DCEVM) Newer version of method available?
+ Method* _new_version;
+ Method* _old_version;
+
#ifdef CC_INTERP
int _result_index; // C++ interpreter needs for converting results to/from stack
#endif
@@ -177,6 +181,23 @@
int name_index() const { return constMethod()->name_index(); }
void set_name_index(int index) { constMethod()->set_name_index(index); }
+ Method* new_version() const { return _new_version; }
+ void set_new_version(Method* m) { _new_version = m; }
+ Method* newest_version() { return (_new_version == NULL) ? this : _new_version->newest_version(); }
+
+ Method* old_version() const { return _old_version; }
+ void set_old_version(Method* m) {
+ /*if (m == NULL) {
+ _old_version = NULL;
+ return;
+ }*/
+
+ assert(_old_version == NULL, "may only be set once");
+ assert(this->code_size() == m->code_size(), "must have same code length");
+ _old_version = m;
+ }
+ const Method* oldest_version() const { return (_old_version == NULL) ? this : _old_version->oldest_version(); }
+
// signature
Symbol* signature() const { return constants()->symbol_at(signature_index()); }
int signature_index() const { return constMethod()->signature_index(); }
diff --git a/src/share/vm/prims/jni.cpp b/src/share/vm/prims/jni.cpp
index 60a6c46..9e92dd4 100644
--- a/src/share/vm/prims/jni.cpp
+++ b/src/share/vm/prims/jni.cpp
@@ -406,6 +406,7 @@
}
Klass* k = SystemDictionary::resolve_from_stream(class_name, class_loader,
Handle(), &st, true,
+ KlassHandle(),
CHECK_NULL);
if (TraceClassResolution && k != NULL) {
diff --git a/src/share/vm/prims/jvm.cpp b/src/share/vm/prims/jvm.cpp
index 3beabbb..6915e23 100644
--- a/src/share/vm/prims/jvm.cpp
+++ b/src/share/vm/prims/jvm.cpp
@@ -930,6 +930,7 @@
Klass* k = SystemDictionary::resolve_from_stream(class_name, class_loader,
protection_domain, &st,
verify != 0,
+ KlassHandle(),
CHECK_NULL);
if (TraceClassResolution && k != NULL) {
diff --git a/src/share/vm/prims/jvmtiEnv.cpp b/src/share/vm/prims/jvmtiEnv.cpp
index b5b3b8a..08fff8a 100644
--- a/src/share/vm/prims/jvmtiEnv.cpp
+++ b/src/share/vm/prims/jvmtiEnv.cpp
@@ -42,6 +42,7 @@
#include "prims/jvmtiManageCapabilities.hpp"
#include "prims/jvmtiRawMonitor.hpp"
#include "prims/jvmtiRedefineClasses.hpp"
+#include "prims/jvmtiRedefineClasses2.hpp"
#include "prims/jvmtiTagMap.hpp"
#include "prims/jvmtiThreadState.inline.hpp"
#include "prims/jvmtiUtil.hpp"
@@ -206,8 +207,10 @@
// is_modifiable_class_ptr - pre-checked for NULL
jvmtiError
JvmtiEnv::IsModifiableClass(oop k_mirror, jboolean* is_modifiable_class_ptr) {
- *is_modifiable_class_ptr = VM_RedefineClasses::is_modifiable_class(k_mirror)?
- JNI_TRUE : JNI_FALSE;
+ bool is_modifiable_class = AllowEnhancedClassRedefinition ?
+ VM_EnhancedRedefineClasses::is_modifiable_class(k_mirror) :
+ VM_RedefineClasses::is_modifiable_class(k_mirror);
+ *is_modifiable_class_ptr = is_modifiable_class ? JNI_TRUE : JNI_FALSE;
return JVMTI_ERROR_NONE;
} /* end IsModifiableClass */
@@ -276,6 +279,11 @@
}
class_definitions[index].klass = jcls;
}
+ if (AllowEnhancedClassRedefinition) {
+ VM_EnhancedRedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform);
+ VMThread::execute(&op);
+ return (op.check_error());
+ }
VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform);
VMThread::execute(&op);
return (op.check_error());
@@ -287,6 +295,11 @@
jvmtiError
JvmtiEnv::RedefineClasses(jint class_count, const jvmtiClassDefinition* class_definitions) {
//TODO: add locking
+ if (AllowEnhancedClassRedefinition) {
+ VM_EnhancedRedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_redefine);
+ VMThread::execute(&op);
+ return (op.check_error());
+ }
VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_redefine);
VMThread::execute(&op);
return (op.check_error());
diff --git a/src/share/vm/prims/jvmtiExport.hpp b/src/share/vm/prims/jvmtiExport.hpp
index d2a7dec..f27a8d4 100644
--- a/src/share/vm/prims/jvmtiExport.hpp
+++ b/src/share/vm/prims/jvmtiExport.hpp
@@ -188,6 +188,7 @@
// systems as needed to relax invariant checks.
static bool _has_redefined_a_class;
friend class VM_RedefineClasses;
+ friend class VM_EnhancedRedefineClasses;
inline static void set_has_redefined_a_class() {
JVMTI_ONLY(_has_redefined_a_class = true;)
}
diff --git a/src/share/vm/prims/jvmtiImpl.cpp b/src/share/vm/prims/jvmtiImpl.cpp
index 0d6d00d..3b1866a 100644
--- a/src/share/vm/prims/jvmtiImpl.cpp
+++ b/src/share/vm/prims/jvmtiImpl.cpp
@@ -289,6 +289,11 @@
Symbol* m_name = _method->name();
Symbol* m_signature = _method->signature();
+ // (DCEVM) Go through old versions of method
+ for (Method* m = _method->old_version(); m != NULL; m = m->old_version()) {
+ (m->*meth_act)(_bci);
+ }
+
// search previous versions if they exist
PreviousVersionWalker pvw(thread, (InstanceKlass *)ikh());
for (PreviousVersionNode * pv_node = pvw.next_previous_version();
diff --git a/src/share/vm/prims/jvmtiRedefineClasses2.cpp b/src/share/vm/prims/jvmtiRedefineClasses2.cpp
new file mode 100644
index 0000000..1a0406e
--- /dev/null
+++ b/src/share/vm/prims/jvmtiRedefineClasses2.cpp
@@ -0,0 +1,2128 @@
+/*
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "classfile/systemDictionary.hpp"
+#include "classfile/verifier.hpp"
+#include "code/codeCache.hpp"
+#include "interpreter/oopMapCache.hpp"
+#include "interpreter/rewriter.hpp"
+#include "memory/gcLocker.hpp"
+#include "memory/universe.inline.hpp"
+#include "memory/metaspaceShared.hpp"
+#include "oops/fieldStreams.hpp"
+#include "oops/klassVtable.hpp"
+#include "prims/jvmtiImpl.hpp"
+#include "prims/jvmtiRedefineClasses2.hpp"
+#include "prims/methodComparator.hpp"
+#include "prims/jvmtiClassFileReconstituter.hpp"
+#include "runtime/deoptimization.hpp"
+#include "runtime/relocator.hpp"
+#include "utilities/bitMap.inline.hpp"
+#include "compiler/compileBroker.hpp"
+#include "oops/instanceMirrorKlass.hpp"
+#include "utilities/pair.hpp"
+
+
+Array<Method*>* VM_EnhancedRedefineClasses::_old_methods = NULL;
+Array<Method*>* VM_EnhancedRedefineClasses::_new_methods = NULL;
+int* VM_EnhancedRedefineClasses::_matching_old_methods = NULL;
+int* VM_EnhancedRedefineClasses::_matching_new_methods = NULL;
+int* VM_EnhancedRedefineClasses::_deleted_methods = NULL;
+int* VM_EnhancedRedefineClasses::_added_methods = NULL;
+int VM_EnhancedRedefineClasses::_matching_methods_length = 0;
+int VM_EnhancedRedefineClasses::_deleted_methods_length = 0;
+int VM_EnhancedRedefineClasses::_added_methods_length = 0;
+GrowableArray<instanceKlassHandle>* VM_EnhancedRedefineClasses::_affected_klasses = NULL;
+
+
+// Holds the revision number of the current class redefinition
+int VM_EnhancedRedefineClasses::_revision_number = -1;
+
+VM_EnhancedRedefineClasses::VM_EnhancedRedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind)
+ : VM_GC_Operation(Universe::heap()->total_full_collections(), GCCause::_heap_inspection) {
+ RC_TIMER_START(_timer_total);
+ _class_count = class_count;
+ _class_defs = class_defs;
+ _class_load_kind = class_load_kind;
+ _result = JVMTI_ERROR_NONE;
+}
+
+VM_EnhancedRedefineClasses::~VM_EnhancedRedefineClasses() {
+ RC_TIMER_STOP(_timer_total);
+}
+
+void VM_EnhancedRedefineClasses::swap_all_method_annotations(ConstMethod* old_method, ConstMethod* new_method) {
+ return; // FIXME-isd: swap annotations!
+
+ AnnotationArray* save;
+
+ save = old_method->method_annotations();
+ old_method->set_method_annotations(new_method->method_annotations());
+ new_method->set_method_annotations(save);
+
+ save = old_method->parameter_annotations();
+ old_method->set_parameter_annotations(new_method->parameter_annotations());
+ new_method->set_parameter_annotations(save);
+
+ save = old_method->default_annotations();
+ old_method->set_default_annotations(new_method->default_annotations());
+ new_method->set_default_annotations(save);
+
+ save = old_method->type_annotations();
+ old_method->set_type_annotations(new_method->type_annotations());
+ new_method->set_type_annotations(save);
+}
+
+void VM_EnhancedRedefineClasses::add_affected_klasses( Klass* klass )
+{
+ assert(!_affected_klasses->contains(klass), "must not occur more than once!");
+ assert(klass->new_version() == NULL, "Only last version is valid entry in system dictionary");
+
+ Klass* k = klass;
+
+ if (k->check_redefinition_flag(Klass::MarkedAsAffected)) {
+ _affected_klasses->append(klass);
+ return;
+ }
+
+ for (juint i = 0; i < k->super_depth(); i++) {
+ Klass* primary = k->primary_super_of_depth(i);
+ // super_depth returns "8" for interfaces, but they don't have primaries other than Object.
+ if (primary == NULL) break;
+ if (primary->check_redefinition_flag(Klass::MarkedAsAffected)) {
+ RC_TRACE(0x00000001, ("Found affected class: %s", k->name()->as_C_string()));
+ k->set_redefinition_flag(Klass::MarkedAsAffected);
+ _affected_klasses->append(klass);
+ return;
+ }
+ }
+
+ // Check secondary supers
+ int cnt = k->secondary_supers()->length();
+ for (int i = 0; i < cnt; i++) {
+ Klass* secondary = k->secondary_supers()->at(i);
+ if (secondary->check_redefinition_flag(Klass::MarkedAsAffected)) {
+ RC_TRACE(0x00000001, ("Found affected class: %s", k->name()->as_C_string()));
+ k->set_redefinition_flag(Klass::MarkedAsAffected);
+ _affected_klasses->append(klass);
+ return;
+ }
+ }
+}
+
+
+// Searches for all affected classes and performs a sorting such that a supertype is always before a subtype.
+jvmtiError VM_EnhancedRedefineClasses::find_sorted_affected_classes() {
+
+ assert(_affected_klasses, "");
+ for (int i = 0; i < _class_count; i++) {
+ oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
+ instanceKlassHandle klass_handle(Thread::current(), java_lang_Class::as_Klass(mirror));
+ klass_handle->set_redefinition_flag(Klass::MarkedAsAffected);
+ assert(klass_handle->new_version() == NULL, "Must be new class");
+ RC_TRACE(0x00000001, ("Class being reloaded: %s", klass_handle->name()->as_C_string()));
+ }
+
+ // Find classes not directly redefined, but affected by a redefinition (because one of its supertypes is redefined)
+ SystemDictionary::classes_do(VM_EnhancedRedefineClasses::add_affected_klasses);
+ RC_TRACE(0x00000001, ("%d classes affected", _affected_klasses->length()));
+
+ // Sort the affected klasses such that a supertype is always on a smaller array index than its subtype.
+ jvmtiError result = do_topological_class_sorting(_class_defs, _class_count, Thread::current());
+ if (RC_TRACE_ENABLED(0x00000001)) {
+ RC_TRACE(0x00000001, ("Redefine order: "));
+ for (int i = 0; i < _affected_klasses->length(); i++) {
+ RC_TRACE(0x00000001, ("%s", _affected_klasses->at(i)->name()->as_C_string()));
+ }
+ }
+
+ return result;
+}
+
+// Searches for the class bytes of the given class and returns them as a byte array.
+jvmtiError VM_EnhancedRedefineClasses::find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed) {
+
+ *not_changed = false;
+
+ // Search for the index in the redefinition array that corresponds to the current class
+ int j;
+ for (j=0; j<_class_count; j++) {
+ oop mirror = JNIHandles::resolve_non_null(_class_defs[j].klass);
+ Klass* the_class_oop = java_lang_Class::as_Klass(mirror);
+ if (the_class_oop == the_class()) {
+ break;
+ }
+ }
+
+ if (j == _class_count) {
+
+ *not_changed = true;
+
+ // Redefine with same bytecodes. This is a class that is only indirectly affected by redefinition,
+ // so the user did not specify a different bytecode for that class.
+
+ if (the_class->get_cached_class_file_bytes() == NULL) {
+ // not cached, we need to reconstitute the class file from VM representation
+ constantPoolHandle constants(Thread::current(), the_class->constants());
+ MonitorLockerEx ml(constants->lock()); // lock constant pool while we query it
+ //ObjectLocker ol(constants, Thread::current()); // lock constant pool while we query it
+
+ JvmtiClassFileReconstituter reconstituter(the_class);
+ if (reconstituter.get_error() != JVMTI_ERROR_NONE) {
+ return reconstituter.get_error();
+ }
+
+ *class_byte_count = (jint)reconstituter.class_file_size();
+ *class_bytes = (unsigned char*)reconstituter.class_file_bytes();
+ } else {
+
+ // it is cached, get it from the cache
+ *class_byte_count = the_class->get_cached_class_file_len();
+ *class_bytes = the_class->get_cached_class_file_bytes();
+ }
+
+ } else {
+
+ // Redefine with bytecodes at index j
+ *class_bytes = _class_defs[j].class_bytes;
+ *class_byte_count = _class_defs[j].class_byte_count;
+ }
+
+ return JVMTI_ERROR_NONE;
+ }
+
+// Prologue of the VM operation, called on the Java thread in parallel to normal program execution
+bool VM_EnhancedRedefineClasses::doit_prologue() {
+
+ _revision_number++;
+ RC_TRACE(0x00000001,
+ ("Redefinition with revision number %d started!", _revision_number));
+
+ assert(Thread::current()->is_Java_thread(), "must be Java thread");
+ RC_TIMER_START(_timer_prologue);
+
+ if (!check_arguments()) {
+ RC_TIMER_STOP(_timer_prologue);
+ return false;
+ }
+
+ // We first load new class versions in the prologue, because somewhere down the
+ // call chain it is required that the current thread is a Java thread.
+ _new_classes = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<instanceKlassHandle>(5, true);
+
+ assert(_affected_klasses == NULL, "");
+ _affected_klasses = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<instanceKlassHandle>(_class_count, true);
+
+ _result = load_new_class_versions(Thread::current());
+
+ RC_TRACE(0x00000001,
+ ("Loaded new class versions!"));
+ if (_result != JVMTI_ERROR_NONE) {
+ RC_TRACE(0x00000001,
+ ("error occured: %d!", _result));
+ delete _new_classes;
+ _new_classes = NULL;
+ delete _affected_klasses;
+ _affected_klasses = NULL;
+ RC_TIMER_STOP(_timer_prologue);
+ return false;
+ }
+
+ VM_GC_Operation::doit_prologue();
+ RC_TIMER_STOP(_timer_prologue);
+
+ RC_TRACE(0x00000001, ("doit_prologue finished!"));
+ return true;
+}
+
+// Checks basic properties of the arguments of the redefinition command.
+jvmtiError VM_EnhancedRedefineClasses::check_arguments_error() {
+ if (_class_defs == NULL) return JVMTI_ERROR_NULL_POINTER;
+ for (int i = 0; i < _class_count; i++) {
+ if (_class_defs[i].klass == NULL) return JVMTI_ERROR_INVALID_CLASS;
+ if (_class_defs[i].class_byte_count == 0) return JVMTI_ERROR_INVALID_CLASS_FORMAT;
+ if (_class_defs[i].class_bytes == NULL) return JVMTI_ERROR_NULL_POINTER;
+ }
+ return JVMTI_ERROR_NONE;
+ }
+
+// Returns false and sets an result error code if the redefinition should be aborted.
+bool VM_EnhancedRedefineClasses::check_arguments() {
+ jvmtiError error = check_arguments_error();
+ if (error != JVMTI_ERROR_NONE || _class_count == 0) {
+ _result = error;
+ return false;
+ }
+ return true;
+}
+
+jvmtiError VM_EnhancedRedefineClasses::check_exception() const {
+ Thread* THREAD = Thread::current();
+ if (HAS_PENDING_EXCEPTION) {
+
+ Symbol* ex_name = PENDING_EXCEPTION->klass()->name();
+ RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("parse_stream exception: '%s'", ex_name->as_C_string()));
+ CLEAR_PENDING_EXCEPTION;
+
+ if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
+ return JVMTI_ERROR_UNSUPPORTED_VERSION;
+ } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) {
+ return JVMTI_ERROR_INVALID_CLASS_FORMAT;
+ } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) {
+ return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
+ } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) {
+ // The message will be "XXX (wrong name: YYY)"
+ return JVMTI_ERROR_NAMES_DONT_MATCH;
+ } else if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
+ return JVMTI_ERROR_OUT_OF_MEMORY;
+ } else {
+ // Just in case more exceptions can be thrown..
+ return JVMTI_ERROR_FAILS_VERIFICATION;
+ }
+ }
+
+ return JVMTI_ERROR_NONE;
+}
+
+// Loads all new class versions and stores the InstanceKlass handles in an array.
+jvmtiError VM_EnhancedRedefineClasses::load_new_class_versions(TRAPS) {
+
+ ResourceMark rm(THREAD);
+
+ RC_TRACE(0x00000001,
+ ("loading new class versions (%d)", _class_count));
+
+ // Retrieve an array of all classes that need to be redefined
+ jvmtiError err = find_sorted_affected_classes();
+ if (err != JVMTI_ERROR_NONE) {
+ RC_TRACE(0x00000001,
+ ("Error finding sorted affected classes: %d", (int)err));
+ return err;
+ }
+
+
+ JvmtiThreadState *state = JvmtiThreadState::state_for(JavaThread::current());
+
+ _max_redefinition_flags = Klass::NoRedefinition;
+ jvmtiError result = JVMTI_ERROR_NONE;
+
+ for (int i = 0; i < _affected_klasses->length(); i++) {
+ instanceKlassHandle the_class = _affected_klasses->at(i);
+
+ RC_TRACE(0x00000001,
+ ("Processing affected class %s (%d of %d)",
+ the_class->name()->as_C_string(),
+ i + 1,
+ _affected_klasses->length()));
+
+ the_class->link_class(THREAD);
+ result = check_exception();
+ if (result != JVMTI_ERROR_NONE) break;
+
+ // Find new class bytes
+ const unsigned char* class_bytes;
+ jint class_byte_count;
+ jvmtiError error;
+ jboolean not_changed;
+ if ((error = find_class_bytes(the_class, &class_bytes, &class_byte_count, ¬_changed)) != JVMTI_ERROR_NONE) {
+ RC_TRACE_WITH_THREAD(0x00000002, THREAD,
+ ("Error finding class bytes: %d", (int)error));
+ result = error;
+ break;
+ }
+ assert(class_bytes != NULL && class_byte_count != 0, "Class bytes defined at this point!");
+
+
+ // Set redefined class handle in JvmtiThreadState class.
+ // This redefined class is sent to agent event handler for class file
+ // load hook event.
+ state->set_class_being_redefined(&the_class, _class_load_kind);
+
+ RC_TIMER_STOP(_timer_prologue);
+ RC_TIMER_START(_timer_class_loading);
+
+ // Parse the stream.
+ Handle the_class_loader(THREAD, the_class->class_loader());
+ Handle protection_domain(THREAD, the_class->protection_domain());
+ ClassFileStream st((u1*) class_bytes, class_byte_count, (char *)"__VM_EhnancedRedefineClasses__");
+
+ Klass* klass =
+ SystemDictionary::resolve_from_stream(
+ the_class->name(),
+ the_class_loader,
+ protection_domain,
+ &st,
+ true,
+ the_class,
+ THREAD);
+ instanceKlassHandle new_class(THREAD, klass);
+
+ RC_TIMER_STOP(_timer_class_loading);
+ RC_TIMER_START(_timer_prologue);
+
+ // Clear class_being_redefined just to be sure.
+ state->clear_class_being_redefined();
+
+ result = check_exception();
+ if (result != JVMTI_ERROR_NONE) break;
+
+ not_changed = false;
+
+#ifdef ASSERT
+
+ assert(new_class() != NULL, "Class could not be loaded!");
+ assert(new_class() != the_class(), "must be different");
+ assert(new_class->new_version() == NULL && new_class->old_version() != NULL, "");
+
+
+ Array<Klass*>* k_interfaces = new_class->local_interfaces();
+ for (int j = 0; j < k_interfaces->length(); j++) {
+ assert(k_interfaces->at(j)->is_newest_version(), "just checking");
+ }
+
+ if (!THREAD->is_Compiler_thread()) {
+ RC_TRACE(0x00000001, ("name=%s loader="INTPTR_FORMAT" protection_domain="INTPTR_FORMAT,
+ the_class->name()->as_C_string(),
+ (intptr_t) (oopDesc*) the_class->class_loader(),
+ (intptr_t) (oopDesc*) the_class->protection_domain()));
+ // If we are on the compiler thread, we must not try to resolve a class.
+ Klass* systemLookup = SystemDictionary::resolve_or_null(the_class->name(), the_class->class_loader(), the_class->protection_domain(), THREAD);
+
+ if (systemLookup != NULL) {
+ assert(systemLookup == new_class->old_version(), "Old class must be in system dictionary!");
+ Klass *subklass = new_class()->subklass();
+ while (subklass != NULL) {
+ assert(subklass->new_version() == NULL, "Most recent version of class!");
+ subklass = subklass->next_sibling();
+ }
+ } else {
+ // This can happen for reflection generated classes.. ?
+ CLEAR_PENDING_EXCEPTION;
+ }
+ }
+
+#endif
+
+ if (RC_TRACE_ENABLED(0x00000001)) {
+ if (new_class->layout_helper() != the_class->layout_helper()) {
+ RC_TRACE(0x00000001,
+ ("Instance size change for class %s: new=%d old=%d",
+ new_class->name()->as_C_string(),
+ new_class->layout_helper(),
+ the_class->layout_helper()));
+ }
+ }
+
+ // Set the new version of the class
+ new_class->set_revision_number(_revision_number);
+ new_class->set_redefinition_index(i);
+ the_class->set_new_version(new_class());
+ _new_classes->append(new_class);
+
+ assert(new_class->new_version() == NULL, "");
+
+ int redefinition_flags = Klass::NoRedefinition;
+
+ if (not_changed) {
+ redefinition_flags = Klass::NoRedefinition;
+ } else {
+ redefinition_flags = calculate_redefinition_flags(new_class);
+ if (redefinition_flags >= Klass::RemoveSuperType) {
+ result = JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
+ break;
+ }
+ }
+
+ if (new_class->super() != NULL) {
+ redefinition_flags = redefinition_flags | new_class->super()->redefinition_flags();
+ }
+
+ for (int j = 0; j<new_class->local_interfaces()->length(); j++) {
+ redefinition_flags = redefinition_flags | (new_class->local_interfaces()->at(j))->redefinition_flags();
+ }
+
+ new_class->set_redefinition_flags(redefinition_flags);
+
+ _max_redefinition_flags = _max_redefinition_flags | redefinition_flags;
+
+ if ((redefinition_flags & Klass::ModifyInstances) != 0) {
+ // TODO: Check if watch access flags of static fields are updated correctly.
+ calculate_instance_update_information(_new_classes->at(i)());
+ } else {
+ // Fields were not changed, transfer special flags only
+ assert(new_class->layout_helper() >> 1 == new_class->old_version()->layout_helper() >> 1, "must be equal");
+ assert(new_class->fields()->length() == InstanceKlass::cast(new_class->old_version())->fields()->length(), "must be equal");
+
+ JavaFieldStream old_fs(the_class);
+ JavaFieldStream new_fs(new_class);
+ for (; !old_fs.done() && !new_fs.done(); old_fs.next(), new_fs.next()) {
+ AccessFlags flags = new_fs.access_flags();
+ flags.set_is_field_modification_watched(old_fs.access_flags().is_field_modification_watched());
+ flags.set_is_field_access_watched(old_fs.access_flags().is_field_access_watched());
+ new_fs.set_access_flags(flags);
+ }
+ }
+
+ if (RC_TRACE_ENABLED(0x00000001)) {
+ RC_TRACE(0x00000001,
+ ("Super class is %s", new_class->super()->name()->as_C_string()));
+ }
+
+#ifdef ASSERT
+ assert(new_class->super() == NULL || new_class->super()->new_version() == NULL, "Super klass must be newest version!");
+
+ the_class->vtable()->verify(tty);
+ new_class->vtable()->verify(tty);
+#endif
+
+ if (i == _affected_klasses->length() - 1) {
+ // This was the last class processed => check if additional classes have been loaded in the meantime
+ for (int j = 0; j<_affected_klasses->length(); j++) {
+
+ Klass* initial_klass = _affected_klasses->at(j)();
+ Klass *initial_subklass = initial_klass->subklass();
+ Klass *cur_klass = initial_subklass;
+ while(cur_klass != NULL) {
+
+ if(cur_klass->oop_is_instance() && cur_klass->is_newest_version() && !cur_klass->is_redefining()) {
+ instanceKlassHandle handle(THREAD, cur_klass);
+ if (!_affected_klasses->contains(handle)) {
+
+ int k = i + 1;
+ for (; k<_affected_klasses->length(); k++) {
+ if (_affected_klasses->at(k)->is_subtype_of(cur_klass)) {
+ break;
+ }
+ }
+ _affected_klasses->insert_before(k, handle);
+ RC_TRACE(0x00000001,
+ ("Adding newly loaded class to affected classes: %s", cur_klass->name()->as_C_string()));
+ }
+ }
+
+ cur_klass = cur_klass->next_sibling();
+ }
+ }
+
+ int new_count = _affected_klasses->length() - 1 - i;
+ if (new_count != 0) {
+ RC_TRACE(0x00000001,
+ ("Found new number of affected classes: %d", new_count));
+ }
+ }
+ }
+
+ if (result != JVMTI_ERROR_NONE) {
+ rollback();
+ return result;
+ }
+
+ RC_TIMER_STOP(_timer_prologue);
+ RC_TIMER_START(_timer_class_linking);
+ // Link and verify new classes _after_ all classes have been updated in the system dictionary!
+ for (int i=0; i<_affected_klasses->length(); i++) {
+ instanceKlassHandle the_class = _affected_klasses->at(i);
+ instanceKlassHandle new_class(the_class->new_version());
+
+ RC_TRACE(0x00000001,
+ ("Linking class %d/%d %s", i, _affected_klasses->length(), the_class->name()->as_C_string()));
+ new_class->link_class(THREAD);
+
+ result = check_exception();
+ if (result != JVMTI_ERROR_NONE) break;
+ }
+ RC_TIMER_STOP(_timer_class_linking);
+ RC_TIMER_START(_timer_prologue);
+
+ if (result != JVMTI_ERROR_NONE) {
+ rollback();
+ return result;
+ }
+
+ RC_TRACE(0x00000001, ("All classes loaded!"));
+
+#ifdef ASSERT
+ for (int i=0; i<_affected_klasses->length(); i++) {
+ instanceKlassHandle the_class = _affected_klasses->at(i);
+ assert(the_class->new_version() != NULL, "Must have been redefined");
+ instanceKlassHandle new_version = instanceKlassHandle(THREAD, the_class->new_version());
+ assert(new_version->new_version() == NULL, "Must be newest version");
+
+ if (!(new_version->super() == NULL || new_version->super()->new_version() == NULL)) {
+ new_version()->print();
+ new_version->super()->print();
+ }
+ assert(new_version->super() == NULL || new_version->super()->new_version() == NULL, "Super class must be newest version");
+ }
+
+ SystemDictionary::classes_do(check_class, THREAD);
+
+#endif
+
+ RC_TRACE(0x00000001, ("Finished verification!"));
+ return JVMTI_ERROR_NONE;
+}
+
+int VM_EnhancedRedefineClasses::calculate_redefinition_flags(instanceKlassHandle new_class) {
+
+ int result = Klass::NoRedefinition;
+ RC_TRACE(0x00000001,
+ ("Comparing different class versions of class %s", new_class->name()->as_C_string()));
+
+ assert(new_class->old_version() != NULL, "must have old version");
+ instanceKlassHandle the_class(new_class->old_version());
+
+ // Check whether class is in the error init state.
+ if (the_class->is_in_error_state()) {
+ // TBD #5057930: special error code is needed in 1.6
+ //result = Klass::union_redefinition_level(result, Klass::Invalid);
+ }
+
+ int i;
+
+ //////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // Check superclasses
+ assert(new_class->super() == NULL || new_class->super()->is_newest_version(), "");
+ if (the_class->super() != new_class->super()) {
+ // Super class changed
+ Klass* cur_klass = the_class->super();
+ while (cur_klass != NULL) {
+ if (!new_class->is_subclass_of(cur_klass->newest_version())) {
+ RC_TRACE(0x00000001,
+ ("Removed super class %s", cur_klass->name()->as_C_string()));
+ result = result | Klass::RemoveSuperType | Klass::ModifyInstances | Klass::ModifyClass;
+
+ if (!cur_klass->has_subtype_changed()) {
+ RC_TRACE(0x00000001,
+ ("Subtype changed of class %s", cur_klass->name()->as_C_string()));
+ cur_klass->set_subtype_changed(true);
+ }
+ }
+
+ cur_klass = cur_klass->super();
+ }
+
+ cur_klass = new_class->super();
+ while (cur_klass != NULL) {
+ if (!the_class->is_subclass_of(cur_klass->old_version())) {
+ RC_TRACE(0x00000001,
+ ("Added super class %s", cur_klass->name()->as_C_string()));
+ result = result | Klass::ModifyClass | Klass::ModifyInstances;
+ }
+ cur_klass = cur_klass->super();
+ }
+ }
+
+ //////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // Check interfaces
+
+ // Interfaces removed?
+ Array<Klass*>* old_interfaces = the_class->transitive_interfaces();
+ for (i = 0; i<old_interfaces->length(); i++) {
+ instanceKlassHandle old_interface(old_interfaces->at(i));
+ if (!new_class->implements_interface_any_version(old_interface())) {
+ result = result | Klass::RemoveSuperType | Klass::ModifyClass;
+ RC_TRACE(0x00000001,
+ ("Removed interface %s", old_interface->name()->as_C_string()));
+
+ if (!old_interface->has_subtype_changed()) {
+ RC_TRACE(0x00000001,
+ ("Subtype changed of interface %s", old_interface->name()->as_C_string()));
+ old_interface->set_subtype_changed(true);
+ }
+ }
+ }
+
+ // Interfaces added?
+ Array<Klass*>* new_interfaces = new_class->transitive_interfaces();
+ for (i = 0; i<new_interfaces->length(); i++) {
+ if (!the_class->implements_interface_any_version(new_interfaces->at(i))) {
+ result = result | Klass::ModifyClass;
+ RC_TRACE(0x00000001,
+ ("Added interface %s", new_interfaces->at(i)->name()->as_C_string()));
+ }
+ }
+
+
+ // Check whether class modifiers are the same.
+ jushort old_flags = (jushort) the_class->access_flags().get_flags();
+ jushort new_flags = (jushort) new_class->access_flags().get_flags();
+ if (old_flags != new_flags) {
+ // TODO Can this have any effects?
+ }
+
+ // Check if the number, names, types and order of fields declared in these classes
+ // are the same.
+ JavaFieldStream old_fs(the_class);
+ JavaFieldStream new_fs(new_class);
+ for (; !old_fs.done() && !new_fs.done(); old_fs.next(), new_fs.next()) {
+ // access
+ old_flags = old_fs.access_flags().as_short();
+ new_flags = new_fs.access_flags().as_short();
+ if ((old_flags ^ new_flags) & JVM_RECOGNIZED_FIELD_MODIFIERS) {
+ // TODO can this have any effect?
+ }
+ // offset
+ if (old_fs.offset() != new_fs.offset()) {
+ result = result | Klass::ModifyInstances;
+ }
+ // name and signature
+ Symbol* name_sym1 = the_class->constants()->symbol_at(old_fs.name_index());
+ Symbol* sig_sym1 = the_class->constants()->symbol_at(old_fs.signature_index());
+ Symbol* name_sym2 = new_class->constants()->symbol_at(new_fs.name_index());
+ Symbol* sig_sym2 = new_class->constants()->symbol_at(new_fs.signature_index());
+ if (name_sym1 != name_sym2 || sig_sym1 != sig_sym2) {
+ result = result | Klass::ModifyInstances;
+ }
+ }
+
+ // If both streams aren't done then we have a differing number of
+ // fields.
+ if (!old_fs.done() || !new_fs.done()) {
+ result = result | Klass::ModifyInstances;
+ }
+
+ // Do a parallel walk through the old and new methods. Detect
+ // cases where they match (exist in both), have been added in
+ // the new methods, or have been deleted (exist only in the
+ // old methods). The class file parser places methods in order
+ // by method name, but does not order overloaded methods by
+ // signature. In order to determine what fate befell the methods,
+ // this code places the overloaded new methods that have matching
+ // old methods in the same order as the old methods and places
+ // new overloaded methods at the end of overloaded methods of
+ // that name. The code for this order normalization is adapted
+ // from the algorithm used in InstanceKlass::find_method().
+ // Since we are swapping out of order entries as we find them,
+ // we only have to search forward through the overloaded methods.
+ // Methods which are added and have the same name as an existing
+ // method (but different signature) will be put at the end of
+ // the methods with that name, and the name mismatch code will
+ // handle them.
+ Array<Method*>* k_old_methods(the_class->methods()); // FIXME-isd: handles???
+ Array<Method*>* k_new_methods(new_class->methods());
+ int n_old_methods = k_old_methods->length();
+ int n_new_methods = k_new_methods->length();
+
+ int ni = 0;
+ int oi = 0;
+ while (true) {
+ Method* k_old_method;
+ Method* k_new_method;
+ enum { matched, added, deleted, undetermined } method_was = undetermined;
+
+ if (oi >= n_old_methods) {
+ if (ni >= n_new_methods) {
+ break; // we've looked at everything, done
+ }
+ // New method at the end
+ k_new_method = k_new_methods->at(ni);
+ method_was = added;
+ } else if (ni >= n_new_methods) {
+ // Old method, at the end, is deleted
+ k_old_method = k_old_methods->at(oi);
+ method_was = deleted;
+ } else {
+ // There are more methods in both the old and new lists
+ k_old_method = k_old_methods->at(oi);
+ k_new_method = k_new_methods->at(ni);
+ if (k_old_method->name() != k_new_method->name()) {
+ // Methods are sorted by method name, so a mismatch means added
+ // or deleted
+ if (k_old_method->name()->fast_compare(k_new_method->name()) > 0) {
+ method_was = added;
+ } else {
+ method_was = deleted;
+ }
+ } else if (k_old_method->signature() == k_new_method->signature()) {
+ // Both the name and signature match
+ method_was = matched;
+ } else {
+ // The name matches, but the signature doesn't, which means we have to
+ // search forward through the new overloaded methods.
+ int nj; // outside the loop for post-loop check
+ for (nj = ni + 1; nj < n_new_methods; nj++) {
+ Method* m = k_new_methods->at(nj);
+ if (k_old_method->name() != m->name()) {
+ // reached another method name so no more overloaded methods
+ method_was = deleted;
+ break;
+ }
+ if (k_old_method->signature() == m->signature()) {
+ // found a match so swap the methods
+ k_new_methods->at_put(ni, m);
+ k_new_methods->at_put(nj, k_new_method);
+ k_new_method = m;
+ method_was = matched;
+ break;
+ }
+ }
+
+ if (nj >= n_new_methods) {
+ // reached the end without a match; so method was deleted
+ method_was = deleted;
+ }
+ }
+ }
+
+ switch (method_was) {
+ case matched:
+ // methods match, be sure modifiers do too
+ old_flags = (jushort) k_old_method->access_flags().get_flags();
+ new_flags = (jushort) k_new_method->access_flags().get_flags();
+ if ((old_flags ^ new_flags) & ~(JVM_ACC_NATIVE)) {
+ // TODO Can this have any effects? Probably yes on vtables?
+ result = result | Klass::ModifyClass;
+ }
+ {
+ u2 new_num = k_new_method->method_idnum();
+ u2 old_num = k_old_method->method_idnum();
+ if (new_num != old_num) {
+ Method* idnum_owner = new_class->method_with_idnum(old_num);
+ if (idnum_owner != NULL) {
+ // There is already a method assigned this idnum -- switch them
+ idnum_owner->set_method_idnum(new_num);
+ }
+ k_new_method->set_method_idnum(old_num);
+ RC_TRACE(0x00008000,
+ ("swapping idnum of new and old method %d / %d!", new_num, old_num);
+ swap_all_method_annotations(k_old_method->constMethod(), k_new_method->constMethod()));
+ }
+ }
+ RC_TRACE(0x00008000, ("Method matched: new: %s [%d] == old: %s [%d]",
+ k_new_method->name_and_sig_as_C_string(), ni,
+ k_old_method->name_and_sig_as_C_string(), oi));
+ // advance to next pair of methods
+ ++oi;
+ ++ni;
+ break;
+ case added:
+ // method added, see if it is OK
+ new_flags = (jushort) k_new_method->access_flags().get_flags();
+ if ((new_flags & JVM_ACC_PRIVATE) == 0
+ // hack: private should be treated as final, but alas
+ || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0) {
+ // new methods must be private
+ result = result | Klass::ModifyClass;
+ }
+ {
+ u2 num = new_class->next_method_idnum();
+ if (num == ConstMethod::UNSET_IDNUM) {
+ // cannot add any more methods
+ result = result | Klass::ModifyClass;
+ }
+ u2 new_num = k_new_method->method_idnum();
+ Method* idnum_owner = new_class->method_with_idnum(num);
+ if (idnum_owner != NULL) {
+ // There is already a method assigned this idnum -- switch them
+ idnum_owner->set_method_idnum(new_num);
+ }
+ k_new_method->set_method_idnum(num);
+ swap_all_method_annotations(k_old_method->constMethod(), k_new_method->constMethod());
+ }
+ RC_TRACE(0x00008000, ("Method added: new: %s [%d], idnum %d",
+ k_new_method->name_and_sig_as_C_string(), ni, k_new_method->method_idnum()));
+ ++ni; // advance to next new method
+ break;
+ case deleted:
+ // method deleted, see if it is OK
+ old_flags = (jushort) k_old_method->access_flags().get_flags();
+ if ((old_flags & JVM_ACC_PRIVATE) == 0
+ // hack: private should be treated as final, but alas
+ || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
+ ) {
+ // deleted methods must be private
+ result = result | Klass::ModifyClass;
+ }
+ RC_TRACE(0x00008000, ("Method deleted: old: %s [%d]",
+ k_old_method->name_and_sig_as_C_string(), oi));
+ ++oi; // advance to next old method
+ break;
+ default:
+ ShouldNotReachHere();
+ }
+ }
+
+ if (new_class()->size() != new_class->old_version()->size()) {
+ result |= Klass::ModifyClassSize;
+ }
+
+ if (new_class->size_helper() != ((InstanceKlass*)(new_class->old_version()))->size_helper()) {
+ result |= Klass::ModifyInstanceSize;
+ }
+
+ // TODO Check method bodies to be able to return NoChange?
+ return result;
+}
+
+void VM_EnhancedRedefineClasses::calculate_instance_update_information(Klass* new_version) {
+
+ class CalculateFieldUpdates : public FieldClosure {
+
+ private:
+ InstanceKlass* _old_ik;
+ GrowableArray<int> _update_info;
+ int _position;
+ bool _copy_backwards;
+
+ public:
+
+ bool does_copy_backwards() {
+ return _copy_backwards;
+ }
+
+ CalculateFieldUpdates(InstanceKlass* old_ik) :
+ _old_ik(old_ik), _position(instanceOopDesc::base_offset_in_bytes()), _copy_backwards(false) {
+ _update_info.append(_position);
+ _update_info.append(0);
+ }
+
+ GrowableArray<int> &finish() {
+ _update_info.append(0);
+ return _update_info;
+ }
+
+ void do_field(fieldDescriptor* fd) {
+ int alignment = fd->offset() - _position;
+ if (alignment > 0) {
+ // This field was aligned, so we need to make sure that we fill the gap
+ fill(alignment);
+ }
+
+ assert(_position == fd->offset(), "must be correct offset!");
+
+ fieldDescriptor old_fd;
+ if (_old_ik->find_field(fd->name(), fd->signature(), false, &old_fd) != NULL) {
+ // Found field in the old class, copy
+ copy(old_fd.offset(), type2aelembytes(fd->field_type()));
+
+ if (old_fd.offset() < fd->offset()) {
+ _copy_backwards = true;
+ }
+
+ // Transfer special flags
+ fd->set_is_field_modification_watched(old_fd.is_field_modification_watched());
+ fd->set_is_field_access_watched(old_fd.is_field_access_watched());
+ } else {
+ // New field, fill
+ fill(type2aelembytes(fd->field_type()));
+ }
+ }
+
+ private:
+
+ void fill(int size) {
+ if (_update_info.length() > 0 && _update_info.at(_update_info.length() - 1) < 0) {
+ (*_update_info.adr_at(_update_info.length() - 1)) -= size;
+ } else {
+ _update_info.append(-size);
+ }
+ _position += size;
+ }
+
+ void copy(int offset, int size) {
+ int prev_end = -1;
+ if (_update_info.length() > 0 && _update_info.at(_update_info.length() - 1) > 0) {
+ prev_end = _update_info.at(_update_info.length() - 2) + _update_info.at(_update_info.length() - 1);
+ }
+
+ if (prev_end == offset) {
+ (*_update_info.adr_at(_update_info.length() - 2)) += size;
+ } else {
+ _update_info.append(size);
+ _update_info.append(offset);
+ }
+
+ _position += size;
+ }
+ };
+
+ InstanceKlass* ik = InstanceKlass::cast(new_version);
+ InstanceKlass* old_ik = InstanceKlass::cast(new_version->old_version());
+ CalculateFieldUpdates cl(old_ik);
+ ik->do_nonstatic_fields(&cl);
+
+ GrowableArray<int> result = cl.finish();
+ ik->store_update_information(result);
+ ik->set_copying_backwards(cl.does_copy_backwards());
+
+
+ if (RC_TRACE_ENABLED(0x00000001)) {
+ RC_TRACE(0x00000001, ("Instance update information for %s:", new_version->name()->as_C_string()));
+ if (cl.does_copy_backwards()) {
+ RC_TRACE(0x00000001, ("\tDoes copy backwards!"));
+ }
+ for (int i=0; i<result.length(); i++) {
+ int curNum = result.at(i);
+ if (curNum < 0) {
+ RC_TRACE(0x00000001, ("\t%d CLEAN", curNum));
+ } else if (curNum > 0) {
+ RC_TRACE(0x00000001, ("\t%d COPY from %d", curNum, result.at(i + 1)));
+ i++;
+ } else {
+ RC_TRACE(0x00000001, ("\tEND"));
+ }
+ }
+ }
+}
+
+void VM_EnhancedRedefineClasses::rollback() {
+ RC_TRACE(0x00000001, ("Rolling back redefinition!"));
+ SystemDictionary::rollback_redefinition();
+
+ for (int i=0; i<_new_classes->length(); i++) {
+ SystemDictionary::remove_from_hierarchy(_new_classes->at(i));
+ }
+
+ for (int i=0; i<_new_classes->length(); i++) {
+ instanceKlassHandle new_class = _new_classes->at(i);
+ new_class->set_redefining(false);
+ new_class->old_version()->set_new_version(NULL);
+ new_class->set_old_version(NULL);
+ }
+
+}
+
+void VM_EnhancedRedefineClasses::swap_marks(oop first, oop second) {
+ markOop first_mark = first->mark();
+ markOop second_mark = second->mark();
+ first->set_mark(second_mark);
+ second->set_mark(first_mark);
+}
+
+class FieldCopier : public FieldClosure {
+ public:
+ void do_field(fieldDescriptor* fd) {
+ InstanceKlass* cur = InstanceKlass::cast(fd->field_holder());
+ oop cur_oop = cur->java_mirror();
+
+ InstanceKlass* old = InstanceKlass::cast(cur->old_version());
+ oop old_oop = old->java_mirror();
+
+ fieldDescriptor result;
+ bool found = old->find_local_field(fd->name(), fd->signature(), &result);
+ if (found && result.is_static()) {
+ RC_TRACE(0x00000001, ("Copying static field value for field %s old_offset=%d new_offset=%d",
+ fd->name()->as_C_string(), result.offset(), fd->offset()));
+ memcpy(cur_oop->obj_field_addr<HeapWord>(fd->offset()),
+ old_oop->obj_field_addr<HeapWord>(result.offset()),
+ type2aelembytes(fd->field_type()));
+
+ // Static fields may have references to java.lang.Class
+ if (fd->field_type() == T_OBJECT) {
+ oop oop = cur_oop->obj_field(fd->offset());
+ if (oop != NULL && oop->is_instanceMirror()) {
+ Klass* klass = java_lang_Class::as_Klass(oop);
+ if (klass != NULL && klass->oop_is_instance()) {
+ assert(oop == InstanceKlass::cast(klass)->java_mirror(), "just checking");
+ if (klass->new_version() != NULL) {
+ oop = InstanceKlass::cast(klass->new_version())->java_mirror();
+ cur_oop->obj_field_put(fd->offset(), oop);
+ }
+ }
+ }
+ }
+ }
+ }
+};
+
+void VM_EnhancedRedefineClasses::mark_as_scavengable(nmethod* nm) {
+ if (!nm->on_scavenge_root_list()) {
+ CodeCache::add_scavenge_root_nmethod(nm);
+ }
+}
+
+struct StoreBarrier {
+ template <class T> static void oop_store(T* p, oop v) { ::oop_store(p, v); }
+};
+
+struct StoreNoBarrier {
+ template <class T> static void oop_store(T* p, oop v) { oopDesc::encode_store_heap_oop_not_null(p, v); }
+};
+
+template <class S>
+class ChangePointersOopClosure : public ExtendedOopClosure {
+ // import java_lang_invoke_MemberName.*
+ enum {
+ REFERENCE_KIND_SHIFT = java_lang_invoke_MemberName::MN_REFERENCE_KIND_SHIFT,
+ REFERENCE_KIND_MASK = java_lang_invoke_MemberName::MN_REFERENCE_KIND_MASK,
+ };
+
+
+ bool update_member_name(oop obj) {
+ int flags = java_lang_invoke_MemberName::flags(obj);
+ int ref_kind = (flags >> REFERENCE_KIND_SHIFT) & REFERENCE_KIND_MASK;
+ if (MethodHandles::ref_kind_is_method(ref_kind)) {
+ Method* m = (Method*) java_lang_invoke_MemberName::vmtarget(obj);
+ if (m != NULL && !m->method_holder()->is_newest_version()) {
+ // Let's try to re-resolve method
+ InstanceKlass* newest = InstanceKlass::cast(m->method_holder()->newest_version());
+ Method* new_method = newest->find_method(m->name(), m->signature());
+
+ // Note: we might set NULL at this point, which should force AbstractMethodError at runtime
+ java_lang_invoke_MemberName::set_vmtarget(obj, new_method);
+ }
+ } else if (MethodHandles::ref_kind_is_field(ref_kind)) {
+ Klass* k = (Klass*) java_lang_invoke_MemberName::vmtarget(obj);
+ if (k == NULL) {
+ return false; // Was cleared before, this MemberName is invalid.
+ }
+
+ if (k != NULL && !k->is_newest_version()) {
+ // Let's try to re-resolve field
+ fieldDescriptor fd;
+ int offset = java_lang_invoke_MemberName::vmindex(obj);
+ bool is_static = MethodHandles::ref_kind_is_static(ref_kind);
+ InstanceKlass* ik = InstanceKlass::cast(k);
+ if (ik->find_local_field_from_offset(offset, is_static, &fd)) {
+ InstanceKlass* newest = InstanceKlass::cast(k->newest_version());
+ fieldDescriptor fd_new;
+ if (newest->find_local_field(fd.name(), fd.signature(), &fd_new)) {
+ java_lang_invoke_MemberName::set_vmtarget(obj, newest);
+ java_lang_invoke_MemberName::set_vmindex(obj, fd_new.offset());
+ } else {
+ // Matching field is not found in new version, not much we can do here.
+ // JVM will crash once faulty MH is invoked.
+ // However, to avoid that all DMH's using this faulty MH are cleared (set to NULL)
+ // Eventually, we probably want to replace them with something more meaningful,
+ // like instance throwing NoSuchFieldError or DMH that will resort to dynamic
+ // field resolution (with possibility of type conversion)
+ java_lang_invoke_MemberName::set_vmtarget(obj, NULL);
+ java_lang_invoke_MemberName::set_vmindex(obj, 0);
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+ }
+
+ bool update_direct_method_handle(oop obj) {
+ // Always update member name first.
+ oop mem_name = java_lang_invoke_DirectMethodHandle::member(obj);
+ if (!update_member_name(mem_name)) {
+ return false;
+ }
+
+ // Here we rely on DirectMethodHandle implementation.
+ // The current implementation caches field offset in $StaticAccessor/$Accessor
+ int flags = java_lang_invoke_MemberName::flags(mem_name);
+ int ref_kind = (flags >> REFERENCE_KIND_SHIFT) & REFERENCE_KIND_MASK;
+ if (MethodHandles::ref_kind_is_field(ref_kind)) {
+ // Note: we don't care about staticBase field (which is java.lang.Class)
+ // It should be processed during normal object update.
+ // Update offset in StaticAccessor
+ int offset = java_lang_invoke_MemberName::vmindex(mem_name);
+ if (offset != 0) { // index of 0 means that field no longer exist
+ if (java_lang_invoke_DirectMethodHandle_StaticAccessor::is_instance(obj)) {
+ java_lang_invoke_DirectMethodHandle_StaticAccessor::set_static_offset(obj, offset);
+ } else if (java_lang_invoke_DirectMethodHandle_Accessor::is_instance(obj)) {
+ java_lang_invoke_DirectMethodHandle_Accessor::set_field_offset(obj, offset);
+ }
+ }
+ }
+ return true;
+ }
+
+ // Forward pointers to InstanceKlass and mirror class to new versions
+ template <class T>
+ inline void do_oop_work(T* p) {
+ oop obj = oopDesc::load_decode_heap_oop(p);
+ if (obj == NULL) {
+ return;
+ }
+ if (obj->is_instanceMirror()) {
+ Klass* klass = java_lang_Class::as_Klass(obj);
+ if (klass != NULL && klass->oop_is_instance()) {
+ assert(obj == InstanceKlass::cast(klass)->java_mirror(), "just checking");
+ if (klass->new_version() != NULL) {
+ obj = InstanceKlass::cast(klass->new_version())->java_mirror();
+ S::oop_store(p, obj);
+ }
+ }
+ }
+
+ // JSR 292 support, uptade java.lang.invoke.MemberName instances
+ if (java_lang_invoke_MemberName::is_instance(obj)) {
+ update_member_name(obj);
+ } else if (java_lang_invoke_DirectMethodHandle::is_instance(obj)) {
+ if (!update_direct_method_handle(obj)) {
+ // DMH is no longer valid, replace it with null reference.
+ // See note above. We probably want to replace this with something more meaningful.
+ S::oop_store(p, NULL);
+ }
+ }
+ }
+
+ virtual void do_oop(oop* o) {
+ do_oop_work(o);
+ }
+
+ virtual void do_oop(narrowOop* o) {
+ do_oop_work(o);
+ }
+};
+
+void VM_EnhancedRedefineClasses::doit() {
+
+ Thread *thread = Thread::current();
+
+ assert((_max_redefinition_flags & Klass::RemoveSuperType) == 0, "removing super types not allowed");
+
+ if (UseSharedSpaces) {
+ // Sharing is enabled so we remap the shared readonly space to
+ // shared readwrite, private just in case we need to redefine
+ // a shared class. We do the remap during the doit() phase of
+ // the safepoint to be safer.
+ if (!MetaspaceShared::remap_shared_readonly_as_readwrite()) {
+ RC_TRACE(0x00000001,
+ ("failed to remap shared readonly space to readwrite, private"));
+ _result = JVMTI_ERROR_INTERNAL;
+ return;
+ }
+ }
+
+ RC_TIMER_START(_timer_prepare_redefinition);
+ for (int i = 0; i < _new_classes->length(); i++) {
+ redefine_single_class(_new_classes->at(i), thread);
+ }
+
+ // Deoptimize all compiled code that depends on this class
+ flush_dependent_code(instanceKlassHandle(Thread::current(), (Klass*)NULL), Thread::current());
+
+ // Adjust constantpool caches for all classes
+ // that reference methods of the evolved class.
+ ClearCpoolCacheAndUnpatch clear_cpool_cache(Thread::current());
+ ClassLoaderDataGraph::classes_do(&clear_cpool_cache);
+
+ RC_TIMER_STOP(_timer_prepare_redefinition);
+ RC_TIMER_START(_timer_heap_iteration);
+
+ class ChangePointersObjectClosure : public ObjectClosure {
+ private:
+
+ OopClosure *_closure;
+ bool _needs_instance_update;
+ oop _tmp_obj;
+ int _tmp_obj_size;
+
+ public:
+ ChangePointersObjectClosure(OopClosure *closure) : _closure(closure), _needs_instance_update(false), _tmp_obj(NULL), _tmp_obj_size(0) {}
+
+ bool needs_instance_update() {
+ return _needs_instance_update;
+ }
+
+ void copy_to_tmp(oop o) {
+ int size = o->size();
+ if (_tmp_obj_size < size) {
+ _tmp_obj_size = size;
+ _tmp_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
+ }
+ Copy::aligned_disjoint_words((HeapWord*)o, (HeapWord*)_tmp_obj, size);
+ }
+
+ virtual void do_object(oop obj) {
+ // FIXME: if (obj->is_instanceKlass()) return;
+ if (obj->is_instanceMirror()) {
+ // static fields may have references to old java.lang.Class instances, update them
+ // at the same time, we don't want to update other oops in the java.lang.Class
+ // Causes SIGSEGV?
+ //instanceMirrorKlass::oop_fields_iterate(obj, _closure);
+ } else {
+ obj->oop_iterate_no_header(_closure);
+ }
+
+ if (obj->klass()->new_version() != NULL) {
+ Klass* new_klass = obj->klass()->new_version();
+ /* FIXME: if (obj->is_perm()) {
+ _needs_instance_update = true;
+ } else */if(new_klass->update_information() != NULL) {
+ int size_diff = obj->size() - obj->size_given_klass(new_klass);
+
+ // Either new size is bigger or gap is to small to be filled
+ if (size_diff < 0 || (size_diff > 0 && (size_t) size_diff < CollectedHeap::min_fill_size())) {
+ // We need an instance update => set back to old klass
+ _needs_instance_update = true;
+ } else {
+ oop src = obj;
+ if (new_klass->is_copying_backwards()) {
+ copy_to_tmp(obj);
+ src = _tmp_obj;
+ }
+ src->set_klass(obj->klass()->new_version());
+ MarkSweep::update_fields(obj, src, new_klass->update_information());
+
+ if (size_diff > 0) {
+ HeapWord* dead_space = ((HeapWord *)obj) + obj->size();
+ CollectedHeap::fill_with_object(dead_space, size_diff);
+ }
+ }
+ } else {
+ obj->set_klass(obj->klass()->new_version());
+ }
+ }
+ }
+ };
+
+ ChangePointersOopClosure<StoreNoBarrier> oopClosureNoBarrier;
+ ChangePointersOopClosure<StoreBarrier> oopClosure;
+ ChangePointersObjectClosure objectClosure(&oopClosure);
+
+ RC_TRACE(0x00000001, ("Before updating instances"));
+ {
+ // Since we may update oops inside nmethod's code blob to point to java.lang.Class in new generation, we need to
+ // make sure such references are properly recognized by GC. For that, If ScavengeRootsInCode is true, we need to
+ // mark such nmethod's as "scavengable".
+ // For now, mark all nmethod's as scavengable that are not scavengable already
+ if (ScavengeRootsInCode) {
+ CodeCache::nmethods_do(mark_as_scavengable);
+ }
+
+ SharedHeap::heap()->gc_prologue(true);
+ Universe::heap()->object_iterate(&objectClosure);
+ Universe::root_oops_do(&oopClosureNoBarrier);
+ SharedHeap::heap()->gc_epilogue(false);
+ }
+ RC_TRACE(0x00000001, ("After updating instances"));
+
+ for (int i = 0; i < _new_classes->length(); i++) {
+ InstanceKlass* cur = InstanceKlass::cast(_new_classes->at(i)());
+ InstanceKlass* old = InstanceKlass::cast(cur->old_version());
+
+ // Swap marks to have same hashcodes
+ markOop cur_mark = cur->prototype_header();
+ markOop old_mark = old->prototype_header();
+ cur->set_prototype_header(old_mark);
+ old->set_prototype_header(cur_mark);
+
+ //swap_marks(cur, old);
+ swap_marks(cur->java_mirror(), old->java_mirror());
+
+ // Revert pool holder for old version of klass (it was updated by one of ours closure!)
+ old->constants()->set_pool_holder(old);
+
+ Klass* array_klasses = old->array_klasses();
+ if (array_klasses != NULL) {
+ assert(cur->array_klasses() == NULL, "just checking");
+
+ // Transfer the array classes, otherwise we might get cast exceptions when casting array types.
+ // Also, set array klasses element klass.
+ cur->set_array_klasses(array_klasses);
+ ObjArrayKlass::cast(array_klasses)->set_element_klass(cur);
+ }
+
+ // Initialize the new class! Special static initialization that does not execute the
+ // static constructor but copies static field values from the old class if name
+ // and signature of a static field match.
+ FieldCopier copier;
+ cur->do_local_static_fields(&copier); // TODO (tw): What about internal static fields??
+ //java_lang_Class::set_klass(old->java_mirror(), cur); // FIXME-isd: is that correct?
+ //FIXME-isd: do we need this: ??? old->set_java_mirror(cur->java_mirror());
+
+ // Transfer init state
+ InstanceKlass::ClassState state = old->init_state();
+ if (state > InstanceKlass::linked) {
+ cur->set_init_state(state);
+ }
+ }
+
+ RC_TIMER_STOP(_timer_heap_iteration);
+ RC_TIMER_START(_timer_redefinition);
+ if (objectClosure.needs_instance_update()) {
+ // Do a full garbage collection to update the instance sizes accordingly
+ RC_TRACE(0x00000001, ("Before performing full GC!"));
+ Universe::set_redefining_gc_run(true);
+ notify_gc_begin(true);
+ Universe::heap()->collect_as_vm_thread(GCCause::_heap_inspection);
+ notify_gc_end();
+ Universe::set_redefining_gc_run(false);
+ RC_TRACE(0x00000001, ("GC done!"));
+ }
+
+ // Unmark Klass*s as "redefining"
+ for (int i=0; i<_new_classes->length(); i++) {
+ Klass* cur_klass = _new_classes->at(i)();
+ InstanceKlass* cur = (InstanceKlass*)cur_klass;
+ cur->set_redefining(false);
+ cur->clear_update_information();
+ }
+
+ // Disable any dependent concurrent compilations
+ SystemDictionary::notice_modification();
+
+ // Set flag indicating that some invariants are no longer true.
+ // See jvmtiExport.hpp for detailed explanation.
+ JvmtiExport::set_has_redefined_a_class();
+
+ // Clean up caches in the compiler interface and compiler threads
+ ciObjectFactory::resort_shared_ci_metadata();
+
+#ifdef ASSERT
+
+ // Universe::verify();
+ // JNIHandles::verify();
+
+ SystemDictionary::classes_do(check_class, thread);
+#endif
+
+ RC_TIMER_STOP(_timer_redefinition);
+
+ if (TraceRedefineClasses > 0) {
+ tty->flush();
+ }
+}
+
+void VM_EnhancedRedefineClasses::doit_epilogue() {
+
+ RC_TIMER_START(_timer_vm_op_epilogue);
+
+ ResourceMark mark;
+
+ VM_GC_Operation::doit_epilogue();
+ RC_TRACE(0x00000001, ("GC Operation epilogue finished!"));
+
+ // Free the array of scratch classes
+ delete _new_classes;
+ _new_classes = NULL;
+
+ // Free the array of affected classes
+ delete _affected_klasses;
+ _affected_klasses = NULL;
+
+ RC_TRACE(0x00000001, ("Redefinition finished!"));
+
+ RC_TIMER_STOP(_timer_vm_op_epilogue);
+}
+
+bool VM_EnhancedRedefineClasses::is_modifiable_class(oop klass_mirror) {
+ // classes for primitives cannot be redefined
+ if (java_lang_Class::is_primitive(klass_mirror)) {
+ return false;
+ }
+ Klass* klass = java_lang_Class::as_Klass(klass_mirror);
+ // classes for arrays cannot be redefined
+ if (klass == NULL || !klass->oop_is_instance()) {
+ return false;
+ }
+ return true;
+}
+
+#ifdef ASSERT
+
+void VM_EnhancedRedefineClasses::verify_classes(Klass* k_oop_latest, oop initiating_loader, TRAPS) {
+ Klass* k_oop = k_oop_latest;
+ while (k_oop != NULL) {
+
+ instanceKlassHandle k_handle(THREAD, k_oop);
+ Verifier::verify(k_handle, Verifier::ThrowException, true, THREAD);
+ k_oop = k_oop->old_version();
+ }
+}
+
+#endif
+
+// Rewrite faster byte-codes back to their slower equivalent. Undoes rewriting happening in templateTable_xxx.cpp
+// The reason is that once we zero cpool caches, we need to re-resolve all entries again. Faster bytecodes do not
+// do that, they assume that cache entry is resolved already.
+void VM_EnhancedRedefineClasses::unpatch_bytecode(Method* method) {
+ RawBytecodeStream bcs(method);
+ Bytecodes::Code code;
+ Bytecodes::Code java_code;
+ while (!bcs.is_last_bytecode()) {
+ code = bcs.raw_next();
+ address bcp = bcs.bcp();
+
+ if (code == Bytecodes::_breakpoint) {
+ int bci = method->bci_from(bcp);
+ code = method->orig_bytecode_at(bci);
+ java_code = Bytecodes::java_code(code);
+ if (code != java_code &&
+ (java_code == Bytecodes::_getfield ||
+ java_code == Bytecodes::_putfield ||
+ java_code == Bytecodes::_aload_0)) {
+ // Let breakpoint table handling unpatch bytecode
+ method->set_orig_bytecode_at(bci, java_code);
+ }
+ } else {
+ java_code = Bytecodes::java_code(code);
+ if (code != java_code &&
+ (java_code == Bytecodes::_getfield ||
+ java_code == Bytecodes::_putfield ||
+ java_code == Bytecodes::_aload_0)) {
+ *bcp = java_code;
+ }
+ }
+
+ // Additionally, we need to unpatch bytecode at bcp+1 for fast_xaccess (which would be fast field access)
+ if (code == Bytecodes::_fast_iaccess_0 || code == Bytecodes::_fast_aaccess_0 || code == Bytecodes::_fast_faccess_0) {
+ Bytecodes::Code code2 = Bytecodes::code_or_bp_at(bcp + 1);
+ assert(code2 == Bytecodes::_fast_igetfield ||
+ code2 == Bytecodes::_fast_agetfield ||
+ code2 == Bytecodes::_fast_fgetfield, "");
+ *(bcp + 1) = Bytecodes::java_code(code2);
+ }
+ }
+ }
+
+// Unevolving classes may point to old methods directly
+// from their constant pool caches, itables, and/or vtables. We
+// use the SystemDictionary::classes_do() facility and this helper
+// to fix up these pointers. Additional field offsets and vtable indices
+// in the constant pool cache entries are fixed.
+//
+// Note: We currently don't support updating the vtable in
+// arrayKlassOops. See Open Issues in jvmtiRedefineClasses.hpp.
+void VM_EnhancedRedefineClasses::ClearCpoolCacheAndUnpatch::do_klass(Klass* klass) {
+ if (!klass->oop_is_instance()) {
+ return;
+ }
+ HandleMark hm(_thread);
+ InstanceKlass *ik = InstanceKlass::cast(klass);
+ constantPoolHandle other_cp = constantPoolHandle(ik->constants());
+
+ // Update host klass of anonymous classes (for example, produced by lambdas) to newest version.
+ if (ik->is_anonymous() && !ik->host_klass()->is_newest_version()) {
+ ik->set_host_klass(ik->host_klass()->newest_version());
+ }
+
+ for (int i = 0; i < other_cp->length(); i++) {
+ if (other_cp->tag_at(i).is_klass()) {
+ Klass* klass = other_cp->klass_at(i, _thread);
+ if (klass->new_version() != NULL) {
+ // (DCEVM) TODO: check why/if this is necessary
+ other_cp->klass_at_put(i, klass->new_version());
+ }
+ klass = other_cp->klass_at(i, _thread);
+ assert(klass->new_version() == NULL, "Must be new klass!");
+ }
+ }
+
+ ConstantPoolCache* cp_cache = other_cp->cache();
+ if (cp_cache != NULL) {
+ cp_cache->clear_entries();
+ }
+
+ // If bytecode rewriting is enabled, we also need to unpatch bytecode to force resolution of zeroed entries
+ if (RewriteBytecodes) {
+ ik->methods_do(unpatch_bytecode);
+ }
+}
+
+void VM_EnhancedRedefineClasses::update_jmethod_ids() {
+ for (int j = 0; j < _matching_methods_length; ++j) {
+ Method* old_method = _old_methods->at(_matching_old_methods[j]);
+ jmethodID jmid = old_method->find_jmethod_id_or_null();
+ RC_TRACE(0x00008000, ("matching method %s, jmid %d", old_method->name_and_sig_as_C_string(), jmid));
+ if (old_method->new_version() != NULL && jmid == NULL) {
+ // (DCEVM) Have to create jmethodID in this case
+ jmid = old_method->jmethod_id();
+ }
+
+ if (jmid != NULL) {
+ // There is a jmethodID, change it to point to the new method
+ methodHandle new_method_h(_new_methods->at(_matching_new_methods[j]));
+ if (old_method->new_version() == NULL) {
+ methodHandle old_method_h(_old_methods->at(_matching_old_methods[j]));
+ jmethodID new_jmethod_id = Method::make_jmethod_id(old_method_h->method_holder()->class_loader_data(), old_method_h());
+ bool result = InstanceKlass::cast(old_method_h->method_holder())->update_jmethod_id(old_method_h(), new_jmethod_id);
+ } else {
+ jmethodID mid = new_method_h->jmethod_id();
+ bool result = InstanceKlass::cast(new_method_h->method_holder())->update_jmethod_id(new_method_h(), jmid);
+ }
+ Method::change_method_associated_with_jmethod_id(jmid, new_method_h());
+ assert(Method::resolve_jmethod_id(jmid) == _new_methods->at(_matching_new_methods[j]), "should be replaced");
+ jmethodID mid = (_new_methods->at(_matching_new_methods[j]))->jmethod_id();
+ //assert(JNIHandles::resolve_non_null((jobject)mid) == new_method_h(), "must match!");
+ }
+ }
+}
+
+
+// Deoptimize all compiled code that depends on this class.
+//
+// If the can_redefine_classes capability is obtained in the onload
+// phase then the compiler has recorded all dependencies from startup.
+// In that case we need only deoptimize and throw away all compiled code
+// that depends on the class.
+//
+// If can_redefine_classes is obtained sometime after the onload
+// phase then the dependency information may be incomplete. In that case
+// the first call to RedefineClasses causes all compiled code to be
+// thrown away. As can_redefine_classes has been obtained then
+// all future compilations will record dependencies so second and
+// subsequent calls to RedefineClasses need only throw away code
+// that depends on the class.
+//
+void VM_EnhancedRedefineClasses::flush_dependent_code(instanceKlassHandle k_h, TRAPS) {
+ assert_locked_or_safepoint(Compile_lock);
+
+ // All dependencies have been recorded from startup or this is a second or
+ // subsequent use of RedefineClasses
+
+ // For now deopt all
+ // (tw) TODO: Improve the dependency system such that we can safely deopt only a subset of the methods
+ if (0 && JvmtiExport::all_dependencies_are_recorded()) {
+ Universe::flush_evol_dependents_on(k_h);
+ } else {
+ CodeCache::mark_all_nmethods_for_deoptimization();
+
+ ResourceMark rm(THREAD);
+ DeoptimizationMarker dm;
+
+ // Deoptimize all activations depending on marked nmethods
+ Deoptimization::deoptimize_dependents();
+
+ // Make the dependent methods not entrant (in VM_Deoptimize they are made zombies)
+ CodeCache::make_marked_nmethods_not_entrant();
+
+ // From now on we know that the dependency information is complete
+ JvmtiExport::set_all_dependencies_are_recorded(true);
+ }
+ }
+
+void VM_EnhancedRedefineClasses::compute_added_deleted_matching_methods() {
+ Method* old_method;
+ Method* new_method;
+
+ _matching_old_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
+ _matching_new_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
+ _added_methods = NEW_RESOURCE_ARRAY(int, _new_methods->length());
+ _deleted_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
+
+ _matching_methods_length = 0;
+ _deleted_methods_length = 0;
+ _added_methods_length = 0;
+
+ int nj = 0;
+ int oj = 0;
+ while (true) {
+ if (oj >= _old_methods->length()) {
+ if (nj >= _new_methods->length()) {
+ break; // we've looked at everything, done
+ }
+ // New method at the end
+ new_method = _new_methods->at(nj);
+ _added_methods[_added_methods_length++] = nj;
+ ++nj;
+ } else if (nj >= _new_methods->length()) {
+ // Old method, at the end, is deleted
+ old_method = _old_methods->at(oj);
+ _deleted_methods[_deleted_methods_length++] = oj;
+ ++oj;
+ } else {
+ old_method = _old_methods->at(oj);
+ new_method = _new_methods->at(nj);
+ if (old_method->name() == new_method->name()) {
+ if (old_method->signature() == new_method->signature()) {
+ _matching_old_methods[_matching_methods_length] = oj;//old_method;
+ _matching_new_methods[_matching_methods_length] = nj;//new_method;
+ _matching_methods_length++;
+ ++nj;
+ ++oj;
+ } else {
+ // added overloaded have already been moved to the end,
+ // so this is a deleted overloaded method
+ _deleted_methods[_deleted_methods_length++] = oj;//old_method;
+ ++oj;
+ }
+ } else { // names don't match
+ if (old_method->name()->fast_compare(new_method->name()) > 0) {
+ // new method
+ _added_methods[_added_methods_length++] = nj;//new_method;
+ ++nj;
+ } else {
+ // deleted method
+ _deleted_methods[_deleted_methods_length++] = oj;//old_method;
+ ++oj;
+ }
+ }
+ }
+ }
+ assert(_matching_methods_length + _deleted_methods_length == _old_methods->length(), "sanity");
+ assert(_matching_methods_length + _added_methods_length == _new_methods->length(), "sanity");
+ RC_TRACE(0x00008000, ("Matching methods = %d / deleted methods = %d / added methods = %d",
+ _matching_methods_length, _deleted_methods_length, _added_methods_length));
+}
+
+
+
+// Install the redefinition of a class:
+// - house keeping (flushing breakpoints and caches, deoptimizing
+// dependent compiled code)
+// - adjusting constant pool caches and vtables in other classes
+void VM_EnhancedRedefineClasses::redefine_single_class(instanceKlassHandle the_new_class, TRAPS) {
+
+ ResourceMark rm(THREAD);
+
+ assert(the_new_class->old_version() != NULL, "Must not be null");
+ assert(the_new_class->old_version()->new_version() == the_new_class(), "Must equal");
+
+ instanceKlassHandle the_old_class = instanceKlassHandle(THREAD, the_new_class->old_version());
+
+#ifndef JVMTI_KERNEL
+ // Remove all breakpoints in methods of this class
+ JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints();
+ jvmti_breakpoints.clearall_in_class_at_safepoint(the_old_class());
+#endif // !JVMTI_KERNEL
+
+ /* FIXME
+ if (the_old_class() == Universe::reflect_invoke_cache()->klass()) {
+ // We are redefining java.lang.reflect.Method. Method.invoke() is
+ // cached and users of the cache care about each active version of
+ // the method so we have to track this previous version.
+ // Do this before methods get switched
+ Universe::reflect_invoke_cache()->add_previous_version(
+ the_old_class->method_with_idnum(Universe::reflect_invoke_cache()->method_idnum()));
+ }*/
+
+ _old_methods = the_old_class->methods();
+ _new_methods = the_new_class->methods();
+ compute_added_deleted_matching_methods();
+
+ // track which methods are EMCP for add_previous_version() call below
+
+ // TODO: Check if we need the concept of EMCP?
+ BitMap emcp_methods(_old_methods->length());
+ int emcp_method_count = 0;
+ emcp_methods.clear(); // clears 0..(length() - 1)
+
+ // We need to mark methods as old!!
+ check_methods_and_mark_as_obsolete(&emcp_methods, &emcp_method_count);
+ update_jmethod_ids();
+
+ // TODO:
+ transfer_old_native_function_registrations(the_old_class);
+
+
+ // JSR-292 support
+
+ // Swap method handles
+ MemberNameTable* mnt = the_old_class->member_names();
+ assert(the_new_class->member_names() == NULL, "");
+ the_new_class->set_member_names(mnt);
+ the_old_class->set_member_names(NULL);
+
+ // FIXME: should we add field MemberName's in this list and process all of them here?
+// if (mnt != NULL) {
+// for (int i = 0; i < mnt->length(); i++) {
+// oop mem_name = mnt->get_member_name(i);
+// if (mem_name != NULL) {
+// Method* method = (Method*) java_lang_invoke_MemberName::vmtarget(mem_name);
+//
+// // Replace the method with matching one from the new class
+// Method* new_method = the_new_class->find_method(method->name(), method->signature());
+// java_lang_invoke_MemberName::set_vmtarget(mem_name, new_method);
+// }
+// }
+// }
+
+#ifdef ASSERT
+
+// Klass* systemLookup1 = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
+// assert(systemLookup1 == the_new_class(), "New class must be in system dictionary!");
+
+ //JNIHandles::verify();
+
+// Klass* systemLookup = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
+
+// assert(systemLookup == the_new_class(), "New class must be in system dictionary!");
+ assert(the_new_class->old_version() != NULL, "Must not be null");
+ assert(the_new_class->old_version()->new_version() == the_new_class(), "Must equal");
+
+ for (int i=0; i<the_new_class->methods()->length(); i++) {
+ assert((the_new_class->methods()->at(i))->method_holder() == the_new_class(), "method holder must match!");
+ }
+
+ // FIXME:
+ //_old_methods->verify();
+ //_new_methods->verify();
+
+ the_new_class->vtable()->verify(tty);
+ the_old_class->vtable()->verify(tty);
+
+#endif
+
+ // increment the classRedefinedCount field in the_class and in any
+ // direct and indirect subclasses of the_class
+ increment_class_counter((InstanceKlass *)the_old_class(), THREAD);
+
+}
+
+
+void VM_EnhancedRedefineClasses::check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p) {
+ RC_TRACE(0x00000100, ("Checking matching methods for EMCP"));
+ *emcp_method_count_p = 0;
+ int obsolete_count = 0;
+ int old_index = 0;
+ for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
+ Method* old_method = _old_methods->at(_matching_old_methods[j]);
+ Method* new_method = _new_methods->at(_matching_new_methods[j]);
+ Method* old_array_method;
+
+ // Maintain an old_index into the _old_methods array by skipping
+ // deleted methods
+ while ((old_array_method = _old_methods->at(old_index)) != old_method) {
+ ++old_index;
+ }
+
+ if (MethodComparator::methods_EMCP(old_method, new_method)) {
+ // The EMCP definition from JSR-163 requires the bytecodes to be
+ // the same with the exception of constant pool indices which may
+ // differ. However, the constants referred to by those indices
+ // must be the same.
+ //
+ // We use methods_EMCP() for comparison since constant pool
+ // merging can remove duplicate constant pool entries that were
+ // present in the old method and removed from the rewritten new
+ // method. A faster binary comparison function would consider the
+ // old and new methods to be different when they are actually
+ // EMCP.
+
+ // track which methods are EMCP for add_previous_version() call
+ emcp_methods->set_bit(old_index);
+ (*emcp_method_count_p)++;
+
+ // An EMCP method is _not_ obsolete. An obsolete method has a
+ // different jmethodID than the current method. An EMCP method
+ // has the same jmethodID as the current method. Having the
+ // same jmethodID for all EMCP versions of a method allows for
+ // a consistent view of the EMCP methods regardless of which
+ // EMCP method you happen to have in hand. For example, a
+ // breakpoint set in one EMCP method will work for all EMCP
+ // versions of the method including the current one.
+
+ old_method->set_new_version(new_method);
+ new_method->set_old_version(old_method);
+
+ RC_TRACE(0x00000100, ("Found EMCP method %s", old_method->name_and_sig_as_C_string()));
+
+ // Transfer breakpoints
+ InstanceKlass *ik = InstanceKlass::cast(old_method->method_holder());
+ for (BreakpointInfo* bp = ik->breakpoints(); bp != NULL; bp = bp->next()) {
+ RC_TRACE(0x00000100, ("Checking breakpoint: %d / %d",
+ bp->match(old_method), bp->match(new_method)));
+ if (bp->match(old_method)) {
+ assert(bp->match(new_method), "if old method is method, then new method must match too");
+ RC_TRACE(0x00000100, ("Found a breakpoint in an old EMCP method"));
+ new_method->set_breakpoint(bp->bci());
+ }
+ }
+ } else {
+ // mark obsolete methods as such
+ old_method->set_is_obsolete();
+ obsolete_count++;
+
+ // With tracing we try not to "yack" too much. The position of
+ // this trace assumes there are fewer obsolete methods than
+ // EMCP methods.
+ RC_TRACE(0x00000100, ("mark %s(%s) as obsolete",
+ old_method->name()->as_C_string(),
+ old_method->signature()->as_C_string()));
+ }
+ old_method->set_is_old();
+ }
+ for (int i = 0; i < _deleted_methods_length; ++i) {
+ Method* old_method = _old_methods->at(_deleted_methods[i]);
+
+ //assert(old_method->vtable_index() < 0,
+ // "cannot delete methods with vtable entries");;
+
+ // Mark all deleted methods as old and obsolete
+ old_method->set_is_old();
+ old_method->set_is_obsolete();
+ ++obsolete_count;
+ // With tracing we try not to "yack" too much. The position of
+ // this trace assumes there are fewer obsolete methods than
+ // EMCP methods.
+ RC_TRACE(0x00000100, ("mark deleted %s(%s) as obsolete",
+ old_method->name()->as_C_string(),
+ old_method->signature()->as_C_string()));
+ }
+ //assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(), "sanity check");
+ RC_TRACE(0x00000100, ("EMCP_cnt=%d, obsolete_cnt=%d !",
+ *emcp_method_count_p, obsolete_count));
+}
+
+// Increment the classRedefinedCount field in the specific InstanceKlass
+// and in all direct and indirect subclasses.
+void VM_EnhancedRedefineClasses::increment_class_counter(Klass* klass, TRAPS) {
+ oop class_mirror = klass->java_mirror();
+ int new_count = java_lang_Class::classRedefinedCount(class_mirror) + 1;
+ java_lang_Class::set_classRedefinedCount(class_mirror, new_count);
+ RC_TRACE(0x00000008, ("updated count for class=%s to %d", klass->external_name(), new_count));
+}
+
+#ifndef PRODUCT
+void VM_EnhancedRedefineClasses::check_class(Klass* k_oop, TRAPS) {
+ Klass *k = k_oop;
+ if (k->oop_is_instance()) {
+ HandleMark hm(THREAD);
+ InstanceKlass *ik = (InstanceKlass *) k;
+ assert(ik->is_newest_version(), "must be latest version in system dictionary");
+
+ if (ik->vtable_length() > 0) {
+ ResourceMark rm(THREAD);
+ assert(ik->vtable()->check_no_old_or_obsolete_entries(), "old method found");
+ ik->vtable()->verify(tty, true);
+ }
+ }
+}
+
+#endif
+
+static bool match_second(void* value, Pair<Klass*, Klass*> elem) {
+ return elem.second == value;
+}
+
+jvmtiError VM_EnhancedRedefineClasses::do_topological_class_sorting( const jvmtiClassDefinition *class_defs, int class_count, TRAPS) {
+ ResourceMark mark(THREAD);
+ GrowableArray<Pair<Klass*, Klass*> > links;
+
+ for (int i=0; i<class_count; i++) {
+
+ oop mirror = JNIHandles::resolve_non_null(class_defs[i].klass);
+ instanceKlassHandle the_class(THREAD, java_lang_Class::as_Klass(mirror));
+ Handle the_class_loader(THREAD, the_class->class_loader());
+ Handle protection_domain(THREAD, the_class->protection_domain());
+
+ ClassFileStream st((u1*) class_defs[i].class_bytes,
+ class_defs[i].class_byte_count, (char *)"__VM_EnhancedRedefineClasses__");
+ ClassFileParser cfp(&st);
+
+
+
+ TempNewSymbol parsed_name;
+ GrowableArray<Symbol*>* super_symbols = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<Symbol*>(0, true);
+ cfp.parseClassFile(the_class->name(),
+ the_class->class_loader_data(),
+ protection_domain,
+ the_class, KlassHandle(),
+ NULL,
+ super_symbols,
+ parsed_name,
+ false,
+ THREAD);
+
+ for (int j = 0; j < super_symbols->length(); j++) {
+ Symbol* sym = super_symbols->at(j);
+ Klass* super_klass = SystemDictionary::resolve_or_null(sym, the_class_loader, protection_domain, THREAD);
+ if (super_klass != NULL) {
+ instanceKlassHandle the_super_class(THREAD, super_klass);
+ if (_affected_klasses->contains(the_super_class)) {
+ links.append(Pair<Klass*, Klass*>(super_klass, the_class()));
+ }
+ }
+ }
+ delete super_symbols;
+
+ assert(the_class->check_redefinition_flag(Klass::MarkedAsAffected), "");
+ the_class->clear_redefinition_flag(Klass::MarkedAsAffected);
+ }
+
+ for (int i=0; i < _affected_klasses->length(); i++) {
+ instanceKlassHandle klass = _affected_klasses->at(i);
+
+ if (klass->check_redefinition_flag(Klass::MarkedAsAffected)) {
+ klass->clear_redefinition_flag(Klass::MarkedAsAffected);
+ Klass* superKlass = klass->super();
+ if (_affected_klasses->contains(superKlass)) {
+ links.append(Pair<Klass*, Klass*>(superKlass, klass()));
+ }
+
+ Array<Klass*>* superInterfaces = klass->local_interfaces();
+ for (int j=0; j<superInterfaces->length(); j++) {
+ Klass* interfaceKlass = superInterfaces->at(j);
+ if (_affected_klasses->contains(interfaceKlass)) {
+ links.append(Pair<Klass*, Klass*>(interfaceKlass, klass()));
+ }
+ }
+ }
+ }
+
+ for (int i = 0; i < _affected_klasses->length(); i++) {
+ int j;
+ for (j = i; j < _affected_klasses->length(); j++) {
+ // Search for node with no incoming edges
+ Klass* oop = _affected_klasses->at(j)();
+ int k = links.find(oop, match_second);
+ if (k == -1) break;
+ }
+ if (j == _affected_klasses->length()) {
+ return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
+ }
+
+ // Remove all links from this node
+ Klass* oop = _affected_klasses->at(j)();
+ int k = 0;
+ while (k < links.length()) {
+ if (links.adr_at(k)->first == oop) {
+ links.delete_at(k);
+ } else {
+ k++;
+ }
+ }
+
+ // Swap node
+ instanceKlassHandle tmp = _affected_klasses->at(j);
+ _affected_klasses->at_put(j, _affected_klasses->at(i));
+ _affected_klasses->at_put(i, tmp);
+ }
+
+ return JVMTI_ERROR_NONE;
+}
+
+// This internal class transfers the native function registration from old methods
+// to new methods. It is designed to handle both the simple case of unchanged
+// native methods and the complex cases of native method prefixes being added and/or
+// removed.
+// It expects only to be used during the VM_EnhancedRedefineClasses op (a safepoint).
+//
+// This class is used after the new methods have been installed in "the_class".
+//
+// So, for example, the following must be handled. Where 'm' is a method and
+// a number followed by an underscore is a prefix.
+//
+// Old Name New Name
+// Simple transfer to new method m -> m
+// Add prefix m -> 1_m
+// Remove prefix 1_m -> m
+// Simultaneous add of prefixes m -> 3_2_1_m
+// Simultaneous removal of prefixes 3_2_1_m -> m
+// Simultaneous add and remove 1_m -> 2_m
+// Same, caused by prefix removal only 3_2_1_m -> 3_2_m
+//
+class TransferNativeFunctionRegistration {
+ private:
+ instanceKlassHandle the_class;
+ int prefix_count;
+ char** prefixes;
+
+ // Recursively search the binary tree of possibly prefixed method names.
+ // Iteration could be used if all agents were well behaved. Full tree walk is
+ // more resilent to agents not cleaning up intermediate methods.
+ // Branch at each depth in the binary tree is:
+ // (1) without the prefix.
+ // (2) with the prefix.
+ // where 'prefix' is the prefix at that 'depth' (first prefix, second prefix,...)
+ Method* search_prefix_name_space(int depth, char* name_str, size_t name_len,
+ Symbol* signature) {
+ Symbol* name_symbol = SymbolTable::probe(name_str, (int)name_len);
+ if (name_symbol != NULL) {
+ Method* method = the_class()->new_version()->lookup_method(name_symbol, signature);
+ if (method != NULL) {
+ // Even if prefixed, intermediate methods must exist.
+ if (method->is_native()) {
+ // Wahoo, we found a (possibly prefixed) version of the method, return it.
+ return method;
+ }
+ if (depth < prefix_count) {
+ // Try applying further prefixes (other than this one).
+ method = search_prefix_name_space(depth+1, name_str, name_len, signature);
+ if (method != NULL) {
+ return method; // found
+ }
+
+ // Try adding this prefix to the method name and see if it matches
+ // another method name.
+ char* prefix = prefixes[depth];
+ size_t prefix_len = strlen(prefix);
+ size_t trial_len = name_len + prefix_len;
+ char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
+ strcpy(trial_name_str, prefix);
+ strcat(trial_name_str, name_str);
+ method = search_prefix_name_space(depth+1, trial_name_str, trial_len,
+ signature);
+ if (method != NULL) {
+ // If found along this branch, it was prefixed, mark as such
+ method->set_is_prefixed_native();
+ return method; // found
+ }
+ }
+ }
+ }
+ return NULL; // This whole branch bore nothing
+ }
+
+ // Return the method name with old prefixes stripped away.
+ char* method_name_without_prefixes(Method* method) {
+ Symbol* name = method->name();
+ char* name_str = name->as_utf8();
+
+ // Old prefixing may be defunct, strip prefixes, if any.
+ for (int i = prefix_count-1; i >= 0; i--) {
+ char* prefix = prefixes[i];
+ size_t prefix_len = strlen(prefix);
+ if (strncmp(prefix, name_str, prefix_len) == 0) {
+ name_str += prefix_len;
+ }
+ }
+ return name_str;
+ }
+
+ // Strip any prefixes off the old native method, then try to find a
+ // (possibly prefixed) new native that matches it.
+ Method* strip_and_search_for_new_native(Method* method) {
+ ResourceMark rm;
+ char* name_str = method_name_without_prefixes(method);
+ return search_prefix_name_space(0, name_str, strlen(name_str),
+ method->signature());
+ }
+
+ public:
+
+ // Construct a native method transfer processor for this class.
+ TransferNativeFunctionRegistration(instanceKlassHandle _the_class) {
+ assert(SafepointSynchronize::is_at_safepoint(), "sanity check");
+
+ the_class = _the_class;
+ prefixes = JvmtiExport::get_all_native_method_prefixes(&prefix_count);
+ }
+
+ // Attempt to transfer any of the old or deleted methods that are native
+ void transfer_registrations(instanceKlassHandle old_klass, int* old_methods, int methods_length) {
+ for (int j = 0; j < methods_length; j++) {
+ Method* old_method = old_klass->methods()->at(old_methods[j]);
+
+ if (old_method->is_native() && old_method->has_native_function()) {
+ Method* new_method = strip_and_search_for_new_native(old_method);
+ if (new_method != NULL) {
+ // Actually set the native function in the new method.
+ // Redefine does not send events (except CFLH), certainly not this
+ // behind the scenes re-registration.
+ new_method->set_native_function(old_method->native_function(),
+ !Method::native_bind_event_is_interesting);
+ }
+ }
+ }
+ }
+};
+
+// Don't lose the association between a native method and its JNI function.
+void VM_EnhancedRedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle old_klass) {
+ TransferNativeFunctionRegistration transfer(old_klass);
+ transfer.transfer_registrations(old_klass, _deleted_methods, _deleted_methods_length);
+ transfer.transfer_registrations(old_klass, _matching_old_methods, _matching_methods_length);
+}
diff --git a/src/share/vm/prims/jvmtiRedefineClasses2.hpp b/src/share/vm/prims/jvmtiRedefineClasses2.hpp
new file mode 100644
index 0000000..e2cfac4
--- /dev/null
+++ b/src/share/vm/prims/jvmtiRedefineClasses2.hpp
@@ -0,0 +1,161 @@
+/*
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef SHARE_VM_PRIMS_JVMTIENHANCEDREDEFINECLASSES_HPP
+#define SHARE_VM_PRIMS_JVMTIENHANCEDREDEFINECLASSES_HPP
+
+#include "jvmtifiles/jvmtiEnv.hpp"
+#include "memory/oopFactory.hpp"
+#include "memory/resourceArea.hpp"
+#include "oops/objArrayKlass.hpp"
+#include "oops/objArrayOop.hpp"
+#include "oops/fieldStreams.hpp"
+#include "prims/jvmtiRedefineClassesTrace.hpp"
+#include "gc_implementation/shared/vmGCOperations.hpp"
+
+// New version that allows arbitrary changes to already loaded classes.
+class VM_EnhancedRedefineClasses: public VM_GC_Operation {
+ private:
+
+ // These static fields are needed by SystemDictionary::classes_do()
+ // facility and the adjust_cpool_cache_and_vtable() helper:
+ static Array<Method*>* _old_methods;
+ static Array<Method*>* _new_methods;
+ static int* _matching_old_methods;
+ static int* _matching_new_methods;
+ static int* _deleted_methods;
+ static int* _added_methods;
+ static int _matching_methods_length;
+ static int _deleted_methods_length;
+ static int _added_methods_length;
+
+ static int _revision_number;
+
+ static GrowableArray<instanceKlassHandle>* _affected_klasses;
+
+ // The instance fields are used to pass information from
+ // doit_prologue() to doit() and doit_epilogue().
+ jint _class_count;
+ const jvmtiClassDefinition *_class_defs; // ptr to _class_count defs
+
+ // This operation is used by both RedefineClasses and
+ // RetransformClasses. Indicate which.
+ JvmtiClassLoadKind _class_load_kind;
+
+ GrowableArray<instanceKlassHandle>* _new_classes;
+ jvmtiError _result;
+ int _max_redefinition_flags;
+
+ // Performance measurement support. These timers do not cover all
+ // the work done for JVM/TI RedefineClasses() but they do cover
+ // the heavy lifting.
+ elapsedTimer _timer_total;
+ elapsedTimer _timer_prologue;
+ elapsedTimer _timer_class_linking;
+ elapsedTimer _timer_class_loading;
+ elapsedTimer _timer_prepare_redefinition;
+ elapsedTimer _timer_heap_iteration;
+ elapsedTimer _timer_redefinition;
+ elapsedTimer _timer_vm_op_epilogue;
+
+ jvmtiError find_sorted_affected_classes( );
+ jvmtiError find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed);
+ jvmtiError load_new_class_versions(TRAPS);
+
+ // Figure out which new methods match old methods in name and signature,
+ // which methods have been added, and which are no longer present
+ void compute_added_deleted_matching_methods();
+
+ // Change jmethodIDs to point to the new methods
+ void update_jmethod_ids();
+
+ void swap_all_method_annotations(ConstMethod* old_method, ConstMethod* new_method);
+
+ static void add_affected_klasses( Klass* obj );
+
+ static jvmtiError do_topological_class_sorting(const jvmtiClassDefinition *class_definitions, int class_count, TRAPS);
+
+ // Install the redefinition of a class
+ void redefine_single_class(instanceKlassHandle the_new_class, TRAPS);
+
+ // Increment the classRedefinedCount field in the specific instanceKlass
+ // and in all direct and indirect subclasses.
+ void increment_class_counter(Klass* klass, TRAPS);
+
+
+ void flush_dependent_code(instanceKlassHandle k_h, TRAPS);
+
+ static void check_class(Klass* k_oop,/* oop initiating_loader,*/ TRAPS) PRODUCT_RETURN;
+
+ static void unpatch_bytecode(Method* method);
+
+#ifdef ASSERT
+ static void verify_classes(Klass* k_oop, oop initiating_loader, TRAPS);
+#endif
+
+ int calculate_redefinition_flags(instanceKlassHandle new_version);
+ void calculate_instance_update_information(Klass* new_version);
+ void check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p);
+ static void mark_as_scavengable(nmethod* nm);
+
+ bool check_arguments();
+ jvmtiError check_arguments_error();
+
+ class ClearCpoolCacheAndUnpatch : public KlassClosure {
+ Thread* _thread;
+ public:
+ ClearCpoolCacheAndUnpatch(Thread* t) : _thread(t) {}
+ void do_klass(Klass* k);
+ };
+
+ public:
+ VM_EnhancedRedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind);
+ virtual ~VM_EnhancedRedefineClasses();
+
+ bool doit_prologue();
+ void doit();
+ void doit_epilogue();
+ void rollback();
+
+ jvmtiError check_exception() const;
+ VMOp_Type type() const { return VMOp_RedefineClasses; }
+ bool skip_operation() const { return false; }
+ bool allow_nested_vm_operations() const { return true; }
+ jvmtiError check_error() { return _result; }
+
+ // Modifiable test must be shared between IsModifiableClass query
+ // and redefine implementation
+ static bool is_modifiable_class(oop klass_mirror);
+
+ // Utility methods for transferring field access flags
+
+ static void transfer_special_access_flags(JavaFieldStream *from, JavaFieldStream *to);
+ static void transfer_special_access_flags(fieldDescriptor *from, fieldDescriptor *to);
+
+ void transfer_old_native_function_registrations(instanceKlassHandle the_class);
+
+ static void swap_marks(oop first, oop second);
+};
+
+#endif // SHARE_VM_PRIMS_JVMTIENHANCEDREDEFINECLASSES_HPP
diff --git a/src/share/vm/runtime/reflection.cpp b/src/share/vm/runtime/reflection.cpp
index a8d24fa..c9496c0 100644
--- a/src/share/vm/runtime/reflection.cpp
+++ b/src/share/vm/runtime/reflection.cpp
@@ -519,6 +519,12 @@
AccessFlags access,
bool classloader_only,
bool protected_restriction) {
+
+ // (DCEVM) Decide accessibility based on active version
+ if (current_class != NULL) {
+ current_class = current_class->active_version();
+ }
+
// Verify that current_class can access a field of field_class, where that
// field's access bits are "access". We assume that we've already verified
// that current_class can access field_class.
|