src/hotspot/share/memory/metaspaceClosure.cpp
author ccheung
Fri, 17 May 2019 08:29:55 -0700
changeset 54927 1512d88b24c6
parent 52631 3009ca99de32
child 55296 357c9dcb6eb9
permissions -rw-r--r--
8207812: Implement Dynamic CDS Archive Summary: Improve the usability of AppCDS Reviewed-by: acorn, jiangli, mseledtsov Contributed-by: ioi.lam@oracle.com, jianglizhou@google.com, calvin.cheung@oracle.com
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
/*
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52631
diff changeset
     2
 * Copyright (c) 2017, 2019, 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
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52631
diff changeset
    37
void MetaspaceClosure::push_impl(MetaspaceClosure::Ref* ref) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52631
diff changeset
    38
  if (_nest_level < MAX_NEST_LEVEL) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52631
diff changeset
    39
    do_push(ref);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52631
diff changeset
    40
    delete ref;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52631
diff changeset
    41
  } else {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52631
diff changeset
    42
    ref->set_next(_pending_refs);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52631
diff changeset
    43
    _pending_refs = ref;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52631
diff changeset
    44
  }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52631
diff changeset
    45
}
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52631
diff changeset
    46
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52631
diff changeset
    47
void MetaspaceClosure::do_push(MetaspaceClosure::Ref* ref) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52631
diff changeset
    48
  if (ref->not_null()) { // FIXME: make this configurable, so DynamicArchiveBuilder mark all pointers
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    49
    bool read_only;
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52631
diff changeset
    50
    Writability w = ref->writability();
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    51
    switch (w) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    52
    case _writable:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    53
      read_only = false;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    54
      break;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    55
    case _not_writable:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    56
      read_only = true;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    57
      break;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    58
    default:
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    59
      assert(w == _default, "must be");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    60
      read_only = ref->is_read_only_by_default();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    61
    }
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52631
diff changeset
    62
    _nest_level ++;
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    63
    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
    64
      ref->metaspace_pointers_do(this);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    65
    }
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52631
diff changeset
    66
    _nest_level --;
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    67
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    68
}
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    69
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52631
diff changeset
    70
void MetaspaceClosure::finish() {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52631
diff changeset
    71
  assert(_nest_level == 0, "must be");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52631
diff changeset
    72
  while (_pending_refs != NULL) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52631
diff changeset
    73
    Ref* ref = _pending_refs;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52631
diff changeset
    74
    _pending_refs = _pending_refs->next();
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52631
diff changeset
    75
    do_push(ref);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52631
diff changeset
    76
    delete ref;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52631
diff changeset
    77
  }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52631
diff changeset
    78
}
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52631
diff changeset
    79
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52631
diff changeset
    80
MetaspaceClosure::~MetaspaceClosure() {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52631
diff changeset
    81
  assert(_pending_refs == NULL,
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52631
diff changeset
    82
         "you must explicitly call MetaspaceClosure::finish() to process all refs!");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52631
diff changeset
    83
}
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52631
diff changeset
    84
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    85
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
    86
  bool* found = _has_been_visited.lookup(ref->obj());
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    87
  if (found != NULL) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    88
    assert(*found == read_only, "must be");
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    89
    return false; // Already visited: no need to iterate embedded pointers.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    90
  } else {
52631
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 47216
diff changeset
    91
    _has_been_visited.add(ref->obj(), read_only);
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 47216
diff changeset
    92
    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
    93
      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
    94
    }
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 52631
diff changeset
    95
    return do_unique_ref(ref, read_only);
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    96
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
diff changeset
    97
}