193 if (cursor->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->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->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) {
680 FieldGroup* cg = _contended_groups.at(i);
681 if (cg->oop_count() > 0) {
682 assert(cg->oop_fields() != nullptr && cg->oop_fields()->at(0) != nullptr, "oop_count > 0 but no oop fields found");
683 nonstatic_oop_maps->add(cg->oop_fields()->at(0)->offset(), cg->oop_count());
684 }
685 }
686 }
687
688 nonstatic_oop_maps->compact();
689
690 int instance_end = align_up(_layout->last_block()->offset(), wordSize);
691 int static_fields_end = align_up(_static_layout->last_block()->offset(), wordSize);
692 int static_fields_size = (static_fields_end -
693 InstanceMirrorKlass::offset_of_static_fields()) / wordSize;
694 int nonstatic_field_end = align_up(_layout->last_block()->offset(), heapOopSize);
695
696 // Pass back information needed for InstanceKlass creation
697
698 _info->oop_map_blocks = nonstatic_oop_maps;
699 _info->_instance_size = align_object_size(instance_end / wordSize);
700 _info->_static_field_size = static_fields_size;
701 _info->_nonstatic_field_size = (nonstatic_field_end - instanceOopDesc::base_offset_in_bytes()) / heapOopSize;
702 _info->_has_nonstatic_fields = _has_nonstatic_fields;
703
704 if (PrintFieldLayout) {
705 ResourceMark rm;
706 tty->print_cr("Layout of class %s", _classname->as_C_string());
707 tty->print_cr("Instance fields:");
708 _layout->print(tty, false, _super_klass);
709 tty->print_cr("Static fields:");
710 _static_layout->print(tty, true, nullptr);
711 tty->print_cr("Instance size = %d bytes", _info->_instance_size * wordSize);
712 tty->print_cr("---");
713 }
714 }
715
716 void FieldLayoutBuilder::build_layout() {
717 compute_regular_layout();
718 }
|
193 if (cursor->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->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->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->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) {
697 FieldGroup* cg = _contended_groups.at(i);
698 if (cg->oop_count() > 0) {
699 assert(cg->oop_fields() != nullptr && cg->oop_fields()->at(0) != nullptr, "oop_count > 0 but no oop fields found");
700 nonstatic_oop_maps->add(cg->oop_fields()->at(0)->offset(), cg->oop_count());
701 }
702 }
703 }
704
705 nonstatic_oop_maps->compact();
706
707 int instance_end = align_up(_layout->last_block()->offset(), wordSize);
708 int static_fields_end = align_up(_static_layout->last_block()->offset(), wordSize);
709 int static_fields_size = (static_fields_end -
710 InstanceMirrorKlass::offset_of_static_fields()) / wordSize;
711 int nonstatic_field_end = align_up(_layout->last_block()->offset(), heapOopSize);
712
713 // Pass back information needed for InstanceKlass creation
714
715 _info->oop_map_blocks = nonstatic_oop_maps;
716 _info->_instance_size = align_object_size(instance_end / wordSize);
717 if (UseCompactObjectHeaders) {
718 _info->_hash_offset = _layout->find_hash_offset();
719 }
720 _info->_static_field_size = static_fields_size;
721 _info->_nonstatic_field_size = (nonstatic_field_end - instanceOopDesc::base_offset_in_bytes()) / heapOopSize;
722 _info->_has_nonstatic_fields = _has_nonstatic_fields;
723
724 if (PrintFieldLayout) {
725 ResourceMark rm;
726 tty->print_cr("Layout of class %s", _classname->as_C_string());
727 tty->print_cr("Instance fields:");
728 _layout->print(tty, false, _super_klass);
729 tty->print_cr("Static fields:");
730 _static_layout->print(tty, true, nullptr);
731 tty->print_cr("Instance size = %d bytes", _info->_instance_size * wordSize);
732 tty->print_cr("---");
733 }
734 }
735
736 void FieldLayoutBuilder::build_layout() {
737 compute_regular_layout();
738 }
|