@@ -968,14 +968,14 @@ class ClassHierarchyWalker {
968
968
Symbol* _signature;
969
969
970
970
// special classes which are not allowed to be witnesses:
971
- Klass* _participants[PARTICIPANT_LIMIT+1 ];
972
- int _num_participants;
971
+ Klass* _participants[PARTICIPANT_LIMIT+1 ];
972
+ uint _num_participants;
973
973
974
974
// cache of method lookups
975
975
Method* _found_methods[PARTICIPANT_LIMIT+1 ];
976
976
977
977
// if non-zero, tells how many witnesses to convert to participants
978
- int _record_witnesses;
978
+ uint _record_witnesses;
979
979
980
980
void initialize (Klass* participant) {
981
981
_record_witnesses = 0 ;
@@ -1012,11 +1012,11 @@ class ClassHierarchyWalker {
1012
1012
_signature = NULL ;
1013
1013
initialize (participant);
1014
1014
}
1015
- ClassHierarchyWalker (Klass* participants[], int num_participants) {
1015
+ ClassHierarchyWalker (Klass* participants[], uint num_participants) {
1016
1016
_name = NULL ;
1017
1017
_signature = NULL ;
1018
1018
initialize (NULL );
1019
- for (int i = 0 ; i < num_participants; ++i) {
1019
+ for (uint i = 0 ; i < num_participants; ++i) {
1020
1020
add_participant (participants[i]);
1021
1021
}
1022
1022
}
@@ -1028,14 +1028,14 @@ class ClassHierarchyWalker {
1028
1028
}
1029
1029
1030
1030
int num_participants () { return _num_participants; }
1031
- Klass* participant (int n) {
1032
- assert (( uint ) n <= ( uint ) _num_participants, " oob" );
1031
+ Klass* participant (uint n) {
1032
+ assert (n <= _num_participants, " oob" );
1033
1033
return _participants[n];
1034
1034
}
1035
1035
1036
1036
// Note: If n==num_participants, returns NULL.
1037
- Method* found_method (int n) {
1038
- assert (( uint ) n <= ( uint ) _num_participants, " oob" );
1037
+ Method* found_method (uint n) {
1038
+ assert (n <= _num_participants, " oob" );
1039
1039
Method* fm = _found_methods[n];
1040
1040
assert (n == _num_participants || fm != NULL , " proper usage" );
1041
1041
if (fm != NULL && fm->method_holder () != _participants[n]) {
@@ -1048,69 +1048,15 @@ class ClassHierarchyWalker {
1048
1048
return fm;
1049
1049
}
1050
1050
1051
- #ifdef ASSERT
1052
- // Assert that m is inherited into ctxk, without intervening overrides.
1053
- // (May return true even if this is not true, in corner cases where we punt.)
1054
- bool check_method_context (InstanceKlass* ctxk, Method* m) {
1055
- if (m->method_holder () == ctxk)
1056
- return true ; // Quick win.
1057
- if (m->is_private ())
1058
- return false ; // Quick lose. Should not happen.
1059
- if (!(m->is_public () || m->is_protected ()))
1060
- // The override story is complex when packages get involved.
1061
- return true ; // Must punt the assertion to true.
1062
- Method* lm = ctxk->lookup_method (m->name (), m->signature ());
1063
- if (lm == NULL && ctxk->is_instance_klass ()) {
1064
- // It might be an interface method
1065
- lm = InstanceKlass::cast (ctxk)->lookup_method_in_ordered_interfaces (m->name (),
1066
- m->signature ());
1067
- }
1068
- if (lm == m)
1069
- // Method m is inherited into ctxk.
1070
- return true ;
1071
- if (lm != NULL ) {
1072
- if (!(lm->is_public () || lm->is_protected ())) {
1073
- // Method is [package-]private, so the override story is complex.
1074
- return true ; // Must punt the assertion to true.
1075
- }
1076
- if (lm->is_static ()) {
1077
- // Static methods don't override non-static so punt
1078
- return true ;
1079
- }
1080
- if (!Dependencies::is_concrete_method (lm, ctxk) &&
1081
- !Dependencies::is_concrete_method (m, ctxk)) {
1082
- // They are both non-concrete
1083
- if (lm->method_holder ()->is_subtype_of (m->method_holder ())) {
1084
- // Method m is overridden by lm, but both are non-concrete.
1085
- return true ;
1086
- }
1087
- if (lm->method_holder ()->is_interface () && m->method_holder ()->is_interface () &&
1088
- ctxk->is_subtype_of (m->method_holder ()) && ctxk->is_subtype_of (lm->method_holder ())) {
1089
- // Interface method defined in multiple super interfaces
1090
- return true ;
1091
- }
1092
- }
1093
- }
1094
- ResourceMark rm;
1095
- tty->print_cr (" Dependency method not found in the associated context:" );
1096
- tty->print_cr (" context = %s" , ctxk->external_name ());
1097
- tty->print ( " method = " ); m->print_short_name (tty); tty->cr ();
1098
- if (lm != NULL ) {
1099
- tty->print ( " found = " ); lm->print_short_name (tty); tty->cr ();
1100
- }
1101
- return false ;
1102
- }
1103
- #endif
1104
-
1105
1051
void add_participant (Klass* participant) {
1106
1052
assert (_num_participants + _record_witnesses < PARTICIPANT_LIMIT, " oob" );
1107
- int np = _num_participants++;
1053
+ uint np = _num_participants++;
1108
1054
_participants[np] = participant;
1109
1055
_participants[np+1 ] = NULL ;
1110
1056
_found_methods[np+1 ] = NULL ;
1111
1057
}
1112
1058
1113
- void record_witnesses (int add) {
1059
+ void record_witnesses (uint add) {
1114
1060
if (add > PARTICIPANT_LIMIT) add = PARTICIPANT_LIMIT;
1115
1061
assert (_num_participants + add < PARTICIPANT_LIMIT, " oob" );
1116
1062
_record_witnesses = add;
@@ -1281,6 +1227,63 @@ static bool count_find_witness_calls() {
1281
1227
#define count_find_witness_calls () (0 )
1282
1228
#endif // PRODUCT
1283
1229
1230
+ #ifdef ASSERT
1231
+ // Assert that m is inherited into ctxk, without intervening overrides.
1232
+ // (May return true even if this is not true, in corner cases where we punt.)
1233
+ bool Dependencies::verify_method_context (InstanceKlass* ctxk, Method* m) {
1234
+ if (m->is_private ()) {
1235
+ return false ; // Quick lose. Should not happen.
1236
+ }
1237
+ if (m->method_holder () == ctxk) {
1238
+ return true ; // Quick win.
1239
+ }
1240
+ if (!(m->is_public () || m->is_protected ())) {
1241
+ // The override story is complex when packages get involved.
1242
+ return true ; // Must punt the assertion to true.
1243
+ }
1244
+ Method* lm = ctxk->lookup_method (m->name (), m->signature ());
1245
+ if (lm == NULL && ctxk->is_instance_klass ()) {
1246
+ // It might be an interface method
1247
+ lm = InstanceKlass::cast (ctxk)->lookup_method_in_ordered_interfaces (m->name (),
1248
+ m->signature ());
1249
+ }
1250
+ if (lm == m) {
1251
+ // Method m is inherited into ctxk.
1252
+ return true ;
1253
+ }
1254
+ if (lm != NULL ) {
1255
+ if (!(lm->is_public () || lm->is_protected ())) {
1256
+ // Method is [package-]private, so the override story is complex.
1257
+ return true ; // Must punt the assertion to true.
1258
+ }
1259
+ if (lm->is_static ()) {
1260
+ // Static methods don't override non-static so punt
1261
+ return true ;
1262
+ }
1263
+ if (!Dependencies::is_concrete_method (lm, ctxk) &&
1264
+ !Dependencies::is_concrete_method (m, ctxk)) {
1265
+ // They are both non-concrete
1266
+ if (lm->method_holder ()->is_subtype_of (m->method_holder ())) {
1267
+ // Method m is overridden by lm, but both are non-concrete.
1268
+ return true ;
1269
+ }
1270
+ if (lm->method_holder ()->is_interface () && m->method_holder ()->is_interface () &&
1271
+ ctxk->is_subtype_of (m->method_holder ()) && ctxk->is_subtype_of (lm->method_holder ())) {
1272
+ // Interface method defined in multiple super interfaces
1273
+ return true ;
1274
+ }
1275
+ }
1276
+ }
1277
+ ResourceMark rm;
1278
+ tty->print_cr (" Dependency method not found in the associated context:" );
1279
+ tty->print_cr (" context = %s" , ctxk->external_name ());
1280
+ tty->print ( " method = " ); m->print_short_name (tty); tty->cr ();
1281
+ if (lm != NULL ) {
1282
+ tty->print ( " found = " ); lm->print_short_name (tty); tty->cr ();
1283
+ }
1284
+ return false ;
1285
+ }
1286
+ #endif // ASSERT
1284
1287
1285
1288
Klass* ClassHierarchyWalker::find_witness_in (KlassDepChange& changes,
1286
1289
InstanceKlass* context_type,
@@ -1308,11 +1311,7 @@ Klass* ClassHierarchyWalker::find_witness_in(KlassDepChange& changes,
1308
1311
if (participants_hide_witnesses) {
1309
1312
// If the new type is a subtype of a participant, we are done.
1310
1313
for (int i = 0 ; i < num_participants (); i++) {
1311
- Klass* part = participant (i);
1312
- if (part == NULL ) continue ;
1313
- assert (changes.involves_context (part) == new_type->is_subtype_of (part),
1314
- " correct marking of participants, b/c new_type is unique" );
1315
- if (changes.involves_context (part)) {
1314
+ if (changes.involves_context (participant (i))) {
1316
1315
// new guy is protected from this check by previous participant
1317
1316
return NULL ;
1318
1317
}
@@ -1392,18 +1391,27 @@ bool Dependencies::is_concrete_klass(Klass* k) {
1392
1391
return true ;
1393
1392
}
1394
1393
1395
- bool Dependencies::is_concrete_method (Method* m, Klass * k) {
1396
- // NULL is not a concrete method,
1397
- // statics are irrelevant to virtual call sites,
1398
- // abstract methods are not concrete,
1399
- // overpass (error) methods are not concrete if k is abstract
1400
- //
1401
- // note "true" is conservative answer --
1402
- // overpass clause is false if k == NULL, implies return true if
1403
- // answer depends on overpass clause.
1404
- return ! ( m == NULL || m -> is_static () || m -> is_abstract () ||
1405
- (m->is_overpass () && k != NULL && k -> is_abstract ()) );
1406
- }
1394
+ bool Dependencies::is_concrete_method (Method* m, Klass* k) {
1395
+ // NULL is not a concrete method.
1396
+ if (m == NULL ) {
1397
+ return false ;
1398
+ }
1399
+ // Statics are irrelevant to virtual call sites.
1400
+ if (m->is_static ()) {
1401
+ return false ;
1402
+ }
1403
+ // Abstract methods are not concrete.
1404
+ if (m->is_abstract ()) {
1405
+ return false ;
1406
+ }
1407
+ // Overpass (error) methods are not concrete if k is abstract.
1408
+ if (m->is_overpass () && k != NULL ) {
1409
+ return !k->is_abstract ();
1410
+ }
1411
+ // Note "true" is conservative answer: overpass clause is false if k == NULL,
1412
+ // implies return true if answer depends on overpass clause.
1413
+ return true ;
1414
+ }
1407
1415
1408
1416
1409
1417
Klass* Dependencies::find_finalizable_subclass (Klass* k) {
@@ -1538,7 +1546,7 @@ Method* Dependencies::find_unique_concrete_method(InstanceKlass* ctxk, Method* m
1538
1546
return NULL ;
1539
1547
}
1540
1548
ClassHierarchyWalker wf (m);
1541
- assert (wf. check_method_context (ctxk, m), " proper context" );
1549
+ assert (verify_method_context (ctxk, m), " proper context" );
1542
1550
wf.record_witnesses (1 );
1543
1551
Klass* wit = wf.find_witness_definer (ctxk);
1544
1552
if (wit != NULL ) return NULL ; // Too many witnesses.
0 commit comments