Debugging code

This commit is contained in:
dpturnbull 2012-11-17 00:33:09 -05:00
parent 51aad5ee74
commit a468512e16

View File

@ -22,10 +22,12 @@ class FirstFit implements baseAlgorithm
noJobs=0, noJobs=0,
s1=0, s1=0,
compMemTest=0, compMemTest=0,
jobLoaded=0,
tableEntries=1; tableEntries=1;
private int[] tempVal = new int[6]; private int[] tempVal = new int[6];
private int[][] memTable = new int[memSize+2][6]; private int[][] memTable = new int[memSize+2][6];
private int[] memory = new int[memSize]; private int[] memory = new int[memSize];
private Job[] jobArray = new Job[memoryManagement.JOBAMOUNT+10];
//this is a no argument constructor //this is a no argument constructor
public FirstFit() public FirstFit()
@ -63,6 +65,15 @@ class FirstFit implements baseAlgorithm
System.exit(0); System.exit(0);
} }
//this will loop until job is loaded into memory
do
{
//this section looks for a place to put the new job //this section looks for a place to put the new job
do do
{ {
@ -79,6 +90,7 @@ class FirstFit implements baseAlgorithm
memTable[s1][5] = 1; memTable[s1][5] = 1;
Job newJob = new Job(jobTime, jobId, jobSize, memTable[s1][2], deallocateMethod, this); Job newJob = new Job(jobTime, jobId, jobSize, memTable[s1][2], deallocateMethod, this);
fillMemory(jobId, jobSize, memTable[s1][2]); fillMemory(jobId, jobSize, memTable[s1][2]);
jobArray[jobId - 1] = newJob;
newJob.start(); newJob.start();
memTable[s1+1][0] = 0; memTable[s1+1][0] = 0;
memTable[s1+1][1] = 0; memTable[s1+1][1] = 0;
@ -87,7 +99,8 @@ class FirstFit implements baseAlgorithm
memTable[s1+1][4] = memSize-memTable[s1+1][2]; memTable[s1+1][4] = memSize-memTable[s1+1][2];
memTable[s1+1][5] = -1; memTable[s1+1][5] = -1;
tableEntries++; tableEntries++;
System.out.println(toString()); jobLoaded=1;
System.out.println("add job "+jobId+toString());
s1=memSize*2; s1=memSize*2;
} }
//runs after the first job and if the only available slot is at the end of memory //runs after the first job and if the only available slot is at the end of memory
@ -101,6 +114,7 @@ class FirstFit implements baseAlgorithm
memTable[s1][5] = 1; memTable[s1][5] = 1;
Job newJob = new Job(jobTime, jobId, jobSize, memTable[s1][2], deallocateMethod, this); Job newJob = new Job(jobTime, jobId, jobSize, memTable[s1][2], deallocateMethod, this);
fillMemory(jobId, jobSize, memTable[s1][2]); fillMemory(jobId, jobSize, memTable[s1][2]);
jobArray[jobId - 1] = newJob;
newJob.start(); newJob.start();
memTable[s1+1][0] = 0; memTable[s1+1][0] = 0;
memTable[s1+1][1] = 0; memTable[s1+1][1] = 0;
@ -109,7 +123,8 @@ class FirstFit implements baseAlgorithm
memTable[s1+1][4] = memSize-memTable[s1+1][2]; memTable[s1+1][4] = memSize-memTable[s1+1][2];
memTable[s1+1][5] = -1; memTable[s1+1][5] = -1;
tableEntries++; tableEntries++;
System.out.println(toString()); jobLoaded=1;
System.out.println("add job "+jobId+toString());
s1=memSize*2; s1=memSize*2;
} }
} }
@ -121,8 +136,10 @@ class FirstFit implements baseAlgorithm
memTable[s1][5] = 1; memTable[s1][5] = 1;
Job newJob = new Job(jobTime, jobId, jobSize, memTable[s1][2], deallocateMethod, this); Job newJob = new Job(jobTime, jobId, jobSize, memTable[s1][2], deallocateMethod, this);
fillMemory(jobId, jobSize, memTable[s1][2]); fillMemory(jobId, jobSize, memTable[s1][2]);
jobArray[jobId - 1] = newJob;
newJob.start(); newJob.start();
System.out.println(toString()); jobLoaded=1;
System.out.println("add job "+jobId+toString());
s1=memSize*2; s1=memSize*2;
} }
else else
@ -130,15 +147,20 @@ class FirstFit implements baseAlgorithm
s1++; s1++;
} }
}while(s1<tableEntries); }while(s1<tableEntries);
//if job will not fit this section will compress memory and try placing the job again //if job will not fit this section will compress memory
if(s1==tableEntries) if(s1==tableEntries)
{ {
noJobs=noJobs-1; noJobs=noJobs-1;
compMem(); compMem();
allocate(ID, size, jobTime);
} }
}while(jobLoaded==0);
s1=0;
jobLoaded=0;
} catch (Exception e) } catch (Exception e)
{ {
System.out.println("Could not allocate job with ID " + jobId); System.out.println("Could not allocate job with ID " + jobId);
@ -147,57 +169,34 @@ class FirstFit implements baseAlgorithm
//this method is used if you want to deallocate a job by jobId
public void removeJob(int ID)
{
jobId = ID;
s1=0;
do
{
if(memTable[s1][0] == jobId)
{
jobSize = memTable[s1][1];
startLoc = memTable[s1][2];
s1=memSize*2;
}
else
{
s1++;
}
}while (s1<tableEntries);
deallocate(jobSize, startLoc);
}
//this method removes a job it does not check to see if the job exisits //this method removes a job it does not check to see if the job exisits
public void deallocate(int jobSize, int beginningLocation) public void deallocate(int jSize, int beginningLocation)
//public void removeJob(int ID)
{ {
jobId = 0; jobSize = jSize;
jobSize = jobSize;
startLoc = beginningLocation; startLoc = beginningLocation;
s1=0; s1=0;
do do
{ {
if(memTable[s1][2] == startLoc) if(memTable[s1][2] == startLoc)
{ {
System.out.println(startLoc+" removed job "+memTable[s1][0]);
memTable[s1][0] = 0; memTable[s1][0] = 0;
memTable[s1][1] = 0; memTable[s1][1] = 0;
memTable[s1][5] = 0; memTable[s1][5] = 0;
s1=memSize*2; System.out.println(memTable[s1][0]+" "+memTable[s1][1]+" "+memTable[s1][5]);
jobId=-1; System.out.println(toString());
noJobs--; noJobs--;
System.out.println("removed job "+memTable[s1][0]); s1=memSize*2;
} }
else else
{ {
s1++; s1++;
} }
}while (s1<tableEntries); }while (s1<tableEntries);
} }
//this method compacts the memory //this method compacts the memory