void MetaspaceShared::generate_vtable_methods(void** vtbl_list, void** vtable, char** md_top, char* md_end, char** mc_top, char* mc_end) { intptr_t vtable_bytes = (num_virtuals * vtbl_list_size) * sizeof(void*); *(intptr_t *)(*md_top) = vtable_bytes; *md_top += sizeof(intptr_t); void** dummy_vtable = (void**)*md_top; *vtable = dummy_vtable; *md_top += vtable_bytes; // Get ready to generate dummy methods. CodeBuffer cb((unsigned char*)*mc_top, mc_end - *mc_top); MacroAssembler* masm = new MacroAssembler(&cb); Label common_code; for (int i = 0; i < vtbl_list_size; ++i) { for (int j = 0; j < num_virtuals; ++j) { dummy_vtable[num_virtuals * i + j] = (void*)masm->pc(); // Load rax, with a value indicating vtable/offset pair. // -- bits[ 7..0] (8 bits) which virtual method in table? // -- bits[12..8] (5 bits) which virtual method table? // -- must fit in 13-bit instruction immediate field. __ movl(rax, (i << 8) + j); __ jmp(common_code); } } __ bind(common_code); #ifdef WIN32 // Expecting to be called with "thiscall" conventions -- the arguments // are on the stack, except that the "this" pointer is in rcx. #else // Expecting to be called with Unix conventions -- the arguments // are on the stack, including the "this" pointer. #endif // In addition, rax was set (above) to the offset of the method in the // table. #ifdef WIN32 __ push(rcx); // save "this" #endif __ mov(rcx, rax); __ shrptr(rcx, 8); // isolate vtable identifier. __ shlptr(rcx, LogBytesPerWord); Address index(noreg, rcx, Address::times_1); ExternalAddress vtbl((address)vtbl_list); __ movptr(rdx, ArrayAddress(vtbl, index)); // get correct vtable address. #ifdef WIN32 __ pop(rcx); // restore "this" #else __ movptr(rcx, Address(rsp, BytesPerWord)); // fetch "this" #endif __ movptr(Address(rcx, 0), rdx); // update vtable pointer. __ andptr(rax, 0x00ff); // isolate vtable method index __ shlptr(rax, LogBytesPerWord); __ addptr(rax, rdx); // address of real method pointer. __ jmp(Address(rax, 0)); // get real method pointer. __ flush(); *mc_top = (char*)__ pc(); }
/////////////////////////////////// // storage entry point to database // void DbIntlog::Add(Clause *c, int first, DbIntlog *owner) { Term h = c->get_head(); ASSERT(!h.type(f_NOTERM)); #ifdef _DEBUG CCP tstring = h.get_funct(); #endif e_DbList *edbl = new e_DbList(c); // retrieve or create the entry kstring funct = h.get_funct(); int arity = h.get_arity(); DbEntry e(funct, arity), *dbe = isin(e); // verify location on create if (dbe == 0 && owner && owner != this) dbe = owner->isin(e); if (!dbe) { dbe = new DbEntry(funct, arity); insert(dbe); } if (dbe->arity == -1) dbe->arity = arity; DbIntlog *dbwork = this; if (dbe->vProp == DbEntry::dynamic) { if (!owner) owner = this; dbe = owner->isin(dbe); ASSERT(dbe); c->set_db(dbwork = owner); } else if (owner && owner != this) { edbl->type = e_DbList::tLocData; c->set_db(owner); } if (first) dbe->entries.insert(edbl, 0); else { DbListSeek eref(e_DbList::tExtRef); DbListSeek vtbl(e_DbList::tVTable); unsigned iref = dbe->entries.seek(&eref); unsigned itbl = dbe->entries.seek(&vtbl); if (iref != SLIST_INVPOS) dbe->entries.insert(edbl, iref); else if (itbl != SLIST_INVPOS) dbe->entries.insert(edbl, itbl); else dbe->entries.append(edbl); } // close inheritance chainings dbwork->check_inherited_entries(dbe); }