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()); }
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::printCode() { ResourceMark m; // in case methods get printed from gdb print_code(this, (char*)insts(), (char*)instsEnd()); }
void nmethod::print() { ResourceMark rm; printIndent(); lprintf("(nmethod*)%#lx", this); if (scopes->root()->isDataAccessScope()) { lprintf(" (data access)"); } else if (scopes->root()->isDataAssignmentScope()) { lprintf(" (data assignment)"); } else { lprintf(" for method %#lx", method()); } lprintf(" { "); if (isYoung()) lprintf("YOUNG "); switch (compiler()) { case NIC: lprintf("NIC "); if (isImpureNIC()) lprintf("impure "); break; case SIC: lprintf("SIC level %ld ", level()); break; default: lprintf("!?!unknown compiler!?! "); break; } if (version()) lprintf("v%d ", version()); if (isDI()) lprintf("DI "); if (isZombie()) lprintf("zombie "); if (isInvalid()) lprintf("INVALID "); if (isDebug()) lprintf("DEBUG "); if (isToBeRecompiled()) lprintf("TBR "); if (isUncommon() || isUncommonRecompiled()) lprintf("UNCOMMON "); lprintf("}:\n"); lprintf( "incoming_arg_count = %d\n", incoming_arg_count() ); print_platform_specific_data(); Indent ++; key.print(); printIndent(); lprintf("code table link: %#lx\n", codeTableLink); printIndent(); lprintf("remember link: "); rememberLink.print(); lprintf("\n"); printIndent(); lprintf("linked sends: "); linkedSends.print(); lprintf("\n"); printIndent(); lprintf("di link: "); diLink.print(); lprintf("\n"); printIndent(); lprintf("instructions (%ld bytes): %#lx,%#lx/i / x/%ldi %#lx\n", instsLen(), insts(), instsEnd() - oopSize, instsLen() / oopSize, insts()); printIndent(); lprintf("p ((nmethod*)%#lx)->printCode() \n", this); scopes->print(); // printLocs(); // printDeps(); Indent --; }
relocInfo* locs() const { return (relocInfo*) instsEnd();}
bool contains(void* p) const { return (void*)insts() <= p && p < (void*)instsEnd(); }
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); }