Skip to content

Commit 9695f09

Browse files
committedAug 8, 2024
8337683: Fix -Wconversion problem with arrayOop.hpp
Reviewed-by: stefank, dholmes
1 parent 78773b1 commit 9695f09

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed
 

‎src/hotspot/share/oops/arrayOop.hpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ class arrayOopDesc : public oopDesc {
6868
// The header is considered the oop part of this type plus the length.
6969
// This is not equivalent to sizeof(arrayOopDesc) which should not appear in the code.
7070
static int header_size_in_bytes() {
71-
size_t hs = length_offset_in_bytes() + sizeof(int);
71+
int hs = length_offset_in_bytes() + (int)sizeof(int);
7272
#ifdef ASSERT
7373
// make sure it isn't called before UseCompressedOops is initialized.
74-
static size_t arrayoopdesc_hs = 0;
74+
static int arrayoopdesc_hs = 0;
7575
if (arrayoopdesc_hs == 0) arrayoopdesc_hs = hs;
7676
assert(arrayoopdesc_hs == hs, "header size can't change");
7777
#endif // ASSERT
@@ -83,13 +83,13 @@ class arrayOopDesc : public oopDesc {
8383
// it occupies the second half of the _klass field in oopDesc.
8484
static int length_offset_in_bytes() {
8585
return UseCompressedClassPointers ? klass_gap_offset_in_bytes() :
86-
sizeof(arrayOopDesc);
86+
(int)sizeof(arrayOopDesc);
8787
}
8888

8989
// Returns the offset of the first element.
9090
static int base_offset_in_bytes(BasicType type) {
91-
size_t hs = header_size_in_bytes();
92-
return (int)(element_type_should_be_aligned(type) ? align_up(hs, BytesPerLong) : hs);
91+
int hs = header_size_in_bytes();
92+
return element_type_should_be_aligned(type) ? align_up(hs, BytesPerLong) : hs;
9393
}
9494

9595
// Returns the address of the first element. The elements in the array will not
@@ -134,14 +134,14 @@ class arrayOopDesc : public oopDesc {
134134
assert(type < T_CONFLICT, "wrong type");
135135
assert(type2aelembytes(type) != 0, "wrong type");
136136

137-
size_t hdr_size_in_bytes = base_offset_in_bytes(type);
137+
int hdr_size_in_bytes = base_offset_in_bytes(type);
138138
// This is rounded-up and may overlap with the first array elements.
139-
size_t hdr_size_in_words = align_up(hdr_size_in_bytes, HeapWordSize) / HeapWordSize;
139+
int hdr_size_in_words = align_up(hdr_size_in_bytes, HeapWordSize) / HeapWordSize;
140140

141141
const size_t max_element_words_per_size_t =
142-
align_down((SIZE_MAX/HeapWordSize - hdr_size_in_words), MinObjAlignment);
142+
align_down((SIZE_MAX/HeapWordSize - (size_t)hdr_size_in_words), MinObjAlignment);
143143
const size_t max_elements_per_size_t =
144-
HeapWordSize * max_element_words_per_size_t / type2aelembytes(type);
144+
HeapWordSize * max_element_words_per_size_t / (size_t)type2aelembytes(type);
145145
if ((size_t)max_jint < max_elements_per_size_t) {
146146
// It should be ok to return max_jint here, but parts of the code
147147
// (CollectedHeap, Klass::oop_oop_iterate(), and more) uses an int for

‎src/hotspot/share/runtime/atomic.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -31,6 +31,7 @@
3131
#include "runtime/orderAccess.hpp"
3232
#include "utilities/align.hpp"
3333
#include "utilities/bytes.hpp"
34+
#include "utilities/checkedCast.hpp"
3435
#include "utilities/macros.hpp"
3536

3637
#include <type_traits>
@@ -1118,7 +1119,7 @@ inline T Atomic::CmpxchgByteUsingInt::operator()(T volatile* dest,
11181119
uint8_t canon_compare_value = compare_value;
11191120
volatile uint32_t* aligned_dest
11201121
= reinterpret_cast<volatile uint32_t*>(align_down(dest, sizeof(uint32_t)));
1121-
size_t offset = pointer_delta(dest, aligned_dest, 1);
1122+
uint32_t offset = checked_cast<uint32_t>(pointer_delta(dest, aligned_dest, 1));
11221123

11231124
uint32_t idx = (Endian::NATIVE == Endian::BIG)
11241125
? (sizeof(uint32_t) - 1 - offset)

‎src/hotspot/share/utilities/byteswap.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#define SHARE_UTILITIES_BYTESWAP_HPP
2727

2828
#include "metaprogramming/enableIf.hpp"
29+
#include "utilities/checkedCast.hpp"
2930
#include "utilities/globalDefinitions.hpp"
3031

3132
#include <cstddef>
@@ -63,7 +64,7 @@ struct ByteswapFallbackImpl;
6364
template <typename T>
6465
struct ByteswapFallbackImpl<T, 2> {
6566
inline constexpr uint16_t operator()(uint16_t x) const {
66-
return (((x & UINT16_C(0x00ff)) << 8) | ((x & UINT16_C(0xff00)) >> 8));
67+
return checked_cast<uint16_t>(((x & UINT16_C(0x00ff)) << 8) | ((x & UINT16_C(0xff00)) >> 8));
6768
}
6869
};
6970

0 commit comments

Comments
 (0)
Please sign in to comment.