@@ -770,20 +770,43 @@ void InstanceKlass::link_class(TRAPS) {
770
770
void InstanceKlass::check_link_state_and_wait (JavaThread* current) {
771
771
MonitorLocker ml (current, _init_monitor);
772
772
773
+ bool debug_logging_enabled = log_is_enabled (Debug, class , init);
774
+
773
775
// Another thread is linking this class, wait.
774
776
while (is_being_linked () && !is_init_thread (current)) {
777
+ if (debug_logging_enabled) {
778
+ ResourceMark rm (current);
779
+ log_debug (class , init)(" Thread \" %s\" waiting for linking of %s by thread \" %s\" " ,
780
+ current->name (), external_name (), init_thread_name ());
781
+ }
775
782
ml.wait ();
776
783
}
777
784
778
785
// This thread is recursively linking this class, continue
779
786
if (is_being_linked () && is_init_thread (current)) {
787
+ if (debug_logging_enabled) {
788
+ ResourceMark rm (current);
789
+ log_debug (class , init)(" Thread \" %s\" recursively linking %s" ,
790
+ current->name (), external_name ());
791
+ }
780
792
return ;
781
793
}
782
794
783
795
// If this class wasn't linked already, set state to being_linked
784
796
if (!is_linked ()) {
797
+ if (debug_logging_enabled) {
798
+ ResourceMark rm (current);
799
+ log_debug (class , init)(" Thread \" %s\" linking %s" ,
800
+ current->name (), external_name ());
801
+ }
785
802
set_init_state (being_linked);
786
803
set_init_thread (current);
804
+ } else {
805
+ if (debug_logging_enabled) {
806
+ ResourceMark rm (current);
807
+ log_debug (class , init)(" Thread \" %s\" found %s already linked" ,
808
+ current->name (), external_name ());
809
+ }
787
810
}
788
811
}
789
812
@@ -1058,13 +1081,21 @@ void InstanceKlass::initialize_impl(TRAPS) {
1058
1081
1059
1082
JavaThread* jt = THREAD;
1060
1083
1084
+ bool debug_logging_enabled = log_is_enabled (Debug, class , init);
1085
+
1061
1086
// refer to the JVM book page 47 for description of steps
1062
1087
// Step 1
1063
1088
{
1064
- MonitorLocker ml (THREAD , _init_monitor);
1089
+ MonitorLocker ml (jt , _init_monitor);
1065
1090
1066
1091
// Step 2
1067
1092
while (is_being_initialized () && !is_init_thread (jt)) {
1093
+ if (debug_logging_enabled) {
1094
+ ResourceMark rm (jt);
1095
+ log_debug (class , init)(" Thread \" %s\" waiting for initialization of %s by thread \" %s\" " ,
1096
+ jt->name (), external_name (), init_thread_name ());
1097
+ }
1098
+
1068
1099
wait = true ;
1069
1100
jt->set_class_to_be_initialized (this );
1070
1101
ml.wait ();
@@ -1073,24 +1104,44 @@ void InstanceKlass::initialize_impl(TRAPS) {
1073
1104
1074
1105
// Step 3
1075
1106
if (is_being_initialized () && is_init_thread (jt)) {
1107
+ if (debug_logging_enabled) {
1108
+ ResourceMark rm (jt);
1109
+ log_debug (class , init)(" Thread \" %s\" recursively initializing %s" ,
1110
+ jt->name (), external_name ());
1111
+ }
1076
1112
DTRACE_CLASSINIT_PROBE_WAIT (recursive, -1 , wait);
1077
1113
return ;
1078
1114
}
1079
1115
1080
1116
// Step 4
1081
1117
if (is_initialized ()) {
1118
+ if (debug_logging_enabled) {
1119
+ ResourceMark rm (jt);
1120
+ log_debug (class , init)(" Thread \" %s\" found %s already initialized" ,
1121
+ jt->name (), external_name ());
1122
+ }
1082
1123
DTRACE_CLASSINIT_PROBE_WAIT (concurrent, -1 , wait);
1083
1124
return ;
1084
1125
}
1085
1126
1086
1127
// Step 5
1087
1128
if (is_in_error_state ()) {
1129
+ if (debug_logging_enabled) {
1130
+ ResourceMark rm (jt);
1131
+ log_debug (class , init)(" Thread \" %s\" found %s is in error state" ,
1132
+ jt->name (), external_name ());
1133
+ }
1088
1134
throw_error = true ;
1089
1135
} else {
1090
1136
1091
1137
// Step 6
1092
1138
set_init_state (being_initialized);
1093
1139
set_init_thread (jt);
1140
+ if (debug_logging_enabled) {
1141
+ ResourceMark rm (jt);
1142
+ log_debug (class , init)(" Thread \" %s\" is initializing %s" ,
1143
+ jt->name (), external_name ());
1144
+ }
1094
1145
}
1095
1146
}
1096
1147
@@ -1564,7 +1615,9 @@ void InstanceKlass::call_class_initializer(TRAPS) {
1564
1615
LogStream ls (lt);
1565
1616
ls.print (" %d Initializing " , call_class_initializer_counter++);
1566
1617
name ()->print_value_on (&ls);
1567
- ls.print_cr (" %s (" PTR_FORMAT " )" , h_method () == nullptr ? " (no method)" : " " , p2i (this ));
1618
+ ls.print_cr (" %s (" PTR_FORMAT " ) by thread \" %s\" " ,
1619
+ h_method () == nullptr ? " (no method)" : " " , p2i (this ),
1620
+ THREAD->name ());
1568
1621
}
1569
1622
if (h_method () != nullptr ) {
1570
1623
JavaCallArguments args; // No arguments
@@ -4427,4 +4480,3 @@ void ClassHierarchyIterator::next() {
4427
4480
_current = _current->next_sibling ();
4428
4481
return ; // visit next sibling subclass
4429
4482
}
4430
-
0 commit comments