| File: | jdk/src/hotspot/share/code/stubs.cpp |
| Warning: | line 75, column 22 Called C++ object pointer is null |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* | |||
| 2 | * Copyright (c) 1997, 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 | * | |||
| 23 | */ | |||
| 24 | ||||
| 25 | #include "precompiled.hpp" | |||
| 26 | #include "code/codeBlob.hpp" | |||
| 27 | #include "code/codeCache.hpp" | |||
| 28 | #include "code/stubs.hpp" | |||
| 29 | #include "memory/allocation.inline.hpp" | |||
| 30 | #include "oops/oop.inline.hpp" | |||
| 31 | #include "runtime/mutexLocker.hpp" | |||
| 32 | #include "utilities/align.hpp" | |||
| 33 | ||||
| 34 | ||||
| 35 | // Implementation of StubQueue | |||
| 36 | // | |||
| 37 | // Standard wrap-around queue implementation; the queue dimensions | |||
| 38 | // are specified by the _queue_begin & _queue_end indices. The queue | |||
| 39 | // can be in two states (transparent to the outside): | |||
| 40 | // | |||
| 41 | // a) contiguous state: all queue entries in one block (or empty) | |||
| 42 | // | |||
| 43 | // Queue: |...|XXXXXXX|...............| | |||
| 44 | // ^0 ^begin ^end ^size = limit | |||
| 45 | // |_______| | |||
| 46 | // one block | |||
| 47 | // | |||
| 48 | // b) non-contiguous state: queue entries in two blocks | |||
| 49 | // | |||
| 50 | // Queue: |XXX|.......|XXXXXXX|.......| | |||
| 51 | // ^0 ^end ^begin ^limit ^size | |||
| 52 | // |___| |_______| | |||
| 53 | // 1st block 2nd block | |||
| 54 | // | |||
| 55 | // In the non-contiguous state, the wrap-around point is | |||
| 56 | // indicated via the _buffer_limit index since the last | |||
| 57 | // queue entry may not fill up the queue completely in | |||
| 58 | // which case we need to know where the 2nd block's end | |||
| 59 | // is to do the proper wrap-around. When removing the | |||
| 60 | // last entry of the 2nd block, _buffer_limit is reset | |||
| 61 | // to _buffer_size. | |||
| 62 | // | |||
| 63 | // CAUTION: DO NOT MESS WITH THIS CODE IF YOU CANNOT PROVE | |||
| 64 | // ITS CORRECTNESS! THIS CODE IS MORE SUBTLE THAN IT LOOKS! | |||
| 65 | ||||
| 66 | ||||
| 67 | StubQueue::StubQueue(StubInterface* stub_interface, int buffer_size, | |||
| 68 | Mutex* lock, const char* name) : _mutex(lock) { | |||
| 69 | intptr_t size = align_up(buffer_size, 2*BytesPerWord); | |||
| 70 | BufferBlob* blob = BufferBlob::create(name, size); | |||
| ||||
| 71 | if( blob == NULL__null) { | |||
| 72 | vm_exit_out_of_memory(size, OOM_MALLOC_ERROR, "CodeCache: no room for %s", name)do { report_vm_out_of_memory("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp" , 72, size, OOM_MALLOC_ERROR, "CodeCache: no room for %s", name ); ::breakpoint(); } while (0); | |||
| 73 | } | |||
| 74 | _stub_interface = stub_interface; | |||
| 75 | _buffer_size = blob->content_size(); | |||
| ||||
| 76 | _buffer_limit = blob->content_size(); | |||
| 77 | _stub_buffer = blob->content_begin(); | |||
| 78 | _queue_begin = 0; | |||
| 79 | _queue_end = 0; | |||
| 80 | _number_of_stubs = 0; | |||
| 81 | } | |||
| 82 | ||||
| 83 | ||||
| 84 | StubQueue::~StubQueue() { | |||
| 85 | // Note: Currently StubQueues are never destroyed so nothing needs to be done here. | |||
| 86 | // If we want to implement the destructor, we need to release the BufferBlob | |||
| 87 | // allocated in the constructor (i.e., we need to keep it around or look it | |||
| 88 | // up via CodeCache::find_blob(...). | |||
| 89 | Unimplemented()do { (*g_assert_poison) = 'X';; report_unimplemented("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp" , 89); ::breakpoint(); } while (0); | |||
| 90 | } | |||
| 91 | ||||
| 92 | void StubQueue::deallocate_unused_tail() { | |||
| 93 | CodeBlob* blob = CodeCache::find_blob((void*)_stub_buffer); | |||
| 94 | CodeCache::free_unused_tail(blob, used_space()); | |||
| 95 | // Update the limits to the new, trimmed CodeBlob size | |||
| 96 | _buffer_size = blob->content_size(); | |||
| 97 | _buffer_limit = blob->content_size(); | |||
| 98 | } | |||
| 99 | ||||
| 100 | Stub* StubQueue::stub_containing(address pc) const { | |||
| 101 | if (contains(pc)) { | |||
| 102 | for (Stub* s = first(); s != NULL__null; s = next(s)) { | |||
| 103 | if (stub_contains(s, pc)) return s; | |||
| 104 | } | |||
| 105 | } | |||
| 106 | return NULL__null; | |||
| 107 | } | |||
| 108 | ||||
| 109 | ||||
| 110 | Stub* StubQueue::request_committed(int code_size) { | |||
| 111 | Stub* s = request(code_size); | |||
| 112 | if (s != NULL__null) commit(code_size); | |||
| 113 | return s; | |||
| 114 | } | |||
| 115 | ||||
| 116 | ||||
| 117 | Stub* StubQueue::request(int requested_code_size) { | |||
| 118 | assert(requested_code_size > 0, "requested_code_size must be > 0")do { if (!(requested_code_size > 0)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp" , 118, "assert(" "requested_code_size > 0" ") failed", "requested_code_size must be > 0" ); ::breakpoint(); } } while (0); | |||
| 119 | if (_mutex != NULL__null) _mutex->lock_without_safepoint_check(); | |||
| 120 | Stub* s = current_stub(); | |||
| 121 | int requested_size = align_up(stub_code_size_to_size(requested_code_size), CodeEntryAlignment); | |||
| 122 | if (requested_size <= available_space()) { | |||
| 123 | if (is_contiguous()) { | |||
| 124 | // Queue: |...|XXXXXXX|.............| | |||
| 125 | // ^0 ^begin ^end ^size = limit | |||
| 126 | assert(_buffer_limit == _buffer_size, "buffer must be fully usable")do { if (!(_buffer_limit == _buffer_size)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp" , 126, "assert(" "_buffer_limit == _buffer_size" ") failed", "buffer must be fully usable" ); ::breakpoint(); } } while (0); | |||
| 127 | if (_queue_end + requested_size <= _buffer_size) { | |||
| 128 | // code fits in at the end => nothing to do | |||
| 129 | stub_initialize(s, requested_size); | |||
| 130 | return s; | |||
| 131 | } else { | |||
| 132 | // stub doesn't fit in at the queue end | |||
| 133 | // => reduce buffer limit & wrap around | |||
| 134 | assert(!is_empty(), "just checkin'")do { if (!(!is_empty())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp" , 134, "assert(" "!is_empty()" ") failed", "just checkin'"); :: breakpoint(); } } while (0); | |||
| 135 | _buffer_limit = _queue_end; | |||
| 136 | _queue_end = 0; | |||
| 137 | } | |||
| 138 | } | |||
| 139 | } | |||
| 140 | if (requested_size <= available_space()) { | |||
| 141 | assert(!is_contiguous(), "just checkin'")do { if (!(!is_contiguous())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp" , 141, "assert(" "!is_contiguous()" ") failed", "just checkin'" ); ::breakpoint(); } } while (0); | |||
| 142 | assert(_buffer_limit <= _buffer_size, "queue invariant broken")do { if (!(_buffer_limit <= _buffer_size)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp" , 142, "assert(" "_buffer_limit <= _buffer_size" ") failed" , "queue invariant broken"); ::breakpoint(); } } while (0); | |||
| 143 | // Queue: |XXX|.......|XXXXXXX|.......| | |||
| 144 | // ^0 ^end ^begin ^limit ^size | |||
| 145 | s = current_stub(); | |||
| 146 | stub_initialize(s, requested_size); | |||
| 147 | return s; | |||
| 148 | } | |||
| 149 | // Not enough space left | |||
| 150 | if (_mutex != NULL__null) _mutex->unlock(); | |||
| 151 | return NULL__null; | |||
| 152 | } | |||
| 153 | ||||
| 154 | ||||
| 155 | void StubQueue::commit(int committed_code_size) { | |||
| 156 | assert(committed_code_size > 0, "committed_code_size must be > 0")do { if (!(committed_code_size > 0)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp" , 156, "assert(" "committed_code_size > 0" ") failed", "committed_code_size must be > 0" ); ::breakpoint(); } } while (0); | |||
| 157 | int committed_size = align_up(stub_code_size_to_size(committed_code_size), CodeEntryAlignment); | |||
| 158 | Stub* s = current_stub(); | |||
| 159 | assert(committed_size <= stub_size(s), "committed size must not exceed requested size")do { if (!(committed_size <= stub_size(s))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp" , 159, "assert(" "committed_size <= stub_size(s)" ") failed" , "committed size must not exceed requested size"); ::breakpoint (); } } while (0); | |||
| 160 | stub_initialize(s, committed_size); | |||
| 161 | _queue_end += committed_size; | |||
| 162 | _number_of_stubs++; | |||
| 163 | if (_mutex != NULL__null) _mutex->unlock(); | |||
| 164 | debug_only(stub_verify(s);)stub_verify(s); | |||
| 165 | } | |||
| 166 | ||||
| 167 | ||||
| 168 | void StubQueue::remove_first() { | |||
| 169 | if (number_of_stubs() == 0) return; | |||
| 170 | Stub* s = first(); | |||
| 171 | debug_only(stub_verify(s);)stub_verify(s); | |||
| 172 | stub_finalize(s); | |||
| 173 | _queue_begin += stub_size(s); | |||
| 174 | assert(_queue_begin <= _buffer_limit, "sanity check")do { if (!(_queue_begin <= _buffer_limit)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp" , 174, "assert(" "_queue_begin <= _buffer_limit" ") failed" , "sanity check"); ::breakpoint(); } } while (0); | |||
| 175 | if (_queue_begin == _queue_end) { | |||
| 176 | // buffer empty | |||
| 177 | // => reset queue indices | |||
| 178 | _queue_begin = 0; | |||
| 179 | _queue_end = 0; | |||
| 180 | _buffer_limit = _buffer_size; | |||
| 181 | } else if (_queue_begin == _buffer_limit) { | |||
| 182 | // buffer limit reached | |||
| 183 | // => reset buffer limit & wrap around | |||
| 184 | _buffer_limit = _buffer_size; | |||
| 185 | _queue_begin = 0; | |||
| 186 | } | |||
| 187 | _number_of_stubs--; | |||
| 188 | } | |||
| 189 | ||||
| 190 | ||||
| 191 | void StubQueue::remove_first(int n) { | |||
| 192 | int i = MIN2(n, number_of_stubs()); | |||
| 193 | while (i-- > 0) remove_first(); | |||
| 194 | } | |||
| 195 | ||||
| 196 | ||||
| 197 | void StubQueue::remove_all(){ | |||
| 198 | debug_only(verify();)verify(); | |||
| 199 | remove_first(number_of_stubs()); | |||
| 200 | assert(number_of_stubs() == 0, "sanity check")do { if (!(number_of_stubs() == 0)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp" , 200, "assert(" "number_of_stubs() == 0" ") failed", "sanity check" ); ::breakpoint(); } } while (0); | |||
| 201 | } | |||
| 202 | ||||
| 203 | ||||
| 204 | void StubQueue::verify() { | |||
| 205 | // verify only if initialized | |||
| 206 | if (_stub_buffer == NULL__null) return; | |||
| 207 | MutexLocker lock(_mutex, Mutex::_no_safepoint_check_flag); | |||
| 208 | // verify index boundaries | |||
| 209 | guarantee(0 <= _buffer_size, "buffer size must be positive")do { if (!(0 <= _buffer_size)) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp" , 209, "guarantee(" "0 <= _buffer_size" ") failed", "buffer size must be positive" ); ::breakpoint(); } } while (0); | |||
| 210 | guarantee(0 <= _buffer_limit && _buffer_limit <= _buffer_size , "_buffer_limit out of bounds")do { if (!(0 <= _buffer_limit && _buffer_limit <= _buffer_size)) { (*g_assert_poison) = 'X';; report_vm_error( "/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp" , 210, "guarantee(" "0 <= _buffer_limit && _buffer_limit <= _buffer_size" ") failed", "_buffer_limit out of bounds"); ::breakpoint(); } } while (0); | |||
| 211 | guarantee(0 <= _queue_begin && _queue_begin < _buffer_limit, "_queue_begin out of bounds")do { if (!(0 <= _queue_begin && _queue_begin < _buffer_limit )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp" , 211, "guarantee(" "0 <= _queue_begin && _queue_begin < _buffer_limit" ") failed", "_queue_begin out of bounds"); ::breakpoint(); } } while (0); | |||
| 212 | guarantee(0 <= _queue_end && _queue_end <= _buffer_limit, "_queue_end out of bounds")do { if (!(0 <= _queue_end && _queue_end <= _buffer_limit )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp" , 212, "guarantee(" "0 <= _queue_end && _queue_end <= _buffer_limit" ") failed", "_queue_end out of bounds"); ::breakpoint(); } } while (0); | |||
| 213 | // verify alignment | |||
| 214 | guarantee(_buffer_size % CodeEntryAlignment == 0, "_buffer_size not aligned")do { if (!(_buffer_size % CodeEntryAlignment == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp" , 214, "guarantee(" "_buffer_size % CodeEntryAlignment == 0" ") failed" , "_buffer_size not aligned"); ::breakpoint(); } } while (0); | |||
| 215 | guarantee(_buffer_limit % CodeEntryAlignment == 0, "_buffer_limit not aligned")do { if (!(_buffer_limit % CodeEntryAlignment == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp" , 215, "guarantee(" "_buffer_limit % CodeEntryAlignment == 0" ") failed", "_buffer_limit not aligned"); ::breakpoint(); } } while (0); | |||
| 216 | guarantee(_queue_begin % CodeEntryAlignment == 0, "_queue_begin not aligned")do { if (!(_queue_begin % CodeEntryAlignment == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp" , 216, "guarantee(" "_queue_begin % CodeEntryAlignment == 0" ") failed" , "_queue_begin not aligned"); ::breakpoint(); } } while (0); | |||
| 217 | guarantee(_queue_end % CodeEntryAlignment == 0, "_queue_end not aligned")do { if (!(_queue_end % CodeEntryAlignment == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp" , 217, "guarantee(" "_queue_end % CodeEntryAlignment == 0" ") failed" , "_queue_end not aligned"); ::breakpoint(); } } while (0); | |||
| 218 | // verify buffer limit/size relationship | |||
| 219 | if (is_contiguous()) { | |||
| 220 | guarantee(_buffer_limit == _buffer_size, "_buffer_limit must equal _buffer_size")do { if (!(_buffer_limit == _buffer_size)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp" , 220, "guarantee(" "_buffer_limit == _buffer_size" ") failed" , "_buffer_limit must equal _buffer_size"); ::breakpoint(); } } while (0); | |||
| 221 | } | |||
| 222 | // verify contents | |||
| 223 | int n = 0; | |||
| 224 | for (Stub* s = first(); s != NULL__null; s = next(s)) { | |||
| 225 | stub_verify(s); | |||
| 226 | n++; | |||
| 227 | } | |||
| 228 | guarantee(n == number_of_stubs(), "number of stubs inconsistent")do { if (!(n == number_of_stubs())) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp" , 228, "guarantee(" "n == number_of_stubs()" ") failed", "number of stubs inconsistent" ); ::breakpoint(); } } while (0); | |||
| 229 | guarantee(_queue_begin != _queue_end || n == 0, "buffer indices must be the same")do { if (!(_queue_begin != _queue_end || n == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/code/stubs.cpp" , 229, "guarantee(" "_queue_begin != _queue_end || n == 0" ") failed" , "buffer indices must be the same"); ::breakpoint(); } } while (0); | |||
| 230 | } | |||
| 231 | ||||
| 232 | ||||
| 233 | void StubQueue::print() { | |||
| 234 | MutexLocker lock(_mutex, Mutex::_no_safepoint_check_flag); | |||
| 235 | for (Stub* s = first(); s != NULL__null; s = next(s)) { | |||
| 236 | stub_print(s); | |||
| 237 | } | |||
| 238 | } |