diff --git a/src/hotspot/cpu/aarch64/continuationFreezeThaw_aarch64.inline.hpp b/src/hotspot/cpu/aarch64/continuationFreezeThaw_aarch64.inline.hpp index 17c86c81071..4e4aa95e171 100644 --- a/src/hotspot/cpu/aarch64/continuationFreezeThaw_aarch64.inline.hpp +++ b/src/hotspot/cpu/aarch64/continuationFreezeThaw_aarch64.inline.hpp @@ -217,7 +217,7 @@ template frame ThawBase::new_stack_frame(const frame& hf, frame& intptr_t* heap_sp = hf.unextended_sp(); // If caller is interpreted it already made room for the callee arguments int overlap = caller.is_interpreted_frame() ? ContinuationHelper::InterpretedFrame::stack_argsize(hf) : 0; - const int fsize = ContinuationHelper::InterpretedFrame::frame_bottom(hf) - hf.unextended_sp() - overlap; + const int fsize = (int)(ContinuationHelper::InterpretedFrame::frame_bottom(hf) - hf.unextended_sp() - overlap); const int locals = hf.interpreter_frame_method()->max_locals(); intptr_t* frame_sp = caller.unextended_sp() - fsize; intptr_t* fp = frame_sp + (hf.fp() - heap_sp); diff --git a/src/hotspot/cpu/aarch64/frame_aarch64.inline.hpp b/src/hotspot/cpu/aarch64/frame_aarch64.inline.hpp index 25383a5ba07..5fc5fe9248e 100644 --- a/src/hotspot/cpu/aarch64/frame_aarch64.inline.hpp +++ b/src/hotspot/cpu/aarch64/frame_aarch64.inline.hpp @@ -232,7 +232,7 @@ inline intptr_t* frame::real_fp() const { inline int frame::frame_size() const { return is_interpreted_frame() - ? sender_sp() - sp() + ? pointer_delta_as_int(sender_sp(), sp()) : cb()->frame_size(); } diff --git a/src/hotspot/cpu/aarch64/stackChunkFrameStream_aarch64.inline.hpp b/src/hotspot/cpu/aarch64/stackChunkFrameStream_aarch64.inline.hpp index 598104264d8..795026ad9fc 100644 --- a/src/hotspot/cpu/aarch64/stackChunkFrameStream_aarch64.inline.hpp +++ b/src/hotspot/cpu/aarch64/stackChunkFrameStream_aarch64.inline.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2023, 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 @@ -114,8 +114,8 @@ inline int StackChunkFrameStream::interpreter_frame_num_oops() const f.interpreted_frame_oop_map(&mask); return mask.num_oops() + 1 // for the mirror oop - + ((intptr_t*)f.interpreter_frame_monitor_begin() - - (intptr_t*)f.interpreter_frame_monitor_end())/BasicObjectLock::size(); + + pointer_delta_as_int((intptr_t*)f.interpreter_frame_monitor_begin(), + (intptr_t*)f.interpreter_frame_monitor_end())/BasicObjectLock::size(); } template<> diff --git a/src/hotspot/cpu/x86/continuationFreezeThaw_x86.inline.hpp b/src/hotspot/cpu/x86/continuationFreezeThaw_x86.inline.hpp index 1078e1dca67..08b1b285651 100644 --- a/src/hotspot/cpu/x86/continuationFreezeThaw_x86.inline.hpp +++ b/src/hotspot/cpu/x86/continuationFreezeThaw_x86.inline.hpp @@ -214,7 +214,7 @@ template frame ThawBase::new_stack_frame(const frame& hf, frame& intptr_t* heap_sp = hf.unextended_sp(); // If caller is interpreted it already made room for the callee arguments int overlap = caller.is_interpreted_frame() ? ContinuationHelper::InterpretedFrame::stack_argsize(hf) : 0; - const int fsize = ContinuationHelper::InterpretedFrame::frame_bottom(hf) - hf.unextended_sp() - overlap; + const int fsize = (int)(ContinuationHelper::InterpretedFrame::frame_bottom(hf) - hf.unextended_sp() - overlap); const int locals = hf.interpreter_frame_method()->max_locals(); intptr_t* frame_sp = caller.unextended_sp() - fsize; intptr_t* fp = frame_sp + (hf.fp() - heap_sp); diff --git a/src/hotspot/cpu/x86/frame_x86.inline.hpp b/src/hotspot/cpu/x86/frame_x86.inline.hpp index 2d8d0797951..d7862afc292 100644 --- a/src/hotspot/cpu/x86/frame_x86.inline.hpp +++ b/src/hotspot/cpu/x86/frame_x86.inline.hpp @@ -221,7 +221,7 @@ inline intptr_t* frame::real_fp() const { inline int frame::frame_size() const { return is_interpreted_frame() - ? sender_sp() - sp() + ? pointer_delta_as_int(sender_sp(), sp()) : cb()->frame_size(); } diff --git a/src/hotspot/cpu/x86/nativeInst_x86.hpp b/src/hotspot/cpu/x86/nativeInst_x86.hpp index d8a2faa44f3..938a10cb63d 100644 --- a/src/hotspot/cpu/x86/nativeInst_x86.hpp +++ b/src/hotspot/cpu/x86/nativeInst_x86.hpp @@ -171,7 +171,7 @@ class NativeCall: public NativeInstruction { intptr_t disp = dest - return_address(); guarantee(disp == (intptr_t)(jint)disp, "must be 32-bit offset"); #endif // AMD64 - set_int_at(displacement_offset, dest - return_address()); + set_int_at(displacement_offset, (int)(dest - return_address())); } // Returns whether the 4-byte displacement operand is 4-byte aligned. bool is_displacement_aligned(); diff --git a/src/hotspot/cpu/x86/stackChunkFrameStream_x86.inline.hpp b/src/hotspot/cpu/x86/stackChunkFrameStream_x86.inline.hpp index 6240de27b6b..3b3e2dee10c 100644 --- a/src/hotspot/cpu/x86/stackChunkFrameStream_x86.inline.hpp +++ b/src/hotspot/cpu/x86/stackChunkFrameStream_x86.inline.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2023, 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 @@ -114,8 +114,8 @@ inline int StackChunkFrameStream::interpreter_frame_num_oops() const f.interpreted_frame_oop_map(&mask); return mask.num_oops() + 1 // for the mirror oop - + ((intptr_t*)f.interpreter_frame_monitor_begin() - - (intptr_t*)f.interpreter_frame_monitor_end())/BasicObjectLock::size(); + + pointer_delta_as_int((intptr_t*)f.interpreter_frame_monitor_begin(), + (intptr_t*)f.interpreter_frame_monitor_end())/BasicObjectLock::size(); } template<> diff --git a/src/hotspot/os/linux/cgroupSubsystem_linux.hpp b/src/hotspot/os/linux/cgroupSubsystem_linux.hpp index 038593a2bc4..6c5470445f1 100644 --- a/src/hotspot/os/linux/cgroupSubsystem_linux.hpp +++ b/src/hotspot/os/linux/cgroupSubsystem_linux.hpp @@ -132,7 +132,7 @@ template int subsystem_file_line_contents(CgroupController* c, } else { // File consists of multiple lines in a "key value" // fashion, we have to find the key. - const int key_len = strlen(key); + const int key_len = (int)strlen(key); for (; line != nullptr; line = fgets(buf, buf_len, fp)) { char* key_substr = strstr(line, key); char after_key = line[key_len]; diff --git a/src/hotspot/share/c1/c1_CodeStubs.hpp b/src/hotspot/share/c1/c1_CodeStubs.hpp index 8c6fabf4f99..04e379842e1 100644 --- a/src/hotspot/share/c1/c1_CodeStubs.hpp +++ b/src/hotspot/share/c1/c1_CodeStubs.hpp @@ -443,7 +443,7 @@ class PatchingStub: public CodeStub { _info = info; _obj = obj; masm->bind(_patch_site_continuation); - _bytes_to_copy = masm->pc() - pc_start(); + _bytes_to_copy = pointer_delta_as_int(masm->pc(), pc_start()); if (_id == PatchingStub::access_field_id) { // embed a fixed offset to handle long patches which need to be offset by a word. // the patching code will just add the field offset field to this offset so diff --git a/src/hotspot/share/c1/c1_Instruction.hpp b/src/hotspot/share/c1/c1_Instruction.hpp index 7308facda6f..6067767da4e 100644 --- a/src/hotspot/share/c1/c1_Instruction.hpp +++ b/src/hotspot/share/c1/c1_Instruction.hpp @@ -325,9 +325,9 @@ class Instruction: public CompilationResourceObj { void set_arg_needs_null_check(int i, bool check) { if (i >= 0 && i < (int)sizeof(_nonnull_state) * BitsPerByte) { if (check) { - _nonnull_state |= nth_bit(i); + _nonnull_state |= (int)nth_bit(i); } else { - _nonnull_state &= ~(nth_bit(i)); + _nonnull_state &= (int)~(nth_bit(i)); } } } diff --git a/src/hotspot/share/cds/archiveHeapWriter.hpp b/src/hotspot/share/cds/archiveHeapWriter.hpp index 6001012ba85..c5fa71fc0b4 100644 --- a/src/hotspot/share/cds/archiveHeapWriter.hpp +++ b/src/hotspot/share/cds/archiveHeapWriter.hpp @@ -115,7 +115,7 @@ class ArchiveHeapWriter : AllStatic { // Both Java bytearray and GrowableArraty use int indices and lengths. Do a safe typecast with range check static int to_array_index(size_t i) { assert(i <= (size_t)max_jint, "must be"); - return (size_t)i; + return (int)i; } static int to_array_length(size_t n) { return to_array_index(n); diff --git a/src/hotspot/share/ci/ciMethodData.hpp b/src/hotspot/share/ci/ciMethodData.hpp index 9c6c877da67..005fa214647 100644 --- a/src/hotspot/share/ci/ciMethodData.hpp +++ b/src/hotspot/share/ci/ciMethodData.hpp @@ -501,7 +501,7 @@ public: // Convert a dp (data pointer) to a di (data index). int dp_to_di(address dp) { - return dp - ((address)_data); + return pointer_delta_as_int(dp, ((address)_data)); } // Get the data at an arbitrary (sort of) data index. diff --git a/src/hotspot/share/ci/ciStreams.hpp b/src/hotspot/share/ci/ciStreams.hpp index 7dae21a0290..110002b3b43 100644 --- a/src/hotspot/share/ci/ciStreams.hpp +++ b/src/hotspot/share/ci/ciStreams.hpp @@ -110,9 +110,9 @@ public: } address cur_bcp() const { return _bc_start; } // Returns bcp to current instruction - int next_bci() const { return _pc - _start; } - int cur_bci() const { return _bc_start - _start; } - int instruction_size() const { return _pc - _bc_start; } + int next_bci() const { return pointer_delta_as_int(_pc, _start); } + int cur_bci() const { return pointer_delta_as_int(_bc_start, _start); } + int instruction_size() const { return pointer_delta_as_int(_pc, _bc_start); } Bytecodes::Code cur_bc() const{ return check_java(_bc); } Bytecodes::Code cur_bc_raw() const { return check_defined(_raw_bc); } diff --git a/src/hotspot/share/classfile/classFileStream.hpp b/src/hotspot/share/classfile/classFileStream.hpp index 55bcf082940..b84956983b9 100644 --- a/src/hotspot/share/classfile/classFileStream.hpp +++ b/src/hotspot/share/classfile/classFileStream.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2023, 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 @@ -64,7 +64,7 @@ class ClassFileStream: public ResourceObj { // Buffer access const u1* buffer() const { return _buffer_start; } - int length() const { return _buffer_end - _buffer_start; } + int length() const { return pointer_delta_as_int(_buffer_end, _buffer_start); } const u1* current() const { return _current; } void set_current(const u1* pos) const { assert(pos >= _buffer_start && pos <= _buffer_end, "invariant"); diff --git a/src/hotspot/share/code/codeBlob.hpp b/src/hotspot/share/code/codeBlob.hpp index eb7f49b185a..c8e67314ba5 100644 --- a/src/hotspot/share/code/codeBlob.hpp +++ b/src/hotspot/share/code/codeBlob.hpp @@ -192,9 +192,9 @@ public: // Sizes int size() const { return _size; } int header_size() const { return _header_size; } - int relocation_size() const { return (address) relocation_end() - (address) relocation_begin(); } - int content_size() const { return content_end() - content_begin(); } - int code_size() const { return code_end() - code_begin(); } + int relocation_size() const { return pointer_delta_as_int((address) relocation_end(), (address) relocation_begin()); } + int content_size() const { return pointer_delta_as_int(content_end(), content_begin()); } + int code_size() const { return pointer_delta_as_int(code_end(), code_begin()); } // Only used from CodeCache::free_unused_tail() after the Interpreter blob was trimmed void adjust_size(size_t used) { _size = (int)used; diff --git a/src/hotspot/share/code/codeBlob.inline.hpp b/src/hotspot/share/code/codeBlob.inline.hpp index bd49fdba210..dbe55435970 100644 --- a/src/hotspot/share/code/codeBlob.inline.hpp +++ b/src/hotspot/share/code/codeBlob.inline.hpp @@ -33,7 +33,7 @@ inline const ImmutableOopMap* CodeBlob::oop_map_for_slot(int slot, address return_address) const { assert(_oop_maps != nullptr, "nope"); - return _oop_maps->find_map_at_slot(slot, (intptr_t) return_address - (intptr_t) code_begin()); + return _oop_maps->find_map_at_slot(slot, pointer_delta_as_int(return_address, code_begin())); } #endif // SHARE_CODE_CODEBLOB_INLINE_HPP diff --git a/src/hotspot/share/code/dependencies.hpp b/src/hotspot/share/code/dependencies.hpp index bdb7998fd8c..124db0b1369 100644 --- a/src/hotspot/share/code/dependencies.hpp +++ b/src/hotspot/share/code/dependencies.hpp @@ -666,7 +666,7 @@ class DependencySignature : public ResourceObj { } static bool equals(DependencySignature const& s1, DependencySignature const& s2); - static unsigned hash (DependencySignature const& s1) { return s1.arg(0) >> 2; } + static unsigned hash (DependencySignature const& s1) { return (unsigned)(s1.arg(0) >> 2); } int args_count() const { return _args_count; } uintptr_t arg(int idx) const { return _argument_hash[idx]; } diff --git a/src/hotspot/share/code/exceptionHandlerTable.hpp b/src/hotspot/share/code/exceptionHandlerTable.hpp index d30d602b33c..f1dcab657ff 100644 --- a/src/hotspot/share/code/exceptionHandlerTable.hpp +++ b/src/hotspot/share/code/exceptionHandlerTable.hpp @@ -172,7 +172,7 @@ public: uint get_exec_offset(uint i) { assert(i < _len, "oob"); return *adr(i); } uint get_cont_offset(uint i) { assert(i < _len, "oob"); return *(adr(i) + 1); } - int size_in_bytes() const { return len() == 0 ? 0 : ((2 * len() + 1) * sizeof(implicit_null_entry)); } + int size_in_bytes() const { return len() == 0 ? 0 : ((2 * len() + 1) * (int)sizeof(implicit_null_entry)); } void copy_to(nmethod* nm); void copy_bytes_to(address addr, int size); diff --git a/src/hotspot/share/code/vtableStubs.hpp b/src/hotspot/share/code/vtableStubs.hpp index bd037e62cce..f993571b58f 100644 --- a/src/hotspot/share/code/vtableStubs.hpp +++ b/src/hotspot/share/code/vtableStubs.hpp @@ -130,7 +130,7 @@ class VtableStub { void* operator new(size_t size, int code_size) throw(); - VtableStub(bool is_vtable_stub, int index) + VtableStub(bool is_vtable_stub, short index) : _next(nullptr), _index(index), _ame_offset(-1), _npe_offset(-1), _is_vtable_stub(is_vtable_stub) {} VtableStub* next() const { return _next; } @@ -151,8 +151,8 @@ class VtableStub { private: void set_exception_points(address npe_addr, address ame_addr) { - _npe_offset = npe_addr - code_begin(); - _ame_offset = ame_addr - code_begin(); + _npe_offset = checked_cast(npe_addr - code_begin()); + _ame_offset = checked_cast(ame_addr - code_begin()); assert(is_abstract_method_error(ame_addr), "offset must be correct"); assert(is_null_pointer_exception(npe_addr), "offset must be correct"); assert(!is_abstract_method_error(npe_addr), "offset must be correct"); diff --git a/src/hotspot/share/oops/compressedOops.inline.hpp b/src/hotspot/share/oops/compressedOops.inline.hpp index 3f33926aa6d..298b1e9dae9 100644 --- a/src/hotspot/share/oops/compressedOops.inline.hpp +++ b/src/hotspot/share/oops/compressedOops.inline.hpp @@ -156,7 +156,7 @@ inline narrowKlass CompressedKlassPointers::encode_not_null(Klass* v, address na assert(KlassEncodingMetaspaceMax > pd, "change encoding max if new encoding"); uint64_t result = pd >> shift(); assert((result & CONST64(0xffffffff00000000)) == 0, "narrow klass pointer overflow"); - assert(decode_not_null(result, narrow_base) == v, "reversibility"); + assert(decode_not_null((narrowKlass)result, narrow_base) == v, "reversibility"); return (narrowKlass)result; } diff --git a/src/hotspot/share/oops/methodCounters.hpp b/src/hotspot/share/oops/methodCounters.hpp index 2c3fe8e43dd..d1b2207961f 100644 --- a/src/hotspot/share/oops/methodCounters.hpp +++ b/src/hotspot/share/oops/methodCounters.hpp @@ -75,17 +75,17 @@ class MethodCounters : public Metadata { _interpreter_throwout_count++; } } - int interpreter_throwout_count() const { + u2 interpreter_throwout_count() const { return _interpreter_throwout_count; } - void set_interpreter_throwout_count(int count) { + void set_interpreter_throwout_count(u2 count) { _interpreter_throwout_count = count; } #else // COMPILER2_OR_JVMCI - int interpreter_throwout_count() const { + u2 interpreter_throwout_count() const { return 0; } - void set_interpreter_throwout_count(int count) { + void set_interpreter_throwout_count(u2 count) { assert(count == 0, "count must be 0"); } #endif // COMPILER2_OR_JVMCI diff --git a/src/hotspot/share/oops/stackChunkOop.inline.hpp b/src/hotspot/share/oops/stackChunkOop.inline.hpp index 39d7dea2d76..e1993207266 100644 --- a/src/hotspot/share/oops/stackChunkOop.inline.hpp +++ b/src/hotspot/share/oops/stackChunkOop.inline.hpp @@ -387,7 +387,7 @@ inline int stackChunkOopDesc::relativize_address(intptr_t* p) const { assert(start_address() <= p && p <= base, "start_address: " PTR_FORMAT " p: " PTR_FORMAT " base: " PTR_FORMAT, p2i(start_address()), p2i(p), p2i(base)); assert(0 <= offset && offset <= std::numeric_limits::max(), "offset: " PTR_FORMAT, offset); - return offset; + return (int)offset; } inline void stackChunkOopDesc::relativize_frame(frame& fr) const { diff --git a/src/hotspot/share/prims/jvmtiTagMapTable.hpp b/src/hotspot/share/prims/jvmtiTagMapTable.hpp index 2f8f14be215..d534da07c6f 100644 --- a/src/hotspot/share/prims/jvmtiTagMapTable.hpp +++ b/src/hotspot/share/prims/jvmtiTagMapTable.hpp @@ -54,7 +54,7 @@ class JvmtiTagMapKey : public CHeapObj { static unsigned get_hash(const JvmtiTagMapKey& entry) { assert(entry._obj != nullptr, "must lookup obj to hash"); - return entry._obj->identity_hash(); + return (unsigned)entry._obj->identity_hash(); } static bool equals(const JvmtiTagMapKey& lhs, const JvmtiTagMapKey& rhs) { diff --git a/src/hotspot/share/runtime/continuationHelper.inline.hpp b/src/hotspot/share/runtime/continuationHelper.inline.hpp index 4e74a7871b9..c20fe24af95 100644 --- a/src/hotspot/share/runtime/continuationHelper.inline.hpp +++ b/src/hotspot/share/runtime/continuationHelper.inline.hpp @@ -79,7 +79,7 @@ inline address ContinuationHelper::InterpretedFrame::return_pc(const frame& f) { } inline int ContinuationHelper::InterpretedFrame::size(const frame&f) { - return InterpretedFrame::frame_bottom(f) - InterpretedFrame::frame_top(f); + return pointer_delta_as_int(InterpretedFrame::frame_bottom(f), InterpretedFrame::frame_top(f)); } inline int ContinuationHelper::InterpretedFrame::stack_argsize(const frame& f) { diff --git a/src/hotspot/share/runtime/stubCodeGenerator.hpp b/src/hotspot/share/runtime/stubCodeGenerator.hpp index d13f1b6aed7..c085e9fc38c 100644 --- a/src/hotspot/share/runtime/stubCodeGenerator.hpp +++ b/src/hotspot/share/runtime/stubCodeGenerator.hpp @@ -90,7 +90,7 @@ class StubCodeDesc: public CHeapObj { address begin() const { return _begin; } address end() const { return _end; } uint disp() const { return _disp; } - int size_in_bytes() const { return _end - _begin; } + int size_in_bytes() const { return pointer_delta_as_int(_end, _begin); } bool contains(address pc) const { return _begin <= pc && pc < _end; } void print_on(outputStream* st) const; void print() const; diff --git a/src/hotspot/share/services/mallocHeader.hpp b/src/hotspot/share/services/mallocHeader.hpp index c376c130e9d..9a2ba3ff053 100644 --- a/src/hotspot/share/services/mallocHeader.hpp +++ b/src/hotspot/share/services/mallocHeader.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2021, 2022 SAP SE. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -108,11 +108,11 @@ class MallocHeader { void print_block_on_error(outputStream* st, address bad_address) const; - static uint16_t build_footer(uint8_t b1, uint8_t b2) { return ((uint16_t)b1 << 8) | (uint16_t)b2; } + static uint16_t build_footer(uint8_t b1, uint8_t b2) { return (uint16_t)(((uint16_t)b1 << 8) | (uint16_t)b2); } uint8_t* footer_address() const { return ((address)this) + sizeof(MallocHeader) + _size; } uint16_t get_footer() const { return build_footer(footer_address()[0], footer_address()[1]); } - void set_footer(uint16_t v) { footer_address()[0] = v >> 8; footer_address()[1] = (uint8_t)v; } + void set_footer(uint16_t v) { footer_address()[0] = (uint8_t)(v >> 8); footer_address()[1] = (uint8_t)v; } template inline static OutTypeParam resolve_checked_impl(InTypeParam memblock); diff --git a/src/hotspot/share/services/mallocSiteTable.hpp b/src/hotspot/share/services/mallocSiteTable.hpp index 2523547a075..2b602527e98 100644 --- a/src/hotspot/share/services/mallocSiteTable.hpp +++ b/src/hotspot/share/services/mallocSiteTable.hpp @@ -119,7 +119,7 @@ class MallocSiteTable : AllStatic { assert(bucket_idx <= MAX_MALLOCSITE_TABLE_SIZE && pos_idx < MAX_BUCKET_LENGTH, "overflow"); return (uint32_t)bucket_idx << 16 | pos_idx; } - static uint16_t bucket_idx_from_marker(uint32_t marker) { return marker >> 16; } + static uint16_t bucket_idx_from_marker(uint32_t marker) { return (uint16_t)(marker >> 16); } static uint16_t pos_idx_from_marker(uint32_t marker) { return marker & 0xFFFF; } public: diff --git a/src/hotspot/share/utilities/align.hpp b/src/hotspot/share/utilities/align.hpp index 7c7a4f67bc5..1414d91a19d 100644 --- a/src/hotspot/share/utilities/align.hpp +++ b/src/hotspot/share/utilities/align.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2023, 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 @@ -63,7 +63,7 @@ constexpr T align_down(T size, A alignment) { // Convert mask to T before logical_not. Otherwise, if alignment is unsigned // and smaller than T, the result of the logical_not will be zero-extended // by integral promotion, and upper bits of size will be discarded. - T result = size & ~T(alignment_mask(alignment)); + T result = T(size & ~T(alignment_mask(alignment))); assert(is_aligned(result, alignment), "must be aligned: " UINT64_FORMAT, (uint64_t)result); return result; @@ -71,7 +71,7 @@ constexpr T align_down(T size, A alignment) { template::value)> constexpr T align_up(T size, A alignment) { - T adjusted = size + alignment_mask(alignment); + T adjusted = checked_cast(size + alignment_mask(alignment)); return align_down(adjusted, alignment); } diff --git a/src/hotspot/share/utilities/elfFile.hpp b/src/hotspot/share/utilities/elfFile.hpp index bad92f82af5..579837ebf80 100644 --- a/src/hotspot/share/utilities/elfFile.hpp +++ b/src/hotspot/share/utilities/elfFile.hpp @@ -255,7 +255,7 @@ class ElfFile: public CHeapObj { } void update_null_terminator_index() { - _null_terminator_index = strlen(_path); + _null_terminator_index = checked_cast(strlen(_path)); } bool copy_to_path_index(uint16_t index_in_path, const char* src); diff --git a/src/hotspot/share/utilities/globalDefinitions.hpp b/src/hotspot/share/utilities/globalDefinitions.hpp index 249cfdf42d4..ce08f147a54 100644 --- a/src/hotspot/share/utilities/globalDefinitions.hpp +++ b/src/hotspot/share/utilities/globalDefinitions.hpp @@ -520,6 +520,14 @@ constexpr T2 checked_cast(T1 thing) { return result; } +// pointer_delta_as_int is called to do pointer subtraction for nearby pointers that +// returns a non-negative int, usually used as a size of a code buffer range. +// This scales to sizeof(T). +template +inline int pointer_delta_as_int(const volatile T* left, const volatile T* right) { + return checked_cast(pointer_delta(left, right, sizeof(T))); +} + // Need the correct linkage to call qsort without warnings extern "C" { typedef int (*_sort_Fn)(const void *, const void *); @@ -661,7 +669,7 @@ inline double fabsd(double value) { // is zero, return 0.0. template inline double percent_of(T numerator, T denominator) { - return denominator != 0 ? (double)numerator / denominator * 100.0 : 0.0; + return denominator != 0 ? (double)numerator / (double)denominator * 100.0 : 0.0; } //---------------------------------------------------------------------------------------------------- diff --git a/src/hotspot/share/utilities/nativeCallStack.hpp b/src/hotspot/share/utilities/nativeCallStack.hpp index 07e30c163e0..841b2cb2045 100644 --- a/src/hotspot/share/utilities/nativeCallStack.hpp +++ b/src/hotspot/share/utilities/nativeCallStack.hpp @@ -120,7 +120,7 @@ public: for (int i = 0; i < NMT_TrackingStackDepth; i++) { hash += (uintptr_t)_stack[i]; } - return hash; + return (unsigned int)hash; } void print_on(outputStream* out) const; diff --git a/src/hotspot/share/utilities/powerOfTwo.hpp b/src/hotspot/share/utilities/powerOfTwo.hpp index 29abc972eaa..786977a347f 100644 --- a/src/hotspot/share/utilities/powerOfTwo.hpp +++ b/src/hotspot/share/utilities/powerOfTwo.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2023, 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 @@ -117,7 +117,7 @@ inline T round_up_power_of_2(T value) { template ::value)> inline T next_power_of_2(T value) { assert(value < std::numeric_limits::max(), "Overflow"); - return round_up_power_of_2(value + 1); + return T(round_up_power_of_2(value + 1)); } // Find log2 value greater than this input