memoryUsage.hpp revision 1879:f95d63e2154a
1294328Sdes/*
298675Sdes * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
398675Sdes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
498675Sdes *
598675Sdes * This code is free software; you can redistribute it and/or modify it
698675Sdes * under the terms of the GNU General Public License version 2 only, as
798675Sdes * published by the Free Software Foundation.
898675Sdes *
998675Sdes * This code is distributed in the hope that it will be useful, but WITHOUT
1098675Sdes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1198675Sdes * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1298675Sdes * version 2 for more details (a copy is included in the LICENSE file that
1398675Sdes * accompanied this code).
1498675Sdes *
1598675Sdes * You should have received a copy of the GNU General Public License version
1698675Sdes * 2 along with this work; if not, write to the Free Software Foundation,
1798675Sdes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1898675Sdes *
1998675Sdes * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2098675Sdes * or visit www.oracle.com if you need additional information or have any
2198675Sdes * questions.
2298675Sdes *
2398675Sdes */
2498675Sdes
2598675Sdes#ifndef SHARE_VM_SERVICES_MEMORYUSAGE_HPP
2698675Sdes#define SHARE_VM_SERVICES_MEMORYUSAGE_HPP
2798675Sdes
28162852Sdes#include "utilities/globalDefinitions.hpp"
29162852Sdes
30162852Sdes// A memory usage contains the following attributes about memory usage:
31162852Sdes//  initSize - represents the initial amount of memory (in bytes) that
32162852Sdes//     the Java virtual machine requests from the operating system
33181111Sdes//     for memory management.  The Java virtual machine may request
34162852Sdes//     additional memory from the operating system later when appropriate.
35294328Sdes//     Its value may be undefined.
36294328Sdes//  used      - represents the amount of memory currently used (in bytes).
37162852Sdes//  committed - represents the amount of memory (in bytes) that is
38181111Sdes//     guaranteed to be available for use by the Java virtual machine.
39162852Sdes//     The amount of committed memory may change over time (increase
40162852Sdes//     or decrease).  It is guaranteed to be greater than or equal
41162852Sdes//     to initSize.
4298675Sdes//  maxSize   - represents the maximum amount of memory (in bytes)
4398675Sdes//     that can be used for memory management. The maximum amount of
4498675Sdes//     memory for memory management could be less than the amount of
45162852Sdes//     committed memory.  Its value may be undefined.
46294328Sdes
4798675Sdesclass MemoryUsage VALUE_OBJ_CLASS_SPEC {
4898675Sdesprivate:
4998675Sdes  size_t _initSize;
50162852Sdes  size_t _used;
51162852Sdes  size_t _committed;
52162852Sdes  size_t _maxSize;
5398675Sdes
5498675Sdespublic:
5598675Sdes  // Constructors
5698675Sdes  MemoryUsage(size_t i, size_t u, size_t c, size_t m) :
5798675Sdes    _initSize(i), _used(u), _committed(c), _maxSize(m) {};
5898675Sdes  MemoryUsage() :
5998675Sdes    _initSize(0), _used(0), _committed(0), _maxSize(0) {};
6098675Sdes
6198675Sdes  size_t init_size() const { return _initSize; }
6298675Sdes  size_t used()      const { return _used; }
6398675Sdes  size_t committed() const { return _committed; }
6498675Sdes  size_t max_size()  const { return _maxSize; }
6598675Sdes
66215116Sdes  inline static jlong convert_to_jlong(size_t val) {
67124208Sdes    // In the 64-bit vm, a size_t can overflow a jlong (which is signed).
68124208Sdes    jlong ret;
6998675Sdes    if (val == (size_t)-1) {
7098675Sdes      ret = -1L;
7198675Sdes    } else {
7298675Sdes      NOT_LP64(ret = val;)
7398675Sdes      LP64_ONLY(ret = MIN2(val, (size_t)max_jlong);)
7498675Sdes    }
7598675Sdes    return ret;
76  }
77
78  jlong init_size_as_jlong() const { return convert_to_jlong(_initSize); }
79  jlong used_as_jlong()      const { return convert_to_jlong(_used); }
80  jlong committed_as_jlong() const { return convert_to_jlong(_committed); }
81  jlong max_size_as_jlong()  const { return convert_to_jlong(_maxSize); }
82};
83
84#endif // SHARE_VM_SERVICES_MEMORYUSAGE_HPP
85