duke@435: /* mikael@6198: * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_SERVICES_MEMORYUSAGE_HPP stefank@2314: #define SHARE_VM_SERVICES_MEMORYUSAGE_HPP stefank@2314: stefank@2314: #include "utilities/globalDefinitions.hpp" stefank@2314: duke@435: // A memory usage contains the following attributes about memory usage: duke@435: // initSize - represents the initial amount of memory (in bytes) that duke@435: // the Java virtual machine requests from the operating system duke@435: // for memory management. The Java virtual machine may request duke@435: // additional memory from the operating system later when appropriate. duke@435: // Its value may be undefined. duke@435: // used - represents the amount of memory currently used (in bytes). duke@435: // committed - represents the amount of memory (in bytes) that is duke@435: // guaranteed to be available for use by the Java virtual machine. duke@435: // The amount of committed memory may change over time (increase duke@435: // or decrease). It is guaranteed to be greater than or equal duke@435: // to initSize. duke@435: // maxSize - represents the maximum amount of memory (in bytes) duke@435: // that can be used for memory management. The maximum amount of duke@435: // memory for memory management could be less than the amount of duke@435: // committed memory. Its value may be undefined. duke@435: duke@435: class MemoryUsage VALUE_OBJ_CLASS_SPEC { duke@435: private: duke@435: size_t _initSize; duke@435: size_t _used; duke@435: size_t _committed; duke@435: size_t _maxSize; duke@435: duke@435: public: duke@435: // Constructors duke@435: MemoryUsage(size_t i, size_t u, size_t c, size_t m) : duke@435: _initSize(i), _used(u), _committed(c), _maxSize(m) {}; duke@435: MemoryUsage() : duke@435: _initSize(0), _used(0), _committed(0), _maxSize(0) {}; duke@435: duke@435: size_t init_size() const { return _initSize; } duke@435: size_t used() const { return _used; } duke@435: size_t committed() const { return _committed; } duke@435: size_t max_size() const { return _maxSize; } duke@435: ehelin@5716: static size_t undefined_size() { return (size_t) -1; } ehelin@5716: duke@435: inline static jlong convert_to_jlong(size_t val) { duke@435: // In the 64-bit vm, a size_t can overflow a jlong (which is signed). duke@435: jlong ret; ehelin@5716: if (val == undefined_size()) { duke@435: ret = -1L; duke@435: } else { duke@435: NOT_LP64(ret = val;) duke@435: LP64_ONLY(ret = MIN2(val, (size_t)max_jlong);) duke@435: } duke@435: return ret; duke@435: } duke@435: duke@435: jlong init_size_as_jlong() const { return convert_to_jlong(_initSize); } duke@435: jlong used_as_jlong() const { return convert_to_jlong(_used); } duke@435: jlong committed_as_jlong() const { return convert_to_jlong(_committed); } duke@435: jlong max_size_as_jlong() const { return convert_to_jlong(_maxSize); } duke@435: }; stefank@2314: stefank@2314: #endif // SHARE_VM_SERVICES_MEMORYUSAGE_HPP