Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AssocCache
- extends Cache
- {
- //declaring global variables used
- int[] cache_entries;
- boolean[] is_valid_object;
- Object[] object_set_cache;
- int valid_entry_position;
- int cache_size;
- int line_size;
- AssocCache(int new_cache_size, int new_line_size)
- {
- //initialsing variables
- cache_size = new_cache_size;
- line_size = new_line_size;
- cache_entries = new int[cache_size / line_size];
- object_set_cache = new Object[cache_size / line_size];
- is_valid_object = new boolean[cache_size / line_size];
- //initialise boolean valid object check values
- for (int index = 0; index < cache_size / line_size; index++) is_valid_object[index] = false;
- }
- public Object cacheSearch(int addr) {
- for(int index = 0; index < cache_size/line_size; index++) {
- //checking if there is a valid cache entry at the given address
- if ((is_valid_object[index] != false) && (cache_entries[index] == (addr/ line_size))) {
- valid_entry_position = index; //remembering cache entry position globally for later use
- return object_set_cache[index]; //returning the object set to the value of the cache entry
- }
- }
- return null; //return null if no valid entry has been found
- }
- public oldCacheLineInfo cacheNewEntry(int addr) {
- for(int index = 0; index < cache_size/line_size; index++) {
- oldCacheLineInfo localOldCacheLineInfo = new oldCacheLineInfo();
- localOldCacheLineInfo.old_valid = is_valid_object[index]; //store old valid value
- cache_entries[index] = (addr / line_size); //set new cache entry
- is_valid_object[index] = true; //set if valid entry to true
- localOldCacheLineInfo.data = (object_set_cache[index] = new Integer(-1)); //set new data
- return localOldCacheLineInfo;
- }
- return null;
- }
- public void cacheWriteData(Object indata) {
- object_set_cache[valid_entry_position] = indata; //update data field of object set cache using the position remembered
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement