-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
8266936: Add a finalization JFR event
Reviewed-by: coleenp, mchung, egahlin
- Loading branch information
Markus Grönlund
committed
Oct 18, 2021
1 parent
bcbe384
commit 72a976e
Showing
36 changed files
with
1,508 additions
and
542 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
src/hotspot/share/jfr/periodic/jfrFinalizerStatisticsEvent.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* | ||
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
* | ||
*/ | ||
|
||
#include "precompiled.hpp" | ||
#include "utilities/macros.hpp" | ||
#if INCLUDE_MANAGEMENT | ||
#include "classfile/classLoaderDataGraph.hpp" | ||
#include "classfile/javaClasses.inline.hpp" | ||
#include "jfr/jfrEvents.hpp" | ||
#include "jfr/jni/jfrJavaSupport.hpp" | ||
#include "jfr/periodic/jfrFinalizerStatisticsEvent.hpp" | ||
#include "jfr/support/jfrSymbolTable.hpp" | ||
#include "jfr/utilities/jfrTime.hpp" | ||
#include "jfr/utilities/jfrTypes.hpp" | ||
#include "oops/instanceKlass.inline.hpp" | ||
#include "runtime/mutexLocker.hpp" | ||
#include "runtime/thread.inline.hpp" | ||
#include "services/finalizerService.hpp" | ||
|
||
static oop get_codesource(oop pd, Thread* thread) { | ||
assert(pd != NULL, "invariant"); | ||
assert(thread != NULL, "invariant"); | ||
JavaValue result(T_OBJECT); | ||
JfrJavaArguments args(&result); | ||
args.set_klass(pd->klass()); | ||
args.set_name("codesource"); | ||
args.set_signature("Ljava/security/CodeSource;"); | ||
args.set_receiver(pd); | ||
JfrJavaSupport::get_field(&args, thread); | ||
return result.get_oop(); | ||
} | ||
|
||
// Caller needs ResourceMark | ||
static const char* get_locationNoFragString(oop codesource, Thread* thread) { | ||
assert(codesource != NULL, "invariant"); | ||
assert(thread != NULL, "invariant"); | ||
JavaValue result(T_OBJECT); | ||
JfrJavaArguments args(&result); | ||
args.set_klass(codesource->klass()); | ||
args.set_name("locationNoFragString"); | ||
args.set_signature("Ljava/lang/String;"); | ||
args.set_receiver(codesource); | ||
JfrJavaSupport::get_field(&args, thread); | ||
const oop string_oop = result.get_oop(); | ||
return string_oop != NULL ? JfrJavaSupport::c_str(string_oop, thread) : NULL; | ||
} | ||
|
||
// Caller needs ResourceMark | ||
static const char* codesource(const InstanceKlass* ik, Thread* thread) { | ||
assert(ik != NULL, "invariant"); | ||
assert(thread != NULL, "invariant"); | ||
oop pd = java_lang_Class::protection_domain(ik->java_mirror()); | ||
if (pd == NULL) { | ||
return NULL; | ||
} | ||
oop codesource = get_codesource(pd, thread); | ||
return codesource != NULL ? get_locationNoFragString(codesource, thread) : NULL; | ||
} | ||
|
||
static void send_event(const FinalizerEntry* fe, const InstanceKlass* ik, const JfrTicks& timestamp, Thread* thread) { | ||
assert(ik != NULL, "invariant"); | ||
assert(ik->has_finalizer(), "invariant"); | ||
assert(thread != NULL, "invariant"); | ||
const char* const url = codesource(ik, thread); | ||
const traceid url_symbol_id = url != NULL ? JfrSymbolTable::add(url) : 0; | ||
EventFinalizerStatistics event(UNTIMED); | ||
event.set_endtime(timestamp); | ||
event.set_finalizableClass(ik); | ||
event.set_codeSource(url_symbol_id); | ||
if (fe == NULL) { | ||
event.set_objects(0); | ||
event.set_totalFinalizersRun(0); | ||
} else { | ||
assert(fe->klass() == ik, "invariant"); | ||
event.set_objects(fe->objects_on_heap()); | ||
event.set_totalFinalizersRun(fe->total_finalizers_run()); | ||
} | ||
event.commit(); | ||
} | ||
|
||
void JfrFinalizerStatisticsEvent::send_unload_event(const InstanceKlass* ik) { | ||
Thread* const thread = Thread::current(); | ||
ResourceMark rm(thread); | ||
send_event(FinalizerService::lookup(ik, thread), ik, JfrTicks::now(), thread); | ||
} | ||
|
||
// Finalizer events generated by the periodic task will all have the same timestamp. | ||
|
||
class FinalizerStatisticsEventClosure : public FinalizerEntryClosure { | ||
private: | ||
Thread* _thread; | ||
const JfrTicks _timestamp; | ||
public: | ||
FinalizerStatisticsEventClosure(Thread* thread) : _thread(thread), _timestamp(JfrTicks::now()) {} | ||
virtual bool do_entry(const FinalizerEntry* fe) { | ||
assert(fe != NULL, "invariant"); | ||
send_event(fe, fe->klass(), _timestamp, _thread); | ||
return true; | ||
} | ||
}; | ||
|
||
void JfrFinalizerStatisticsEvent::generate_events() { | ||
Thread* const thread = Thread::current(); | ||
ResourceMark rm(thread); | ||
FinalizerStatisticsEventClosure fsec(thread); | ||
MutexLocker lock(ClassLoaderDataGraph_lock); // To prevent entries from being removed by class unloading. | ||
FinalizerService::do_entries(&fsec, thread); | ||
} | ||
|
||
#endif // INCLUDE_MANAGEMENT |
38 changes: 38 additions & 0 deletions
38
src/hotspot/share/jfr/periodic/jfrFinalizerStatisticsEvent.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
* | ||
*/ | ||
|
||
#ifndef SHARE_JFR_PERIODIC_JFRFINALIZERSTATISTICSEVENT_HPP | ||
#define SHARE_JFR_PERIODIC_JFRFINALIZERSTATISTICSEVENT_HPP | ||
|
||
#include "memory/allocation.hpp" | ||
|
||
class InstanceKlass; | ||
|
||
class JfrFinalizerStatisticsEvent : AllStatic { | ||
public: | ||
static void send_unload_event(const InstanceKlass* ik) NOT_MANAGEMENT_RETURN; | ||
static void generate_events() NOT_MANAGEMENT_RETURN; | ||
}; | ||
|
||
#endif // SHARE_JFR_PERIODIC_JFRFINALIZERSTATISTICSEVENT_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
72a976e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review
Issues
72a976e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/backport jdk17u
72a976e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jbachorik Could not automatically backport
72a976ef
to openjdk/jdk17u due to conflicts in the following files:To manually resolve these conflicts run the following commands in your personal fork of openjdk/jdk17u:
Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk17u with the title
Backport 72a976ef05fc2c62657920a560a0abc60b27c852
.72a976e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/backport jdk17u-dev
72a976e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jbachorik Could not automatically backport
72a976ef
to openjdk/jdk17u-dev due to conflicts in the following files:To manually resolve these conflicts run the following commands in your personal fork of openjdk/jdk17u-dev:
Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk17u-dev with the title
Backport 72a976ef05fc2c62657920a560a0abc60b27c852
.