118 branch_data_tag, |
118 branch_data_tag, |
119 multi_branch_data_tag, |
119 multi_branch_data_tag, |
120 arg_info_data_tag, |
120 arg_info_data_tag, |
121 call_type_data_tag, |
121 call_type_data_tag, |
122 virtual_call_type_data_tag, |
122 virtual_call_type_data_tag, |
123 parameters_type_data_tag |
123 parameters_type_data_tag, |
|
124 speculative_trap_data_tag |
124 }; |
125 }; |
125 |
126 |
126 enum { |
127 enum { |
127 // The _struct._flags word is formatted as [trap_state:4 | flags:4]. |
128 // The _struct._flags word is formatted as [trap_state:4 | flags:4]. |
128 // The trap state breaks down further as [recompile:1 | reason:3]. |
129 // The trap state breaks down further as [recompile:1 | reason:3]. |
187 } |
188 } |
188 |
189 |
189 void set_header(intptr_t value) { |
190 void set_header(intptr_t value) { |
190 _header._bits = value; |
191 _header._bits = value; |
191 } |
192 } |
192 void release_set_header(intptr_t value) { |
|
193 OrderAccess::release_store_ptr(&_header._bits, value); |
|
194 } |
|
195 intptr_t header() { |
193 intptr_t header() { |
196 return _header._bits; |
194 return _header._bits; |
197 } |
195 } |
198 void set_cell_at(int index, intptr_t value) { |
196 void set_cell_at(int index, intptr_t value) { |
199 _cells[index] = value; |
197 _cells[index] = value; |
438 virtual bool is_MultiBranchData() const { return false; } |
439 virtual bool is_MultiBranchData() const { return false; } |
439 virtual bool is_ArgInfoData() const { return false; } |
440 virtual bool is_ArgInfoData() const { return false; } |
440 virtual bool is_CallTypeData() const { return false; } |
441 virtual bool is_CallTypeData() const { return false; } |
441 virtual bool is_VirtualCallTypeData()const { return false; } |
442 virtual bool is_VirtualCallTypeData()const { return false; } |
442 virtual bool is_ParametersTypeData() const { return false; } |
443 virtual bool is_ParametersTypeData() const { return false; } |
|
444 virtual bool is_SpeculativeTrapData()const { return false; } |
443 |
445 |
444 |
446 |
445 BitData* as_BitData() const { |
447 BitData* as_BitData() const { |
446 assert(is_BitData(), "wrong type"); |
448 assert(is_BitData(), "wrong type"); |
447 return is_BitData() ? (BitData*) this : NULL; |
449 return is_BitData() ? (BitData*) this : NULL; |
491 return is_VirtualCallTypeData() ? (VirtualCallTypeData*)this : NULL; |
493 return is_VirtualCallTypeData() ? (VirtualCallTypeData*)this : NULL; |
492 } |
494 } |
493 ParametersTypeData* as_ParametersTypeData() const { |
495 ParametersTypeData* as_ParametersTypeData() const { |
494 assert(is_ParametersTypeData(), "wrong type"); |
496 assert(is_ParametersTypeData(), "wrong type"); |
495 return is_ParametersTypeData() ? (ParametersTypeData*)this : NULL; |
497 return is_ParametersTypeData() ? (ParametersTypeData*)this : NULL; |
|
498 } |
|
499 SpeculativeTrapData* as_SpeculativeTrapData() const { |
|
500 assert(is_SpeculativeTrapData(), "wrong type"); |
|
501 return is_SpeculativeTrapData() ? (SpeculativeTrapData*)this : NULL; |
496 } |
502 } |
497 |
503 |
498 |
504 |
499 // Subclass specific initialization |
505 // Subclass specific initialization |
500 virtual void post_initialize(BytecodeStream* stream, MethodData* mdo) {} |
506 virtual void post_initialize(BytecodeStream* stream, MethodData* mdo) {} |
507 // an oop in a ProfileData to the ci equivalent. Generally speaking, |
513 // an oop in a ProfileData to the ci equivalent. Generally speaking, |
508 // most ProfileData don't require any translation, so we provide the null |
514 // most ProfileData don't require any translation, so we provide the null |
509 // translation here, and the required translators are in the ci subclasses. |
515 // translation here, and the required translators are in the ci subclasses. |
510 virtual void translate_from(const ProfileData* data) {} |
516 virtual void translate_from(const ProfileData* data) {} |
511 |
517 |
512 virtual void print_data_on(outputStream* st) const { |
518 virtual void print_data_on(outputStream* st, const char* extra = NULL) const { |
513 ShouldNotReachHere(); |
519 ShouldNotReachHere(); |
514 } |
520 } |
515 |
521 |
|
522 void print_data_on(outputStream* st, const MethodData* md) const; |
|
523 |
516 #ifndef PRODUCT |
524 #ifndef PRODUCT |
517 void print_shared(outputStream* st, const char* name) const; |
525 void print_shared(outputStream* st, const char* name, const char* extra) const; |
518 void tab(outputStream* st, bool first = false) const; |
526 void tab(outputStream* st, bool first = false) const; |
519 #endif |
527 #endif |
520 }; |
528 }; |
521 |
529 |
522 // BitData |
530 // BitData |
724 |
732 |
725 // Specific initialization. |
733 // Specific initialization. |
726 void post_initialize(BytecodeStream* stream, MethodData* mdo); |
734 void post_initialize(BytecodeStream* stream, MethodData* mdo); |
727 |
735 |
728 #ifndef PRODUCT |
736 #ifndef PRODUCT |
729 void print_data_on(outputStream* st) const; |
737 void print_data_on(outputStream* st, const char* extra = NULL) const; |
730 #endif |
738 #endif |
731 }; |
739 }; |
732 |
740 |
733 // Entries in a ProfileData object to record types: it can either be |
741 // Entries in a ProfileData object to record types: it can either be |
734 // none (no profile), unknown (conflicting profile data) or a klass if |
742 // none (no profile), unknown (conflicting profile data) or a klass if |
1911 virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) { |
1919 virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) { |
1912 _parameters.clean_weak_klass_links(is_alive_closure); |
1920 _parameters.clean_weak_klass_links(is_alive_closure); |
1913 } |
1921 } |
1914 |
1922 |
1915 #ifndef PRODUCT |
1923 #ifndef PRODUCT |
1916 virtual void print_data_on(outputStream* st) const; |
1924 virtual void print_data_on(outputStream* st, const char* extra = NULL) const; |
1917 #endif |
1925 #endif |
1918 |
1926 |
1919 static ByteSize stack_slot_offset(int i) { |
1927 static ByteSize stack_slot_offset(int i) { |
1920 return cell_offset(stack_slot_local_offset(i)); |
1928 return cell_offset(stack_slot_local_offset(i)); |
1921 } |
1929 } |
1922 |
1930 |
1923 static ByteSize type_offset(int i) { |
1931 static ByteSize type_offset(int i) { |
1924 return cell_offset(type_local_offset(i)); |
1932 return cell_offset(type_local_offset(i)); |
1925 } |
1933 } |
|
1934 }; |
|
1935 |
|
1936 // SpeculativeTrapData |
|
1937 // |
|
1938 // A SpeculativeTrapData is used to record traps due to type |
|
1939 // speculation. It records the root of the compilation: that type |
|
1940 // speculation is wrong in the context of one compilation (for |
|
1941 // method1) doesn't mean it's wrong in the context of another one (for |
|
1942 // method2). Type speculation could have more/different data in the |
|
1943 // context of the compilation of method2 and it's worthwhile to try an |
|
1944 // optimization that failed for compilation of method1 in the context |
|
1945 // of compilation of method2. |
|
1946 // Space for SpeculativeTrapData entries is allocated from the extra |
|
1947 // data space in the MDO. If we run out of space, the trap data for |
|
1948 // the ProfileData at that bci is updated. |
|
1949 class SpeculativeTrapData : public ProfileData { |
|
1950 protected: |
|
1951 enum { |
|
1952 method_offset, |
|
1953 speculative_trap_cell_count |
|
1954 }; |
|
1955 public: |
|
1956 SpeculativeTrapData(DataLayout* layout) : ProfileData(layout) { |
|
1957 assert(layout->tag() == DataLayout::speculative_trap_data_tag, "wrong type"); |
|
1958 } |
|
1959 |
|
1960 virtual bool is_SpeculativeTrapData() const { return true; } |
|
1961 |
|
1962 static int static_cell_count() { |
|
1963 return speculative_trap_cell_count; |
|
1964 } |
|
1965 |
|
1966 virtual int cell_count() const { |
|
1967 return static_cell_count(); |
|
1968 } |
|
1969 |
|
1970 // Direct accessor |
|
1971 Method* method() const { |
|
1972 return (Method*)intptr_at(method_offset); |
|
1973 } |
|
1974 |
|
1975 void set_method(Method* m) { |
|
1976 set_intptr_at(method_offset, (intptr_t)m); |
|
1977 } |
|
1978 |
|
1979 #ifndef PRODUCT |
|
1980 virtual void print_data_on(outputStream* st, const char* extra = NULL) const; |
|
1981 #endif |
1926 }; |
1982 }; |
1927 |
1983 |
1928 // MethodData* |
1984 // MethodData* |
1929 // |
1985 // |
1930 // A MethodData* holds information which has been collected about |
1986 // A MethodData* holds information which has been collected about |
1983 int _size; |
2039 int _size; |
1984 |
2040 |
1985 // Cached hint for bci_to_dp and bci_to_data |
2041 // Cached hint for bci_to_dp and bci_to_data |
1986 int _hint_di; |
2042 int _hint_di; |
1987 |
2043 |
|
2044 Mutex _extra_data_lock; |
|
2045 |
1988 MethodData(methodHandle method, int size, TRAPS); |
2046 MethodData(methodHandle method, int size, TRAPS); |
1989 public: |
2047 public: |
1990 static MethodData* allocate(ClassLoaderData* loader_data, methodHandle method, TRAPS); |
2048 static MethodData* allocate(ClassLoaderData* loader_data, methodHandle method, TRAPS); |
1991 MethodData() {}; // For ciMethodData |
2049 MethodData() : _extra_data_lock(Monitor::leaf, "MDO extra data lock") {}; // For ciMethodData |
1992 |
2050 |
1993 bool is_methodData() const volatile { return true; } |
2051 bool is_methodData() const volatile { return true; } |
1994 |
2052 |
1995 // Whole-method sticky bits and flags |
2053 // Whole-method sticky bits and flags |
1996 enum { |
2054 enum { |
1997 _trap_hist_limit = 17, // decoupled from Deoptimization::Reason_LIMIT |
2055 _trap_hist_limit = 19, // decoupled from Deoptimization::Reason_LIMIT |
1998 _trap_hist_mask = max_jubyte, |
2056 _trap_hist_mask = max_jubyte, |
1999 _extra_data_count = 4 // extra DataLayout headers, for trap history |
2057 _extra_data_count = 4 // extra DataLayout headers, for trap history |
2000 }; // Public flag values |
2058 }; // Public flag values |
2001 private: |
2059 private: |
2002 uint _nof_decompiles; // count of all nmethod removals |
2060 uint _nof_decompiles; // count of all nmethod removals |
2023 // Same for backedges. |
2081 // Same for backedges. |
2024 InvocationCounter _backedge_counter; |
2082 InvocationCounter _backedge_counter; |
2025 // Counter values at the time profiling started. |
2083 // Counter values at the time profiling started. |
2026 int _invocation_counter_start; |
2084 int _invocation_counter_start; |
2027 int _backedge_counter_start; |
2085 int _backedge_counter_start; |
|
2086 |
|
2087 #if INCLUDE_RTM_OPT |
|
2088 // State of RTM code generation during compilation of the method |
|
2089 int _rtm_state; |
|
2090 #endif |
|
2091 |
2028 // Number of loops and blocks is computed when compiling the first |
2092 // Number of loops and blocks is computed when compiling the first |
2029 // time with C1. It is used to determine if method is trivial. |
2093 // time with C1. It is used to determine if method is trivial. |
2030 short _num_loops; |
2094 short _num_loops; |
2031 short _num_blocks; |
2095 short _num_blocks; |
2032 // Highest compile level this method has ever seen. |
2096 // Highest compile level this method has ever seen. |
2047 intptr_t _data[1]; |
2111 intptr_t _data[1]; |
2048 |
2112 |
2049 // Helper for size computation |
2113 // Helper for size computation |
2050 static int compute_data_size(BytecodeStream* stream); |
2114 static int compute_data_size(BytecodeStream* stream); |
2051 static int bytecode_cell_count(Bytecodes::Code code); |
2115 static int bytecode_cell_count(Bytecodes::Code code); |
|
2116 static bool is_speculative_trap_bytecode(Bytecodes::Code code); |
2052 enum { no_profile_data = -1, variable_cell_count = -2 }; |
2117 enum { no_profile_data = -1, variable_cell_count = -2 }; |
2053 |
2118 |
2054 // Helper for initialization |
2119 // Helper for initialization |
2055 DataLayout* data_layout_at(int data_index) const { |
2120 DataLayout* data_layout_at(int data_index) const { |
2056 assert(data_index % sizeof(intptr_t) == 0, "unaligned"); |
2121 assert(data_index % sizeof(intptr_t) == 0, "unaligned"); |
2090 } |
2155 } |
2091 |
2156 |
2092 // What is the index of the first data entry? |
2157 // What is the index of the first data entry? |
2093 int first_di() const { return 0; } |
2158 int first_di() const { return 0; } |
2094 |
2159 |
|
2160 ProfileData* bci_to_extra_data_helper(int bci, Method* m, DataLayout*& dp, bool concurrent); |
2095 // Find or create an extra ProfileData: |
2161 // Find or create an extra ProfileData: |
2096 ProfileData* bci_to_extra_data(int bci, bool create_if_missing); |
2162 ProfileData* bci_to_extra_data(int bci, Method* m, bool create_if_missing); |
2097 |
2163 |
2098 // return the argument info cell |
2164 // return the argument info cell |
2099 ArgInfoData *arg_info(); |
2165 ArgInfoData *arg_info(); |
2100 |
2166 |
2101 enum { |
2167 enum { |
2114 static bool profile_return_for_invoke(methodHandle m, int bci); |
2180 static bool profile_return_for_invoke(methodHandle m, int bci); |
2115 static int profile_parameters_flag(); |
2181 static int profile_parameters_flag(); |
2116 static bool profile_parameters_jsr292_only(); |
2182 static bool profile_parameters_jsr292_only(); |
2117 static bool profile_all_parameters(); |
2183 static bool profile_all_parameters(); |
2118 |
2184 |
|
2185 void clean_extra_data(BoolObjectClosure* is_alive); |
|
2186 void clean_extra_data_helper(DataLayout* dp, int shift, bool reset = false); |
|
2187 void verify_extra_data_clean(BoolObjectClosure* is_alive); |
|
2188 |
2119 public: |
2189 public: |
2120 static int header_size() { |
2190 static int header_size() { |
2121 return sizeof(MethodData)/wordSize; |
2191 return sizeof(MethodData)/wordSize; |
2122 } |
2192 } |
2123 |
2193 |
2124 // Compute the size of a MethodData* before it is created. |
2194 // Compute the size of a MethodData* before it is created. |
2125 static int compute_allocation_size_in_bytes(methodHandle method); |
2195 static int compute_allocation_size_in_bytes(methodHandle method); |
2126 static int compute_allocation_size_in_words(methodHandle method); |
2196 static int compute_allocation_size_in_words(methodHandle method); |
2127 static int compute_extra_data_count(int data_size, int empty_bc_count); |
2197 static int compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps); |
2128 |
2198 |
2129 // Determine if a given bytecode can have profile information. |
2199 // Determine if a given bytecode can have profile information. |
2130 static bool bytecode_has_profile(Bytecodes::Code code) { |
2200 static bool bytecode_has_profile(Bytecodes::Code code) { |
2131 return bytecode_cell_count(code) != no_profile_data; |
2201 return bytecode_cell_count(code) != no_profile_data; |
2132 } |
2202 } |
2179 _backedge_counter_start = backedge_count(); |
2249 _backedge_counter_start = backedge_count(); |
2180 } |
2250 } |
2181 |
2251 |
2182 InvocationCounter* invocation_counter() { return &_invocation_counter; } |
2252 InvocationCounter* invocation_counter() { return &_invocation_counter; } |
2183 InvocationCounter* backedge_counter() { return &_backedge_counter; } |
2253 InvocationCounter* backedge_counter() { return &_backedge_counter; } |
|
2254 |
|
2255 #if INCLUDE_RTM_OPT |
|
2256 int rtm_state() const { |
|
2257 return _rtm_state; |
|
2258 } |
|
2259 void set_rtm_state(RTMState rstate) { |
|
2260 _rtm_state = (int)rstate; |
|
2261 } |
|
2262 void atomic_set_rtm_state(RTMState rstate) { |
|
2263 Atomic::store((int)rstate, &_rtm_state); |
|
2264 } |
|
2265 |
|
2266 static int rtm_state_offset_in_bytes() { |
|
2267 return offset_of(MethodData, _rtm_state); |
|
2268 } |
|
2269 #endif |
2184 |
2270 |
2185 void set_would_profile(bool p) { _would_profile = p; } |
2271 void set_would_profile(bool p) { _would_profile = p; } |
2186 bool would_profile() const { return _would_profile; } |
2272 bool would_profile() const { return _would_profile; } |
2187 |
2273 |
2188 int highest_comp_level() const { return _highest_comp_level; } |
2274 int highest_comp_level() const { return _highest_comp_level; } |
2263 |
2349 |
2264 // Get the data at an arbitrary bci, or NULL if there is none. |
2350 // Get the data at an arbitrary bci, or NULL if there is none. |
2265 ProfileData* bci_to_data(int bci); |
2351 ProfileData* bci_to_data(int bci); |
2266 |
2352 |
2267 // Same, but try to create an extra_data record if one is needed: |
2353 // Same, but try to create an extra_data record if one is needed: |
2268 ProfileData* allocate_bci_to_data(int bci) { |
2354 ProfileData* allocate_bci_to_data(int bci, Method* m) { |
2269 ProfileData* data = bci_to_data(bci); |
2355 ProfileData* data = NULL; |
2270 return (data != NULL) ? data : bci_to_extra_data(bci, true); |
2356 // If m not NULL, try to allocate a SpeculativeTrapData entry |
|
2357 if (m == NULL) { |
|
2358 data = bci_to_data(bci); |
|
2359 } |
|
2360 if (data != NULL) { |
|
2361 return data; |
|
2362 } |
|
2363 data = bci_to_extra_data(bci, m, true); |
|
2364 if (data != NULL) { |
|
2365 return data; |
|
2366 } |
|
2367 // If SpeculativeTrapData allocation fails try to allocate a |
|
2368 // regular entry |
|
2369 data = bci_to_data(bci); |
|
2370 if (data != NULL) { |
|
2371 return data; |
|
2372 } |
|
2373 return bci_to_extra_data(bci, NULL, true); |
2271 } |
2374 } |
2272 |
2375 |
2273 // Add a handful of extra data records, for trap tracking. |
2376 // Add a handful of extra data records, for trap tracking. |
2274 DataLayout* extra_data_base() const { return limit_data_position(); } |
2377 DataLayout* extra_data_base() const { return limit_data_position(); } |
2275 DataLayout* extra_data_limit() const { return (DataLayout*)((address)this + size_in_bytes()); } |
2378 DataLayout* extra_data_limit() const { return (DataLayout*)((address)this + size_in_bytes()); } |
2276 int extra_data_size() const { return (address)extra_data_limit() |
2379 int extra_data_size() const { return (address)extra_data_limit() |
2277 - (address)extra_data_base(); } |
2380 - (address)extra_data_base(); } |
2278 static DataLayout* next_extra(DataLayout* dp) { return (DataLayout*)((address)dp + in_bytes(DataLayout::cell_offset(0))); } |
2381 static DataLayout* next_extra(DataLayout* dp); |
2279 |
2382 |
2280 // Return (uint)-1 for overflow. |
2383 // Return (uint)-1 for overflow. |
2281 uint trap_count(int reason) const { |
2384 uint trap_count(int reason) const { |
2282 assert((uint)reason < _trap_hist_limit, "oob"); |
2385 assert((uint)reason < _trap_hist_limit, "oob"); |
2283 return (int)((_trap_hist._array[reason]+1) & _trap_hist_mask) - 1; |
2386 return (int)((_trap_hist._array[reason]+1) & _trap_hist_mask) - 1; |
2373 static bool profile_parameters_for_method(methodHandle m); |
2476 static bool profile_parameters_for_method(methodHandle m); |
2374 static bool profile_arguments(); |
2477 static bool profile_arguments(); |
2375 static bool profile_return(); |
2478 static bool profile_return(); |
2376 static bool profile_parameters(); |
2479 static bool profile_parameters(); |
2377 static bool profile_return_jsr292_only(); |
2480 static bool profile_return_jsr292_only(); |
|
2481 |
|
2482 void clean_method_data(BoolObjectClosure* is_alive); |
2378 }; |
2483 }; |
2379 |
2484 |
2380 #endif // SHARE_VM_OOPS_METHODDATAOOP_HPP |
2485 #endif // SHARE_VM_OOPS_METHODDATAOOP_HPP |