Path: blob/master/src/hotspot/share/classfile/fieldLayoutBuilder.cpp
40949 views
/*1* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "jvm.h"26#include "classfile/classFileParser.hpp"27#include "classfile/fieldLayoutBuilder.hpp"28#include "memory/resourceArea.hpp"29#include "oops/array.hpp"30#include "oops/fieldStreams.inline.hpp"31#include "oops/instanceMirrorKlass.hpp"32#include "oops/instanceKlass.inline.hpp"33#include "oops/klass.inline.hpp"34#include "runtime/fieldDescriptor.inline.hpp"353637LayoutRawBlock::LayoutRawBlock(Kind kind, int size) :38_next_block(NULL),39_prev_block(NULL),40_kind(kind),41_offset(-1),42_alignment(1),43_size(size),44_field_index(-1),45_is_reference(false) {46assert(kind == EMPTY || kind == RESERVED || kind == PADDING || kind == INHERITED,47"Otherwise, should use the constructor with a field index argument");48assert(size > 0, "Sanity check");49}505152LayoutRawBlock::LayoutRawBlock(int index, Kind kind, int size, int alignment, bool is_reference) :53_next_block(NULL),54_prev_block(NULL),55_kind(kind),56_offset(-1),57_alignment(alignment),58_size(size),59_field_index(index),60_is_reference(is_reference) {61assert(kind == REGULAR || kind == FLATTENED || kind == INHERITED,62"Other kind do not have a field index");63assert(size > 0, "Sanity check");64assert(alignment > 0, "Sanity check");65}6667bool LayoutRawBlock::fit(int size, int alignment) {68int adjustment = 0;69if ((_offset % alignment) != 0) {70adjustment = alignment - (_offset % alignment);71}72return _size >= size + adjustment;73}7475FieldGroup::FieldGroup(int contended_group) :76_next(NULL),77_primitive_fields(NULL),78_oop_fields(NULL),79_contended_group(contended_group), // -1 means no contended group, 0 means default contended group80_oop_count(0) {}8182void FieldGroup::add_primitive_field(AllFieldStream fs, BasicType type) {83int size = type2aelembytes(type);84LayoutRawBlock* block = new LayoutRawBlock(fs.index(), LayoutRawBlock::REGULAR, size, size /* alignment == size for primitive types */, false);85if (_primitive_fields == NULL) {86_primitive_fields = new(ResourceObj::RESOURCE_AREA, mtInternal) GrowableArray<LayoutRawBlock*>(INITIAL_LIST_SIZE);87}88_primitive_fields->append(block);89}9091void FieldGroup::add_oop_field(AllFieldStream fs) {92int size = type2aelembytes(T_OBJECT);93LayoutRawBlock* block = new LayoutRawBlock(fs.index(), LayoutRawBlock::REGULAR, size, size /* alignment == size for oops */, true);94if (_oop_fields == NULL) {95_oop_fields = new(ResourceObj::RESOURCE_AREA, mtInternal) GrowableArray<LayoutRawBlock*>(INITIAL_LIST_SIZE);96}97_oop_fields->append(block);98_oop_count++;99}100101void FieldGroup::sort_by_size() {102if (_primitive_fields != NULL) {103_primitive_fields->sort(LayoutRawBlock::compare_size_inverted);104}105}106107FieldLayout::FieldLayout(Array<u2>* fields, ConstantPool* cp) :108_fields(fields),109_cp(cp),110_blocks(NULL),111_start(_blocks),112_last(_blocks) {}113114void FieldLayout::initialize_static_layout() {115_blocks = new LayoutRawBlock(LayoutRawBlock::EMPTY, INT_MAX);116_blocks->set_offset(0);117_last = _blocks;118_start = _blocks;119// Note: at this stage, InstanceMirrorKlass::offset_of_static_fields() could be zero, because120// during bootstrapping, the size of the java.lang.Class is still not known when layout121// of static field is computed. Field offsets are fixed later when the size is known122// (see java_lang_Class::fixup_mirror())123if (InstanceMirrorKlass::offset_of_static_fields() > 0) {124insert(first_empty_block(), new LayoutRawBlock(LayoutRawBlock::RESERVED, InstanceMirrorKlass::offset_of_static_fields()));125_blocks->set_offset(0);126}127}128129void FieldLayout::initialize_instance_layout(const InstanceKlass* super_klass) {130if (super_klass == NULL) {131_blocks = new LayoutRawBlock(LayoutRawBlock::EMPTY, INT_MAX);132_blocks->set_offset(0);133_last = _blocks;134_start = _blocks;135insert(first_empty_block(), new LayoutRawBlock(LayoutRawBlock::RESERVED, instanceOopDesc::base_offset_in_bytes()));136} else {137bool has_fields = reconstruct_layout(super_klass);138fill_holes(super_klass);139if ((UseEmptySlotsInSupers && !super_klass->has_contended_annotations()) || !has_fields) {140_start = _blocks; // start allocating fields from the first empty block141} else {142_start = _last; // append fields at the end of the reconstructed layout143}144}145}146147LayoutRawBlock* FieldLayout::first_field_block() {148LayoutRawBlock* block = _start;149while (block->kind() != LayoutRawBlock::INHERITED && block->kind() != LayoutRawBlock::REGULAR150&& block->kind() != LayoutRawBlock::FLATTENED && block->kind() != LayoutRawBlock::PADDING) {151block = block->next_block();152}153return block;154}155156157// Insert a set of fields into a layout using a best-fit strategy.158// For each field, search for the smallest empty slot able to fit the field159// (satisfying both size and alignment requirements), if none is found,160// add the field at the end of the layout.161// Fields cannot be inserted before the block specified in the "start" argument162void FieldLayout::add(GrowableArray<LayoutRawBlock*>* list, LayoutRawBlock* start) {163if (list == NULL) return;164if (start == NULL) start = this->_start;165bool last_search_success = false;166int last_size = 0;167int last_alignment = 0;168for (int i = 0; i < list->length(); i ++) {169LayoutRawBlock* b = list->at(i);170LayoutRawBlock* cursor = NULL;171LayoutRawBlock* candidate = NULL;172173// if start is the last block, just append the field174if (start == last_block()) {175candidate = last_block();176}177// Before iterating over the layout to find an empty slot fitting the field's requirements,178// check if the previous field had the same requirements and if the search for a fitting slot179// was successful. If the requirements were the same but the search failed, a new search will180// fail the same way, so just append the field at the of the layout.181else if (b->size() == last_size && b->alignment() == last_alignment && !last_search_success) {182candidate = last_block();183} else {184// Iterate over the layout to find an empty slot fitting the field's requirements185last_size = b->size();186last_alignment = b->alignment();187cursor = last_block()->prev_block();188assert(cursor != NULL, "Sanity check");189last_search_success = true;190while (cursor != start) {191if (cursor->kind() == LayoutRawBlock::EMPTY && cursor->fit(b->size(), b->alignment())) {192if (candidate == NULL || cursor->size() < candidate->size()) {193candidate = cursor;194}195}196cursor = cursor->prev_block();197}198if (candidate == NULL) {199candidate = last_block();200last_search_success = false;201}202assert(candidate != NULL, "Candidate must not be null");203assert(candidate->kind() == LayoutRawBlock::EMPTY, "Candidate must be an empty block");204assert(candidate->fit(b->size(), b->alignment()), "Candidate must be able to store the block");205}206207insert_field_block(candidate, b);208}209}210211// Used for classes with hard coded field offsets, insert a field at the specified offset */212void FieldLayout::add_field_at_offset(LayoutRawBlock* block, int offset, LayoutRawBlock* start) {213assert(block != NULL, "Sanity check");214block->set_offset(offset);215if (start == NULL) {216start = this->_start;217}218LayoutRawBlock* slot = start;219while (slot != NULL) {220if ((slot->offset() <= block->offset() && (slot->offset() + slot->size()) > block->offset()) ||221slot == _last){222assert(slot->kind() == LayoutRawBlock::EMPTY, "Matching slot must be an empty slot");223assert(slot->size() >= block->offset() + block->size() ,"Matching slot must be big enough");224if (slot->offset() < block->offset()) {225int adjustment = block->offset() - slot->offset();226LayoutRawBlock* adj = new LayoutRawBlock(LayoutRawBlock::EMPTY, adjustment);227insert(slot, adj);228}229insert(slot, block);230if (slot->size() == 0) {231remove(slot);232}233FieldInfo::from_field_array(_fields, block->field_index())->set_offset(block->offset());234return;235}236slot = slot->next_block();237}238fatal("Should have found a matching slot above, corrupted layout or invalid offset");239}240241// The allocation logic uses a best fit strategy: the set of fields is allocated242// in the first empty slot big enough to contain the whole set ((including padding243// to fit alignment constraints).244void FieldLayout::add_contiguously(GrowableArray<LayoutRawBlock*>* list, LayoutRawBlock* start) {245if (list == NULL) return;246if (start == NULL) {247start = _start;248}249// This code assumes that if the first block is well aligned, the following250// blocks would naturally be well aligned (no need for adjustment)251int size = 0;252for (int i = 0; i < list->length(); i++) {253size += list->at(i)->size();254}255256LayoutRawBlock* candidate = NULL;257if (start == last_block()) {258candidate = last_block();259} else {260LayoutRawBlock* first = list->at(0);261candidate = last_block()->prev_block();262while (candidate->kind() != LayoutRawBlock::EMPTY || !candidate->fit(size, first->alignment())) {263if (candidate == start) {264candidate = last_block();265break;266}267candidate = candidate->prev_block();268}269assert(candidate != NULL, "Candidate must not be null");270assert(candidate->kind() == LayoutRawBlock::EMPTY, "Candidate must be an empty block");271assert(candidate->fit(size, first->alignment()), "Candidate must be able to store the whole contiguous block");272}273274for (int i = 0; i < list->length(); i++) {275LayoutRawBlock* b = list->at(i);276insert_field_block(candidate, b);277assert((candidate->offset() % b->alignment() == 0), "Contiguous blocks must be naturally well aligned");278}279}280281LayoutRawBlock* FieldLayout::insert_field_block(LayoutRawBlock* slot, LayoutRawBlock* block) {282assert(slot->kind() == LayoutRawBlock::EMPTY, "Blocks can only be inserted in empty blocks");283if (slot->offset() % block->alignment() != 0) {284int adjustment = block->alignment() - (slot->offset() % block->alignment());285LayoutRawBlock* adj = new LayoutRawBlock(LayoutRawBlock::EMPTY, adjustment);286insert(slot, adj);287}288insert(slot, block);289if (slot->size() == 0) {290remove(slot);291}292FieldInfo::from_field_array(_fields, block->field_index())->set_offset(block->offset());293return block;294}295296bool FieldLayout::reconstruct_layout(const InstanceKlass* ik) {297bool has_instance_fields = false;298GrowableArray<LayoutRawBlock*>* all_fields = new GrowableArray<LayoutRawBlock*>(32);299while (ik != NULL) {300for (AllFieldStream fs(ik->fields(), ik->constants()); !fs.done(); fs.next()) {301BasicType type = Signature::basic_type(fs.signature());302// distinction between static and non-static fields is missing303if (fs.access_flags().is_static()) continue;304has_instance_fields = true;305int size = type2aelembytes(type);306// INHERITED blocks are marked as non-reference because oop_maps are handled by their holder class307LayoutRawBlock* block = new LayoutRawBlock(fs.index(), LayoutRawBlock::INHERITED, size, size, false);308block->set_offset(fs.offset());309all_fields->append(block);310}311ik = ik->super() == NULL ? NULL : InstanceKlass::cast(ik->super());312}313314all_fields->sort(LayoutRawBlock::compare_offset);315_blocks = new LayoutRawBlock(LayoutRawBlock::RESERVED, instanceOopDesc::base_offset_in_bytes());316_blocks->set_offset(0);317_last = _blocks;318319for(int i = 0; i < all_fields->length(); i++) {320LayoutRawBlock* b = all_fields->at(i);321_last->set_next_block(b);322b->set_prev_block(_last);323_last = b;324}325_start = _blocks;326return has_instance_fields;327}328329// Called during the reconstruction of a layout, after fields from super330// classes have been inserted. It fills unused slots between inserted fields331// with EMPTY blocks, so the regular field insertion methods would work.332// This method handles classes with @Contended annotations differently333// by inserting PADDING blocks instead of EMPTY block to prevent subclasses'334// fields to interfere with contended fields/classes.335void FieldLayout::fill_holes(const InstanceKlass* super_klass) {336assert(_blocks != NULL, "Sanity check");337assert(_blocks->offset() == 0, "first block must be at offset zero");338LayoutRawBlock::Kind filling_type = super_klass->has_contended_annotations() ? LayoutRawBlock::PADDING: LayoutRawBlock::EMPTY;339LayoutRawBlock* b = _blocks;340while (b->next_block() != NULL) {341if (b->next_block()->offset() > (b->offset() + b->size())) {342int size = b->next_block()->offset() - (b->offset() + b->size());343LayoutRawBlock* empty = new LayoutRawBlock(filling_type, size);344empty->set_offset(b->offset() + b->size());345empty->set_next_block(b->next_block());346b->next_block()->set_prev_block(empty);347b->set_next_block(empty);348empty->set_prev_block(b);349}350b = b->next_block();351}352assert(b->next_block() == NULL, "Invariant at this point");353assert(b->kind() != LayoutRawBlock::EMPTY, "Sanity check");354355// If the super class has @Contended annotation, a padding block is356// inserted at the end to ensure that fields from the subclasses won't share357// the cache line of the last field of the contended class358if (super_klass->has_contended_annotations() && ContendedPaddingWidth > 0) {359LayoutRawBlock* p = new LayoutRawBlock(LayoutRawBlock::PADDING, ContendedPaddingWidth);360p->set_offset(b->offset() + b->size());361b->set_next_block(p);362p->set_prev_block(b);363b = p;364}365366if (!UseEmptySlotsInSupers) {367// Add an empty slots to align fields of the subclass on a heapOopSize boundary368// in order to emulate the behavior of the previous algorithm369int align = (b->offset() + b->size()) % heapOopSize;370if (align != 0) {371int sz = heapOopSize - align;372LayoutRawBlock* p = new LayoutRawBlock(LayoutRawBlock::EMPTY, sz);373p->set_offset(b->offset() + b->size());374b->set_next_block(p);375p->set_prev_block(b);376b = p;377}378}379380LayoutRawBlock* last = new LayoutRawBlock(LayoutRawBlock::EMPTY, INT_MAX);381last->set_offset(b->offset() + b->size());382assert(last->offset() > 0, "Sanity check");383b->set_next_block(last);384last->set_prev_block(b);385_last = last;386}387388LayoutRawBlock* FieldLayout::insert(LayoutRawBlock* slot, LayoutRawBlock* block) {389assert(slot->kind() == LayoutRawBlock::EMPTY, "Blocks can only be inserted in empty blocks");390assert(slot->offset() % block->alignment() == 0, "Incompatible alignment");391block->set_offset(slot->offset());392slot->set_offset(slot->offset() + block->size());393assert((slot->size() - block->size()) < slot->size(), "underflow checking");394assert(slot->size() - block->size() >= 0, "no negative size allowed");395slot->set_size(slot->size() - block->size());396block->set_prev_block(slot->prev_block());397block->set_next_block(slot);398slot->set_prev_block(block);399if (block->prev_block() != NULL) {400block->prev_block()->set_next_block(block);401}402if (_blocks == slot) {403_blocks = block;404}405return block;406}407408void FieldLayout::remove(LayoutRawBlock* block) {409assert(block != NULL, "Sanity check");410assert(block != _last, "Sanity check");411if (_blocks == block) {412_blocks = block->next_block();413if (_blocks != NULL) {414_blocks->set_prev_block(NULL);415}416} else {417assert(block->prev_block() != NULL, "_prev should be set for non-head blocks");418block->prev_block()->set_next_block(block->next_block());419block->next_block()->set_prev_block(block->prev_block());420}421if (block == _start) {422_start = block->prev_block();423}424}425426void FieldLayout::print(outputStream* output, bool is_static, const InstanceKlass* super) {427ResourceMark rm;428LayoutRawBlock* b = _blocks;429while(b != _last) {430switch(b->kind()) {431case LayoutRawBlock::REGULAR: {432FieldInfo* fi = FieldInfo::from_field_array(_fields, b->field_index());433output->print_cr(" @%d \"%s\" %s %d/%d %s",434b->offset(),435fi->name(_cp)->as_C_string(),436fi->signature(_cp)->as_C_string(),437b->size(),438b->alignment(),439"REGULAR");440break;441}442case LayoutRawBlock::FLATTENED: {443FieldInfo* fi = FieldInfo::from_field_array(_fields, b->field_index());444output->print_cr(" @%d \"%s\" %s %d/%d %s",445b->offset(),446fi->name(_cp)->as_C_string(),447fi->signature(_cp)->as_C_string(),448b->size(),449b->alignment(),450"FLATTENED");451break;452}453case LayoutRawBlock::RESERVED: {454output->print_cr(" @%d %d/- %s",455b->offset(),456b->size(),457"RESERVED");458break;459}460case LayoutRawBlock::INHERITED: {461assert(!is_static, "Static fields are not inherited in layouts");462assert(super != NULL, "super klass must be provided to retrieve inherited fields info");463bool found = false;464const InstanceKlass* ik = super;465while (!found && ik != NULL) {466for (AllFieldStream fs(ik->fields(), ik->constants()); !fs.done(); fs.next()) {467if (fs.offset() == b->offset()) {468output->print_cr(" @%d \"%s\" %s %d/%d %s",469b->offset(),470fs.name()->as_C_string(),471fs.signature()->as_C_string(),472b->size(),473b->size(), // so far, alignment constraint == size, will change with Valhalla474"INHERITED");475found = true;476break;477}478}479ik = ik->java_super();480}481break;482}483case LayoutRawBlock::EMPTY:484output->print_cr(" @%d %d/1 %s",485b->offset(),486b->size(),487"EMPTY");488break;489case LayoutRawBlock::PADDING:490output->print_cr(" @%d %d/1 %s",491b->offset(),492b->size(),493"PADDING");494break;495}496b = b->next_block();497}498}499500FieldLayoutBuilder::FieldLayoutBuilder(const Symbol* classname, const InstanceKlass* super_klass, ConstantPool* constant_pool,501Array<u2>* fields, bool is_contended, FieldLayoutInfo* info) :502_classname(classname),503_super_klass(super_klass),504_constant_pool(constant_pool),505_fields(fields),506_info(info),507_root_group(NULL),508_contended_groups(GrowableArray<FieldGroup*>(8)),509_static_fields(NULL),510_layout(NULL),511_static_layout(NULL),512_nonstatic_oopmap_count(0),513_alignment(-1),514_has_nonstatic_fields(false),515_is_contended(is_contended) {}516517518FieldGroup* FieldLayoutBuilder::get_or_create_contended_group(int g) {519assert(g > 0, "must only be called for named contended groups");520FieldGroup* fg = NULL;521for (int i = 0; i < _contended_groups.length(); i++) {522fg = _contended_groups.at(i);523if (fg->contended_group() == g) return fg;524}525fg = new FieldGroup(g);526_contended_groups.append(fg);527return fg;528}529530void FieldLayoutBuilder::prologue() {531_layout = new FieldLayout(_fields, _constant_pool);532const InstanceKlass* super_klass = _super_klass;533_layout->initialize_instance_layout(super_klass);534if (super_klass != NULL) {535_has_nonstatic_fields = super_klass->has_nonstatic_fields();536}537_static_layout = new FieldLayout(_fields, _constant_pool);538_static_layout->initialize_static_layout();539_static_fields = new FieldGroup();540_root_group = new FieldGroup();541}542543// Field sorting for regular classes:544// - fields are sorted in static and non-static fields545// - non-static fields are also sorted according to their contention group546// (support of the @Contended annotation)547// - @Contended annotation is ignored for static fields548void FieldLayoutBuilder::regular_field_sorting() {549for (AllFieldStream fs(_fields, _constant_pool); !fs.done(); fs.next()) {550FieldGroup* group = NULL;551if (fs.access_flags().is_static()) {552group = _static_fields;553} else {554_has_nonstatic_fields = true;555if (fs.is_contended()) {556int g = fs.contended_group();557if (g == 0) {558group = new FieldGroup(true);559_contended_groups.append(group);560} else {561group = get_or_create_contended_group(g);562}563} else {564group = _root_group;565}566}567assert(group != NULL, "invariant");568BasicType type = Signature::basic_type(fs.signature());569switch(type) {570case T_BYTE:571case T_CHAR:572case T_DOUBLE:573case T_FLOAT:574case T_INT:575case T_LONG:576case T_SHORT:577case T_BOOLEAN:578group->add_primitive_field(fs, type);579break;580case T_OBJECT:581case T_ARRAY:582if (group != _static_fields) _nonstatic_oopmap_count++;583group->add_oop_field(fs);584break;585default:586fatal("Something wrong?");587}588}589_root_group->sort_by_size();590_static_fields->sort_by_size();591if (!_contended_groups.is_empty()) {592for (int i = 0; i < _contended_groups.length(); i++) {593_contended_groups.at(i)->sort_by_size();594}595}596}597598void FieldLayoutBuilder::insert_contended_padding(LayoutRawBlock* slot) {599if (ContendedPaddingWidth > 0) {600LayoutRawBlock* padding = new LayoutRawBlock(LayoutRawBlock::PADDING, ContendedPaddingWidth);601_layout->insert(slot, padding);602}603}604605// Computation of regular classes layout is an evolution of the previous default layout606// (FieldAllocationStyle 1):607// - primitive fields are allocated first (from the biggest to the smallest)608// - then oop fields are allocated, either in existing gaps or at the end of609// the layout610void FieldLayoutBuilder::compute_regular_layout() {611bool need_tail_padding = false;612prologue();613regular_field_sorting();614615if (_is_contended) {616_layout->set_start(_layout->last_block());617// insertion is currently easy because the current strategy doesn't try to fill holes618// in super classes layouts => the _start block is by consequence the _last_block619insert_contended_padding(_layout->start());620need_tail_padding = true;621}622_layout->add(_root_group->primitive_fields());623_layout->add(_root_group->oop_fields());624625if (!_contended_groups.is_empty()) {626for (int i = 0; i < _contended_groups.length(); i++) {627FieldGroup* cg = _contended_groups.at(i);628LayoutRawBlock* start = _layout->last_block();629insert_contended_padding(start);630_layout->add(cg->primitive_fields(), start);631_layout->add(cg->oop_fields(), start);632need_tail_padding = true;633}634}635636if (need_tail_padding) {637insert_contended_padding(_layout->last_block());638}639640_static_layout->add_contiguously(this->_static_fields->oop_fields());641_static_layout->add(this->_static_fields->primitive_fields());642643epilogue();644}645646void FieldLayoutBuilder::epilogue() {647// Computing oopmaps648int super_oop_map_count = (_super_klass == NULL) ? 0 :_super_klass->nonstatic_oop_map_count();649int max_oop_map_count = super_oop_map_count + _nonstatic_oopmap_count;650651OopMapBlocksBuilder* nonstatic_oop_maps =652new OopMapBlocksBuilder(max_oop_map_count);653if (super_oop_map_count > 0) {654nonstatic_oop_maps->initialize_inherited_blocks(_super_klass->start_of_nonstatic_oop_maps(),655_super_klass->nonstatic_oop_map_count());656}657658if (_root_group->oop_fields() != NULL) {659for (int i = 0; i < _root_group->oop_fields()->length(); i++) {660LayoutRawBlock* b = _root_group->oop_fields()->at(i);661nonstatic_oop_maps->add(b->offset(), 1);662}663}664665if (!_contended_groups.is_empty()) {666for (int i = 0; i < _contended_groups.length(); i++) {667FieldGroup* cg = _contended_groups.at(i);668if (cg->oop_count() > 0) {669assert(cg->oop_fields() != NULL && cg->oop_fields()->at(0) != NULL, "oop_count > 0 but no oop fields found");670nonstatic_oop_maps->add(cg->oop_fields()->at(0)->offset(), cg->oop_count());671}672}673}674675nonstatic_oop_maps->compact();676677int instance_end = align_up(_layout->last_block()->offset(), wordSize);678int static_fields_end = align_up(_static_layout->last_block()->offset(), wordSize);679int static_fields_size = (static_fields_end -680InstanceMirrorKlass::offset_of_static_fields()) / wordSize;681int nonstatic_field_end = align_up(_layout->last_block()->offset(), heapOopSize);682683// Pass back information needed for InstanceKlass creation684685_info->oop_map_blocks = nonstatic_oop_maps;686_info->_instance_size = align_object_size(instance_end / wordSize);687_info->_static_field_size = static_fields_size;688_info->_nonstatic_field_size = (nonstatic_field_end - instanceOopDesc::base_offset_in_bytes()) / heapOopSize;689_info->_has_nonstatic_fields = _has_nonstatic_fields;690691if (PrintFieldLayout) {692ResourceMark rm;693tty->print_cr("Layout of class %s", _classname->as_C_string());694tty->print_cr("Instance fields:");695_layout->print(tty, false, _super_klass);696tty->print_cr("Static fields:");697_static_layout->print(tty, true, NULL);698tty->print_cr("Instance size = %d bytes", _info->_instance_size * wordSize);699tty->print_cr("---");700}701}702703void FieldLayoutBuilder::build_layout() {704compute_regular_layout();705}706707708