| File: | jdk/src/hotspot/share/prims/jvmtiCodeBlobEvents.cpp |
| Warning: | line 279, column 13 Value stored to 'scopes_data' during its initialization is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* |
| 2 | * Copyright (c) 2003, 2020, 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/scopeDesc.hpp" |
| 29 | #include "code/vtableStubs.hpp" |
| 30 | #include "memory/allocation.inline.hpp" |
| 31 | #include "memory/resourceArea.hpp" |
| 32 | #include "oops/oop.inline.hpp" |
| 33 | #include "prims/jvmtiCodeBlobEvents.hpp" |
| 34 | #include "prims/jvmtiExport.hpp" |
| 35 | #include "prims/jvmtiThreadState.inline.hpp" |
| 36 | #include "runtime/handles.inline.hpp" |
| 37 | #include "runtime/safepointVerifiers.hpp" |
| 38 | #include "runtime/stubCodeGenerator.hpp" |
| 39 | #include "runtime/vmThread.hpp" |
| 40 | |
| 41 | // Support class to collect a list of the non-nmethod CodeBlobs in |
| 42 | // the CodeCache. |
| 43 | // |
| 44 | // This class actually creates a list of JvmtiCodeBlobDesc - each JvmtiCodeBlobDesc |
| 45 | // describes a single CodeBlob in the CodeCache. Note that collection is |
| 46 | // done to a static list - this is because CodeCache::blobs_do is defined |
| 47 | // as void CodeCache::blobs_do(void f(CodeBlob* nm)) and hence requires |
| 48 | // a C or static method. |
| 49 | // |
| 50 | // Usage :- |
| 51 | // |
| 52 | // CodeBlobCollector collector; |
| 53 | // |
| 54 | // collector.collect(); |
| 55 | // JvmtiCodeBlobDesc* blob = collector.first(); |
| 56 | // while (blob != NULL) { |
| 57 | // : |
| 58 | // blob = collector.next(); |
| 59 | // } |
| 60 | // |
| 61 | |
| 62 | class CodeBlobCollector : StackObj { |
| 63 | private: |
| 64 | GrowableArray<JvmtiCodeBlobDesc*>* _code_blobs; // collected blobs |
| 65 | int _pos; // iterator position |
| 66 | |
| 67 | // used during a collection |
| 68 | static GrowableArray<JvmtiCodeBlobDesc*>* _global_code_blobs; |
| 69 | static void do_blob(CodeBlob* cb); |
| 70 | static void do_vtable_stub(VtableStub* vs); |
| 71 | public: |
| 72 | CodeBlobCollector() { |
| 73 | _code_blobs = NULL__null; |
| 74 | _pos = -1; |
| 75 | } |
| 76 | ~CodeBlobCollector() { |
| 77 | if (_code_blobs != NULL__null) { |
| 78 | for (int i=0; i<_code_blobs->length(); i++) { |
| 79 | FreeHeap(_code_blobs->at(i)); |
| 80 | } |
| 81 | delete _code_blobs; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | // collect list of code blobs in the cache |
| 86 | void collect(); |
| 87 | |
| 88 | // iteration support - return first code blob |
| 89 | JvmtiCodeBlobDesc* first() { |
| 90 | assert(_code_blobs != NULL, "not collected")do { if (!(_code_blobs != __null)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/prims/jvmtiCodeBlobEvents.cpp" , 90, "assert(" "_code_blobs != __null" ") failed", "not collected" ); ::breakpoint(); } } while (0); |
| 91 | if (_code_blobs->length() == 0) { |
| 92 | return NULL__null; |
| 93 | } |
| 94 | _pos = 0; |
| 95 | return _code_blobs->at(0); |
| 96 | } |
| 97 | |
| 98 | // iteration support - return next code blob |
| 99 | JvmtiCodeBlobDesc* next() { |
| 100 | assert(_pos >= 0, "iteration not started")do { if (!(_pos >= 0)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/prims/jvmtiCodeBlobEvents.cpp" , 100, "assert(" "_pos >= 0" ") failed", "iteration not started" ); ::breakpoint(); } } while (0); |
| 101 | if (_pos+1 >= _code_blobs->length()) { |
| 102 | return NULL__null; |
| 103 | } |
| 104 | return _code_blobs->at(++_pos); |
| 105 | } |
| 106 | |
| 107 | }; |
| 108 | |
| 109 | // used during collection |
| 110 | GrowableArray<JvmtiCodeBlobDesc*>* CodeBlobCollector::_global_code_blobs; |
| 111 | |
| 112 | |
| 113 | // called for each CodeBlob in the CodeCache |
| 114 | // |
| 115 | // This function filters out nmethods as it is only interested in |
| 116 | // other CodeBlobs. This function also filters out CodeBlobs that have |
| 117 | // a duplicate starting address as previous blobs. This is needed to |
| 118 | // handle the case where multiple stubs are generated into a single |
| 119 | // BufferBlob. |
| 120 | |
| 121 | void CodeBlobCollector::do_blob(CodeBlob* cb) { |
| 122 | |
| 123 | // ignore nmethods |
| 124 | if (cb->is_nmethod()) { |
| 125 | return; |
| 126 | } |
| 127 | // exclude VtableStubs, which are processed separately |
| 128 | if (cb->is_buffer_blob() && strcmp(cb->name(), "vtable chunks") == 0) { |
| 129 | return; |
| 130 | } |
| 131 | |
| 132 | // check if this starting address has been seen already - the |
| 133 | // assumption is that stubs are inserted into the list before the |
| 134 | // enclosing BufferBlobs. |
| 135 | address addr = cb->code_begin(); |
| 136 | for (int i=0; i<_global_code_blobs->length(); i++) { |
| 137 | JvmtiCodeBlobDesc* scb = _global_code_blobs->at(i); |
| 138 | if (addr == scb->code_begin()) { |
| 139 | return; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | // record the CodeBlob details as a JvmtiCodeBlobDesc |
| 144 | JvmtiCodeBlobDesc* scb = new JvmtiCodeBlobDesc(cb->name(), cb->code_begin(), cb->code_end()); |
| 145 | _global_code_blobs->append(scb); |
| 146 | } |
| 147 | |
| 148 | // called for each VtableStub in VtableStubs |
| 149 | |
| 150 | void CodeBlobCollector::do_vtable_stub(VtableStub* vs) { |
| 151 | JvmtiCodeBlobDesc* scb = new JvmtiCodeBlobDesc(vs->is_vtable_stub() ? "vtable stub" : "itable stub", |
| 152 | vs->code_begin(), vs->code_end()); |
| 153 | _global_code_blobs->append(scb); |
| 154 | } |
| 155 | |
| 156 | // collects a list of CodeBlobs in the CodeCache. |
| 157 | // |
| 158 | // The created list is growable array of JvmtiCodeBlobDesc - each one describes |
| 159 | // a CodeBlob. Note that the list is static - this is because CodeBlob::blobs_do |
| 160 | // requires a a C or static function so we can't use an instance function. This |
| 161 | // isn't a problem as the iteration is serial anyway as we need the CodeCache_lock |
| 162 | // to iterate over the code cache. |
| 163 | // |
| 164 | // Note that the CodeBlobs in the CodeCache will include BufferBlobs that may |
| 165 | // contain multiple stubs. As a profiler is interested in the stubs rather than |
| 166 | // the enclosing container we first iterate over the stub code descriptors so |
| 167 | // that the stubs go into the list first. do_blob will then filter out the |
| 168 | // enclosing blobs if the starting address of the enclosing blobs matches the |
| 169 | // starting address of first stub generated in the enclosing blob. |
| 170 | |
| 171 | void CodeBlobCollector::collect() { |
| 172 | assert_locked_or_safepoint(CodeCache_lock); |
| 173 | assert(_global_code_blobs == NULL, "checking")do { if (!(_global_code_blobs == __null)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/prims/jvmtiCodeBlobEvents.cpp" , 173, "assert(" "_global_code_blobs == __null" ") failed", "checking" ); ::breakpoint(); } } while (0); |
| 174 | |
| 175 | // create the global list |
| 176 | _global_code_blobs = new (ResourceObj::C_HEAP, mtServiceability) GrowableArray<JvmtiCodeBlobDesc*>(50, mtServiceability); |
| 177 | |
| 178 | // iterate over the stub code descriptors and put them in the list first. |
| 179 | for (StubCodeDesc* desc = StubCodeDesc::first(); desc != NULL__null; desc = StubCodeDesc::next(desc)) { |
| 180 | _global_code_blobs->append(new JvmtiCodeBlobDesc(desc->name(), desc->begin(), desc->end())); |
| 181 | } |
| 182 | |
| 183 | // Vtable stubs are not described with StubCodeDesc, |
| 184 | // process them separately |
| 185 | VtableStubs::vtable_stub_do(do_vtable_stub); |
| 186 | |
| 187 | // next iterate over all the non-nmethod code blobs and add them to |
| 188 | // the list - as noted above this will filter out duplicates and |
| 189 | // enclosing blobs. |
| 190 | CodeCache::blobs_do(do_blob); |
| 191 | |
| 192 | // make the global list the instance list so that it can be used |
| 193 | // for other iterations. |
| 194 | _code_blobs = _global_code_blobs; |
| 195 | _global_code_blobs = NULL__null; |
| 196 | } |
| 197 | |
| 198 | |
| 199 | // Generate a DYNAMIC_CODE_GENERATED event for each non-nmethod code blob. |
| 200 | |
| 201 | jvmtiError JvmtiCodeBlobEvents::generate_dynamic_code_events(JvmtiEnv* env) { |
| 202 | CodeBlobCollector collector; |
| 203 | |
| 204 | // First collect all the code blobs. This has to be done in a |
| 205 | // single pass over the code cache with CodeCache_lock held because |
| 206 | // there isn't any safe way to iterate over regular CodeBlobs since |
| 207 | // they can be freed at any point. |
| 208 | { |
| 209 | MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
| 210 | collector.collect(); |
| 211 | } |
| 212 | |
| 213 | // iterate over the collected list and post an event for each blob |
| 214 | JvmtiCodeBlobDesc* blob = collector.first(); |
| 215 | while (blob != NULL__null) { |
| 216 | JvmtiExport::post_dynamic_code_generated(env, blob->name(), blob->code_begin(), blob->code_end()); |
| 217 | blob = collector.next(); |
| 218 | } |
| 219 | return JVMTI_ERROR_NONE; |
| 220 | } |
| 221 | |
| 222 | |
| 223 | // Generate a COMPILED_METHOD_LOAD event for each nnmethod |
| 224 | jvmtiError JvmtiCodeBlobEvents::generate_compiled_method_load_events(JvmtiEnv* env) { |
| 225 | JavaThread* java_thread = JavaThread::current(); |
| 226 | JvmtiThreadState* state = JvmtiThreadState::state_for(java_thread); |
| 227 | { |
| 228 | NoSafepointVerifier nsv; // safepoints are not safe while collecting methods to post. |
| 229 | { |
| 230 | // Walk the CodeCache notifying for live nmethods. We hold the CodeCache_lock |
| 231 | // to ensure the iteration is safe and nmethods are not concurrently freed. |
| 232 | // However, they may still change states and become !is_alive(). Filtering |
| 233 | // those out is done inside of nmethod::post_compiled_method_load_event(). |
| 234 | // Save events to the queue for posting outside the CodeCache_lock. |
| 235 | MutexLocker mu(java_thread, CodeCache_lock, Mutex::_no_safepoint_check_flag); |
| 236 | // Iterate over non-profiled and profiled nmethods |
| 237 | NMethodIterator iter(NMethodIterator::only_alive_and_not_unloading); |
| 238 | while(iter.next()) { |
| 239 | nmethod* current = iter.method(); |
| 240 | current->post_compiled_method_load_event(state); |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | // Enter nmethod barrier code if present outside CodeCache_lock |
| 245 | state->run_nmethod_entry_barriers(); |
| 246 | } |
| 247 | |
| 248 | // Now post all the events outside the CodeCache_lock. |
| 249 | // If there's a safepoint, the queued events will be kept alive. |
| 250 | // Adding these events to the service thread to post is something that |
| 251 | // should work, but the service thread doesn't keep up in stress scenarios and |
| 252 | // the os eventually kills the process with OOM. |
| 253 | // We want this thread to wait until the events are all posted. |
| 254 | state->post_events(env); |
| 255 | return JVMTI_ERROR_NONE; |
| 256 | } |
| 257 | |
| 258 | |
| 259 | // create a C-heap allocated address location map for an nmethod |
| 260 | void JvmtiCodeBlobEvents::build_jvmti_addr_location_map(nmethod *nm, |
| 261 | jvmtiAddrLocationMap** map_ptr, |
| 262 | jint *map_length_ptr) |
| 263 | { |
| 264 | ResourceMark rm; |
| 265 | jvmtiAddrLocationMap* map = NULL__null; |
| 266 | jint map_length = 0; |
| 267 | |
| 268 | |
| 269 | // Generate line numbers using PcDesc and ScopeDesc info |
| 270 | methodHandle mh(Thread::current(), nm->method()); |
| 271 | |
| 272 | if (!mh->is_native()) { |
| 273 | PcDesc *pcd; |
| 274 | int pcds_in_method; |
| 275 | |
| 276 | pcds_in_method = (nm->scopes_pcs_end() - nm->scopes_pcs_begin()); |
| 277 | map = NEW_C_HEAP_ARRAY(jvmtiAddrLocationMap, pcds_in_method, mtInternal)(jvmtiAddrLocationMap*) (AllocateHeap((pcds_in_method) * sizeof (jvmtiAddrLocationMap), mtInternal)); |
| 278 | |
| 279 | address scopes_data = nm->scopes_data_begin(); |
Value stored to 'scopes_data' during its initialization is never read | |
| 280 | for( pcd = nm->scopes_pcs_begin(); pcd < nm->scopes_pcs_end(); ++pcd ) { |
| 281 | ScopeDesc sc0(nm, pcd, true); |
| 282 | ScopeDesc *sd = &sc0; |
| 283 | while( !sd->is_top() ) { sd = sd->sender(); } |
| 284 | int bci = sd->bci(); |
| 285 | if (bci >= 0) { |
| 286 | assert(map_length < pcds_in_method, "checking")do { if (!(map_length < pcds_in_method)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/prims/jvmtiCodeBlobEvents.cpp" , 286, "assert(" "map_length < pcds_in_method" ") failed", "checking"); ::breakpoint(); } } while (0); |
| 287 | map[map_length].start_address = (const void*)pcd->real_pc(nm); |
| 288 | map[map_length].location = bci; |
| 289 | ++map_length; |
| 290 | } |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | *map_ptr = map; |
| 295 | *map_length_ptr = map_length; |
| 296 | } |