bool OopNCode::gc_unmark_contents() { ResourceMark m; bool needToInvalICache = false; addrDesc* p = locs(), *end = locsEnd(); LocChange* changes = NEW_RESOURCE_ARRAY( LocChange, end - p); int32 locLen = 0; for (; p < end; p++) { if (!p->isOop()) { // no oops here } else { oop oldOop = (oop)p->referent(this); oop newOop = oldOop; UNMARK_TEMPLATE(&newOop); if (newOop != oldOop) { changes[locLen].p = p; changes[locLen].newOop = newOop; locLen ++; needToInvalICache = true; } } } for (LocChange* l = &changes[0]; locLen > 0; locLen--, l++) { l->p->set_referent(this, (char*)l->newOop); } return needToInvalICache; }
bool OopNCode::switch_pointers(oop from, oop to, nmethodBList* nmethods_to_invalidate) { Unused(nmethods_to_invalidate); ResourceMark m; bool needToInvalICache = false; char* bound = Memory->new_gen->boundary(); addrDesc* p = locs(), *end = locsEnd(); LocChange* changes = NEW_RESOURCE_ARRAY( LocChange, end - p); int32 locLen = 0; for (; p < end; p++) { if (!p->isOop()) { // no oops here } else { oop oldOop = (oop)p->referent(this); if (oldOop == from) { changes[locLen].p = p; locLen ++; check_store(to, bound); needToInvalICache = true; } } } for (LocChange* l = &changes[0]; locLen > 0; locLen--, l++) { l->p->set_referent(this, (char*)to); } return needToInvalICache; }
bool OopNCode::scavenge_contents() { ResourceMark m; bool needToInvalICache = false; char* bound = Memory->new_gen->boundary(); rememberLink.init(); addrDesc* p = locs(), *end = locsEnd(); LocChange* changes = NEW_RESOURCE_ARRAY( LocChange, end - p); int32 locLen = 0; for (; p < end; p++) { if (p->isOop()) { oop oldOop = (oop)p->referent(this); oop newOop = oldOop->scavenge(); if (newOop != oldOop) { changes[locLen].p = p; changes[locLen].newOop = newOop; locLen ++; needToInvalICache = true; } check_store(newOop, bound); } } for (LocChange* l = &changes[0]; locLen > 0; locLen--, l++) { l->p->set_referent(this, (char*)l->newOop); } return needToInvalICache; }
bool OopNCode::code_oops_do(oopsDoFn f) { ResourceMark m; bool needToInvalICache = false; char* bound = Memory->new_gen->boundary(); addrDesc* p = locs(), *end = locsEnd(); LocChange* changes = NEW_RESOURCE_ARRAY( LocChange, end - p); int32 locLen = 0; for (; p < end; p++) { if (!p->isOop()) { // no oops here } else { oop oldOop = (oop)p->referent(this); oop newOop = oldOop; OOPS_DO_TEMPLATE(&newOop, f); if (newOop != oldOop) { changes[locLen].p = p; changes[locLen].newOop = newOop; locLen ++; check_store(newOop, bound); needToInvalICache = true; } } } for (LocChange* l = &changes[0]; locLen > 0; locLen--, l++) { l->p->set_referent(this, (char*)l->newOop); } return needToInvalICache; }
fint nmethod::nsends(bool includeAll) { // add up the inlinable sends of the nmethod (i.e. those sent by inline // caches with comparing stubs); if includeAll, also count non-inlinable // sends fint nsends = 0; bool isNIC = compiler() == NIC; for (addrDesc* a = locs(), *aend = locsEnd(); a < aend; a++) { if (a->isSendDesc()) { sendDesc* sd = a->asSendDesc(this); if (!sd->isUninlinable()) { nsends += sd->nsends(); } else if (isNIC && sd->countType() == Counting) { // must be a method containing _Restart nsends += sd->nsends(); } else if (isNIC) { // NIC methods have no count stubs (to save space) but count the // # of invocations; assume all sends in NIC method are executed // once per execution of the method nsends += useCount[id]; } else if (includeAll) { nsends += sd->nsends(); } } } return nsends; }
bool nmethod::encompasses(void* p) { return includes(p, this, this + 1) || includes(p, deps(), depsEnd()) || includes(p, insts(), instsEnd()) || includes(p, locs(), locsEnd()) || scopes->includes((ScopeDesc*) p) || includes(p, pcs(), pcsEnd()); }
void nmethod::printLocs() { ResourceMark m; // in case methods get printed from gdb printIndent(); lprintf("locations:\n"); Indent ++; for (addrDesc* l = locs(); l < locsEnd(); l ++) l->print(this); Indent --; }
// unlink di Links and save them int32 nmethod::unlinkDI(nmln*& savedDIChildren) { int32 nlinks = 0; savedDIChildren = NEW_RESOURCE_ARRAY(nmln, locsEnd() - locs()); for (addrDesc* p = locs(), *pend = locsEnd(); p < pend; p++) { if (p->isDIDesc()) { nmln* l = p->asDIDesc(this)->dependency(); savedDIChildren[nlinks].init(); if (l->notEmpty()) { assert(l->next->next == l, "should be a pair"); l->next->rebind(&savedDIChildren[nlinks]); assert(savedDIChildren[nlinks].notEmpty(), "should have saved link"); } assert(p->asDIDesc(this)->dependency()->isEmpty(), "should be empty now"); nlinks++; } } return nlinks; }
// remove this methods PICs; return total size of flushed PICs int32 nmethod::flushPICs() { int32 flushed = 0; for (addrDesc* p = locs(), *pend = locsEnd(); p < pend; p++) { if (p->isSendDesc()) { sendDesc* sd = p->asSendDesc(this); CacheStub* s = sd->pic(); if (s) { flushed += s->size(); s->deallocate(); } } } MachineCache::flush_instruction_cache_for_debugging(); return flushed; }
void nmethod::relinkDI(int32 n, nmln*& savedDIChildren) { Unused(n); int32 nlinks = 0; for (addrDesc* p = locs(), *pend = locsEnd(); p < pend; p++) { if (p->isDIDesc()) { assert(nlinks < n, "too many DI caches in method"); nmln* l = p->asDIDesc(this)->dependency(); assert(l->isEmpty(), "should be empty"); if (savedDIChildren[nlinks].notEmpty()) { nmln* ln = savedDIChildren[nlinks].next; // cfront bug! ln->rebind(l); nmethod* target = findNMethod(ln); p->asDIDesc(this)->set_jump_addr(target->insts()); assert(p->asDIDesc(this)->dependency()->notEmpty(), "should be rebound now"); } nlinks++; } } MachineCache::flush_instruction_cache_for_debugging(); assert(n == nlinks, "too few DI links in method"); }
void OopNCode::relocate() { ResourceMark m; addrDesc* p = locs(), *end = locsEnd(); LocChange* changes = NEW_RESOURCE_ARRAY( LocChange, end - p); int32 locLen = 0; for (; p < end; p++) { if (!p->isOop()) { // no oops here } else { oop oldOop = (oop)p->referent(this); oop newOop = oldOop; RELOCATE_TEMPLATE(&newOop); if (newOop != oldOop) { changes[locLen].p = p; changes[locLen].newOop = newOop; locLen ++; } } } for (LocChange* l = &changes[0]; locLen > 0; locLen--, l++) { l->p->set_referent(this, (char*)l->newOop); } }
bool OopNCode::verify() { bool r = true; const char* name = isNMethod() ? "nmethod" : (isCacheStub() ? " PIC" : "count stub"); NCodeBase::verify2(name); if (!rememberLink.verify_list_integrity()) { lprintf("\tof rememberLink of %s %#lx\n", name, this); r = false; } for (addrDesc* l = locs(); l < locsEnd(); l++) { bool ok = isNMethod() ? l->verify((nmethod*)this) : l->verify((CacheStub*)this); if (! ok) { lprintf("\t\tin %s at %#lx\n", name, this); r = false; } else if (l->isOop() && // not no oops here oop(l->referent(this))->is_new() && rememberLink.isEmpty()) { error2("%s %#lx should be remembered", name, this); r = false; } } return r; }
bool nmethod::verify() { bool r = true; ResourceMark rm; r &= OopNCode::verify2("nmethod"); if (insts() != (char*)(this + 1)) { error1("nmethod at 0x%lx has incorrect insts pointer", this); r = false; } if (!Memory->code->contains(this)) { error1("nmethod at 0x%lx not in zone", this); r = false; } if (!zoneLink.verify_list_integrity()) { lprintf("\tof zoneLink of nmethod 0x%lx\n", this); r = false; } { FOR_MY_CODETABLE_ENTRIES(e) if (e->nm != this) { error1("bad code table link for nmethod %#lx\n", this); r = false; } } bool isAligned = (frame_size & (frame_word_alignment-1)) == 0; if (!isAligned) { lprintf("nmethod at %#lx: frame size is not multiple of %d words\n", (long unsigned)this, frame_word_alignment); r = false; } if (codeTableLink != NULL) { nmethod *tableResult = isDebug() ? Memory->code->debugTable->lookup(key) : Memory->code->table ->lookup(key); if (tableResult != this) { error1("nmethod at %#lx: code table lookup failed", this); r = false; } } if (!key.verify()) { lprintf("\tof key of nmethod 0x%lx\n", this); r = false; } { FOR_MY_CODETABLE_ENTRIES(e) if (!e->key.verify()) { lprintf("\tof code table key %#lx of nmethod 0x%lx\n", (long unsigned)&e->key, (long unsigned)this); r = false; } } if (!linkedSends.verify_list_integrity()) { lprintf("\tof linkedSends of nmethod 0x%lx\n", this); r = false; } if (!diLink.verify_list_integrity()) { lprintf("\tof diLink of nmethod 0x%lx\n", this); r = false; } r &= scopes->verify(); for (PcDesc* p = pcs(); p < pcsEnd(); p++) { if (! p->verify(this)) { lprintf("\t\tin nmethod at %#lx (pcs)\n", this); r = false; } } // more checks in ncode::verify called above bool shouldBeDI = diLink.notEmpty(); for (addrDesc* l = locs(); l < locsEnd(); l++) { if (l->isDIDesc()) { shouldBeDI = true; } } if (shouldBeDI && !isDI()) { error1("nmethod %#lx should be marked isDI", this); r = false; } else if (!shouldBeDI && isDI()) { error1("nmethod %#lx should not be marked isDI", this); r = false; } if (! key.receiverMap()->is_block() ) { for (nmln* d = deps(); d < depsEnd(); d++) { if (! d->verify_list_integrity()) { lprintf("\tin nmethod at %#lx (deps)\n", this); r = false; } } } if (frame_chain != NoFrameChain) { error1("nmethod %#lx has non-zero frame chain value", this); r = false; } if (findNMethod( instsEnd() - oopSize) != this) { error1("findNMethod did not find this nmethod (%#lx)", this); r = false; } return r; }
nmethod::nmethod(AbstractCompiler* c, bool generateDebugCode) { CHECK_VTBL_VALUE; _instsLen = roundTo(iLen, oopSize); _locsLen = ilLen; depsLen = dLen; // backpointer is just before deps depsAddr = (nmln*) ((char*)dAddr + sizeof(nmethod*)); *dBackLinkAddr() = this; // Copy the nmethodScopes scopeDescs generated by the ScopeDescRecorder // to the allocation area. c->scopeDescRecorder()->copyTo((VtblPtr_t*)sAddr, (int32)this); this->scopes = (nmethodScopes*) sAddr; oldCount = 0; flags.clear(); flags.isDebug = generateDebugCode; setCompiler(c->name()); flags.isUncommonRecompiled = currentProcess->isUncommon(); verifiedOffset = c->verifiedOffset(); diCheckOffset = c->diCheckOffset(); frameCreationOffset = c->frameCreationOffset(); rememberLink.init(); codeTableLink= NULL; diLink.init(c->diLink); if (diLink.notEmpty()) flags.isDI = true; flags.level = c->level(); if (flags.level >= MaxRecompilationLevels) { // added = zzzz warning1("setting invalid nmethod level %ld", flags.level); // fix this flags.level = 0; } flags.version = c->version(); if (c->nmName() == nm_nic && ((FCompiler*)c)->isImpure) makeImpureNIC(); key.set_from(c->L->key); check_store(); clear_frame_chain(); assert(c->frameSize() >= 0, "frame size cannot be negative"); frame_size = c->frameSize(); _incoming_arg_count = c->incoming_arg_count(); get_platform_specific_data(c); Assembler* instsA = c->instructions(); copy_bytes( instsA->instsStart, insts(), instsLen()); copy_words((int32*)instsA->locsStart, (int32*)locs(), ilLen/4); copy_words((int32*)depsStart, (int32*)deps(), depsLen/4); addrDesc *l, *lend; for (l = locs(), lend = locsEnd(); l < lend; l++) { l->initialShift(this, (char*)insts() - (char*)instsA->instsStart, 0); } char* bound = Memory->new_gen->boundary(); for (l = locs(), lend = locsEnd(); l < lend; l++) { if (l->isOop()) OopNCode::check_store(oop(l->referent(this)), bound); // cfront garbage else if (l->isSendDesc()) { l->asSendDesc(this)->dependency()->init(); } else if (l->isDIDesc()) { l->asDIDesc(this)->dependency()->init(); flags.isDI = true; } } for (nmln* d = deps(), *dend = depsEnd(); d < dend; d++) { d->relocate(); } MachineCache::flush_instruction_cache_range(insts(), instsEnd()); MachineCache::flush_instruction_cache_for_debugging(); if (this == (nmethod*)catchThisOne) warning("caught nmethod"); }
void nmethod::flush() { BlockProfilerTicks bpt(exclude_nmethod_flush); CSect cs(profilerSemaphore); // for profiler # if GENERATE_DEBUGGING_AIDS if (CheckAssertions) { // for debugging if (nmethodFlushCount && --nmethodFlushCount == 0) warning("nmethodFlushCount"); if (this == (nmethod*)catchThisOne) warning("caught nmethod"); } # endif // EventMarker em("flushing nmethod %#lx %s", this, ""); if (PrintMethodFlushing) { ResourceMark m; char *compilerName = VMString[compiler()]->copy_null_terminated(); lprintf("*flushing %s%s%s-nmethod 0x%lx %d\t(", isZombie() ? "zombie " : "", isAccess() ? "access " : "", compilerName, (void*)(long unsigned)this, (void*)useCount[id]); printName(0, key.selector); lprintf(")"); } // always check the following - tests are really cheap if (flags.flushed) fatal1("nmethod %#lx already flushed", this); if (zone::frame_chain_nesting == 0) fatal("frames must be chained when flushing"); if (frame_chain != NoFrameChain) { // Can't remove an nmethod from deps chains now, because later // programming changes may need to invalidate it. // That is, don't unlink() now. // See comment for makeZombie routine. The comment above is the // "original comment" referred to there. // -- dmu 1/12/03 if (this == recompilee) { // nmethod is being recompiled; cannot really flush yet // em.event.args[1] = "(being recompiled)"; if (PrintMethodFlushing) { lprintf(" (being recompiled)\n"); } } else { // nmethod is currently being executed; cannot flush yet // em.event.args[1] = "(currently active)"; if (PrintMethodFlushing) { lprintf(" (currently active)\n"); } } makeZombie(false); } else { unlink(); // nmethod is not being executed; completely throw away // em.event.args[1] = "(not currently active)"; if (PrintMethodFlushing) { lprintf("\n"); } flatProfiler->flush((char*)this, instsEnd()); zoneLink.remove(); rememberLink.remove(); for (addrDesc* p = locs(), *pend = locsEnd(); p < pend; p++) { if (p->isSendDesc()) { p->asSendDesc(this)->unlink(); } else if (p->isDIDesc()) { p->asDIDesc(this)->dependency()->flush(); } } flags.flushed = 1; // to detect flushing errors # if GENERATE_DEBUGGING_AIDS if (CheckAssertions) { set_oops((oop*)insts(), instsLen()/oopSize, 0); // for quicker detection } # endif Memory->code->free_nmethod(this); } MachineCache::flush_instruction_cache_for_debugging(); }
void nmethod::moveTo_inner(NCodeBase* p, int32 delta, int32 size) { nmethod* to = (nmethod*)p; if (this == to) return; if (PrintCodeCompaction) { lprintf("*moving nmethod %#lx (", this); printName(0, key.selector); lprintf(") to %#lx\n", to); } OopNCode::moveTo_inner(to, delta, size); assert(iabs((char*)to - (char*)this) >= sizeof(NCodeBase), "nmethods overlap too much"); assert(sizeof(NCodeBase) % oopSize == 0, "should be word-aligned"); // init to's vtable copy_words((int32*)this, (int32*)to, sizeof(NCodeBase) / sizeof(int32)); scopes->_nmethod_backPointer = to; *dBackLinkAddr() = to; flatProfiler->move(insts(), instsEnd(), to->insts()); zoneLink.shift(delta); FOR_MY_CODETABLE_ENTRIES(e) { e->nm= to; } for (nmln *x = linkedSends.next, *y = x->next; x != &linkedSends; x = y, y = y->next) { NCodeBase* s = findThing(x); s->shift_target(x, delta); } linkedSends.shift(delta, this); if (diLink.notEmpty()) { assert(diLink.next->next == &diLink, "diLink should be a pair"); diLink.next->asDIDesc()->shift_jump_addr(delta); } diLink.shift(delta); for (addrDesc* q = locs(), *pend = locsEnd(); q < pend; q++) { if (q->isSendDesc()) { sendDesc* sd = q->asSendDesc(this); sd->shift(delta, this); } else if (q->isDIDesc()) { nmln* l = q->asDIDesc(this)->dependency(); l->shift(delta); } q->shift(this, delta); } if (frame_chain != NoFrameChain && frame_chain != SavedFrameChain) frame_chain->nmethod_moved_by(delta, this); }