Wed, 19 Nov 2014 18:14:01 +0100
8065361: Fixup headers and definitions for INCLUDE_TRACE
Reviewed-by: sla, stefank
coleenp@4490 | 1 | /* |
coleenp@4490 | 2 | * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
coleenp@4490 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
coleenp@4490 | 4 | * |
coleenp@4490 | 5 | * This code is free software; you can redistribute it and/or modify it |
coleenp@4490 | 6 | * under the terms of the GNU General Public License version 2 only, as |
coleenp@4490 | 7 | * published by the Free Software Foundation. |
coleenp@4490 | 8 | * |
coleenp@4490 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
coleenp@4490 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
coleenp@4490 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
coleenp@4490 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
coleenp@4490 | 13 | * accompanied this code). |
coleenp@4490 | 14 | * |
coleenp@4490 | 15 | * You should have received a copy of the GNU General Public License version |
coleenp@4490 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
coleenp@4490 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
coleenp@4490 | 18 | * |
coleenp@4490 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
coleenp@4490 | 20 | * or visit www.oracle.com if you need additional information or have any |
coleenp@4490 | 21 | * questions. |
coleenp@4490 | 22 | * |
coleenp@4490 | 23 | */ |
coleenp@4490 | 24 | |
coleenp@4490 | 25 | #include "precompiled.hpp" |
coleenp@4490 | 26 | #include "classfile/metadataOnStackMark.hpp" |
coleenp@4490 | 27 | #include "code/codeCache.hpp" |
coleenp@4490 | 28 | #include "compiler/compileBroker.hpp" |
coleenp@4490 | 29 | #include "oops/metadata.hpp" |
coleenp@6063 | 30 | #include "prims/jvmtiImpl.hpp" |
coleenp@4490 | 31 | #include "runtime/synchronizer.hpp" |
coleenp@4490 | 32 | #include "runtime/thread.hpp" |
sla@6122 | 33 | #include "services/threadService.hpp" |
stefank@7333 | 34 | #include "utilities/chunkedList.hpp" |
coleenp@4490 | 35 | |
stefank@7333 | 36 | volatile MetadataOnStackBuffer* MetadataOnStackMark::_used_buffers = NULL; |
stefank@7333 | 37 | volatile MetadataOnStackBuffer* MetadataOnStackMark::_free_buffers = NULL; |
coleenp@4490 | 38 | |
coleenp@4490 | 39 | NOT_PRODUCT(bool MetadataOnStackMark::_is_active = false;) |
coleenp@4490 | 40 | |
coleenp@4490 | 41 | // Walk metadata on the stack and mark it so that redefinition doesn't delete |
coleenp@4490 | 42 | // it. Class unloading also walks the previous versions and might try to |
coleenp@4490 | 43 | // delete it, so this class is used by class unloading also. |
stefank@7333 | 44 | MetadataOnStackMark::MetadataOnStackMark(bool visit_code_cache) { |
coleenp@4490 | 45 | assert(SafepointSynchronize::is_at_safepoint(), "sanity check"); |
stefank@7333 | 46 | assert(_used_buffers == NULL, "sanity check"); |
coleenp@4490 | 47 | NOT_PRODUCT(_is_active = true;) |
stefank@6992 | 48 | |
coleenp@4490 | 49 | Threads::metadata_do(Metadata::mark_on_stack); |
stefank@7333 | 50 | if (visit_code_cache) { |
stefank@6992 | 51 | CodeCache::alive_nmethods_do(nmethod::mark_on_stack); |
stefank@6992 | 52 | } |
coleenp@4490 | 53 | CompileBroker::mark_on_stack(); |
coleenp@6063 | 54 | JvmtiCurrentBreakpoints::metadata_do(Metadata::mark_on_stack); |
sla@6122 | 55 | ThreadService::metadata_do(Metadata::mark_on_stack); |
coleenp@4490 | 56 | } |
coleenp@4490 | 57 | |
coleenp@4490 | 58 | MetadataOnStackMark::~MetadataOnStackMark() { |
coleenp@4490 | 59 | assert(SafepointSynchronize::is_at_safepoint(), "sanity check"); |
coleenp@4490 | 60 | // Unmark everything that was marked. Can't do the same walk because |
coleenp@4490 | 61 | // redefine classes messes up the code cache so the set of methods |
coleenp@4490 | 62 | // might not be the same. |
stefank@7333 | 63 | |
stefank@7333 | 64 | retire_buffer_for_thread(Thread::current()); |
stefank@7333 | 65 | |
stefank@7333 | 66 | MetadataOnStackBuffer* buffer = const_cast<MetadataOnStackBuffer* >(_used_buffers); |
stefank@7333 | 67 | while (buffer != NULL) { |
stefank@7333 | 68 | // Clear on stack state for all metadata. |
stefank@7333 | 69 | size_t size = buffer->size(); |
stefank@7333 | 70 | for (size_t i = 0; i < size; i++) { |
stefank@7333 | 71 | Metadata* md = buffer->at(i); |
stefank@7333 | 72 | md->set_on_stack(false); |
stefank@7333 | 73 | } |
stefank@7333 | 74 | |
stefank@7333 | 75 | MetadataOnStackBuffer* next = buffer->next_used(); |
stefank@7333 | 76 | |
stefank@7333 | 77 | // Move the buffer to the free list. |
stefank@7333 | 78 | buffer->clear(); |
stefank@7333 | 79 | buffer->set_next_used(NULL); |
stefank@7333 | 80 | buffer->set_next_free(const_cast<MetadataOnStackBuffer*>(_free_buffers)); |
stefank@7333 | 81 | _free_buffers = buffer; |
stefank@7333 | 82 | |
stefank@7333 | 83 | // Step to next used buffer. |
stefank@7333 | 84 | buffer = next; |
coleenp@4490 | 85 | } |
stefank@7333 | 86 | |
stefank@7333 | 87 | _used_buffers = NULL; |
stefank@7333 | 88 | |
coleenp@4490 | 89 | NOT_PRODUCT(_is_active = false;) |
coleenp@4490 | 90 | } |
coleenp@4490 | 91 | |
stefank@7333 | 92 | void MetadataOnStackMark::retire_buffer(MetadataOnStackBuffer* buffer) { |
stefank@7333 | 93 | if (buffer == NULL) { |
stefank@7333 | 94 | return; |
stefank@7333 | 95 | } |
stefank@7333 | 96 | |
stefank@7333 | 97 | MetadataOnStackBuffer* old_head; |
stefank@7333 | 98 | |
stefank@7333 | 99 | do { |
stefank@7333 | 100 | old_head = const_cast<MetadataOnStackBuffer*>(_used_buffers); |
stefank@7333 | 101 | buffer->set_next_used(old_head); |
stefank@7333 | 102 | } while (Atomic::cmpxchg_ptr(buffer, &_used_buffers, old_head) != old_head); |
stefank@7333 | 103 | } |
stefank@7333 | 104 | |
stefank@7333 | 105 | void MetadataOnStackMark::retire_buffer_for_thread(Thread* thread) { |
stefank@7333 | 106 | retire_buffer(thread->metadata_on_stack_buffer()); |
stefank@7333 | 107 | thread->set_metadata_on_stack_buffer(NULL); |
stefank@7333 | 108 | } |
stefank@7333 | 109 | |
stefank@7333 | 110 | bool MetadataOnStackMark::has_buffer_for_thread(Thread* thread) { |
stefank@7333 | 111 | return thread->metadata_on_stack_buffer() != NULL; |
stefank@7333 | 112 | } |
stefank@7333 | 113 | |
stefank@7333 | 114 | MetadataOnStackBuffer* MetadataOnStackMark::allocate_buffer() { |
stefank@7333 | 115 | MetadataOnStackBuffer* allocated; |
stefank@7333 | 116 | MetadataOnStackBuffer* new_head; |
stefank@7333 | 117 | |
stefank@7333 | 118 | do { |
stefank@7333 | 119 | allocated = const_cast<MetadataOnStackBuffer*>(_free_buffers); |
stefank@7333 | 120 | if (allocated == NULL) { |
stefank@7333 | 121 | break; |
stefank@7333 | 122 | } |
stefank@7333 | 123 | new_head = allocated->next_free(); |
stefank@7333 | 124 | } while (Atomic::cmpxchg_ptr(new_head, &_free_buffers, allocated) != allocated); |
stefank@7333 | 125 | |
stefank@7333 | 126 | if (allocated == NULL) { |
stefank@7333 | 127 | allocated = new MetadataOnStackBuffer(); |
stefank@7333 | 128 | } |
stefank@7333 | 129 | |
stefank@7333 | 130 | assert(!allocated->is_full(), err_msg("Should not be full: " PTR_FORMAT, p2i(allocated))); |
stefank@7333 | 131 | |
stefank@7333 | 132 | return allocated; |
stefank@7333 | 133 | } |
stefank@7333 | 134 | |
coleenp@4490 | 135 | // Record which objects are marked so we can unmark the same objects. |
stefank@7333 | 136 | void MetadataOnStackMark::record(Metadata* m, Thread* thread) { |
coleenp@4490 | 137 | assert(_is_active, "metadata on stack marking is active"); |
stefank@7333 | 138 | |
stefank@7333 | 139 | MetadataOnStackBuffer* buffer = thread->metadata_on_stack_buffer(); |
stefank@7333 | 140 | |
stefank@7333 | 141 | if (buffer != NULL && buffer->is_full()) { |
stefank@7333 | 142 | retire_buffer(buffer); |
stefank@7333 | 143 | buffer = NULL; |
stefank@7333 | 144 | } |
stefank@7333 | 145 | |
stefank@7333 | 146 | if (buffer == NULL) { |
stefank@7333 | 147 | buffer = allocate_buffer(); |
stefank@7333 | 148 | thread->set_metadata_on_stack_buffer(buffer); |
stefank@7333 | 149 | } |
stefank@7333 | 150 | |
stefank@7333 | 151 | buffer->push(m); |
coleenp@4490 | 152 | } |