< 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/classLoaderData.hpp"
 30 #include "classfile/compactHashtable.hpp"
 31 #include "compiler/compilerDefinitions.hpp"
 32 #include "compiler/compiler_globals.hpp"
 33 #include "memory/allocation.hpp"
 34 #include "memory/metaspaceClosure.hpp"
 35 #include "oops/instanceKlass.hpp"
 36 #include "oops/method.hpp"
 37 #include "runtime/handles.hpp"
 38 #include "runtime/mutexLocker.hpp"

 39 #include "utilities/resizeableResourceHash.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.

292     if (have_data()) {
293       archived_training_data_dictionary()->iterate(fn);
294     }
295     if (need_data()) {
296       training_data_set()->iterate(fn);
297     }
298   }
299 
300   virtual MethodTrainingData*   as_MethodTrainingData()  const { return nullptr; }
301   virtual KlassTrainingData*    as_KlassTrainingData()   const { return nullptr; }
302   virtual CompileTrainingData*  as_CompileTrainingData() const { return nullptr; }
303   bool is_MethodTrainingData()  const { return as_MethodTrainingData()  != nullptr; }
304   bool is_KlassTrainingData()   const { return as_KlassTrainingData()   != nullptr; }
305   bool is_CompileTrainingData() const { return as_CompileTrainingData() != nullptr; }
306 
307   virtual void prepare(Visitor& visitor) = 0;
308   virtual void cleanup(Visitor& visitor) = 0;
309 
310   static void initialize() NOT_CDS_RETURN;
311 
312   static void verify();
313 
314   // Widget for recording dependencies, as an N-to-M graph relation,
315   // possibly cyclic.
316   template<typename E>
317   class DepList : public StackObj {
318     GrowableArrayCHeap<E, mtCompiler>* _deps_dyn;
319     Array<E>*                          _deps;
320   public:
321     DepList() {
322       _deps_dyn = nullptr;
323       _deps = nullptr;
324     }
325 
326     int length() const {
327       return (_deps_dyn != nullptr ? _deps_dyn->length()
328               : _deps   != nullptr ? _deps->length()
329               : 0);
330     }
331     E* adr_at(int i) const {
332       return (_deps_dyn != nullptr ? _deps_dyn->adr_at(i)

720   bool _was_toplevel;
721   // metadata snapshots of final state:
722   MethodCounters* _final_counters;
723   MethodData*     _final_profile;
724 
725   MethodTrainingData();
726   MethodTrainingData(Method* method, KlassTrainingData* ktd) : TrainingData(method) {
727     _klass = ktd;
728     _holder = method;
729     for (int i = 0; i < CompLevel_count - 1; i++) {
730       _last_toplevel_compiles[i] = nullptr;
731     }
732     _highest_top_level = CompLevel_none;
733     _level_mask = 0;
734     _was_toplevel = false;
735   }
736 
737   static int level_mask(int level) {
738     return ((level & 0xF) != level ? 0 : 1 << level);
739   }





740 
741  public:
742   KlassTrainingData* klass()  const { return _klass; }
743   bool has_holder()           const { return _holder != nullptr; }
744   Method* holder()            const { return _holder; }
745   bool only_inlined()         const { return !_was_toplevel; }
746   bool saw_level(CompLevel l) const { return (_level_mask & level_mask(l)) != 0; }

747   int highest_top_level()     const { return _highest_top_level; }
748   MethodData* final_profile() const { return _final_profile; }
749 
750   Symbol* name() const {
751     precond(has_holder());
752     return holder()->name();
753   }
754   Symbol* signature() const {
755     precond(has_holder());
756     return holder()->signature();
757   }
758 
759   CompileTrainingData* last_toplevel_compile(int level) const {
760     if (level > CompLevel_none) {
761       return _last_toplevel_compiles[level - 1];
762     }
763     return nullptr;
764   }
765 
766   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/classLoaderData.hpp"
 30 #include "classfile/compactHashtable.hpp"
 31 #include "compiler/compilerDefinitions.hpp"
 32 #include "compiler/compiler_globals.hpp"
 33 #include "memory/allocation.hpp"
 34 #include "memory/metaspaceClosure.hpp"
 35 #include "oops/instanceKlass.hpp"
 36 #include "oops/method.hpp"
 37 #include "runtime/handles.hpp"
 38 #include "runtime/mutexLocker.hpp"
 39 #include "utilities/count_leading_zeros.hpp"
 40 #include "utilities/resizeableResourceHash.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.

293     if (have_data()) {
294       archived_training_data_dictionary()->iterate(fn);
295     }
296     if (need_data()) {
297       training_data_set()->iterate(fn);
298     }
299   }
300 
301   virtual MethodTrainingData*   as_MethodTrainingData()  const { return nullptr; }
302   virtual KlassTrainingData*    as_KlassTrainingData()   const { return nullptr; }
303   virtual CompileTrainingData*  as_CompileTrainingData() const { return nullptr; }
304   bool is_MethodTrainingData()  const { return as_MethodTrainingData()  != nullptr; }
305   bool is_KlassTrainingData()   const { return as_KlassTrainingData()   != nullptr; }
306   bool is_CompileTrainingData() const { return as_CompileTrainingData() != nullptr; }
307 
308   virtual void prepare(Visitor& visitor) = 0;
309   virtual void cleanup(Visitor& visitor) = 0;
310 
311   static void initialize() NOT_CDS_RETURN;
312 
313   static void verify() NOT_CDS_RETURN;
314 
315   // Widget for recording dependencies, as an N-to-M graph relation,
316   // possibly cyclic.
317   template<typename E>
318   class DepList : public StackObj {
319     GrowableArrayCHeap<E, mtCompiler>* _deps_dyn;
320     Array<E>*                          _deps;
321   public:
322     DepList() {
323       _deps_dyn = nullptr;
324       _deps = nullptr;
325     }
326 
327     int length() const {
328       return (_deps_dyn != nullptr ? _deps_dyn->length()
329               : _deps   != nullptr ? _deps->length()
330               : 0);
331     }
332     E* adr_at(int i) const {
333       return (_deps_dyn != nullptr ? _deps_dyn->adr_at(i)

721   bool _was_toplevel;
722   // metadata snapshots of final state:
723   MethodCounters* _final_counters;
724   MethodData*     _final_profile;
725 
726   MethodTrainingData();
727   MethodTrainingData(Method* method, KlassTrainingData* ktd) : TrainingData(method) {
728     _klass = ktd;
729     _holder = method;
730     for (int i = 0; i < CompLevel_count - 1; i++) {
731       _last_toplevel_compiles[i] = nullptr;
732     }
733     _highest_top_level = CompLevel_none;
734     _level_mask = 0;
735     _was_toplevel = false;
736   }
737 
738   static int level_mask(int level) {
739     return ((level & 0xF) != level ? 0 : 1 << level);
740   }
741   static CompLevel highest_level(int mask) {
742     if (mask == 0)  return (CompLevel) 0;
743     int diff = (count_leading_zeros(level_mask(0)) - count_leading_zeros(mask));
744     return (CompLevel) diff;
745   }
746 
747  public:
748   KlassTrainingData* klass()  const { return _klass; }
749   bool has_holder()           const { return _holder != nullptr; }
750   Method* holder()            const { return _holder; }
751   bool only_inlined()         const { return !_was_toplevel; }
752   bool saw_level(CompLevel l) const { return (_level_mask & level_mask(l)) != 0; }
753   int highest_level()         const { return highest_level(_level_mask); }
754   int highest_top_level()     const { return _highest_top_level; }
755   MethodData* final_profile() const { return _final_profile; }
756 
757   Symbol* name() const {
758     precond(has_holder());
759     return holder()->name();
760   }
761   Symbol* signature() const {
762     precond(has_holder());
763     return holder()->signature();
764   }
765 
766   CompileTrainingData* last_toplevel_compile(int level) const {
767     if (level > CompLevel_none) {
768       return _last_toplevel_compiles[level - 1];
769     }
770     return nullptr;
771   }
772 
773   void notice_compilation(int level, bool inlined = false) {
< prev index next >