RFR 8245289: Clean up offset code in JavaClasses
coleen.phillimore at oracle.com
coleen.phillimore at oracle.com
Tue May 26 13:49:57 UTC 2020
I might have a better idea, so please disregard this for now.
thanks,
Coleen
On 5/26/20 8:39 AM, coleen.phillimore at oracle.com wrote:
> Summary: Use X macro to declare and define offset, and declare
> accessors when needed, also make names consistent.
>
> Changes include.
>
> 1. making all offset field names start with underscore.
> 2. renamed blah_offset_in_bytes to just blah_offset (they are all in
> bytes and would never be in "words")
> 3. Use X macro to declare then define the field offsets to avoid
> retyping all that
> 4. Use X macro to define accessors for classes that needed them, so
> that the accessors can check if the field has been initialized. Since
> these are member fields and static fields, their offsets can never be
> zero, so there's no need to have a test for -1. I kept some
> _initialized members for a couple of classes. They can be removed
> later if we want.
> - I didn't change offset field access internally in the class member
> functions everywhere because it wouldn't be a net improvements in
> lines of code
> 5. removed "private" keyword because in class declarations fields are
> private by default.
>
> Most of these classes have accessor patterns like
>
> void java_lang_Class::set_class_loader(oop java_class, oop loader) {
> assert(_class_loader_offset != 0, "offsets should have been
> initialized");
> java_class->obj_field_put(_class_loader_offset, loader);
> }
>
> oop java_lang_Class::class_loader(oop java_class) {
> assert(_class_loader_offset != 0, "must be set");
> return java_class->obj_field(_class_loader_offset);
> }
>
> So it seems like it'd be useful to wrap that up with the X macro too,
> but there are also a lot of classes that don't have this pattern for
> all of the fields, ie. they do some other things so there's be too
> many exceptions to make this a nice code savings change. The jvmci
> code has this sort of giant X macro that is, in my opinion, completely
> unreadable.
>
> Anyway, this is an improvement for now and tested tier1-6. What do
> you think?
>
> open webrev at http://cr.openjdk.java.net/~coleenp/2020/8245289.01/webrev
> bug link https://bugs.openjdk.java.net/browse/JDK-8245289
>
> thanks,
> Coleen
>
More information about the hotspot-dev
mailing list