7123315: instanceKlass::_static_oop_field_count and instanceKlass::_java_fields_count should be u2 type.
Summary: Change instanceKlass::_static_oop_field_count and instanceKlass::_java_fields_count to u2 type.
Reviewed-by: never, bdelsart, dholmes
Contributed-by: Jiangli Zhou <jiangli.zhou@oracle.com>
--- a/hotspot/src/share/vm/classfile/classFileParser.cpp Tue Dec 20 12:33:05 2011 +0100
+++ b/hotspot/src/share/vm/classfile/classFileParser.cpp Wed Dec 28 12:15:57 2011 -0500
@@ -1050,7 +1050,7 @@
class FieldAllocationCount: public ResourceObj {
public:
- unsigned int count[MAX_FIELD_ALLOCATION_TYPE];
+ u2 count[MAX_FIELD_ALLOCATION_TYPE];
FieldAllocationCount() {
for (int i = 0; i < MAX_FIELD_ALLOCATION_TYPE; i++) {
@@ -1060,6 +1060,8 @@
FieldAllocationType update(bool is_static, BasicType type) {
FieldAllocationType atype = basic_type_to_atype(is_static, type);
+ // Make sure there is no overflow with injected fields.
+ assert(count[atype] < 0xFFFF, "More than 65535 fields");
count[atype]++;
return atype;
}
@@ -1070,7 +1072,7 @@
constantPoolHandle cp, bool is_interface,
FieldAllocationCount *fac,
objArrayHandle* fields_annotations,
- int* java_fields_count_ptr, TRAPS) {
+ u2* java_fields_count_ptr, TRAPS) {
ClassFileStream* cfs = stream();
typeArrayHandle nullHandle;
cfs->guarantee_more(2, CHECK_(nullHandle)); // length
@@ -2843,7 +2845,7 @@
local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, CHECK_(nullHandle));
}
- int java_fields_count = 0;
+ u2 java_fields_count = 0;
// Fields (offsets are filled in later)
FieldAllocationCount fac;
objArrayHandle fields_annotations;
--- a/hotspot/src/share/vm/classfile/classFileParser.hpp Tue Dec 20 12:33:05 2011 +0100
+++ b/hotspot/src/share/vm/classfile/classFileParser.hpp Wed Dec 28 12:15:57 2011 -0500
@@ -91,7 +91,7 @@
constantPoolHandle cp, bool is_interface,
FieldAllocationCount *fac,
objArrayHandle* fields_annotations,
- int* java_fields_count_ptr, TRAPS);
+ u2* java_fields_count_ptr, TRAPS);
// Method parsing
methodHandle parse_method(constantPoolHandle cp, bool is_interface,
--- a/hotspot/src/share/vm/oops/instanceKlass.hpp Tue Dec 20 12:33:05 2011 +0100
+++ b/hotspot/src/share/vm/oops/instanceKlass.hpp Wed Dec 28 12:15:57 2011 -0500
@@ -227,9 +227,9 @@
// (including inherited fields but after header_size()).
int _nonstatic_field_size;
int _static_field_size; // number words used by static fields (oop and non-oop) in this klass
- int _static_oop_field_count;// number of static oop fields in this klass
+ u2 _static_oop_field_count;// number of static oop fields in this klass
+ u2 _java_fields_count; // The number of declared Java fields
int _nonstatic_oop_map_size;// size in words of nonstatic oop map blocks
- int _java_fields_count; // The number of declared Java fields
u2 _minor_version; // minor version number of class file
u2 _major_version; // major version number of class file
@@ -299,8 +299,8 @@
int static_field_size() const { return _static_field_size; }
void set_static_field_size(int size) { _static_field_size = size; }
- int static_oop_field_count() const { return _static_oop_field_count; }
- void set_static_oop_field_count(int size) { _static_oop_field_count = size; }
+ int static_oop_field_count() const { return (int)_static_oop_field_count; }
+ void set_static_oop_field_count(u2 size) { _static_oop_field_count = size; }
// Java vtable
int vtable_length() const { return _vtable_len; }
@@ -340,14 +340,14 @@
Symbol* field_signature (int index) const { return field(index)->signature(constants()); }
// Number of Java declared fields
- int java_fields_count() const { return _java_fields_count; }
+ int java_fields_count() const { return (int)_java_fields_count; }
// Number of fields including any injected fields
int all_fields_count() const { return _fields->length() / sizeof(FieldInfo::field_slots); }
typeArrayOop fields() const { return _fields; }
- void set_fields(typeArrayOop f, int java_fields_count) {
+ void set_fields(typeArrayOop f, u2 java_fields_count) {
oop_store_without_check((oop*) &_fields, (oop) f);
_java_fields_count = java_fields_count;
}
--- a/hotspot/src/share/vm/runtime/vmStructs.cpp Tue Dec 20 12:33:05 2011 +0100
+++ b/hotspot/src/share/vm/runtime/vmStructs.cpp Wed Dec 28 12:15:57 2011 -0500
@@ -295,7 +295,7 @@
nonstatic_field(instanceKlass, _nof_implementors, int) \
nonstatic_field(instanceKlass, _implementors[0], klassOop) \
nonstatic_field(instanceKlass, _fields, typeArrayOop) \
- nonstatic_field(instanceKlass, _java_fields_count, int) \
+ nonstatic_field(instanceKlass, _java_fields_count, u2) \
nonstatic_field(instanceKlass, _constants, constantPoolOop) \
nonstatic_field(instanceKlass, _class_loader, oop) \
nonstatic_field(instanceKlass, _protection_domain, oop) \
@@ -305,7 +305,7 @@
nonstatic_field(instanceKlass, _inner_classes, typeArrayOop) \
nonstatic_field(instanceKlass, _nonstatic_field_size, int) \
nonstatic_field(instanceKlass, _static_field_size, int) \
- nonstatic_field(instanceKlass, _static_oop_field_count, int) \
+ nonstatic_field(instanceKlass, _static_oop_field_count, u2) \
nonstatic_field(instanceKlass, _nonstatic_oop_map_size, int) \
nonstatic_field(instanceKlass, _misc_flags, u1) \
nonstatic_field(instanceKlass, _minor_version, u2) \