1 /* 2 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 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 class ciBitData; 26 class ciCounterData; 27 class ciJumpData; 28 class ciReceiverTypeData; 29 class ciRetData; 30 class ciBranchData; 31 class ciArrayData; 32 class ciMultiBranchData; 33 class ciArgInfoData; 34 35 typedef ProfileData ciProfileData; 36 37 class ciBitData : public BitData { 38 public: 39 ciBitData(DataLayout* layout) : BitData(layout) {}; 40 }; 41 42 class ciCounterData : public CounterData { 43 public: 44 ciCounterData(DataLayout* layout) : CounterData(layout) {}; 45 }; 46 47 class ciJumpData : public JumpData { 48 public: 49 ciJumpData(DataLayout* layout) : JumpData(layout) {}; 50 }; 51 52 class ciReceiverTypeData : public ReceiverTypeData { 53 public: 54 ciReceiverTypeData(DataLayout* layout) : ReceiverTypeData(layout) {}; 55 56 void set_receiver(uint row, ciKlass* recv) { 57 assert((uint)row < row_limit(), "oob"); 58 set_intptr_at(receiver0_offset + row * receiver_type_row_cell_count, 59 (intptr_t) recv); 60 } 61 62 ciKlass* receiver(uint row) { 63 assert((uint)row < row_limit(), "oob"); 64 ciObject* recv = (ciObject*)intptr_at(receiver0_offset + row * receiver_type_row_cell_count); 65 assert(recv == NULL || recv->is_klass(), "wrong type"); 66 return (ciKlass*)recv; 67 } 68 69 // Copy & translate from oop based ReceiverTypeData 70 virtual void translate_from(ProfileData* data) { 71 translate_receiver_data_from(data); 72 } 73 void translate_receiver_data_from(ProfileData* data); 74 #ifndef PRODUCT 75 void print_data_on(outputStream* st); 76 void print_receiver_data_on(outputStream* st); 77 #endif 78 }; 79 80 class ciVirtualCallData : public VirtualCallData { 81 // Fake multiple inheritance... It's a ciReceiverTypeData also. 82 ciReceiverTypeData* rtd_super() { return (ciReceiverTypeData*) this; } 83 84 public: 85 ciVirtualCallData(DataLayout* layout) : VirtualCallData(layout) {}; 86 87 void set_receiver(uint row, ciKlass* recv) { 88 rtd_super()->set_receiver(row, recv); 89 } 90 91 ciKlass* receiver(uint row) { 92 return rtd_super()->receiver(row); 93 } 94 95 // Copy & translate from oop based VirtualCallData 96 virtual void translate_from(ProfileData* data) { 97 rtd_super()->translate_receiver_data_from(data); 98 } 99 #ifndef PRODUCT 100 void print_data_on(outputStream* st); 101 #endif 102 }; 103 104 105 class ciRetData : public RetData { 106 public: 107 ciRetData(DataLayout* layout) : RetData(layout) {}; 108 }; 109 110 class ciBranchData : public BranchData { 111 public: 112 ciBranchData(DataLayout* layout) : BranchData(layout) {}; 113 }; 114 115 class ciArrayData : public ArrayData { 116 public: 117 ciArrayData(DataLayout* layout) : ArrayData(layout) {}; 118 }; 119 120 class ciMultiBranchData : public MultiBranchData { 121 public: 122 ciMultiBranchData(DataLayout* layout) : MultiBranchData(layout) {}; 123 }; 124 125 class ciArgInfoData : public ArgInfoData { 126 public: 127 ciArgInfoData(DataLayout* layout) : ArgInfoData(layout) {}; 128 }; 129 130 // ciMethodData 131 // 132 // This class represents a methodDataOop in the HotSpot virtual 133 // machine. 134 135 class ciMethodData : public ciObject { 136 CI_PACKAGE_ACCESS 137 138 private: 139 // Size in bytes 140 int _data_size; 141 int _extra_data_size; 142 143 // Data entries 144 intptr_t* _data; 145 146 // Cached hint for data_before() 147 int _hint_di; 148 149 // Is data attached? And is it mature? 150 enum { empty_state, immature_state, mature_state }; 151 u_char _state; 152 153 // Set this true if empty extra_data slots are ever witnessed. 154 u_char _saw_free_extra_data; 155 156 // Support for interprocedural escape analysis 157 intx _eflags; // flags on escape information 158 intx _arg_local; // bit set of non-escaping arguments 159 intx _arg_stack; // bit set of stack-allocatable arguments 160 intx _arg_returned; // bit set of returned arguments 161 162 // Maturity of the oop when the snapshot is taken. 163 int _current_mileage; 164 165 // These counters hold the age of MDO in tiered. In tiered we can have the same method 166 // running at different compilation levels concurrently. So, in order to precisely measure 167 // its maturity we need separate counters. 168 int _invocation_counter; 169 int _backedge_counter; 170 171 // Coherent snapshot of original header. 172 methodDataOopDesc _orig; 173 174 ciMethodData(methodDataHandle h_md); 175 ciMethodData(); 176 177 // Accessors 178 int data_size() const { return _data_size; } 179 int extra_data_size() const { return _extra_data_size; } 180 intptr_t * data() const { return _data; } 181 182 methodDataOop get_methodDataOop() const { 183 if (handle() == NULL) return NULL; 184 methodDataOop mdo = (methodDataOop)get_oop(); 185 assert(mdo != NULL, "illegal use of unloaded method data"); 186 return mdo; 187 } 188 189 const char* type_string() { return "ciMethodData"; } 190 191 void print_impl(outputStream* st); 192 193 DataLayout* data_layout_at(int data_index) const { 194 assert(data_index % sizeof(intptr_t) == 0, "unaligned"); 195 return (DataLayout*) (((address)_data) + data_index); 196 } 197 198 bool out_of_bounds(int data_index) { 199 return data_index >= data_size(); 200 } 201 202 // hint accessors 203 int hint_di() const { return _hint_di; } 204 void set_hint_di(int di) { 205 assert(!out_of_bounds(di), "hint_di out of bounds"); 206 _hint_di = di; 207 } 208 ciProfileData* data_before(int bci) { 209 // avoid SEGV on this edge case 210 if (data_size() == 0) 211 return NULL; 212 int hint = hint_di(); 213 if (data_layout_at(hint)->bci() <= bci) 214 return data_at(hint); 215 return first_data(); 216 } 217 218 219 // What is the index of the first data entry? 220 int first_di() { return 0; } 221 222 ciArgInfoData *arg_info() const; 223 224 public: 225 bool is_method_data() { return true; } 226 bool is_empty() { return _state == empty_state; } 227 bool is_mature() { return _state == mature_state; } 228 229 int creation_mileage() { return _orig.creation_mileage(); } 230 int current_mileage() { return _current_mileage; } 231 232 int invocation_count() { return _invocation_counter; } 233 int backedge_count() { return _backedge_counter; } 234 // Transfer information about the method to methodDataOop. 235 // would_profile means we would like to profile this method, 236 // meaning it's not trivial. 237 void set_would_profile(bool p); 238 // Also set the numer of loops and blocks in the method. 239 // Again, this is used to determine if a method is trivial. 240 void set_compilation_stats(short loops, short blocks); 241 242 void load_data(); 243 244 // Convert a dp (data pointer) to a di (data index). 245 int dp_to_di(address dp) { 246 return dp - ((address)_data); 247 } 248 249 // Get the data at an arbitrary (sort of) data index. 250 ciProfileData* data_at(int data_index); 251 252 // Walk through the data in order. 253 ciProfileData* first_data() { return data_at(first_di()); } 254 ciProfileData* next_data(ciProfileData* current); 255 bool is_valid(ciProfileData* current) { return current != NULL; } 256 257 // Get the data at an arbitrary bci, or NULL if there is none. 258 ciProfileData* bci_to_data(int bci); 259 ciProfileData* bci_to_extra_data(int bci, bool create_if_missing); 260 261 uint overflow_trap_count() const { 262 return _orig.overflow_trap_count(); 263 } 264 uint overflow_recompile_count() const { 265 return _orig.overflow_recompile_count(); 266 } 267 uint decompile_count() const { 268 return _orig.decompile_count(); 269 } 270 uint trap_count(int reason) const { 271 return _orig.trap_count(reason); 272 } 273 uint trap_reason_limit() const { return _orig.trap_reason_limit(); } 274 uint trap_count_limit() const { return _orig.trap_count_limit(); } 275 276 // Helpful query functions that decode trap_state. 277 int has_trap_at(ciProfileData* data, int reason); 278 int has_trap_at(int bci, int reason) { 279 return has_trap_at(bci_to_data(bci), reason); 280 } 281 int trap_recompiled_at(ciProfileData* data); 282 int trap_recompiled_at(int bci) { 283 return trap_recompiled_at(bci_to_data(bci)); 284 } 285 286 void clear_escape_info(); 287 bool has_escape_info(); 288 void update_escape_info(); 289 290 void set_eflag(methodDataOopDesc::EscapeFlag f); 291 void clear_eflag(methodDataOopDesc::EscapeFlag f); 292 bool eflag_set(methodDataOopDesc::EscapeFlag f) const; 293 294 void set_arg_local(int i); 295 void set_arg_stack(int i); 296 void set_arg_returned(int i); 297 void set_arg_modified(int arg, uint val); 298 299 bool is_arg_local(int i) const; 300 bool is_arg_stack(int i) const; 301 bool is_arg_returned(int i) const; 302 uint arg_modified(int arg) const; 303 304 // Code generation helper 305 ByteSize offset_of_slot(ciProfileData* data, ByteSize slot_offset_in_data); 306 int byte_offset_of_slot(ciProfileData* data, ByteSize slot_offset_in_data) { return in_bytes(offset_of_slot(data, slot_offset_in_data)); } 307 308 #ifndef PRODUCT 309 // printing support for method data 310 void print(); 311 void print_data_on(outputStream* st); 312 #endif 313 };