RFR: 8275201: C2: hide klass() accessor from TypeOopPtr and typeKlassPtr subclasses

Tobias Hartmann thartmann at openjdk.java.net
Tue Feb 8 10:50:05 UTC 2022


On Mon, 6 Dec 2021 09:59:44 GMT, Roland Westrelin <roland at openjdk.org> wrote:

> Outside the type system code itself, c2 usually assumes that a
> TypeOopPtr or a TypeKlassPtr's java type is fully represented by its
> klass(). To have proper support for interfaces, that can't be true as
> a type needs to be represented by an instance class and a set of
> interfaces. This patch hides the klass() accessor of
> TypeOopPtr/TypeKlassPtr and reworks c2 code that relies on it in a way
> that makes that code suitable for proper interface support in a
> subsequent change. This patch doesn't add proper interface support yet
> and is mostly refactoring. "Mostly" because there are cases where the
> previous logic would use a ciKlass but the new one works with a
> TypeKlassPtr/TypeInstPtr which carries the ciKlass and whether the
> klass is exact or not. That extra bit of information can sometimes
> help and so could result in slightly different decisions.
> 
> To remove the klass() accessors, the new logic either relies on:
> 
> - new methods of TypeKlassPtr/TypeInstPtr. For instance, instead of:
> toop->klass()->is_subtype_of(other_toop->klass())
> the new code is:
> toop->is_java_subtype_of(other_toop)
> 
> - variants of the klass() accessors for narrower cases like
>   TypeInstPtr::instance_klass() (returns _klass except if _klass is an
>   interface in which case it returns Object),
>   TypeOopPtr::unloaded_klass() (returns _klass but only when the klass
>   is unloaed), TypeOopPtr::exact_klass() (returns _klass but only when
>   the type is exact).
> 
> When I tested this patch, for most changes in this patch, I had the
> previous logic, the new logic and a check that verified that they
> return the same result. I ran as much testing as I could that way.

Quickly ran this through testing, seeing build failures:


[2022-02-08T10:43:57,398Z] /System/Volumes/Data/mesos/work_dir/slaves/c82600aa-2448-475c-8c08-6f02a5b3f3af-S24420/frameworks/1735e8a2-a1db-478c-8104-60c8b0af87dd-0196/executors/d28f4559-13f6-46e3-b407-8090e4d3f411/runs/ecf578fc-ee25-4f6e-a577-ebd7c77ee02d/workspace/open/src/hotspot/share/opto/graphKit.cpp:3987:17: error: 'klass' is a protected member of 'TypeOopPtr'
[2022-02-08T10:43:57,398Z]   if (ary_type->klass()->is_array_klass()) {
[2022-02-08T10:43:57,398Z]                 ^
[2022-02-08T10:43:57,398Z] /System/Volumes/Data/mesos/work_dir/slaves/c82600aa-2448-475c-8c08-6f02a5b3f3af-S24420/frameworks/1735e8a2-a1db-478c-8104-60c8b0af87dd-0196/executors/d28f4559-13f6-46e3-b407-8090e4d3f411/runs/ecf578fc-ee25-4f6e-a577-ebd7c77ee02d/workspace/open/src/hotspot/share/opto/type.hpp:1096:20: note: declared protected here
[2022-02-08T10:43:57,398Z]   virtual ciKlass* klass() const { return _klass;     }
[2022-02-08T10:43:57,398Z]                    ^
[2022-02-08T10:43:57,398Z] /System/Volumes/Data/mesos/work_dir/slaves/c82600aa-2448-475c-8c08-6f02a5b3f3af-S24420/frameworks/1735e8a2-a1db-478c-8104-60c8b0af87dd-0196/executors/d28f4559-13f6-46e3-b407-8090e4d3f411/runs/ecf578fc-ee25-4f6e-a577-ebd7c77ee02d/workspace/open/src/hotspot/share/opto/graphKit.cpp:3988:30: error: 'klass' is a protected member of 'TypeOopPtr'
[2022-02-08T10:43:57,398Z]     BasicType bt = ary_type->klass()->as_array_klass()->element_type()->basic_type();
[2022-02-08T10:43:57,398Z]                              ^
[2022-02-08T10:43:57,398Z] /System/Volumes/Data/mesos/work_dir/slaves/c82600aa-2448-475c-8c08-6f02a5b3f3af-S24420/frameworks/1735e8a2-a1db-478c-8104-60c8b0af87dd-0196/executors/d28f4559-13f6-46e3-b407-8090e4d3f411/runs/ecf578fc-ee25-4f6e-a577-ebd7c77ee02d/workspace/open/src/hotspot/share/opto/type.hpp:1096:20: note: declared protected here
[2022-02-08T10:43:57,398Z]   virtual ciKlass* klass() const { return _klass;     }

-------------

PR: https://git.openjdk.java.net/jdk/pull/6717


More information about the hotspot-compiler-dev mailing list