From e370e14abf2ee25019ed13cde9edfa24047d982d Mon Sep 17 00:00:00 2001 From: tstuefe Date: Fri, 14 Feb 2025 15:47:03 +0100 Subject: [PATCH 1/4] start --- src/hotspot/share/c1/c1_Compilation.cpp | 4 ++-- src/hotspot/share/c1/c1_Compilation.hpp | 2 ++ src/hotspot/share/ci/ciEnv.cpp | 16 ++++++++++++++++ src/hotspot/share/ci/ciEnv.hpp | 6 +++++- src/hotspot/share/opto/compile.cpp | 4 ++-- src/hotspot/share/opto/compile.hpp | 4 +++- 6 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/hotspot/share/c1/c1_Compilation.cpp b/src/hotspot/share/c1/c1_Compilation.cpp index 9b80c8a20a852..f089a1f5a177b 100644 --- a/src/hotspot/share/c1/c1_Compilation.cpp +++ b/src/hotspot/share/c1/c1_Compilation.cpp @@ -592,7 +592,7 @@ Compilation::Compilation(AbstractCompiler* compiler, ciEnv* env, ciMethod* metho #endif // PRODUCT { _arena = Thread::current()->resource_area(); - _env->set_compiler_data(this); + _env->set_compiler_data(this, CompilerType::compiler_c1); _exception_info_list = new ExceptionInfoList(); _implicit_exception_table.set_size(0); PhaseTraceTime timeit(_t_compile); @@ -624,7 +624,7 @@ Compilation::~Compilation() { // simulate crash during compilation assert(CICrashAt < 0 || (uintx)_env->compile_id() != (uintx)CICrashAt, "just as planned"); delete _first_failure_details; - _env->set_compiler_data(nullptr); + _env->set_compiler_data(nullptr, CompilerType::compiler_none); } void Compilation::add_exception_handlers_for_pco(int pco, XHandlers* exception_handlers) { diff --git a/src/hotspot/share/c1/c1_Compilation.hpp b/src/hotspot/share/c1/c1_Compilation.hpp index dab584ac3b084..fc8d8ae4c15ea 100644 --- a/src/hotspot/share/c1/c1_Compilation.hpp +++ b/src/hotspot/share/c1/c1_Compilation.hpp @@ -32,6 +32,7 @@ #include "compiler/compilerDefinitions.inline.hpp" #include "compiler/compilerDirectives.hpp" #include "runtime/deoptimization.hpp" +#include "utilities/debug.hpp" class CompilationFailureInfo; class CompilationResourceObj; @@ -130,6 +131,7 @@ class Compilation: public StackObj { static Compilation* current() { + DEBUG_ONLY(ciEnv::current()->check_compiler_data_c1_or_null();) return (Compilation*) ciEnv::current()->compiler_data(); } diff --git a/src/hotspot/share/ci/ciEnv.cpp b/src/hotspot/share/ci/ciEnv.cpp index e87c5ba08e95e..689e23290e6c2 100644 --- a/src/hotspot/share/ci/ciEnv.cpp +++ b/src/hotspot/share/ci/ciEnv.cpp @@ -119,6 +119,7 @@ ciEnv::ciEnv(CompileTask* task) _inc_decompile_count_on_failure = true; _compilable = MethodCompilable; _break_at_compile = false; + _compiler_data_type = CompilerType::compiler_none; _compiler_data = nullptr; #ifndef PRODUCT assert(!firstEnv, "not initialized properly"); @@ -253,6 +254,7 @@ ciEnv::ciEnv(Arena* arena) : _ciEnv_arena(mtCompiler) { _inc_decompile_count_on_failure = true; _compilable = MethodCompilable_never; _break_at_compile = false; + _compiler_data_type = CompilerType::compiler_none; _compiler_data = nullptr; #ifndef PRODUCT assert(firstEnv, "must be first"); @@ -1155,6 +1157,20 @@ int ciEnv::compile_id() { return task()->compile_id(); } +void ciEnv::set_compiler_data(void* x, CompilerType type) { + _compiler_data = x; + _compiler_data_type = type; +} + +#ifdef ASSERT +void ciEnv::check_compiler_data_c1_or_null() const { + assert(_compiler_data == nullptr || _compiler_data_type == CompilerType::compiler_c1, "Not C1 data"); +} +void ciEnv::check_compiler_data_c2_or_null() const { + assert(_compiler_data == nullptr || _compiler_data_type == CompilerType::compiler_c2, "Not C2 data"); +} +#endif + // ------------------------------------------------------------------ // ciEnv::notice_inlined_method() void ciEnv::notice_inlined_method(ciMethod* method) { diff --git a/src/hotspot/share/ci/ciEnv.hpp b/src/hotspot/share/ci/ciEnv.hpp index 6c66633ee1749..2924574e6b8a6 100644 --- a/src/hotspot/share/ci/ciEnv.hpp +++ b/src/hotspot/share/ci/ciEnv.hpp @@ -32,6 +32,7 @@ #include "code/dependencies.hpp" #include "code/exceptionHandlerTable.hpp" #include "compiler/compiler_globals.hpp" +#include "compiler/compilerDefinitions.hpp" #include "compiler/compilerThread.hpp" #include "compiler/cHeapStringHolder.hpp" #include "oops/methodData.hpp" @@ -65,6 +66,7 @@ class ciEnv : StackObj { int _num_inlined_bytecodes; CompileTask* _task; // faster access to CompilerThread::task CompileLog* _log; // faster access to CompilerThread::log + CompilerType _compiler_data_type; void* _compiler_data; // compiler-specific stuff, if any char* _name_buffer; @@ -447,7 +449,9 @@ class ciEnv : StackObj { // Per-compiler data. (Used by C2 to publish the Compile* pointer.) void* compiler_data() const { return _compiler_data; } - void set_compiler_data(void* x) { _compiler_data = x; } + void set_compiler_data(void* x, CompilerType type); + DEBUG_ONLY(void check_compiler_data_c1_or_null() const;) + DEBUG_ONLY(void check_compiler_data_c2_or_null() const;) // Notice that a method has been inlined in the current compile; // used only for statistics. diff --git a/src/hotspot/share/opto/compile.cpp b/src/hotspot/share/opto/compile.cpp index 7a03ac418a892..70d43953a4921 100644 --- a/src/hotspot/share/opto/compile.cpp +++ b/src/hotspot/share/opto/compile.cpp @@ -482,7 +482,7 @@ CompileWrapper::CompileWrapper(Compile* compile) : _compile(compile) { ciEnv* env = compile->env(); assert(env == ciEnv::current(), "must already be a ciEnv active"); assert(env->compiler_data() == nullptr, "compile already active?"); - env->set_compiler_data(compile); + env->set_compiler_data(compile, CompilerType::compiler_c2); assert(compile == Compile::current(), "sanity"); compile->set_type_dict(nullptr); @@ -502,7 +502,7 @@ CompileWrapper::~CompileWrapper() { assert(CICrashAt < 0 || _compile->compile_id() != CICrashAt, "just as planned"); _compile->end_method(); - _compile->env()->set_compiler_data(nullptr); + _compile->env()->set_compiler_data(nullptr, CompilerType::compiler_none); } diff --git a/src/hotspot/share/opto/compile.hpp b/src/hotspot/share/opto/compile.hpp index 9325289120704..62a31fc6a5860 100644 --- a/src/hotspot/share/opto/compile.hpp +++ b/src/hotspot/share/opto/compile.hpp @@ -39,14 +39,15 @@ #include "opto/idealGraphPrinter.hpp" #include "opto/phasetype.hpp" #include "opto/phase.hpp" +#include "opto/printinlining.hpp" #include "opto/regmask.hpp" #include "runtime/deoptimization.hpp" #include "runtime/sharedRuntime.hpp" #include "runtime/timerTrace.hpp" #include "runtime/vmThread.hpp" +#include "utilities/debug.hpp" #include "utilities/ticks.hpp" #include "utilities/vmEnums.hpp" -#include "opto/printinlining.hpp" class AbstractLockNode; class AddPNode; @@ -530,6 +531,7 @@ class Compile : public Phase { // The Compile instance currently active in this (compiler) thread. static Compile* current() { + DEBUG_ONLY(ciEnv::current()->check_compiler_data_c2_or_null();) return (Compile*) ciEnv::current()->compiler_data(); } From a103b4552304d57bd64fb0d19a70652aeed6aa66 Mon Sep 17 00:00:00 2001 From: tstuefe Date: Fri, 14 Feb 2025 15:50:20 +0100 Subject: [PATCH 2/4] copyrights --- src/hotspot/share/ci/ciEnv.hpp | 2 +- src/hotspot/share/opto/compile.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hotspot/share/ci/ciEnv.hpp b/src/hotspot/share/ci/ciEnv.hpp index 2924574e6b8a6..f1b6df98d474e 100644 --- a/src/hotspot/share/ci/ciEnv.hpp +++ b/src/hotspot/share/ci/ciEnv.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2025, 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 diff --git a/src/hotspot/share/opto/compile.hpp b/src/hotspot/share/opto/compile.hpp index 62a31fc6a5860..2f815f2da40cd 100644 --- a/src/hotspot/share/opto/compile.hpp +++ b/src/hotspot/share/opto/compile.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2025, 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 From b77e1f36848def10fcdb5768b1a136772497e137 Mon Sep 17 00:00:00 2001 From: tstuefe Date: Sat, 15 Feb 2025 07:21:39 +0100 Subject: [PATCH 3/4] Revert "start" This reverts commit e370e14abf2ee25019ed13cde9edfa24047d982d. --- src/hotspot/share/c1/c1_Compilation.cpp | 4 ++-- src/hotspot/share/c1/c1_Compilation.hpp | 2 -- src/hotspot/share/ci/ciEnv.cpp | 16 ---------------- src/hotspot/share/ci/ciEnv.hpp | 8 ++------ src/hotspot/share/opto/compile.cpp | 4 ++-- src/hotspot/share/opto/compile.hpp | 4 +--- 6 files changed, 7 insertions(+), 31 deletions(-) diff --git a/src/hotspot/share/c1/c1_Compilation.cpp b/src/hotspot/share/c1/c1_Compilation.cpp index f089a1f5a177b..9b80c8a20a852 100644 --- a/src/hotspot/share/c1/c1_Compilation.cpp +++ b/src/hotspot/share/c1/c1_Compilation.cpp @@ -592,7 +592,7 @@ Compilation::Compilation(AbstractCompiler* compiler, ciEnv* env, ciMethod* metho #endif // PRODUCT { _arena = Thread::current()->resource_area(); - _env->set_compiler_data(this, CompilerType::compiler_c1); + _env->set_compiler_data(this); _exception_info_list = new ExceptionInfoList(); _implicit_exception_table.set_size(0); PhaseTraceTime timeit(_t_compile); @@ -624,7 +624,7 @@ Compilation::~Compilation() { // simulate crash during compilation assert(CICrashAt < 0 || (uintx)_env->compile_id() != (uintx)CICrashAt, "just as planned"); delete _first_failure_details; - _env->set_compiler_data(nullptr, CompilerType::compiler_none); + _env->set_compiler_data(nullptr); } void Compilation::add_exception_handlers_for_pco(int pco, XHandlers* exception_handlers) { diff --git a/src/hotspot/share/c1/c1_Compilation.hpp b/src/hotspot/share/c1/c1_Compilation.hpp index fc8d8ae4c15ea..dab584ac3b084 100644 --- a/src/hotspot/share/c1/c1_Compilation.hpp +++ b/src/hotspot/share/c1/c1_Compilation.hpp @@ -32,7 +32,6 @@ #include "compiler/compilerDefinitions.inline.hpp" #include "compiler/compilerDirectives.hpp" #include "runtime/deoptimization.hpp" -#include "utilities/debug.hpp" class CompilationFailureInfo; class CompilationResourceObj; @@ -131,7 +130,6 @@ class Compilation: public StackObj { static Compilation* current() { - DEBUG_ONLY(ciEnv::current()->check_compiler_data_c1_or_null();) return (Compilation*) ciEnv::current()->compiler_data(); } diff --git a/src/hotspot/share/ci/ciEnv.cpp b/src/hotspot/share/ci/ciEnv.cpp index 689e23290e6c2..e87c5ba08e95e 100644 --- a/src/hotspot/share/ci/ciEnv.cpp +++ b/src/hotspot/share/ci/ciEnv.cpp @@ -119,7 +119,6 @@ ciEnv::ciEnv(CompileTask* task) _inc_decompile_count_on_failure = true; _compilable = MethodCompilable; _break_at_compile = false; - _compiler_data_type = CompilerType::compiler_none; _compiler_data = nullptr; #ifndef PRODUCT assert(!firstEnv, "not initialized properly"); @@ -254,7 +253,6 @@ ciEnv::ciEnv(Arena* arena) : _ciEnv_arena(mtCompiler) { _inc_decompile_count_on_failure = true; _compilable = MethodCompilable_never; _break_at_compile = false; - _compiler_data_type = CompilerType::compiler_none; _compiler_data = nullptr; #ifndef PRODUCT assert(firstEnv, "must be first"); @@ -1157,20 +1155,6 @@ int ciEnv::compile_id() { return task()->compile_id(); } -void ciEnv::set_compiler_data(void* x, CompilerType type) { - _compiler_data = x; - _compiler_data_type = type; -} - -#ifdef ASSERT -void ciEnv::check_compiler_data_c1_or_null() const { - assert(_compiler_data == nullptr || _compiler_data_type == CompilerType::compiler_c1, "Not C1 data"); -} -void ciEnv::check_compiler_data_c2_or_null() const { - assert(_compiler_data == nullptr || _compiler_data_type == CompilerType::compiler_c2, "Not C2 data"); -} -#endif - // ------------------------------------------------------------------ // ciEnv::notice_inlined_method() void ciEnv::notice_inlined_method(ciMethod* method) { diff --git a/src/hotspot/share/ci/ciEnv.hpp b/src/hotspot/share/ci/ciEnv.hpp index f1b6df98d474e..6c66633ee1749 100644 --- a/src/hotspot/share/ci/ciEnv.hpp +++ b/src/hotspot/share/ci/ciEnv.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -32,7 +32,6 @@ #include "code/dependencies.hpp" #include "code/exceptionHandlerTable.hpp" #include "compiler/compiler_globals.hpp" -#include "compiler/compilerDefinitions.hpp" #include "compiler/compilerThread.hpp" #include "compiler/cHeapStringHolder.hpp" #include "oops/methodData.hpp" @@ -66,7 +65,6 @@ class ciEnv : StackObj { int _num_inlined_bytecodes; CompileTask* _task; // faster access to CompilerThread::task CompileLog* _log; // faster access to CompilerThread::log - CompilerType _compiler_data_type; void* _compiler_data; // compiler-specific stuff, if any char* _name_buffer; @@ -449,9 +447,7 @@ class ciEnv : StackObj { // Per-compiler data. (Used by C2 to publish the Compile* pointer.) void* compiler_data() const { return _compiler_data; } - void set_compiler_data(void* x, CompilerType type); - DEBUG_ONLY(void check_compiler_data_c1_or_null() const;) - DEBUG_ONLY(void check_compiler_data_c2_or_null() const;) + void set_compiler_data(void* x) { _compiler_data = x; } // Notice that a method has been inlined in the current compile; // used only for statistics. diff --git a/src/hotspot/share/opto/compile.cpp b/src/hotspot/share/opto/compile.cpp index 70d43953a4921..7a03ac418a892 100644 --- a/src/hotspot/share/opto/compile.cpp +++ b/src/hotspot/share/opto/compile.cpp @@ -482,7 +482,7 @@ CompileWrapper::CompileWrapper(Compile* compile) : _compile(compile) { ciEnv* env = compile->env(); assert(env == ciEnv::current(), "must already be a ciEnv active"); assert(env->compiler_data() == nullptr, "compile already active?"); - env->set_compiler_data(compile, CompilerType::compiler_c2); + env->set_compiler_data(compile); assert(compile == Compile::current(), "sanity"); compile->set_type_dict(nullptr); @@ -502,7 +502,7 @@ CompileWrapper::~CompileWrapper() { assert(CICrashAt < 0 || _compile->compile_id() != CICrashAt, "just as planned"); _compile->end_method(); - _compile->env()->set_compiler_data(nullptr, CompilerType::compiler_none); + _compile->env()->set_compiler_data(nullptr); } diff --git a/src/hotspot/share/opto/compile.hpp b/src/hotspot/share/opto/compile.hpp index 2f815f2da40cd..59a190bda7a52 100644 --- a/src/hotspot/share/opto/compile.hpp +++ b/src/hotspot/share/opto/compile.hpp @@ -39,15 +39,14 @@ #include "opto/idealGraphPrinter.hpp" #include "opto/phasetype.hpp" #include "opto/phase.hpp" -#include "opto/printinlining.hpp" #include "opto/regmask.hpp" #include "runtime/deoptimization.hpp" #include "runtime/sharedRuntime.hpp" #include "runtime/timerTrace.hpp" #include "runtime/vmThread.hpp" -#include "utilities/debug.hpp" #include "utilities/ticks.hpp" #include "utilities/vmEnums.hpp" +#include "opto/printinlining.hpp" class AbstractLockNode; class AddPNode; @@ -531,7 +530,6 @@ class Compile : public Phase { // The Compile instance currently active in this (compiler) thread. static Compile* current() { - DEBUG_ONLY(ciEnv::current()->check_compiler_data_c2_or_null();) return (Compile*) ciEnv::current()->compiler_data(); } From b4b1bbd3c0e2d21e6959f0dab604bcf14c196f63 Mon Sep 17 00:00:00 2001 From: tstuefe Date: Sat, 15 Feb 2025 08:11:38 +0100 Subject: [PATCH 4/4] redo --- src/hotspot/share/c1/c1_Compilation.cpp | 8 ++++++++ src/hotspot/share/c1/c1_Compilation.hpp | 3 +++ src/hotspot/share/opto/compile.cpp | 8 ++++++++ src/hotspot/share/opto/compile.hpp | 3 +++ 4 files changed, 22 insertions(+) diff --git a/src/hotspot/share/c1/c1_Compilation.cpp b/src/hotspot/share/c1/c1_Compilation.cpp index 9b80c8a20a852..163911ab82953 100644 --- a/src/hotspot/share/c1/c1_Compilation.cpp +++ b/src/hotspot/share/c1/c1_Compilation.cpp @@ -32,6 +32,7 @@ #include "c1/c1_ValueMap.hpp" #include "c1/c1_ValueStack.hpp" #include "code/debugInfoRec.hpp" +#include "compiler/abstractCompiler.hpp" #include "compiler/compilationFailureInfo.hpp" #include "compiler/compilationMemoryStatistic.hpp" #include "compiler/compilerDirectives.hpp" @@ -42,6 +43,7 @@ #include "memory/resourceArea.hpp" #include "runtime/sharedRuntime.hpp" #include "runtime/timerTrace.hpp" +#include "utilities/debug.hpp" typedef enum { _t_compile, @@ -734,3 +736,9 @@ Interval* find_interval(int reg_num) { } #endif // NOT PRODUCT + +#ifdef ASSERT +void Compilation::check_current_compiler_c1() { + assert(CompilerThread::current()->compiler()->is_c1(), "Not on C1"); +} +#endif // ASSERT diff --git a/src/hotspot/share/c1/c1_Compilation.hpp b/src/hotspot/share/c1/c1_Compilation.hpp index dab584ac3b084..709e878af680f 100644 --- a/src/hotspot/share/c1/c1_Compilation.hpp +++ b/src/hotspot/share/c1/c1_Compilation.hpp @@ -122,6 +122,8 @@ class Compilation: public StackObj { CFGPrinterOutput* _cfg_printer_output; #endif // PRODUCT + static void check_current_compiler_c1() NOT_DEBUG({}); + public: // creation Compilation(AbstractCompiler* compiler, ciEnv* env, ciMethod* method, @@ -130,6 +132,7 @@ class Compilation: public StackObj { static Compilation* current() { + check_current_compiler_c1(); return (Compilation*) ciEnv::current()->compiler_data(); } diff --git a/src/hotspot/share/opto/compile.cpp b/src/hotspot/share/opto/compile.cpp index 7a03ac418a892..741840c6ff3c2 100644 --- a/src/hotspot/share/opto/compile.cpp +++ b/src/hotspot/share/opto/compile.cpp @@ -28,6 +28,7 @@ #include "classfile/javaClasses.hpp" #include "code/exceptionHandlerTable.hpp" #include "code/nmethod.hpp" +#include "compiler/abstractCompiler.hpp" #include "compiler/compilationFailureInfo.hpp" #include "compiler/compilationMemoryStatistic.hpp" #include "compiler/compileBroker.hpp" @@ -83,6 +84,7 @@ #include "runtime/timer.hpp" #include "utilities/align.hpp" #include "utilities/copy.hpp" +#include "utilities/debug.hpp" #include "utilities/macros.hpp" #include "utilities/resourceHash.hpp" @@ -5209,3 +5211,9 @@ Node* Compile::narrow_value(BasicType bt, Node* value, const Type* type, PhaseGV void Compile::record_method_not_compilable_oom() { record_method_not_compilable(CompilationMemoryStatistic::failure_reason_memlimit()); } + +#ifdef ASSERT +void Compile::check_current_compiler_c2() { + assert(CompilerThread::current()->compiler()->is_c2(), "Not on C2"); +} +#endif // ASSERT diff --git a/src/hotspot/share/opto/compile.hpp b/src/hotspot/share/opto/compile.hpp index 59a190bda7a52..b0319886e27e8 100644 --- a/src/hotspot/share/opto/compile.hpp +++ b/src/hotspot/share/opto/compile.hpp @@ -491,6 +491,8 @@ class Compile : public Phase { InlinePrinter _inline_printer; + static void check_current_compiler_c2() NOT_DEBUG({}}); + public: void* barrier_set_state() const { return _barrier_set_state; } @@ -530,6 +532,7 @@ class Compile : public Phase { // The Compile instance currently active in this (compiler) thread. static Compile* current() { + check_current_compiler_c2(); return (Compile*) ciEnv::current()->compiler_data(); }