1 /* |
1 /* |
2 * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. |
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. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
843 default: |
843 default: |
844 return false; |
844 return false; |
845 } |
845 } |
846 return false; |
846 return false; |
847 } |
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 |
848 |
928 |
849 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps) { |
929 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps) { |
850 #if INCLUDE_JVMCI |
930 #if INCLUDE_JVMCI |
851 if (ProfileTraps) { |
931 if (ProfileTraps) { |
852 // Assume that up to 30% of the possibly trapping BCIs with no MDP will need to allocate one. |
932 // Assume that up to 30% of the possibly trapping BCIs with no MDP will need to allocate one. |