Skip to content

Commit 48d7943

Browse files
committedSep 5, 2024
8339342: FieldAllocationCount is mostly unused
Reviewed-by: fparain, stuefe, matsaave
1 parent e203df4 commit 48d7943

File tree

2 files changed

+7
-104
lines changed

2 files changed

+7
-104
lines changed
 

‎src/hotspot/share/classfile/classFileParser.cpp

+6-101
Original file line numberDiff line numberDiff line change
@@ -1352,105 +1352,16 @@ void ClassFileParser::parse_field_attributes(const ClassFileStream* const cfs,
13521352
}
13531353

13541354

1355-
// Field allocation types. Used for computing field offsets.
1356-
1357-
enum FieldAllocationType {
1358-
STATIC_OOP, // Oops
1359-
STATIC_BYTE, // Boolean, Byte, char
1360-
STATIC_SHORT, // shorts
1361-
STATIC_WORD, // ints
1362-
STATIC_DOUBLE, // aligned long or double
1363-
NONSTATIC_OOP,
1364-
NONSTATIC_BYTE,
1365-
NONSTATIC_SHORT,
1366-
NONSTATIC_WORD,
1367-
NONSTATIC_DOUBLE,
1368-
MAX_FIELD_ALLOCATION_TYPE,
1369-
BAD_ALLOCATION_TYPE = -1
1370-
};
1371-
1372-
static FieldAllocationType _basic_type_to_atype[2 * (T_CONFLICT + 1)] = {
1373-
BAD_ALLOCATION_TYPE, // 0
1374-
BAD_ALLOCATION_TYPE, // 1
1375-
BAD_ALLOCATION_TYPE, // 2
1376-
BAD_ALLOCATION_TYPE, // 3
1377-
NONSTATIC_BYTE , // T_BOOLEAN = 4,
1378-
NONSTATIC_SHORT, // T_CHAR = 5,
1379-
NONSTATIC_WORD, // T_FLOAT = 6,
1380-
NONSTATIC_DOUBLE, // T_DOUBLE = 7,
1381-
NONSTATIC_BYTE, // T_BYTE = 8,
1382-
NONSTATIC_SHORT, // T_SHORT = 9,
1383-
NONSTATIC_WORD, // T_INT = 10,
1384-
NONSTATIC_DOUBLE, // T_LONG = 11,
1385-
NONSTATIC_OOP, // T_OBJECT = 12,
1386-
NONSTATIC_OOP, // T_ARRAY = 13,
1387-
BAD_ALLOCATION_TYPE, // T_VOID = 14,
1388-
BAD_ALLOCATION_TYPE, // T_ADDRESS = 15,
1389-
BAD_ALLOCATION_TYPE, // T_NARROWOOP = 16,
1390-
BAD_ALLOCATION_TYPE, // T_METADATA = 17,
1391-
BAD_ALLOCATION_TYPE, // T_NARROWKLASS = 18,
1392-
BAD_ALLOCATION_TYPE, // T_CONFLICT = 19,
1393-
BAD_ALLOCATION_TYPE, // 0
1394-
BAD_ALLOCATION_TYPE, // 1
1395-
BAD_ALLOCATION_TYPE, // 2
1396-
BAD_ALLOCATION_TYPE, // 3
1397-
STATIC_BYTE , // T_BOOLEAN = 4,
1398-
STATIC_SHORT, // T_CHAR = 5,
1399-
STATIC_WORD, // T_FLOAT = 6,
1400-
STATIC_DOUBLE, // T_DOUBLE = 7,
1401-
STATIC_BYTE, // T_BYTE = 8,
1402-
STATIC_SHORT, // T_SHORT = 9,
1403-
STATIC_WORD, // T_INT = 10,
1404-
STATIC_DOUBLE, // T_LONG = 11,
1405-
STATIC_OOP, // T_OBJECT = 12,
1406-
STATIC_OOP, // T_ARRAY = 13,
1407-
BAD_ALLOCATION_TYPE, // T_VOID = 14,
1408-
BAD_ALLOCATION_TYPE, // T_ADDRESS = 15,
1409-
BAD_ALLOCATION_TYPE, // T_NARROWOOP = 16,
1410-
BAD_ALLOCATION_TYPE, // T_METADATA = 17,
1411-
BAD_ALLOCATION_TYPE, // T_NARROWKLASS = 18,
1412-
BAD_ALLOCATION_TYPE, // T_CONFLICT = 19,
1413-
};
1414-
1415-
static FieldAllocationType basic_type_to_atype(bool is_static, BasicType type) {
1416-
assert(type >= T_BOOLEAN && type < T_VOID, "only allowable values");
1417-
FieldAllocationType result = _basic_type_to_atype[type + (is_static ? (T_CONFLICT + 1) : 0)];
1418-
assert(result != BAD_ALLOCATION_TYPE, "bad type");
1419-
return result;
1420-
}
1421-
1422-
class ClassFileParser::FieldAllocationCount : public ResourceObj {
1423-
public:
1424-
u2 count[MAX_FIELD_ALLOCATION_TYPE];
1425-
1426-
FieldAllocationCount() {
1427-
for (int i = 0; i < MAX_FIELD_ALLOCATION_TYPE; i++) {
1428-
count[i] = 0;
1429-
}
1430-
}
1431-
1432-
void update(bool is_static, BasicType type) {
1433-
FieldAllocationType atype = basic_type_to_atype(is_static, type);
1434-
if (atype != BAD_ALLOCATION_TYPE) {
1435-
// Make sure there is no overflow with injected fields.
1436-
assert(count[atype] < 0xFFFF, "More than 65535 fields");
1437-
count[atype]++;
1438-
}
1439-
}
1440-
};
1441-
14421355
// Side-effects: populates the _fields, _fields_annotations,
14431356
// _fields_type_annotations fields
14441357
void ClassFileParser::parse_fields(const ClassFileStream* const cfs,
14451358
bool is_interface,
1446-
FieldAllocationCount* const fac,
14471359
ConstantPool* cp,
14481360
const int cp_size,
14491361
u2* const java_fields_count_ptr,
14501362
TRAPS) {
14511363

14521364
assert(cfs != nullptr, "invariant");
1453-
assert(fac != nullptr, "invariant");
14541365
assert(cp != nullptr, "invariant");
14551366
assert(java_fields_count_ptr != nullptr, "invariant");
14561367

@@ -1544,8 +1455,10 @@ void ClassFileParser::parse_fields(const ClassFileStream* const cfs,
15441455

15451456
const BasicType type = cp->basic_type_for_signature_at(signature_index);
15461457

1547-
// Update FieldAllocationCount for this kind of field
1548-
fac->update(is_static, type);
1458+
// Update number of static oop fields.
1459+
if (is_static && is_reference_type(type)) {
1460+
_static_oop_count++;
1461+
}
15491462

15501463
FieldInfo fi(access_flags, name_index, signature_index, constantvalue_index, fieldFlags);
15511464
fi.set_index(n);
@@ -1590,10 +1503,6 @@ void ClassFileParser::parse_fields(const ClassFileStream* const cfs,
15901503
FieldInfo fi(aflags, (u2)(injected[n].name_index), (u2)(injected[n].signature_index), 0, fflags);
15911504
fi.set_index(index);
15921505
_temp_field_info->append(fi);
1593-
1594-
// Update FieldAllocationCount for this kind of field
1595-
const BasicType type = Signature::basic_type(injected[n].signature());
1596-
fac->update(false, type);
15971506
index++;
15981507
}
15991508
}
@@ -5117,8 +5026,7 @@ void ClassFileParser::fill_instance_klass(InstanceKlass* ik,
51175026
// Not yet: supers are done below to support the new subtype-checking fields
51185027
ik->set_nonstatic_field_size(_field_info->_nonstatic_field_size);
51195028
ik->set_has_nonstatic_fields(_field_info->_has_nonstatic_fields);
5120-
assert(_fac != nullptr, "invariant");
5121-
ik->set_static_oop_field_count(_fac->count[STATIC_OOP]);
5029+
ik->set_static_oop_field_count(_static_oop_count);
51225030

51235031
// this transfers ownership of a lot of arrays from
51245032
// the parser onto the InstanceKlass*
@@ -5360,6 +5268,7 @@ ClassFileParser::ClassFileParser(ClassFileStream* stream,
53605268
_is_hidden(cl_info->is_hidden()),
53615269
_can_access_vm_annotations(cl_info->can_access_vm_annotations()),
53625270
_orig_cp_size(0),
5271+
_static_oop_count(0),
53635272
_super_klass(),
53645273
_cp(nullptr),
53655274
_fieldinfo_stream(nullptr),
@@ -5380,7 +5289,6 @@ ClassFileParser::ClassFileParser(ClassFileStream* stream,
53805289
_klass(nullptr),
53815290
_klass_to_deallocate(nullptr),
53825291
_parsed_annotations(nullptr),
5383-
_fac(nullptr),
53845292
_field_info(nullptr),
53855293
_temp_field_info(nullptr),
53865294
_method_ordering(nullptr),
@@ -5706,10 +5614,8 @@ void ClassFileParser::parse_stream(const ClassFileStream* const stream,
57065614
assert(_local_interfaces != nullptr, "invariant");
57075615

57085616
// Fields (offsets are filled in later)
5709-
_fac = new FieldAllocationCount();
57105617
parse_fields(stream,
57115618
_access_flags.is_interface(),
5712-
_fac,
57135619
cp,
57145620
cp_size,
57155621
&_java_fields_count,
@@ -5867,7 +5773,6 @@ void ClassFileParser::post_process_parsed_stream(const ClassFileStream* const st
58675773
_itable_size = _access_flags.is_interface() ? 0 :
58685774
klassItable::compute_itable_size(_transitive_interfaces);
58695775

5870-
assert(_fac != nullptr, "invariant");
58715776
assert(_parsed_annotations != nullptr, "invariant");
58725777

58735778
_field_info = new FieldLayoutInfo();

‎src/hotspot/share/classfile/classFileParser.hpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ class ClassFileParser {
8686
friend class FieldLayout;
8787

8888
class ClassAnnotationCollector;
89-
class FieldAllocationCount;
9089
class FieldAnnotationCollector;
9190

9291
public:
@@ -116,6 +115,7 @@ class ClassFileParser {
116115
const bool _is_hidden;
117116
const bool _can_access_vm_annotations;
118117
int _orig_cp_size;
118+
unsigned int _static_oop_count;
119119

120120
// Metadata created before the instance klass is created. Must be deallocated
121121
// if not transferred to the InstanceKlass upon successful class loading
@@ -141,7 +141,6 @@ class ClassFileParser {
141141
InstanceKlass* _klass_to_deallocate; // an InstanceKlass* to be destroyed
142142

143143
ClassAnnotationCollector* _parsed_annotations;
144-
FieldAllocationCount* _fac;
145144
FieldLayoutInfo* _field_info;
146145
GrowableArray<FieldInfo>* _temp_field_info;
147146
const intArray* _method_ordering;
@@ -260,7 +259,6 @@ class ClassFileParser {
260259

261260
void parse_fields(const ClassFileStream* const cfs,
262261
bool is_interface,
263-
FieldAllocationCount* const fac,
264262
ConstantPool* cp,
265263
const int cp_size,
266264
u2* const java_fields_count_ptr,

0 commit comments

Comments
 (0)
Please sign in to comment.