From 7652f9811bfddf08650b0c3277012074873deade Mon Sep 17 00:00:00 2001 From: Vladimir Ivanov Date: Mon, 20 May 2024 17:56:44 +0000 Subject: [PATCH] 8331885: C2: meet between unloaded and speculative types is not symmetric Reviewed-by: roland, thartmann --- src/hotspot/share/opto/type.cpp | 20 +++++++++++-------- src/hotspot/share/opto/type.hpp | 1 + .../runtime/unloaded/TestMHUnloaded.java | 7 +++++++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/hotspot/share/opto/type.cpp b/src/hotspot/share/opto/type.cpp index 70b2c705cd3..690107f169c 100644 --- a/src/hotspot/share/opto/type.cpp +++ b/src/hotspot/share/opto/type.cpp @@ -4180,24 +4180,24 @@ const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst, const T // assert(loaded->ptr() != TypePtr::Null, "insanity check"); // - if (loaded->ptr() == TypePtr::TopPTR) { return unloaded; } + if (loaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); } else if (loaded->ptr() == TypePtr::AnyNull) { return make(ptr, unloaded->klass(), interfaces, false, nullptr, off, instance_id, speculative, depth); } - else if (loaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM; } + else if (loaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM->with_speculative(speculative); } else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) { - if (unloaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM; } - else { return TypeInstPtr::NOTNULL; } + if (unloaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM->with_speculative(speculative); } + else { return TypeInstPtr::NOTNULL->with_speculative(speculative); } } - else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded; } + else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); } - return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr(); + return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr()->with_speculative(speculative); } // Both are unloaded, not the same class, not Object // Or meet unloaded with a different loaded class, not java/lang/Object if (ptr != TypePtr::BotPTR) { - return TypeInstPtr::NOTNULL; + return TypeInstPtr::NOTNULL->with_speculative(speculative); } - return TypeInstPtr::BOTTOM; + return TypeInstPtr::BOTTOM->with_speculative(speculative); } @@ -4600,6 +4600,10 @@ const TypeInstPtr* TypeInstPtr::remove_speculative() const { _instance_id, nullptr, _inline_depth); } +const TypeInstPtr* TypeInstPtr::with_speculative(const TypePtr* speculative) const { + return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _instance_id, speculative, _inline_depth); +} + const TypePtr* TypeInstPtr::with_inline_depth(int depth) const { if (!UseInlineDepthForSpeculativeTypes) { return this; diff --git a/src/hotspot/share/opto/type.hpp b/src/hotspot/share/opto/type.hpp index 1b11ed95367..b9883d51391 100644 --- a/src/hotspot/share/opto/type.hpp +++ b/src/hotspot/share/opto/type.hpp @@ -1356,6 +1356,7 @@ public: // Speculative type helper methods. virtual const TypeInstPtr* remove_speculative() const; + const TypeInstPtr* with_speculative(const TypePtr* speculative) const; virtual const TypePtr* with_inline_depth(int depth) const; virtual const TypePtr* with_instance_id(int instance_id) const; diff --git a/test/hotspot/jtreg/compiler/runtime/unloaded/TestMHUnloaded.java b/test/hotspot/jtreg/compiler/runtime/unloaded/TestMHUnloaded.java index 23c6e83a6c5..8a1be961c80 100644 --- a/test/hotspot/jtreg/compiler/runtime/unloaded/TestMHUnloaded.java +++ b/test/hotspot/jtreg/compiler/runtime/unloaded/TestMHUnloaded.java @@ -31,10 +31,17 @@ * * @compile TestMHUnloaded.java TestMHUnloadedHelper.java * @run driver jdk.test.lib.helpers.ClassFileInstaller compiler.runtime.unloaded.TestMHUnloadedHelper + * * @run main/othervm -Xbootclasspath/a:. * -Xbatch -XX:-TieredCompilation -XX:CompileCommand=exclude,*::test * -XX:+UnlockDiagnosticVMOptions -XX:+PrintCompilation -XX:+PrintInlining * compiler.runtime.unloaded.TestMHUnloaded + * + * @run main/othervm -Xbootclasspath/a:. + * -Xbatch -XX:-TieredCompilation -XX:CompileCommand=exclude,*::test + * -XX:+UnlockDiagnosticVMOptions -XX:+PrintCompilation -XX:+PrintInlining + * -XX:+IgnoreUnrecognizedVMOptions -XX:+AlwaysIncrementalInline + * compiler.runtime.unloaded.TestMHUnloaded */ package compiler.runtime.unloaded;