Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java NACHOS虚拟内存和缓存的实现_Java_Operating System_Tlb_Virtual Address Space_Nachos - Fatal编程技术网

Java NACHOS虚拟内存和缓存的实现

Java NACHOS虚拟内存和缓存的实现,java,operating-system,tlb,virtual-address-space,nachos,Java,Operating System,Tlb,Virtual Address Space,Nachos,我正在用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 < Mach

我正在用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;
        }
    }
}
/**
*在上下文切换后还原此进程的状态。叫来
*UThread.restoreState()
*/
公共屋({
//使所有TLB条目无效;
对于(int i=0;i
这里,vmk=(VMKernel)Kernel.Kernel。我不理解syncPageTable()函数。for子句中的TranslationEntry e:pageTable是什么意思?if-else块实际检查的是什么

for( TranslationEntry e : pageTable ) { /* block */ }
这称为“for each”语句。它迭代pageTable中的每个TranslationEntry并执行块中的语句。当前条目名为“e”。有关更多详细信息,请阅读javadoc

正式确定:

for( <type> <variable-name> : <name of the container containing <type> entries> ) {}
(:){}的

关于块中的语句:函数
lookupAddress()
看起来像是返回
TranslationEntry
null
。您需要首先检查
null
,因为如果第一部分为true,则不会计算
|
语句的第二部分。如果对
null
忽略此测试,
f.valid
将引发空指针异常

现在:
else如果(f!=null)
: 第一个if语句为false、f为null或f无效。要知道发生了哪种情况,必须测试1的倒数。您还可以测试
是否(f.valid==true)
,但与前面一样,这可能引发空指针异常。所以这真正需要的是:
如果(f!=null&&f.valid==true)