/* * Copyright (c) 2020, 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
// Classes below are used to compute the field layout of classes.
// A LayoutRawBlock describes an element of a layout. // Each field is represented by a LayoutRawBlock. // LayoutRawBlocks can also represent elements injected by the JVM: // padding, empty blocks, inherited fields, etc. // All LayoutRawBlocks must have a size and an alignment. The size is the // exact size of the field expressed in bytes. The alignment is // the alignment constraint of the field (1 for byte, 2 for short, // 4 for int, 8 for long, etc.) // // LayoutRawBlock are designed to be used in two data structures: // - a linked list in a layout (using _next_block, _prev_block) // - a GrowableArray in field group (the growable array contains pointers to LayoutRawBlocks) // // next/prev pointers are included in the LayoutRawBlock class to narrow // the number of allocation required during the computation of a layout. // class LayoutRawBlock : public ResourceObj { public: // Some code relies on the order of values below. enum Kind {
EMPTY, // empty slot, space is taken from this to allocate fields
RESERVED, // reserved for JVM usage (for instance object header)
PADDING, // padding (because of alignment constraints or @Contended)
REGULAR, // primitive or oop field (including non-flattened inline fields)
FLATTENED, // flattened field
INHERITED // field(s) inherited from super classes
};
private:
LayoutRawBlock* _next_block;
LayoutRawBlock* _prev_block;
Kind _kind; int _offset; int _alignment; int _size; int _field_index; bool _is_reference;
staticint compare_offset(LayoutRawBlock** x, LayoutRawBlock** y) { return (*x)->offset() - (*y)->offset(); } // compare_size_inverted() returns the opposite of a regular compare method in order to // sort fields in decreasing order. // Note: with line types, the comparison should include alignment constraint if sizes are equals staticint compare_size_inverted(LayoutRawBlock** x, LayoutRawBlock** y) { #ifdef _WINDOWS // qsort() on Windows reverse the order of fields with the same size // the extension of the comparison function below preserves this order int diff = (*y)->size() - (*x)->size(); if (diff == 0) {
diff = (*x)->field_index() - (*y)->field_index();
} return diff; #else return (*y)->size() - (*x)->size(); #endif// _WINDOWS
}
};
// A Field group represents a set of fields that have to be allocated together, // this is the way the @Contended annotation is supported. // Inside a FieldGroup, fields are sorted based on their kind: primitive, // oop, or flattened. // class FieldGroup : public ResourceObj {
private:
FieldGroup* _next;
GrowableArray<LayoutRawBlock*>* _primitive_fields;
GrowableArray<LayoutRawBlock*>* _oop_fields; int _contended_group; int _oop_count; staticconstint INITIAL_LIST_SIZE = 16;
// The FieldLayout class represents a set of fields organized // in a layout. // An instance of FieldLayout can either represent the layout // of non-static fields (used in an instance object) or the // layout of static fields (to be included in the class mirror). // // _block is a pointer to a list of LayoutRawBlock ordered by increasing // offsets. // _start points to the LayoutRawBlock with the first offset that can // be used to allocate fields of the current class // _last points to the last LayoutRawBlock of the list. In order to // simplify the code, the LayoutRawBlock list always ends with an // EMPTY block (the kind of LayoutRawBlock from which space is taken // to allocate fields) with a size big enough to satisfy all // field allocations. // class FieldLayout : public ResourceObj { private:
Array<u2>* _fields;
ConstantPool* _cp;
LayoutRawBlock* _blocks; // the layout being computed
LayoutRawBlock* _start; // points to the first block where a field can be inserted
LayoutRawBlock* _last; // points to the last block of the layout (big empty block)
// FieldLayoutBuilder is the main entry point for layout computation. // This class has three methods to generate layout: one for regular classes // and two for classes with hard coded offsets (java,lang.ref.Reference // and the boxing classes). The rationale for having multiple methods // is that each kind of class has a different set goals regarding // its layout, so instead of mixing several layout strategies into a // single method, each kind has its own method (see comments below // for more details about the allocation strategies). // // Computing the layout of a class always goes through 4 steps: // 1 - Prologue: preparation of data structure and gathering of // layout information inherited from super classes // 2 - Field sorting: fields are sorted according to their // kind (oop, primitive, inline class) and their contention // annotation (if any) // 3 - Layout is computed from the set of lists generated during // step 2 // 4 - Epilogue: oopmaps are generated, layout information is // prepared so other VM components can use it (instance size, // static field size, non-static field size, etc.) // // Steps 1 and 4 are common to all layout computations. Step 2 and 3 // can vary with the allocation strategy. // class FieldLayoutBuilder : public ResourceObj { private:
const Symbol* _classname; const InstanceKlass* _super_klass;
ConstantPool* _constant_pool;
Array<u2>* _fields;
FieldLayoutInfo* _info;
FieldGroup* _root_group;
GrowableArray<FieldGroup*> _contended_groups;
FieldGroup* _static_fields;
FieldLayout* _layout;
FieldLayout* _static_layout; int _nonstatic_oopmap_count; int _alignment; bool _has_nonstatic_fields; bool _is_contended; // is a contended class?
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.