Skip to content

Commit

Permalink
8289524: Add JFR JIT restart event
Browse files Browse the repository at this point in the history
Reviewed-by: kvn, lucy
  • Loading branch information
MBaesken committed Jul 19, 2022
1 parent 4e6cd67 commit dfbc691
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/hotspot/share/code/codeCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,7 @@ void CodeCache::report_codemem_full(int code_blob_type, bool print) {
event.set_adaptorCount(heap->adapter_count());
event.set_unallocatedCapacity(heap->unallocated_capacity());
event.set_fullCount(heap->full_count());
event.set_codeCacheMaxCapacity(CodeCache::max_capacity());
event.commit();
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/hotspot/share/jfr/metadata/metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,11 @@
<Field type="ulong" contentType="bytes" name="used" label="Used" />
</Event>

<Event name="JitRestart" category="Java Virtual Machine, Compiler" label="JIT Restart" stackTrace="false" startTime="false" thread="true">
<Field type="int" contentType="bytes" name="freedMemory" label="Freed Memory" />
<Field type="ulong" contentType="bytes" name="codeCacheMaxCapacity" label="Code Cache Maximum Capacity" />
</Event>

<Event name="Compilation" category="Java Virtual Machine, Compiler" label="Compilation" thread="true">
<Field type="uint" name="compileId" label="Compilation Identifier" relation="CompileId" />
<Field type="CompilerType" name="compiler" label="Compiler" />
Expand Down Expand Up @@ -612,6 +617,7 @@
<Field type="int" name="adaptorCount" label="Adaptors" />
<Field type="ulong" contentType="bytes" name="unallocatedCapacity" label="Unallocated" />
<Field type="int" name="fullCount" label="Full Count" />
<Field type="ulong" contentType="bytes" name="codeCacheMaxCapacity" label="Code Cache Maximum Capacity" />
</Event>

<Event name="Deoptimization" category="Java Virtual Machine, Compiler" label="Deoptimization" thread="true" stackTrace="true" startTime="false">
Expand Down
14 changes: 9 additions & 5 deletions src/hotspot/share/runtime/sweeper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,6 @@ void NMethodSweeper::sweep_code_cache() {
_peak_sweep_time = MAX2(_peak_sweep_time, _total_time_this_sweep);
}

EventSweepCodeCache event(UNTIMED);
if (event.should_commit()) {
post_sweep_event(&event, sweep_start_counter, sweep_end_counter, (s4)_traversals, swept_count, flushed_count, zombified_count);
}

#ifdef ASSERT
if(PrintMethodFlushing) {
tty->print_cr("### sweeper: sweep time(" JLONG_FORMAT "): ", sweep_time.value());
Expand All @@ -442,6 +437,15 @@ void NMethodSweeper::sweep_code_cache() {
CompileBroker::set_should_compile_new_jobs(CompileBroker::run_compilation);
log.debug("restart compiler");
log_sweep("restart_compiler");
EventJitRestart event;
event.set_freedMemory(freed_memory);
event.set_codeCacheMaxCapacity(CodeCache::max_capacity());
event.commit();
}

EventSweepCodeCache event(UNTIMED);
if (event.should_commit()) {
post_sweep_event(&event, sweep_start_counter, sweep_end_counter, (s4)_traversals, swept_count, flushed_count, zombified_count);
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/jdk.jfr/share/conf/jfr/default.jfc
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,10 @@
<setting name="enabled" control="compiler-enabled-failure">false</setting>
</event>

<event name="jdk.JitRestart">
<setting name="enabled" control="compiler-enabled">true</setting>
</event>

<event name="jdk.CodeSweeperConfiguration">
<setting name="enabled" control="compiler-enabled">true</setting>
<setting name="period">beginChunk</setting>
Expand Down
4 changes: 4 additions & 0 deletions src/jdk.jfr/share/conf/jfr/profile.jfc
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,10 @@
<setting name="enabled" control="compiler-enabled-failure">false</setting>
</event>

<event name="jdk.JitRestart">
<setting name="enabled" control="compiler-enabled">true</setting>
</event>

<event name="jdk.CodeSweeperConfiguration">
<setting name="enabled" control="compiler-enabled">true</setting>
<setting name="period">beginChunk</setting>
Expand Down
1 change: 1 addition & 0 deletions test/jdk/jdk/jfr/event/compiler/TestCodeCacheFull.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ private static void testWithBlobType(BlobType btype, long availableSize) throws
Events.assertField(event, "startAddress").notEqual(0L);
Events.assertField(event, "commitedTopAddress").notEqual(0L);
Events.assertField(event, "reservedTopAddress").notEqual(0L);
Events.assertField(event, "codeCacheMaxCapacity").notEqual(0L);
}

private static BlobType blobTypeFromName(String codeBlobTypeName) throws Exception {
Expand Down
103 changes: 103 additions & 0 deletions test/jdk/jdk/jfr/event/compiler/TestJitRestart.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Copyright (c) 2013, 2022, 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.
*/

package jdk.jfr.event.compiler;

import java.util.List;

import jdk.jfr.Recording;
import jdk.jfr.consumer.RecordedEvent;
import jdk.test.lib.Asserts;
import jdk.test.lib.jfr.EventNames;
import jdk.test.lib.jfr.Events;
import jdk.test.whitebox.WhiteBox;
import jdk.test.whitebox.code.BlobType;

/**
* @test TestJitRestart
* @requires vm.hasJFR
*
* @library /test/lib
* @modules jdk.jfr
* jdk.management.jfr
* @build jdk.test.whitebox.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
*
* @run main/othervm -Xbootclasspath/a:.
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
* -XX:+SegmentedCodeCache -XX:-UseLargePages jdk.jfr.event.compiler.TestJitRestart
*/
public class TestJitRestart {

public static void main(String[] args) throws Exception {
boolean foundJitRestart = false;
for (BlobType btype : BlobType.getAvailable()) {
boolean jr = testWithBlobType(btype, calculateAvailableSize(btype));
if (jr) {
System.out.println("JIT restart event found for BlobType " + btype);
foundJitRestart = true;
}
}
Asserts.assertTrue(foundJitRestart, "No JIT restart event found");
}

private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();

private static boolean testWithBlobType(BlobType btype, long availableSize) throws Exception {
Recording r = new Recording();
r.enable(EventNames.CodeCacheFull);
r.enable(EventNames.JitRestart);
r.start();
long addr = WHITE_BOX.allocateCodeBlob(availableSize, btype.id);
WHITE_BOX.freeCodeBlob(addr);
WHITE_BOX.forceNMethodSweep();
r.stop();

List<RecordedEvent> events = Events.fromRecording(r);
System.out.println("# events:" + events.size());
Events.hasEvents(events);

for (RecordedEvent evt: events) {
System.out.println(evt);
if (evt.getEventType().getName().equals("jdk.JitRestart")) {
Events.assertField(evt, "codeCacheMaxCapacity").notEqual(0L);
Events.assertField(evt, "freedMemory").notEqual(0L);
return true;
}
}
return false;
}

// Compute the available size for this BlobType by taking into account
// that it may be stored in a different code heap in case it does not fit
// into the current one.
private static long calculateAvailableSize(BlobType btype) {
long availableSize = btype.getSize();
for (BlobType alternative : BlobType.getAvailable()) {
if (btype.allowTypeWhenOverflow(alternative)) {
availableSize = Math.max(availableSize, alternative.getSize());
}
}
return availableSize;
}
}
1 change: 1 addition & 0 deletions test/lib/jdk/test/lib/jfr/EventNames.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ public class EventNames {
public final static String ObjectAllocationOutsideTLAB = PREFIX + "ObjectAllocationOutsideTLAB";
public final static String ObjectAllocationSample = PREFIX + "ObjectAllocationSample";
public final static String Deoptimization = PREFIX + "Deoptimization";
public final static String JitRestart = PREFIX + "JitRestart";

// OS
public final static String OSInformation = PREFIX + "OSInformation";
Expand Down

3 comments on commit dfbc691

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MBaesken
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on dfbc691 Oct 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MBaesken Could not automatically backport dfbc6919 to openjdk/jdk17u-dev due to conflicts in the following files:

  • src/hotspot/share/jfr/metadata/metadata.xml

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk17u-dev. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk17u-dev master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b MBaesken-backport-dfbc6919

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk dfbc6919e1e233b42aede97f1323ce5529fab7cf

# Backport the commit
$ git cherry-pick --no-commit dfbc6919e1e233b42aede97f1323ce5529fab7cf
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport dfbc6919e1e233b42aede97f1323ce5529fab7cf'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk17u-dev with the title Backport dfbc6919e1e233b42aede97f1323ce5529fab7cf.

Please sign in to comment.