Skip to content

Commit cf82e31

Browse files
committedJul 5, 2023
8311077: Fix -Wconversion warnings in jvmti code
Reviewed-by: fparain, matsaave, dholmes
1 parent 00ac46c commit cf82e31

16 files changed

+98
-95
lines changed
 

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ class ConstMethod : public MetaspaceObj {
324324
static bool is_read_only_by_default() { return true; }
325325

326326
// code size
327-
int code_size() const { return _code_size; }
327+
u2 code_size() const { return _code_size; }
328328
void set_code_size(int size) {
329329
assert(max_method_code_size < (1 << 16),
330330
"u2 is too small to hold method code size in general");

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -587,16 +587,16 @@ class ConstantPool : public Metadata {
587587
"Corrupted CP operands");
588588
return operand_offset_at(operands(), bsms_attribute_index);
589589
}
590-
int operand_bootstrap_method_ref_index_at(int bsms_attribute_index) {
590+
u2 operand_bootstrap_method_ref_index_at(int bsms_attribute_index) {
591591
int offset = operand_offset_at(bsms_attribute_index);
592592
return operands()->at(offset + _indy_bsm_offset);
593593
}
594-
int operand_argument_count_at(int bsms_attribute_index) {
594+
u2 operand_argument_count_at(int bsms_attribute_index) {
595595
int offset = operand_offset_at(bsms_attribute_index);
596-
int argc = operands()->at(offset + _indy_argc_offset);
596+
u2 argc = operands()->at(offset + _indy_argc_offset);
597597
return argc;
598598
}
599-
int operand_argument_index_at(int bsms_attribute_index, int j) {
599+
u2 operand_argument_index_at(int bsms_attribute_index, int j) {
600600
int offset = operand_offset_at(bsms_attribute_index);
601601
return operands()->at(offset + _indy_argv_offset + j);
602602
}
@@ -618,21 +618,21 @@ class ConstantPool : public Metadata {
618618
// Shrink the operands array to a smaller array with new_len length
619619
void shrink_operands(int new_len, TRAPS);
620620

621-
int bootstrap_method_ref_index_at(int which) {
621+
u2 bootstrap_method_ref_index_at(int which) {
622622
assert(tag_at(which).has_bootstrap(), "Corrupted constant pool");
623623
int op_base = bootstrap_operand_base(which);
624624
return operands()->at(op_base + _indy_bsm_offset);
625625
}
626-
int bootstrap_argument_count_at(int which) {
626+
u2 bootstrap_argument_count_at(int which) {
627627
assert(tag_at(which).has_bootstrap(), "Corrupted constant pool");
628628
int op_base = bootstrap_operand_base(which);
629-
int argc = operands()->at(op_base + _indy_argc_offset);
629+
u2 argc = operands()->at(op_base + _indy_argc_offset);
630630
DEBUG_ONLY(int end_offset = op_base + _indy_argv_offset + argc;
631631
int next_offset = bootstrap_operand_limit(which));
632632
assert(end_offset == next_offset, "matched ending");
633633
return argc;
634634
}
635-
int bootstrap_argument_index_at(int which, int j) {
635+
u2 bootstrap_argument_index_at(int which, int j) {
636636
int op_base = bootstrap_operand_base(which);
637637
DEBUG_ONLY(int argc = operands()->at(op_base + _indy_argc_offset));
638638
assert((uint)j < (uint)argc, "oob");

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -140,26 +140,26 @@ class JavaFieldStream : public FieldStreamBase {
140140
public:
141141
JavaFieldStream(const InstanceKlass* k): FieldStreamBase(k->fieldinfo_stream(), k->constants(), 0, k->java_fields_count()) {}
142142

143-
int name_index() const {
143+
u2 name_index() const {
144144
assert(!field()->field_flags().is_injected(), "regular only");
145145
return field()->name_index();
146146
}
147147

148-
int signature_index() const {
148+
u2 signature_index() const {
149149
assert(!field()->field_flags().is_injected(), "regular only");
150150
return field()->signature_index();
151151
return -1;
152152
}
153153

154-
int generic_signature_index() const {
154+
u2 generic_signature_index() const {
155155
assert(!field()->field_flags().is_injected(), "regular only");
156156
if (field()->field_flags().is_generic()) {
157157
return field()->generic_signature_index();
158158
}
159159
return 0;
160160
}
161161

162-
int initval_index() const {
162+
u2 initval_index() const {
163163
assert(!field()->field_flags().is_injected(), "regular only");
164164
return field()->initializer_index();
165165
}

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

+11-11
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ class Method : public Metadata {
254254
void set_orig_method_idnum(u2 idnum) { constMethod()->set_orig_method_idnum(idnum); }
255255

256256
// code size
257-
int code_size() const { return constMethod()->code_size(); }
257+
u2 code_size() const { return constMethod()->code_size(); }
258258

259259
// method size in words
260260
int method_size() const { return sizeof(Method)/wordSize + ( is_native() ? 2 : 0 ); }
@@ -265,13 +265,13 @@ class Method : public Metadata {
265265

266266
// max stack
267267
// return original max stack size for method verification
268-
int verifier_max_stack() const { return constMethod()->max_stack(); }
269-
int max_stack() const { return constMethod()->max_stack() + extra_stack_entries(); }
270-
void set_max_stack(int size) { constMethod()->set_max_stack(size); }
268+
u2 verifier_max_stack() const { return constMethod()->max_stack(); }
269+
int max_stack() const { return constMethod()->max_stack() + extra_stack_entries(); }
270+
void set_max_stack(int size) { constMethod()->set_max_stack(size); }
271271

272272
// max locals
273-
int max_locals() const { return constMethod()->max_locals(); }
274-
void set_max_locals(int size) { constMethod()->set_max_locals(size); }
273+
u2 max_locals() const { return constMethod()->max_locals(); }
274+
void set_max_locals(int size) { constMethod()->set_max_locals(size); }
275275

276276
int highest_comp_level() const;
277277
void set_highest_comp_level(int level);
@@ -520,18 +520,18 @@ class Method : public Metadata {
520520
int method_parameters_length() const
521521
{ return constMethod()->method_parameters_length(); }
522522
MethodParametersElement* method_parameters_start() const
523-
{ return constMethod()->method_parameters_start(); }
523+
{ return constMethod()->method_parameters_start(); }
524524

525525
// checked exceptions
526-
int checked_exceptions_length() const
526+
u2 checked_exceptions_length() const
527527
{ return constMethod()->checked_exceptions_length(); }
528528
CheckedExceptionElement* checked_exceptions_start() const
529-
{ return constMethod()->checked_exceptions_start(); }
529+
{ return constMethod()->checked_exceptions_start(); }
530530

531531
// localvariable table
532532
bool has_localvariable_table() const
533533
{ return constMethod()->has_localvariable_table(); }
534-
int localvariable_table_length() const
534+
u2 localvariable_table_length() const
535535
{ return constMethod()->localvariable_table_length(); }
536536
LocalVariableTableElement* localvariable_table_start() const
537537
{ return constMethod()->localvariable_table_start(); }
@@ -1038,7 +1038,7 @@ class ExceptionTable : public StackObj {
10381038
}
10391039
}
10401040

1041-
int length() const {
1041+
u2 length() const {
10421042
return _length;
10431043
}
10441044

‎src/hotspot/share/prims/jvmtiClassFileReconstituter.cpp

+30-30
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ void JvmtiClassFileReconstituter::write_field_infos() {
6464
// Compute the real number of Java fields
6565
int java_fields = ik()->java_fields_count();
6666

67-
write_u2(java_fields);
67+
write_u2(checked_cast<u2>(java_fields));
6868
for (JavaFieldStream fs(ik()); !fs.done(); fs.next()) {
6969
AccessFlags access_flags = fs.access_flags();
70-
int name_index = fs.name_index();
71-
int signature_index = fs.signature_index();
72-
int initial_value_index = fs.initval_index();
70+
u2 name_index = fs.name_index();
71+
u2 signature_index = fs.signature_index();
72+
u2 initial_value_index = fs.initval_index();
7373
guarantee(name_index != 0 && signature_index != 0, "bad constant pool index for field");
7474
// int offset = ik()->field_offset( index );
75-
int generic_signature_index = fs.generic_signature_index();
75+
u2 generic_signature_index = fs.generic_signature_index();
7676
AnnotationArray* anno = fields_anno == nullptr ? nullptr : fields_anno->at(fs.index());
7777
AnnotationArray* type_anno = fields_type_anno == nullptr ? nullptr : fields_type_anno->at(fs.index());
7878

@@ -84,10 +84,10 @@ void JvmtiClassFileReconstituter::write_field_infos() {
8484
// JVMSpec| attribute_info attributes[attributes_count];
8585
// JVMSpec| }
8686

87-
write_u2(access_flags.as_int() & JVM_RECOGNIZED_FIELD_MODIFIERS);
87+
write_u2(access_flags.get_flags() & JVM_RECOGNIZED_FIELD_MODIFIERS);
8888
write_u2(name_index);
8989
write_u2(signature_index);
90-
int attr_count = 0;
90+
u2 attr_count = 0;
9191
if (initial_value_index != 0) {
9292
++attr_count;
9393
}
@@ -147,11 +147,11 @@ void JvmtiClassFileReconstituter::write_code_attribute(const methodHandle& metho
147147
ConstMethod* const_method = method->constMethod();
148148
u2 line_num_cnt = 0;
149149
int stackmap_len = 0;
150-
int local_variable_table_length = 0;
151-
int local_variable_type_table_length = 0;
150+
u2 local_variable_table_length = 0;
151+
u2 local_variable_type_table_length = 0;
152152

153153
// compute number and length of attributes
154-
int attr_count = 0;
154+
u2 attr_count = 0;
155155
int attr_size = 0;
156156
if (const_method->has_linenumber_table()) {
157157
line_num_cnt = line_number_table_entries(method);
@@ -229,7 +229,7 @@ void JvmtiClassFileReconstituter::write_code_attribute(const methodHandle& metho
229229
}
230230

231231
ExceptionTable exception_table(method());
232-
int exception_table_length = exception_table.length();
232+
u2 exception_table_length = exception_table.length();
233233
int code_size = const_method->code_size();
234234
int size =
235235
2+2+4 + // max_stack, max_locals, code_length
@@ -276,7 +276,7 @@ void JvmtiClassFileReconstituter::write_code_attribute(const methodHandle& metho
276276
// JVMSpec| }
277277
void JvmtiClassFileReconstituter::write_exceptions_attribute(ConstMethod* const_method) {
278278
CheckedExceptionElement* checked_exceptions = const_method->checked_exceptions_start();
279-
int checked_exceptions_length = const_method->checked_exceptions_length();
279+
u2 checked_exceptions_length = const_method->checked_exceptions_length();
280280
int size =
281281
2 + // number_of_exceptions
282282
2 * checked_exceptions_length; // exception_index_table
@@ -307,7 +307,7 @@ void JvmtiClassFileReconstituter::write_method_parameter_attribute(const ConstMe
307307

308308
write_attribute_name_index("MethodParameters");
309309
write_u4(size);
310-
write_u1(length);
310+
write_u1((u1)length);
311311
for (int index = 0; index < length; index++) {
312312
write_u2(parameters[index].name_cp_index);
313313
write_u2(parameters[index].flags);
@@ -361,7 +361,7 @@ void JvmtiClassFileReconstituter::write_signature_attribute(u2 generic_signature
361361
// Compute the number of entries in the InnerClasses attribute
362362
u2 JvmtiClassFileReconstituter::inner_classes_attribute_length() {
363363
InnerClassesIterator iter(ik());
364-
return iter.length();
364+
return checked_cast<u2>(iter.length());
365365
}
366366

367367
// Write an annotation attribute. The VM stores them in raw form, so all we need
@@ -394,17 +394,17 @@ void JvmtiClassFileReconstituter::write_bootstrapmethod_attribute() {
394394
int num_bootstrap_methods = ConstantPool::operand_array_length(operands);
395395

396396
// calculate length of attribute
397-
int length = sizeof(u2); // num_bootstrap_methods
397+
u4 length = sizeof(u2); // num_bootstrap_methods
398398
for (int n = 0; n < num_bootstrap_methods; n++) {
399399
u2 num_bootstrap_arguments = cpool()->operand_argument_count_at(n);
400400
length += sizeof(u2); // bootstrap_method_ref
401401
length += sizeof(u2); // num_bootstrap_arguments
402-
length += sizeof(u2) * num_bootstrap_arguments; // bootstrap_arguments[num_bootstrap_arguments]
402+
length += (u4)sizeof(u2) * num_bootstrap_arguments; // bootstrap_arguments[num_bootstrap_arguments]
403403
}
404404
write_u4(length);
405405

406406
// write attribute
407-
write_u2(num_bootstrap_methods);
407+
write_u2(checked_cast<u2>(num_bootstrap_methods));
408408
for (int n = 0; n < num_bootstrap_methods; n++) {
409409
u2 bootstrap_method_ref = cpool()->operand_bootstrap_method_ref_index_at(n);
410410
u2 num_bootstrap_arguments = cpool()->operand_argument_count_at(n);
@@ -424,7 +424,7 @@ void JvmtiClassFileReconstituter::write_bootstrapmethod_attribute() {
424424
// }
425425
void JvmtiClassFileReconstituter::write_nest_host_attribute() {
426426
int length = sizeof(u2);
427-
int host_class_index = ik()->nest_host_index();
427+
u2 host_class_index = ik()->nest_host_index();
428428

429429
write_attribute_name_index("NestHost");
430430
write_u4(length);
@@ -444,7 +444,7 @@ void JvmtiClassFileReconstituter::write_nest_members_attribute() {
444444

445445
write_attribute_name_index("NestMembers");
446446
write_u4(length);
447-
write_u2(number_of_classes);
447+
write_u2(checked_cast<u2>(number_of_classes));
448448
for (int i = 0; i < number_of_classes; i++) {
449449
u2 class_cp_index = nest_members->at(i);
450450
write_u2(class_cp_index);
@@ -464,7 +464,7 @@ void JvmtiClassFileReconstituter::write_permitted_subclasses_attribute() {
464464

465465
write_attribute_name_index("PermittedSubclasses");
466466
write_u4(length);
467-
write_u2(number_of_classes);
467+
write_u2(checked_cast<u2>(number_of_classes));
468468
for (int i = 0; i < number_of_classes; i++) {
469469
u2 class_cp_index = permitted_subclasses->at(i);
470470
write_u2(class_cp_index);
@@ -488,7 +488,7 @@ void JvmtiClassFileReconstituter::write_record_attribute() {
488488
int number_of_components = components->length();
489489

490490
// Each component has a u2 for name, descr, attribute count
491-
int length = sizeof(u2) + (sizeof(u2) * 3 * number_of_components);
491+
u4 length = checked_cast<u4>(sizeof(u2) + (sizeof(u2) * 3 * number_of_components));
492492
for (int x = 0; x < number_of_components; x++) {
493493
RecordComponent* component = components->at(x);
494494
if (component->generic_signature_index() != 0) {
@@ -505,7 +505,7 @@ void JvmtiClassFileReconstituter::write_record_attribute() {
505505

506506
write_attribute_name_index("Record");
507507
write_u4(length);
508-
write_u2(number_of_components);
508+
write_u2(checked_cast<u2>(number_of_components));
509509
for (int i = 0; i < number_of_components; i++) {
510510
RecordComponent* component = components->at(i);
511511
write_u2(component->name_index());
@@ -538,7 +538,7 @@ void JvmtiClassFileReconstituter::write_inner_classes_attribute(int length) {
538538
InnerClassesIterator iter(ik());
539539
guarantee(iter.length() != 0 && iter.length() == length,
540540
"caller must check");
541-
u2 entry_count = length / InstanceKlass::inner_class_next_offset;
541+
u2 entry_count = checked_cast<u2>(length / InstanceKlass::inner_class_next_offset);
542542
u4 size = 2 + entry_count * (2+2+2+2);
543543

544544
write_attribute_name_index("InnerClasses");
@@ -592,8 +592,8 @@ void JvmtiClassFileReconstituter::write_line_number_table_attribute(const method
592592

593593
CompressedLineNumberReadStream stream(method->compressed_linenumber_table());
594594
while (stream.read_pair()) {
595-
write_u2(stream.bci());
596-
write_u2(stream.line());
595+
write_u2(checked_cast<u2>(stream.bci()));
596+
write_u2(checked_cast<u2>(stream.line()));
597597
}
598598
}
599599

@@ -736,7 +736,7 @@ void JvmtiClassFileReconstituter::write_method_info(const methodHandle& method)
736736
++attr_count; // has RuntimeVisibleTypeAnnotations attribute
737737
}
738738

739-
write_u2(attr_count);
739+
write_u2(checked_cast<u2>(attr_count));
740740
if (const_method->code_size() > 0) {
741741
write_code_attribute(method);
742742
}
@@ -776,7 +776,7 @@ void JvmtiClassFileReconstituter::write_class_attributes() {
776776
AnnotationArray* anno = ik()->class_annotations();
777777
AnnotationArray* type_anno = ik()->class_type_annotations();
778778

779-
int attr_count = 0;
779+
u2 attr_count = 0;
780780
if (generic_signature != nullptr) {
781781
++attr_count;
782782
}
@@ -867,7 +867,7 @@ void JvmtiClassFileReconstituter::write_method_infos() {
867867
}
868868
}
869869

870-
write_u2(num_methods - num_overpass);
870+
write_u2(checked_cast<u2>(num_methods - num_overpass));
871871
if (JvmtiExport::can_maintain_original_method_order()) {
872872
int index;
873873
int original_index;
@@ -911,7 +911,7 @@ void JvmtiClassFileReconstituter::write_class_file_format() {
911911

912912
// JVMSpec| u2 constant_pool_count;
913913
// JVMSpec| cp_info constant_pool[constant_pool_count-1];
914-
write_u2(cpool()->length());
914+
write_u2(checked_cast<u2>(cpool()->length()));
915915
copy_cpool_bytes(writeable_address(cpool_size()));
916916

917917
// JVMSpec| u2 access_flags;
@@ -928,7 +928,7 @@ void JvmtiClassFileReconstituter::write_class_file_format() {
928928
// JVMSpec| u2 interfaces[interfaces_count];
929929
Array<InstanceKlass*>* interfaces = ik()->local_interfaces();
930930
int num_interfaces = interfaces->length();
931-
write_u2(num_interfaces);
931+
write_u2(checked_cast<u2>(num_interfaces));
932932
for (int index = 0; index < num_interfaces; index++) {
933933
HandleMark hm(thread());
934934
InstanceKlass* iik = interfaces->at(index);

‎src/hotspot/share/prims/jvmtiCodeBlobEvents.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,7 @@ void JvmtiCodeBlobEvents::build_jvmti_addr_location_map(nmethod *nm,
271271

272272
if (!mh->is_native()) {
273273
PcDesc *pcd;
274-
int pcds_in_method;
275-
276-
pcds_in_method = (nm->scopes_pcs_end() - nm->scopes_pcs_begin());
274+
int pcds_in_method = pointer_delta_as_int(nm->scopes_pcs_end(), nm->scopes_pcs_begin());
277275
map = NEW_C_HEAP_ARRAY(jvmtiAddrLocationMap, pcds_in_method, mtInternal);
278276

279277
address scopes_data = nm->scopes_data_begin();

‎src/hotspot/share/prims/jvmtiEnvBase.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ JvmtiEnvBase::phase() {
145145

146146
bool
147147
JvmtiEnvBase::is_valid() {
148-
jint value = 0;
148+
jlong value = 0;
149149

150150
// This object might not be a JvmtiEnvBase so we can't assume
151151
// the _magic field is properly aligned. Get the value in a safe
@@ -616,7 +616,7 @@ JvmtiEnvBase::get_field_descriptor(Klass* k, jfieldID field, fieldDescriptor* fd
616616
found = id->find_local_field(fd);
617617
} else {
618618
// Non-static field. The fieldID is really the offset of the field within the object.
619-
int offset = jfieldIDWorkaround::from_instance_jfieldID(k, field);
619+
int offset = checked_cast<int>(jfieldIDWorkaround::from_instance_jfieldID(k, field));
620620
found = InstanceKlass::cast(k)->find_field_from_offset(offset, false, fd);
621621
}
622622
return found;
@@ -796,7 +796,7 @@ JvmtiEnvBase::get_vthread_state(oop thread_oop, JavaThread* java_thread) {
796796
// This call can trigger a safepoint, so thread_oop must not be used after it.
797797
state = get_thread_state_base(ct_oop, java_thread) & ~filtered_bits;
798798
} else {
799-
jshort vt_state = java_lang_VirtualThread::state(thread_oop);
799+
int vt_state = java_lang_VirtualThread::state(thread_oop);
800800
state = (jint)java_lang_VirtualThread::map_state_to_thread_status(vt_state);
801801
}
802802
if (ext_suspended && ((state & JVMTI_THREAD_STATE_ALIVE) != 0)) {
@@ -2549,7 +2549,7 @@ VirtualThreadGetFrameLocationClosure::do_thread(Thread *target) {
25492549
void
25502550
VirtualThreadGetThreadStateClosure::do_thread(Thread *target) {
25512551
assert(target->is_Java_thread(), "just checking");
2552-
jshort vthread_state = java_lang_VirtualThread::state(_vthread_h());
2552+
int vthread_state = java_lang_VirtualThread::state(_vthread_h());
25532553
oop carrier_thread_oop = java_lang_VirtualThread::carrier_thread(_vthread_h());
25542554
jint state;
25552555

‎src/hotspot/share/prims/jvmtiEnvThreadState.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ void JvmtiEnvThreadState::set_agent_thread_local_storage_data (void *data) {
175175
void JvmtiEnvThreadState::compare_and_set_current_location(Method* new_method,
176176
address new_location, jvmtiEvent event) {
177177

178-
int new_bci = new_location - new_method->code_base();
178+
int new_bci = pointer_delta_as_int(new_location, new_method->code_base());
179179

180180
// The method is identified and stored as a jmethodID which is safe in this
181181
// case because the class cannot be unloaded while a method is executing.

‎src/hotspot/share/prims/jvmtiExport.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ class JvmtiClassFileLoadHookPoster : public StackObj {
910910
_data_ptr = data_ptr;
911911
_end_ptr = end_ptr;
912912
_thread = JavaThread::current();
913-
_curr_len = *end_ptr - *data_ptr;
913+
_curr_len = pointer_delta_as_int(*end_ptr, *data_ptr);
914914
_curr_data = *data_ptr;
915915
_curr_env = nullptr;
916916
_cached_class_file_ptr = cache_ptr;

‎src/hotspot/share/prims/jvmtiManageCapabilities.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2023, 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
@@ -182,7 +182,7 @@ jvmtiCapabilities *JvmtiManageCapabilities::exclude(const jvmtiCapabilities *a,
182182
char *resultp = (char *)result;
183183

184184
for (int i = 0; i < CAPA_SIZE; ++i) {
185-
*resultp++ = *ap++ & ~*bp++;
185+
*resultp++ = *ap++ & (char)~*bp++;
186186
}
187187

188188
return result;

‎src/hotspot/share/prims/jvmtiRawMonitor.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ JvmtiRawMonitor::~JvmtiRawMonitor() {
8080

8181
bool
8282
JvmtiRawMonitor::is_valid() {
83-
int value = 0;
83+
jlong value = 0;
8484

8585
// This object might not be a JvmtiRawMonitor so we can't assume
8686
// the _magic field is properly aligned. Get the value in a safe
@@ -382,7 +382,7 @@ int JvmtiRawMonitor::raw_wait(jlong millis, Thread* self) {
382382
self->_ParkEvent->reset();
383383
OrderAccess::fence();
384384

385-
intptr_t save = _recursions;
385+
int save = _recursions;
386386
_recursions = 0;
387387
ret = simple_wait(self, millis);
388388

‎src/hotspot/share/prims/jvmtiRedefineClasses.cpp

+23-18
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ void VM_RedefineClasses::append_entry(const constantPoolHandle& scratch_cp,
622622
} // end append_entry()
623623

624624

625-
int VM_RedefineClasses::find_or_append_indirect_entry(const constantPoolHandle& scratch_cp,
625+
u2 VM_RedefineClasses::find_or_append_indirect_entry(const constantPoolHandle& scratch_cp,
626626
int ref_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p) {
627627

628628
int new_ref_i = ref_i;
@@ -647,7 +647,9 @@ int VM_RedefineClasses::find_or_append_indirect_entry(const constantPoolHandle&
647647
}
648648
}
649649

650-
return new_ref_i;
650+
// constant pool indices are u2, unless the merged constant pool overflows which
651+
// we don't check for.
652+
return checked_cast<u2>(new_ref_i);
651653
} // end find_or_append_indirect_entry()
652654

653655

@@ -657,9 +659,9 @@ int VM_RedefineClasses::find_or_append_indirect_entry(const constantPoolHandle&
657659
void VM_RedefineClasses::append_operand(const constantPoolHandle& scratch_cp, int old_bs_i,
658660
constantPoolHandle *merge_cp_p, int *merge_cp_length_p) {
659661

660-
int old_ref_i = scratch_cp->operand_bootstrap_method_ref_index_at(old_bs_i);
661-
int new_ref_i = find_or_append_indirect_entry(scratch_cp, old_ref_i, merge_cp_p,
662-
merge_cp_length_p);
662+
u2 old_ref_i = scratch_cp->operand_bootstrap_method_ref_index_at(old_bs_i);
663+
u2 new_ref_i = find_or_append_indirect_entry(scratch_cp, old_ref_i, merge_cp_p,
664+
merge_cp_length_p);
663665
if (new_ref_i != old_ref_i) {
664666
log_trace(redefine, class, constantpool)
665667
("operands entry@%d bootstrap method ref_index change: %d to %d", _operands_cur_length, old_ref_i, new_ref_i);
@@ -671,16 +673,16 @@ void VM_RedefineClasses::append_operand(const constantPoolHandle& scratch_cp, in
671673
// However, the operand_offset_at(0) was set in the extend_operands() call.
672674
int new_base = (new_bs_i == 0) ? (*merge_cp_p)->operand_offset_at(0)
673675
: (*merge_cp_p)->operand_next_offset_at(new_bs_i - 1);
674-
int argc = scratch_cp->operand_argument_count_at(old_bs_i);
676+
u2 argc = scratch_cp->operand_argument_count_at(old_bs_i);
675677

676678
ConstantPool::operand_offset_at_put(merge_ops, _operands_cur_length, new_base);
677679
merge_ops->at_put(new_base++, new_ref_i);
678680
merge_ops->at_put(new_base++, argc);
679681

680682
for (int i = 0; i < argc; i++) {
681-
int old_arg_ref_i = scratch_cp->operand_argument_index_at(old_bs_i, i);
682-
int new_arg_ref_i = find_or_append_indirect_entry(scratch_cp, old_arg_ref_i, merge_cp_p,
683-
merge_cp_length_p);
683+
u2 old_arg_ref_i = scratch_cp->operand_argument_index_at(old_bs_i, i);
684+
u2 new_arg_ref_i = find_or_append_indirect_entry(scratch_cp, old_arg_ref_i, merge_cp_p,
685+
merge_cp_length_p);
684686
merge_ops->at_put(new_base++, new_arg_ref_i);
685687
if (new_arg_ref_i != old_arg_ref_i) {
686688
log_trace(redefine, class, constantpool)
@@ -1234,7 +1236,7 @@ jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
12341236
// Find new constant pool index value for old constant pool index value
12351237
// by searching the index map. Returns zero (0) if there is no mapped
12361238
// value for the old constant pool index.
1237-
int VM_RedefineClasses::find_new_index(int old_index) {
1239+
u2 VM_RedefineClasses::find_new_index(int old_index) {
12381240
if (_index_map_count == 0) {
12391241
// map is empty so nothing can be found
12401242
return 0;
@@ -1253,7 +1255,9 @@ int VM_RedefineClasses::find_new_index(int old_index) {
12531255
return 0;
12541256
}
12551257

1256-
return value;
1258+
// constant pool indices are u2, unless the merged constant pool overflows which
1259+
// we don't check for.
1260+
return checked_cast<u2>(value);
12571261
} // end find_new_index()
12581262

12591263

@@ -2188,8 +2192,8 @@ void VM_RedefineClasses::rewrite_cp_refs_in_method(methodHandle method,
21882192
switch (c) {
21892193
case Bytecodes::_ldc:
21902194
{
2191-
int cp_index = *(bcp + 1);
2192-
int new_index = find_new_index(cp_index);
2195+
u1 cp_index = *(bcp + 1);
2196+
u2 new_index = find_new_index(cp_index);
21932197

21942198
if (StressLdcRewrite && new_index == 0) {
21952199
// If we are stressing ldc -> ldc_w rewriting, then we
@@ -2203,7 +2207,8 @@ void VM_RedefineClasses::rewrite_cp_refs_in_method(methodHandle method,
22032207
// unless we are trying to stress ldc -> ldc_w rewriting
22042208
log_trace(redefine, class, constantpool)
22052209
("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c), p2i(bcp), cp_index, new_index);
2206-
*(bcp + 1) = new_index;
2210+
// We checked that new_index fits in a u1 so this cast is safe
2211+
*(bcp + 1) = (u1)new_index;
22072212
} else {
22082213
log_trace(redefine, class, constantpool)
22092214
("%s->ldc_w@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c), p2i(bcp), cp_index, new_index);
@@ -2262,7 +2267,7 @@ void VM_RedefineClasses::rewrite_cp_refs_in_method(methodHandle method,
22622267
{
22632268
address p = bcp + 1;
22642269
int cp_index = Bytes::get_Java_u2(p);
2265-
int new_index = find_new_index(cp_index);
2270+
u2 new_index = find_new_index(cp_index);
22662271
if (new_index != 0) {
22672272
// the original index is mapped so update w/ new value
22682273
log_trace(redefine, class, constantpool)
@@ -3600,7 +3605,7 @@ void VM_RedefineClasses::set_new_constant_pool(
36003605
if (cur_index == 0) {
36013606
continue; // JVM spec. allows null inner class refs so skip it
36023607
}
3603-
int new_index = find_new_index(cur_index);
3608+
u2 new_index = find_new_index(cur_index);
36043609
if (new_index != 0) {
36053610
log_trace(redefine, class, constantpool)("inner_class_info change: %d to %d", cur_index, new_index);
36063611
iter.set_inner_class_info_index(new_index);
@@ -3626,7 +3631,7 @@ void VM_RedefineClasses::set_new_constant_pool(
36263631
methodHandle method(THREAD, methods->at(i));
36273632
method->set_constants(scratch_cp());
36283633

3629-
int new_index = find_new_index(method->name_index());
3634+
u2 new_index = find_new_index(method->name_index());
36303635
if (new_index != 0) {
36313636
log_trace(redefine, class, constantpool)
36323637
("method-name_index change: %d to %d", method->name_index(), new_index);
@@ -3671,7 +3676,7 @@ void VM_RedefineClasses::set_new_constant_pool(
36713676

36723677
for (int j = 0; j < ext_length; j ++) {
36733678
int cur_index = ex_table.catch_type_index(j);
3674-
int new_index = find_new_index(cur_index);
3679+
u2 new_index = find_new_index(cur_index);
36753680
if (new_index != 0) {
36763681
log_trace(redefine, class, constantpool)("ext-klass_index change: %d to %d", cur_index, new_index);
36773682
ex_table.set_catch_type_index(j, new_index);

‎src/hotspot/share/prims/jvmtiRedefineClasses.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -432,11 +432,11 @@ class VM_RedefineClasses: public VM_Operation {
432432
void append_operand(const constantPoolHandle& scratch_cp, int scratch_bootstrap_spec_index,
433433
constantPoolHandle *merge_cp_p, int *merge_cp_length_p);
434434
void finalize_operands_merge(const constantPoolHandle& merge_cp, TRAPS);
435-
int find_or_append_indirect_entry(const constantPoolHandle& scratch_cp, int scratch_i,
435+
u2 find_or_append_indirect_entry(const constantPoolHandle& scratch_cp, int scratch_i,
436436
constantPoolHandle *merge_cp_p, int *merge_cp_length_p);
437437
int find_or_append_operand(const constantPoolHandle& scratch_cp, int scratch_bootstrap_spec_index,
438438
constantPoolHandle *merge_cp_p, int *merge_cp_length_p);
439-
int find_new_index(int old_index);
439+
u2 find_new_index(int old_index);
440440
int find_new_operand_index(int old_bootstrap_spec_index);
441441
bool is_unresolved_class_mismatch(const constantPoolHandle& cp1, int index1,
442442
const constantPoolHandle& cp2, int index2);

‎src/hotspot/share/prims/jvmtiTrace.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ void JvmtiTrace::initialize() {
202202
if (op == '+') {
203203
_trace_flags[i] |= bits;
204204
} else {
205-
_trace_flags[i] &= ~bits;
205+
_trace_flags[i] &= (jbyte)~bits;
206206
}
207207
_on = true;
208208
}
@@ -231,7 +231,7 @@ void JvmtiTrace::initialize() {
231231
if (op == '+') {
232232
_event_trace_flags[i] |= bits;
233233
} else {
234-
_event_trace_flags[i] &= ~bits;
234+
_event_trace_flags[i] &= (jbyte)~bits;
235235
}
236236
_on = true;
237237
}

‎src/hotspot/share/prims/methodComparator.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ bool MethodComparator::args_same(Bytecodes::Code const c_old, Bytecodes::Code c
7575
case Bytecodes::_multianewarray : // fall through
7676
case Bytecodes::_checkcast : // fall through
7777
case Bytecodes::_instanceof : {
78-
u2 cpi_old = s_old->get_index_u2();
79-
u2 cpi_new = s_new->get_index_u2();
78+
int cpi_old = s_old->get_index_u2();
79+
int cpi_new = s_new->get_index_u2();
8080
if (old_cp->klass_at_noresolve(cpi_old) != new_cp->klass_at_noresolve(cpi_new))
8181
return false;
8282
if (c_old == Bytecodes::_multianewarray &&
@@ -155,8 +155,8 @@ bool MethodComparator::args_same(Bytecodes::Code const c_old, Bytecodes::Code c
155155
}
156156

157157
case Bytecodes::_ldc2_w : {
158-
u2 cpi_old = s_old->get_index_u2();
159-
u2 cpi_new = s_new->get_index_u2();
158+
int cpi_old = s_old->get_index_u2();
159+
int cpi_new = s_new->get_index_u2();
160160
constantTag tag_old = old_cp->tag_at(cpi_old);
161161
constantTag tag_new = new_cp->tag_at(cpi_new);
162162
if (tag_old.value() != tag_new.value())

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2023, 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
@@ -89,7 +89,7 @@ class jfieldIDWorkaround: AllStatic {
8989
if (VerifyJNIFields && is_checked_jfieldID(id)) {
9090
result &= small_offset_mask; // cut off the hash bits
9191
}
92-
return (intptr_t)result;
92+
return result;
9393
}
9494
static intptr_t encode_klass_hash(Klass* k, intptr_t offset);
9595
static bool klass_hash_ok(Klass* k, jfieldID id);

0 commit comments

Comments
 (0)
Please sign in to comment.