src/share/vm/services/memBaseline.cpp

Wed, 31 Jan 2018 19:24:57 -0500

author
dbuck
date
Wed, 31 Jan 2018 19:24:57 -0500
changeset 9289
427b2fb1944f
parent 9054
db49d511817a
child 9122
024be04bb151
child 9778
bf6ea7319424
permissions
-rw-r--r--

8189170: Add option to disable stack overflow checking in primordial thread for use with JNI_CreateJavaJVM
Reviewed-by: dcubed

zgu@3900 1 /*
zgu@9054 2 * Copyright (c) 2012, 2017, 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 #include "precompiled.hpp"
zgu@7074 25
zgu@3900 26 #include "memory/allocation.hpp"
zgu@4980 27 #include "runtime/safepoint.hpp"
zgu@4980 28 #include "runtime/thread.inline.hpp"
zgu@3900 29 #include "services/memBaseline.hpp"
zgu@3900 30 #include "services/memTracker.hpp"
zgu@3900 31
zgu@7074 32 /*
zgu@7074 33 * Sizes are sorted in descenting order for reporting
zgu@7074 34 */
zgu@7074 35 int compare_malloc_size(const MallocSite& s1, const MallocSite& s2) {
zgu@7074 36 if (s1.size() == s2.size()) {
zgu@7074 37 return 0;
zgu@7074 38 } else if (s1.size() > s2.size()) {
zgu@7074 39 return -1;
zgu@7074 40 } else {
zgu@7074 41 return 1;
zgu@3900 42 }
zgu@3900 43 }
zgu@3900 44
zgu@7074 45
zgu@7074 46 int compare_virtual_memory_size(const VirtualMemoryAllocationSite& s1,
zgu@7074 47 const VirtualMemoryAllocationSite& s2) {
zgu@7074 48 if (s1.reserved() == s2.reserved()) {
zgu@7074 49 return 0;
zgu@7074 50 } else if (s1.reserved() > s2.reserved()) {
zgu@7074 51 return -1;
zgu@7074 52 } else {
zgu@7074 53 return 1;
zgu@7074 54 }
zgu@3900 55 }
zgu@3900 56
zgu@7074 57 // Sort into allocation site addresses order for baseline comparison
zgu@7074 58 int compare_malloc_site(const MallocSite& s1, const MallocSite& s2) {
zgu@7074 59 return s1.call_stack()->compare(*s2.call_stack());
zgu@7074 60 }
zgu@7074 61
zgu@9054 62 // Sort into allocation site addresses and memory type order for baseline comparison
zgu@9054 63 int compare_malloc_site_and_type(const MallocSite& s1, const MallocSite& s2) {
zgu@9054 64 int res = compare_malloc_site(s1, s2);
zgu@9054 65 if (res == 0) {
zgu@9054 66 res = (int)(s1.flags() - s2.flags());
zgu@9054 67 }
zgu@9054 68
zgu@9054 69 return res;
zgu@9054 70 }
zgu@7074 71
zgu@7074 72 int compare_virtual_memory_site(const VirtualMemoryAllocationSite& s1,
zgu@7074 73 const VirtualMemoryAllocationSite& s2) {
zgu@7074 74 return s1.call_stack()->compare(*s2.call_stack());
zgu@7074 75 }
zgu@7074 76
zgu@7074 77 /*
zgu@7074 78 * Walker to walk malloc allocation site table
zgu@7074 79 */
zgu@7074 80 class MallocAllocationSiteWalker : public MallocSiteWalker {
zgu@7074 81 private:
zgu@7080 82 SortedLinkedList<MallocSite, compare_malloc_size> _malloc_sites;
zgu@7074 83 size_t _count;
zgu@7074 84
zgu@7074 85 // Entries in MallocSiteTable with size = 0 and count = 0,
zgu@7074 86 // when the malloc site is not longer there.
zgu@7074 87 public:
zgu@7080 88 MallocAllocationSiteWalker() : _count(0) { }
zgu@7074 89
zgu@7074 90 inline size_t count() const { return _count; }
zgu@7074 91
zgu@7074 92 LinkedList<MallocSite>* malloc_sites() {
zgu@7074 93 return &_malloc_sites;
zgu@7074 94 }
zgu@7074 95
zgu@7074 96 bool do_malloc_site(const MallocSite* site) {
zgu@7074 97 if (site->size() >= MemBaseline::SIZE_THRESHOLD) {
zgu@7074 98 if (_malloc_sites.add(*site) != NULL) {
zgu@7074 99 _count++;
zgu@7074 100 return true;
zgu@7074 101 } else {
zgu@7074 102 return false; // OOM
zgu@7074 103 }
zgu@4274 104 } else {
zgu@7074 105 // malloc site does not meet threshold, ignore and continue
zgu@7074 106 return true;
zgu@7074 107 }
zgu@7074 108 }
zgu@7074 109 };
zgu@7074 110
zgu@7074 111 // Compare virtual memory region's base address
zgu@7074 112 int compare_virtual_memory_base(const ReservedMemoryRegion& r1, const ReservedMemoryRegion& r2) {
zgu@7074 113 return r1.compare(r2);
zgu@7074 114 }
zgu@7074 115
zgu@7074 116 // Walk all virtual memory regions for baselining
zgu@7074 117 class VirtualMemoryAllocationWalker : public VirtualMemoryWalker {
zgu@7074 118 private:
zgu@7080 119 SortedLinkedList<ReservedMemoryRegion, compare_virtual_memory_base>
zgu@7074 120 _virtual_memory_regions;
zgu@7074 121 size_t _count;
zgu@7074 122
zgu@7074 123 public:
zgu@7080 124 VirtualMemoryAllocationWalker() : _count(0) { }
zgu@7074 125
zgu@7074 126 bool do_allocation_site(const ReservedMemoryRegion* rgn) {
zgu@7074 127 if (rgn->size() >= MemBaseline::SIZE_THRESHOLD) {
zgu@7074 128 if (_virtual_memory_regions.add(*rgn) != NULL) {
zgu@7074 129 _count ++;
zgu@7074 130 return true;
zgu@7074 131 } else {
zgu@7074 132 return false;
zgu@3900 133 }
zgu@3900 134 }
zgu@7074 135 return true;
zgu@3900 136 }
zgu@3900 137
zgu@7074 138 LinkedList<ReservedMemoryRegion>* virtual_memory_allocations() {
zgu@7074 139 return &_virtual_memory_regions;
zgu@7074 140 }
zgu@7074 141 };
zgu@7074 142
zgu@7074 143
zgu@7074 144 bool MemBaseline::baseline_summary() {
zgu@7080 145 MallocMemorySummary::snapshot(&_malloc_memory_snapshot);
zgu@7080 146 VirtualMemorySummary::snapshot(&_virtual_memory_snapshot);
zgu@7074 147 return true;
zgu@7074 148 }
zgu@7074 149
zgu@7074 150 bool MemBaseline::baseline_allocation_sites() {
zgu@7074 151 // Malloc allocation sites
zgu@7080 152 MallocAllocationSiteWalker malloc_walker;
zgu@7074 153 if (!MallocSiteTable::walk_malloc_site(&malloc_walker)) {
zgu@7074 154 return false;
zgu@7074 155 }
zgu@7074 156
zgu@7080 157 _malloc_sites.move(malloc_walker.malloc_sites());
zgu@7074 158 // The malloc sites are collected in size order
zgu@7074 159 _malloc_sites_order = by_size;
zgu@7074 160
zgu@7074 161 // Virtual memory allocation sites
zgu@7080 162 VirtualMemoryAllocationWalker virtual_memory_walker;
zgu@7074 163 if (!VirtualMemoryTracker::walk_virtual_memory(&virtual_memory_walker)) {
zgu@7074 164 return false;
zgu@7074 165 }
zgu@7074 166
zgu@7074 167 // Virtual memory allocations are collected in call stack order
zgu@7080 168 _virtual_memory_allocations.move(virtual_memory_walker.virtual_memory_allocations());
zgu@7074 169
zgu@7074 170 if (!aggregate_virtual_memory_allocation_sites()) {
zgu@7074 171 return false;
zgu@7074 172 }
zgu@7074 173 // Virtual memory allocation sites are aggregrated in call stack order
zgu@7074 174 _virtual_memory_sites_order = by_address;
zgu@3900 175
zgu@3900 176 return true;
zgu@3900 177 }
zgu@3900 178
zgu@7074 179 bool MemBaseline::baseline(bool summaryOnly) {
zgu@7074 180 reset();
zgu@4193 181
zgu@7074 182 _class_count = InstanceKlass::number_of_instance_classes();
zgu@4193 183
zgu@7074 184 if (!baseline_summary()) {
zgu@4193 185 return false;
zgu@4193 186 }
zgu@4193 187
zgu@7074 188 _baseline_type = Summary_baselined;
zgu@4193 189
zgu@7074 190 // baseline details
zgu@7074 191 if (!summaryOnly &&
zgu@7074 192 MemTracker::tracking_level() == NMT_detail) {
zgu@7074 193 baseline_allocation_sites();
zgu@7074 194 _baseline_type = Detail_baselined;
zgu@4193 195 }
zgu@4193 196
zgu@3900 197 return true;
zgu@3900 198 }
zgu@3900 199
zgu@7074 200 int compare_allocation_site(const VirtualMemoryAllocationSite& s1,
zgu@7074 201 const VirtualMemoryAllocationSite& s2) {
zgu@7074 202 return s1.call_stack()->compare(*s2.call_stack());
zgu@3900 203 }
zgu@3900 204
zgu@7074 205 bool MemBaseline::aggregate_virtual_memory_allocation_sites() {
zgu@7080 206 SortedLinkedList<VirtualMemoryAllocationSite, compare_allocation_site> allocation_sites;
zgu@3900 207
zgu@7074 208 VirtualMemoryAllocationIterator itr = virtual_memory_allocations();
zgu@7074 209 const ReservedMemoryRegion* rgn;
zgu@7074 210 VirtualMemoryAllocationSite* site;
zgu@7074 211 while ((rgn = itr.next()) != NULL) {
zgu@7074 212 VirtualMemoryAllocationSite tmp(*rgn->call_stack());
zgu@7074 213 site = allocation_sites.find(tmp);
zgu@7074 214 if (site == NULL) {
zgu@7074 215 LinkedListNode<VirtualMemoryAllocationSite>* node =
zgu@7074 216 allocation_sites.add(tmp);
zgu@7074 217 if (node == NULL) return false;
zgu@7074 218 site = node->data();
zgu@3900 219 }
zgu@7074 220 site->reserve_memory(rgn->size());
zgu@7074 221 site->commit_memory(rgn->committed_size());
zgu@3900 222 }
zgu@7074 223
zgu@7080 224 _virtual_memory_sites.move(&allocation_sites);
zgu@7074 225 return true;
zgu@3900 226 }
zgu@3900 227
zgu@7074 228 MallocSiteIterator MemBaseline::malloc_sites(SortingOrder order) {
zgu@7080 229 assert(!_malloc_sites.is_empty(), "Not detail baseline");
zgu@7074 230 switch(order) {
zgu@7074 231 case by_size:
zgu@7074 232 malloc_sites_to_size_order();
zgu@7074 233 break;
zgu@7074 234 case by_site:
zgu@7074 235 malloc_sites_to_allocation_site_order();
zgu@7074 236 break;
zgu@9054 237 case by_site_and_type:
zgu@9054 238 malloc_sites_to_allocation_site_and_type_order();
zgu@9054 239 break;
zgu@7074 240 case by_address:
zgu@7074 241 default:
zgu@7074 242 ShouldNotReachHere();
zgu@3900 243 }
zgu@7074 244 return MallocSiteIterator(_malloc_sites.head());
zgu@3900 245 }
zgu@3900 246
zgu@7074 247 VirtualMemorySiteIterator MemBaseline::virtual_memory_sites(SortingOrder order) {
zgu@7080 248 assert(!_virtual_memory_sites.is_empty(), "Not detail baseline");
zgu@7074 249 switch(order) {
zgu@7074 250 case by_size:
zgu@7074 251 virtual_memory_sites_to_size_order();
zgu@7074 252 break;
zgu@7074 253 case by_site:
zgu@7074 254 virtual_memory_sites_to_reservation_site_order();
zgu@7074 255 break;
zgu@7074 256 case by_address:
zgu@7074 257 default:
zgu@7074 258 ShouldNotReachHere();
zgu@3900 259 }
zgu@7074 260 return VirtualMemorySiteIterator(_virtual_memory_sites.head());
zgu@3900 261 }
zgu@3900 262
zgu@3900 263
zgu@7074 264 // Sorting allocations sites in different orders
zgu@7074 265 void MemBaseline::malloc_sites_to_size_order() {
zgu@7074 266 if (_malloc_sites_order != by_size) {
zgu@7080 267 SortedLinkedList<MallocSite, compare_malloc_size> tmp;
zgu@7074 268
zgu@7074 269 // Add malloc sites to sorted linked list to sort into size order
zgu@7074 270 tmp.move(&_malloc_sites);
zgu@7074 271 _malloc_sites.set_head(tmp.head());
zgu@7074 272 tmp.set_head(NULL);
zgu@7074 273 _malloc_sites_order = by_size;
zgu@7074 274 }
zgu@3900 275 }
zgu@3900 276
zgu@7074 277 void MemBaseline::malloc_sites_to_allocation_site_order() {
zgu@9054 278 if (_malloc_sites_order != by_site && _malloc_sites_order != by_site_and_type) {
zgu@7080 279 SortedLinkedList<MallocSite, compare_malloc_site> tmp;
zgu@7074 280 // Add malloc sites to sorted linked list to sort into site (address) order
zgu@7074 281 tmp.move(&_malloc_sites);
zgu@7074 282 _malloc_sites.set_head(tmp.head());
zgu@7074 283 tmp.set_head(NULL);
zgu@7074 284 _malloc_sites_order = by_site;
zgu@7074 285 }
zgu@3900 286 }
zgu@3900 287
zgu@9054 288 void MemBaseline::malloc_sites_to_allocation_site_and_type_order() {
zgu@9054 289 if (_malloc_sites_order != by_site_and_type) {
zgu@9054 290 SortedLinkedList<MallocSite, compare_malloc_site_and_type> tmp;
zgu@9054 291 // Add malloc sites to sorted linked list to sort into site (address) order
zgu@9054 292 tmp.move(&_malloc_sites);
zgu@9054 293 _malloc_sites.set_head(tmp.head());
zgu@9054 294 tmp.set_head(NULL);
zgu@9054 295 _malloc_sites_order = by_site_and_type;
zgu@9054 296 }
zgu@9054 297 }
zgu@9054 298
zgu@7074 299 void MemBaseline::virtual_memory_sites_to_size_order() {
zgu@7074 300 if (_virtual_memory_sites_order != by_size) {
zgu@7080 301 SortedLinkedList<VirtualMemoryAllocationSite, compare_virtual_memory_size> tmp;
zgu@7074 302
zgu@7074 303 tmp.move(&_virtual_memory_sites);
zgu@7074 304
zgu@7074 305 _virtual_memory_sites.set_head(tmp.head());
zgu@7074 306 tmp.set_head(NULL);
zgu@7074 307 _virtual_memory_sites_order = by_size;
zgu@7074 308 }
zgu@3900 309 }
zgu@3900 310
zgu@7074 311 void MemBaseline::virtual_memory_sites_to_reservation_site_order() {
zgu@7074 312 if (_virtual_memory_sites_order != by_size) {
zgu@7080 313 SortedLinkedList<VirtualMemoryAllocationSite, compare_virtual_memory_site> tmp;
zgu@3900 314
zgu@7080 315 tmp.move(&_virtual_memory_sites);
zgu@7074 316
zgu@7074 317 _virtual_memory_sites.set_head(tmp.head());
zgu@7074 318 tmp.set_head(NULL);
zgu@7074 319
zgu@7074 320 _virtual_memory_sites_order = by_size;
zgu@7074 321 }
zgu@3900 322 }
zgu@3900 323

mercurial