< prev index next >

src/hotspot/share/classfile/fieldLayoutBuilder.cpp

Print this page

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

















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

656       FieldGroup* cg = _contended_groups.at(i);
657       if (cg->oop_count() > 0) {
658         assert(cg->oop_fields() != nullptr && cg->oop_fields()->at(0) != nullptr, "oop_count > 0 but no oop fields found");
659         nonstatic_oop_maps->add(cg->oop_fields()->at(0)->offset(), cg->oop_count());
660       }
661     }
662   }
663 
664   nonstatic_oop_maps->compact();
665 
666   int instance_end = align_up(_layout->last_block()->offset(), wordSize);
667   int static_fields_end = align_up(_static_layout->last_block()->offset(), wordSize);
668   int static_fields_size = (static_fields_end -
669       InstanceMirrorKlass::offset_of_static_fields()) / wordSize;
670   int nonstatic_field_end = align_up(_layout->last_block()->offset(), heapOopSize);
671 
672   // Pass back information needed for InstanceKlass creation
673 
674   _info->oop_map_blocks = nonstatic_oop_maps;
675   _info->_instance_size = align_object_size(instance_end / wordSize);



676   _info->_static_field_size = static_fields_size;
677   _info->_nonstatic_field_size = (nonstatic_field_end - instanceOopDesc::base_offset_in_bytes()) / heapOopSize;
678   _info->_has_nonstatic_fields = _has_nonstatic_fields;
679 
680   if (PrintFieldLayout) {
681     ResourceMark rm;
682     tty->print_cr("Layout of class %s", _classname->as_C_string());
683     tty->print_cr("Instance fields:");
684     _layout->print(tty, false, _super_klass);
685     tty->print_cr("Static fields:");
686     _static_layout->print(tty, true, nullptr);
687     tty->print_cr("Instance size = %d bytes", _info->_instance_size * wordSize);
688     tty->print_cr("---");
689   }
690 }
691 
692 void FieldLayoutBuilder::build_layout() {
693   compute_regular_layout();
694 }

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

673       FieldGroup* cg = _contended_groups.at(i);
674       if (cg->oop_count() > 0) {
675         assert(cg->oop_fields() != nullptr && cg->oop_fields()->at(0) != nullptr, "oop_count > 0 but no oop fields found");
676         nonstatic_oop_maps->add(cg->oop_fields()->at(0)->offset(), cg->oop_count());
677       }
678     }
679   }
680 
681   nonstatic_oop_maps->compact();
682 
683   int instance_end = align_up(_layout->last_block()->offset(), wordSize);
684   int static_fields_end = align_up(_static_layout->last_block()->offset(), wordSize);
685   int static_fields_size = (static_fields_end -
686       InstanceMirrorKlass::offset_of_static_fields()) / wordSize;
687   int nonstatic_field_end = align_up(_layout->last_block()->offset(), heapOopSize);
688 
689   // Pass back information needed for InstanceKlass creation
690 
691   _info->oop_map_blocks = nonstatic_oop_maps;
692   _info->_instance_size = align_object_size(instance_end / wordSize);
693   if (UseCompactObjectHeaders) {
694     _info->_hash_offset   = _layout->find_hash_offset();
695   }
696   _info->_static_field_size = static_fields_size;
697   _info->_nonstatic_field_size = (nonstatic_field_end - instanceOopDesc::base_offset_in_bytes()) / heapOopSize;
698   _info->_has_nonstatic_fields = _has_nonstatic_fields;
699 
700   if (PrintFieldLayout) {
701     ResourceMark rm;
702     tty->print_cr("Layout of class %s", _classname->as_C_string());
703     tty->print_cr("Instance fields:");
704     _layout->print(tty, false, _super_klass);
705     tty->print_cr("Static fields:");
706     _static_layout->print(tty, true, nullptr);
707     tty->print_cr("Instance size = %d bytes", _info->_instance_size * wordSize);
708     tty->print_cr("---");
709   }
710 }
711 
712 void FieldLayoutBuilder::build_layout() {
713   compute_regular_layout();
714 }
< prev index next >