[jdk18] RFR: 8279011: JFR: JfrChunkWriter incorrectly handles int64_t chunk size as size_t
Aleksey Shipilev
shade at openjdk.java.net
Mon Dec 20 17:27:24 UTC 2021
On Mon, 20 Dec 2021 17:03:39 GMT, Markus Grönlund <mgronlun at openjdk.org> wrote:
> But surprised there is not a compile error here (both incompatible type size and sign), if sizeof(size_t) == 4 and sizeof(int64_t) == 8:
>
> const size_t sz_written = size_written(); // <-- returns int64_t
I believe narrowing conversions like these are implicit in C++, and do not produce warnings in modern compilers. See: https://godbolt.org/z/48oh91YE9
> So the value is written as a 4-byte quantity only, since it is dimensioned using sizeof(size_t), and therefore does not fill the full 8- bytes slot associated with the 'chunksize' header field. And uninitialized memory in the high 4-bytes leads to this high value?
Actually, I think it is worse than that, since `sizeof(T)*len + len` can produce the `pos` that is way off, because of multiplication by `len`:
template <typename BE, typename IE, typename WriterPolicyImpl >
template <typename T>
inline void WriterHost<BE, IE, WriterPolicyImpl>::be_write(const T* value, size_t len) {
assert(value != NULL, "invariant");
assert(len > 0, "invariant");
// Might need T + 1 size
u1* const pos = ensure_size(sizeof(T) * len + len);
if (pos) {
this->set_current_pos(BE::be_write(value, len, pos));
}
So it might just store the `chunk_size` somewhere else...
-------------
PR: https://git.openjdk.java.net/jdk18/pull/50
More information about the hotspot-jfr-dev
mailing list