Posts

Showing posts from February, 2017

The WeakReference class, monitoring memory leak and garbage collection in a Java application

Image
 Below is a Stack implementation that uses an internal resizeable array structure.  public class MyStack< T > implements Stack< T > { private static final int CAPACITY = 100 ; private Object[] array ; private int pos = 0 ; public MyStack () { this . array = new Object[ CAPACITY ] ; } @Override public void push ( T item) { if ( pos >= array . length / 2 ) { Object[] newArray = new Object[ pos * 2 ] ; System. arraycopy ( array , 0 , newArray , 0 , array . length ) ; array = newArray ; } array [ pos ++] = item ; } @Override public T pop () { if (isEmpty()) { throw new RuntimeException( "empty stack" ) ; } @SuppressWarnings ( "unchecked" ) T item = ( T ) array [ pos - 1 ] ; pos -= 1 ; return item ; } @Override @SuppressWarnings ( "unchecked" ) public T peek...

Understanding SimpleScalar codebase

Among others, sim-safe is the most user-friendly simulator and the implementation is crafted for clarity. Generally there are two types of simulators: Functional simulators implement architecture (what programmers see) perform the actual execution sim-fast, sim-safe , sim-profile, sim-cache Performance simulators implement micro-architecture model system internals measure time sim-outorder Question: What is Dlite debugger? How can we debug a simulator?? DLite is a symbolic debugger. To use it, start the simulator with -i option Then user the debugger commands, for example: "step" Question: To work with TLB, do I have to fully understand sim-outorder ?? http://www.simplescalar.com/docs/simple_tutorial_v2.pdf page:14 http://www.simplescalar.com/docs/hack_guide_v2.pdf Question: How does sim-safe count number of instructions? Where is iTLB related code? In main.c file: /* options database*/ struct opt_odb_t *sim_odb; /* simulated re...

More on Virtual Memory and TLB

Below is a series of videos on virtual memory: https://www.youtube.com/watch?v=KNUJhZCQZ9c Virtual memory is a layer of indirection. Without virtual memory the program address would be equal to the RAM address.  Discs are 1000x slower than RAM. What happens if a page is not on RAM?  Page table tells that the page is on disc. Hardware (CPU) generates a page fault exception . This exception will be picked up by the operating system. ( page fault handler ) Operating system kicks out (evicts) another page from RAM and writes it to disc If the page is dirty, it needs to be written back to disc first. Then OS reads the page from disk and puts it in RAM Then OS updates the page table to map the new page Finally OS jumps back to the instruction that caused the page fault A page fault is the slowest possible thing that can happen to a computer. (except for human interaction) Some operating sytems do not use paging: iOS kills the program if it uses too much memory....

Popular posts from this blog

Trie Data Structure and Finding Patterns in a Collection of Words

My Crappy Looking Solution to "Binary Tree Common Ancestor" Problem

A Graph Application in Java: Using WordNet to Find Outcast Words