RFR: 8308655: Narrow types of ConstantPool and ConstMethod returns

Frederic Parain fparain at openjdk.org
Wed May 24 14:00:59 UTC 2023


On Tue, 23 May 2023 01:18:07 GMT, Coleen Phillimore <coleenp at openjdk.org> wrote:

> This change uses a number of ways to eliminate -Wconversion warnings in the metadata files in the oops directory. 
> 
> 1. narrow return types to u2 if the accessor is for a field or value that's u2 (u2 is most common for constMethod fields and constant pool indices)
> 2. Use checked_cast<type> for places where we know the int value is u2 or s2 but propagating these types is too much fan out.
> 3. Use plain casts where it's obvious that the int value fits in the casted-to type.
> 4. Moved KlassKind to be contained in Klass to add the Unknown enum value to use instead of -1.
> 5. Moved the compute_from_signature function into ConstMethod as it sets values in ConstMethod and the parameters are changed in the set functions.  Removed some pass through functions in Method.
> 
> Tested with tier1-4.

Overall, the changes look good, only two points that could be improved (see comments in the code)

src/hotspot/share/oops/constMethod.hpp line 453:

> 451: 
> 452:   // max stack
> 453:   int  max_stack() const                         { return _max_stack; }

max_stack() and max_locals() could return u2 instead of int.

src/hotspot/share/oops/klass.cpp line 264:

> 262:       super_check_cell = &_secondary_super_cache;
> 263:     }
> 264:     set_super_check_offset(u4((address)super_check_cell - (address) this));

The argument is cast to u4 but set_super_check_offset()'s declaration says that the argument should be a juint.

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

PR Review: https://git.openjdk.org/jdk/pull/14092#pullrequestreview-1440305413
PR Review Comment: https://git.openjdk.org/jdk/pull/14092#discussion_r1202903002
PR Review Comment: https://git.openjdk.org/jdk/pull/14092#discussion_r1202800867


More information about the hotspot-dev mailing list