src/hotspot/share/memory/metaspaceClosure.cpp
author coleenp
Fri, 04 Jan 2019 15:06:01 -0500
changeset 53149 259c36ef27df
parent 52631 3009ca99de32
child 54927 1512d88b24c6
permissions -rw-r--r--
8215731: Move forward class definitions out of globalDefinitions.hpp Summary: redistribute the forward declarations to the header files that need them. Reviewed-by: dholmes, lfoltan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
     1
/*
52631
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 47216
diff changeset
     2
 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
     4
 *
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
     8
 *
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    13
 * accompanied this code).
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    14
 *
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    18
 *
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    21
 * questions.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    22
 *
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    23
 */
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    24
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    25
#include "precompiled.hpp"
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    26
#include "memory/metaspaceClosure.hpp"
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    27
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    28
// Update the reference to point to new_loc.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    29
void MetaspaceClosure::Ref::update(address new_loc) const {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    30
  log_trace(cds)("Ref: [" PTR_FORMAT "] -> " PTR_FORMAT " => " PTR_FORMAT,
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    31
                 p2i(mpp()), p2i(obj()), p2i(new_loc));
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    32
  uintx p = (uintx)new_loc;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    33
  p |= flag_bits(); // Make sure the flag bits are copied to the new pointer.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    34
  *(address*)mpp() = (address)p;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    35
}
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    36
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    37
void MetaspaceClosure::push_impl(MetaspaceClosure::Ref* ref, Writability w) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    38
  if (ref->not_null()) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    39
    bool read_only;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    40
    switch (w) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    41
    case _writable:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    42
      read_only = false;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    43
      break;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    44
    case _not_writable:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    45
      read_only = true;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    46
      break;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    47
    default:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    48
      assert(w == _default, "must be");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    49
      read_only = ref->is_read_only_by_default();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    50
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    51
    if (do_ref(ref, read_only)) { // true means we want to iterate the embedded pointer in <ref>
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    52
      ref->metaspace_pointers_do(this);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    53
    }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    54
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    55
}
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    56
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    57
bool UniqueMetaspaceClosure::do_ref(MetaspaceClosure::Ref* ref, bool read_only) {
52631
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 47216
diff changeset
    58
  bool* found = _has_been_visited.lookup(ref->obj());
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    59
  if (found != NULL) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    60
    assert(*found == read_only, "must be");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    61
    return false; // Already visited: no need to iterate embedded pointers.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    62
  } else {
52631
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 47216
diff changeset
    63
    _has_been_visited.add(ref->obj(), read_only);
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 47216
diff changeset
    64
    if (_has_been_visited.maybe_grow(MAX_TABLE_SIZE)) {
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 47216
diff changeset
    65
      log_info(cds, hashtables)("Expanded _has_been_visited table to %d", _has_been_visited.table_size());
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 47216
diff changeset
    66
    }
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    67
    do_unique_ref(ref, read_only);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    68
    return true;  // Saw this for the first time: iterate the embedded pointers.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    69
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    70
}