8289524: Add JFR JIT restart event

Reviewed-by: kvn, lucy
This commit is contained in:
Matthias Baesken 2022-07-19 07:07:41 +00:00
parent 4e6cd67fec
commit dfbc6919e1
8 changed files with 129 additions and 5 deletions
src
hotspot/share
jdk.jfr/share/conf/jfr
test
jdk/jdk/jfr/event/compiler
lib/jdk/test/lib/jfr

@ -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();
}
}

@ -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" />
@ -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">

@ -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());
@ -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);
}
}

@ -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>

@ -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>

@ -79,6 +79,7 @@ public class TestCodeCacheFull {
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 {

@ -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;
}
}

@ -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";