src/share/vm/services/memoryUsage.hpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6198
55fb97c4c58d
parent 0
f90c822e73f8
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_SERVICES_MEMORYUSAGE_HPP
aoqi@0 26 #define SHARE_VM_SERVICES_MEMORYUSAGE_HPP
aoqi@0 27
aoqi@0 28 #include "utilities/globalDefinitions.hpp"
aoqi@0 29
aoqi@0 30 // A memory usage contains the following attributes about memory usage:
aoqi@0 31 // initSize - represents the initial amount of memory (in bytes) that
aoqi@0 32 // the Java virtual machine requests from the operating system
aoqi@0 33 // for memory management. The Java virtual machine may request
aoqi@0 34 // additional memory from the operating system later when appropriate.
aoqi@0 35 // Its value may be undefined.
aoqi@0 36 // used - represents the amount of memory currently used (in bytes).
aoqi@0 37 // committed - represents the amount of memory (in bytes) that is
aoqi@0 38 // guaranteed to be available for use by the Java virtual machine.
aoqi@0 39 // The amount of committed memory may change over time (increase
aoqi@0 40 // or decrease). It is guaranteed to be greater than or equal
aoqi@0 41 // to initSize.
aoqi@0 42 // maxSize - represents the maximum amount of memory (in bytes)
aoqi@0 43 // that can be used for memory management. The maximum amount of
aoqi@0 44 // memory for memory management could be less than the amount of
aoqi@0 45 // committed memory. Its value may be undefined.
aoqi@0 46
aoqi@0 47 class MemoryUsage VALUE_OBJ_CLASS_SPEC {
aoqi@0 48 private:
aoqi@0 49 size_t _initSize;
aoqi@0 50 size_t _used;
aoqi@0 51 size_t _committed;
aoqi@0 52 size_t _maxSize;
aoqi@0 53
aoqi@0 54 public:
aoqi@0 55 // Constructors
aoqi@0 56 MemoryUsage(size_t i, size_t u, size_t c, size_t m) :
aoqi@0 57 _initSize(i), _used(u), _committed(c), _maxSize(m) {};
aoqi@0 58 MemoryUsage() :
aoqi@0 59 _initSize(0), _used(0), _committed(0), _maxSize(0) {};
aoqi@0 60
aoqi@0 61 size_t init_size() const { return _initSize; }
aoqi@0 62 size_t used() const { return _used; }
aoqi@0 63 size_t committed() const { return _committed; }
aoqi@0 64 size_t max_size() const { return _maxSize; }
aoqi@0 65
aoqi@0 66 static size_t undefined_size() { return (size_t) -1; }
aoqi@0 67
aoqi@0 68 inline static jlong convert_to_jlong(size_t val) {
aoqi@0 69 // In the 64-bit vm, a size_t can overflow a jlong (which is signed).
aoqi@0 70 jlong ret;
aoqi@0 71 if (val == undefined_size()) {
aoqi@0 72 ret = -1L;
aoqi@0 73 } else {
aoqi@0 74 NOT_LP64(ret = val;)
aoqi@0 75 LP64_ONLY(ret = MIN2(val, (size_t)max_jlong);)
aoqi@0 76 }
aoqi@0 77 return ret;
aoqi@0 78 }
aoqi@0 79
aoqi@0 80 jlong init_size_as_jlong() const { return convert_to_jlong(_initSize); }
aoqi@0 81 jlong used_as_jlong() const { return convert_to_jlong(_used); }
aoqi@0 82 jlong committed_as_jlong() const { return convert_to_jlong(_committed); }
aoqi@0 83 jlong max_size_as_jlong() const { return convert_to_jlong(_maxSize); }
aoqi@0 84 };
aoqi@0 85
aoqi@0 86 #endif // SHARE_VM_SERVICES_MEMORYUSAGE_HPP

mercurial