⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 machine.java

📁 nachos操作系统框架
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// PART OF THE MACHINE SIMULATION. DO NOT CHANGE.package nachos.machine;import nachos.security.*;import nachos.ag.*;import java.io.File;/** * The master class of the simulated machine. Processes command line arguments, * constructs all simulated hardware devices, and starts the grader. */public final class Machine {    /**     * Nachos main entry point.     *     * @param	args	the command line arguments.     */    public static void main(final String[] args) {	System.out.print("nachos 5.0j initializing...");		Lib.assert(Machine.args == null);	Machine.args = args;	processArgs();	Config.load(configFileName);	// get the current directory (.)	baseDirectory = new File(new File("").getAbsolutePath());	// get the nachos directory (./nachos)	nachosDirectory = new File(baseDirectory, "nachos");	String testDirectoryName =	    Config.getString("FileSystem.testDirectory");	// get the test directory	if (testDirectoryName != null) {	    testDirectory = new File(testDirectoryName);	}	else {	    // use ../test	    testDirectory = new File(baseDirectory.getParentFile(), "test");	}	securityManager = new NachosSecurityManager(testDirectory);	privilege = securityManager.getPrivilege();	privilege.machine = new MachinePrivilege();	TCB.givePrivilege(privilege);	privilege.stats = stats;	securityManager.enable();	createDevices();	checkUserClasses();	autoGrader = (AutoGrader) Lib.constructObject(autoGraderClassName);	new TCB().start(new Runnable() {	    public void run() { autoGrader.start(privilege); }	});    }    /**     * Yield to non-Nachos threads. Use in non-preemptive JVM's to give     * non-Nachos threads a chance to run.     */    public static void yield() {	Thread.yield();    }    /**     * Terminate Nachos. Same as <tt>TCB.die()</tt>.     */    public static void terminate() {	TCB.die();    }    /**     * Terminate Nachos as the result of an unhandled exception or error.     *     * @param	e	the exception or error.     */    public static void terminate(Throwable e) {	if (e instanceof ThreadDeath)	    throw (ThreadDeath) e;		e.printStackTrace();	terminate();    }    /**     * Print stats, and terminate Nachos.     */    public static void halt() {	System.out.print("Machine halting!\n\n");	stats.print();	terminate();    }    /**     * Return an array containing all command line arguments.     *     * @return	the command line arguments passed to Nachos.     */    public static String[] getCommandLineArguments() {	String[] result = new String[args.length];	System.arraycopy(args, 0, result, 0, args.length);	return result;    }    private static void processArgs() {	for (int i=0; i<args.length; ) {	    String arg = args[i++];	    if (arg.length() > 0 && arg.charAt(0) == '-') {		if (arg.equals("-d")) {		    Lib.assert(i < args.length, "switch without argument");		    Lib.enableDebugFlags(args[i++]);		}		else if (arg.equals("-h")) {		    System.out.print(help);		    System.exit(1);		}		else if (arg.equals("-m")) {		    Lib.assert(i < args.length, "switch without argument");		    try {			numPhysPages = Integer.parseInt(args[i++]);		    }		    catch (NumberFormatException e) {			Lib.assertNotReached("bad value for -m switch");		    }		}		else if (arg.equals("-s")) {		    Lib.assert(i < args.length, "switch without argument");		    try {			randomSeed = Long.parseLong(args[i++]);		    }		    catch (NumberFormatException e) {			Lib.assertNotReached("bad value for -s switch");		    }		}		else if (arg.equals("-x")) {		    Lib.assert(i < args.length, "switch without argument");		    shellProgramName = args[i++];		    		}		    		else if (arg.equals("-z")) {		    System.out.print(copyright);		    System.exit(1);		}		// these switches are reserved for the autograder		else if (arg.equals("-[]")) {		    Lib.assert(i < args.length, "switch without argument");		    configFileName = args[i++];		}		else if (arg.equals("--")) {		    Lib.assert(i < args.length, "switch without argument");		    autoGraderClassName = args[i++];		}	    }	}	Lib.seedRandom(randomSeed);    }    private static void createDevices() {	interrupt = new Interrupt(privilege);	timer = new Timer(privilege);	if (Config.getBoolean("Machine.bank"))	    bank = new ElevatorBank(privilege);	if (Config.getBoolean("Machine.processor")) {	    if (numPhysPages == -1)		numPhysPages = Config.getInteger("Processor.numPhysPages");	    processor = new Processor(privilege, numPhysPages);	}				      	if (Config.getBoolean("Machine.console"))	    console = new StandardConsole(privilege);	if (Config.getBoolean("Machine.stubFileSystem"))	    stubFileSystem = new StubFileSystem(privilege, testDirectory);	if (Config.getBoolean("Machine.networkLink"))	    networkLink = new NetworkLink(privilege);    }    private static void checkUserClasses() {	System.out.print(" user-check");		Class aclsInt = (new int[0]).getClass();	Class clsObject = Lib.loadClass("java.lang.Object");	Class clsRunnable = Lib.loadClass("java.lang.Runnable");	Class clsString = Lib.loadClass("java.lang.String");	Class clsKernel = Lib.loadClass("nachos.machine.Kernel");	Class clsFileSystem = Lib.loadClass("nachos.machine.FileSystem");	Class clsRiderControls = Lib.loadClass("nachos.machine.RiderControls");	Class clsElevatorControls =	    Lib.loadClass("nachos.machine.ElevatorControls");	Class clsRiderInterface =	    Lib.loadClass("nachos.machine.RiderInterface");	Class clsElevatorControllerInterface =	    Lib.loadClass("nachos.machine.ElevatorControllerInterface");	Class clsAlarm = Lib.loadClass("nachos.threads.Alarm");	Class clsThreadedKernel =	    Lib.loadClass("nachos.threads.ThreadedKernel");	Class clsKThread = Lib.loadClass("nachos.threads.KThread");	Class clsCommunicator = Lib.loadClass("nachos.threads.Communicator");	Class clsSemaphore = Lib.loadClass("nachos.threads.Semaphore");	Class clsLock = Lib.loadClass("nachos.threads.Lock");	Class clsCondition = Lib.loadClass("nachos.threads.Condition");	Class clsCondition2 = Lib.loadClass("nachos.threads.Condition2");	Class clsRider = Lib.loadClass("nachos.threads.Rider");	Class clsElevatorController =	    Lib.loadClass("nachos.threads.ElevatorController");	Lib.checkDerivation(clsThreadedKernel, clsKernel);		Lib.checkStaticField(clsThreadedKernel, "alarm", clsAlarm);	Lib.checkStaticField(clsThreadedKernel, "fileSystem", clsFileSystem);		Lib.checkMethod(clsAlarm, "waitUntil", new Class[] { long.class },			void.class);		Lib.checkConstructor(clsKThread, new Class[] { });	Lib.checkConstructor(clsKThread, new Class[] { clsRunnable });	Lib.checkStaticMethod(clsKThread, "currentThread", new Class[] {},			      clsKThread);	Lib.checkStaticMethod(clsKThread, "finish", new Class[] {},			      void.class);	Lib.checkStaticMethod(clsKThread, "yield", new Class[] {}, void.class);	Lib.checkStaticMethod(clsKThread, "sleep", new Class[] {}, void.class);	Lib.checkMethod(clsKThread, "setTarget", new Class[]{ clsRunnable },			clsKThread);	Lib.checkMethod(clsKThread, "setName", new Class[] { clsString },			clsKThread);	Lib.checkMethod(clsKThread, "getName", new Class[] { }, clsString);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -