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 {
751 int _invocation_count;
752 int _backedge_count;
753
754 MethodTrainingData();
755 MethodTrainingData(Method* method, KlassTrainingData* ktd) : TrainingData(method) {
756 _klass = ktd;
757 _holder = method;
758 for (int i = 0; i < CompLevel_count - 1; i++) {
759 _last_toplevel_compiles[i] = nullptr;
760 }
761 _highest_top_level = CompLevel_none;
762 _level_mask = 0;
763 _was_toplevel = false;
764 _invocation_count = 0;
765 _backedge_count = 0;
766 }
767
768 static int level_mask(int level) {
769 return ((level & 0xF) != level ? 0 : 1 << level);
770 }
771
772 public:
773 KlassTrainingData* klass() const { return _klass; }
774 bool has_holder() const { return _holder != nullptr; }
775 Method* holder() const { return _holder; }
776 bool only_inlined() const { return !_was_toplevel; }
777 bool saw_level(CompLevel l) const { return (_level_mask & level_mask(l)) != 0; }
778 int highest_top_level() const { return _highest_top_level; }
779 MethodData* final_profile() const { return _final_profile; }
780 int invocation_count() const { return _invocation_count; }
781 int backedge_count() const { return _backedge_count; }
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 }
|
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 {
752 int _invocation_count;
753 int _backedge_count;
754
755 MethodTrainingData();
756 MethodTrainingData(Method* method, KlassTrainingData* ktd) : TrainingData(method) {
757 _klass = ktd;
758 _holder = method;
759 for (int i = 0; i < CompLevel_count - 1; i++) {
760 _last_toplevel_compiles[i] = nullptr;
761 }
762 _highest_top_level = CompLevel_none;
763 _level_mask = 0;
764 _was_toplevel = false;
765 _invocation_count = 0;
766 _backedge_count = 0;
767 }
768
769 static int level_mask(int level) {
770 return ((level & 0xF) != level ? 0 : 1 << level);
771 }
772 static CompLevel highest_level(int mask) {
773 if (mask == 0) return (CompLevel) 0;
774 int diff = (count_leading_zeros(level_mask(0)) - count_leading_zeros(mask));
775 return (CompLevel) diff;
776 }
777
778 public:
779 KlassTrainingData* klass() const { return _klass; }
780 bool has_holder() const { return _holder != nullptr; }
781 Method* holder() const { return _holder; }
782 bool only_inlined() const { return !_was_toplevel; }
783 bool saw_level(CompLevel l) const { return (_level_mask & level_mask(l)) != 0; }
784 int highest_level() const { return highest_level(_level_mask); }
785 int highest_top_level() const { return _highest_top_level; }
786 MethodData* final_profile() const { return _final_profile; }
787 int invocation_count() const { return _invocation_count; }
788 int backedge_count() const { return _backedge_count; }
789
790 Symbol* name() const {
791 precond(has_holder());
792 return holder()->name();
793 }
794 Symbol* signature() const {
795 precond(has_holder());
796 return holder()->signature();
797 }
798
799 CompileTrainingData* last_toplevel_compile(int level) const {
800 if (level > CompLevel_none) {
801 return _last_toplevel_compiles[level - 1];
802 }
803 return nullptr;
804 }
|