< prev index next >

src/hotspot/share/classfile/fieldLayoutBuilder.cpp

Print this page

193         if (cursor->block_kind() == LayoutRawBlock::EMPTY && cursor->fit(b->size(), b->alignment())) {
194           if (candidate == nullptr || cursor->size() < candidate->size()) {
195             candidate = cursor;
196           }
197         }
198         cursor = cursor->prev_block();
199       }
200       if (candidate == nullptr) {
201         candidate = last_block();
202         last_search_success = false;
203       }
204       assert(candidate != nullptr, "Candidate must not be null");
205       assert(candidate->block_kind() == LayoutRawBlock::EMPTY, "Candidate must be an empty block");
206       assert(candidate->fit(b->size(), b->alignment()), "Candidate must be able to store the block");
207     }
208 
209     insert_field_block(candidate, b);
210   }
211 }
212 

















213 // Used for classes with hard coded field offsets, insert a field at the specified offset */
214 void FieldLayout::add_field_at_offset(LayoutRawBlock* block, int offset, LayoutRawBlock* start) {
215   assert(block != nullptr, "Sanity check");
216   block->set_offset(offset);
217   if (start == nullptr) {
218     start = this->_start;
219   }
220   LayoutRawBlock* slot = start;
221   while (slot != nullptr) {
222     if ((slot->offset() <= block->offset() && (slot->offset() + slot->size()) > block->offset()) ||
223         slot == _last){
224       assert(slot->block_kind() == LayoutRawBlock::EMPTY, "Matching slot must be an empty slot");
225       assert(slot->size() >= block->offset() + block->size() ,"Matching slot must be big enough");
226       if (slot->offset() < block->offset()) {
227         int adjustment = block->offset() - slot->offset();
228         LayoutRawBlock* adj = new LayoutRawBlock(LayoutRawBlock::EMPTY, adjustment);
229         insert(slot, adj);
230       }
231       insert(slot, block);
232       if (slot->size() == 0) {

692       FieldGroup* cg = _contended_groups.at(i);
693       if (cg->oop_count() > 0) {
694         assert(cg->oop_fields() != nullptr && cg->oop_fields()->at(0) != nullptr, "oop_count > 0 but no oop fields found");
695         nonstatic_oop_maps->add(cg->oop_fields()->at(0)->offset(), cg->oop_count());
696       }
697     }
698   }
699 
700   nonstatic_oop_maps->compact();
701 
702   int instance_end = align_up(_layout->last_block()->offset(), wordSize);
703   int static_fields_end = align_up(_static_layout->last_block()->offset(), wordSize);
704   int static_fields_size = (static_fields_end -
705       InstanceMirrorKlass::offset_of_static_fields()) / wordSize;
706   int nonstatic_field_end = align_up(_layout->last_block()->offset(), heapOopSize);
707 
708   // Pass back information needed for InstanceKlass creation
709 
710   _info->oop_map_blocks = nonstatic_oop_maps;
711   _info->_instance_size = align_object_size(instance_end / wordSize);



712   _info->_static_field_size = static_fields_size;
713   _info->_nonstatic_field_size = (nonstatic_field_end - instanceOopDesc::base_offset_in_bytes()) / heapOopSize;
714   _info->_has_nonstatic_fields = _has_nonstatic_fields;
715 
716   if (PrintFieldLayout) {
717     ResourceMark rm;
718     tty->print_cr("Layout of class %s", _classname->as_C_string());
719     tty->print_cr("Instance fields:");
720     _layout->print(tty, false, _super_klass);
721     tty->print_cr("Static fields:");
722     _static_layout->print(tty, true, nullptr);
723     tty->print_cr("Instance size = %d bytes", _info->_instance_size * wordSize);
724     tty->print_cr("---");
725   }
726 }
727 
728 void FieldLayoutBuilder::build_layout() {
729   compute_regular_layout();
730 }

193         if (cursor->block_kind() == LayoutRawBlock::EMPTY && cursor->fit(b->size(), b->alignment())) {
194           if (candidate == nullptr || cursor->size() < candidate->size()) {
195             candidate = cursor;
196           }
197         }
198         cursor = cursor->prev_block();
199       }
200       if (candidate == nullptr) {
201         candidate = last_block();
202         last_search_success = false;
203       }
204       assert(candidate != nullptr, "Candidate must not be null");
205       assert(candidate->block_kind() == LayoutRawBlock::EMPTY, "Candidate must be an empty block");
206       assert(candidate->fit(b->size(), b->alignment()), "Candidate must be able to store the block");
207     }
208 
209     insert_field_block(candidate, b);
210   }
211 }
212 
213 // Finds a slot for the identity hash-code.
214 // Same basic algorithm as above add() method, but simplified
215 // and does not actually insert the field.
216 int FieldLayout::find_hash_offset() {
217   LayoutRawBlock* start = this->_start;
218   LayoutRawBlock* last = last_block();
219   LayoutRawBlock* cursor = start;
220   while (cursor != last) {
221     assert(cursor != nullptr, "Sanity check");
222     if (cursor->block_kind() == LayoutRawBlock::EMPTY && cursor->fit(4, 1)) {
223       break;
224     }
225     cursor = cursor->next_block();
226   }
227   return cursor->offset();
228 }
229 
230 // Used for classes with hard coded field offsets, insert a field at the specified offset */
231 void FieldLayout::add_field_at_offset(LayoutRawBlock* block, int offset, LayoutRawBlock* start) {
232   assert(block != nullptr, "Sanity check");
233   block->set_offset(offset);
234   if (start == nullptr) {
235     start = this->_start;
236   }
237   LayoutRawBlock* slot = start;
238   while (slot != nullptr) {
239     if ((slot->offset() <= block->offset() && (slot->offset() + slot->size()) > block->offset()) ||
240         slot == _last){
241       assert(slot->block_kind() == LayoutRawBlock::EMPTY, "Matching slot must be an empty slot");
242       assert(slot->size() >= block->offset() + block->size() ,"Matching slot must be big enough");
243       if (slot->offset() < block->offset()) {
244         int adjustment = block->offset() - slot->offset();
245         LayoutRawBlock* adj = new LayoutRawBlock(LayoutRawBlock::EMPTY, adjustment);
246         insert(slot, adj);
247       }
248       insert(slot, block);
249       if (slot->size() == 0) {

709       FieldGroup* cg = _contended_groups.at(i);
710       if (cg->oop_count() > 0) {
711         assert(cg->oop_fields() != nullptr && cg->oop_fields()->at(0) != nullptr, "oop_count > 0 but no oop fields found");
712         nonstatic_oop_maps->add(cg->oop_fields()->at(0)->offset(), cg->oop_count());
713       }
714     }
715   }
716 
717   nonstatic_oop_maps->compact();
718 
719   int instance_end = align_up(_layout->last_block()->offset(), wordSize);
720   int static_fields_end = align_up(_static_layout->last_block()->offset(), wordSize);
721   int static_fields_size = (static_fields_end -
722       InstanceMirrorKlass::offset_of_static_fields()) / wordSize;
723   int nonstatic_field_end = align_up(_layout->last_block()->offset(), heapOopSize);
724 
725   // Pass back information needed for InstanceKlass creation
726 
727   _info->oop_map_blocks = nonstatic_oop_maps;
728   _info->_instance_size = align_object_size(instance_end / wordSize);
729   if (UseCompactObjectHeaders) {
730     _info->_hash_offset   = _layout->find_hash_offset();
731   }
732   _info->_static_field_size = static_fields_size;
733   _info->_nonstatic_field_size = (nonstatic_field_end - instanceOopDesc::base_offset_in_bytes()) / heapOopSize;
734   _info->_has_nonstatic_fields = _has_nonstatic_fields;
735 
736   if (PrintFieldLayout) {
737     ResourceMark rm;
738     tty->print_cr("Layout of class %s", _classname->as_C_string());
739     tty->print_cr("Instance fields:");
740     _layout->print(tty, false, _super_klass);
741     tty->print_cr("Static fields:");
742     _static_layout->print(tty, true, nullptr);
743     tty->print_cr("Instance size = %d bytes", _info->_instance_size * wordSize);
744     tty->print_cr("---");
745   }
746 }
747 
748 void FieldLayoutBuilder::build_layout() {
749   compute_regular_layout();
750 }
< prev index next >