hotspot/src/share/vm/asm/codeBuffer.cpp
changeset 14588 8ec26d2d9339
parent 14294 130e947dfbe6
child 14633 58caa6fc3b7c
equal deleted inserted replaced
14584:bd4290e6d0a5 14588:8ec26d2d9339
   490   // Done calculating sections; did it come out to the right end?
   490   // Done calculating sections; did it come out to the right end?
   491   assert(buf_offset == total_content_size(), "sanity");
   491   assert(buf_offset == total_content_size(), "sanity");
   492   dest->verify_section_allocation();
   492   dest->verify_section_allocation();
   493 }
   493 }
   494 
   494 
       
   495 // Anonymous classes need mirror to keep the metadata alive but
       
   496 // for regular classes, the class_loader is sufficient.
       
   497 static void append_oop_references(GrowableArray<oop>* oops, Klass* k) {
       
   498   if (k->oop_is_instance()) {
       
   499     InstanceKlass* ik = InstanceKlass::cast(k);
       
   500     if (ik->is_anonymous()) {
       
   501       oop o = ik->java_mirror();
       
   502       assert (o != NULL, "should have a mirror");
       
   503       if (!oops->contains(o)) {
       
   504         oops->append(o);
       
   505       }
       
   506       return;  // only need the mirror
       
   507     }
       
   508   }
       
   509   oop cl = k->class_loader();
       
   510   if (cl != NULL && !oops->contains(cl)) {
       
   511     oops->append(cl);
       
   512   }
       
   513 }
       
   514 
   495 void CodeBuffer::finalize_oop_references(methodHandle mh) {
   515 void CodeBuffer::finalize_oop_references(methodHandle mh) {
   496   No_Safepoint_Verifier nsv;
   516   No_Safepoint_Verifier nsv;
   497 
   517 
   498   GrowableArray<oop> oops;
   518   GrowableArray<oop> oops;
   499 
   519 
   507       if (iter.type() == relocInfo::metadata_type) {
   527       if (iter.type() == relocInfo::metadata_type) {
   508         metadata_Relocation* md = iter.metadata_reloc();
   528         metadata_Relocation* md = iter.metadata_reloc();
   509         if (md->metadata_is_immediate()) {
   529         if (md->metadata_is_immediate()) {
   510           Metadata* m = md->metadata_value();
   530           Metadata* m = md->metadata_value();
   511           if (oop_recorder()->is_real(m)) {
   531           if (oop_recorder()->is_real(m)) {
   512             oop o = NULL;
       
   513             if (m->is_methodData()) {
   532             if (m->is_methodData()) {
   514               m = ((MethodData*)m)->method();
   533               m = ((MethodData*)m)->method();
   515             }
   534             }
   516             if (m->is_method()) {
   535             if (m->is_method()) {
   517               m = ((Method*)m)->method_holder();
   536               m = ((Method*)m)->method_holder();
   518             }
   537             }
   519             if (m->is_klass()) {
   538             if (m->is_klass()) {
   520               o = ((Klass*)m)->class_loader();
   539               append_oop_references(&oops, (Klass*)m);
   521             } else {
   540             } else {
   522               // XXX This will currently occur for MDO which don't
   541               // XXX This will currently occur for MDO which don't
   523               // have a backpointer.  This has to be fixed later.
   542               // have a backpointer.  This has to be fixed later.
   524               m->print();
   543               m->print();
   525               ShouldNotReachHere();
   544               ShouldNotReachHere();
   526             }
   545             }
   527             if (o != NULL && oops.find(o) == -1) {
       
   528               oops.append(o);
       
   529             }
       
   530           }
   546           }
   531         }
   547         }
   532       }
   548       }
   533     }
   549     }
   534   }
   550   }
   535 
   551 
   536   if (!oop_recorder()->is_unused()) {
   552   if (!oop_recorder()->is_unused()) {
   537     for (int i = 0; i < oop_recorder()->metadata_count(); i++) {
   553     for (int i = 0; i < oop_recorder()->metadata_count(); i++) {
   538       Metadata* m = oop_recorder()->metadata_at(i);
   554       Metadata* m = oop_recorder()->metadata_at(i);
   539       if (oop_recorder()->is_real(m)) {
   555       if (oop_recorder()->is_real(m)) {
   540         oop o = NULL;
       
   541         if (m->is_methodData()) {
   556         if (m->is_methodData()) {
   542           m = ((MethodData*)m)->method();
   557           m = ((MethodData*)m)->method();
   543         }
   558         }
   544         if (m->is_method()) {
   559         if (m->is_method()) {
   545           m = ((Method*)m)->method_holder();
   560           m = ((Method*)m)->method_holder();
   546         }
   561         }
   547         if (m->is_klass()) {
   562         if (m->is_klass()) {
   548           o = ((Klass*)m)->class_loader();
   563           append_oop_references(&oops, (Klass*)m);
   549         } else {
   564         } else {
   550           m->print();
   565           m->print();
   551           ShouldNotReachHere();
   566           ShouldNotReachHere();
   552         }
   567         }
   553         if (o != NULL && oops.find(o) == -1) {
       
   554           oops.append(o);
       
   555         }
       
   556       }
   568       }
   557     }
   569     }
   558 
   570 
   559   }
   571   }
   560 
   572 
   561   // Add the class loader of Method* for the nmethod itself
   573   // Add the class loader of Method* for the nmethod itself
   562   oop cl = mh->method_holder()->class_loader();
   574   append_oop_references(&oops, mh->method_holder());
   563   if (cl != NULL) {
       
   564     oops.append(cl);
       
   565   }
       
   566 
   575 
   567   // Add any oops that we've found
   576   // Add any oops that we've found
   568   Thread* thread = Thread::current();
   577   Thread* thread = Thread::current();
   569   for (int i = 0; i < oops.length(); i++) {
   578   for (int i = 0; i < oops.length(); i++) {
   570     oop_recorder()->find_index((jobject)thread->handle_area()->allocate_handle(oops.at(i)));
   579     oop_recorder()->find_index((jobject)thread->handle_area()->allocate_handle(oops.at(i)));