src/hotspot/share/gc/shared/hSpaceCounters.cpp
author pliden
Wed, 20 Nov 2019 10:37:46 +0100
changeset 59153 1152339c298a
parent 58084 cddef3bde924
permissions -rw-r--r--
8234437: Remove CollectedHeap::safe_object_iterate() Reviewed-by: kbarrett, sjohanss
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9338
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
     1
/*
58084
cddef3bde924 8230398: Remove NULL checks before FREE_C_HEAP_ARRAY
lkorinth
parents: 48196
diff changeset
     2
 * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
9338
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
     4
 *
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
     7
 * published by the Free Software Foundation.
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
     8
 *
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    13
 * accompanied this code).
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    14
 *
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    18
 *
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    21
 * questions.
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    22
 *
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    23
 */
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    24
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    25
#include "precompiled.hpp"
48116
8a5e8cd321d9 8191861: Move and refactor hSpaceCounters
stefank
parents: 47216
diff changeset
    26
#include "gc/shared/hSpaceCounters.hpp"
48157
7c4d43c26352 8192061: Clean up allocation.inline.hpp includes
stefank
parents: 48116
diff changeset
    27
#include "memory/allocation.inline.hpp"
9338
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    28
#include "memory/resourceArea.hpp"
48116
8a5e8cd321d9 8191861: Move and refactor hSpaceCounters
stefank
parents: 47216
diff changeset
    29
#include "runtime/perfData.hpp"
9338
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    30
48116
8a5e8cd321d9 8191861: Move and refactor hSpaceCounters
stefank
parents: 47216
diff changeset
    31
HSpaceCounters::HSpaceCounters(const char* name_space,
8a5e8cd321d9 8191861: Move and refactor hSpaceCounters
stefank
parents: 47216
diff changeset
    32
                               const char* name,
9338
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    33
                               int ordinal,
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    34
                               size_t max_size,
48116
8a5e8cd321d9 8191861: Move and refactor hSpaceCounters
stefank
parents: 47216
diff changeset
    35
                               size_t initial_capacity) {
9338
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    36
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    37
  if (UsePerfData) {
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    38
    EXCEPTION_MARK;
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    39
    ResourceMark rm;
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    40
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    41
    const char* cns =
48116
8a5e8cd321d9 8191861: Move and refactor hSpaceCounters
stefank
parents: 47216
diff changeset
    42
      PerfDataManager::name_space(name_space, "space", ordinal);
9338
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    43
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 9338
diff changeset
    44
    _name_space = NEW_C_HEAP_ARRAY(char, strlen(cns)+1, mtGC);
9338
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    45
    strcpy(_name_space, cns);
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    46
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    47
    const char* cname = PerfDataManager::counter_name(_name_space, "name");
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    48
    PerfDataManager::create_string_constant(SUN_GC, cname, name, CHECK);
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    49
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    50
    cname = PerfDataManager::counter_name(_name_space, "maxCapacity");
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    51
    PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_Bytes,
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    52
                                     (jlong)max_size, CHECK);
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    53
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    54
    cname = PerfDataManager::counter_name(_name_space, "capacity");
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    55
    _capacity = PerfDataManager::create_variable(SUN_GC, cname,
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    56
                                                 PerfData::U_Bytes,
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    57
                                                 initial_capacity, CHECK);
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    58
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    59
    cname = PerfDataManager::counter_name(_name_space, "used");
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    60
    _used = PerfDataManager::create_variable(SUN_GC, cname, PerfData::U_Bytes,
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    61
                                             (jlong) 0, CHECK);
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    62
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    63
    cname = PerfDataManager::counter_name(_name_space, "initCapacity");
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    64
    PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_Bytes,
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    65
                                     initial_capacity, CHECK);
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    66
  }
05ee447bd420 6946417: G1: Java VisualVM does not support G1 properly.
jmasa
parents:
diff changeset
    67
}
48116
8a5e8cd321d9 8191861: Move and refactor hSpaceCounters
stefank
parents: 47216
diff changeset
    68
8a5e8cd321d9 8191861: Move and refactor hSpaceCounters
stefank
parents: 47216
diff changeset
    69
HSpaceCounters::~HSpaceCounters() {
58084
cddef3bde924 8230398: Remove NULL checks before FREE_C_HEAP_ARRAY
lkorinth
parents: 48196
diff changeset
    70
  FREE_C_HEAP_ARRAY(char, _name_space);
48116
8a5e8cd321d9 8191861: Move and refactor hSpaceCounters
stefank
parents: 47216
diff changeset
    71
}
8a5e8cd321d9 8191861: Move and refactor hSpaceCounters
stefank
parents: 47216
diff changeset
    72
8a5e8cd321d9 8191861: Move and refactor hSpaceCounters
stefank
parents: 47216
diff changeset
    73
void HSpaceCounters::update_capacity(size_t v) {
8a5e8cd321d9 8191861: Move and refactor hSpaceCounters
stefank
parents: 47216
diff changeset
    74
  _capacity->set_value(v);
8a5e8cd321d9 8191861: Move and refactor hSpaceCounters
stefank
parents: 47216
diff changeset
    75
}
8a5e8cd321d9 8191861: Move and refactor hSpaceCounters
stefank
parents: 47216
diff changeset
    76
8a5e8cd321d9 8191861: Move and refactor hSpaceCounters
stefank
parents: 47216
diff changeset
    77
void HSpaceCounters::update_used(size_t v) {
8a5e8cd321d9 8191861: Move and refactor hSpaceCounters
stefank
parents: 47216
diff changeset
    78
  _used->set_value(v);
8a5e8cd321d9 8191861: Move and refactor hSpaceCounters
stefank
parents: 47216
diff changeset
    79
}
8a5e8cd321d9 8191861: Move and refactor hSpaceCounters
stefank
parents: 47216
diff changeset
    80
8a5e8cd321d9 8191861: Move and refactor hSpaceCounters
stefank
parents: 47216
diff changeset
    81
void HSpaceCounters::update_all(size_t capacity, size_t used) {
8a5e8cd321d9 8191861: Move and refactor hSpaceCounters
stefank
parents: 47216
diff changeset
    82
  update_capacity(capacity);
8a5e8cd321d9 8191861: Move and refactor hSpaceCounters
stefank
parents: 47216
diff changeset
    83
  update_used(used);
8a5e8cd321d9 8191861: Move and refactor hSpaceCounters
stefank
parents: 47216
diff changeset
    84
}
8a5e8cd321d9 8191861: Move and refactor hSpaceCounters
stefank
parents: 47216
diff changeset
    85
8a5e8cd321d9 8191861: Move and refactor hSpaceCounters
stefank
parents: 47216
diff changeset
    86
debug_only(
8a5e8cd321d9 8191861: Move and refactor hSpaceCounters
stefank
parents: 47216
diff changeset
    87
  // for security reasons, we do not allow arbitrary reads from
8a5e8cd321d9 8191861: Move and refactor hSpaceCounters
stefank
parents: 47216
diff changeset
    88
  // the counters as they may live in shared memory.
8a5e8cd321d9 8191861: Move and refactor hSpaceCounters
stefank
parents: 47216
diff changeset
    89
  jlong HSpaceCounters::used() {
8a5e8cd321d9 8191861: Move and refactor hSpaceCounters
stefank
parents: 47216
diff changeset
    90
    return _used->get_value();
8a5e8cd321d9 8191861: Move and refactor hSpaceCounters
stefank
parents: 47216
diff changeset
    91
  }
8a5e8cd321d9 8191861: Move and refactor hSpaceCounters
stefank
parents: 47216
diff changeset
    92
  jlong HSpaceCounters::capacity() {
8a5e8cd321d9 8191861: Move and refactor hSpaceCounters
stefank
parents: 47216
diff changeset
    93
    return _used->get_value();
8a5e8cd321d9 8191861: Move and refactor hSpaceCounters
stefank
parents: 47216
diff changeset
    94
  }
8a5e8cd321d9 8191861: Move and refactor hSpaceCounters
stefank
parents: 47216
diff changeset
    95
)