111
112 enum {
113 cell_size = sizeof(intptr_t)
114 };
115
116 // Tag values
117 enum {
118 no_tag,
119 bit_data_tag,
120 counter_data_tag,
121 jump_data_tag,
122 receiver_type_data_tag,
123 virtual_call_data_tag,
124 ret_data_tag,
125 branch_data_tag,
126 multi_branch_data_tag,
127 arg_info_data_tag,
128 call_type_data_tag,
129 virtual_call_type_data_tag,
130 parameters_type_data_tag,
131 speculative_trap_data_tag
132 };
133
134 enum {
135 // The trap state breaks down as [recompile:1 | reason:31].
136 // This further breakdown is defined in deoptimization.cpp.
137 // See Deoptimization::trap_state_reason for an assert that
138 // trap_bits is big enough to hold reasons < Reason_RECORDED_LIMIT.
139 //
140 // The trap_state is collected only if ProfileTraps is true.
141 trap_bits = 1+31, // 31: enough to distinguish [0..Reason_RECORDED_LIMIT].
142 trap_mask = -1,
143 first_flag = 0
144 };
145
146 // Size computation
147 static int header_size_in_bytes() {
148 return header_size_in_cells() * cell_size;
149 }
150 static int header_size_in_cells() {
151 return LP64_ONLY(1) NOT_LP64(2);
247 return DataLayout::compute_size_in_bytes(cells);
248 }
249 int cell_count();
250
251 // GC support
252 void clean_weak_klass_links(bool always_clean);
253 };
254
255
256 // ProfileData class hierarchy
257 class ProfileData;
258 class BitData;
259 class CounterData;
260 class ReceiverTypeData;
261 class VirtualCallData;
262 class VirtualCallTypeData;
263 class RetData;
264 class CallTypeData;
265 class JumpData;
266 class BranchData;
267 class ArrayData;
268 class MultiBranchData;
269 class ArgInfoData;
270 class ParametersTypeData;
271 class SpeculativeTrapData;
272
273 // ProfileData
274 //
275 // A ProfileData object is created to refer to a section of profiling
276 // data in a structured way.
277 class ProfileData : public ResourceObj {
278 friend class TypeEntries;
279 friend class ReturnTypeEntry;
280 friend class TypeStackSlotEntries;
281 private:
282 enum {
283 tab_width_one = 16,
284 tab_width_two = 36
285 };
286
287 // This is a pointer to a section of profiling data.
288 DataLayout* _data;
289
290 char* print_data_on_helper(const MethodData* md) const;
291
292 protected:
293 DataLayout* data() { return _data; }
294 const DataLayout* data() const { return _data; }
295
296 enum {
297 cell_size = DataLayout::cell_size
298 };
299
380 }
381 void set_trap_state(int new_state) {
382 data()->set_trap_state(new_state);
383 }
384
385 // Type checking
386 virtual bool is_BitData() const { return false; }
387 virtual bool is_CounterData() const { return false; }
388 virtual bool is_JumpData() const { return false; }
389 virtual bool is_ReceiverTypeData()const { return false; }
390 virtual bool is_VirtualCallData() const { return false; }
391 virtual bool is_RetData() const { return false; }
392 virtual bool is_BranchData() const { return false; }
393 virtual bool is_ArrayData() const { return false; }
394 virtual bool is_MultiBranchData() const { return false; }
395 virtual bool is_ArgInfoData() const { return false; }
396 virtual bool is_CallTypeData() const { return false; }
397 virtual bool is_VirtualCallTypeData()const { return false; }
398 virtual bool is_ParametersTypeData() const { return false; }
399 virtual bool is_SpeculativeTrapData()const { return false; }
400
401
402 BitData* as_BitData() const {
403 assert(is_BitData(), "wrong type");
404 return is_BitData() ? (BitData*) this : NULL;
405 }
406 CounterData* as_CounterData() const {
407 assert(is_CounterData(), "wrong type");
408 return is_CounterData() ? (CounterData*) this : NULL;
409 }
410 JumpData* as_JumpData() const {
411 assert(is_JumpData(), "wrong type");
412 return is_JumpData() ? (JumpData*) this : NULL;
413 }
414 ReceiverTypeData* as_ReceiverTypeData() const {
415 assert(is_ReceiverTypeData(), "wrong type");
416 return is_ReceiverTypeData() ? (ReceiverTypeData*)this : NULL;
417 }
418 VirtualCallData* as_VirtualCallData() const {
419 assert(is_VirtualCallData(), "wrong type");
438 ArgInfoData* as_ArgInfoData() const {
439 assert(is_ArgInfoData(), "wrong type");
440 return is_ArgInfoData() ? (ArgInfoData*)this : NULL;
441 }
442 CallTypeData* as_CallTypeData() const {
443 assert(is_CallTypeData(), "wrong type");
444 return is_CallTypeData() ? (CallTypeData*)this : NULL;
445 }
446 VirtualCallTypeData* as_VirtualCallTypeData() const {
447 assert(is_VirtualCallTypeData(), "wrong type");
448 return is_VirtualCallTypeData() ? (VirtualCallTypeData*)this : NULL;
449 }
450 ParametersTypeData* as_ParametersTypeData() const {
451 assert(is_ParametersTypeData(), "wrong type");
452 return is_ParametersTypeData() ? (ParametersTypeData*)this : NULL;
453 }
454 SpeculativeTrapData* as_SpeculativeTrapData() const {
455 assert(is_SpeculativeTrapData(), "wrong type");
456 return is_SpeculativeTrapData() ? (SpeculativeTrapData*)this : NULL;
457 }
458
459
460 // Subclass specific initialization
461 virtual void post_initialize(BytecodeStream* stream, MethodData* mdo) {}
462
463 // GC support
464 virtual void clean_weak_klass_links(bool always_clean) {}
465
466 // CI translation: ProfileData can represent both MethodDataOop data
467 // as well as CIMethodData data. This function is provided for translating
468 // an oop in a ProfileData to the ci equivalent. Generally speaking,
469 // most ProfileData don't require any translation, so we provide the null
470 // translation here, and the required translators are in the ci subclasses.
471 virtual void translate_from(const ProfileData* data) {}
472
473 virtual void print_data_on(outputStream* st, const char* extra = NULL) const {
474 ShouldNotReachHere();
475 }
476
477 void print_data_on(outputStream* st, const MethodData* md) const;
592 // branch. It is a counter, used for counting the number of branches,
593 // plus a data displacement, used for realigning the data pointer to
594 // the corresponding target bci.
595 class JumpData : public ProfileData {
596 friend class VMStructs;
597 friend class JVMCIVMStructs;
598 protected:
599 enum {
600 taken_off_set,
601 displacement_off_set,
602 jump_cell_count
603 };
604
605 void set_displacement(int displacement) {
606 set_int_at(displacement_off_set, displacement);
607 }
608
609 public:
610 JumpData(DataLayout* layout) : ProfileData(layout) {
611 assert(layout->tag() == DataLayout::jump_data_tag ||
612 layout->tag() == DataLayout::branch_data_tag, "wrong type");
613 }
614
615 virtual bool is_JumpData() const { return true; }
616
617 static int static_cell_count() {
618 return jump_cell_count;
619 }
620
621 virtual int cell_count() const {
622 return static_cell_count();
623 }
624
625 // Direct accessor
626 uint taken() const {
627 return uint_at(taken_off_set);
628 }
629
630 void set_taken(uint cnt) {
631 set_uint_at(taken_off_set, cnt);
632 }
828 static ByteSize per_arg_size() {
829 return in_ByteSize(per_arg_cell_count * DataLayout::cell_size);
830 }
831
832 static int per_arg_count() {
833 return per_arg_cell_count;
834 }
835
836 ByteSize type_offset(int i) const {
837 return DataLayout::cell_offset(type_offset_in_cells(i));
838 }
839
840 // GC support
841 void clean_weak_klass_links(bool always_clean);
842
843 void print_data_on(outputStream* st) const;
844 };
845
846 // Type entry used for return from a call. A single cell to record the
847 // type.
848 class ReturnTypeEntry : public TypeEntries {
849
850 private:
851 enum {
852 cell_count = 1
853 };
854
855 public:
856 ReturnTypeEntry(int base_off)
857 : TypeEntries(base_off) {}
858
859 void post_initialize() {
860 set_type(type_none());
861 }
862
863 intptr_t type() const {
864 return _pd->intptr_at(_base_off);
865 }
866
867 void set_type(intptr_t k) {
868 _pd->set_intptr_at(_base_off, k);
869 }
870
871 static int static_cell_count() {
872 return cell_count;
873 }
874
875 static ByteSize size() {
876 return in_ByteSize(cell_count * DataLayout::cell_size);
877 }
878
879 ByteSize type_offset() {
880 return DataLayout::cell_offset(_base_off);
881 }
882
883 // GC support
884 void clean_weak_klass_links(bool always_clean);
885
886 void print_data_on(outputStream* st) const;
887 };
888
889 // Entries to collect type information at a call: contains arguments
890 // (TypeStackSlotEntries), a return type (ReturnTypeEntry) and a
891 // number of cells. Because the number of cells for the return type is
892 // smaller than the number of cells for the type of an arguments, the
893 // number of cells is used to tell how many arguments are profiled and
894 // whether a return value is profiled. See has_arguments() and
895 // has_return().
896 class TypeEntriesAtCall {
897 private:
898 static int stack_slot_local_offset(int i) {
899 return header_cell_count() + TypeStackSlotEntries::stack_slot_local_offset(i);
900 }
901
902 static int argument_type_local_offset(int i) {
903 return header_cell_count() + TypeStackSlotEntries::type_local_offset(i);
904 }
905
906 public:
907
908 static int header_cell_count() {
909 return 1;
910 }
924 static bool return_profiling_enabled();
925
926 // Code generation support
927 static ByteSize cell_count_offset() {
928 return in_ByteSize(cell_count_local_offset() * DataLayout::cell_size);
929 }
930
931 static ByteSize args_data_offset() {
932 return in_ByteSize(header_cell_count() * DataLayout::cell_size);
933 }
934
935 static ByteSize stack_slot_offset(int i) {
936 return in_ByteSize(stack_slot_local_offset(i) * DataLayout::cell_size);
937 }
938
939 static ByteSize argument_type_offset(int i) {
940 return in_ByteSize(argument_type_local_offset(i) * DataLayout::cell_size);
941 }
942
943 static ByteSize return_only_size() {
944 return ReturnTypeEntry::size() + in_ByteSize(header_cell_count() * DataLayout::cell_size);
945 }
946
947 };
948
949 // CallTypeData
950 //
951 // A CallTypeData is used to access profiling information about a non
952 // virtual call for which we collect type information about arguments
953 // and return value.
954 class CallTypeData : public CounterData {
955 private:
956 // entries for arguments if any
957 TypeStackSlotEntries _args;
958 // entry for return type if any
959 ReturnTypeEntry _ret;
960
961 int cell_count_global_offset() const {
962 return CounterData::static_cell_count() + TypeEntriesAtCall::cell_count_local_offset();
963 }
964
965 // number of cells not counting the header
966 int cell_count_no_header() const {
967 return uint_at(cell_count_global_offset());
968 }
969
970 void check_number_of_arguments(int total) {
971 assert(number_of_arguments() == total, "should be set in DataLayout::initialize");
972 }
973
974 public:
975 CallTypeData(DataLayout* layout) :
976 CounterData(layout),
977 _args(CounterData::static_cell_count()+TypeEntriesAtCall::header_cell_count(), number_of_arguments()),
978 _ret(cell_count() - ReturnTypeEntry::static_cell_count())
979 {
980 assert(layout->tag() == DataLayout::call_type_data_tag, "wrong type");
981 // Some compilers (VC++) don't want this passed in member initialization list
982 _args.set_profile_data(this);
983 _ret.set_profile_data(this);
984 }
985
986 const TypeStackSlotEntries* args() const {
987 assert(has_arguments(), "no profiling of arguments");
988 return &_args;
989 }
990
991 const ReturnTypeEntry* ret() const {
992 assert(has_return(), "no profiling of return value");
993 return &_ret;
994 }
995
996 virtual bool is_CallTypeData() const { return true; }
997
998 static int static_cell_count() {
999 return -1;
1000 }
1001
1002 static int compute_cell_count(BytecodeStream* stream) {
1003 return CounterData::static_cell_count() + TypeEntriesAtCall::compute_cell_count(stream);
1004 }
1005
1006 static void initialize(DataLayout* dl, int cell_count) {
1007 TypeEntriesAtCall::initialize(dl, CounterData::static_cell_count(), cell_count);
1008 }
1009
1010 virtual void post_initialize(BytecodeStream* stream, MethodData* mdo);
1011
1242
1243 // Direct accessors
1244 static ByteSize virtual_call_data_size() {
1245 return cell_offset(static_cell_count());
1246 }
1247
1248 void print_method_data_on(outputStream* st) const NOT_JVMCI_RETURN;
1249 void print_data_on(outputStream* st, const char* extra = NULL) const;
1250 };
1251
1252 // VirtualCallTypeData
1253 //
1254 // A VirtualCallTypeData is used to access profiling information about
1255 // a virtual call for which we collect type information about
1256 // arguments and return value.
1257 class VirtualCallTypeData : public VirtualCallData {
1258 private:
1259 // entries for arguments if any
1260 TypeStackSlotEntries _args;
1261 // entry for return type if any
1262 ReturnTypeEntry _ret;
1263
1264 int cell_count_global_offset() const {
1265 return VirtualCallData::static_cell_count() + TypeEntriesAtCall::cell_count_local_offset();
1266 }
1267
1268 // number of cells not counting the header
1269 int cell_count_no_header() const {
1270 return uint_at(cell_count_global_offset());
1271 }
1272
1273 void check_number_of_arguments(int total) {
1274 assert(number_of_arguments() == total, "should be set in DataLayout::initialize");
1275 }
1276
1277 public:
1278 VirtualCallTypeData(DataLayout* layout) :
1279 VirtualCallData(layout),
1280 _args(VirtualCallData::static_cell_count()+TypeEntriesAtCall::header_cell_count(), number_of_arguments()),
1281 _ret(cell_count() - ReturnTypeEntry::static_cell_count())
1282 {
1283 assert(layout->tag() == DataLayout::virtual_call_type_data_tag, "wrong type");
1284 // Some compilers (VC++) don't want this passed in member initialization list
1285 _args.set_profile_data(this);
1286 _ret.set_profile_data(this);
1287 }
1288
1289 const TypeStackSlotEntries* args() const {
1290 assert(has_arguments(), "no profiling of arguments");
1291 return &_args;
1292 }
1293
1294 const ReturnTypeEntry* ret() const {
1295 assert(has_return(), "no profiling of return value");
1296 return &_ret;
1297 }
1298
1299 virtual bool is_VirtualCallTypeData() const { return true; }
1300
1301 static int static_cell_count() {
1302 return -1;
1303 }
1304
1305 static int compute_cell_count(BytecodeStream* stream) {
1306 return VirtualCallData::static_cell_count() + TypeEntriesAtCall::compute_cell_count(stream);
1307 }
1308
1309 static void initialize(DataLayout* dl, int cell_count) {
1310 TypeEntriesAtCall::initialize(dl, VirtualCallData::static_cell_count(), cell_count);
1311 }
1312
1313 virtual void post_initialize(BytecodeStream* stream, MethodData* mdo);
1314
1476 // BranchData
1477 //
1478 // A BranchData is used to access profiling data for a two-way branch.
1479 // It consists of taken and not_taken counts as well as a data displacement
1480 // for the taken case.
1481 class BranchData : public JumpData {
1482 friend class VMStructs;
1483 friend class JVMCIVMStructs;
1484 protected:
1485 enum {
1486 not_taken_off_set = jump_cell_count,
1487 branch_cell_count
1488 };
1489
1490 void set_displacement(int displacement) {
1491 set_int_at(displacement_off_set, displacement);
1492 }
1493
1494 public:
1495 BranchData(DataLayout* layout) : JumpData(layout) {
1496 assert(layout->tag() == DataLayout::branch_data_tag, "wrong type");
1497 }
1498
1499 virtual bool is_BranchData() const { return true; }
1500
1501 static int static_cell_count() {
1502 return branch_cell_count;
1503 }
1504
1505 virtual int cell_count() const {
1506 return static_cell_count();
1507 }
1508
1509 // Direct accessor
1510 uint not_taken() const {
1511 return uint_at(not_taken_off_set);
1512 }
1513
1514 void set_not_taken(uint cnt) {
1515 set_uint_at(not_taken_off_set, cnt);
1516 }
1830 }
1831
1832 virtual int cell_count() const {
1833 return static_cell_count();
1834 }
1835
1836 // Direct accessor
1837 Method* method() const {
1838 return (Method*)intptr_at(speculative_trap_method);
1839 }
1840
1841 void set_method(Method* m) {
1842 assert(!m->is_old(), "cannot add old methods");
1843 set_intptr_at(speculative_trap_method, (intptr_t)m);
1844 }
1845
1846 static ByteSize method_offset() {
1847 return cell_offset(speculative_trap_method);
1848 }
1849
1850 virtual void print_data_on(outputStream* st, const char* extra = NULL) const;
1851 };
1852
1853 // MethodData*
1854 //
1855 // A MethodData* holds information which has been collected about
1856 // a method. Its layout looks like this:
1857 //
1858 // -----------------------------
1859 // | header |
1860 // | klass |
1861 // -----------------------------
1862 // | method |
1863 // | size of the MethodData* |
1864 // -----------------------------
1865 // | Data entries... |
1866 // | (variable size) |
1867 // | |
1868 // . .
1869 // . .
|
111
112 enum {
113 cell_size = sizeof(intptr_t)
114 };
115
116 // Tag values
117 enum {
118 no_tag,
119 bit_data_tag,
120 counter_data_tag,
121 jump_data_tag,
122 receiver_type_data_tag,
123 virtual_call_data_tag,
124 ret_data_tag,
125 branch_data_tag,
126 multi_branch_data_tag,
127 arg_info_data_tag,
128 call_type_data_tag,
129 virtual_call_type_data_tag,
130 parameters_type_data_tag,
131 speculative_trap_data_tag,
132 array_load_store_data_tag,
133 acmp_data_tag
134 };
135
136 enum {
137 // The trap state breaks down as [recompile:1 | reason:31].
138 // This further breakdown is defined in deoptimization.cpp.
139 // See Deoptimization::trap_state_reason for an assert that
140 // trap_bits is big enough to hold reasons < Reason_RECORDED_LIMIT.
141 //
142 // The trap_state is collected only if ProfileTraps is true.
143 trap_bits = 1+31, // 31: enough to distinguish [0..Reason_RECORDED_LIMIT].
144 trap_mask = -1,
145 first_flag = 0
146 };
147
148 // Size computation
149 static int header_size_in_bytes() {
150 return header_size_in_cells() * cell_size;
151 }
152 static int header_size_in_cells() {
153 return LP64_ONLY(1) NOT_LP64(2);
249 return DataLayout::compute_size_in_bytes(cells);
250 }
251 int cell_count();
252
253 // GC support
254 void clean_weak_klass_links(bool always_clean);
255 };
256
257
258 // ProfileData class hierarchy
259 class ProfileData;
260 class BitData;
261 class CounterData;
262 class ReceiverTypeData;
263 class VirtualCallData;
264 class VirtualCallTypeData;
265 class RetData;
266 class CallTypeData;
267 class JumpData;
268 class BranchData;
269 class ACmpData;
270 class ArrayData;
271 class MultiBranchData;
272 class ArgInfoData;
273 class ParametersTypeData;
274 class SpeculativeTrapData;
275 class ArrayLoadStoreData;
276
277 // ProfileData
278 //
279 // A ProfileData object is created to refer to a section of profiling
280 // data in a structured way.
281 class ProfileData : public ResourceObj {
282 friend class TypeEntries;
283 friend class SingleTypeEntry;
284 friend class TypeStackSlotEntries;
285 private:
286 enum {
287 tab_width_one = 16,
288 tab_width_two = 36
289 };
290
291 // This is a pointer to a section of profiling data.
292 DataLayout* _data;
293
294 char* print_data_on_helper(const MethodData* md) const;
295
296 protected:
297 DataLayout* data() { return _data; }
298 const DataLayout* data() const { return _data; }
299
300 enum {
301 cell_size = DataLayout::cell_size
302 };
303
384 }
385 void set_trap_state(int new_state) {
386 data()->set_trap_state(new_state);
387 }
388
389 // Type checking
390 virtual bool is_BitData() const { return false; }
391 virtual bool is_CounterData() const { return false; }
392 virtual bool is_JumpData() const { return false; }
393 virtual bool is_ReceiverTypeData()const { return false; }
394 virtual bool is_VirtualCallData() const { return false; }
395 virtual bool is_RetData() const { return false; }
396 virtual bool is_BranchData() const { return false; }
397 virtual bool is_ArrayData() const { return false; }
398 virtual bool is_MultiBranchData() const { return false; }
399 virtual bool is_ArgInfoData() const { return false; }
400 virtual bool is_CallTypeData() const { return false; }
401 virtual bool is_VirtualCallTypeData()const { return false; }
402 virtual bool is_ParametersTypeData() const { return false; }
403 virtual bool is_SpeculativeTrapData()const { return false; }
404 virtual bool is_ArrayLoadStoreData() const { return false; }
405 virtual bool is_ACmpData() const { return false; }
406
407
408 BitData* as_BitData() const {
409 assert(is_BitData(), "wrong type");
410 return is_BitData() ? (BitData*) this : NULL;
411 }
412 CounterData* as_CounterData() const {
413 assert(is_CounterData(), "wrong type");
414 return is_CounterData() ? (CounterData*) this : NULL;
415 }
416 JumpData* as_JumpData() const {
417 assert(is_JumpData(), "wrong type");
418 return is_JumpData() ? (JumpData*) this : NULL;
419 }
420 ReceiverTypeData* as_ReceiverTypeData() const {
421 assert(is_ReceiverTypeData(), "wrong type");
422 return is_ReceiverTypeData() ? (ReceiverTypeData*)this : NULL;
423 }
424 VirtualCallData* as_VirtualCallData() const {
425 assert(is_VirtualCallData(), "wrong type");
444 ArgInfoData* as_ArgInfoData() const {
445 assert(is_ArgInfoData(), "wrong type");
446 return is_ArgInfoData() ? (ArgInfoData*)this : NULL;
447 }
448 CallTypeData* as_CallTypeData() const {
449 assert(is_CallTypeData(), "wrong type");
450 return is_CallTypeData() ? (CallTypeData*)this : NULL;
451 }
452 VirtualCallTypeData* as_VirtualCallTypeData() const {
453 assert(is_VirtualCallTypeData(), "wrong type");
454 return is_VirtualCallTypeData() ? (VirtualCallTypeData*)this : NULL;
455 }
456 ParametersTypeData* as_ParametersTypeData() const {
457 assert(is_ParametersTypeData(), "wrong type");
458 return is_ParametersTypeData() ? (ParametersTypeData*)this : NULL;
459 }
460 SpeculativeTrapData* as_SpeculativeTrapData() const {
461 assert(is_SpeculativeTrapData(), "wrong type");
462 return is_SpeculativeTrapData() ? (SpeculativeTrapData*)this : NULL;
463 }
464 ArrayLoadStoreData* as_ArrayLoadStoreData() const {
465 assert(is_ArrayLoadStoreData(), "wrong type");
466 return is_ArrayLoadStoreData() ? (ArrayLoadStoreData*)this : NULL;
467 }
468 ACmpData* as_ACmpData() const {
469 assert(is_ACmpData(), "wrong type");
470 return is_ACmpData() ? (ACmpData*)this : NULL;
471 }
472
473
474 // Subclass specific initialization
475 virtual void post_initialize(BytecodeStream* stream, MethodData* mdo) {}
476
477 // GC support
478 virtual void clean_weak_klass_links(bool always_clean) {}
479
480 // CI translation: ProfileData can represent both MethodDataOop data
481 // as well as CIMethodData data. This function is provided for translating
482 // an oop in a ProfileData to the ci equivalent. Generally speaking,
483 // most ProfileData don't require any translation, so we provide the null
484 // translation here, and the required translators are in the ci subclasses.
485 virtual void translate_from(const ProfileData* data) {}
486
487 virtual void print_data_on(outputStream* st, const char* extra = NULL) const {
488 ShouldNotReachHere();
489 }
490
491 void print_data_on(outputStream* st, const MethodData* md) const;
606 // branch. It is a counter, used for counting the number of branches,
607 // plus a data displacement, used for realigning the data pointer to
608 // the corresponding target bci.
609 class JumpData : public ProfileData {
610 friend class VMStructs;
611 friend class JVMCIVMStructs;
612 protected:
613 enum {
614 taken_off_set,
615 displacement_off_set,
616 jump_cell_count
617 };
618
619 void set_displacement(int displacement) {
620 set_int_at(displacement_off_set, displacement);
621 }
622
623 public:
624 JumpData(DataLayout* layout) : ProfileData(layout) {
625 assert(layout->tag() == DataLayout::jump_data_tag ||
626 layout->tag() == DataLayout::branch_data_tag ||
627 layout->tag() == DataLayout::acmp_data_tag, "wrong type");
628 }
629
630 virtual bool is_JumpData() const { return true; }
631
632 static int static_cell_count() {
633 return jump_cell_count;
634 }
635
636 virtual int cell_count() const {
637 return static_cell_count();
638 }
639
640 // Direct accessor
641 uint taken() const {
642 return uint_at(taken_off_set);
643 }
644
645 void set_taken(uint cnt) {
646 set_uint_at(taken_off_set, cnt);
647 }
843 static ByteSize per_arg_size() {
844 return in_ByteSize(per_arg_cell_count * DataLayout::cell_size);
845 }
846
847 static int per_arg_count() {
848 return per_arg_cell_count;
849 }
850
851 ByteSize type_offset(int i) const {
852 return DataLayout::cell_offset(type_offset_in_cells(i));
853 }
854
855 // GC support
856 void clean_weak_klass_links(bool always_clean);
857
858 void print_data_on(outputStream* st) const;
859 };
860
861 // Type entry used for return from a call. A single cell to record the
862 // type.
863 class SingleTypeEntry : public TypeEntries {
864
865 private:
866 enum {
867 cell_count = 1
868 };
869
870 public:
871 SingleTypeEntry(int base_off)
872 : TypeEntries(base_off) {}
873
874 void post_initialize() {
875 set_type(type_none());
876 }
877
878 intptr_t type() const {
879 return _pd->intptr_at(_base_off);
880 }
881
882 void set_type(intptr_t k) {
883 _pd->set_intptr_at(_base_off, k);
884 }
885
886 static int static_cell_count() {
887 return cell_count;
888 }
889
890 static ByteSize size() {
891 return in_ByteSize(cell_count * DataLayout::cell_size);
892 }
893
894 ByteSize type_offset() {
895 return DataLayout::cell_offset(_base_off);
896 }
897
898 // GC support
899 void clean_weak_klass_links(bool always_clean);
900
901 void print_data_on(outputStream* st) const;
902 };
903
904 // Entries to collect type information at a call: contains arguments
905 // (TypeStackSlotEntries), a return type (SingleTypeEntry) and a
906 // number of cells. Because the number of cells for the return type is
907 // smaller than the number of cells for the type of an arguments, the
908 // number of cells is used to tell how many arguments are profiled and
909 // whether a return value is profiled. See has_arguments() and
910 // has_return().
911 class TypeEntriesAtCall {
912 private:
913 static int stack_slot_local_offset(int i) {
914 return header_cell_count() + TypeStackSlotEntries::stack_slot_local_offset(i);
915 }
916
917 static int argument_type_local_offset(int i) {
918 return header_cell_count() + TypeStackSlotEntries::type_local_offset(i);
919 }
920
921 public:
922
923 static int header_cell_count() {
924 return 1;
925 }
939 static bool return_profiling_enabled();
940
941 // Code generation support
942 static ByteSize cell_count_offset() {
943 return in_ByteSize(cell_count_local_offset() * DataLayout::cell_size);
944 }
945
946 static ByteSize args_data_offset() {
947 return in_ByteSize(header_cell_count() * DataLayout::cell_size);
948 }
949
950 static ByteSize stack_slot_offset(int i) {
951 return in_ByteSize(stack_slot_local_offset(i) * DataLayout::cell_size);
952 }
953
954 static ByteSize argument_type_offset(int i) {
955 return in_ByteSize(argument_type_local_offset(i) * DataLayout::cell_size);
956 }
957
958 static ByteSize return_only_size() {
959 return SingleTypeEntry::size() + in_ByteSize(header_cell_count() * DataLayout::cell_size);
960 }
961
962 };
963
964 // CallTypeData
965 //
966 // A CallTypeData is used to access profiling information about a non
967 // virtual call for which we collect type information about arguments
968 // and return value.
969 class CallTypeData : public CounterData {
970 private:
971 // entries for arguments if any
972 TypeStackSlotEntries _args;
973 // entry for return type if any
974 SingleTypeEntry _ret;
975
976 int cell_count_global_offset() const {
977 return CounterData::static_cell_count() + TypeEntriesAtCall::cell_count_local_offset();
978 }
979
980 // number of cells not counting the header
981 int cell_count_no_header() const {
982 return uint_at(cell_count_global_offset());
983 }
984
985 void check_number_of_arguments(int total) {
986 assert(number_of_arguments() == total, "should be set in DataLayout::initialize");
987 }
988
989 public:
990 CallTypeData(DataLayout* layout) :
991 CounterData(layout),
992 _args(CounterData::static_cell_count()+TypeEntriesAtCall::header_cell_count(), number_of_arguments()),
993 _ret(cell_count() - SingleTypeEntry::static_cell_count())
994 {
995 assert(layout->tag() == DataLayout::call_type_data_tag, "wrong type");
996 // Some compilers (VC++) don't want this passed in member initialization list
997 _args.set_profile_data(this);
998 _ret.set_profile_data(this);
999 }
1000
1001 const TypeStackSlotEntries* args() const {
1002 assert(has_arguments(), "no profiling of arguments");
1003 return &_args;
1004 }
1005
1006 const SingleTypeEntry* ret() const {
1007 assert(has_return(), "no profiling of return value");
1008 return &_ret;
1009 }
1010
1011 virtual bool is_CallTypeData() const { return true; }
1012
1013 static int static_cell_count() {
1014 return -1;
1015 }
1016
1017 static int compute_cell_count(BytecodeStream* stream) {
1018 return CounterData::static_cell_count() + TypeEntriesAtCall::compute_cell_count(stream);
1019 }
1020
1021 static void initialize(DataLayout* dl, int cell_count) {
1022 TypeEntriesAtCall::initialize(dl, CounterData::static_cell_count(), cell_count);
1023 }
1024
1025 virtual void post_initialize(BytecodeStream* stream, MethodData* mdo);
1026
1257
1258 // Direct accessors
1259 static ByteSize virtual_call_data_size() {
1260 return cell_offset(static_cell_count());
1261 }
1262
1263 void print_method_data_on(outputStream* st) const NOT_JVMCI_RETURN;
1264 void print_data_on(outputStream* st, const char* extra = NULL) const;
1265 };
1266
1267 // VirtualCallTypeData
1268 //
1269 // A VirtualCallTypeData is used to access profiling information about
1270 // a virtual call for which we collect type information about
1271 // arguments and return value.
1272 class VirtualCallTypeData : public VirtualCallData {
1273 private:
1274 // entries for arguments if any
1275 TypeStackSlotEntries _args;
1276 // entry for return type if any
1277 SingleTypeEntry _ret;
1278
1279 int cell_count_global_offset() const {
1280 return VirtualCallData::static_cell_count() + TypeEntriesAtCall::cell_count_local_offset();
1281 }
1282
1283 // number of cells not counting the header
1284 int cell_count_no_header() const {
1285 return uint_at(cell_count_global_offset());
1286 }
1287
1288 void check_number_of_arguments(int total) {
1289 assert(number_of_arguments() == total, "should be set in DataLayout::initialize");
1290 }
1291
1292 public:
1293 VirtualCallTypeData(DataLayout* layout) :
1294 VirtualCallData(layout),
1295 _args(VirtualCallData::static_cell_count()+TypeEntriesAtCall::header_cell_count(), number_of_arguments()),
1296 _ret(cell_count() - SingleTypeEntry::static_cell_count())
1297 {
1298 assert(layout->tag() == DataLayout::virtual_call_type_data_tag, "wrong type");
1299 // Some compilers (VC++) don't want this passed in member initialization list
1300 _args.set_profile_data(this);
1301 _ret.set_profile_data(this);
1302 }
1303
1304 const TypeStackSlotEntries* args() const {
1305 assert(has_arguments(), "no profiling of arguments");
1306 return &_args;
1307 }
1308
1309 const SingleTypeEntry* ret() const {
1310 assert(has_return(), "no profiling of return value");
1311 return &_ret;
1312 }
1313
1314 virtual bool is_VirtualCallTypeData() const { return true; }
1315
1316 static int static_cell_count() {
1317 return -1;
1318 }
1319
1320 static int compute_cell_count(BytecodeStream* stream) {
1321 return VirtualCallData::static_cell_count() + TypeEntriesAtCall::compute_cell_count(stream);
1322 }
1323
1324 static void initialize(DataLayout* dl, int cell_count) {
1325 TypeEntriesAtCall::initialize(dl, VirtualCallData::static_cell_count(), cell_count);
1326 }
1327
1328 virtual void post_initialize(BytecodeStream* stream, MethodData* mdo);
1329
1491 // BranchData
1492 //
1493 // A BranchData is used to access profiling data for a two-way branch.
1494 // It consists of taken and not_taken counts as well as a data displacement
1495 // for the taken case.
1496 class BranchData : public JumpData {
1497 friend class VMStructs;
1498 friend class JVMCIVMStructs;
1499 protected:
1500 enum {
1501 not_taken_off_set = jump_cell_count,
1502 branch_cell_count
1503 };
1504
1505 void set_displacement(int displacement) {
1506 set_int_at(displacement_off_set, displacement);
1507 }
1508
1509 public:
1510 BranchData(DataLayout* layout) : JumpData(layout) {
1511 assert(layout->tag() == DataLayout::branch_data_tag || layout->tag() == DataLayout::acmp_data_tag, "wrong type");
1512 }
1513
1514 virtual bool is_BranchData() const { return true; }
1515
1516 static int static_cell_count() {
1517 return branch_cell_count;
1518 }
1519
1520 virtual int cell_count() const {
1521 return static_cell_count();
1522 }
1523
1524 // Direct accessor
1525 uint not_taken() const {
1526 return uint_at(not_taken_off_set);
1527 }
1528
1529 void set_not_taken(uint cnt) {
1530 set_uint_at(not_taken_off_set, cnt);
1531 }
1845 }
1846
1847 virtual int cell_count() const {
1848 return static_cell_count();
1849 }
1850
1851 // Direct accessor
1852 Method* method() const {
1853 return (Method*)intptr_at(speculative_trap_method);
1854 }
1855
1856 void set_method(Method* m) {
1857 assert(!m->is_old(), "cannot add old methods");
1858 set_intptr_at(speculative_trap_method, (intptr_t)m);
1859 }
1860
1861 static ByteSize method_offset() {
1862 return cell_offset(speculative_trap_method);
1863 }
1864
1865 virtual void print_data_on(outputStream* st, const char* extra = NULL) const;
1866 };
1867
1868 class ArrayLoadStoreData : public ProfileData {
1869 private:
1870 enum {
1871 flat_array_flag = DataLayout::first_flag,
1872 null_free_array_flag = flat_array_flag + 1,
1873 };
1874
1875 SingleTypeEntry _array;
1876 SingleTypeEntry _element;
1877
1878 public:
1879 ArrayLoadStoreData(DataLayout* layout) :
1880 ProfileData(layout),
1881 _array(0),
1882 _element(SingleTypeEntry::static_cell_count()) {
1883 assert(layout->tag() == DataLayout::array_load_store_data_tag, "wrong type");
1884 _array.set_profile_data(this);
1885 _element.set_profile_data(this);
1886 }
1887
1888 const SingleTypeEntry* array() const {
1889 return &_array;
1890 }
1891
1892 const SingleTypeEntry* element() const {
1893 return &_element;
1894 }
1895
1896 virtual bool is_ArrayLoadStoreData() const { return true; }
1897
1898 static int static_cell_count() {
1899 return SingleTypeEntry::static_cell_count() * 2;
1900 }
1901
1902 virtual int cell_count() const {
1903 return static_cell_count();
1904 }
1905
1906 void set_flat_array() { set_flag_at(flat_array_flag); }
1907 bool flat_array() const { return flag_at(flat_array_flag); }
1908
1909 void set_null_free_array() { set_flag_at(null_free_array_flag); }
1910 bool null_free_array() const { return flag_at(null_free_array_flag); }
1911
1912 // Code generation support
1913 static int flat_array_byte_constant() {
1914 return flag_number_to_constant(flat_array_flag);
1915 }
1916
1917 static int null_free_array_byte_constant() {
1918 return flag_number_to_constant(null_free_array_flag);
1919 }
1920
1921 static ByteSize array_offset() {
1922 return cell_offset(0);
1923 }
1924
1925 static ByteSize element_offset() {
1926 return cell_offset(SingleTypeEntry::static_cell_count());
1927 }
1928
1929 virtual void clean_weak_klass_links(bool always_clean) {
1930 _array.clean_weak_klass_links(always_clean);
1931 _element.clean_weak_klass_links(always_clean);
1932 }
1933
1934 static ByteSize array_load_store_data_size() {
1935 return cell_offset(static_cell_count());
1936 }
1937
1938 virtual void print_data_on(outputStream* st, const char* extra = NULL) const;
1939 };
1940
1941 class ACmpData : public BranchData {
1942 private:
1943 enum {
1944 left_inline_type_flag = DataLayout::first_flag,
1945 right_inline_type_flag
1946 };
1947
1948 SingleTypeEntry _left;
1949 SingleTypeEntry _right;
1950
1951 public:
1952 ACmpData(DataLayout* layout) :
1953 BranchData(layout),
1954 _left(BranchData::static_cell_count()),
1955 _right(BranchData::static_cell_count() + SingleTypeEntry::static_cell_count()) {
1956 assert(layout->tag() == DataLayout::acmp_data_tag, "wrong type");
1957 _left.set_profile_data(this);
1958 _right.set_profile_data(this);
1959 }
1960
1961 const SingleTypeEntry* left() const {
1962 return &_left;
1963 }
1964
1965 const SingleTypeEntry* right() const {
1966 return &_right;
1967 }
1968
1969 virtual bool is_ACmpData() const { return true; }
1970
1971 static int static_cell_count() {
1972 return BranchData::static_cell_count() + SingleTypeEntry::static_cell_count() * 2;
1973 }
1974
1975 virtual int cell_count() const {
1976 return static_cell_count();
1977 }
1978
1979 void set_left_inline_type() { set_flag_at(left_inline_type_flag); }
1980 bool left_inline_type() const { return flag_at(left_inline_type_flag); }
1981
1982 void set_right_inline_type() { set_flag_at(right_inline_type_flag); }
1983 bool right_inline_type() const { return flag_at(right_inline_type_flag); }
1984
1985 // Code generation support
1986 static int left_inline_type_byte_constant() {
1987 return flag_number_to_constant(left_inline_type_flag);
1988 }
1989
1990 static int right_inline_type_byte_constant() {
1991 return flag_number_to_constant(right_inline_type_flag);
1992 }
1993
1994 static ByteSize left_offset() {
1995 return cell_offset(BranchData::static_cell_count());
1996 }
1997
1998 static ByteSize right_offset() {
1999 return cell_offset(BranchData::static_cell_count() + SingleTypeEntry::static_cell_count());
2000 }
2001
2002 virtual void clean_weak_klass_links(bool always_clean) {
2003 _left.clean_weak_klass_links(always_clean);
2004 _right.clean_weak_klass_links(always_clean);
2005 }
2006
2007 static ByteSize acmp_data_size() {
2008 return cell_offset(static_cell_count());
2009 }
2010
2011 virtual void print_data_on(outputStream* st, const char* extra = NULL) const;
2012 };
2013
2014 // MethodData*
2015 //
2016 // A MethodData* holds information which has been collected about
2017 // a method. Its layout looks like this:
2018 //
2019 // -----------------------------
2020 // | header |
2021 // | klass |
2022 // -----------------------------
2023 // | method |
2024 // | size of the MethodData* |
2025 // -----------------------------
2026 // | Data entries... |
2027 // | (variable size) |
2028 // | |
2029 // . .
2030 // . .
|