< prev index next >

src/hotspot/share/cds/archiveBuilder.cpp

Print this page

 405 
 406   int num_klasses = _klasses->length();
 407   for (i = 0; i < num_klasses; i++) {
 408     it->push(_klasses->adr_at(i));
 409   }
 410 
 411   iterate_roots(it, is_relocating_pointers);
 412 }
 413 
 414 class GatherSortedSourceObjs : public MetaspaceClosure {
 415   ArchiveBuilder* _builder;
 416 
 417 public:
 418   GatherSortedSourceObjs(ArchiveBuilder* builder) : _builder(builder) {}
 419 
 420   virtual bool do_ref(Ref* ref, bool read_only) {
 421     return _builder->gather_one_source_obj(enclosing_ref(), ref, read_only);
 422   }
 423 
 424   virtual void push_special(SpecialRef type, Ref* ref, intptr_t* p) {
 425     assert(type == _method_entry_ref, "only special type allowed for now");
 426     address src_obj = ref->obj();
 427     size_t field_offset = pointer_delta(p, src_obj,  sizeof(u1));
 428     _builder->add_special_ref(type, src_obj, field_offset);
 429   };
 430 
 431   virtual void do_pending_ref(Ref* ref) {
 432     if (ref->obj() != NULL) {
 433       _builder->remember_embedded_pointer_in_copied_obj(enclosing_ref(), ref);
 434     }
 435   }
 436 };
 437 
 438 bool ArchiveBuilder::gather_one_source_obj(MetaspaceClosure::Ref* enclosing_ref,
 439                                            MetaspaceClosure::Ref* ref, bool read_only) {
 440   address src_obj = ref->obj();
 441   if (src_obj == NULL) {
 442     return false;
 443   }
 444   ref->set_keep_after_pushing();
 445   remember_embedded_pointer_in_copied_obj(enclosing_ref, ref);
 446 
 447   FollowMode follow_mode = get_follow_mode(ref);
 448   SourceObjInfo src_info(ref, read_only, follow_mode);

 452     if (_src_obj_table.maybe_grow()) {
 453       log_info(cds, hashtables)("Expanded _src_obj_table table to %d", _src_obj_table.table_size());
 454     }
 455   }
 456 
 457   assert(p->read_only() == src_info.read_only(), "must be");
 458 
 459   if (created && src_info.should_copy()) {
 460     ref->set_user_data((void*)p);
 461     if (read_only) {
 462       _ro_src_objs.append(enclosing_ref, p);
 463     } else {
 464       _rw_src_objs.append(enclosing_ref, p);
 465     }
 466     return true; // Need to recurse into this ref only if we are copying it
 467   } else {
 468     return false;
 469   }
 470 }
 471 
 472 void ArchiveBuilder::add_special_ref(MetaspaceClosure::SpecialRef type, address src_obj, size_t field_offset) {
 473   _special_refs->append(SpecialRefInfo(type, src_obj, field_offset));
 474 }
 475 
 476 void ArchiveBuilder::remember_embedded_pointer_in_copied_obj(MetaspaceClosure::Ref* enclosing_ref,
 477                                                              MetaspaceClosure::Ref* ref) {
 478   assert(ref->obj() != NULL, "should have checked");
 479 
 480   if (enclosing_ref != NULL) {
 481     SourceObjInfo* src_info = (SourceObjInfo*)enclosing_ref->user_data();
 482     if (src_info == NULL) {
 483       // source objects of point_to_it/set_to_null types are not copied
 484       // so we don't need to remember their pointers.
 485     } else {
 486       if (src_info->read_only()) {
 487         _ro_src_objs.remember_embedded_pointer(src_info, ref);
 488       } else {
 489         _rw_src_objs.remember_embedded_pointer(src_info, ref);
 490       }
 491     }
 492   }
 493 }
 494 
 495 void ArchiveBuilder::gather_source_objs() {

 662   assert(is_in_buffer_space(buffered_addr), "must be");
 663   address* src_p = _buffered_to_src_table.get(buffered_addr);
 664   assert(src_p != NULL && *src_p != NULL, "must be");
 665   return *src_p;
 666 }
 667 
 668 void ArchiveBuilder::relocate_embedded_pointers(ArchiveBuilder::SourceObjList* src_objs) {
 669   for (int i = 0; i < src_objs->objs()->length(); i++) {
 670     src_objs->relocate(i, this);
 671   }
 672 }
 673 
 674 void ArchiveBuilder::update_special_refs() {
 675   for (int i = 0; i < _special_refs->length(); i++) {
 676     SpecialRefInfo s = _special_refs->at(i);
 677     size_t field_offset = s.field_offset();
 678     address src_obj = s.src_obj();
 679     address dst_obj = get_buffered_addr(src_obj);
 680     intptr_t* src_p = (intptr_t*)(src_obj + field_offset);
 681     intptr_t* dst_p = (intptr_t*)(dst_obj + field_offset);
 682     assert(s.type() == MetaspaceClosure::_method_entry_ref, "only special type allowed for now");
 683 
 684     assert(*src_p == *dst_p, "must be a copy");

















 685     ArchivePtrMarker::mark_pointer((address*)dst_p);
 686   }
 687 }
 688 
 689 class RefRelocator: public MetaspaceClosure {
 690   ArchiveBuilder* _builder;
 691 
 692 public:
 693   RefRelocator(ArchiveBuilder* builder) : _builder(builder) {}
 694 
 695   virtual bool do_ref(Ref* ref, bool read_only) {
 696     if (ref->not_null()) {
 697       ref->update(_builder->get_buffered_addr(ref->obj()));
 698       ArchivePtrMarker::mark_pointer(ref->addr());
 699     }
 700     return false; // Do not recurse.
 701   }
 702 };
 703 
 704 void ArchiveBuilder::relocate_roots() {

 405 
 406   int num_klasses = _klasses->length();
 407   for (i = 0; i < num_klasses; i++) {
 408     it->push(_klasses->adr_at(i));
 409   }
 410 
 411   iterate_roots(it, is_relocating_pointers);
 412 }
 413 
 414 class GatherSortedSourceObjs : public MetaspaceClosure {
 415   ArchiveBuilder* _builder;
 416 
 417 public:
 418   GatherSortedSourceObjs(ArchiveBuilder* builder) : _builder(builder) {}
 419 
 420   virtual bool do_ref(Ref* ref, bool read_only) {
 421     return _builder->gather_one_source_obj(enclosing_ref(), ref, read_only);
 422   }
 423 
 424   virtual void push_special(SpecialRef type, Ref* ref, intptr_t* p) {

 425     address src_obj = ref->obj();
 426     size_t field_offset = pointer_delta(p, src_obj,  sizeof(u1));
 427     _builder->add_special_ref(type, src_obj, field_offset, ref->size() * BytesPerWord);
 428   };
 429 
 430   virtual void do_pending_ref(Ref* ref) {
 431     if (ref->obj() != NULL) {
 432       _builder->remember_embedded_pointer_in_copied_obj(enclosing_ref(), ref);
 433     }
 434   }
 435 };
 436 
 437 bool ArchiveBuilder::gather_one_source_obj(MetaspaceClosure::Ref* enclosing_ref,
 438                                            MetaspaceClosure::Ref* ref, bool read_only) {
 439   address src_obj = ref->obj();
 440   if (src_obj == NULL) {
 441     return false;
 442   }
 443   ref->set_keep_after_pushing();
 444   remember_embedded_pointer_in_copied_obj(enclosing_ref, ref);
 445 
 446   FollowMode follow_mode = get_follow_mode(ref);
 447   SourceObjInfo src_info(ref, read_only, follow_mode);

 451     if (_src_obj_table.maybe_grow()) {
 452       log_info(cds, hashtables)("Expanded _src_obj_table table to %d", _src_obj_table.table_size());
 453     }
 454   }
 455 
 456   assert(p->read_only() == src_info.read_only(), "must be");
 457 
 458   if (created && src_info.should_copy()) {
 459     ref->set_user_data((void*)p);
 460     if (read_only) {
 461       _ro_src_objs.append(enclosing_ref, p);
 462     } else {
 463       _rw_src_objs.append(enclosing_ref, p);
 464     }
 465     return true; // Need to recurse into this ref only if we are copying it
 466   } else {
 467     return false;
 468   }
 469 }
 470 




 471 void ArchiveBuilder::remember_embedded_pointer_in_copied_obj(MetaspaceClosure::Ref* enclosing_ref,
 472                                                              MetaspaceClosure::Ref* ref) {
 473   assert(ref->obj() != NULL, "should have checked");
 474 
 475   if (enclosing_ref != NULL) {
 476     SourceObjInfo* src_info = (SourceObjInfo*)enclosing_ref->user_data();
 477     if (src_info == NULL) {
 478       // source objects of point_to_it/set_to_null types are not copied
 479       // so we don't need to remember their pointers.
 480     } else {
 481       if (src_info->read_only()) {
 482         _ro_src_objs.remember_embedded_pointer(src_info, ref);
 483       } else {
 484         _rw_src_objs.remember_embedded_pointer(src_info, ref);
 485       }
 486     }
 487   }
 488 }
 489 
 490 void ArchiveBuilder::gather_source_objs() {

 657   assert(is_in_buffer_space(buffered_addr), "must be");
 658   address* src_p = _buffered_to_src_table.get(buffered_addr);
 659   assert(src_p != NULL && *src_p != NULL, "must be");
 660   return *src_p;
 661 }
 662 
 663 void ArchiveBuilder::relocate_embedded_pointers(ArchiveBuilder::SourceObjList* src_objs) {
 664   for (int i = 0; i < src_objs->objs()->length(); i++) {
 665     src_objs->relocate(i, this);
 666   }
 667 }
 668 
 669 void ArchiveBuilder::update_special_refs() {
 670   for (int i = 0; i < _special_refs->length(); i++) {
 671     SpecialRefInfo s = _special_refs->at(i);
 672     size_t field_offset = s.field_offset();
 673     address src_obj = s.src_obj();
 674     address dst_obj = get_buffered_addr(src_obj);
 675     intptr_t* src_p = (intptr_t*)(src_obj + field_offset);
 676     intptr_t* dst_p = (intptr_t*)(dst_obj + field_offset);

 677 
 678 
 679     MetaspaceClosure::assert_valid(s.type());
 680     switch (s.type()) {
 681     case MetaspaceClosure::_method_entry_ref:
 682       assert(*src_p == *dst_p, "must be a copy");
 683       break;
 684     case MetaspaceClosure::_internal_pointer_ref:
 685       {
 686         // *src_p points to a location inside src_obj. Let's make *dst_p point to
 687         // the same location inside dst_obj.
 688         size_t off = pointer_delta(*((address*)src_p), src_obj, sizeof(u1));
 689         assert(off < s.src_obj_size_in_bytes(), "must point to internal address");
 690         *((address*)dst_p) = dst_obj + off;
 691       }
 692       break;
 693     default:
 694       ShouldNotReachHere();
 695     }
 696     ArchivePtrMarker::mark_pointer((address*)dst_p);
 697   }
 698 }
 699 
 700 class RefRelocator: public MetaspaceClosure {
 701   ArchiveBuilder* _builder;
 702 
 703 public:
 704   RefRelocator(ArchiveBuilder* builder) : _builder(builder) {}
 705 
 706   virtual bool do_ref(Ref* ref, bool read_only) {
 707     if (ref->not_null()) {
 708       ref->update(_builder->get_buffered_addr(ref->obj()));
 709       ArchivePtrMarker::mark_pointer(ref->addr());
 710     }
 711     return false; // Do not recurse.
 712   }
 713 };
 714 
 715 void ArchiveBuilder::relocate_roots() {
< prev index next >