src/hotspot/share/jfr/leakprofiler/chains/rootSetClosure.cpp
author coleenp
Fri, 28 Sep 2018 16:07:39 -0400
changeset 51959 db0c3952de52
parent 50297 580744d900c8
child 52141 de6dc206a92b
permissions -rw-r--r--
8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files Reviewed-by: iklam, stuefe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     1
/*
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     2
 * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     4
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     7
 * published by the Free Software Foundation.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     8
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    13
 * accompanied this code).
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    14
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    18
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    21
 * questions.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    22
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    23
 */
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    24
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    25
#include "precompiled.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    26
#include "aot/aotLoader.hpp"
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents: 50297
diff changeset
    27
#include "classfile/classLoaderDataGraph.hpp"
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    28
#include "classfile/stringTable.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    29
#include "classfile/systemDictionary.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    30
#include "gc/shared/strongRootsScope.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    31
#include "jfr/leakprofiler/chains/edgeQueue.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    32
#include "jfr/leakprofiler/chains/rootSetClosure.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    33
#include "jfr/leakprofiler/utilities/saveRestore.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    34
#include "jfr/leakprofiler/utilities/unifiedOop.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    35
#include "memory/universe.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    36
#include "oops/access.inline.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    37
#include "prims/jvmtiExport.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    38
#include "runtime/jniHandles.inline.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    39
#include "runtime/synchronizer.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    40
#include "runtime/thread.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    41
#include "services/management.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    42
#include "utilities/align.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    43
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    44
RootSetClosure::RootSetClosure(EdgeQueue* edge_queue) :
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    45
  _edge_queue(edge_queue) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    46
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    47
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    48
void RootSetClosure::do_oop(oop* ref) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    49
  assert(ref != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    50
  // We discard unaligned root references because
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    51
  // our reference tagging scheme will use
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    52
  // the lowest bit in a represented reference
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    53
  // to indicate the reference is narrow.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    54
  // It is mainly roots delivered via nmethods::do_oops()
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    55
  // that come in unaligned. It should be ok to duck these
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    56
  // since they are supposedly weak.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    57
  if (!is_aligned(ref, HeapWordSize)) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    58
    return;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    59
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    60
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    61
  assert(is_aligned(ref, HeapWordSize), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    62
  const oop pointee = *ref;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    63
  if (pointee != NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    64
    closure_impl(ref, pointee);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    65
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    66
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    67
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    68
void RootSetClosure::do_oop(narrowOop* ref) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    69
  assert(ref != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    70
  assert(is_aligned(ref, sizeof(narrowOop)), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    71
  const oop pointee = RawAccess<>::oop_load(ref);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    72
  if (pointee != NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    73
    closure_impl(UnifiedOop::encode(ref), pointee);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    74
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    75
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    76
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    77
void RootSetClosure::closure_impl(const oop* reference, const oop pointee) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    78
  if (!_edge_queue->is_full())  {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    79
    _edge_queue->add(NULL, reference);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    80
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    81
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    82
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    83
void RootSetClosure::add_to_queue(EdgeQueue* edge_queue) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    84
  RootSetClosure rs(edge_queue);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    85
  process_roots(&rs);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    86
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    87
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    88
class RootSetClosureMarkScope : public MarkScope {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    89
};
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    90
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    91
void RootSetClosure::process_roots(OopClosure* closure) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    92
  SaveRestoreCLDClaimBits save_restore_cld_claim_bits;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    93
  RootSetClosureMarkScope mark_scope;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    94
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    95
  CLDToOopClosure cldt_closure(closure);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    96
  ClassLoaderDataGraph::always_strong_cld_do(&cldt_closure);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    97
  CodeBlobToOopClosure blobs(closure, false);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    98
  Threads::oops_do(closure, &blobs);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    99
  ObjectSynchronizer::oops_do(closure);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   100
  Universe::oops_do(closure);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   101
  JNIHandles::oops_do(closure);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   102
  JvmtiExport::oops_do(closure);
50297
580744d900c8 8202813: Move vm_weak processing from SystemDictionary to WeakProcessor
coleenp
parents: 50113
diff changeset
   103
  SystemDictionary::oops_do(closure);
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   104
  Management::oops_do(closure);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   105
  StringTable::oops_do(closure);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   106
  AOTLoader::oops_do(closure);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   107
}