SIMS 255: Assignment 2

    Due Thursday September 19. (This is the only assignment in this class that is due in 7 days instead of 10 days. Thus, it is short.) Please do this on your own. Turn a hardcopy in in class.

    To help you answer these questions, you might want to look at this math review.

    1. Addressing Memory
    2. The RAM memory used by a CPU is often divided up into fixed-size contiguous units, called frames, each of which can hold a page of memory of a process. The first frame begins at memory address 0, and is called frame number 0. The second frame is frame number 1, and begins at memory address (0 + the number of bytes in a page), and so on.

      The memory that a process needs in order to run is broken up into page-size units. When it is a process's turn to run, the operating system swaps the process's data from the hard disk into page frames in memory that are currently free. (If the amount of memory a process needs is not a perfect multiple of the page size, then the process simply wastes the unused space in the last page.)

      User processes act as if they start at memory address 0, and continue contiguously from there. However, they might be put into any of the frames in memory. The operation system translates the "logical" addresses of the program into "physical" addresses in RAM. Thus if the process wants to access memory address 127 (a logical address), and it is put into frame number 1, its physical location is the size of a page frame plus 127.

      Say we have a 32 bit machine whose page size is 256KB. Say also that one of the logical addresses is 32,892 (decimal), and is placed into frame number 7.

      (1) How many pages can the system address?
      (2) How many pages can be kept in a main memory of 16MB?
      (3) What is the physical address for the given logical address?

    3. Memory Management Algorithms
    4. Consider a region of main memory (RAM) (shown in the diagram below), and a set of processes that need to use the RAM. Your job is to illustrate how the memory manager will allocate the memory to the processes, over time, according to two different allocation strategies (first fit and best fit).

      Assume this system does not allow the address space for a given process to be broken up. Assume also that it does not interrupt a process while it is executing. When a process exits, its memory gets freed up.

      In the case where there is not enough available memory to meet a process' request, that process will need to wait while other processes execute until enough memory is freed up. It will then be given highest priority access to that memory.

      Currently four processes (A, B, C, and D) have been allocated memory in the locations shown in the diagram. The areas with slanted lines are currently free (unallocated) space. Suppose the following actions occur:

    5. Process E starts and requests 300 memory units.
    6. Process A requests 400 more memory units.
    7. Process B exits.
    8. Process F starts and requests 800 memory units.
    9. Process C exits.
    10. Process G starts and requests 900 memory units.
    11. For the following questions you should describe the answers in words and pictures:

        (1) Describe the contents of memory after each action using the first-fit algorithm. Be sure to note when a process must wait for another porcess to exit.

        (2) Describe the contents of memory after each action using the best-fit algorithm. Be sure to note when a process must wait for another process to exit.

        (3) For this example, which algorithm is best? Why?

    12. Short Answer Questions
    13. Please answer the following with 1 paragraph answers.

        (1) Why is Virtual Memory useful?

        (2) What is Thrashing? Can thrashing occur if only one user is using a machine?

        (3) Consider the class Fish, as shown in Lecture 6 (slides 18 and 19). Write code to instantiate two new objects of this class. Be certain that their values are different than those shown in the lecture. Show where they would appear in memory if they were defined immediately after Charlie and Freddy. Now define a new (simple) class (say, of type Frog) and instantiate two instances of it. Place these instances directly after the Fish instances.

    Alternate Questions

      You may do these questions instead of (or in addition to!) the ones above, if you like, but if you chose this, option you must do both questions.

      (1) If you are familiar with written music, analyze musical notation as a programming language. What are the control structures? What is the syntax for inserting programming comments? What music notation has syntax similar to for statements? (from Brookshear).

      (2) Read up on the java bytecode specification at http://java.sun.com/docs/books/vmspec/2nd-edition/html/Compiling.doc.html (or elsewhere).

        Do one of the following:

        (a) Try to write some bytecode from scratch.
        (b) Write a one or two page discussion of something about the bytecode approach.