The function compute_offset() [in vm/classfile/javaClasses.cpp] can be used to
obtain the offset for both ordinary fields and static fields. The caller must
know which kind of field is being looked for, and must treat the result
differently according to that knowledge. And there's no way to verify that
the field found by compute_offset() was actually of the expected kind.
When a static field is looked for, the resulting offset is from the base of
the class mirror object, which makes it unsuitable for use with the
static_field_addr() function that one would expect to be used to convert a
static field offset to the address of the value; the computed offset instead
needs to be decremented by the mirror's offset_of_static_fields() value.
This is a potential source of hard to debug errors.
It would be better if there were separate functions for getting the offset of
ordinary fields and static fields (though they might share a common
implementation).
obtain the offset for both ordinary fields and static fields. The caller must
know which kind of field is being looked for, and must treat the result
differently according to that knowledge. And there's no way to verify that
the field found by compute_offset() was actually of the expected kind.
When a static field is looked for, the resulting offset is from the base of
the class mirror object, which makes it unsuitable for use with the
static_field_addr() function that one would expect to be used to convert a
static field offset to the address of the value; the computed offset instead
needs to be decremented by the mirror's offset_of_static_fields() value.
This is a potential source of hard to debug errors.
It would be better if there were separate functions for getting the offset of
ordinary fields and static fields (though they might share a common
implementation).
- relates to
-
JDK-4953140 Remove hardcoded field offsets in javaClasses.cpp
-
- Closed
-