8337683: Fix -Wconversion problem with arrayOop.hpp

Reviewed-by: stefank, dholmes
This commit is contained in:
Coleen Phillimore 2024-08-08 16:11:08 +00:00
parent 78773b1769
commit 9695f09581
3 changed files with 14 additions and 12 deletions
src/hotspot/share

@ -68,10 +68,10 @@ private:
// The header is considered the oop part of this type plus the length.
// This is not equivalent to sizeof(arrayOopDesc) which should not appear in the code.
static int header_size_in_bytes() {
size_t hs = length_offset_in_bytes() + sizeof(int);
int hs = length_offset_in_bytes() + (int)sizeof(int);
#ifdef ASSERT
// make sure it isn't called before UseCompressedOops is initialized.
static size_t arrayoopdesc_hs = 0;
static int arrayoopdesc_hs = 0;
if (arrayoopdesc_hs == 0) arrayoopdesc_hs = hs;
assert(arrayoopdesc_hs == hs, "header size can't change");
#endif // ASSERT
@ -83,13 +83,13 @@ private:
// it occupies the second half of the _klass field in oopDesc.
static int length_offset_in_bytes() {
return UseCompressedClassPointers ? klass_gap_offset_in_bytes() :
sizeof(arrayOopDesc);
(int)sizeof(arrayOopDesc);
}
// Returns the offset of the first element.
static int base_offset_in_bytes(BasicType type) {
size_t hs = header_size_in_bytes();
return (int)(element_type_should_be_aligned(type) ? align_up(hs, BytesPerLong) : hs);
int hs = header_size_in_bytes();
return element_type_should_be_aligned(type) ? align_up(hs, BytesPerLong) : hs;
}
// Returns the address of the first element. The elements in the array will not
@ -134,14 +134,14 @@ private:
assert(type < T_CONFLICT, "wrong type");
assert(type2aelembytes(type) != 0, "wrong type");
size_t hdr_size_in_bytes = base_offset_in_bytes(type);
int hdr_size_in_bytes = base_offset_in_bytes(type);
// This is rounded-up and may overlap with the first array elements.
size_t hdr_size_in_words = align_up(hdr_size_in_bytes, HeapWordSize) / HeapWordSize;
int hdr_size_in_words = align_up(hdr_size_in_bytes, HeapWordSize) / HeapWordSize;
const size_t max_element_words_per_size_t =
align_down((SIZE_MAX/HeapWordSize - hdr_size_in_words), MinObjAlignment);
align_down((SIZE_MAX/HeapWordSize - (size_t)hdr_size_in_words), MinObjAlignment);
const size_t max_elements_per_size_t =
HeapWordSize * max_element_words_per_size_t / type2aelembytes(type);
HeapWordSize * max_element_words_per_size_t / (size_t)type2aelembytes(type);
if ((size_t)max_jint < max_elements_per_size_t) {
// It should be ok to return max_jint here, but parts of the code
// (CollectedHeap, Klass::oop_oop_iterate(), and more) uses an int for

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -31,6 +31,7 @@
#include "runtime/orderAccess.hpp"
#include "utilities/align.hpp"
#include "utilities/bytes.hpp"
#include "utilities/checkedCast.hpp"
#include "utilities/macros.hpp"
#include <type_traits>
@ -1118,7 +1119,7 @@ inline T Atomic::CmpxchgByteUsingInt::operator()(T volatile* dest,
uint8_t canon_compare_value = compare_value;
volatile uint32_t* aligned_dest
= reinterpret_cast<volatile uint32_t*>(align_down(dest, sizeof(uint32_t)));
size_t offset = pointer_delta(dest, aligned_dest, 1);
uint32_t offset = checked_cast<uint32_t>(pointer_delta(dest, aligned_dest, 1));
uint32_t idx = (Endian::NATIVE == Endian::BIG)
? (sizeof(uint32_t) - 1 - offset)

@ -26,6 +26,7 @@
#define SHARE_UTILITIES_BYTESWAP_HPP
#include "metaprogramming/enableIf.hpp"
#include "utilities/checkedCast.hpp"
#include "utilities/globalDefinitions.hpp"
#include <cstddef>
@ -63,7 +64,7 @@ struct ByteswapFallbackImpl;
template <typename T>
struct ByteswapFallbackImpl<T, 2> {
inline constexpr uint16_t operator()(uint16_t x) const {
return (((x & UINT16_C(0x00ff)) << 8) | ((x & UINT16_C(0xff00)) >> 8));
return checked_cast<uint16_t>(((x & UINT16_C(0x00ff)) << 8) | ((x & UINT16_C(0xff00)) >> 8));
}
};