< prev index next >

src/share/vm/compiler/oopMap.cpp

Print this page




  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "code/codeBlob.hpp"
  27 #include "code/codeCache.hpp"
  28 #include "code/nmethod.hpp"
  29 #include "code/scopeDesc.hpp"
  30 #include "compiler/oopMap.hpp"
  31 #include "gc/shared/collectedHeap.hpp"
  32 #include "memory/allocation.inline.hpp"
  33 #include "memory/resourceArea.hpp"
  34 #include "runtime/frame.inline.hpp"
  35 #include "runtime/signature.hpp"
  36 #ifdef COMPILER1
  37 #include "c1/c1_Defs.hpp"
  38 #endif
  39 #ifdef COMPILER2
  40 #include "opto/optoreg.hpp"
  41 #endif



  42 
  43 // OopMapStream
  44 
  45 OopMapStream::OopMapStream(OopMap* oop_map, int oop_types_mask) {
  46   _stream = new CompressedReadStream(oop_map->write_stream()->buffer());
  47   _mask = oop_types_mask;
  48   _size = oop_map->omv_count();
  49   _position = 0;
  50   _valid_omv = false;
  51 }
  52 
  53 OopMapStream::OopMapStream(const ImmutableOopMap* oop_map, int oop_types_mask) {
  54   _stream = new CompressedReadStream(oop_map->data_addr());
  55   _mask = oop_types_mask;
  56   _size = oop_map->count();
  57   _position = 0;
  58   _valid_omv = false;
  59 }
  60 
  61 void OopMapStream::find_next() {


 255       break;
 256   }
 257 
 258   assert( i < len, "oopmap not found" );
 259 
 260   OopMap* m = at(i);
 261   assert( m->offset() == pc_offset, "oopmap not found" );
 262   return m;
 263 }
 264 
 265 class DoNothingClosure: public OopClosure {
 266  public:
 267   void do_oop(oop* p)       {}
 268   void do_oop(narrowOop* p) {}
 269 };
 270 static DoNothingClosure do_nothing;
 271 
 272 static void add_derived_oop(oop* base, oop* derived) {
 273 #ifndef TIERED
 274   COMPILER1_PRESENT(ShouldNotReachHere();)





 275 #endif // TIERED
 276 #ifdef COMPILER2
 277   DerivedPointerTable::add(derived, base);
 278 #endif // COMPILER2
 279 }
 280 
 281 
 282 #ifndef PRODUCT
 283 static void trace_codeblob_maps(const frame *fr, const RegisterMap *reg_map) {
 284   // Print oopmap and regmap
 285   tty->print_cr("------ ");
 286   CodeBlob* cb = fr->cb();
 287   ImmutableOopMapSet* maps = cb->oop_maps();
 288   const ImmutableOopMap* map = cb->oop_map_for_return_address(fr->pc());
 289   map->print();
 290   if( cb->is_nmethod() ) {
 291     nmethod* nm = (nmethod*)cb;
 292     // native wrappers have no scope data, it is implied
 293     if (nm->is_native_method()) {
 294       tty->print("bci: 0 (native)");
 295     } else {
 296       ScopeDesc* scope  = nm->scope_desc_at(fr->pc());
 297       tty->print("bci: %d ",scope->bci());
 298     }
 299   }
 300   tty->cr();
 301   fr->print_on(tty);
 302   tty->print("     ");
 303   cb->print_value_on(tty);  tty->cr();
 304   reg_map->print();
 305   tty->print_cr("------ ");
 306 
 307 }
 308 #endif // PRODUCT
 309 
 310 void OopMapSet::oops_do(const frame *fr, const RegisterMap* reg_map, OopClosure* f) {
 311   // add derived oops to a table
 312   all_do(fr, reg_map, f, add_derived_oop, &do_nothing);
 313 }
 314 
 315 
 316 void OopMapSet::all_do(const frame *fr, const RegisterMap *reg_map,
 317                        OopClosure* oop_fn, void derived_oop_fn(oop*, oop*),
 318                        OopClosure* value_fn) {
 319   CodeBlob* cb = fr->cb();
 320   assert(cb != NULL, "no codeblob");
 321 
 322   NOT_PRODUCT(if (TraceCodeBlobStacks) trace_codeblob_maps(fr, reg_map);)
 323 
 324   ImmutableOopMapSet* maps = cb->oop_maps();
 325   const ImmutableOopMap* map = cb->oop_map_for_return_address(fr->pc());
 326   assert(map != NULL, "no ptr map found");
 327 
 328   // handle derived pointers first (otherwise base pointer may be
 329   // changed before derived pointer offset has been collected)
 330   OopMapValue omv;
 331   {
 332     OopMapStream oms(map,OopMapValue::derived_oop_value);
 333     if (!oms.is_done()) {
 334 #ifndef TIERED
 335       COMPILER1_PRESENT(ShouldNotReachHere();)





 336 #endif // !TIERED
 337       // Protect the operation on the derived pointers.  This
 338       // protects the addition of derived pointers to the shared
 339       // derived pointer table in DerivedPointerTable::add().
 340       MutexLockerEx x(DerivedPointerTableGC_lock, Mutex::_no_safepoint_check_flag);
 341       do {
 342         omv = oms.current();
 343         oop* loc = fr->oopmapreg_to_location(omv.reg(),reg_map);
 344         guarantee(loc != NULL, "missing saved register");
 345         oop *base_loc    = fr->oopmapreg_to_location(omv.content_reg(), reg_map);
 346         oop *derived_loc = loc;
 347         oop val = *base_loc;
 348         if (val == (oop)NULL || Universe::is_narrow_oop_base(val)) {
 349           // Ignore NULL oops and decoded NULL narrow oops which
 350           // equal to Universe::narrow_oop_base when a narrow oop
 351           // implicit null check is used in compiled code.
 352           // The narrow_oop_base could be NULL or be the address
 353           // of the page below heap depending on compressed oops mode.
 354         } else {
 355           derived_oop_fn(base_loc, derived_loc);


 431          "include_argument_oops should already be set");
 432 
 433   // Scan through oopmap and find location of all callee-saved registers
 434   // (we do not do update in place, since info could be overwritten)
 435 
 436   address pc = fr->pc();
 437   const ImmutableOopMap* map  = cb->oop_map_for_return_address(pc);
 438   assert(map != NULL, "no ptr map found");
 439   DEBUG_ONLY(int nof_callee = 0;)
 440 
 441   for (OopMapStream oms(map, OopMapValue::callee_saved_value); !oms.is_done(); oms.next()) {
 442     OopMapValue omv = oms.current();
 443     VMReg reg = omv.content_reg();
 444     oop* loc = fr->oopmapreg_to_location(omv.reg(), reg_map);
 445     reg_map->set_location(reg, (address) loc);
 446     DEBUG_ONLY(nof_callee++;)
 447   }
 448 
 449   // Check that runtime stubs save all callee-saved registers
 450 #ifdef COMPILER2
 451   assert(cb->is_compiled_by_c1() || !cb->is_runtime_stub() ||
 452          (nof_callee >= SAVED_ON_ENTRY_REG_COUNT || nof_callee >= C_SAVED_ON_ENTRY_REG_COUNT),
 453          "must save all");
 454 #endif // COMPILER2
 455 }
 456 
 457 //=============================================================================
 458 // Non-Product code
 459 
 460 #ifndef PRODUCT
 461 
 462 bool ImmutableOopMap::has_derived_pointer() const {
 463 #ifndef TIERED
 464   COMPILER1_PRESENT(return false);





 465 #endif // !TIERED
 466 #ifdef COMPILER2
 467   OopMapStream oms((OopMap*)this,OopMapValue::derived_oop_value);
 468   return oms.is_done();
 469 #else
 470   return false;
 471 #endif // COMPILER2
 472 }
 473 
 474 #endif //PRODUCT
 475 
 476 // Printing code is present in product build for -XX:+PrintAssembly.
 477 
 478 static
 479 void print_register_type(OopMapValue::oop_types x, VMReg optional,
 480                          outputStream* st) {
 481   switch( x ) {
 482   case OopMapValue::oop_value:
 483     st->print("Oop");
 484     break;
 485   case OopMapValue::narrowoop_value:
 486     st->print("NarrowOop");
 487     break;
 488   case OopMapValue::callee_saved_value:
 489     st->print("Callers_");
 490     optional->print_on(st);
 491     break;


 584 const ImmutableOopMap* ImmutableOopMapPair::get_from(const ImmutableOopMapSet* set) const {
 585   return set->oopmap_at_offset(_oopmap_offset);
 586 }
 587 
 588 ImmutableOopMap::ImmutableOopMap(const OopMap* oopmap) : _count(oopmap->count()) {
 589   address addr = data_addr();
 590   oopmap->copy_data_to(addr);
 591 }
 592 
 593 #ifdef ASSERT
 594 int ImmutableOopMap::nr_of_bytes() const {
 595   OopMapStream oms(this);
 596 
 597   while (!oms.is_done()) {
 598     oms.next();
 599   }
 600   return sizeof(ImmutableOopMap) + oms.stream_position();
 601 }
 602 #endif
 603 
 604 class ImmutableOopMapBuilder {
 605 private:
 606   class Mapping;
 607 
 608 private:
 609   const OopMapSet* _set;
 610   const OopMap* _empty;
 611   const OopMap* _last;
 612   int _empty_offset;
 613   int _last_offset;
 614   int _offset;
 615   Mapping* _mapping;
 616   ImmutableOopMapSet* _new_set;
 617 
 618   /* Used for bookkeeping when building ImmutableOopMaps */
 619   class Mapping : public ResourceObj {
 620   public:
 621     enum kind_t { OOPMAP_UNKNOWN = 0, OOPMAP_NEW = 1, OOPMAP_EMPTY = 2, OOPMAP_DUPLICATE = 3 };
 622 
 623     kind_t _kind;
 624     int _offset;
 625     int _size;
 626     const OopMap* _map;
 627     const OopMap* _other;
 628 
 629     Mapping() : _kind(OOPMAP_UNKNOWN), _offset(-1), _size(-1), _map(NULL) {}
 630 
 631     void set(kind_t kind, int offset, int size, const OopMap* map = 0, const OopMap* other = 0) {
 632       _kind = kind;
 633       _offset = offset;
 634       _size = size;
 635       _map = map;
 636       _other = other;
 637     }
 638   };
 639 
 640 public:
 641   ImmutableOopMapBuilder(const OopMapSet* set) : _set(set), _new_set(NULL), _empty(NULL), _last(NULL), _empty_offset(-1), _last_offset(-1), _offset(0) {
 642     _mapping = NEW_RESOURCE_ARRAY(Mapping, _set->size());
 643   }
 644 
 645   int heap_size();
 646   ImmutableOopMapSet* build();
 647 private:
 648   bool is_empty(const OopMap* map) const {
 649     return map->count() == 0;
 650   }
 651 
 652   bool is_last_duplicate(const OopMap* map) {
 653     if (_last != NULL && _last->count() > 0 && _last->equals(map)) {
 654       return true;
 655     }
 656     return false;
 657   }
 658 
 659 #ifdef ASSERT
 660   void verify(address buffer, int size, const ImmutableOopMapSet* set);
 661 #endif
 662 
 663   bool has_empty() const {
 664     return _empty_offset != -1;
 665   }
 666 
 667   int size_for(const OopMap* map) const;
 668   void fill_pair(ImmutableOopMapPair* pair, const OopMap* map, int offset, const ImmutableOopMapSet* set);
 669   int fill_map(ImmutableOopMapPair* pair, const OopMap* map, int offset, const ImmutableOopMapSet* set);
 670   void fill(ImmutableOopMapSet* set, int size);
 671 };
 672 
 673 int ImmutableOopMapBuilder::size_for(const OopMap* map) const {
 674   return align_size_up(sizeof(ImmutableOopMap) + map->data_size(), 8);
 675 }
 676 
 677 int ImmutableOopMapBuilder::heap_size() {
 678   int base = sizeof(ImmutableOopMapSet);
 679   base = align_size_up(base, 8);
 680 
 681   // all of ours pc / offset pairs
 682   int pairs = _set->size() * sizeof(ImmutableOopMapPair);
 683   pairs = align_size_up(pairs, 8);
 684 
 685   for (int i = 0; i < _set->size(); ++i) {
 686     int size = 0;
 687     OopMap* map = _set->at(i);
 688 
 689     if (is_empty(map)) {
 690       /* only keep a single empty map in the set */
 691       if (has_empty()) {


 696         size = size_for(map);
 697         _mapping[i].set(Mapping::OOPMAP_NEW, _offset, size, map);
 698       }
 699     } else if (is_last_duplicate(map)) {
 700       /* if this entry is identical to the previous one, just point it there */
 701       _mapping[i].set(Mapping::OOPMAP_DUPLICATE, _last_offset, 0, map, _last);
 702     } else {
 703       /* not empty, not an identical copy of the previous entry */
 704       size = size_for(map);
 705       _mapping[i].set(Mapping::OOPMAP_NEW, _offset, size, map);
 706       _last_offset = _offset;
 707       _last = map;
 708     }
 709 
 710     assert(_mapping[i]._map == map, "check");
 711     _offset += size;
 712   }
 713 
 714   int total = base + pairs + _offset;
 715   DEBUG_ONLY(total += 8);

 716   return total;
 717 }
 718 
 719 void ImmutableOopMapBuilder::fill_pair(ImmutableOopMapPair* pair, const OopMap* map, int offset, const ImmutableOopMapSet* set) {
 720   assert(offset < set->nr_of_bytes(), "check");
 721   new ((address) pair) ImmutableOopMapPair(map->offset(), offset);
 722 }
 723 
 724 int ImmutableOopMapBuilder::fill_map(ImmutableOopMapPair* pair, const OopMap* map, int offset, const ImmutableOopMapSet* set) {
 725   fill_pair(pair, map, offset, set);
 726   address addr = (address) pair->get_from(_new_set); // location of the ImmutableOopMap
 727 
 728   new (addr) ImmutableOopMap(map);
 729   return align_size_up(sizeof(ImmutableOopMap) + map->data_size(), 8);
 730 }
 731 
 732 void ImmutableOopMapBuilder::fill(ImmutableOopMapSet* set, int sz) {
 733   ImmutableOopMapPair* pairs = set->get_pairs();
 734 
 735   for (int i = 0; i < set->count(); ++i) {


 747     assert(memcmp(map->data(), nv->data_addr(), map->data_size()) == 0, "check identity");
 748   }
 749 }
 750 
 751 #ifdef ASSERT
 752 void ImmutableOopMapBuilder::verify(address buffer, int size, const ImmutableOopMapSet* set) {
 753   for (int i = 0; i < 8; ++i) {
 754     assert(buffer[size - 8 + i] == (unsigned char) 0xff, "overwritten memory check");
 755   }
 756 
 757   for (int i = 0; i < set->count(); ++i) {
 758     const ImmutableOopMapPair* pair = set->pair_at(i);
 759     assert(pair->oopmap_offset() < set->nr_of_bytes(), "check size");
 760     const ImmutableOopMap* map = pair->get_from(set);
 761     int nr_of_bytes = map->nr_of_bytes();
 762     assert(pair->oopmap_offset() + nr_of_bytes <= set->nr_of_bytes(), "check size + size");
 763   }
 764 }
 765 #endif
 766 
 767 ImmutableOopMapSet* ImmutableOopMapBuilder::build() {
 768   int required = heap_size();
 769 
 770   // We need to allocate a chunk big enough to hold the ImmutableOopMapSet and all of its ImmutableOopMaps
 771   address buffer = (address) NEW_C_HEAP_ARRAY(unsigned char, required, mtCode);
 772   DEBUG_ONLY(memset(&buffer[required-8], 0xff, 8));
 773 
 774   _new_set = new (buffer) ImmutableOopMapSet(_set, required);
 775   fill(_new_set, required);
 776 
 777   DEBUG_ONLY(verify(buffer, required, _new_set));
 778 
 779   return _new_set;
 780 }
 781 








 782 ImmutableOopMapSet* ImmutableOopMapSet::build_from(const OopMapSet* oopmap_set) {
 783   ResourceMark mark;
 784   ImmutableOopMapBuilder builder(oopmap_set);
 785   return builder.build();
 786 }
 787 
 788 
 789 //------------------------------DerivedPointerTable---------------------------
 790 
 791 #ifdef COMPILER2
 792 
 793 class DerivedPointerEntry : public CHeapObj<mtCompiler> {
 794  private:
 795   oop*     _location; // Location of derived pointer (also pointing to the base)
 796   intptr_t _offset;   // Offset from base pointer
 797  public:
 798   DerivedPointerEntry(oop* location, intptr_t offset) { _location = location; _offset = offset; }
 799   oop* location()    { return _location; }
 800   intptr_t  offset() { return _offset; }
 801 };
 802 
 803 
 804 GrowableArray<DerivedPointerEntry*>* DerivedPointerTable::_list = NULL;
 805 bool DerivedPointerTable::_active = false;
 806 
 807 
 808 void DerivedPointerTable::clear() {
 809   // The first time, we create the list.  Otherwise it should be
 810   // empty.  If not, then we have probably forgotton to call
 811   // update_pointers after last GC/Scavenge.


 864     assert(value_of_loc(derived_loc) - value_of_loc(&base) == offset, "sanity check");
 865 
 866     if (TraceDerivedPointers) {
 867       tty->print_cr("Updating derived pointer@" INTPTR_FORMAT
 868                     " - Derived: " INTPTR_FORMAT "  Base: " INTPTR_FORMAT " (Offset: " INTX_FORMAT ")",
 869           p2i(derived_loc), p2i((address)*derived_loc), p2i((address)base), offset);
 870     }
 871 
 872     // Delete entry
 873     delete entry;
 874     _list->at_put(i, NULL);
 875   }
 876   // Clear list, so it is ready for next traversal (this is an invariant)
 877   if (TraceDerivedPointers && !_list->is_empty()) {
 878     tty->print_cr("--------------------------");
 879   }
 880   _list->clear();
 881   _active = false;
 882 }
 883 
 884 #endif // COMPILER2


  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "code/codeBlob.hpp"
  27 #include "code/codeCache.hpp"
  28 #include "code/nmethod.hpp"
  29 #include "code/scopeDesc.hpp"
  30 #include "compiler/oopMap.hpp"
  31 #include "gc/shared/collectedHeap.hpp"
  32 #include "memory/allocation.inline.hpp"
  33 #include "memory/resourceArea.hpp"
  34 #include "runtime/frame.inline.hpp"
  35 #include "runtime/signature.hpp"
  36 #ifdef COMPILER1
  37 #include "c1/c1_Defs.hpp"
  38 #endif
  39 #ifdef COMPILER2
  40 #include "opto/optoreg.hpp"
  41 #endif
  42 #ifdef SPARC
  43 #include "vmreg_sparc.inline.hpp"
  44 #endif
  45 
  46 // OopMapStream
  47 
  48 OopMapStream::OopMapStream(OopMap* oop_map, int oop_types_mask) {
  49   _stream = new CompressedReadStream(oop_map->write_stream()->buffer());
  50   _mask = oop_types_mask;
  51   _size = oop_map->omv_count();
  52   _position = 0;
  53   _valid_omv = false;
  54 } 
  55 
  56 OopMapStream::OopMapStream(const ImmutableOopMap* oop_map, int oop_types_mask) {
  57   _stream = new CompressedReadStream(oop_map->data_addr());
  58   _mask = oop_types_mask;
  59   _size = oop_map->count();
  60   _position = 0;
  61   _valid_omv = false;
  62 }
  63 
  64 void OopMapStream::find_next() {


 258       break;
 259   }
 260 
 261   assert( i < len, "oopmap not found" );
 262 
 263   OopMap* m = at(i);
 264   assert( m->offset() == pc_offset, "oopmap not found" );
 265   return m;
 266 }
 267 
 268 class DoNothingClosure: public OopClosure {
 269  public:
 270   void do_oop(oop* p)       {}
 271   void do_oop(narrowOop* p) {}
 272 };
 273 static DoNothingClosure do_nothing;
 274 
 275 static void add_derived_oop(oop* base, oop* derived) {
 276 #ifndef TIERED
 277   COMPILER1_PRESENT(ShouldNotReachHere();)
 278 #if INCLUDE_JVMCI
 279   if (UseJVMCICompiler) {
 280     ShouldNotReachHere();
 281   }
 282 #endif
 283 #endif // TIERED
 284 #if defined(COMPILER2) || INCLUDE_JVMCI
 285   DerivedPointerTable::add(derived, base);
 286 #endif // COMPILER2 || INCLUDE_JVMCI
 287 }
 288 
 289 
 290 #ifndef PRODUCT
 291 static void trace_codeblob_maps(const frame *fr, const RegisterMap *reg_map) {
 292   // Print oopmap and regmap
 293   tty->print_cr("------ ");
 294   CodeBlob* cb = fr->cb();
 295   const ImmutableOopMapSet* maps = cb->oop_maps();
 296   const ImmutableOopMap* map = cb->oop_map_for_return_address(fr->pc());
 297   map->print();
 298   if( cb->is_nmethod() ) {
 299     nmethod* nm = (nmethod*)cb;
 300     // native wrappers have no scope data, it is implied
 301     if (nm->is_native_method()) {
 302       tty->print("bci: 0 (native)");
 303     } else {
 304       ScopeDesc* scope  = nm->scope_desc_at(fr->pc());
 305       tty->print("bci: %d ",scope->bci());
 306     }
 307   }
 308   tty->cr();
 309   fr->print_on(tty);
 310   tty->print("     ");
 311   cb->print_value_on(tty);  tty->cr();
 312   reg_map->print();
 313   tty->print_cr("------ ");
 314 
 315 }
 316 #endif // PRODUCT
 317 
 318 void OopMapSet::oops_do(const frame *fr, const RegisterMap* reg_map, OopClosure* f) {
 319   // add derived oops to a table
 320   all_do(fr, reg_map, f, add_derived_oop, &do_nothing);
 321 }
 322 
 323 
 324 void OopMapSet::all_do(const frame *fr, const RegisterMap *reg_map,
 325                        OopClosure* oop_fn, void derived_oop_fn(oop*, oop*),
 326                        OopClosure* value_fn) {
 327   CodeBlob* cb = fr->cb();
 328   assert(cb != NULL, "no codeblob");
 329 
 330   NOT_PRODUCT(if (TraceCodeBlobStacks) trace_codeblob_maps(fr, reg_map);)
 331 
 332   const ImmutableOopMapSet* maps = cb->oop_maps();
 333   const ImmutableOopMap* map = cb->oop_map_for_return_address(fr->pc());
 334   assert(map != NULL, "no ptr map found");
 335 
 336   // handle derived pointers first (otherwise base pointer may be
 337   // changed before derived pointer offset has been collected)
 338   OopMapValue omv;
 339   {
 340     OopMapStream oms(map,OopMapValue::derived_oop_value);
 341     if (!oms.is_done()) {
 342 #ifndef TIERED
 343       COMPILER1_PRESENT(ShouldNotReachHere();)
 344 #if INCLUDE_JVMCI
 345       if (UseJVMCICompiler) {
 346         ShouldNotReachHere();
 347       }
 348 #endif
 349 #endif // !TIERED
 350       // Protect the operation on the derived pointers.  This
 351       // protects the addition of derived pointers to the shared
 352       // derived pointer table in DerivedPointerTable::add().
 353       MutexLockerEx x(DerivedPointerTableGC_lock, Mutex::_no_safepoint_check_flag);
 354       do {
 355         omv = oms.current();
 356         oop* loc = fr->oopmapreg_to_location(omv.reg(),reg_map);
 357         guarantee(loc != NULL, "missing saved register");
 358         oop *base_loc    = fr->oopmapreg_to_location(omv.content_reg(), reg_map);
 359         oop *derived_loc = loc;
 360         oop val = *base_loc;
 361         if (val == (oop)NULL || Universe::is_narrow_oop_base(val)) {
 362           // Ignore NULL oops and decoded NULL narrow oops which
 363           // equal to Universe::narrow_oop_base when a narrow oop
 364           // implicit null check is used in compiled code.
 365           // The narrow_oop_base could be NULL or be the address
 366           // of the page below heap depending on compressed oops mode.
 367         } else {
 368           derived_oop_fn(base_loc, derived_loc);


 444          "include_argument_oops should already be set");
 445 
 446   // Scan through oopmap and find location of all callee-saved registers
 447   // (we do not do update in place, since info could be overwritten)
 448 
 449   address pc = fr->pc();
 450   const ImmutableOopMap* map  = cb->oop_map_for_return_address(pc);
 451   assert(map != NULL, "no ptr map found");
 452   DEBUG_ONLY(int nof_callee = 0;)
 453 
 454   for (OopMapStream oms(map, OopMapValue::callee_saved_value); !oms.is_done(); oms.next()) {
 455     OopMapValue omv = oms.current();
 456     VMReg reg = omv.content_reg();
 457     oop* loc = fr->oopmapreg_to_location(omv.reg(), reg_map);
 458     reg_map->set_location(reg, (address) loc);
 459     DEBUG_ONLY(nof_callee++;)
 460   }
 461 
 462   // Check that runtime stubs save all callee-saved registers
 463 #ifdef COMPILER2
 464   assert(cb->is_compiled_by_c1() || cb->is_compiled_by_jvmci() || !cb->is_runtime_stub() ||
 465          (nof_callee >= SAVED_ON_ENTRY_REG_COUNT || nof_callee >= C_SAVED_ON_ENTRY_REG_COUNT),
 466          "must save all");
 467 #endif // COMPILER2
 468 }
 469 
 470 //=============================================================================
 471 // Non-Product code
 472 
 473 #ifndef PRODUCT
 474 
 475 bool ImmutableOopMap::has_derived_pointer() const {
 476 #ifndef TIERED
 477   COMPILER1_PRESENT(return false);
 478 #if INCLUDE_JVMCI
 479   if (UseJVMCICompiler) {
 480     return false;
 481   }
 482 #endif
 483 #endif // !TIERED
 484 #if defined(COMPILER2) || INCLUDE_JVMCI
 485   OopMapStream oms(this,OopMapValue::derived_oop_value);
 486   return oms.is_done();
 487 #else
 488   return false;
 489 #endif // COMPILER2 || INCLUDE_JVMCI
 490 }
 491 
 492 #endif //PRODUCT
 493 
 494 // Printing code is present in product build for -XX:+PrintAssembly.
 495 
 496 static
 497 void print_register_type(OopMapValue::oop_types x, VMReg optional,
 498                          outputStream* st) {
 499   switch( x ) {
 500   case OopMapValue::oop_value:
 501     st->print("Oop");
 502     break;
 503   case OopMapValue::narrowoop_value:
 504     st->print("NarrowOop");
 505     break;
 506   case OopMapValue::callee_saved_value:
 507     st->print("Callers_");
 508     optional->print_on(st);
 509     break;


 602 const ImmutableOopMap* ImmutableOopMapPair::get_from(const ImmutableOopMapSet* set) const {
 603   return set->oopmap_at_offset(_oopmap_offset);
 604 }
 605 
 606 ImmutableOopMap::ImmutableOopMap(const OopMap* oopmap) : _count(oopmap->count()) {
 607   address addr = data_addr();
 608   oopmap->copy_data_to(addr);
 609 }
 610 
 611 #ifdef ASSERT
 612 int ImmutableOopMap::nr_of_bytes() const {
 613   OopMapStream oms(this);
 614 
 615   while (!oms.is_done()) {
 616     oms.next();
 617   }
 618   return sizeof(ImmutableOopMap) + oms.stream_position();
 619 }
 620 #endif
 621 
 622 ImmutableOopMapBuilder::ImmutableOopMapBuilder(const OopMapSet* set) : _set(set), _new_set(NULL), _empty(NULL), _last(NULL), _empty_offset(-1), _last_offset(-1), _offset(0), _required(-1) {





































 623   _mapping = NEW_RESOURCE_ARRAY(Mapping, _set->size());
 624 }




























 625 
 626 int ImmutableOopMapBuilder::size_for(const OopMap* map) const {
 627   return align_size_up(sizeof(ImmutableOopMap) + map->data_size(), 8);
 628 }
 629 
 630 int ImmutableOopMapBuilder::heap_size() {
 631   int base = sizeof(ImmutableOopMapSet);
 632   base = align_size_up(base, 8);
 633 
 634   // all of ours pc / offset pairs
 635   int pairs = _set->size() * sizeof(ImmutableOopMapPair);
 636   pairs = align_size_up(pairs, 8);
 637 
 638   for (int i = 0; i < _set->size(); ++i) {
 639     int size = 0;
 640     OopMap* map = _set->at(i);
 641 
 642     if (is_empty(map)) {
 643       /* only keep a single empty map in the set */
 644       if (has_empty()) {


 649         size = size_for(map);
 650         _mapping[i].set(Mapping::OOPMAP_NEW, _offset, size, map);
 651       }
 652     } else if (is_last_duplicate(map)) {
 653       /* if this entry is identical to the previous one, just point it there */
 654       _mapping[i].set(Mapping::OOPMAP_DUPLICATE, _last_offset, 0, map, _last);
 655     } else {
 656       /* not empty, not an identical copy of the previous entry */
 657       size = size_for(map);
 658       _mapping[i].set(Mapping::OOPMAP_NEW, _offset, size, map);
 659       _last_offset = _offset;
 660       _last = map;
 661     }
 662 
 663     assert(_mapping[i]._map == map, "check");
 664     _offset += size;
 665   }
 666 
 667   int total = base + pairs + _offset;
 668   DEBUG_ONLY(total += 8);
 669   _required = total;
 670   return total;
 671 }
 672 
 673 void ImmutableOopMapBuilder::fill_pair(ImmutableOopMapPair* pair, const OopMap* map, int offset, const ImmutableOopMapSet* set) {
 674   assert(offset < set->nr_of_bytes(), "check");
 675   new ((address) pair) ImmutableOopMapPair(map->offset(), offset);
 676 }
 677 
 678 int ImmutableOopMapBuilder::fill_map(ImmutableOopMapPair* pair, const OopMap* map, int offset, const ImmutableOopMapSet* set) {
 679   fill_pair(pair, map, offset, set);
 680   address addr = (address) pair->get_from(_new_set); // location of the ImmutableOopMap
 681 
 682   new (addr) ImmutableOopMap(map);
 683   return align_size_up(sizeof(ImmutableOopMap) + map->data_size(), 8);
 684 }
 685 
 686 void ImmutableOopMapBuilder::fill(ImmutableOopMapSet* set, int sz) {
 687   ImmutableOopMapPair* pairs = set->get_pairs();
 688 
 689   for (int i = 0; i < set->count(); ++i) {


 701     assert(memcmp(map->data(), nv->data_addr(), map->data_size()) == 0, "check identity");
 702   }
 703 }
 704 
 705 #ifdef ASSERT
 706 void ImmutableOopMapBuilder::verify(address buffer, int size, const ImmutableOopMapSet* set) {
 707   for (int i = 0; i < 8; ++i) {
 708     assert(buffer[size - 8 + i] == (unsigned char) 0xff, "overwritten memory check");
 709   }
 710 
 711   for (int i = 0; i < set->count(); ++i) {
 712     const ImmutableOopMapPair* pair = set->pair_at(i);
 713     assert(pair->oopmap_offset() < set->nr_of_bytes(), "check size");
 714     const ImmutableOopMap* map = pair->get_from(set);
 715     int nr_of_bytes = map->nr_of_bytes();
 716     assert(pair->oopmap_offset() + nr_of_bytes <= set->nr_of_bytes(), "check size + size");
 717   }
 718 }
 719 #endif
 720 
 721 ImmutableOopMapSet* ImmutableOopMapBuilder::generate_into(address buffer) {
 722   DEBUG_ONLY(memset(&buffer[_required-8], 0xff, 8));




 723 
 724   _new_set = new (buffer) ImmutableOopMapSet(_set, _required);
 725   fill(_new_set, _required);
 726 
 727   DEBUG_ONLY(verify(buffer, _required, _new_set));
 728 
 729   return _new_set;
 730 }
 731 
 732 ImmutableOopMapSet* ImmutableOopMapBuilder::build() {
 733   _required = heap_size();
 734 
 735   // We need to allocate a chunk big enough to hold the ImmutableOopMapSet and all of its ImmutableOopMaps
 736   address buffer = (address) NEW_C_HEAP_ARRAY(unsigned char, _required, mtCode);
 737   return generate_into(buffer);
 738 }
 739 
 740 ImmutableOopMapSet* ImmutableOopMapSet::build_from(const OopMapSet* oopmap_set) {
 741   ResourceMark mark;
 742   ImmutableOopMapBuilder builder(oopmap_set);
 743   return builder.build();
 744 }
 745  
 746 
 747 //------------------------------DerivedPointerTable---------------------------
 748 
 749 #if defined(COMPILER2) || INCLUDE_JVMCI
 750 
 751 class DerivedPointerEntry : public CHeapObj<mtCompiler> {
 752  private:
 753   oop*     _location; // Location of derived pointer (also pointing to the base)
 754   intptr_t _offset;   // Offset from base pointer
 755  public:
 756   DerivedPointerEntry(oop* location, intptr_t offset) { _location = location; _offset = offset; }
 757   oop* location()    { return _location; }
 758   intptr_t  offset() { return _offset; }
 759 };
 760 
 761 
 762 GrowableArray<DerivedPointerEntry*>* DerivedPointerTable::_list = NULL;
 763 bool DerivedPointerTable::_active = false;
 764 
 765 
 766 void DerivedPointerTable::clear() {
 767   // The first time, we create the list.  Otherwise it should be
 768   // empty.  If not, then we have probably forgotton to call
 769   // update_pointers after last GC/Scavenge.


 822     assert(value_of_loc(derived_loc) - value_of_loc(&base) == offset, "sanity check");
 823 
 824     if (TraceDerivedPointers) {
 825       tty->print_cr("Updating derived pointer@" INTPTR_FORMAT
 826                     " - Derived: " INTPTR_FORMAT "  Base: " INTPTR_FORMAT " (Offset: " INTX_FORMAT ")",
 827           p2i(derived_loc), p2i((address)*derived_loc), p2i((address)base), offset);
 828     }
 829 
 830     // Delete entry
 831     delete entry;
 832     _list->at_put(i, NULL);
 833   }
 834   // Clear list, so it is ready for next traversal (this is an invariant)
 835   if (TraceDerivedPointers && !_list->is_empty()) {
 836     tty->print_cr("--------------------------");
 837   }
 838   _list->clear();
 839   _active = false;
 840 }
 841 
 842 #endif // COMPILER2 || INCLUDE_JVMCI
< prev index next >