1 /*
   2  * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  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_interface/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) {
  46   if(oop_map->omv_data() == NULL) {
  47     _stream = new CompressedReadStream(oop_map->write_stream()->buffer());
  48   } else {
  49     _stream = new CompressedReadStream(oop_map->omv_data());
  50   }
  51   _mask = OopMapValue::type_mask_in_place;
  52   _size = oop_map->omv_count();
  53   _position = 0;
  54   _valid_omv = false;
  55 }
  56 
  57 
  58 OopMapStream::OopMapStream(OopMap* oop_map, int oop_types_mask) {
  59   if(oop_map->omv_data() == NULL) {
  60     _stream = new CompressedReadStream(oop_map->write_stream()->buffer());
  61   } else {
  62     _stream = new CompressedReadStream(oop_map->omv_data());
  63   }
  64   _mask = oop_types_mask;
  65   _size = oop_map->omv_count();
  66   _position = 0;
  67   _valid_omv = false;
  68 }
  69 
  70 
  71 void OopMapStream::find_next() {
  72   while(_position++ < _size) {
  73     _omv.read_from(_stream);
  74     if(((int)_omv.type() & _mask) > 0) {
  75       _valid_omv = true;
  76       return;
  77     }
  78   }
  79   _valid_omv = false;
  80 }
  81 
  82 
  83 // OopMap
  84 
  85 // frame_size units are stack-slots (4 bytes) NOT intptr_t; we can name odd
  86 // slots to hold 4-byte values like ints and floats in the LP64 build.
  87 OopMap::OopMap(int frame_size, int arg_count) {
  88   // OopMaps are usually quite so small, so pick a small initial size
  89   set_write_stream(new CompressedWriteStream(32));
  90   set_omv_data(NULL);
  91   set_omv_count(0);
  92 
  93 #ifdef ASSERT
  94   _locs_length = VMRegImpl::stack2reg(0)->value() + frame_size + arg_count;
  95   _locs_used   = NEW_RESOURCE_ARRAY(OopMapValue::oop_types, _locs_length);
  96   for(int i = 0; i < _locs_length; i++) _locs_used[i] = OopMapValue::unused_value;
  97 #endif
  98 }
  99 
 100 
 101 OopMap::OopMap(OopMap::DeepCopyToken, OopMap* source) {
 102   // This constructor does a deep copy
 103   // of the source OopMap.
 104   set_write_stream(new CompressedWriteStream(source->omv_count() * 2));
 105   set_omv_data(NULL);
 106   set_omv_count(0);
 107   set_offset(source->offset());
 108 
 109 #ifdef ASSERT
 110   _locs_length = source->_locs_length;
 111   _locs_used = NEW_RESOURCE_ARRAY(OopMapValue::oop_types, _locs_length);
 112   for(int i = 0; i < _locs_length; i++) _locs_used[i] = OopMapValue::unused_value;
 113 #endif
 114 
 115   // We need to copy the entries too.
 116   for (OopMapStream oms(source); !oms.is_done(); oms.next()) {
 117     OopMapValue omv = oms.current();
 118     omv.write_on(write_stream());
 119     increment_count();
 120   }
 121 }
 122 
 123 
 124 OopMap* OopMap::deep_copy() {
 125   return new OopMap(_deep_copy_token, this);
 126 }
 127 
 128 
 129 void OopMap::copy_to(address addr) {
 130   memcpy(addr,this,sizeof(OopMap));
 131   memcpy(addr + sizeof(OopMap),write_stream()->buffer(),write_stream()->position());
 132   OopMap* new_oop = (OopMap*)addr;
 133   new_oop->set_omv_data_size(write_stream()->position());
 134   new_oop->set_omv_data((unsigned char *)(addr + sizeof(OopMap)));
 135   new_oop->set_write_stream(NULL);
 136 }
 137 
 138 
 139 int OopMap::heap_size() const {
 140   int size = sizeof(OopMap);
 141   int align = sizeof(void *) - 1;
 142   if(write_stream() != NULL) {
 143     size += write_stream()->position();
 144   } else {
 145     size += omv_data_size();
 146   }
 147   // Align to a reasonable ending point
 148   size = ((size+align) & ~align);
 149   return size;
 150 }
 151 
 152 // frame_size units are stack-slots (4 bytes) NOT intptr_t; we can name odd
 153 // slots to hold 4-byte values like ints and floats in the LP64 build.
 154 void OopMap::set_xxx(VMReg reg, OopMapValue::oop_types x, VMReg optional) {
 155 
 156   assert(reg->value() < _locs_length, "too big reg value for stack size");
 157   assert( _locs_used[reg->value()] == OopMapValue::unused_value, "cannot insert twice" );
 158   debug_only( _locs_used[reg->value()] = x; )
 159 
 160   OopMapValue o(reg, x);
 161 
 162   if(x == OopMapValue::callee_saved_value) {
 163     // This can never be a stack location, so we don't need to transform it.
 164     assert(optional->is_reg(), "Trying to callee save a stack location");
 165     o.set_content_reg(optional);
 166   } else if(x == OopMapValue::derived_oop_value) {
 167     o.set_content_reg(optional);
 168   }
 169 
 170   o.write_on(write_stream());
 171   increment_count();
 172 }
 173 
 174 
 175 void OopMap::set_oop(VMReg reg) {
 176   set_xxx(reg, OopMapValue::oop_value, VMRegImpl::Bad());
 177 }
 178 
 179 
 180 void OopMap::set_value(VMReg reg) {
 181   // At this time, we only need value entries in our OopMap when ZapDeadCompiledLocals is active.
 182   if (ZapDeadCompiledLocals)
 183     set_xxx(reg, OopMapValue::value_value, VMRegImpl::Bad());
 184 }
 185 
 186 
 187 void OopMap::set_narrowoop(VMReg reg) {
 188   set_xxx(reg, OopMapValue::narrowoop_value, VMRegImpl::Bad());
 189 }
 190 
 191 
 192 void OopMap::set_callee_saved(VMReg reg, VMReg caller_machine_register ) {
 193   set_xxx(reg, OopMapValue::callee_saved_value, caller_machine_register);
 194 }
 195 
 196 
 197 void OopMap::set_derived_oop(VMReg reg, VMReg derived_from_local_register ) {
 198   if( reg == derived_from_local_register ) {
 199     // Actually an oop, derived shares storage with base,
 200     set_oop(reg);
 201   } else {
 202     set_xxx(reg, OopMapValue::derived_oop_value, derived_from_local_register);
 203   }
 204 }
 205 
 206 // OopMapSet
 207 
 208 OopMapSet::OopMapSet() {
 209   set_om_size(MinOopMapAllocation);
 210   set_om_count(0);
 211   OopMap** temp = NEW_RESOURCE_ARRAY(OopMap*, om_size());
 212   set_om_data(temp);
 213 }
 214 
 215 
 216 void OopMapSet::grow_om_data() {
 217   int new_size = om_size() * 2;
 218   OopMap** new_data = NEW_RESOURCE_ARRAY(OopMap*, new_size);
 219   memcpy(new_data,om_data(),om_size() * sizeof(OopMap*));
 220   set_om_size(new_size);
 221   set_om_data(new_data);
 222 }
 223 
 224 
 225 void OopMapSet::copy_to(address addr) {
 226   address temp = addr;
 227   int align = sizeof(void *) - 1;
 228   // Copy this
 229   memcpy(addr,this,sizeof(OopMapSet));
 230   temp += sizeof(OopMapSet);
 231   temp = (address)((intptr_t)(temp + align) & ~align);
 232   // Do the needed fixups to the new OopMapSet
 233   OopMapSet* new_set = (OopMapSet*)addr;
 234   new_set->set_om_data((OopMap**)temp);
 235   // Allow enough space for the OopMap pointers
 236   temp += (om_count() * sizeof(OopMap*));
 237 
 238   for(int i=0; i < om_count(); i++) {
 239     OopMap* map = at(i);
 240     map->copy_to((address)temp);
 241     new_set->set(i,(OopMap*)temp);
 242     temp += map->heap_size();
 243   }
 244   // This "locks" the OopMapSet
 245   new_set->set_om_size(-1);
 246 }
 247 
 248 
 249 void OopMapSet::add_gc_map(int pc_offset, OopMap *map ) {
 250   assert(om_size() != -1,"Cannot grow a fixed OopMapSet");
 251 
 252   if(om_count() >= om_size()) {
 253     grow_om_data();
 254   }
 255   map->set_offset(pc_offset);
 256 
 257 #ifdef ASSERT
 258   if(om_count() > 0) {
 259     OopMap* last = at(om_count()-1);
 260     if (last->offset() == map->offset() ) {
 261       fatal("OopMap inserted twice");
 262     }
 263     if(last->offset() > map->offset()) {
 264       tty->print_cr( "WARNING, maps not sorted: pc[%d]=%d, pc[%d]=%d",
 265                       om_count(),last->offset(),om_count()+1,map->offset());
 266     }
 267   }
 268 #endif // ASSERT
 269 
 270   set(om_count(),map);
 271   increment_count();
 272 }
 273 
 274 
 275 int OopMapSet::heap_size() const {
 276   // The space we use
 277   int size = sizeof(OopMap);
 278   int align = sizeof(void *) - 1;
 279   size = ((size+align) & ~align);
 280   size += om_count() * sizeof(OopMap*);
 281 
 282   // Now add in the space needed for the indivdiual OopMaps
 283   for(int i=0; i < om_count(); i++) {
 284     size += at(i)->heap_size();
 285   }
 286   // We don't need to align this, it will be naturally pointer aligned
 287   return size;
 288 }
 289 
 290 
 291 OopMap* OopMapSet::singular_oop_map() {
 292   guarantee(om_count() == 1, "Make sure we only have a single gc point");
 293   return at(0);
 294 }
 295 
 296 
 297 OopMap* OopMapSet::find_map_at_offset(int pc_offset) const {
 298   int i, len = om_count();
 299   assert( len > 0, "must have pointer maps" );
 300 
 301   // Scan through oopmaps. Stop when current offset is either equal or greater
 302   // than the one we are looking for.
 303   for( i = 0; i < len; i++) {
 304     if( at(i)->offset() >= pc_offset )
 305       break;
 306   }
 307 
 308   assert( i < len, "oopmap not found" );
 309 
 310   OopMap* m = at(i);
 311   assert( m->offset() == pc_offset, "oopmap not found" );
 312   return m;
 313 }
 314 
 315 class DoNothingClosure: public OopClosure {
 316  public:
 317   void do_oop(oop* p)       {}
 318   void do_oop(narrowOop* p) {}
 319 };
 320 static DoNothingClosure do_nothing;
 321 
 322 static void add_derived_oop(oop* base, oop* derived) {
 323 #ifndef TIERED
 324   COMPILER1_PRESENT(ShouldNotReachHere();)
 325 #endif // TIERED
 326 #ifdef COMPILER2
 327   DerivedPointerTable::add(derived, base);
 328 #endif // COMPILER2
 329 }
 330 
 331 
 332 #ifndef PRODUCT
 333 static void trace_codeblob_maps(const frame *fr, const RegisterMap *reg_map) {
 334   // Print oopmap and regmap
 335   tty->print_cr("------ ");
 336   CodeBlob* cb = fr->cb();
 337   OopMapSet* maps = cb->oop_maps();
 338   OopMap* map = cb->oop_map_for_return_address(fr->pc());
 339   map->print();
 340   if( cb->is_nmethod() ) {
 341     nmethod* nm = (nmethod*)cb;
 342     // native wrappers have no scope data, it is implied
 343     if (nm->is_native_method()) {
 344       tty->print("bci: 0 (native)");
 345     } else {
 346       ScopeDesc* scope  = nm->scope_desc_at(fr->pc());
 347       tty->print("bci: %d ",scope->bci());
 348     }
 349   }
 350   tty->cr();
 351   fr->print_on(tty);
 352   tty->print("     ");
 353   cb->print_value_on(tty);  tty->cr();
 354   reg_map->print();
 355   tty->print_cr("------ ");
 356 
 357 }
 358 #endif // PRODUCT
 359 
 360 void OopMapSet::oops_do(const frame *fr, const RegisterMap* reg_map, OopClosure* f) {
 361   // add derived oops to a table
 362   all_do(fr, reg_map, f, add_derived_oop, &do_nothing);
 363 }
 364 
 365 
 366 void OopMapSet::all_do(const frame *fr, const RegisterMap *reg_map,
 367                        OopClosure* oop_fn, void derived_oop_fn(oop*, oop*),
 368                        OopClosure* value_fn) {
 369   CodeBlob* cb = fr->cb();
 370   assert(cb != NULL, "no codeblob");
 371 
 372   NOT_PRODUCT(if (TraceCodeBlobStacks) trace_codeblob_maps(fr, reg_map);)
 373 
 374   OopMapSet* maps = cb->oop_maps();
 375   OopMap* map = cb->oop_map_for_return_address(fr->pc());
 376   assert(map != NULL, "no ptr map found");
 377 
 378   // handle derived pointers first (otherwise base pointer may be
 379   // changed before derived pointer offset has been collected)
 380   OopMapValue omv;
 381   {
 382     OopMapStream oms(map,OopMapValue::derived_oop_value);
 383     if (!oms.is_done()) {
 384 #ifndef TIERED
 385       COMPILER1_PRESENT(ShouldNotReachHere();)
 386 #endif // !TIERED
 387       // Protect the operation on the derived pointers.  This
 388       // protects the addition of derived pointers to the shared
 389       // derived pointer table in DerivedPointerTable::add().
 390       MutexLockerEx x(DerivedPointerTableGC_lock, Mutex::_no_safepoint_check_flag);
 391       do {
 392         omv = oms.current();
 393         oop* loc = fr->oopmapreg_to_location(omv.reg(),reg_map);
 394         if ( loc != NULL ) {
 395           oop *base_loc    = fr->oopmapreg_to_location(omv.content_reg(), reg_map);
 396           oop *derived_loc = loc;
 397           oop val = *base_loc;
 398           if (val == (oop)NULL || Universe::is_narrow_oop_base(val)) {
 399             // Ignore NULL oops and decoded NULL narrow oops which
 400             // equal to Universe::narrow_oop_base when a narrow oop
 401             // implicit null check is used in compiled code.
 402             // The narrow_oop_base could be NULL or be the address
 403             // of the page below heap depending on compressed oops mode.
 404           } else
 405             derived_oop_fn(base_loc, derived_loc);
 406         }
 407         oms.next();
 408       }  while (!oms.is_done());
 409     }
 410   }
 411 
 412   // We want coop, value and oop oop_types
 413   int mask = OopMapValue::oop_value | OopMapValue::value_value | OopMapValue::narrowoop_value;
 414   {
 415     for (OopMapStream oms(map,mask); !oms.is_done(); oms.next()) {
 416       omv = oms.current();
 417       oop* loc = fr->oopmapreg_to_location(omv.reg(),reg_map);
 418       if ( loc != NULL ) {
 419         if ( omv.type() == OopMapValue::oop_value ) {
 420           oop val = *loc;
 421           if (val == (oop)NULL || Universe::is_narrow_oop_base(val)) {
 422             // Ignore NULL oops and decoded NULL narrow oops which
 423             // equal to Universe::narrow_oop_base when a narrow oop
 424             // implicit null check is used in compiled code.
 425             // The narrow_oop_base could be NULL or be the address
 426             // of the page below heap depending on compressed oops mode.
 427             continue;
 428           }
 429 #ifdef ASSERT
 430           if ((((uintptr_t)loc & (sizeof(*loc)-1)) != 0) ||
 431              !Universe::heap()->is_in_or_null(*loc)) {
 432             tty->print_cr("# Found non oop pointer.  Dumping state at failure");
 433             // try to dump out some helpful debugging information
 434             trace_codeblob_maps(fr, reg_map);
 435             omv.print();
 436             tty->print_cr("register r");
 437             omv.reg()->print();
 438             tty->print_cr("loc = %p *loc = %p\n", loc, (address)*loc);
 439             // do the real assert.
 440             assert(Universe::heap()->is_in_or_null(*loc), "found non oop pointer");
 441           }
 442 #endif // ASSERT
 443           oop_fn->do_oop(loc);
 444         } else if ( omv.type() == OopMapValue::value_value ) {
 445           assert((*loc) == (oop)NULL || !Universe::is_narrow_oop_base(*loc),
 446                  "found invalid value pointer");
 447           value_fn->do_oop(loc);
 448         } else if ( omv.type() == OopMapValue::narrowoop_value ) {
 449           narrowOop *nl = (narrowOop*)loc;
 450 #ifndef VM_LITTLE_ENDIAN
 451           if (!omv.reg()->is_stack()) {
 452             // compressed oops in registers only take up 4 bytes of an
 453             // 8 byte register but they are in the wrong part of the
 454             // word so adjust loc to point at the right place.
 455             nl = (narrowOop*)((address)nl + 4);
 456           }
 457 #endif
 458           oop_fn->do_oop(nl);
 459         }
 460       }
 461     }
 462   }
 463 }
 464 
 465 
 466 // Update callee-saved register info for the following frame
 467 void OopMapSet::update_register_map(const frame *fr, RegisterMap *reg_map) {
 468   ResourceMark rm;
 469   CodeBlob* cb = fr->cb();
 470   assert(cb != NULL, "no codeblob");
 471 
 472   // Any reg might be saved by a safepoint handler (see generate_handler_blob).
 473   assert( reg_map->_update_for_id == NULL || fr->is_older(reg_map->_update_for_id),
 474          "already updated this map; do not 'update' it twice!" );
 475   debug_only(reg_map->_update_for_id = fr->id());
 476 
 477   // Check if caller must update oop argument
 478   assert((reg_map->include_argument_oops() ||
 479           !cb->caller_must_gc_arguments(reg_map->thread())),
 480          "include_argument_oops should already be set");
 481 
 482   // Scan through oopmap and find location of all callee-saved registers
 483   // (we do not do update in place, since info could be overwritten)
 484 
 485   address pc = fr->pc();
 486   OopMap* map  = cb->oop_map_for_return_address(pc);
 487   assert(map != NULL, "no ptr map found");
 488   DEBUG_ONLY(int nof_callee = 0;)
 489 
 490   for (OopMapStream oms(map, OopMapValue::callee_saved_value); !oms.is_done(); oms.next()) {
 491     OopMapValue omv = oms.current();
 492     VMReg reg = omv.content_reg();
 493     oop* loc = fr->oopmapreg_to_location(omv.reg(), reg_map);
 494     reg_map->set_location(reg, (address) loc);
 495     DEBUG_ONLY(nof_callee++;)
 496   }
 497 
 498   // Check that runtime stubs save all callee-saved registers
 499 #ifdef COMPILER2
 500   assert(cb->is_compiled_by_c1() || !cb->is_runtime_stub() ||
 501          (nof_callee >= SAVED_ON_ENTRY_REG_COUNT || nof_callee >= C_SAVED_ON_ENTRY_REG_COUNT),
 502          "must save all");
 503 #endif // COMPILER2
 504 }
 505 
 506 //=============================================================================
 507 // Non-Product code
 508 
 509 #ifndef PRODUCT
 510 
 511 bool OopMap::has_derived_pointer() const {
 512 #ifndef TIERED
 513   COMPILER1_PRESENT(return false);
 514 #endif // !TIERED
 515 #ifdef COMPILER2
 516   OopMapStream oms((OopMap*)this,OopMapValue::derived_oop_value);
 517   return oms.is_done();
 518 #else
 519   return false;
 520 #endif // COMPILER2
 521 }
 522 
 523 #endif //PRODUCT
 524 
 525 // Printing code is present in product build for -XX:+PrintAssembly.
 526 
 527 static
 528 void print_register_type(OopMapValue::oop_types x, VMReg optional,
 529                          outputStream* st) {
 530   switch( x ) {
 531   case OopMapValue::oop_value:
 532     st->print("Oop");
 533     break;
 534   case OopMapValue::value_value:
 535     st->print("Value");
 536     break;
 537   case OopMapValue::narrowoop_value:
 538     st->print("NarrowOop");
 539     break;
 540   case OopMapValue::callee_saved_value:
 541     st->print("Callers_");
 542     optional->print_on(st);
 543     break;
 544   case OopMapValue::derived_oop_value:
 545     st->print("Derived_oop_");
 546     optional->print_on(st);
 547     break;
 548   default:
 549     ShouldNotReachHere();
 550   }
 551 }
 552 
 553 
 554 void OopMapValue::print_on(outputStream* st) const {
 555   reg()->print_on(st);
 556   st->print("=");
 557   print_register_type(type(),content_reg(),st);
 558   st->print(" ");
 559 }
 560 
 561 
 562 void OopMap::print_on(outputStream* st) const {
 563   OopMapValue omv;
 564   st->print("OopMap{");
 565   for(OopMapStream oms((OopMap*)this); !oms.is_done(); oms.next()) {
 566     omv = oms.current();
 567     omv.print_on(st);
 568   }
 569   st->print("off=%d}", (int) offset());
 570 }
 571 
 572 
 573 void OopMapSet::print_on(outputStream* st) const {
 574   int i, len = om_count();
 575 
 576   st->print_cr("OopMapSet contains %d OopMaps\n",len);
 577 
 578   for( i = 0; i < len; i++) {
 579     OopMap* m = at(i);
 580     st->print_cr("#%d ",i);
 581     m->print_on(st);
 582     st->cr();
 583   }
 584 }
 585 
 586 
 587 
 588 //------------------------------DerivedPointerTable---------------------------
 589 
 590 #ifdef COMPILER2
 591 
 592 class DerivedPointerEntry : public CHeapObj<mtCompiler> {
 593  private:
 594   oop*     _location; // Location of derived pointer (also pointing to the base)
 595   intptr_t _offset;   // Offset from base pointer
 596  public:
 597   DerivedPointerEntry(oop* location, intptr_t offset) { _location = location; _offset = offset; }
 598   oop* location()    { return _location; }
 599   intptr_t  offset() { return _offset; }
 600 };
 601 
 602 
 603 GrowableArray<DerivedPointerEntry*>* DerivedPointerTable::_list = NULL;
 604 bool DerivedPointerTable::_active = false;
 605 
 606 
 607 void DerivedPointerTable::clear() {
 608   // The first time, we create the list.  Otherwise it should be
 609   // empty.  If not, then we have probably forgotton to call
 610   // update_pointers after last GC/Scavenge.
 611   assert (!_active, "should not be active");
 612   assert(_list == NULL || _list->length() == 0, "table not empty");
 613   if (_list == NULL) {
 614     _list = new (ResourceObj::C_HEAP, mtCompiler) GrowableArray<DerivedPointerEntry*>(10, true); // Allocated on C heap
 615   }
 616   _active = true;
 617 }
 618 
 619 
 620 // Returns value of location as an int
 621 intptr_t value_of_loc(oop *pointer) { return cast_from_oop<intptr_t>((*pointer)); }
 622 
 623 
 624 void DerivedPointerTable::add(oop *derived_loc, oop *base_loc) {
 625   assert(Universe::heap()->is_in_or_null(*base_loc), "not an oop");
 626   assert(derived_loc != base_loc, "Base and derived in same location");
 627   if (_active) {
 628     assert(*derived_loc != (oop)base_loc, "location already added");
 629     assert(_list != NULL, "list must exist");
 630     intptr_t offset = value_of_loc(derived_loc) - value_of_loc(base_loc);
 631     // This assert is invalid because derived pointers can be
 632     // arbitrarily far away from their base.
 633     // assert(offset >= -1000000, "wrong derived pointer info");
 634 
 635     if (TraceDerivedPointers) {
 636       tty->print_cr(
 637         "Add derived pointer@" INTPTR_FORMAT
 638         " - Derived: " INTPTR_FORMAT
 639         " Base: " INTPTR_FORMAT " (@" INTPTR_FORMAT ") (Offset: " INTX_FORMAT ")",
 640         p2i(derived_loc), p2i((address)*derived_loc), p2i((address)*base_loc), p2i(base_loc), offset
 641       );
 642     }
 643     // Set derived oop location to point to base.
 644     *derived_loc = (oop)base_loc;
 645     assert_lock_strong(DerivedPointerTableGC_lock);
 646     DerivedPointerEntry *entry = new DerivedPointerEntry(derived_loc, offset);
 647     _list->append(entry);
 648   }
 649 }
 650 
 651 
 652 void DerivedPointerTable::update_pointers() {
 653   assert(_list != NULL, "list must exist");
 654   for(int i = 0; i < _list->length(); i++) {
 655     DerivedPointerEntry* entry = _list->at(i);
 656     oop* derived_loc = entry->location();
 657     intptr_t offset  = entry->offset();
 658     // The derived oop was setup to point to location of base
 659     oop  base        = **(oop**)derived_loc;
 660     assert(Universe::heap()->is_in_or_null(base), "must be an oop");
 661 
 662     *derived_loc = (oop)(((address)base) + offset);
 663     assert(value_of_loc(derived_loc) - value_of_loc(&base) == offset, "sanity check");
 664 
 665     if (TraceDerivedPointers) {
 666       tty->print_cr("Updating derived pointer@" INTPTR_FORMAT
 667                     " - Derived: " INTPTR_FORMAT "  Base: " INTPTR_FORMAT " (Offset: " INTX_FORMAT ")",
 668           p2i(derived_loc), p2i((address)*derived_loc), p2i((address)base), offset);
 669     }
 670 
 671     // Delete entry
 672     delete entry;
 673     _list->at_put(i, NULL);
 674   }
 675   // Clear list, so it is ready for next traversal (this is an invariant)
 676   if (TraceDerivedPointers && !_list->is_empty()) {
 677     tty->print_cr("--------------------------");
 678   }
 679   _list->clear();
 680   _active = false;
 681 }
 682 
 683 #endif // COMPILER2