Question: Problem Description: You are to use Java to write a Cache Simulator that explores the characteristics of a direct-mapped cache. You must be able to
Problem Description:
You are to use Java to write a Cache Simulator that explores the characteristics of a direct-mapped cache. You must be able to create a cache with a specified address size, word size, block size and number of lines.
You will create a class called Cache and test it with a test driver that I have provided (CacheDriver.java). To test your application, you can use the test data in the example below and should get the same results. I will be running your program with different data.
Email to send CacheDriver.java , ecervan4@email.asu.edu
Class Definition:
Constructor (public)
Cache(String name, int addressSize, int wordSize, int blockSize, int numLines): Creates a direct mapped cache, with the attributes shown below. Upon creation, the cache should be cleared and the number of requests, hits and misses set to 0. Note: you do not really need to cache memory and therefore your simulated cache should not contain data for the retrieved blocks.
Name: a name to identify the cache
addressSize: Size of the system memory address space in bits (4 addressSize 32).
wordSize: Size of a memory word in bits (8 wordSize 64). This must be a power of
2.
blockSize: Number of words in a cache block (1 blockSize 1024). This must be a
power of 2.
numLines: Number of lines in the cache (1 numLines 1024). This must be a power
of 2.
Functions
public void readLocation(int address): Simulates the reading of the memory at the given address. The Cache object should track the total number of hits, misses and requests. During a read, the following information should be printed. Each value is printed in decimal and binary. The binary numbers should be displayed with the appropriate number of digits. For example, with a Block Size of 16, 4 bits will be used for the index of the target address in its containing block, therefore, the index field should display as 4 bits (see example below in Required Output).
Read Mem : address (binary)
Block #: blockNumber (binary)
Offset : offset (binary)
Index : index (binary)
Tag : tag (binary)
Result : Miss (or ** Hit **)
where:
address: The target address
blockNumber: The block of memory that would contain the target address
offset: The word offset within the block of the target address
index: The index in cache for the block (once loaded)
tag: The tag for the line of cache once loaded with the target address
result: display Hit or Miss (see examples below in Required Output)
public void print(): Print a simple size report for the Cache as follows:
********** SSSS Cache Size Report **********
Memory : W words of S bits (T bytes)
Cache : L lines of B words (C bytes)
where:
SSSS: The name of the cache
W: Number of words in memory
S: Size of memory word in bits
T: Total bytes of memory
L: Number of lines in cache
B: Number of words per block of cache
C: Total bytes required to store the Cache. For calculating the size of Cache,
assume that each line consists of a 32 bits for the Valid Flag and Tag combined plus the required space for the block.
public void stats(): Print basic statistics for the Cache as follows:
********** SSSS Cache Stats Report **********
Requests: R
Hits : H (HR%)
Misses : M (MR%)
where:
SSSS: The name of the cache
R: Total number of requests
H: Total number of Hits
HR: Hit Ratio as a percentage (0 HR 100)
M: Total number of Misses
MR: Miss Ratio as a percentage (0 HR 100)
Required Main Class:
CacheDriver This class is provided for you (CacheDriver.java).
Required Input:
Address size, in bits
Word size, in bits
Block size, in words
Number of Lines
Starting Address for the memory requests test
Ending Address for the memory requests test
Increments in the memory request tests
Required Output:
Your output should look something like the following example:
Cache Information: Address size, in bits? 10 Word size, in bits? 32 Block size, in words? 16 Number of Lines? 32
Test Parameters: Starting Address? 100 Ending Address? 200 Increment? 10
********** CSC230 Cache Size Report ********** Memory : 1024 words of 32 bits (4096 bytes) Cache : 32 lines of 16 words (2176 bytes)
Read Mem : 100 (0001100100) Block #: 6 (000110) Offset : 4 (0100) Index : 6 (00110)
Tag : 0 (0) Result: Miss
Read Mem : 110 (0001101110) Block #: 6 (000110) Offset : 14 (1110) Index : 6 (00110)
Tag : 0 (0) Result: ** Hit **
Read Mem : 120 (0001111000) Block #: 7 (000111) Offset : 8 (1000) Index : 7 (00111)
Tag : 0 (0) Result: Miss
Read Mem : 130 (0010000010) Block #: 8 (001000) Offset : 2 (0010) Index : 8 (01000)
Tag : 0 (0) Result: Miss
Read Mem : 140 (0010001100) Block #: 8 (001000) Offset : 12 (1100) Index : 8 (01000)
Tag : 0 (0) Result: ** Hit **
Read Mem : 150 (0010010110) Block #: 9 (001001) Offset : 6 (0110) Index : 9 (01001)
Tag : 0 (0) Result: Miss
Read Mem : 160 (0010100000) Block #: 10 (001010) Offset : 0 (0000) Index : 10 (01010)
Tag : 0 (0) Result: Miss
Read Mem : 170 (0010101010) Block #: 10 (001010) Offset : 10 (1010) Index : 10 (01010)
Tag : 0 (0) Result: ** Hit **
Read Mem : 180 (0010110100) Block #: 11 (001011) Offset : 4 (0100) Index : 11 (01011)
Tag : 0 (0) Result: Miss
Read Mem : 190 (0010111110) Block #: 11 (001011) Offset : 14 (1110) Index : 11 (01011)
Tag : 0 (0) Result: ** Hit **
Read Mem : 200 (0011001000) Block #: 12 (001100) Offset : 8 (1000) Index : 12 (01100)
Tag : 0 (0) Result: Miss
********** CSC230 Cache Stats Report ********** Requests: 11 Hits : 4 (36.36363636363637%) Misses : 7 (63.63636363636363%)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
