192 if (cursor->kind() == LayoutRawBlock::EMPTY && cursor->fit(b->size(), b->alignment())) {
193 if (candidate == nullptr || cursor->size() < candidate->size()) {
194 candidate = cursor;
195 }
196 }
197 cursor = cursor->prev_block();
198 }
199 if (candidate == nullptr) {
200 candidate = last_block();
201 last_search_success = false;
202 }
203 assert(candidate != nullptr, "Candidate must not be null");
204 assert(candidate->kind() == LayoutRawBlock::EMPTY, "Candidate must be an empty block");
205 assert(candidate->fit(b->size(), b->alignment()), "Candidate must be able to store the block");
206 }
207
208 insert_field_block(candidate, b);
209 }
210 }
211
212 // Used for classes with hard coded field offsets, insert a field at the specified offset */
213 void FieldLayout::add_field_at_offset(LayoutRawBlock* block, int offset, LayoutRawBlock* start) {
214 assert(block != nullptr, "Sanity check");
215 block->set_offset(offset);
216 if (start == nullptr) {
217 start = this->_start;
218 }
219 LayoutRawBlock* slot = start;
220 while (slot != nullptr) {
221 if ((slot->offset() <= block->offset() && (slot->offset() + slot->size()) > block->offset()) ||
222 slot == _last){
223 assert(slot->kind() == LayoutRawBlock::EMPTY, "Matching slot must be an empty slot");
224 assert(slot->size() >= block->offset() + block->size() ,"Matching slot must be big enough");
225 if (slot->offset() < block->offset()) {
226 int adjustment = block->offset() - slot->offset();
227 LayoutRawBlock* adj = new LayoutRawBlock(LayoutRawBlock::EMPTY, adjustment);
228 insert(slot, adj);
229 }
230 insert(slot, block);
231 if (slot->size() == 0) {
657 FieldGroup* cg = _contended_groups.at(i);
658 if (cg->oop_count() > 0) {
659 assert(cg->oop_fields() != nullptr && cg->oop_fields()->at(0) != nullptr, "oop_count > 0 but no oop fields found");
660 nonstatic_oop_maps->add(cg->oop_fields()->at(0)->offset(), cg->oop_count());
661 }
662 }
663 }
664
665 nonstatic_oop_maps->compact();
666
667 int instance_end = align_up(_layout->last_block()->offset(), wordSize);
668 int static_fields_end = align_up(_static_layout->last_block()->offset(), wordSize);
669 int static_fields_size = (static_fields_end -
670 InstanceMirrorKlass::offset_of_static_fields()) / wordSize;
671 int nonstatic_field_end = align_up(_layout->last_block()->offset(), heapOopSize);
672
673 // Pass back information needed for InstanceKlass creation
674
675 _info->oop_map_blocks = nonstatic_oop_maps;
676 _info->_instance_size = align_object_size(instance_end / wordSize);
677 _info->_static_field_size = static_fields_size;
678 _info->_nonstatic_field_size = (nonstatic_field_end - instanceOopDesc::base_offset_in_bytes()) / heapOopSize;
679 _info->_has_nonstatic_fields = _has_nonstatic_fields;
680
681 if (PrintFieldLayout) {
682 ResourceMark rm;
683 tty->print_cr("Layout of class %s", _classname->as_C_string());
684 tty->print_cr("Instance fields:");
685 _layout->print(tty, false, _super_klass);
686 tty->print_cr("Static fields:");
687 _static_layout->print(tty, true, nullptr);
688 tty->print_cr("Instance size = %d bytes", _info->_instance_size * wordSize);
689 tty->print_cr("---");
690 }
691 }
692
693 void FieldLayoutBuilder::build_layout() {
694 compute_regular_layout();
695 }
|
192 if (cursor->kind() == LayoutRawBlock::EMPTY && cursor->fit(b->size(), b->alignment())) {
193 if (candidate == nullptr || cursor->size() < candidate->size()) {
194 candidate = cursor;
195 }
196 }
197 cursor = cursor->prev_block();
198 }
199 if (candidate == nullptr) {
200 candidate = last_block();
201 last_search_success = false;
202 }
203 assert(candidate != nullptr, "Candidate must not be null");
204 assert(candidate->kind() == LayoutRawBlock::EMPTY, "Candidate must be an empty block");
205 assert(candidate->fit(b->size(), b->alignment()), "Candidate must be able to store the block");
206 }
207
208 insert_field_block(candidate, b);
209 }
210 }
211
212 // Finds a slot for the identity hash-code.
213 // Same basic algorithm as above add() method, but simplified
214 // and does not actually insert the field.
215 int FieldLayout::find_hash_offset() {
216 LayoutRawBlock* start = this->_start;
217 LayoutRawBlock* last = last_block();
218 LayoutRawBlock* cursor = start;
219 while (cursor != last) {
220 assert(cursor != nullptr, "Sanity check");
221 if (cursor->kind() == LayoutRawBlock::EMPTY && cursor->fit(4, 1)) {
222 break;
223 }
224 cursor = cursor->next_block();
225 }
226 return cursor->offset();
227 }
228
229 // Used for classes with hard coded field offsets, insert a field at the specified offset */
230 void FieldLayout::add_field_at_offset(LayoutRawBlock* block, int offset, LayoutRawBlock* start) {
231 assert(block != nullptr, "Sanity check");
232 block->set_offset(offset);
233 if (start == nullptr) {
234 start = this->_start;
235 }
236 LayoutRawBlock* slot = start;
237 while (slot != nullptr) {
238 if ((slot->offset() <= block->offset() && (slot->offset() + slot->size()) > block->offset()) ||
239 slot == _last){
240 assert(slot->kind() == LayoutRawBlock::EMPTY, "Matching slot must be an empty slot");
241 assert(slot->size() >= block->offset() + block->size() ,"Matching slot must be big enough");
242 if (slot->offset() < block->offset()) {
243 int adjustment = block->offset() - slot->offset();
244 LayoutRawBlock* adj = new LayoutRawBlock(LayoutRawBlock::EMPTY, adjustment);
245 insert(slot, adj);
246 }
247 insert(slot, block);
248 if (slot->size() == 0) {
674 FieldGroup* cg = _contended_groups.at(i);
675 if (cg->oop_count() > 0) {
676 assert(cg->oop_fields() != nullptr && cg->oop_fields()->at(0) != nullptr, "oop_count > 0 but no oop fields found");
677 nonstatic_oop_maps->add(cg->oop_fields()->at(0)->offset(), cg->oop_count());
678 }
679 }
680 }
681
682 nonstatic_oop_maps->compact();
683
684 int instance_end = align_up(_layout->last_block()->offset(), wordSize);
685 int static_fields_end = align_up(_static_layout->last_block()->offset(), wordSize);
686 int static_fields_size = (static_fields_end -
687 InstanceMirrorKlass::offset_of_static_fields()) / wordSize;
688 int nonstatic_field_end = align_up(_layout->last_block()->offset(), heapOopSize);
689
690 // Pass back information needed for InstanceKlass creation
691
692 _info->oop_map_blocks = nonstatic_oop_maps;
693 _info->_instance_size = align_object_size(instance_end / wordSize);
694 if (UseCompactObjectHeaders) {
695 _info->_hash_offset = _layout->find_hash_offset();
696 }
697 _info->_static_field_size = static_fields_size;
698 _info->_nonstatic_field_size = (nonstatic_field_end - instanceOopDesc::base_offset_in_bytes()) / heapOopSize;
699 _info->_has_nonstatic_fields = _has_nonstatic_fields;
700
701 if (PrintFieldLayout) {
702 ResourceMark rm;
703 tty->print_cr("Layout of class %s", _classname->as_C_string());
704 tty->print_cr("Instance fields:");
705 _layout->print(tty, false, _super_klass);
706 tty->print_cr("Static fields:");
707 _static_layout->print(tty, true, nullptr);
708 tty->print_cr("Instance size = %d bytes", _info->_instance_size * wordSize);
709 tty->print_cr("---");
710 }
711 }
712
713 void FieldLayoutBuilder::build_layout() {
714 compute_regular_layout();
715 }
|