src/hotspot/share/memory/metaspace/runningCounters.hpp
author stuefe
Tue, 10 Sep 2019 09:24:05 +0200
branchstuefe-new-metaspace-branch
changeset 58063 bdf136b8ae0e
permissions -rw-r--r--
Initial changes for new metaspace. Only tested for Linux x64.

/*
 * Copyright (c) 2019 SAP SE. All rights reserved.
 * Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 *
 */

#ifndef SHARE_MEMORY_METASPACE_RUNNINGCOUNTERS_HPP
#define SHARE_MEMORY_METASPACE_RUNNINGCOUNTERS_HPP

#include "memory/allocation.hpp"
#include "memory/metaspace/counter.hpp"

namespace metaspace {

class ClassLoaderMetaspace;

// These are running counters for some basic Metaspace statistics.
// Their value can be obtained quickly without locking.

class RunningCounters : public AllStatic {

  friend class ClassLoaderMetaspace;

  // ---- in-use chunks ----

  // Used space, in words.
  // (Note that the used counter is on the hot path of Metaspace allocation.
  //  Do we really need it? We may get by with capacity only and get more details
  //  with get_statistics_slow().)
  static SizeAtomicCounter _used_class_counter;
  static SizeAtomicCounter _used_nonclass_counter;

public:

  // ---- virtual memory -----

  // Return reserved size, in words, for Metaspace
  static size_t reserved_words();
  static size_t reserved_words_class();
  static size_t reserved_words_nonclass();

  // Return total committed size, in words, for Metaspace
  static size_t committed_words();
  static size_t committed_words_class();
  static size_t committed_words_nonclass();


  // ---- used chunks -----

  // Returns size, in words, used for metadata.
  static size_t used_words();
  static size_t used_words_class();
  static size_t used_words_nonclass();

  // ---- free chunks -----

  // Returns size, in words, of all chunks in all freelists.
  static size_t free_chunks_words();
  static size_t free_chunks_words_class();
  static size_t free_chunks_words_nonclass();

  // Direct access to the counters.
  static SizeAtomicCounter* used_nonclass_counter()     { return &_used_nonclass_counter; }
  static SizeAtomicCounter* used_class_counter()        { return &_used_class_counter; }

};

} // namespace metaspace

#endif // SHARE_MEMORY_METASPACE_RUNNINGCOUNTERS_HPP