You are on page 1of 6

Cache memory Simulator

Over the past few years, the speed of microprocessors has increased faster than the
speed of semiconductor memories. The effective speed of memory can be increased
by using a small amount of high-speed cache memory to hold frequently accessed
data and instructions.

The purpose of this project is to create a cache memory simulator in order to analyze
the effect of changing a cache's parameters (size, organization, line size). Ideally,
the simulator would be written as a Java applet.

Address and Data Simulator

Computers generate addresses and either read data from memory or write data to
memory. Instructions are read from memory sequentially, unless a branch or jump
instruction modifies the flow of control.

Cache memory systems rely on the "locality of reference" of data; that is, data
elements are frequently accessed from locations that are close together.

The goal of this project is to produce a CPU simulator that generates random
addresses and data to simulate a real processor. The simulator can be programmed
to behave in various modes. You can select how clustered the data is, the frequency
of subroutine calls, the size of subroutines, and so on.
/* A cache simulation
* Updated 24 March 1997 for JDK1.1
* Updated 5 Aug 97 to put entities in separate files to
* keep jar tool happy.
*/
package cache;

import java.applet.*;
import java.awt.*;
import eduni.simanim.*;
import eduni.simjava.*;
import eduni.simdiag.*;

public class Applet5 extends Anim_applet implements Runnable {


Panel inputs;
Label reqLabel, assocLabel;
TextField reqField;
Choice assocChoice;

public void anim_init() {


int i;
inputs = new Panel();
inputs.setLayout(new GridLayout(0,2));
reqLabel = new Label("Memory requests:", Label.RIGHT);
inputs.add(reqLabel);
reqField = new TextField("5",3);
inputs.add(reqField);

assocLabel = new Label("Cache associativity:", Label.RIGHT);


inputs.add(assocLabel);
assocChoice = new Choice();
assocChoice.addItem("direct mapped");
for(i=2; i<8; i*=2) assocChoice.addItem(" "+i+" way");
assocChoice.addItem("fully associative");
assocChoice.select(2);
inputs.add(assocChoice);

// Add a trace saver


trace_out.addTraceListener( new TraceSaver("tracefile") );

this.add("North", inputs);
}

//public boolean handleEvent(Event e) {


// return super.handleEvent(e);
//}

public void anim_layout() {


int reqs, assoc, i;
int NUM_FRAMES = 8;

// Extract GUI info


reqs = Integer.parseInt(reqField.getText());
assoc = 1;
assoc <<= assocChoice.getSelectedIndex();

// Build ents
Sim_system.add(new Cpu("CPU", reqs, 100, 20));
Sim_system.add(new Memory("Memory", 100, 218));
for(i=0; i<NUM_FRAMES; i++) {
Sim_system.add(new CacheFrame("Frame_"+i, 170, 56+i*20));
}
Sim_system.add(new Cache("Cache", assoc, NUM_FRAMES, 108, 102));
// Link ents
Sim_system.link_ports("CPU", "io", "Cache", "cpu");
Sim_system.link_ports("Memory", "io", "Cache", "mem");
for(i=0; i<NUM_FRAMES; i++) {
Sim_system.link_ports("Cache", "frame_"+i, "Frame_"+i, "io");
}
}
}

You might also like