src/hotspot/share/jfr/periodic/jfrModuleEvent.cpp
author coleenp
Fri, 28 Sep 2018 16:07:39 -0400
changeset 51959 db0c3952de52
parent 51608 625a5bdde0c5
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) 2015, 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"
51959
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents: 51608
diff changeset
    26
#include "classfile/classLoaderData.inline.hpp"
db0c3952de52 8209645: Split ClassLoaderData and ClassLoaderDataGraph into separate files
coleenp
parents: 51608
diff changeset
    27
#include "classfile/classLoaderDataGraph.hpp"
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    28
#include "classfile/moduleEntry.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    29
#include "classfile/packageEntry.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    30
#include "jfr/jfrEvents.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    31
#include "jfr/periodic/jfrModuleEvent.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    32
#include "jfr/utilities/jfrTime.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    33
#include "runtime/mutexLocker.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    34
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    35
// we want all periodic module events to have the same timestamp
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    36
static JfrTicks invocation_time;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    37
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    38
typedef void (*EventFunc)(const void* iterated_address, const ModuleEntry* module);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    39
class ModuleEventCallbackClosure : public ModuleClosure {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    40
 protected:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    41
  const EventFunc _event_func;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    42
  ModuleEventCallbackClosure(EventFunc ef) : _event_func(ef) {}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    43
};
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    44
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    45
class ModuleDependencyClosure : public ModuleEventCallbackClosure {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    46
 private:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    47
  const ModuleEntry* const _module;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    48
 public:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    49
   ModuleDependencyClosure(const ModuleEntry* module, EventFunc ef) : ModuleEventCallbackClosure(ef), _module(module) {}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    50
   void do_module(ModuleEntry* entry);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    51
};
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    52
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    53
class ModuleExportClosure : public ModuleEventCallbackClosure {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    54
 private:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    55
  const PackageEntry* const _package;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    56
 public:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    57
  ModuleExportClosure(const PackageEntry* pkg, EventFunc ef) : ModuleEventCallbackClosure(ef), _package(pkg) {}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    58
  void do_module(ModuleEntry* entry);
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
static void write_module_dependency_event(const void* from_module, const ModuleEntry* to_module) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    62
  EventModuleRequire event(UNTIMED);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    63
  event.set_endtime(invocation_time);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    64
  event.set_source((const ModuleEntry* const)from_module);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    65
  event.set_requiredModule(to_module);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    66
  event.commit();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    67
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    68
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    69
static void write_module_export_event(const void* package, const ModuleEntry* qualified_export) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    70
  EventModuleExport event(UNTIMED);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    71
  event.set_endtime(invocation_time);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    72
  event.set_exportedPackage((const PackageEntry*)package);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    73
  event.set_targetModule(qualified_export);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    74
  event.commit();
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 ModuleDependencyClosure::do_module(ModuleEntry* to_module) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    78
  assert_locked_or_safepoint(Module_lock);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    79
  assert(to_module != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    80
  assert(_module != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    81
  assert(_event_func != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    82
  _event_func(_module, to_module);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    83
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    84
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    85
void ModuleExportClosure::do_module(ModuleEntry* qualified_export) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    86
  assert_locked_or_safepoint(Module_lock);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    87
  assert(qualified_export != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    88
  assert(_package != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    89
  assert(_event_func != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    90
  _event_func(_package, qualified_export);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    91
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    92
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    93
static void module_dependency_event_callback(ModuleEntry* module) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    94
  assert_locked_or_safepoint(Module_lock);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    95
  assert(module != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    96
  if (module->has_reads_list()) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    97
    // create an individual event for each directed edge
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    98
    ModuleDependencyClosure directed_edges(module, &write_module_dependency_event);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    99
    module->module_reads_do(&directed_edges);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   100
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   101
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   102
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   103
static void module_export_event_callback(PackageEntry* package) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   104
  assert_locked_or_safepoint(Module_lock);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   105
  assert(package != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   106
  if (package->is_exported()) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   107
    if (package->has_qual_exports_list()) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   108
      // package is qualifiedly exported to a set of modules,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   109
      // create an event for each module in the qualified exported list
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   110
      ModuleExportClosure qexports(package, &write_module_export_event);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   111
      package->package_exports_do(&qexports);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   112
      return;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   113
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   114
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   115
    assert(!package->is_qual_exported() || package->is_exported_allUnnamed(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   116
    // no qualified exports
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   117
    // only create a single event with NULL
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   118
    // for the qualified_exports module
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   119
    write_module_export_event(package, NULL);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   120
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   121
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   122
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   123
void JfrModuleEvent::generate_module_dependency_events() {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   124
  invocation_time = JfrTicks::now();
51608
625a5bdde0c5 8210155: Lock ClassLoaderDataGraph
coleenp
parents: 50113
diff changeset
   125
  MutexLocker cld_lock(ClassLoaderDataGraph_lock);
625a5bdde0c5 8210155: Lock ClassLoaderDataGraph
coleenp
parents: 50113
diff changeset
   126
  MutexLocker module_lock(Module_lock);
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   127
  ClassLoaderDataGraph::modules_do(&module_dependency_event_callback);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   128
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   129
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   130
void JfrModuleEvent::generate_module_export_events() {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   131
  invocation_time = JfrTicks::now();
51608
625a5bdde0c5 8210155: Lock ClassLoaderDataGraph
coleenp
parents: 50113
diff changeset
   132
  MutexLocker cld_lock(ClassLoaderDataGraph_lock);
625a5bdde0c5 8210155: Lock ClassLoaderDataGraph
coleenp
parents: 50113
diff changeset
   133
  MutexLocker module_lock(Module_lock);
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   134
  ClassLoaderDataGraph::packages_do(&module_export_event_callback);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   135
}