Skip to content

Commit 07c8ff4

Browse files
author
Vladimir Ivanov
committed
8264871: Dependencies: Miscellaneous cleanups in dependencies.cpp
Reviewed-by: neliasso
1 parent 863feab commit 07c8ff4

File tree

2 files changed

+98
-86
lines changed

2 files changed

+98
-86
lines changed

src/hotspot/share/code/dependencies.cpp

Lines changed: 91 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -968,14 +968,14 @@ class ClassHierarchyWalker {
968968
Symbol* _signature;
969969

970970
// 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;
973973

974974
// cache of method lookups
975975
Method* _found_methods[PARTICIPANT_LIMIT+1];
976976

977977
// if non-zero, tells how many witnesses to convert to participants
978-
int _record_witnesses;
978+
uint _record_witnesses;
979979

980980
void initialize(Klass* participant) {
981981
_record_witnesses = 0;
@@ -1012,11 +1012,11 @@ class ClassHierarchyWalker {
10121012
_signature = NULL;
10131013
initialize(participant);
10141014
}
1015-
ClassHierarchyWalker(Klass* participants[], int num_participants) {
1015+
ClassHierarchyWalker(Klass* participants[], uint num_participants) {
10161016
_name = NULL;
10171017
_signature = NULL;
10181018
initialize(NULL);
1019-
for (int i = 0; i < num_participants; ++i) {
1019+
for (uint i = 0; i < num_participants; ++i) {
10201020
add_participant(participants[i]);
10211021
}
10221022
}
@@ -1028,14 +1028,14 @@ class ClassHierarchyWalker {
10281028
}
10291029

10301030
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");
10331033
return _participants[n];
10341034
}
10351035

10361036
// 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");
10391039
Method* fm = _found_methods[n];
10401040
assert(n == _num_participants || fm != NULL, "proper usage");
10411041
if (fm != NULL && fm->method_holder() != _participants[n]) {
@@ -1048,69 +1048,15 @@ class ClassHierarchyWalker {
10481048
return fm;
10491049
}
10501050

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-
11051051
void add_participant(Klass* participant) {
11061052
assert(_num_participants + _record_witnesses < PARTICIPANT_LIMIT, "oob");
1107-
int np = _num_participants++;
1053+
uint np = _num_participants++;
11081054
_participants[np] = participant;
11091055
_participants[np+1] = NULL;
11101056
_found_methods[np+1] = NULL;
11111057
}
11121058

1113-
void record_witnesses(int add) {
1059+
void record_witnesses(uint add) {
11141060
if (add > PARTICIPANT_LIMIT) add = PARTICIPANT_LIMIT;
11151061
assert(_num_participants + add < PARTICIPANT_LIMIT, "oob");
11161062
_record_witnesses = add;
@@ -1281,6 +1227,63 @@ static bool count_find_witness_calls() {
12811227
#define count_find_witness_calls() (0)
12821228
#endif //PRODUCT
12831229

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
12841287

12851288
Klass* ClassHierarchyWalker::find_witness_in(KlassDepChange& changes,
12861289
InstanceKlass* context_type,
@@ -1308,11 +1311,7 @@ Klass* ClassHierarchyWalker::find_witness_in(KlassDepChange& changes,
13081311
if (participants_hide_witnesses) {
13091312
// If the new type is a subtype of a participant, we are done.
13101313
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))) {
13161315
// new guy is protected from this check by previous participant
13171316
return NULL;
13181317
}
@@ -1392,18 +1391,27 @@ bool Dependencies::is_concrete_klass(Klass* k) {
13921391
return true;
13931392
}
13941393

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+
}
14071415

14081416

14091417
Klass* Dependencies::find_finalizable_subclass(Klass* k) {
@@ -1538,7 +1546,7 @@ Method* Dependencies::find_unique_concrete_method(InstanceKlass* ctxk, Method* m
15381546
return NULL;
15391547
}
15401548
ClassHierarchyWalker wf(m);
1541-
assert(wf.check_method_context(ctxk, m), "proper context");
1549+
assert(verify_method_context(ctxk, m), "proper context");
15421550
wf.record_witnesses(1);
15431551
Klass* wit = wf.find_witness_definer(ctxk);
15441552
if (wit != NULL) return NULL; // Too many witnesses.

src/hotspot/share/code/dependencies.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,10 @@ class Dependencies: public ResourceObj {
420420
static Klass* find_unique_concrete_subtype(InstanceKlass* ctxk);
421421
static Method* find_unique_concrete_method(InstanceKlass* ctxk, Method* m);
422422

423+
#ifdef ASSERT
424+
static bool verify_method_context(InstanceKlass* ctxk, Method* m);
425+
#endif // ASSERT
426+
423427
// Create the encoding which will be stored in an nmethod.
424428
void encode_content_bytes();
425429

@@ -719,13 +723,13 @@ class DepChange : public StackObj {
719723
class KlassDepChange : public DepChange {
720724
private:
721725
// each change set is rooted in exactly one new type (at present):
722-
Klass* _new_type;
726+
InstanceKlass* _new_type;
723727

724728
void initialize();
725729

726730
public:
727731
// notes the new type, marks it and all its super-types
728-
KlassDepChange(Klass* new_type)
732+
KlassDepChange(InstanceKlass* new_type)
729733
: _new_type(new_type)
730734
{
731735
initialize();
@@ -741,7 +745,7 @@ class KlassDepChange : public DepChange {
741745
nm->mark_for_deoptimization(/*inc_recompile_counts=*/true);
742746
}
743747

744-
Klass* new_type() { return _new_type; }
748+
InstanceKlass* new_type() { return _new_type; }
745749

746750
// involves_context(k) is true if k is new_type or any of the super types
747751
bool involves_context(Klass* k);

0 commit comments

Comments
 (0)