Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

convert this code to java language //vmgr.c //Virtual Memory Manager //CS433 - Final Project //Professor: Tom Springer //Authors: Mike Bobadilla, Nelson DeBate //Date: 5-11-16 #include

convert this code to java language

//vmgr.c //Virtual Memory Manager //CS433 - Final Project //Professor: Tom Springer //Authors: Mike Bobadilla, Nelson DeBate //Date: 5-11-16

#include #include #include #include #include

const int PAGE_SIZE = 256; const int VM_SIZE = 256; const int MM_SIZE = 128; const int TLB_SIZE = 16;

int main(int argc, char *argv[]){

int physical_memory[MM_SIZE]; int virtual_memory[VM_SIZE][2]; int tlb[TLB_SIZE][2];

// INITIAL PAGE TABLE FILLING // [0] Physical Address [1] Age for(int i = 0; i < VM_SIZE; i++){ virtual_memory[i][0] = (i > MM_SIZE - 1)? -1 : i; virtual_memory[i][1] = (i > MM_SIZE - 1)? -1 : MM_SIZE - i; } for(int i = 0; i < MM_SIZE; i++){ physical_memory[i] = i; }

for(int i = 0; i < TLB_SIZE; i++){ tlb[i][0] = (i > TLB_SIZE - 1)? -1 : i; tlb[i][1] = (i > TLB_SIZE - 1)? -1 : TLB_SIZE - i; }

// Check to see if correct arguments exist if(argc != 2){ printf("Incorrect Number of Arguments. "); return 1; }

FILE *pFile; pFile = fopen(argv[1], "r");

//checks to see if the .txt file supplied is empty if(pFile == NULL){ printf("Error opening a file %s: %s ", argv[1], strerror(errno)); exit(EXIT_FAILURE); }

char *line = NULL; size_t len = 0; ssize_t read;

int page_number = 0; int physicalAddress = 0; int pageFaultCount = 0;

double pageFaultRate = 0.0;

printf("================================== " ); printf(" Virtual Memory Manager " ); printf("================================== " );

printf("Translating 1000 Logical Addresses: ");

while((read = getline(&line, &len, pFile)) != -1){ int offset = atoi(line) & 255; int page = atoi(line) & 65280; int page_table_number = page >> 8; int tlb_hit = 0;

for(int i = 0; i < TLB_SIZE; i++){ if(tlb[i][0] == page_table_number){ tlb_hit = 1; printf("TLB HIT "); break; } }

if(virtual_memory[page_table_number][0] < 0 && !tlb_hit){ pageFaultCount++; srand(time(NULL)); int r = rand();

// EVICT SOMEONE int largest = 0; int evict = 0; for(int i = 0; i < VM_SIZE; i++){ if(virtual_memory[i][1] > largest){ largest = virtual_memory[i][1]; evict = i; } }

int tlb_replacement = r % 15; tlb[tlb_replacement][0] = page_table_number; tlb[tlb_replacement][1] = virtual_memory[evict][0]; virtual_memory[page_table_number][0] = virtual_memory[evict][0]; virtual_memory[page_table_number][1] = 0; virtual_memory[evict][0] = -1; virtual_memory[evict][1] = 0; }

//printing formatting for Virtual Address if (page < 100) { printf("Virtual Address = %d \t", page); } else if (page < 1000) { printf("Virtual Address = %d \t", page); } else { printf("Virtual Address = %d \t", page); }

//calculates the physical address physicalAddress = (physical_memory[virtual_memory[page_table_number][0]] * PAGE_SIZE) + offset;

printf("Physical Address: %d ", physicalAddress);

page_number++;

for(int i = 0; i < VM_SIZE; i++){ virtual_memory[i][1]++; } }

//calculates the % of page faults pageFaultRate = (double) pageFaultCount / 1000 * 100; printf(" Page Fault Rate: %.2f%% ", pageFaultRate);

free(line); fclose(pFile);

exit(EXIT_SUCCESS);

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David M. Kroenke

12th Edition International Edition

1292023422, 978-1292023427

More Books

Students also viewed these Databases questions