The Artima Developer Community
Sponsored Link

Java Answers Forum
cache classes to test a trace file

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Holly

Posts: 1
Nickname: degree
Registered: Feb, 2003

cache classes to test a trace file Posted: Feb 26, 2003 3:37 PM
Reply to this message Reply
Advertisement
Hi...im new to this website..and i really need some help on my java..

I will need to write a class of direct mapped,associative and fully associative cache, which implements the class given below. Then they will be tested on a trace file. Please can anybody give me some help??



public abstract class Cache{
int size,line_size; //sizes in bytes initialised by constructor of subclass
// counters used to generate performance statistics
int total_accesses, read_accesses, write_accesses; //all total numbers hit or miss
// read includes read and fetch
int read_misses, write_misses, rejections, main_mem_accesses;
// rejections is when a valid line in the cache is replaced by a new line

Cache(){
//initialise statistics when new cache created
total_accesses = 0;
read_accesses = 0; //read and fetch accesses
write_accesses = 0;
read_misses = 0;
write_misses = 0;
rejections = 0;
main_mem_accesses = 0;
}

public void write(int addr, Object indata) {
// You must write this code for ex1
total_accesses++;
write_accesses++;

if(search(addr)!= null){

putData(indata);

}

else{
write_misses++;
}

}

public Object read(int addr) {
1
total_accesses++;
read_accesses++;

if(search(addr) == null){

main_mem_accesses++;
read_misses++;

CacheFillInfo cacheFInfo = cacheFill(addr) ;

if(cacheFInfo.old_valid== true){

rejections++;

}

return cacheFInfo.data;
}

else{
return null;
}
}

abstract Object search(int addr);
abstract CacheFillInfo cacheFill(int addr);
abstract void putData(Object entry);

public void dumpStats(){
System.out.println("Total accesses = "+ total_accesses);
System.out.println("Total read accesses = "+ read_accesses);
System.out.println("Total write accesses = "+ write_accesses);
System.out.println("Read Misses = "+ read_misses);
System.out.println("Write Misses = "+ write_misses);
System.out.println("Total rejections = "+ rejections);
System.out.println("Total main memory accesses = "+ main_mem_accesses);
System.out.println("Read Miss Rate = "+(float)100*read_misses/read_accesses+"%");
System.out.println("Write Miss Rate = "+(float)100*write_misses/write_accesses+"%");
}

public int totalAccesses() {
return total_accesses;
}
public int readAccesses() {
return read_accesses;
}
public int writeAccesses() {
return write_accesses;
}
public int readMisses() {
return read_misses;
}
public int writeMisses() {
return write_misses;
}
public int numRejections() {
return rejections;
}
public int mainMemAccesses() {
return main_mem_accesses;
}
}

Topic: Math.random() Previous Topic   Next Topic Topic: ORA-01461: can bind a LONG value only for insert into a LONG column

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use