< prev index next >

src/hotspot/share/ci/ciMethodData.cpp

Print this page

 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "ci/ciMetadata.hpp"
 26 #include "ci/ciMethodData.hpp"
 27 #include "ci/ciReplay.hpp"
 28 #include "ci/ciUtilities.inline.hpp"
 29 #include "compiler/compiler_globals.hpp"
 30 #include "memory/allocation.inline.hpp"
 31 #include "memory/resourceArea.hpp"
 32 #include "oops/klass.inline.hpp"
 33 #include "oops/methodData.inline.hpp"

 34 #include "runtime/deoptimization.hpp"
 35 #include "utilities/copy.hpp"
 36 
 37 // ciMethodData
 38 
 39 // ------------------------------------------------------------------
 40 // ciMethodData::ciMethodData
 41 //
 42 ciMethodData::ciMethodData(MethodData* md)
 43 : ciMetadata(md),
 44   _data_size(0), _extra_data_size(0), _data(nullptr),
 45   _parameters_data_offset(0),
 46   _exception_handlers_data_offset(0),
 47   // Set an initial hint. Don't use set_hint_di() because
 48   // first_di() may be out of bounds if data_size is 0.
 49   _hint_di(first_di()),
 50   _state(empty_state),
 51   _saw_free_extra_data(false),
 52   // Initialize the escape information (to "don't know.");
 53   _eflags(0), _arg_local(0), _arg_stack(0), _arg_returned(0),
 54   _invocation_counter(0),
 55   _orig() {}
 56 









 57 // Check for entries that reference an unloaded method
 58 class PrepareExtraDataClosure : public CleanExtraDataClosure {
 59   MethodData*            _mdo;
 60   SafepointStateTracker  _safepoint_tracker;
 61   GrowableArray<Method*> _uncached_methods;
 62 
 63 public:
 64   PrepareExtraDataClosure(MethodData* mdo)
 65     : _mdo(mdo),
 66       _safepoint_tracker(SafepointSynchronize::safepoint_state_tracker()),
 67       _uncached_methods()
 68   { }
 69 
 70   bool is_live(Method* m) {
 71     if (!m->method_holder()->is_loader_alive()) {

 72       return false;
 73     }
 74     if (CURRENT_ENV->cached_metadata(m) == nullptr) {
 75       // Uncached entries need to be pre-populated.
 76       _uncached_methods.append(m);
 77     }
 78     return true;
 79   }
 80 
 81   bool has_safepointed() {
 82     return _safepoint_tracker.safepoint_state_changed();
 83   }
 84 
 85   bool finish() {
 86     if (_uncached_methods.length() == 0) {
 87       // Preparation finished iff all Methods* were already cached.
 88       return true;
 89     }
 90     // We are currently holding the extra_data_lock and ensuring
 91     // no safepoint breaks the lock.

286     _invocation_counter = 1;
287   }
288 
289   _state = mdo->is_mature() ? mature_state : immature_state;
290   _eflags = mdo->eflags();
291   _arg_local = mdo->arg_local();
292   _arg_stack = mdo->arg_stack();
293   _arg_returned  = mdo->arg_returned();
294   if (ReplayCompiles) {
295     ciReplay::initialize(this);
296     if (is_empty()) {
297       return false;
298     }
299   }
300   return true;
301 }
302 
303 void ciReceiverTypeData::translate_receiver_data_from(const ProfileData* data) {
304   for (uint row = 0; row < row_limit(); row++) {
305     Klass* k = data->as_ReceiverTypeData()->receiver(row);
306     if (k != nullptr) {
307       if (k->is_loader_alive()) {
308         ciKlass* klass = CURRENT_ENV->get_klass(k);
309         set_receiver(row, klass);
310       } else {
311         // With concurrent class unloading, the MDO could have stale metadata; override it
312         clear_row(row);
313       }
314     } else {
315       set_receiver(row, nullptr);
316     }
317   }
318 }
319 
320 void ciTypeStackSlotEntries::translate_type_data_from(const TypeStackSlotEntries* entries) {
321   for (int i = 0; i < number_of_entries(); i++) {
322     intptr_t k = entries->type(i);
323     Klass* klass = (Klass*)klass_part(k);
324     if (klass != nullptr && !klass->is_loader_alive()) {
325       // With concurrent class unloading, the MDO could have stale metadata; override it
326       TypeStackSlotEntries::set_type(i, TypeStackSlotEntries::with_status((Klass*)nullptr, k));
327     } else {
328       TypeStackSlotEntries::set_type(i, translate_klass(k));
329     }
330   }
331 }
332 
333 void ciReturnTypeEntry::translate_type_data_from(const ReturnTypeEntry* ret) {
334   intptr_t k = ret->type();
335   Klass* klass = (Klass*)klass_part(k);
336   if (klass != nullptr && !klass->is_loader_alive()) {
337     // With concurrent class unloading, the MDO could have stale metadata; override it
338     set_type(ReturnTypeEntry::with_status((Klass*)nullptr, k));
339   } else {
340     set_type(translate_klass(k));
341   }
342 }
343 
344 void ciSpeculativeTrapData::translate_from(const ProfileData* data) {
345   Method* m = data->as_SpeculativeTrapData()->method();
346   ciMethod* ci_m = CURRENT_ENV->get_method(m);
347   set_method(ci_m);
348 }
349 
350 // Get the data at an arbitrary (sort of) data index.
351 ciProfileData* ciMethodData::data_at(int data_index) {
352   if (out_of_bounds(data_index)) {
353     return nullptr;
354   }
355   DataLayout* data_layout = data_layout_at(data_index);
356   return data_from(data_layout);

 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "ci/ciMetadata.hpp"
 26 #include "ci/ciMethodData.hpp"
 27 #include "ci/ciReplay.hpp"
 28 #include "ci/ciUtilities.inline.hpp"
 29 #include "compiler/compiler_globals.hpp"
 30 #include "memory/allocation.inline.hpp"
 31 #include "memory/resourceArea.hpp"
 32 #include "oops/klass.inline.hpp"
 33 #include "oops/methodData.inline.hpp"
 34 #include "oops/trainingData.hpp"
 35 #include "runtime/deoptimization.hpp"
 36 #include "utilities/copy.hpp"
 37 
 38 // ciMethodData
 39 
 40 // ------------------------------------------------------------------
 41 // ciMethodData::ciMethodData
 42 //
 43 ciMethodData::ciMethodData(MethodData* md)
 44 : ciMetadata(md),
 45   _data_size(0), _extra_data_size(0), _data(nullptr),
 46   _parameters_data_offset(0),
 47   _exception_handlers_data_offset(0),
 48   // Set an initial hint. Don't use set_hint_di() because
 49   // first_di() may be out of bounds if data_size is 0.
 50   _hint_di(first_di()),
 51   _state(empty_state),
 52   _saw_free_extra_data(false),
 53   // Initialize the escape information (to "don't know.");
 54   _eflags(0), _arg_local(0), _arg_stack(0), _arg_returned(0),
 55   _invocation_counter(0),
 56   _orig() {}
 57 
 58 
 59 static bool is_klass_loaded(Klass* k) {
 60   if (TrainingData::have_data()) {
 61     // If we're running in AOT mode some classes may not be loaded yet
 62     return !k->is_instance_klass() || InstanceKlass::cast(k)->is_loaded();
 63   }
 64   return true;
 65 }
 66 
 67 // Check for entries that reference an unloaded method
 68 class PrepareExtraDataClosure : public CleanExtraDataClosure {
 69   MethodData*            _mdo;
 70   SafepointStateTracker  _safepoint_tracker;
 71   GrowableArray<Method*> _uncached_methods;
 72 
 73 public:
 74   PrepareExtraDataClosure(MethodData* mdo)
 75     : _mdo(mdo),
 76       _safepoint_tracker(SafepointSynchronize::safepoint_state_tracker()),
 77       _uncached_methods()
 78   { }
 79 
 80   bool is_live(Method* m) {
 81     Klass* holder = m->method_holder();
 82     if (holder == nullptr || !holder->is_loader_present_and_alive() || !is_klass_loaded(holder)) {
 83       return false;
 84     }
 85     if (CURRENT_ENV->cached_metadata(m) == nullptr) {
 86       // Uncached entries need to be pre-populated.
 87       _uncached_methods.append(m);
 88     }
 89     return true;
 90   }
 91 
 92   bool has_safepointed() {
 93     return _safepoint_tracker.safepoint_state_changed();
 94   }
 95 
 96   bool finish() {
 97     if (_uncached_methods.length() == 0) {
 98       // Preparation finished iff all Methods* were already cached.
 99       return true;
100     }
101     // We are currently holding the extra_data_lock and ensuring
102     // no safepoint breaks the lock.

297     _invocation_counter = 1;
298   }
299 
300   _state = mdo->is_mature() ? mature_state : immature_state;
301   _eflags = mdo->eflags();
302   _arg_local = mdo->arg_local();
303   _arg_stack = mdo->arg_stack();
304   _arg_returned  = mdo->arg_returned();
305   if (ReplayCompiles) {
306     ciReplay::initialize(this);
307     if (is_empty()) {
308       return false;
309     }
310   }
311   return true;
312 }
313 
314 void ciReceiverTypeData::translate_receiver_data_from(const ProfileData* data) {
315   for (uint row = 0; row < row_limit(); row++) {
316     Klass* k = data->as_ReceiverTypeData()->receiver(row);
317     if (k != nullptr && k->class_loader_data() != nullptr && is_klass_loaded(k)) {
318       if (k->is_loader_alive()) {
319         ciKlass* klass = CURRENT_ENV->get_klass(k);
320         set_receiver(row, klass);
321       } else {
322         // With concurrent class unloading, the MDO could have stale metadata; override it
323         clear_row(row);
324       }
325     } else {
326       set_receiver(row, nullptr);
327     }
328   }
329 }
330 
331 void ciTypeStackSlotEntries::translate_type_data_from(const TypeStackSlotEntries* entries) {
332   for (int i = 0; i < number_of_entries(); i++) {
333     intptr_t k = entries->type(i);
334     Klass* klass = (Klass*)klass_part(k);
335     if (klass == nullptr || !klass->is_loader_present_and_alive() || !is_klass_loaded(klass)) {
336       // With concurrent class unloading, the MDO could have stale metadata; override it
337       TypeStackSlotEntries::set_type(i, TypeStackSlotEntries::with_status((Klass*)nullptr, k));
338     } else {
339       TypeStackSlotEntries::set_type(i, translate_klass(k));
340     }
341   }
342 }
343 
344 void ciReturnTypeEntry::translate_type_data_from(const ReturnTypeEntry* ret) {
345   intptr_t k = ret->type();
346   Klass* klass = (Klass*)klass_part(k);
347   if (klass == nullptr || !klass->is_loader_present_and_alive() || !is_klass_loaded(klass)) {
348     // With concurrent class unloading, the MDO could have stale metadata; override it
349     set_type(ReturnTypeEntry::with_status((Klass*)nullptr, k));
350   } else {
351     set_type(translate_klass(k));
352   }
353 }
354 
355 void ciSpeculativeTrapData::translate_from(const ProfileData* data) {
356   Method* m = data->as_SpeculativeTrapData()->method();
357   ciMethod* ci_m = CURRENT_ENV->get_method(m);
358   set_method(ci_m);
359 }
360 
361 // Get the data at an arbitrary (sort of) data index.
362 ciProfileData* ciMethodData::data_at(int data_index) {
363   if (out_of_bounds(data_index)) {
364     return nullptr;
365   }
366   DataLayout* data_layout = data_layout_at(data_index);
367   return data_from(data_layout);
< prev index next >