1.1 --- a/src/share/vm/services/memPtr.hpp Wed Aug 27 09:36:55 2014 +0200 1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 @@ -1,510 +0,0 @@ 1.4 -/* 1.5 - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 - * 1.8 - * This code is free software; you can redistribute it and/or modify it 1.9 - * under the terms of the GNU General Public License version 2 only, as 1.10 - * published by the Free Software Foundation. 1.11 - * 1.12 - * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 - * version 2 for more details (a copy is included in the LICENSE file that 1.16 - * accompanied this code). 1.17 - * 1.18 - * You should have received a copy of the GNU General Public License version 1.19 - * 2 along with this work; if not, write to the Free Software Foundation, 1.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 - * 1.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 - * or visit www.oracle.com if you need additional information or have any 1.24 - * questions. 1.25 - * 1.26 - */ 1.27 - 1.28 -#ifndef SHARE_VM_SERVICES_MEM_PTR_HPP 1.29 -#define SHARE_VM_SERVICES_MEM_PTR_HPP 1.30 - 1.31 -#include "memory/allocation.hpp" 1.32 -#include "runtime/atomic.hpp" 1.33 -#include "runtime/os.hpp" 1.34 -#include "runtime/safepoint.hpp" 1.35 - 1.36 -/* 1.37 - * global sequence generator that generates sequence numbers to serialize 1.38 - * memory records. 1.39 - */ 1.40 -class SequenceGenerator : AllStatic { 1.41 - public: 1.42 - static jint next(); 1.43 - 1.44 - // peek last sequence number 1.45 - static jint peek() { 1.46 - return _seq_number; 1.47 - } 1.48 - 1.49 - // reset sequence number 1.50 - static void reset() { 1.51 - assert(SafepointSynchronize::is_at_safepoint(), "Safepoint required"); 1.52 - _seq_number = 1; 1.53 - _generation ++; 1.54 - }; 1.55 - 1.56 - static unsigned long current_generation() { return _generation; } 1.57 - NOT_PRODUCT(static jint max_seq_num() { return _max_seq_number; }) 1.58 - 1.59 - private: 1.60 - static volatile jint _seq_number; 1.61 - static volatile unsigned long _generation; 1.62 - NOT_PRODUCT(static jint _max_seq_number; ) 1.63 -}; 1.64 - 1.65 -/* 1.66 - * followings are the classes that are used to hold memory activity records in different stages. 1.67 - * MemPointer 1.68 - * |--------MemPointerRecord 1.69 - * | 1.70 - * |----MemPointerRecordEx 1.71 - * | | 1.72 - * | |-------SeqMemPointerRecordEx 1.73 - * | 1.74 - * |----SeqMemPointerRecord 1.75 - * | 1.76 - * |----VMMemRegion 1.77 - * | 1.78 - * |-----VMMemRegionEx 1.79 - * 1.80 - * 1.81 - * prefix 'Seq' - sequenced, the record contains a sequence number 1.82 - * surfix 'Ex' - extension, the record contains a caller's pc 1.83 - * 1.84 - * per-thread recorder : SeqMemPointerRecord(Ex) 1.85 - * snapshot staging : SeqMemPointerRecord(Ex) 1.86 - * snapshot : MemPointerRecord(Ex) and VMMemRegion(Ex) 1.87 - * 1.88 - */ 1.89 - 1.90 -/* 1.91 - * class that wraps an address to a memory block, 1.92 - * the memory pointer either points to a malloc'd 1.93 - * memory block, or a mmap'd memory block 1.94 - */ 1.95 -class MemPointer VALUE_OBJ_CLASS_SPEC { 1.96 - public: 1.97 - MemPointer(): _addr(0) { } 1.98 - MemPointer(address addr): _addr(addr) { } 1.99 - 1.100 - MemPointer(const MemPointer& copy_from) { 1.101 - _addr = copy_from.addr(); 1.102 - } 1.103 - 1.104 - inline address addr() const { 1.105 - return _addr; 1.106 - } 1.107 - 1.108 - inline operator address() const { 1.109 - return addr(); 1.110 - } 1.111 - 1.112 - inline bool operator == (const MemPointer& other) const { 1.113 - return addr() == other.addr(); 1.114 - } 1.115 - 1.116 - inline MemPointer& operator = (const MemPointer& other) { 1.117 - _addr = other.addr(); 1.118 - return *this; 1.119 - } 1.120 - 1.121 - protected: 1.122 - inline void set_addr(address addr) { _addr = addr; } 1.123 - 1.124 - protected: 1.125 - // memory address 1.126 - address _addr; 1.127 -}; 1.128 - 1.129 -/* MemPointerRecord records an activityand associated 1.130 - * attributes on a memory block. 1.131 - */ 1.132 -class MemPointerRecord : public MemPointer { 1.133 - private: 1.134 - MEMFLAGS _flags; 1.135 - size_t _size; 1.136 - 1.137 -public: 1.138 - /* extension of MemoryType enum 1.139 - * see share/vm/memory/allocation.hpp for details. 1.140 - * 1.141 - * The tag values are associated to sorting orders, so be 1.142 - * careful if changes are needed. 1.143 - * The allocation records should be sorted ahead of tagging 1.144 - * records, which in turn ahead of deallocation records 1.145 - */ 1.146 - enum MemPointerTags { 1.147 - tag_alloc = 0x0001, // malloc or reserve record 1.148 - tag_commit = 0x0002, // commit record 1.149 - tag_type = 0x0003, // tag virtual memory to a memory type 1.150 - tag_uncommit = 0x0004, // uncommit record 1.151 - tag_release = 0x0005, // free or release record 1.152 - tag_size = 0x0006, // arena size 1.153 - tag_masks = 0x0007, // all tag bits 1.154 - vmBit = 0x0008 1.155 - }; 1.156 - 1.157 - /* helper functions to interpret the tagging flags */ 1.158 - 1.159 - inline static bool is_allocation_record(MEMFLAGS flags) { 1.160 - return (flags & tag_masks) == tag_alloc; 1.161 - } 1.162 - 1.163 - inline static bool is_deallocation_record(MEMFLAGS flags) { 1.164 - return (flags & tag_masks) == tag_release; 1.165 - } 1.166 - 1.167 - inline static bool is_arena_record(MEMFLAGS flags) { 1.168 - return (flags & (otArena | tag_size)) == otArena; 1.169 - } 1.170 - 1.171 - inline static bool is_arena_memory_record(MEMFLAGS flags) { 1.172 - return (flags & (otArena | tag_size)) == (otArena | tag_size); 1.173 - } 1.174 - 1.175 - inline static bool is_virtual_memory_record(MEMFLAGS flags) { 1.176 - return (flags & vmBit) != 0; 1.177 - } 1.178 - 1.179 - inline static bool is_virtual_memory_reserve_record(MEMFLAGS flags) { 1.180 - return (flags & 0x0F) == (tag_alloc | vmBit); 1.181 - } 1.182 - 1.183 - inline static bool is_virtual_memory_commit_record(MEMFLAGS flags) { 1.184 - return (flags & 0x0F) == (tag_commit | vmBit); 1.185 - } 1.186 - 1.187 - inline static bool is_virtual_memory_uncommit_record(MEMFLAGS flags) { 1.188 - return (flags & 0x0F) == (tag_uncommit | vmBit); 1.189 - } 1.190 - 1.191 - inline static bool is_virtual_memory_release_record(MEMFLAGS flags) { 1.192 - return (flags & 0x0F) == (tag_release | vmBit); 1.193 - } 1.194 - 1.195 - inline static bool is_virtual_memory_type_record(MEMFLAGS flags) { 1.196 - return (flags & 0x0F) == (tag_type | vmBit); 1.197 - } 1.198 - 1.199 - /* tagging flags */ 1.200 - inline static MEMFLAGS malloc_tag() { return tag_alloc; } 1.201 - inline static MEMFLAGS free_tag() { return tag_release; } 1.202 - inline static MEMFLAGS arena_size_tag() { return tag_size | otArena; } 1.203 - inline static MEMFLAGS virtual_memory_tag() { return vmBit; } 1.204 - inline static MEMFLAGS virtual_memory_reserve_tag() { return (tag_alloc | vmBit); } 1.205 - inline static MEMFLAGS virtual_memory_commit_tag() { return (tag_commit | vmBit); } 1.206 - inline static MEMFLAGS virtual_memory_uncommit_tag(){ return (tag_uncommit | vmBit); } 1.207 - inline static MEMFLAGS virtual_memory_release_tag() { return (tag_release | vmBit); } 1.208 - inline static MEMFLAGS virtual_memory_type_tag() { return (tag_type | vmBit); } 1.209 - 1.210 - public: 1.211 - MemPointerRecord(): _size(0), _flags(mtNone) { } 1.212 - 1.213 - MemPointerRecord(address addr, MEMFLAGS memflags, size_t size = 0): 1.214 - MemPointer(addr), _flags(memflags), _size(size) { } 1.215 - 1.216 - MemPointerRecord(const MemPointerRecord& copy_from): 1.217 - MemPointer(copy_from), _flags(copy_from.flags()), 1.218 - _size(copy_from.size()) { 1.219 - } 1.220 - 1.221 - /* MemPointerRecord is not sequenced, it always return 1.222 - * 0 to indicate non-sequenced 1.223 - */ 1.224 - virtual jint seq() const { return 0; } 1.225 - 1.226 - inline size_t size() const { return _size; } 1.227 - inline void set_size(size_t size) { _size = size; } 1.228 - 1.229 - inline MEMFLAGS flags() const { return _flags; } 1.230 - inline void set_flags(MEMFLAGS flags) { _flags = flags; } 1.231 - 1.232 - MemPointerRecord& operator= (const MemPointerRecord& ptr) { 1.233 - MemPointer::operator=(ptr); 1.234 - _flags = ptr.flags(); 1.235 -#ifdef ASSERT 1.236 - if (IS_ARENA_OBJ(_flags)) { 1.237 - assert(!is_vm_pointer(), "wrong flags"); 1.238 - assert((_flags & ot_masks) == otArena, "wrong flags"); 1.239 - } 1.240 -#endif 1.241 - _size = ptr.size(); 1.242 - return *this; 1.243 - } 1.244 - 1.245 - // if the pointer represents a malloc-ed memory address 1.246 - inline bool is_malloced_pointer() const { 1.247 - return !is_vm_pointer(); 1.248 - } 1.249 - 1.250 - // if the pointer represents a virtual memory address 1.251 - inline bool is_vm_pointer() const { 1.252 - return is_virtual_memory_record(_flags); 1.253 - } 1.254 - 1.255 - // if this record records a 'malloc' or virtual memory 1.256 - // 'reserve' call 1.257 - inline bool is_allocation_record() const { 1.258 - return is_allocation_record(_flags); 1.259 - } 1.260 - 1.261 - // if this record records a size information of an arena 1.262 - inline bool is_arena_memory_record() const { 1.263 - return is_arena_memory_record(_flags); 1.264 - } 1.265 - 1.266 - // if this pointer represents an address to an arena object 1.267 - inline bool is_arena_record() const { 1.268 - return is_arena_record(_flags); 1.269 - } 1.270 - 1.271 - // if this record represents a size information of specific arena 1.272 - inline bool is_memory_record_of_arena(const MemPointerRecord* arena_rc) { 1.273 - assert(is_arena_memory_record(), "not size record"); 1.274 - assert(arena_rc->is_arena_record(), "not arena record"); 1.275 - return (arena_rc->addr() + sizeof(void*)) == addr(); 1.276 - } 1.277 - 1.278 - // if this record records a 'free' or virtual memory 'free' call 1.279 - inline bool is_deallocation_record() const { 1.280 - return is_deallocation_record(_flags); 1.281 - } 1.282 - 1.283 - // if this record records a virtual memory 'commit' call 1.284 - inline bool is_commit_record() const { 1.285 - return is_virtual_memory_commit_record(_flags); 1.286 - } 1.287 - 1.288 - // if this record records a virtual memory 'uncommit' call 1.289 - inline bool is_uncommit_record() const { 1.290 - return is_virtual_memory_uncommit_record(_flags); 1.291 - } 1.292 - 1.293 - // if this record is a tagging record of a virtual memory block 1.294 - inline bool is_type_tagging_record() const { 1.295 - return is_virtual_memory_type_record(_flags); 1.296 - } 1.297 - 1.298 - // if the two memory pointer records actually represent the same 1.299 - // memory block 1.300 - inline bool is_same_region(const MemPointerRecord* other) const { 1.301 - return (addr() == other->addr() && size() == other->size()); 1.302 - } 1.303 - 1.304 - // if this memory region fully contains another one 1.305 - inline bool contains_region(const MemPointerRecord* other) const { 1.306 - return contains_region(other->addr(), other->size()); 1.307 - } 1.308 - 1.309 - // if this memory region fully contains specified memory range 1.310 - inline bool contains_region(address add, size_t sz) const { 1.311 - return (addr() <= add && addr() + size() >= add + sz); 1.312 - } 1.313 - 1.314 - inline bool contains_address(address add) const { 1.315 - return (addr() <= add && addr() + size() > add); 1.316 - } 1.317 - 1.318 - // if this memory region overlaps another region 1.319 - inline bool overlaps_region(const MemPointerRecord* other) const { 1.320 - assert(other != NULL, "Just check"); 1.321 - assert(size() > 0 && other->size() > 0, "empty range"); 1.322 - return contains_address(other->addr()) || 1.323 - contains_address(other->addr() + other->size() - 1) || // exclude end address 1.324 - other->contains_address(addr()) || 1.325 - other->contains_address(addr() + size() - 1); // exclude end address 1.326 - } 1.327 - 1.328 -}; 1.329 - 1.330 -// MemPointerRecordEx also records callsite pc, from where 1.331 -// the memory block is allocated 1.332 -class MemPointerRecordEx : public MemPointerRecord { 1.333 - private: 1.334 - address _pc; // callsite pc 1.335 - 1.336 - public: 1.337 - MemPointerRecordEx(): _pc(0) { } 1.338 - 1.339 - MemPointerRecordEx(address addr, MEMFLAGS memflags, size_t size = 0, address pc = 0): 1.340 - MemPointerRecord(addr, memflags, size), _pc(pc) {} 1.341 - 1.342 - MemPointerRecordEx(const MemPointerRecordEx& copy_from): 1.343 - MemPointerRecord(copy_from), _pc(copy_from.pc()) {} 1.344 - 1.345 - inline address pc() const { return _pc; } 1.346 - 1.347 - void init(const MemPointerRecordEx* mpe) { 1.348 - MemPointerRecord::operator=(*mpe); 1.349 - _pc = mpe->pc(); 1.350 - } 1.351 - 1.352 - void init(const MemPointerRecord* mp) { 1.353 - MemPointerRecord::operator=(*mp); 1.354 - _pc = 0; 1.355 - } 1.356 -}; 1.357 - 1.358 -// a virtual memory region. The region can represent a reserved 1.359 -// virtual memory region or a committed memory region 1.360 -class VMMemRegion : public MemPointerRecord { 1.361 -public: 1.362 - VMMemRegion() { } 1.363 - 1.364 - void init(const MemPointerRecord* mp) { 1.365 - assert(mp->is_vm_pointer(), "Sanity check"); 1.366 - _addr = mp->addr(); 1.367 - set_size(mp->size()); 1.368 - set_flags(mp->flags()); 1.369 - } 1.370 - 1.371 - VMMemRegion& operator=(const VMMemRegion& other) { 1.372 - MemPointerRecord::operator=(other); 1.373 - return *this; 1.374 - } 1.375 - 1.376 - inline bool is_reserved_region() const { 1.377 - return is_allocation_record(); 1.378 - } 1.379 - 1.380 - inline bool is_committed_region() const { 1.381 - return is_commit_record(); 1.382 - } 1.383 - 1.384 - /* base address of this virtual memory range */ 1.385 - inline address base() const { 1.386 - return addr(); 1.387 - } 1.388 - 1.389 - /* tag this virtual memory range to the specified memory type */ 1.390 - inline void tag(MEMFLAGS f) { 1.391 - set_flags(flags() | (f & mt_masks)); 1.392 - } 1.393 - 1.394 - // expand this region to also cover specified range. 1.395 - // The range has to be on either end of the memory region. 1.396 - void expand_region(address addr, size_t sz) { 1.397 - if (addr < base()) { 1.398 - assert(addr + sz == base(), "Sanity check"); 1.399 - _addr = addr; 1.400 - set_size(size() + sz); 1.401 - } else { 1.402 - assert(base() + size() == addr, "Sanity check"); 1.403 - set_size(size() + sz); 1.404 - } 1.405 - } 1.406 - 1.407 - // exclude the specified address range from this region. 1.408 - // The excluded memory range has to be on either end of this memory 1.409 - // region. 1.410 - inline void exclude_region(address add, size_t sz) { 1.411 - assert(is_reserved_region() || is_committed_region(), "Sanity check"); 1.412 - assert(addr() != NULL && size() != 0, "Sanity check"); 1.413 - assert(add >= addr() && add < addr() + size(), "Sanity check"); 1.414 - assert(add == addr() || (add + sz) == (addr() + size()), 1.415 - "exclude in the middle"); 1.416 - if (add == addr()) { 1.417 - set_addr(add + sz); 1.418 - set_size(size() - sz); 1.419 - } else { 1.420 - set_size(size() - sz); 1.421 - } 1.422 - } 1.423 -}; 1.424 - 1.425 -class VMMemRegionEx : public VMMemRegion { 1.426 - private: 1.427 - jint _seq; // sequence number 1.428 - 1.429 - public: 1.430 - VMMemRegionEx(): _pc(0) { } 1.431 - 1.432 - void init(const MemPointerRecordEx* mpe) { 1.433 - VMMemRegion::init(mpe); 1.434 - _pc = mpe->pc(); 1.435 - } 1.436 - 1.437 - void init(const MemPointerRecord* mpe) { 1.438 - VMMemRegion::init(mpe); 1.439 - _pc = 0; 1.440 - } 1.441 - 1.442 - VMMemRegionEx& operator=(const VMMemRegionEx& other) { 1.443 - VMMemRegion::operator=(other); 1.444 - _pc = other.pc(); 1.445 - return *this; 1.446 - } 1.447 - 1.448 - inline address pc() const { return _pc; } 1.449 - private: 1.450 - address _pc; 1.451 -}; 1.452 - 1.453 -/* 1.454 - * Sequenced memory record 1.455 - */ 1.456 -class SeqMemPointerRecord : public MemPointerRecord { 1.457 - private: 1.458 - jint _seq; // sequence number 1.459 - 1.460 - public: 1.461 - SeqMemPointerRecord(): _seq(0){ } 1.462 - 1.463 - SeqMemPointerRecord(address addr, MEMFLAGS flags, size_t size, jint seq) 1.464 - : MemPointerRecord(addr, flags, size), _seq(seq) { 1.465 - } 1.466 - 1.467 - SeqMemPointerRecord(const SeqMemPointerRecord& copy_from) 1.468 - : MemPointerRecord(copy_from) { 1.469 - _seq = copy_from.seq(); 1.470 - } 1.471 - 1.472 - SeqMemPointerRecord& operator= (const SeqMemPointerRecord& ptr) { 1.473 - MemPointerRecord::operator=(ptr); 1.474 - _seq = ptr.seq(); 1.475 - return *this; 1.476 - } 1.477 - 1.478 - inline jint seq() const { 1.479 - return _seq; 1.480 - } 1.481 -}; 1.482 - 1.483 - 1.484 - 1.485 -class SeqMemPointerRecordEx : public MemPointerRecordEx { 1.486 - private: 1.487 - jint _seq; // sequence number 1.488 - 1.489 - public: 1.490 - SeqMemPointerRecordEx(): _seq(0) { } 1.491 - 1.492 - SeqMemPointerRecordEx(address addr, MEMFLAGS flags, size_t size, 1.493 - jint seq, address pc): 1.494 - MemPointerRecordEx(addr, flags, size, pc), _seq(seq) { 1.495 - } 1.496 - 1.497 - SeqMemPointerRecordEx(const SeqMemPointerRecordEx& copy_from) 1.498 - : MemPointerRecordEx(copy_from) { 1.499 - _seq = copy_from.seq(); 1.500 - } 1.501 - 1.502 - SeqMemPointerRecordEx& operator= (const SeqMemPointerRecordEx& ptr) { 1.503 - MemPointerRecordEx::operator=(ptr); 1.504 - _seq = ptr.seq(); 1.505 - return *this; 1.506 - } 1.507 - 1.508 - inline jint seq() const { 1.509 - return _seq; 1.510 - } 1.511 -}; 1.512 - 1.513 -#endif // SHARE_VM_SERVICES_MEM_PTR_HPP