Sun, 03 Feb 2013 22:28:08 +0400
8002048: Protocol to discovery of manageable Java processes on a network
Summary: Introduce a protocol to discover manageble Java instances across a network subnet, JDP
Reviewed-by: sla, dfuchs
zgu@3900 | 1 | /* |
zgu@3900 | 2 | * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
zgu@3900 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
zgu@3900 | 4 | * |
zgu@3900 | 5 | * This code is free software; you can redistribute it and/or modify it |
zgu@3900 | 6 | * under the terms of the GNU General Public License version 2 only, as |
zgu@3900 | 7 | * published by the Free Software Foundation. |
zgu@3900 | 8 | * |
zgu@3900 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
zgu@3900 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
zgu@3900 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
zgu@3900 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
zgu@3900 | 13 | * accompanied this code). |
zgu@3900 | 14 | * |
zgu@3900 | 15 | * You should have received a copy of the GNU General Public License version |
zgu@3900 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
zgu@3900 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
zgu@3900 | 18 | * |
zgu@3900 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
zgu@3900 | 20 | * or visit www.oracle.com if you need additional information or have any |
zgu@3900 | 21 | * questions. |
zgu@3900 | 22 | * |
zgu@3900 | 23 | */ |
zgu@3900 | 24 | |
zgu@3900 | 25 | #include "precompiled.hpp" |
zgu@3900 | 26 | |
zgu@3900 | 27 | #include "runtime/atomic.hpp" |
zgu@3900 | 28 | #include "services/memBaseline.hpp" |
zgu@3900 | 29 | #include "services/memRecorder.hpp" |
zgu@3900 | 30 | #include "services/memPtr.hpp" |
zgu@3900 | 31 | #include "services/memTracker.hpp" |
zgu@3900 | 32 | |
zgu@3900 | 33 | MemPointer* SequencedRecordIterator::next_record() { |
zgu@4193 | 34 | MemPointerRecord* itr_cur = (MemPointerRecord*)_itr.current(); |
zgu@4193 | 35 | if (itr_cur == NULL) { |
zgu@4193 | 36 | return itr_cur; |
zgu@4193 | 37 | } |
zgu@3900 | 38 | |
zgu@4193 | 39 | MemPointerRecord* itr_next = (MemPointerRecord*)_itr.next(); |
zgu@4193 | 40 | |
zgu@4193 | 41 | // don't collapse virtual memory records |
zgu@4193 | 42 | while (itr_next != NULL && !itr_cur->is_vm_pointer() && |
zgu@4193 | 43 | !itr_next->is_vm_pointer() && |
zgu@4193 | 44 | same_kind(itr_cur, itr_next)) { |
zgu@3900 | 45 | itr_cur = itr_next; |
zgu@4193 | 46 | itr_next = (MemPointerRecord*)_itr.next(); |
zgu@3900 | 47 | } |
zgu@3900 | 48 | |
zgu@3900 | 49 | return itr_cur; |
zgu@3900 | 50 | } |
zgu@3900 | 51 | |
zgu@3900 | 52 | |
zgu@3935 | 53 | volatile jint MemRecorder::_instance_count = 0; |
zgu@3900 | 54 | |
zgu@3900 | 55 | MemRecorder::MemRecorder() { |
zgu@3900 | 56 | assert(MemTracker::is_on(), "Native memory tracking is off"); |
zgu@3935 | 57 | Atomic::inc(&_instance_count); |
ctornqvi@4512 | 58 | set_generation(); |
zgu@3900 | 59 | |
zgu@3900 | 60 | if (MemTracker::track_callsite()) { |
zgu@3900 | 61 | _pointer_records = new (std::nothrow)FixedSizeMemPointerArray<SeqMemPointerRecordEx, |
zgu@3900 | 62 | DEFAULT_RECORDER_PTR_ARRAY_SIZE>(); |
zgu@3900 | 63 | } else { |
zgu@3900 | 64 | _pointer_records = new (std::nothrow)FixedSizeMemPointerArray<SeqMemPointerRecord, |
zgu@3900 | 65 | DEFAULT_RECORDER_PTR_ARRAY_SIZE>(); |
zgu@3900 | 66 | } |
zgu@3900 | 67 | _next = NULL; |
zgu@3900 | 68 | |
zgu@3900 | 69 | |
zgu@3900 | 70 | if (_pointer_records != NULL) { |
zgu@3900 | 71 | // recode itself |
zgu@3900 | 72 | record((address)this, (MemPointerRecord::malloc_tag()|mtNMT|otNMTRecorder), |
zgu@3900 | 73 | sizeof(MemRecorder), CALLER_PC); |
zgu@3900 | 74 | record((address)_pointer_records, (MemPointerRecord::malloc_tag()|mtNMT|otNMTRecorder), |
zgu@3900 | 75 | _pointer_records->instance_size(),CURRENT_PC); |
zgu@3900 | 76 | } |
zgu@3900 | 77 | } |
zgu@3900 | 78 | |
zgu@3900 | 79 | MemRecorder::~MemRecorder() { |
zgu@3900 | 80 | if (_pointer_records != NULL) { |
zgu@3900 | 81 | if (MemTracker::is_on()) { |
zgu@3900 | 82 | MemTracker::record_free((address)_pointer_records, mtNMT); |
zgu@3900 | 83 | MemTracker::record_free((address)this, mtNMT); |
zgu@3900 | 84 | } |
zgu@3900 | 85 | delete _pointer_records; |
zgu@3900 | 86 | } |
zgu@4400 | 87 | // delete all linked recorders |
zgu@4400 | 88 | while (_next != NULL) { |
zgu@4400 | 89 | MemRecorder* tmp = _next; |
zgu@4400 | 90 | _next = _next->next(); |
zgu@4400 | 91 | tmp->set_next(NULL); |
zgu@4400 | 92 | delete tmp; |
zgu@3900 | 93 | } |
zgu@3900 | 94 | Atomic::dec(&_instance_count); |
zgu@3900 | 95 | } |
zgu@3900 | 96 | |
zgu@3900 | 97 | // Sorting order: |
zgu@3900 | 98 | // 1. memory block address |
zgu@3900 | 99 | // 2. mem pointer record tags |
zgu@3900 | 100 | // 3. sequence number |
zgu@3900 | 101 | int MemRecorder::sort_record_fn(const void* e1, const void* e2) { |
zgu@3900 | 102 | const MemPointerRecord* p1 = (const MemPointerRecord*)e1; |
zgu@3900 | 103 | const MemPointerRecord* p2 = (const MemPointerRecord*)e2; |
zgu@3900 | 104 | int delta = UNSIGNED_COMPARE(p1->addr(), p2->addr()); |
zgu@3900 | 105 | if (delta == 0) { |
zgu@3900 | 106 | int df = UNSIGNED_COMPARE((p1->flags() & MemPointerRecord::tag_masks), |
zgu@3900 | 107 | (p2->flags() & MemPointerRecord::tag_masks)); |
zgu@3900 | 108 | if (df == 0) { |
zgu@3900 | 109 | assert(p1->seq() != p2->seq(), "dup seq"); |
zgu@3900 | 110 | return p1->seq() - p2->seq(); |
zgu@3900 | 111 | } else { |
zgu@3900 | 112 | return df; |
zgu@3900 | 113 | } |
zgu@3900 | 114 | } else { |
zgu@3900 | 115 | return delta; |
zgu@3900 | 116 | } |
zgu@3900 | 117 | } |
zgu@3900 | 118 | |
zgu@3900 | 119 | bool MemRecorder::record(address p, MEMFLAGS flags, size_t size, address pc) { |
zgu@3900 | 120 | #ifdef ASSERT |
zgu@3900 | 121 | if (MemPointerRecord::is_virtual_memory_record(flags)) { |
zgu@3900 | 122 | assert((flags & MemPointerRecord::tag_masks) != 0, "bad virtual memory record"); |
zgu@3900 | 123 | } else { |
zgu@3900 | 124 | assert((flags & MemPointerRecord::tag_masks) == MemPointerRecord::malloc_tag() || |
zgu@3900 | 125 | (flags & MemPointerRecord::tag_masks) == MemPointerRecord::free_tag() || |
zgu@3900 | 126 | IS_ARENA_OBJ(flags), |
zgu@3900 | 127 | "bad malloc record"); |
zgu@3900 | 128 | } |
zgu@3900 | 129 | // a recorder should only hold records within the same generation |
zgu@3900 | 130 | unsigned long cur_generation = SequenceGenerator::current_generation(); |
zgu@3900 | 131 | assert(cur_generation == _generation, |
zgu@3900 | 132 | "this thread did not enter sync point"); |
zgu@3900 | 133 | #endif |
zgu@3900 | 134 | |
zgu@3900 | 135 | if (MemTracker::track_callsite()) { |
zgu@3900 | 136 | SeqMemPointerRecordEx ap(p, flags, size, pc); |
zgu@3900 | 137 | debug_only(check_dup_seq(ap.seq());) |
zgu@3900 | 138 | return _pointer_records->append(&ap); |
zgu@3900 | 139 | } else { |
zgu@3900 | 140 | SeqMemPointerRecord ap(p, flags, size); |
zgu@3900 | 141 | debug_only(check_dup_seq(ap.seq());) |
zgu@3900 | 142 | return _pointer_records->append(&ap); |
zgu@3900 | 143 | } |
zgu@3900 | 144 | } |
zgu@3900 | 145 | |
zgu@3900 | 146 | // iterator for alloc pointers |
zgu@3900 | 147 | SequencedRecordIterator MemRecorder::pointer_itr() { |
zgu@3900 | 148 | assert(_pointer_records != NULL, "just check"); |
zgu@3900 | 149 | _pointer_records->sort((FN_SORT)sort_record_fn); |
zgu@3900 | 150 | return SequencedRecordIterator(_pointer_records); |
zgu@3900 | 151 | } |
zgu@3900 | 152 | |
zgu@3900 | 153 | |
zgu@3900 | 154 | void MemRecorder::set_generation() { |
zgu@3900 | 155 | _generation = SequenceGenerator::current_generation(); |
zgu@3900 | 156 | } |
zgu@3900 | 157 | |
ctornqvi@4512 | 158 | #ifdef ASSERT |
ctornqvi@4512 | 159 | |
zgu@3900 | 160 | void MemRecorder::check_dup_seq(jint seq) const { |
zgu@3900 | 161 | MemPointerArrayIteratorImpl itr(_pointer_records); |
zgu@3900 | 162 | MemPointerRecord* rc = (MemPointerRecord*)itr.current(); |
zgu@3900 | 163 | while (rc != NULL) { |
zgu@3900 | 164 | assert(rc->seq() != seq, "dup seq"); |
zgu@3900 | 165 | rc = (MemPointerRecord*)itr.next(); |
zgu@3900 | 166 | } |
zgu@3900 | 167 | } |
zgu@3900 | 168 | |
zgu@3900 | 169 | #endif |