1 /*
2 * Copyright (c) 2000, 2018, 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 *
829 case Bytecodes::_instanceof:
830 case Bytecodes::_aastore:
831 case Bytecodes::_invokevirtual:
832 case Bytecodes::_invokeinterface:
833 case Bytecodes::_if_acmpeq:
834 case Bytecodes::_if_acmpne:
835 case Bytecodes::_ifnull:
836 case Bytecodes::_ifnonnull:
837 case Bytecodes::_invokestatic:
838 #ifdef COMPILER2
839 if (is_server_compilation_mode_vm()) {
840 return UseTypeSpeculation;
841 }
842 #endif
843 default:
844 return false;
845 }
846 return false;
847 }
848
849 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps) {
850 #if INCLUDE_JVMCI
851 if (ProfileTraps) {
852 // Assume that up to 30% of the possibly trapping BCIs with no MDP will need to allocate one.
853 int extra_data_count = MIN2(empty_bc_count, MAX2(4, (empty_bc_count * 30) / 100));
854
855 // Make sure we have a minimum number of extra data slots to
856 // allocate SpeculativeTrapData entries. We would want to have one
857 // entry per compilation that inlines this method and for which
858 // some type speculation assumption fails. So the room we need for
859 // the SpeculativeTrapData entries doesn't directly depend on the
860 // size of the method. Because it's hard to estimate, we reserve
861 // space for an arbitrary number of entries.
862 int spec_data_count = (needs_speculative_traps ? SpecTrapLimitExtraEntries : 0) *
863 (SpeculativeTrapData::static_cell_count() + DataLayout::header_size_in_cells());
864
865 return MAX2(extra_data_count, spec_data_count);
866 } else {
867 return 0;
868 }
1210
1211 void MethodData::init() {
1212 _invocation_counter.init();
1213 _backedge_counter.init();
1214 _invocation_counter_start = 0;
1215 _backedge_counter_start = 0;
1216
1217 // Set per-method invoke- and backedge mask.
1218 double scale = 1.0;
1219 CompilerOracle::has_option_value(_method, "CompileThresholdScaling", scale);
1220 _invoke_mask = right_n_bits(CompilerConfig::scaled_freq_log(Tier0InvokeNotifyFreqLog, scale)) << InvocationCounter::count_shift;
1221 _backedge_mask = right_n_bits(CompilerConfig::scaled_freq_log(Tier0BackedgeNotifyFreqLog, scale)) << InvocationCounter::count_shift;
1222
1223 _tenure_traps = 0;
1224 _num_loops = 0;
1225 _num_blocks = 0;
1226 _would_profile = unknown;
1227
1228 #if INCLUDE_JVMCI
1229 _jvmci_ir_size = 0;
1230 #endif
1231
1232 #if INCLUDE_RTM_OPT
1233 _rtm_state = NoRTM; // No RTM lock eliding by default
1234 if (UseRTMLocking &&
1235 !CompilerOracle::has_option_string(_method, "NoRTMLockEliding")) {
1236 if (CompilerOracle::has_option_string(_method, "UseRTMLockEliding") || !UseRTMDeopt) {
1237 // Generate RTM lock eliding code without abort ratio calculation code.
1238 _rtm_state = UseRTM;
1239 } else if (UseRTMDeopt) {
1240 // Generate RTM lock eliding code and include abort ratio calculation
1241 // code if UseRTMDeopt is on.
1242 _rtm_state = ProfileRTM;
1243 }
1244 }
1245 #endif
1246
1247 // Initialize flags and trap history.
1248 _nof_decompiles = 0;
1249 _nof_overflow_recompiles = 0;
|
1 /*
2 * Copyright (c) 2000, 2019, 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 *
829 case Bytecodes::_instanceof:
830 case Bytecodes::_aastore:
831 case Bytecodes::_invokevirtual:
832 case Bytecodes::_invokeinterface:
833 case Bytecodes::_if_acmpeq:
834 case Bytecodes::_if_acmpne:
835 case Bytecodes::_ifnull:
836 case Bytecodes::_ifnonnull:
837 case Bytecodes::_invokestatic:
838 #ifdef COMPILER2
839 if (is_server_compilation_mode_vm()) {
840 return UseTypeSpeculation;
841 }
842 #endif
843 default:
844 return false;
845 }
846 return false;
847 }
848
849 #if INCLUDE_JVMCI
850
851 void* FailedSpeculation::operator new(size_t size, size_t fs_size) throw() {
852 return CHeapObj<mtCompiler>::operator new(fs_size, std::nothrow);
853 }
854
855 FailedSpeculation::FailedSpeculation(address speculation, int speculation_len) : _data_len(speculation_len), _next(NULL) {
856 memcpy(data(), speculation, speculation_len);
857 }
858
859 // A heuristic check to detect nmethods that outlive a failed speculations list.
860 static void guarantee_failed_speculations_alive(nmethod* nm, FailedSpeculation** failed_speculations_address) {
861 jlong head = (jlong)(address) *failed_speculations_address;
862 if ((head & 0x1) == 0x1) {
863 stringStream st;
864 if (nm != NULL) {
865 st.print("%d", nm->compile_id());
866 Method* method = nm->method();
867 st.print_raw("{");
868 if (method != NULL) {
869 method->print_name(&st);
870 } else {
871 const char* jvmci_name = nm->jvmci_name();
872 if (jvmci_name != NULL) {
873 st.print_raw(jvmci_name);
874 }
875 }
876 st.print_raw("}");
877 } else {
878 st.print("<unknown>");
879 }
880 fatal("Adding to failed speculations list that appears to have been freed. Source: %s", st.as_string());
881 }
882 }
883
884 bool FailedSpeculation::add_failed_speculation(nmethod* nm, FailedSpeculation** failed_speculations_address, address speculation, int speculation_len) {
885 assert(failed_speculations_address != NULL, "must be");
886 size_t fs_size = sizeof(FailedSpeculation) + speculation_len;
887 FailedSpeculation* fs = new (fs_size) FailedSpeculation(speculation, speculation_len);
888 if (fs == NULL) {
889 // no memory -> ignore failed speculation
890 return false;
891 }
892
893 guarantee(is_aligned(fs, sizeof(FailedSpeculation*)), "FailedSpeculation objects must be pointer aligned");
894 guarantee_failed_speculations_alive(nm, failed_speculations_address);
895
896 FailedSpeculation** cursor = failed_speculations_address;
897 do {
898 if (*cursor == NULL) {
899 FailedSpeculation* old_fs = Atomic::cmpxchg(fs, cursor, (FailedSpeculation*) NULL);
900 if (old_fs == NULL) {
901 // Successfully appended fs to end of the list
902 return true;
903 }
904 cursor = old_fs->next_adr();
905 } else {
906 cursor = (*cursor)->next_adr();
907 }
908 } while (true);
909 }
910
911 void FailedSpeculation::free_failed_speculations(FailedSpeculation** failed_speculations_address) {
912 assert(failed_speculations_address != NULL, "must be");
913 FailedSpeculation* fs = *failed_speculations_address;
914 while (fs != NULL) {
915 FailedSpeculation* next = fs->next();
916 delete fs;
917 fs = next;
918 }
919
920 // Write an unaligned value to failed_speculations_address to denote
921 // that it is no longer a valid pointer. This is allows for the check
922 // in add_failed_speculation against adding to a freed failed
923 // speculations list.
924 long* head = (long*) failed_speculations_address;
925 (*head) = (*head) | 0x1;
926 }
927 #endif // INCLUDE_JVMCI
928
929 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps) {
930 #if INCLUDE_JVMCI
931 if (ProfileTraps) {
932 // Assume that up to 30% of the possibly trapping BCIs with no MDP will need to allocate one.
933 int extra_data_count = MIN2(empty_bc_count, MAX2(4, (empty_bc_count * 30) / 100));
934
935 // Make sure we have a minimum number of extra data slots to
936 // allocate SpeculativeTrapData entries. We would want to have one
937 // entry per compilation that inlines this method and for which
938 // some type speculation assumption fails. So the room we need for
939 // the SpeculativeTrapData entries doesn't directly depend on the
940 // size of the method. Because it's hard to estimate, we reserve
941 // space for an arbitrary number of entries.
942 int spec_data_count = (needs_speculative_traps ? SpecTrapLimitExtraEntries : 0) *
943 (SpeculativeTrapData::static_cell_count() + DataLayout::header_size_in_cells());
944
945 return MAX2(extra_data_count, spec_data_count);
946 } else {
947 return 0;
948 }
1290
1291 void MethodData::init() {
1292 _invocation_counter.init();
1293 _backedge_counter.init();
1294 _invocation_counter_start = 0;
1295 _backedge_counter_start = 0;
1296
1297 // Set per-method invoke- and backedge mask.
1298 double scale = 1.0;
1299 CompilerOracle::has_option_value(_method, "CompileThresholdScaling", scale);
1300 _invoke_mask = right_n_bits(CompilerConfig::scaled_freq_log(Tier0InvokeNotifyFreqLog, scale)) << InvocationCounter::count_shift;
1301 _backedge_mask = right_n_bits(CompilerConfig::scaled_freq_log(Tier0BackedgeNotifyFreqLog, scale)) << InvocationCounter::count_shift;
1302
1303 _tenure_traps = 0;
1304 _num_loops = 0;
1305 _num_blocks = 0;
1306 _would_profile = unknown;
1307
1308 #if INCLUDE_JVMCI
1309 _jvmci_ir_size = 0;
1310 _failed_speculations = NULL;
1311 #endif
1312
1313 #if INCLUDE_RTM_OPT
1314 _rtm_state = NoRTM; // No RTM lock eliding by default
1315 if (UseRTMLocking &&
1316 !CompilerOracle::has_option_string(_method, "NoRTMLockEliding")) {
1317 if (CompilerOracle::has_option_string(_method, "UseRTMLockEliding") || !UseRTMDeopt) {
1318 // Generate RTM lock eliding code without abort ratio calculation code.
1319 _rtm_state = UseRTM;
1320 } else if (UseRTMDeopt) {
1321 // Generate RTM lock eliding code and include abort ratio calculation
1322 // code if UseRTMDeopt is on.
1323 _rtm_state = ProfileRTM;
1324 }
1325 }
1326 #endif
1327
1328 // Initialize flags and trap history.
1329 _nof_decompiles = 0;
1330 _nof_overflow_recompiles = 0;
|