< prev index next >

src/hotspot/share/oops/trainingData.hpp

Print this page

 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 #ifndef SHARE_OOPS_TRAININGDATA_HPP
 26 #define SHARE_OOPS_TRAININGDATA_HPP
 27 
 28 #include "cds/cdsConfig.hpp"
 29 #include "classfile/compactHashtable.hpp"
 30 #include "compiler/compiler_globals.hpp"
 31 #include "compiler/compilerDefinitions.hpp"
 32 #include "memory/allocation.hpp"
 33 #include "memory/metaspaceClosure.hpp"
 34 #include "oops/instanceKlass.hpp"
 35 #include "oops/method.hpp"
 36 #include "oops/objArrayKlass.hpp"
 37 #include "runtime/handles.hpp"
 38 #include "runtime/mutexLocker.hpp"

 39 #include "utilities/resizableHashTable.hpp"
 40 
 41 class ciEnv;
 42 class ciBaseObject;
 43 class CompileTask;
 44 class CompileTrainingData;
 45 class KlassTrainingData;
 46 class MethodTrainingData;
 47 
 48 // Base class for all the training data varieties
 49 class TrainingData : public Metadata {
 50   friend KlassTrainingData;
 51   friend MethodTrainingData;
 52   friend CompileTrainingData;
 53 public:
 54   // Key is used to insert any TrainingData (TD) object into a hash tables. The key is currently a
 55   // pointer to a metaspace object the TD is associated with. For example,
 56   // for KlassTrainingData it's an InstanceKlass, for MethodTrainingData it's a Method.
 57   // The utility of the these hash tables is to be able to find a TD object for a given metaspace
 58   // metaspace object.

312     if (have_data()) {
313       archived_training_data_dictionary()->iterate(fn);
314     }
315     if (need_data()) {
316       training_data_set()->iterate(fn);
317     }
318   }
319 
320   virtual MethodTrainingData*   as_MethodTrainingData()  const { return nullptr; }
321   virtual KlassTrainingData*    as_KlassTrainingData()   const { return nullptr; }
322   virtual CompileTrainingData*  as_CompileTrainingData() const { return nullptr; }
323   bool is_MethodTrainingData()  const { return as_MethodTrainingData()  != nullptr; }
324   bool is_KlassTrainingData()   const { return as_KlassTrainingData()   != nullptr; }
325   bool is_CompileTrainingData() const { return as_CompileTrainingData() != nullptr; }
326 
327   virtual void prepare(Visitor& visitor) = 0;
328   virtual void cleanup(Visitor& visitor) = 0;
329 
330   static void initialize() NOT_CDS_RETURN;
331 
332   static void verify();
333 
334   // Widget for recording dependencies, as an N-to-M graph relation,
335   // possibly cyclic.
336   template<typename E>
337   class DepList : public StackObj {
338     GrowableArrayCHeap<E, mtCompiler>* _deps_dyn;
339     Array<E>*                          _deps;
340   public:
341     DepList() {
342       _deps_dyn = nullptr;
343       _deps = nullptr;
344     }
345 
346     int length() const {
347       TrainingDataLocker::assert_locked_or_snapshotted();
348       return (_deps_dyn != nullptr ? _deps_dyn->length()
349               : _deps   != nullptr ? _deps->length()
350               : 0);
351     }
352     E* adr_at(int i) const {

746   bool _was_toplevel;
747   // metadata snapshots of final state:
748   MethodCounters* _final_counters;
749   MethodData*     _final_profile;
750 
751   MethodTrainingData();
752   MethodTrainingData(Method* method, KlassTrainingData* ktd) : TrainingData(method) {
753     _klass = ktd;
754     _holder = method;
755     for (int i = 0; i < CompLevel_count - 1; i++) {
756       _last_toplevel_compiles[i] = nullptr;
757     }
758     _highest_top_level = CompLevel_none;
759     _level_mask = 0;
760     _was_toplevel = false;
761   }
762 
763   static int level_mask(int level) {
764     return ((level & 0xF) != level ? 0 : 1 << level);
765   }





766 
767  public:
768   KlassTrainingData* klass()  const { return _klass; }
769   bool has_holder()           const { return _holder != nullptr; }
770   Method* holder()            const { return _holder; }
771   bool only_inlined()         const { return !_was_toplevel; }
772   bool saw_level(CompLevel l) const { return (_level_mask & level_mask(l)) != 0; }

773   int highest_top_level()     const { return _highest_top_level; }
774   MethodData* final_profile() const { return _final_profile; }
775 
776   Symbol* name() const {
777     precond(has_holder());
778     return holder()->name();
779   }
780   Symbol* signature() const {
781     precond(has_holder());
782     return holder()->signature();
783   }
784 
785   CompileTrainingData* last_toplevel_compile(int level) const {
786     if (level > CompLevel_none) {
787       return _last_toplevel_compiles[level - 1];
788     }
789     return nullptr;
790   }
791 
792   void notice_compilation(int level, bool inlined = false) {

 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 #ifndef SHARE_OOPS_TRAININGDATA_HPP
 26 #define SHARE_OOPS_TRAININGDATA_HPP
 27 
 28 #include "cds/cdsConfig.hpp"
 29 #include "classfile/compactHashtable.hpp"
 30 #include "compiler/compiler_globals.hpp"
 31 #include "compiler/compilerDefinitions.hpp"
 32 #include "memory/allocation.hpp"
 33 #include "memory/metaspaceClosure.hpp"
 34 #include "oops/instanceKlass.hpp"
 35 #include "oops/method.hpp"
 36 #include "oops/objArrayKlass.hpp"
 37 #include "runtime/handles.hpp"
 38 #include "runtime/mutexLocker.hpp"
 39 #include "utilities/count_leading_zeros.hpp"
 40 #include "utilities/resizableHashTable.hpp"
 41 
 42 class ciEnv;
 43 class ciBaseObject;
 44 class CompileTask;
 45 class CompileTrainingData;
 46 class KlassTrainingData;
 47 class MethodTrainingData;
 48 
 49 // Base class for all the training data varieties
 50 class TrainingData : public Metadata {
 51   friend KlassTrainingData;
 52   friend MethodTrainingData;
 53   friend CompileTrainingData;
 54 public:
 55   // Key is used to insert any TrainingData (TD) object into a hash tables. The key is currently a
 56   // pointer to a metaspace object the TD is associated with. For example,
 57   // for KlassTrainingData it's an InstanceKlass, for MethodTrainingData it's a Method.
 58   // The utility of the these hash tables is to be able to find a TD object for a given metaspace
 59   // metaspace object.

313     if (have_data()) {
314       archived_training_data_dictionary()->iterate(fn);
315     }
316     if (need_data()) {
317       training_data_set()->iterate(fn);
318     }
319   }
320 
321   virtual MethodTrainingData*   as_MethodTrainingData()  const { return nullptr; }
322   virtual KlassTrainingData*    as_KlassTrainingData()   const { return nullptr; }
323   virtual CompileTrainingData*  as_CompileTrainingData() const { return nullptr; }
324   bool is_MethodTrainingData()  const { return as_MethodTrainingData()  != nullptr; }
325   bool is_KlassTrainingData()   const { return as_KlassTrainingData()   != nullptr; }
326   bool is_CompileTrainingData() const { return as_CompileTrainingData() != nullptr; }
327 
328   virtual void prepare(Visitor& visitor) = 0;
329   virtual void cleanup(Visitor& visitor) = 0;
330 
331   static void initialize() NOT_CDS_RETURN;
332 
333   static void verify() NOT_CDS_RETURN;
334 
335   // Widget for recording dependencies, as an N-to-M graph relation,
336   // possibly cyclic.
337   template<typename E>
338   class DepList : public StackObj {
339     GrowableArrayCHeap<E, mtCompiler>* _deps_dyn;
340     Array<E>*                          _deps;
341   public:
342     DepList() {
343       _deps_dyn = nullptr;
344       _deps = nullptr;
345     }
346 
347     int length() const {
348       TrainingDataLocker::assert_locked_or_snapshotted();
349       return (_deps_dyn != nullptr ? _deps_dyn->length()
350               : _deps   != nullptr ? _deps->length()
351               : 0);
352     }
353     E* adr_at(int i) const {

747   bool _was_toplevel;
748   // metadata snapshots of final state:
749   MethodCounters* _final_counters;
750   MethodData*     _final_profile;
751 
752   MethodTrainingData();
753   MethodTrainingData(Method* method, KlassTrainingData* ktd) : TrainingData(method) {
754     _klass = ktd;
755     _holder = method;
756     for (int i = 0; i < CompLevel_count - 1; i++) {
757       _last_toplevel_compiles[i] = nullptr;
758     }
759     _highest_top_level = CompLevel_none;
760     _level_mask = 0;
761     _was_toplevel = false;
762   }
763 
764   static int level_mask(int level) {
765     return ((level & 0xF) != level ? 0 : 1 << level);
766   }
767   static CompLevel highest_level(int mask) {
768     if (mask == 0)  return (CompLevel) 0;
769     int diff = (count_leading_zeros(level_mask(0)) - count_leading_zeros(mask));
770     return (CompLevel) diff;
771   }
772 
773  public:
774   KlassTrainingData* klass()  const { return _klass; }
775   bool has_holder()           const { return _holder != nullptr; }
776   Method* holder()            const { return _holder; }
777   bool only_inlined()         const { return !_was_toplevel; }
778   bool saw_level(CompLevel l) const { return (_level_mask & level_mask(l)) != 0; }
779   int highest_level()         const { return highest_level(_level_mask); }
780   int highest_top_level()     const { return _highest_top_level; }
781   MethodData* final_profile() const { return _final_profile; }
782 
783   Symbol* name() const {
784     precond(has_holder());
785     return holder()->name();
786   }
787   Symbol* signature() const {
788     precond(has_holder());
789     return holder()->signature();
790   }
791 
792   CompileTrainingData* last_toplevel_compile(int level) const {
793     if (level > CompLevel_none) {
794       return _last_toplevel_compiles[level - 1];
795     }
796     return nullptr;
797   }
798 
799   void notice_compilation(int level, bool inlined = false) {
< prev index next >