View this PageEdit this Page (locked)Attachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Guan Lin Liao

Name: Guan Lin Liao.
E-mail: gtg595p[~at~]

CoWeb Assignment 3

Object-Oriented Language Design (2 Points)
OO programming languages differ quite a bit in their philosophy, purpose, and implementation. The following five questions ask you to examine some design choices for creating an OO language. Answer only two of the following:

1. Java, C++, and C# have primitive types. Eiffel, Ruby, and Smalltalk do not. What are the advantages and disadvantages of having primitive types?

3. Most OO languages run on a virtual machine. Java and Smalltalk do. C++ does not. What are the advantages and disadvantages of using a virtual machine for OO programming?

Garbage Collection (3 Points)
(Part A) What are the advantages and disadvantages to using garbage collection? (Part B) Explain how reference counting works. Include an example. (Part C) Explain how mark and sweep works. Include an example. (Part D) What problems of garbage collection do generational scavenging and “stop and copy” address? How do they address them?

PART A – Advantages & Disadvantages to Garbage Collection


PART B – Reference Counting
A garbage collection algorithm that each object keeps a count on how many reference it has. If this count reaches 0, then it can’t be accessed and therefore garbage collected.


Uploaded Image: Reference1.JPG
Initial state

Uploaded Image: Reference2.JPG
Last reference was removed making the last object have a count of 0.

Uploaded Image: Reference3.JPG
Object removed.

PART C – Mark and Sweep Algorithm
This garbage collection algorithm trace from root objects to everything that is accessible to them and marking them. Those that aren’t mark gets sweep away. The root objects are objects that a program can access directly which are local variables and any static variables that refer to objects.


Uploaded Image: sweep1.JPG
Initial state

Uploaded Image: sweep2.JPG
Runs the mark part of the algorithm

Uploaded Image: sweep3.JPG
Sweep away the non-reachable objects

PART D – Generational Scavenging & Stop and Copy

Generational Scavenging addresses the fact that we do not have to run a full mark and sweep algorithm because the objects that need to be mostly freed are the newest created objects. The way they address this is by having different memory regions to where we allocate our objects and slowly move the object up the a memory generation when that particular region is full.

Stop and Copy addresses memory fragmentation. It splits our memory into two regions, the current active region and the inactive region. Once the current active region is full, we will find the objects that are still active and pass them over to the inactive region and then switch the region active and set the other to inactive.

CoWeb Assignment 1

Writing Code (1 point)

Implement a method in Squeak that will give you the nth Fibonacci number. For both 0 and 1, the Fibonacci number equals 1. From then on, the next in the series is simply the sum of the previous two in the series (1, 1, 2, 3, 5, 8, 13, 21, 34, 55, etc.). Return an error when applicable. Your code should be based on good OO-style and be an efficient algorithm.

fib: anum
	|firstNumber secondNumber secondTempHolder counter|
	firstNumber := 0.	
	secondNumber := 1.
	secondTempHolder := 0.
	counter := anum.

	(counter < 0) ifTrue: [self error: 'Invalid number.  Please input a nonnegative number'].
	[counter >= 0] whileTrue:
		[secondTempHolder := firstNumber + secondNumber.
		 firstNumber := secondNumber.
		 secondNumber := secondTempHolder.
		 counter := counter - 1.

Tracing Code (1 point)
The following code solves the rainfall problem, which you may have seen in previous CS classes. For each line, describe what the Smalltalk code does. Be as specific as possible. In particular, what is data at the various points in the code?

data onlyPositiveNumbers
"Sets the local variables. Currently does not have anything in them"

data := OrderedCollection withAll: #(1 2 3 -4 -5 'error' 6 -7 999 2).
"Sets data as a orderedCollection with all those items inside"

onlyPositiveNumbers := [:i | (i isKindOf: Number) and: [i positive]].
"Sets the reference of that block to onlyPositiveNumbers variable. The block iterates and finds all numbers that are a number and also positive. It does not actually do it."

data := data select: onlyPositiveNumbers.
"This sets the data to only positive numbers using the block reference in onlyPositiveNumbers. data = an OrderedCollection(1 2 3 6 999 2)"

data := data copyUpTo: 999. "not including"
"This copy all the items in data up to 999 and not including 999. This sets data to an OrderedCollection(1 2 3 6)"

Transcript show: data average
"Average the remaining items in the OrderedCollection which will be shown on a transcript with a value of 3."

CoWeb Assignment 2

Squeak Finding Tools Mini Tutorial

Since Squeak is not very well documented, it is very hard to find classes we desire on the net. There are a few tools inside Squeak that can help us find things easier.

Implementors of it

This tool can be used in situations when there is a method and you want to know where it located is and what is its functionality.

How to Use It

Suppose you wanted to know what playOn: at: method does in the playPhoneticEvent: event at: time method of GesturalVoice.

Uploaded Image: imp1.JPG
Figure 1

Highlight playOn: at: and bring up the yellow-button menu. (Figure 1)

Uploaded Image: imp2.JPG
Figure 2

Find the implementors of it choice. You might need to hit more… to find it.

Uploaded Image: imp3.jpeg
Figure 3

Once you have done that, the window above will be displayed on the screen. The top part shows the class that implements this method for the message playOn: at: and the bottom part shows the code on the method.

Senders of it
Suppose you see a method and now you want to know what is using it in the current system. Using the same example above, let’s say you want to find who uses playOn: at: in the system. Highlight the method just like Figure 1 and do the same as Figure 2, but instead find the Senders of it choice.

Uploaded Image: sender1.JPG
Figure 4

That should pull a window similar to the Figure 4. As you can see, it shows all the places that playOn:at: is used. You can see the method were we first found the playOn:at: being listed also.

Method Finder
This tool is probably used most often to find methods in Squeak. Sometimes you know a part of a method name, but not too sure exactly what it was. At times like those, we use the Method Finder to help us. There are two ways to access the Method Finder:
a) Access the Window menu and choose open… and Method Finder.
b) Press the Tools tab on the right side and drag a Method Finder.

Uploaded Image: metFind.JPG

Once you have opened a Method Finder, you can type in whatever keyword you want to search for in the upper left and methods that contain those keywords are shown in the window right underneath the search box. Clicking on any of those search results will give us the implementors of it.

Links to this Page