From 151ef5d4d261c9fc740d3ccd64a70d3b9ccc1ab5 Mon Sep 17 00:00:00 2001 From: Thomas Stuefe Date: Mon, 29 Apr 2024 10:58:07 +0000 Subject: [PATCH] 8330677: Add Per-Compilation memory usage to JFR Reviewed-by: kvn, mbaesken --- .../share/compiler/compilationMemoryStatistic.cpp | 14 +++++++++----- src/hotspot/share/compiler/compileBroker.cpp | 3 ++- src/hotspot/share/compiler/compileTask.cpp | 3 ++- src/hotspot/share/compiler/compileTask.hpp | 6 +++++- src/hotspot/share/compiler/compilerEvent.cpp | 7 +++++-- src/hotspot/share/compiler/compilerEvent.hpp | 6 ++++-- src/hotspot/share/jfr/metadata/metadata.xml | 1 + .../jfr/event/compiler/TestCompilerCompile.java | 2 ++ 8 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/hotspot/share/compiler/compilationMemoryStatistic.cpp b/src/hotspot/share/compiler/compilationMemoryStatistic.cpp index 2cf8efa23c3..ae3c2c75fdb 100644 --- a/src/hotspot/share/compiler/compilationMemoryStatistic.cpp +++ b/src/hotspot/share/compiler/compilationMemoryStatistic.cpp @@ -1,6 +1,6 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2023, Red Hat, Inc. and/or its affiliates. + * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2024, Red Hat, Inc. and/or its affiliates. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -394,16 +394,20 @@ void CompilationMemoryStatistic::on_end_compilation() { ResourceMark rm; CompilerThread* const th = Thread::current()->as_Compiler_thread(); ArenaStatCounter* const arena_stat = th->arena_stat(); - const CompilerType ct = th->task()->compiler()->type(); + CompileTask* const task = th->task(); + const CompilerType ct = task->compiler()->type(); const Method* const m = th->task()->method(); FullMethodName fmn(m); fmn.make_permanent(); const DirectiveSet* directive = th->task()->directive(); - assert(directive->should_collect_memstat(), "Only call if memstat is enabled"); + assert(directive->should_collect_memstat(), "Should only be called if memstat is enabled for this method"); const bool print = directive->should_print_memstat(); + // Store memory used in task, for later processing by JFR + task->set_arena_bytes(arena_stat->peak_since_start()); + // Store result // For this to work, we must call on_end_compilation() at a point where // Compile|Compilation already handed over the failure string to ciEnv, @@ -492,7 +496,7 @@ void CompilationMemoryStatistic::on_arena_change(ssize_t diff, const Arena* aren CompilerType ct = compiler_none; // get some more info - const CompileTask* task = th->task(); + const CompileTask* const task = th->task(); if (task != nullptr) { ct = task->compiler()->type(); const DirectiveSet* directive = task->directive(); diff --git a/src/hotspot/share/compiler/compileBroker.cpp b/src/hotspot/share/compiler/compileBroker.cpp index 82f0996bc60..0935ea6a8e1 100644 --- a/src/hotspot/share/compiler/compileBroker.cpp +++ b/src/hotspot/share/compiler/compileBroker.cpp @@ -2126,7 +2126,8 @@ static void post_compilation_event(EventCompilation& event, CompileTask* task) { task->is_success(), task->osr_bci() != CompileBroker::standard_entry_bci, task->nm_total_size(), - task->num_inlined_bytecodes()); + task->num_inlined_bytecodes(), + task->arena_bytes()); } int DirectivesStack::_depth = 0; diff --git a/src/hotspot/share/compiler/compileTask.cpp b/src/hotspot/share/compiler/compileTask.cpp index 4690cd5c134..1a2af572166 100644 --- a/src/hotspot/share/compiler/compileTask.cpp +++ b/src/hotspot/share/compiler/compileTask.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2024, 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 @@ -123,6 +123,7 @@ void CompileTask::initialize(int compile_id, _nm_total_size = 0; _failure_reason = nullptr; _failure_reason_on_C_heap = false; + _arena_bytes = 0; if (LogCompilation) { if (hot_method.not_null()) { diff --git a/src/hotspot/share/compiler/compileTask.hpp b/src/hotspot/share/compiler/compileTask.hpp index fabfb8e0487..137e9843c35 100644 --- a/src/hotspot/share/compiler/compileTask.hpp +++ b/src/hotspot/share/compiler/compileTask.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2024, 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 @@ -114,6 +114,7 @@ class CompileTask : public CHeapObj { const char* _failure_reason; // Specifies if _failure_reason is on the C heap. bool _failure_reason_on_C_heap; + size_t _arena_bytes; // peak size of temporary memory during compilation (e.g. node arenas) public: CompileTask() : _failure_reason(nullptr), _failure_reason_on_C_heap(false) { @@ -200,6 +201,9 @@ class CompileTask : public CHeapObj { void metadata_do(MetadataClosure* f); void mark_on_stack(); + void set_arena_bytes(size_t s) { _arena_bytes = s; } + size_t arena_bytes() const { return _arena_bytes; } + private: static void print_impl(outputStream* st, Method* method, int compile_id, int comp_level, bool is_osr_method = false, int osr_bci = -1, bool is_blocking = false, diff --git a/src/hotspot/share/compiler/compilerEvent.cpp b/src/hotspot/share/compiler/compilerEvent.cpp index 0e14f62a468..d2f6e7ba886 100644 --- a/src/hotspot/share/compiler/compilerEvent.cpp +++ b/src/hotspot/share/compiler/compilerEvent.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2024, 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 @@ -134,7 +134,9 @@ static inline void commit(EventType& event) { } } -void CompilerEvent::CompilationEvent::post(EventCompilation& event, int compile_id, CompilerType compiler_type, Method* method, int compile_level, bool success, bool is_osr, int code_size, int inlined_bytecodes) { +void CompilerEvent::CompilationEvent::post(EventCompilation& event, int compile_id, CompilerType compiler_type, Method* method, + int compile_level, bool success, bool is_osr, int code_size, + int inlined_bytecodes, size_t arenaBytes) { event.set_compileId(compile_id); event.set_compiler(compiler_type); event.set_method(method); @@ -143,6 +145,7 @@ void CompilerEvent::CompilationEvent::post(EventCompilation& event, int compile_ event.set_isOsr(is_osr); event.set_codeSize(code_size); event.set_inlinedBytes(inlined_bytecodes); + event.set_arenaBytes(arenaBytes); commit(event); } diff --git a/src/hotspot/share/compiler/compilerEvent.hpp b/src/hotspot/share/compiler/compilerEvent.hpp index d2ffd8fe2d4..aaebe86b5dc 100644 --- a/src/hotspot/share/compiler/compilerEvent.hpp +++ b/src/hotspot/share/compiler/compilerEvent.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2024, 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 @@ -52,7 +52,9 @@ class CompilerEvent : AllStatic { class CompilationEvent : AllStatic { public: - static void post(EventCompilation& event, int compile_id, CompilerType type, Method* method, int compile_level, bool success, bool is_osr, int code_size, int inlined_bytecodes) NOT_JFR_RETURN(); + static void post(EventCompilation& event, int compile_id, CompilerType type, Method* method, + int compile_level, bool success, bool is_osr, int code_size, + int inlined_bytecodes, size_t arenaBytes) NOT_JFR_RETURN(); }; class CompilationFailureEvent : AllStatic { diff --git a/src/hotspot/share/jfr/metadata/metadata.xml b/src/hotspot/share/jfr/metadata/metadata.xml index 42facf56217..0ebfdd9210c 100644 --- a/src/hotspot/share/jfr/metadata/metadata.xml +++ b/src/hotspot/share/jfr/metadata/metadata.xml @@ -608,6 +608,7 @@ +