This repository has been archived by the owner on Sep 2, 2022. It is now read-only.
/
methodData.hpp
2478 lines (2076 loc) · 76.1 KB
/
methodData.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#ifndef SHARE_OOPS_METHODDATA_HPP
#define SHARE_OOPS_METHODDATA_HPP
#include "interpreter/bytecodes.hpp"
#include "oops/metadata.hpp"
#include "oops/method.hpp"
#include "oops/oop.hpp"
#include "runtime/atomic.hpp"
#include "utilities/align.hpp"
#include "utilities/copy.hpp"
class BytecodeStream;
// The MethodData object collects counts and other profile information
// during zeroth-tier (interpretive) and first-tier execution.
// The profile is used later by compilation heuristics. Some heuristics
// enable use of aggressive (or "heroic") optimizations. An aggressive
// optimization often has a down-side, a corner case that it handles
// poorly, but which is thought to be rare. The profile provides
// evidence of this rarity for a given method or even BCI. It allows
// the compiler to back out of the optimization at places where it
// has historically been a poor choice. Other heuristics try to use
// specific information gathered about types observed at a given site.
//
// All data in the profile is approximate. It is expected to be accurate
// on the whole, but the system expects occasional inaccuraces, due to
// counter overflow, multiprocessor races during data collection, space
// limitations, missing MDO blocks, etc. Bad or missing data will degrade
// optimization quality but will not affect correctness. Also, each MDO
// is marked with its birth-date ("creation_mileage") which can be used
// to assess the quality ("maturity") of its data.
//
// Short (<32-bit) counters are designed to overflow to a known "saturated"
// state. Also, certain recorded per-BCI events are given one-bit counters
// which overflow to a saturated state which applied to all counters at
// that BCI. In other words, there is a small lattice which approximates
// the ideal of an infinite-precision counter for each event at each BCI,
// and the lattice quickly "bottoms out" in a state where all counters
// are taken to be indefinitely large.
//
// The reader will find many data races in profile gathering code, starting
// with invocation counter incrementation. None of these races harm correct
// execution of the compiled code.
// forward decl
class ProfileData;
// DataLayout
//
// Overlay for generic profiling data.
class DataLayout {
friend class VMStructs;
friend class JVMCIVMStructs;
private:
// Every data layout begins with a header. This header
// contains a tag, which is used to indicate the size/layout
// of the data, 8 bits of flags, which can be used in any way,
// 32 bits of trap history (none/one reason/many reasons),
// and a bci, which is used to tie this piece of data to a
// specific bci in the bytecodes.
union {
u8 _bits;
struct {
u1 _tag;
u1 _flags;
u2 _bci;
u4 _traps;
} _struct;
} _header;
// The data layout has an arbitrary number of cells, each sized
// to accomodate a pointer or an integer.
intptr_t _cells[1];
// Some types of data layouts need a length field.
static bool needs_array_len(u1 tag);
public:
enum {
counter_increment = 1
};
enum {
cell_size = sizeof(intptr_t)
};
// Tag values
enum {
no_tag,
bit_data_tag,
counter_data_tag,
jump_data_tag,
receiver_type_data_tag,
virtual_call_data_tag,
ret_data_tag,
branch_data_tag,
multi_branch_data_tag,
arg_info_data_tag,
call_type_data_tag,
virtual_call_type_data_tag,
parameters_type_data_tag,
speculative_trap_data_tag
};
enum {
// The trap state breaks down as [recompile:1 | reason:31].
// This further breakdown is defined in deoptimization.cpp.
// See Deoptimization::trap_state_reason for an assert that
// trap_bits is big enough to hold reasons < Reason_RECORDED_LIMIT.
//
// The trap_state is collected only if ProfileTraps is true.
trap_bits = 1+31, // 31: enough to distinguish [0..Reason_RECORDED_LIMIT].
trap_mask = -1,
first_flag = 0
};
// Size computation
static int header_size_in_bytes() {
return header_size_in_cells() * cell_size;
}
static int header_size_in_cells() {
return LP64_ONLY(1) NOT_LP64(2);
}
static int compute_size_in_bytes(int cell_count) {
return header_size_in_bytes() + cell_count * cell_size;
}
// Initialization
void initialize(u1 tag, u2 bci, int cell_count);
// Accessors
u1 tag() {
return _header._struct._tag;
}
// Return 32 bits of trap state.
// The state tells if traps with zero, one, or many reasons have occurred.
// It also tells whether zero or many recompilations have occurred.
// The associated trap histogram in the MDO itself tells whether
// traps are common or not. If a BCI shows that a trap X has
// occurred, and the MDO shows N occurrences of X, we make the
// simplifying assumption that all N occurrences can be blamed
// on that BCI.
uint trap_state() const {
return _header._struct._traps;
}
void set_trap_state(uint new_state) {
assert(ProfileTraps, "used only under +ProfileTraps");
uint old_flags = _header._struct._traps;
_header._struct._traps = new_state | old_flags;
}
u1 flags() const {
return _header._struct._flags;
}
u2 bci() const {
return _header._struct._bci;
}
void set_header(u8 value) {
_header._bits = value;
}
u8 header() {
return _header._bits;
}
void set_cell_at(int index, intptr_t value) {
_cells[index] = value;
}
void release_set_cell_at(int index, intptr_t value);
intptr_t cell_at(int index) const {
return _cells[index];
}
void set_flag_at(u1 flag_number) {
_header._struct._flags |= (0x1 << flag_number);
}
bool flag_at(u1 flag_number) const {
return (_header._struct._flags & (0x1 << flag_number)) != 0;
}
// Low-level support for code generation.
static ByteSize header_offset() {
return byte_offset_of(DataLayout, _header);
}
static ByteSize tag_offset() {
return byte_offset_of(DataLayout, _header._struct._tag);
}
static ByteSize flags_offset() {
return byte_offset_of(DataLayout, _header._struct._flags);
}
static ByteSize bci_offset() {
return byte_offset_of(DataLayout, _header._struct._bci);
}
static ByteSize cell_offset(int index) {
return byte_offset_of(DataLayout, _cells) + in_ByteSize(index * cell_size);
}
// Return a value which, when or-ed as a byte into _flags, sets the flag.
static u1 flag_number_to_constant(u1 flag_number) {
DataLayout temp; temp.set_header(0);
temp.set_flag_at(flag_number);
return temp._header._struct._flags;
}
// Return a value which, when or-ed as a word into _header, sets the flag.
static u8 flag_mask_to_header_mask(uint byte_constant) {
DataLayout temp; temp.set_header(0);
temp._header._struct._flags = byte_constant;
return temp._header._bits;
}
ProfileData* data_in();
int size_in_bytes() {
int cells = cell_count();
assert(cells >= 0, "invalid number of cells");
return DataLayout::compute_size_in_bytes(cells);
}
int cell_count();
// GC support
void clean_weak_klass_links(bool always_clean);
};
// ProfileData class hierarchy
class ProfileData;
class BitData;
class CounterData;
class ReceiverTypeData;
class VirtualCallData;
class VirtualCallTypeData;
class RetData;
class CallTypeData;
class JumpData;
class BranchData;
class ArrayData;
class MultiBranchData;
class ArgInfoData;
class ParametersTypeData;
class SpeculativeTrapData;
// ProfileData
//
// A ProfileData object is created to refer to a section of profiling
// data in a structured way.
class ProfileData : public ResourceObj {
friend class TypeEntries;
friend class ReturnTypeEntry;
friend class TypeStackSlotEntries;
private:
enum {
tab_width_one = 16,
tab_width_two = 36
};
// This is a pointer to a section of profiling data.
DataLayout* _data;
char* print_data_on_helper(const MethodData* md) const;
protected:
DataLayout* data() { return _data; }
const DataLayout* data() const { return _data; }
enum {
cell_size = DataLayout::cell_size
};
public:
// How many cells are in this?
virtual int cell_count() const {
ShouldNotReachHere();
return -1;
}
// Return the size of this data.
int size_in_bytes() {
return DataLayout::compute_size_in_bytes(cell_count());
}
protected:
// Low-level accessors for underlying data
void set_intptr_at(int index, intptr_t value) {
assert(0 <= index && index < cell_count(), "oob");
data()->set_cell_at(index, value);
}
void release_set_intptr_at(int index, intptr_t value);
intptr_t intptr_at(int index) const {
assert(0 <= index && index < cell_count(), "oob");
return data()->cell_at(index);
}
void set_uint_at(int index, uint value) {
set_intptr_at(index, (intptr_t) value);
}
void release_set_uint_at(int index, uint value);
uint uint_at(int index) const {
return (uint)intptr_at(index);
}
void set_int_at(int index, int value) {
set_intptr_at(index, (intptr_t) value);
}
void release_set_int_at(int index, int value);
int int_at(int index) const {
return (int)intptr_at(index);
}
int int_at_unchecked(int index) const {
return (int)data()->cell_at(index);
}
void set_oop_at(int index, oop value) {
set_intptr_at(index, cast_from_oop<intptr_t>(value));
}
oop oop_at(int index) const {
return cast_to_oop(intptr_at(index));
}
void set_flag_at(int flag_number) {
data()->set_flag_at(flag_number);
}
bool flag_at(int flag_number) const {
return data()->flag_at(flag_number);
}
// two convenient imports for use by subclasses:
static ByteSize cell_offset(int index) {
return DataLayout::cell_offset(index);
}
static int flag_number_to_constant(int flag_number) {
return DataLayout::flag_number_to_constant(flag_number);
}
ProfileData(DataLayout* data) {
_data = data;
}
public:
// Constructor for invalid ProfileData.
ProfileData();
u2 bci() const {
return data()->bci();
}
address dp() {
return (address)_data;
}
int trap_state() const {
return data()->trap_state();
}
void set_trap_state(int new_state) {
data()->set_trap_state(new_state);
}
// Type checking
virtual bool is_BitData() const { return false; }
virtual bool is_CounterData() const { return false; }
virtual bool is_JumpData() const { return false; }
virtual bool is_ReceiverTypeData()const { return false; }
virtual bool is_VirtualCallData() const { return false; }
virtual bool is_RetData() const { return false; }
virtual bool is_BranchData() const { return false; }
virtual bool is_ArrayData() const { return false; }
virtual bool is_MultiBranchData() const { return false; }
virtual bool is_ArgInfoData() const { return false; }
virtual bool is_CallTypeData() const { return false; }
virtual bool is_VirtualCallTypeData()const { return false; }
virtual bool is_ParametersTypeData() const { return false; }
virtual bool is_SpeculativeTrapData()const { return false; }
BitData* as_BitData() const {
assert(is_BitData(), "wrong type");
return is_BitData() ? (BitData*) this : NULL;
}
CounterData* as_CounterData() const {
assert(is_CounterData(), "wrong type");
return is_CounterData() ? (CounterData*) this : NULL;
}
JumpData* as_JumpData() const {
assert(is_JumpData(), "wrong type");
return is_JumpData() ? (JumpData*) this : NULL;
}
ReceiverTypeData* as_ReceiverTypeData() const {
assert(is_ReceiverTypeData(), "wrong type");
return is_ReceiverTypeData() ? (ReceiverTypeData*)this : NULL;
}
VirtualCallData* as_VirtualCallData() const {
assert(is_VirtualCallData(), "wrong type");
return is_VirtualCallData() ? (VirtualCallData*)this : NULL;
}
RetData* as_RetData() const {
assert(is_RetData(), "wrong type");
return is_RetData() ? (RetData*) this : NULL;
}
BranchData* as_BranchData() const {
assert(is_BranchData(), "wrong type");
return is_BranchData() ? (BranchData*) this : NULL;
}
ArrayData* as_ArrayData() const {
assert(is_ArrayData(), "wrong type");
return is_ArrayData() ? (ArrayData*) this : NULL;
}
MultiBranchData* as_MultiBranchData() const {
assert(is_MultiBranchData(), "wrong type");
return is_MultiBranchData() ? (MultiBranchData*)this : NULL;
}
ArgInfoData* as_ArgInfoData() const {
assert(is_ArgInfoData(), "wrong type");
return is_ArgInfoData() ? (ArgInfoData*)this : NULL;
}
CallTypeData* as_CallTypeData() const {
assert(is_CallTypeData(), "wrong type");
return is_CallTypeData() ? (CallTypeData*)this : NULL;
}
VirtualCallTypeData* as_VirtualCallTypeData() const {
assert(is_VirtualCallTypeData(), "wrong type");
return is_VirtualCallTypeData() ? (VirtualCallTypeData*)this : NULL;
}
ParametersTypeData* as_ParametersTypeData() const {
assert(is_ParametersTypeData(), "wrong type");
return is_ParametersTypeData() ? (ParametersTypeData*)this : NULL;
}
SpeculativeTrapData* as_SpeculativeTrapData() const {
assert(is_SpeculativeTrapData(), "wrong type");
return is_SpeculativeTrapData() ? (SpeculativeTrapData*)this : NULL;
}
// Subclass specific initialization
virtual void post_initialize(BytecodeStream* stream, MethodData* mdo) {}
// GC support
virtual void clean_weak_klass_links(bool always_clean) {}
// CI translation: ProfileData can represent both MethodDataOop data
// as well as CIMethodData data. This function is provided for translating
// an oop in a ProfileData to the ci equivalent. Generally speaking,
// most ProfileData don't require any translation, so we provide the null
// translation here, and the required translators are in the ci subclasses.
virtual void translate_from(const ProfileData* data) {}
virtual void print_data_on(outputStream* st, const char* extra = NULL) const {
ShouldNotReachHere();
}
void print_data_on(outputStream* st, const MethodData* md) const;
void print_shared(outputStream* st, const char* name, const char* extra) const;
void tab(outputStream* st, bool first = false) const;
};
// BitData
//
// A BitData holds a flag or two in its header.
class BitData : public ProfileData {
friend class VMStructs;
friend class JVMCIVMStructs;
protected:
enum {
// null_seen:
// saw a null operand (cast/aastore/instanceof)
null_seen_flag = DataLayout::first_flag + 0
#if INCLUDE_JVMCI
// bytecode threw any exception
, exception_seen_flag = null_seen_flag + 1
#endif
};
enum { bit_cell_count = 0 }; // no additional data fields needed.
public:
BitData(DataLayout* layout) : ProfileData(layout) {
}
virtual bool is_BitData() const { return true; }
static int static_cell_count() {
return bit_cell_count;
}
virtual int cell_count() const {
return static_cell_count();
}
// Accessor
// The null_seen flag bit is specially known to the interpreter.
// Consulting it allows the compiler to avoid setting up null_check traps.
bool null_seen() { return flag_at(null_seen_flag); }
void set_null_seen() { set_flag_at(null_seen_flag); }
#if INCLUDE_JVMCI
// true if an exception was thrown at the specific BCI
bool exception_seen() { return flag_at(exception_seen_flag); }
void set_exception_seen() { set_flag_at(exception_seen_flag); }
#endif
// Code generation support
static int null_seen_byte_constant() {
return flag_number_to_constant(null_seen_flag);
}
static ByteSize bit_data_size() {
return cell_offset(bit_cell_count);
}
void print_data_on(outputStream* st, const char* extra = NULL) const;
};
// CounterData
//
// A CounterData corresponds to a simple counter.
class CounterData : public BitData {
friend class VMStructs;
friend class JVMCIVMStructs;
protected:
enum {
count_off,
counter_cell_count
};
public:
CounterData(DataLayout* layout) : BitData(layout) {}
virtual bool is_CounterData() const { return true; }
static int static_cell_count() {
return counter_cell_count;
}
virtual int cell_count() const {
return static_cell_count();
}
// Direct accessor
int count() const {
intptr_t raw_data = intptr_at(count_off);
if (raw_data > max_jint) {
raw_data = max_jint;
} else if (raw_data < min_jint) {
raw_data = min_jint;
}
return int(raw_data);
}
// Code generation support
static ByteSize count_offset() {
return cell_offset(count_off);
}
static ByteSize counter_data_size() {
return cell_offset(counter_cell_count);
}
void set_count(int count) {
set_int_at(count_off, count);
}
void print_data_on(outputStream* st, const char* extra = NULL) const;
};
// JumpData
//
// A JumpData is used to access profiling information for a direct
// branch. It is a counter, used for counting the number of branches,
// plus a data displacement, used for realigning the data pointer to
// the corresponding target bci.
class JumpData : public ProfileData {
friend class VMStructs;
friend class JVMCIVMStructs;
protected:
enum {
taken_off_set,
displacement_off_set,
jump_cell_count
};
void set_displacement(int displacement) {
set_int_at(displacement_off_set, displacement);
}
public:
JumpData(DataLayout* layout) : ProfileData(layout) {
assert(layout->tag() == DataLayout::jump_data_tag ||
layout->tag() == DataLayout::branch_data_tag, "wrong type");
}
virtual bool is_JumpData() const { return true; }
static int static_cell_count() {
return jump_cell_count;
}
virtual int cell_count() const {
return static_cell_count();
}
// Direct accessor
uint taken() const {
return uint_at(taken_off_set);
}
void set_taken(uint cnt) {
set_uint_at(taken_off_set, cnt);
}
// Saturating counter
uint inc_taken() {
uint cnt = taken() + 1;
// Did we wrap? Will compiler screw us??
if (cnt == 0) cnt--;
set_uint_at(taken_off_set, cnt);
return cnt;
}
int displacement() const {
return int_at(displacement_off_set);
}
// Code generation support
static ByteSize taken_offset() {
return cell_offset(taken_off_set);
}
static ByteSize displacement_offset() {
return cell_offset(displacement_off_set);
}
// Specific initialization.
void post_initialize(BytecodeStream* stream, MethodData* mdo);
void print_data_on(outputStream* st, const char* extra = NULL) const;
};
// Entries in a ProfileData object to record types: it can either be
// none (no profile), unknown (conflicting profile data) or a klass if
// a single one is seen. Whether a null reference was seen is also
// recorded. No counter is associated with the type and a single type
// is tracked (unlike VirtualCallData).
class TypeEntries {
public:
// A single cell is used to record information for a type:
// - the cell is initialized to 0
// - when a type is discovered it is stored in the cell
// - bit zero of the cell is used to record whether a null reference
// was encountered or not
// - bit 1 is set to record a conflict in the type information
enum {
null_seen = 1,
type_mask = ~null_seen,
type_unknown = 2,
status_bits = null_seen | type_unknown,
type_klass_mask = ~status_bits
};
// what to initialize a cell to
static intptr_t type_none() {
return 0;
}
// null seen = bit 0 set?
static bool was_null_seen(intptr_t v) {
return (v & null_seen) != 0;
}
// conflicting type information = bit 1 set?
static bool is_type_unknown(intptr_t v) {
return (v & type_unknown) != 0;
}
// not type information yet = all bits cleared, ignoring bit 0?
static bool is_type_none(intptr_t v) {
return (v & type_mask) == 0;
}
// recorded type: cell without bit 0 and 1
static intptr_t klass_part(intptr_t v) {
intptr_t r = v & type_klass_mask;
return r;
}
// type recorded
static Klass* valid_klass(intptr_t k) {
if (!is_type_none(k) &&
!is_type_unknown(k)) {
Klass* res = (Klass*)klass_part(k);
assert(res != NULL, "invalid");
return res;
} else {
return NULL;
}
}
static intptr_t with_status(intptr_t k, intptr_t in) {
return k | (in & status_bits);
}
static intptr_t with_status(Klass* k, intptr_t in) {
return with_status((intptr_t)k, in);
}
static void print_klass(outputStream* st, intptr_t k);
protected:
// ProfileData object these entries are part of
ProfileData* _pd;
// offset within the ProfileData object where the entries start
const int _base_off;
TypeEntries(int base_off)
: _pd(NULL), _base_off(base_off) {}
void set_intptr_at(int index, intptr_t value) {
_pd->set_intptr_at(index, value);
}
intptr_t intptr_at(int index) const {
return _pd->intptr_at(index);
}
public:
void set_profile_data(ProfileData* pd) {
_pd = pd;
}
};
// Type entries used for arguments passed at a call and parameters on
// method entry. 2 cells per entry: one for the type encoded as in
// TypeEntries and one initialized with the stack slot where the
// profiled object is to be found so that the interpreter can locate
// it quickly.
class TypeStackSlotEntries : public TypeEntries {
private:
enum {
stack_slot_entry,
type_entry,
per_arg_cell_count
};
// offset of cell for stack slot for entry i within ProfileData object
int stack_slot_offset(int i) const {
return _base_off + stack_slot_local_offset(i);
}
const int _number_of_entries;
// offset of cell for type for entry i within ProfileData object
int type_offset_in_cells(int i) const {
return _base_off + type_local_offset(i);
}
public:
TypeStackSlotEntries(int base_off, int nb_entries)
: TypeEntries(base_off), _number_of_entries(nb_entries) {}
static int compute_cell_count(Symbol* signature, bool include_receiver, int max);
void post_initialize(Symbol* signature, bool has_receiver, bool include_receiver);
int number_of_entries() const { return _number_of_entries; }
// offset of cell for stack slot for entry i within this block of cells for a TypeStackSlotEntries
static int stack_slot_local_offset(int i) {
return i * per_arg_cell_count + stack_slot_entry;
}
// offset of cell for type for entry i within this block of cells for a TypeStackSlotEntries
static int type_local_offset(int i) {
return i * per_arg_cell_count + type_entry;
}
// stack slot for entry i
uint stack_slot(int i) const {
assert(i >= 0 && i < _number_of_entries, "oob");
return _pd->uint_at(stack_slot_offset(i));
}
// set stack slot for entry i
void set_stack_slot(int i, uint num) {
assert(i >= 0 && i < _number_of_entries, "oob");
_pd->set_uint_at(stack_slot_offset(i), num);
}
// type for entry i
intptr_t type(int i) const {
assert(i >= 0 && i < _number_of_entries, "oob");
return _pd->intptr_at(type_offset_in_cells(i));
}
// set type for entry i
void set_type(int i, intptr_t k) {
assert(i >= 0 && i < _number_of_entries, "oob");
_pd->set_intptr_at(type_offset_in_cells(i), k);
}
static ByteSize per_arg_size() {
return in_ByteSize(per_arg_cell_count * DataLayout::cell_size);
}
static int per_arg_count() {
return per_arg_cell_count;
}
ByteSize type_offset(int i) const {
return DataLayout::cell_offset(type_offset_in_cells(i));
}
// GC support
void clean_weak_klass_links(bool always_clean);
void print_data_on(outputStream* st) const;
};
// Type entry used for return from a call. A single cell to record the
// type.
class ReturnTypeEntry : public TypeEntries {
private:
enum {
cell_count = 1
};
public:
ReturnTypeEntry(int base_off)
: TypeEntries(base_off) {}
void post_initialize() {
set_type(type_none());
}
intptr_t type() const {
return _pd->intptr_at(_base_off);
}
void set_type(intptr_t k) {
_pd->set_intptr_at(_base_off, k);
}
static int static_cell_count() {
return cell_count;
}
static ByteSize size() {
return in_ByteSize(cell_count * DataLayout::cell_size);
}
ByteSize type_offset() {
return DataLayout::cell_offset(_base_off);
}
// GC support
void clean_weak_klass_links(bool always_clean);
void print_data_on(outputStream* st) const;
};
// Entries to collect type information at a call: contains arguments
// (TypeStackSlotEntries), a return type (ReturnTypeEntry) and a
// number of cells. Because the number of cells for the return type is
// smaller than the number of cells for the type of an arguments, the
// number of cells is used to tell how many arguments are profiled and
// whether a return value is profiled. See has_arguments() and
// has_return().
class TypeEntriesAtCall {
private:
static int stack_slot_local_offset(int i) {
return header_cell_count() + TypeStackSlotEntries::stack_slot_local_offset(i);
}
static int argument_type_local_offset(int i) {
return header_cell_count() + TypeStackSlotEntries::type_local_offset(i);
}
public:
static int header_cell_count() {
return 1;
}
static int cell_count_local_offset() {
return 0;
}
static int compute_cell_count(BytecodeStream* stream);
static void initialize(DataLayout* dl, int base, int cell_count) {
int off = base + cell_count_local_offset();
dl->set_cell_at(off, cell_count - base - header_cell_count());
}
static bool arguments_profiling_enabled();
static bool return_profiling_enabled();
// Code generation support
static ByteSize cell_count_offset() {
return in_ByteSize(cell_count_local_offset() * DataLayout::cell_size);
}
static ByteSize args_data_offset() {
return in_ByteSize(header_cell_count() * DataLayout::cell_size);
}
static ByteSize stack_slot_offset(int i) {
return in_ByteSize(stack_slot_local_offset(i) * DataLayout::cell_size);
}
static ByteSize argument_type_offset(int i) {
return in_ByteSize(argument_type_local_offset(i) * DataLayout::cell_size);
}
static ByteSize return_only_size() {
return ReturnTypeEntry::size() + in_ByteSize(header_cell_count() * DataLayout::cell_size);
}
};
// CallTypeData
//
// A CallTypeData is used to access profiling information about a non
// virtual call for which we collect type information about arguments
// and return value.
class CallTypeData : public CounterData {
private:
// entries for arguments if any
TypeStackSlotEntries _args;
// entry for return type if any
ReturnTypeEntry _ret;
int cell_count_global_offset() const {
return CounterData::static_cell_count() + TypeEntriesAtCall::cell_count_local_offset();
}
// number of cells not counting the header
int cell_count_no_header() const {
return uint_at(cell_count_global_offset());
}
void check_number_of_arguments(int total) {
assert(number_of_arguments() == total, "should be set in DataLayout::initialize");
}
public:
CallTypeData(DataLayout* layout) :
CounterData(layout),
_args(CounterData::static_cell_count()+TypeEntriesAtCall::header_cell_count(), number_of_arguments()),
_ret(cell_count() - ReturnTypeEntry::static_cell_count())
{
assert(layout->tag() == DataLayout::call_type_data_tag, "wrong type");
// Some compilers (VC++) don't want this passed in member initialization list
_args.set_profile_data(this);
_ret.set_profile_data(this);
}
const TypeStackSlotEntries* args() const {
assert(has_arguments(), "no profiling of arguments");
return &_args;
}
const ReturnTypeEntry* ret() const {
assert(has_return(), "no profiling of return value");
return &_ret;
}
virtual bool is_CallTypeData() const { return true; }
static int static_cell_count() {
return -1;
}
static int compute_cell_count(BytecodeStream* stream) {
return CounterData::static_cell_count() + TypeEntriesAtCall::compute_cell_count(stream);
}