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
-
Prelab 5: For Part II of this lab, you will work with the following system in static equilibrium: R Mg Center of Mass mg Fx T Pivot a.) Using the first condition for static equilibrium (F = 0), write...
-
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
-
Duit plc has recently acquired Ucando Ltd which is a regional builders' merchants/DIY company with three outlets all within a radius of 40 miles. Duit plc is building up its national coverage of...
-
FIGURE EX39.17 shows the wave function of an electron. a. What is the value of c?b. Draw a graph of |(x)| 2 .c. What is the probability that the electron is located between x = -1.0 nm and x = 1.0...
-
What role do professional organizations have in establishing guidelines for ethical conduct?
-
Delaware Chemical Company uses oil to produce two types of plastic products, P1 and P2. Deleware budgeted 25,000 barrels of oil for purchase in September for $72 per barrel. Direct labor budgeted in...
-
Given the following information on Project X, compute the accounting rate of return and the payback period. Year Accounting Profits Cash Flows 1 $799 $4 000 2 $799 $4 000 3 $799 $4 000 4 $799 $4 000...
-
Table 1: Calculation of 3 month forward rates using the simple interest rate parity principle (4 marks) Exchange rate Forward rate 3 months Workings (show calculations in this column) from now...
-
5. (5.6) Evaluate the following integrals using partial fractions. Note, if the degree of the polynomial in the numerator is larger than the degree of the polynomial in the denominator, we need to...
-
a.) An automobile driver uses a control system to maintain ther speed of the car at a prescribed level. Sketch a block diagram to illustrate this feedback system. b.) Fly-Fishing is a sport that...
-
A communication channel accepts X that is either 00 or 01 or 10 or 11. The channel transmits each bit binary input with probability p and enormously with probability (1-p) and gives out Y as output....
-
Define logistics. (2) Explain what logistics does. (3) Discuss how important logistics is to be successfully managed within the supply chain of ANY organization
-
The following is the payoff diagram of the trading strategy. Use this diagram and the information of option price from the table below to answer the questions. Payoff 90 95 Stock 105 100 price Class...
-
Mill Creek School District is a high school district in Mill Creek, Illinois. Mill Creek School District has 3 high schools within the district. The 3 high schools are Bradley High School, Mooney...
-
Average Rate of Return Method, Net Present Value Method, and Analysis The capital investment committee of Overnight Express Inc. is considering two investment projects. The estimated income from...
-
What does non-recourse financing mean?
-
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,...
-
NOPAT is the amount of net income a company would generate if it had no debt and held no financial assets. NOPAT is a better measure of the performance of a company's operations because debt lowers...
-
Free cash flow is the cash flow actually available for distribution to investors after the company has made all the investments in fixed assets and working capital necessary to sustain ongoing...
-
If the business were organized as a partnership or a proprietorship, its income could be taken out by the owners without being subject to double taxation. Also, if you expected to have losses for a...
Study smarter with the SolutionInn App