Use Java to write a Cache Simulator that emulates a direct-mapped cache. You must be able...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Use Java to write a Cache Simulator that emulates 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 examples below and should get the same results. 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). Addresses are always to the byte level. wordSize: Size of a memory word in bits (8≤ wordSize≤64). Must be a power of 2. blockSize: Number of words in a cache block (1 ≤ blockSize ≤ 1024). Must be a power of 2. numLines: Number of lines in the cache (1 ≤ numLines ≤ 1024). Must be a power of 2. Methods public void readLocation(int address): Simulates the reading of the memory at the given byte 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 bytes, 4 bits will be used for the offset of the target address in its containing block, therefore the offset field should display as 4 bits. Likewise, if there are 64 lines, the index will display as 6 bits (2º = 64). Read Mem : address (binary) Block Addr: blockAddress (binary) Offset offset (binary) Block Num: index (binary) Tag Result where: : tag (binary) Miss (or Hit **) ⚫address: The target byte address • blockAddress: The block of memory that would contain the target byte address offset: The byte offset within the block of the target byte address index: The index in cache for the block (also known as the Block Number) ⚫ tag: The tag for the line of cache once loaded with the target byte 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 (7 bytes) Cache lines with X bits of tag, 1 bit for the valid flag and B words of data each (C bits) where: ⚫ SSSS: The name of the cache • W: • • • S: T: L: Number of words in memory Size of memory word in bits Total bytes of memory Number of lines in cache • X: • B: • C: ت Number of bits per tag Number of words per block of cache Total bits required to store the Cache. For calculating the size of Cache, multiply the number of blocks by the space for each block (Tag bits plus 1 for the valid bit plus the bits needed for one block). public void stats(): Print basic statistics for the Cache as follows (all 7 lines): ********** SSSS Cache Stats Report ********** Semester Year Requests: R Hits : H (HR%) Misses M (MR%) where: This year (e.g. 2021) SSSS: The name of the cache • Semester: Fall or Spring • Year: • R: H: • HR: • M: • MR: Total number of requests Total number of Hits Hit Ratio as a percentage (0 ≤ HR ≤ 100) Total number of Misses Miss Ratio as a percentage (0 ≤ HR ≤ 100) Notes: Do not create these classes in a package. Turn in only your source file(s). Hint: Printing a certain number of binary digits: private String binary(int x, int size) { return String.format("%32s", Integer.toBinaryString(x)). replace("", "").substring(32-size); } 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 byte Address for the memory requests test Ending byte Address for the memory requests test Increments, in bytes, for the memory request tests Required Output: Your output should look something like the following examples. It must include your name: Example 1 (from page 390 in your textbook) *** Cache Simulator *** Cache Information: Address size, in bits? 32 Word size, in bits? 32 Block size, in words? 4 Number of Lines? 64 Test Parameters: Starting Address? 1203 Ending Address? 1203 Increment? 1 Number of Iterations? 1 Cache Size Report ********** Memory : 1073741824 words of 32 bits (4294967296 bytes) Cache (9664 bits) Read Mem : 64 lines with 22 bits of tag, 1 bit for the valid flag and 4 words of data each : 1203 (00000000000000000000010010110011) Block Addr: 75 (000000000 Offset 3 (0011) Block Num: 11 (001011) Tag : 1 (00000000 Result: Miss 000000001001011) 001) Use Java to write a Cache Simulator that emulates 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 examples below and should get the same results. 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). Addresses are always to the byte level. wordSize: Size of a memory word in bits (8≤ wordSize≤64). Must be a power of 2. blockSize: Number of words in a cache block (1 ≤ blockSize ≤ 1024). Must be a power of 2. numLines: Number of lines in the cache (1 ≤ numLines ≤ 1024). Must be a power of 2. Methods public void readLocation(int address): Simulates the reading of the memory at the given byte 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 bytes, 4 bits will be used for the offset of the target address in its containing block, therefore the offset field should display as 4 bits. Likewise, if there are 64 lines, the index will display as 6 bits (2º = 64). Read Mem : address (binary) Block Addr: blockAddress (binary) Offset offset (binary) Block Num: index (binary) Tag Result where: : tag (binary) Miss (or Hit **) ⚫address: The target byte address • blockAddress: The block of memory that would contain the target byte address offset: The byte offset within the block of the target byte address index: The index in cache for the block (also known as the Block Number) ⚫ tag: The tag for the line of cache once loaded with the target byte 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 (7 bytes) Cache lines with X bits of tag, 1 bit for the valid flag and B words of data each (C bits) where: ⚫ SSSS: The name of the cache • W: • • • S: T: L: Number of words in memory Size of memory word in bits Total bytes of memory Number of lines in cache • X: • B: • C: ت Number of bits per tag Number of words per block of cache Total bits required to store the Cache. For calculating the size of Cache, multiply the number of blocks by the space for each block (Tag bits plus 1 for the valid bit plus the bits needed for one block). public void stats(): Print basic statistics for the Cache as follows (all 7 lines): ********** SSSS Cache Stats Report ********** Semester Year Requests: R Hits : H (HR%) Misses M (MR%) where: This year (e.g. 2021) SSSS: The name of the cache • Semester: Fall or Spring • Year: • R: H: • HR: • M: • MR: Total number of requests Total number of Hits Hit Ratio as a percentage (0 ≤ HR ≤ 100) Total number of Misses Miss Ratio as a percentage (0 ≤ HR ≤ 100) Notes: Do not create these classes in a package. Turn in only your source file(s). Hint: Printing a certain number of binary digits: private String binary(int x, int size) { return String.format("%32s", Integer.toBinaryString(x)). replace("", "").substring(32-size); } 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 byte Address for the memory requests test Ending byte Address for the memory requests test Increments, in bytes, for the memory request tests Required Output: Your output should look something like the following examples. It must include your name: Example 1 (from page 390 in your textbook) *** Cache Simulator *** Cache Information: Address size, in bits? 32 Word size, in bits? 32 Block size, in words? 4 Number of Lines? 64 Test Parameters: Starting Address? 1203 Ending Address? 1203 Increment? 1 Number of Iterations? 1 Cache Size Report ********** Memory : 1073741824 words of 32 bits (4294967296 bytes) Cache (9664 bits) Read Mem : 64 lines with 22 bits of tag, 1 bit for the valid flag and 4 words of data each : 1203 (00000000000000000000010010110011) Block Addr: 75 (000000000 Offset 3 (0011) Block Num: 11 (001011) Tag : 1 (00000000 Result: Miss 000000001001011) 001)
Expert Answer:
Related Book For
Posted Date:
Students also viewed these programming questions
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
You have been employed to create program to assist the manager of a coffee shop. You decide to make a prototype application in Java to show what you can do, and to be able to ask the manager what...
-
Find the maximum of f(x,y) = x + y - x - y - xy
-
On September 17, 2018, Ziltech, Inc., entered into an agreement to sell one of its divisions that qualifies as a component of the entity according to generally accepted accounting principles. By...
-
Compute the sample correlation coefficient for the data of problem 1011. In problem An article in the Journal of Monetary Economics assesses the relationship between percentage growth in wealth over...
-
Use equity theory to explain why a dentist who earns \($100\) 000 a year might be more dissatisfied with her job than a factory worker who earns \($40\) 000.
-
The Orange Blossom Marathon takes place in Orlando, Florida, each December. The organizers of this race are trying to solve a problem that occurs at the finish line each year. Thousands of runners...
-
Suppose we run a six-factor model, including market, size, value, momentum, profitability (RMW) and investments (CMA). The regression results are as below: Compare the six-factor alpha with the...
-
NNS Hospitals Ltd. is a publicly owned company that owns a chain of hospitals. The Balance Sheet of NNS as of 31/3/2015 is given below: Liabilities and Owners Equity Accounts Payable 120,000 Salaries...
-
7. Assume the rate of return given below are for two stocks listed on the Ghana Stock Exchange (GSE) Year 1 2 3 4 5 State of economy Recession Return on stock A 0.2 0.10 0.14 0.05 0.01 a. Calculate...
-
In discharge summary, which tense should be used?Question 16 options:Past tensePresent tenseFuture tense
-
Ambiguous statements may require a queryQuestion 17 options:TrueFalse
-
MTs from which level can be involved with research?Question 18 options:Professional level 1Professional level 2
-
1. In Levine's article, Listening with spirit and the art of dialog, he suggests that perhaps most important for our purpose of establishing a connection between listening and dialogue is the...
-
Analyze your short-term career goals based on an ideal job you would like to attain in the long term (specify the job title and any other particulars such as industry). I want to become a food...
-
How many strings of three lowercase English letters contain at least one vowel?
-
The text defined intrinsic value as the value of an asset given a hypothetically complete understanding of the assets investment characteristics. Discuss why hypothetically is included in the...
-
Refer to Exercise 2. a. Find the probability that the proportion of graduates who pass the test is at most 0.20 higher than the proportion of dropouts who pass, assuming that the researchers report...
-
What critical value t* from Table B should be used for a confidence interval for the population mean in each of the following situations? a. A 95% confidence interval based on n = 10 randomly...
-
Here are the amounts of money (cents) in coins carried by 10 students in a statistics class: 50, 35, 0, 46, 86, 0, 5, 47, 23, 65. To make a stemplot of these data, you would use stems a. 0, 2, 3, 4,...
-
Does the snowflake have rotational symmetry in Figure 1.6? If yes, describe the ways in which the flake can be rotated without changing its appearance. Does it have reflection symmetry? If yes,...
-
Which of the following statements are hypotheses? (a) Heavier objects fall to Earth faster than lighter ones. (b) The planet Mars is inhabited by invisible beings that are able to elude any type of...
-
A battery-operated wall clock no longer keeps timeneither hand moves. Develop a hypothesis explaining why it fails to work, and then make a prediction that permits you to test your hypothesis....
Study smarter with the SolutionInn App