Skip to content
Permalink
Browse files

8238048: Close alignment gaps in InstanceKlass

Moved fields around and some constant fields into ConstantPool

Reviewed-by: cjplummer, dlong, iklam
  • Loading branch information
Coleen Phillimore
Coleen Phillimore committed Apr 23, 2020
1 parent 37e5aec commit 90ada6a3140d1504e36edfd6aeef4672f259ce0d
@@ -58,9 +58,7 @@ ConstantPool* BytecodeConstantPool::create_constant_pool(TRAPS) const {
_orig->copy_cp_to(1, _orig->length() - 1, cp_h, 1, CHECK_NULL);

// Preserve dynamic constant information from the original pool
if (_orig->has_dynamic_constant()) {
cp->set_has_dynamic_constant();
}
cp->copy_fields(_orig);

for (int i = 0; i < _entries.length(); ++i) {
BytecodeCPEntry entry = _entries.at(i);
@@ -116,7 +116,8 @@
nonstatic_field(ConstantPool, _tags, Array<u1>*) \
nonstatic_field(ConstantPool, _pool_holder, InstanceKlass*) \
nonstatic_field(ConstantPool, _length, int) \
nonstatic_field(ConstantPool, _flags, int) \
nonstatic_field(ConstantPool, _flags, u2) \
nonstatic_field(ConstantPool, _source_file_name_index, u2) \
\
nonstatic_field(ConstMethod, _constants, ConstantPool*) \
nonstatic_field(ConstMethod, _flags, u2) \
@@ -155,10 +156,9 @@
\
nonstatic_field(InstanceKlass, _fields, Array<u2>*) \
nonstatic_field(InstanceKlass, _constants, ConstantPool*) \
nonstatic_field(InstanceKlass, _source_file_name_index, u2) \
nonstatic_field(InstanceKlass, _init_state, u1) \
nonstatic_field(InstanceKlass, _init_thread, Thread*) \
nonstatic_field(InstanceKlass, _misc_flags, u4) \
nonstatic_field(InstanceKlass, _misc_flags, u2) \
nonstatic_field(InstanceKlass, _annotations, Annotations*) \
\
volatile_nonstatic_field(JavaFrameAnchor, _last_Java_sp, intptr_t*) \
@@ -65,6 +65,20 @@ ConstantPool* ConstantPool::allocate(ClassLoaderData* loader_data, int length, T
return new (loader_data, size, MetaspaceObj::ConstantPoolType, THREAD) ConstantPool(tags);
}

void ConstantPool::copy_fields(const ConstantPool* orig) {
// Preserve dynamic constant information from the original pool
if (orig->has_dynamic_constant()) {
set_has_dynamic_constant();
}

// Copy class version
set_major_version(orig->major_version());
set_minor_version(orig->minor_version());

set_source_file_name_index(orig->source_file_name_index());
set_generic_signature_index(orig->generic_signature_index());
}

#ifdef ASSERT

// MetaspaceObj allocation invariant is calloc equivalent memory
@@ -110,15 +110,26 @@ class ConstantPool : public Metadata {
// save space on 64-bit platforms.
Array<Klass*>* _resolved_klasses;

u2 _major_version; // major version number of class file
u2 _minor_version; // minor version number of class file

// Constant pool index to the utf8 entry of the Generic signature,
// or 0 if none.
u2 _generic_signature_index;
// Constant pool index to the utf8 entry for the name of source file
// containing this klass, 0 if not specified.
u2 _source_file_name_index;

enum {
_has_preresolution = 1, // Flags
_on_stack = 2,
_is_shared = 4,
_has_dynamic_constant = 8
};

int _flags; // old fashioned bit twiddling
int _length; // number of elements in the array
u2 _flags; // old fashioned bit twiddling

int _length; // number of elements in the array

union {
// set for CDS to restore resolved references
@@ -135,8 +146,8 @@ class ConstantPool : public Metadata {

void set_operands(Array<u2>* operands) { _operands = operands; }

int flags() const { return _flags; }
void set_flags(int f) { _flags = f; }
u2 flags() const { return _flags; }
void set_flags(u2 f) { _flags = f; }

private:
intptr_t* base() const { return (intptr_t*) (((char*) this) + sizeof(ConstantPool)); }
@@ -189,6 +200,30 @@ class ConstantPool : public Metadata {
_flags |= _has_preresolution;
}

// minor and major version numbers of class file
u2 major_version() const { return _major_version; }
void set_major_version(u2 major_version) { _major_version = major_version; }
u2 minor_version() const { return _minor_version; }
void set_minor_version(u2 minor_version) { _minor_version = minor_version; }

// generics support
Symbol* generic_signature() const {
return (_generic_signature_index == 0) ?
(Symbol*)NULL : symbol_at(_generic_signature_index);
}
u2 generic_signature_index() const { return _generic_signature_index; }
void set_generic_signature_index(u2 sig_index) { _generic_signature_index = sig_index; }

// source file name
Symbol* source_file_name() const {
return (_source_file_name_index == 0) ?
(Symbol*)NULL : symbol_at(_source_file_name_index);
}
u2 source_file_name_index() const { return _source_file_name_index; }
void set_source_file_name_index(u2 sourcefile_index) { _source_file_name_index = sourcefile_index; }

void copy_fields(const ConstantPool* orig);

// Redefine classes support. If a method refering to this constant pool
// is on the executing stack, or as a handle in vm code, this constant pool
// can't be removed from the set of previous versions saved in the instance
@@ -43,7 +43,7 @@ class InstanceClassLoaderKlass: public InstanceKlass {
static const KlassID ID = InstanceClassLoaderKlassID;

private:
InstanceClassLoaderKlass(const ClassFileParser& parser) : InstanceKlass(parser, InstanceKlass::_misc_kind_class_loader, ID) {}
InstanceClassLoaderKlass(const ClassFileParser& parser) : InstanceKlass(parser, InstanceKlass::_kind_class_loader, ID) {}

public:
InstanceClassLoaderKlass() { assert(DumpSharedSpaces || UseSharedSpaces, "only for CDS"); }
@@ -442,7 +442,7 @@ InstanceKlass* InstanceKlass::allocate_instance_klass(const ClassFileParser& par
ik = new (loader_data, size, THREAD) InstanceClassLoaderKlass(parser);
} else {
// normal
ik = new (loader_data, size, THREAD) InstanceKlass(parser, InstanceKlass::_misc_kind_other);
ik = new (loader_data, size, THREAD) InstanceKlass(parser, InstanceKlass::_kind_other);
}
} else {
// reference
@@ -483,15 +483,15 @@ Array<int>* InstanceKlass::create_new_default_vtable_indices(int len, TRAPS) {
InstanceKlass::InstanceKlass(const ClassFileParser& parser, unsigned kind, KlassID id) :
Klass(id),
_nest_members(NULL),
_nest_host_index(0),
_nest_host(NULL),
_record_components(NULL),
_static_field_size(parser.static_field_size()),
_nonstatic_oop_map_size(nonstatic_oop_map_size(parser.total_oop_map_count())),
_itable_len(parser.itable_size()),
_init_thread(NULL),
_nest_host_index(0),
_init_state(allocated),
_reference_type(parser.reference_type())
_reference_type(parser.reference_type()),
_init_thread(NULL)
{
set_vtable_length(parser.vtable_size());
set_kind(kind);

0 comments on commit 90ada6a

Please sign in to comment.
You can’t perform that action at this time.