76 // Initialize the escape information (to "don't know."); |
76 // Initialize the escape information (to "don't know."); |
77 _eflags = _arg_local = _arg_stack = _arg_returned = 0; |
77 _eflags = _arg_local = _arg_stack = _arg_returned = 0; |
78 _parameters = NULL; |
78 _parameters = NULL; |
79 } |
79 } |
80 |
80 |
|
81 // Check for entries that reference an unloaded method |
|
82 class PrepareExtraDataClosure : public CleanExtraDataClosure { |
|
83 MethodData* _mdo; |
|
84 uint64_t _safepoint_counter; |
|
85 GrowableArray<Method*> _uncached_methods; |
|
86 |
|
87 public: |
|
88 PrepareExtraDataClosure(MethodData* mdo) |
|
89 : _mdo(mdo), |
|
90 _safepoint_counter(SafepointSynchronize::safepoint_counter()), |
|
91 _uncached_methods() |
|
92 { } |
|
93 |
|
94 bool is_live(Method* m) { |
|
95 if (!m->method_holder()->is_loader_alive()) { |
|
96 return false; |
|
97 } |
|
98 if (CURRENT_ENV->cached_metadata(m) == NULL) { |
|
99 // Uncached entries need to be pre-populated. |
|
100 _uncached_methods.append(m); |
|
101 } |
|
102 return true; |
|
103 } |
|
104 |
|
105 bool has_safepointed() { |
|
106 return SafepointSynchronize::safepoint_counter() != _safepoint_counter; |
|
107 } |
|
108 |
|
109 bool finish() { |
|
110 if (_uncached_methods.length() == 0) { |
|
111 // Preparation finished iff all Methods* were already cached. |
|
112 return true; |
|
113 } |
|
114 // Holding locks through safepoints is bad practice. |
|
115 MutexUnlocker mu(_mdo->extra_data_lock()); |
|
116 for (int i = 0; i < _uncached_methods.length(); ++i) { |
|
117 if (has_safepointed()) { |
|
118 // The metadata in the growable array might contain stale |
|
119 // entries after a safepoint. |
|
120 return false; |
|
121 } |
|
122 Method* method = _uncached_methods.at(i); |
|
123 // Populating ciEnv caches may cause safepoints due |
|
124 // to taking the Compile_lock with safepoint checks. |
|
125 (void)CURRENT_ENV->get_method(method); |
|
126 } |
|
127 return false; |
|
128 } |
|
129 }; |
|
130 |
|
131 void ciMethodData::prepare_metadata() { |
|
132 MethodData* mdo = get_MethodData(); |
|
133 |
|
134 for (;;) { |
|
135 ResourceMark rm; |
|
136 PrepareExtraDataClosure cl(mdo); |
|
137 mdo->clean_extra_data(&cl); |
|
138 if (cl.finish()) { |
|
139 // When encountering uncached metadata, the Compile_lock might be |
|
140 // acquired when creating ciMetadata handles, causing safepoints |
|
141 // which requires a new round of preparation to clean out potentially |
|
142 // new unloading metadata. |
|
143 return; |
|
144 } |
|
145 } |
|
146 } |
|
147 |
81 void ciMethodData::load_extra_data() { |
148 void ciMethodData::load_extra_data() { |
82 MethodData* mdo = get_MethodData(); |
149 MethodData* mdo = get_MethodData(); |
83 |
|
84 MutexLocker ml(mdo->extra_data_lock()); |
150 MutexLocker ml(mdo->extra_data_lock()); |
|
151 // Deferred metadata cleaning due to concurrent class unloading. |
|
152 prepare_metadata(); |
|
153 // After metadata preparation, there is no stale metadata, |
|
154 // and no safepoints can introduce more stale metadata. |
|
155 NoSafepointVerifier no_safepoint; |
85 |
156 |
86 // speculative trap entries also hold a pointer to a Method so need to be translated |
157 // speculative trap entries also hold a pointer to a Method so need to be translated |
87 DataLayout* dp_src = mdo->extra_data_base(); |
158 DataLayout* dp_src = mdo->extra_data_base(); |
88 DataLayout* end_src = mdo->args_data_limit(); |
159 DataLayout* end_src = mdo->args_data_limit(); |
89 DataLayout* dp_dst = extra_data_base(); |
160 DataLayout* dp_dst = extra_data_base(); |
92 assert(((intptr_t)dp_dst) - ((intptr_t)extra_data_base()) == ((intptr_t)dp_src) - ((intptr_t)mdo->extra_data_base()), "source and destination don't match"); |
163 assert(((intptr_t)dp_dst) - ((intptr_t)extra_data_base()) == ((intptr_t)dp_src) - ((intptr_t)mdo->extra_data_base()), "source and destination don't match"); |
93 |
164 |
94 // New traps in the MDO may have been added since we copied the |
165 // New traps in the MDO may have been added since we copied the |
95 // data (concurrent deoptimizations before we acquired |
166 // data (concurrent deoptimizations before we acquired |
96 // extra_data_lock above) or can be removed (a safepoint may occur |
167 // extra_data_lock above) or can be removed (a safepoint may occur |
97 // in the translate_from call below) as we translate the copy: |
168 // in the prepare_metadata call above) as we translate the copy: |
98 // update the copy as we go. |
169 // update the copy as we go. |
99 int tag = dp_src->tag(); |
170 int tag = dp_src->tag(); |
100 if (tag != DataLayout::arg_info_data_tag) { |
171 if (tag != DataLayout::arg_info_data_tag) { |
101 memcpy(dp_dst, dp_src, ((intptr_t)MethodData::next_extra(dp_src)) - ((intptr_t)dp_src)); |
172 memcpy(dp_dst, dp_src, ((intptr_t)MethodData::next_extra(dp_src)) - ((intptr_t)dp_src)); |
102 } |
173 } |
103 |
174 |
104 switch(tag) { |
175 switch(tag) { |
105 case DataLayout::speculative_trap_data_tag: { |
176 case DataLayout::speculative_trap_data_tag: { |
106 ciSpeculativeTrapData data_dst(dp_dst); |
177 ciSpeculativeTrapData data_dst(dp_dst); |
107 SpeculativeTrapData data_src(dp_src); |
178 SpeculativeTrapData data_src(dp_src); |
108 |
179 data_dst.translate_from(&data_src); |
109 { // During translation a safepoint can happen or VM lock can be taken (e.g., Compile_lock). |
|
110 MutexUnlocker ml(mdo->extra_data_lock()); |
|
111 data_dst.translate_from(&data_src); |
|
112 } |
|
113 break; |
180 break; |
114 } |
181 } |
115 case DataLayout::bit_data_tag: |
182 case DataLayout::bit_data_tag: |
116 break; |
183 break; |
117 case DataLayout::no_tag: |
184 case DataLayout::no_tag: |