我正在用 java 做 NACHOS 第 3 阶段项目(缓存和虚拟内存)。我在实现下面给出的功能时有些困惑:
/**
* Restore the state of this process after a context switch. Called by
* UThread.restoreState()
*/
public void restoreState() {
// Invalidate all TLB entries;
for(int i=0; i < Machine.processor().getTLBSize(); i++){
Lib.debug(dbgVM, "Invalidating TLB on context switch.");
TranslationEntry entry = Machine.processor().readTLBEntry(i);
entry.valid = false;
Machine.processor().writeTLBEntry(i, entry);
}
syncPageTable();
}
/**
* Called when the process is context switched in. Synchs the process
* pagetable with the global one so that read/writeVirtualMemory calls
* can proceed as they would normally in the UserProcess class.
*/
private void syncPageTable(){
for(TranslationEntry e : pageTable){
TranslationEntry f = vmk.lookupAddress(super.getPid(), e.vpn);
if(f == null || f.valid == false){
e.valid = false;
}else if(f != null){
f.valid = true;
}
}
}
这里,vmk = (VMKernel)Kernel.kernel; . 我还没有理解syncPageTable()函数。TranslationEntry e : pageTable在 for 子句中的含义是什么,以及 if-else 块实际检查的内容是什么?