










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Instructions for building an incremental stop© collector for java interfaces without write barriers. It also covers the concept of interface references and their usage in java. Additionally, it discusses the differences between virtual-call dispatch tables for objects appearing in virtual and interface calls.
Typology: Exams
1 / 18
This page cannot be seen from the preview
Don't miss anything!











NAME and LOGIN:
Your SSN or Student ID:
Circle the time of your section: 9:00 10:00 11:00 2:00 3:
Q1 (30 points) Q2 (45 points) Q3 (25 points) Q4 (50 points) Total ( 150 points)
1 Garbage Collection
This question asks about the Stop&Copy garbage collector, and also about how to extend this col- lector with incremental collection.
The questions.
Draw your answer here (don’t draw pointer links that didn’t change):
(a) from a copied object to a copied-and-scanned object, or (b) from an object in an old space to a copied-and-scanned object, or (c) from a copied-and-scanned object to an object in the old space, or (d) from a copied object to an object in the old space.
Justify your answer by stating what would go wrong with the collection process if the main program indeed placed this link. Explain the problem with an example.
2 Run-time Organization for Interfaces (a “project” question)
Imagine you want to add to Decaf the Java interface construct. To compile Java interfaces, you will have to design a different style of dynamic dispatch tables. This question asks you to design such a dispatch mechanism.
Background. If you never heard of Java interfaces, don’t despair. We provide a sufficient back- ground: Java interfaces provide a limited form of multiple inheritance. For the purpose of this question (we simplify Java unnoticeably), a Java interface is a type whose members are abstract methods. Except for the special class Object, each Java class extends exactly one class and implements zero or more interfaces. A class C is said to implement an interface I when C im- plements (that is, provides bodies of) all methods of I.
Example. The simple example below defines two interfaces (IK and IM) and three classes that implement (some) of the two interfaces.
public interface IK { abstract public void k(); } public interface IM { abstract public void m(); } public class A implements IK, IM { public void k() { System.out.println("A:k"); } public void m() { System.out.println("A:m"); } } public class B implements IM { public void k() { System.out.println("B:k"); } public void m() { System.out.println("B:m"); } } public class C extends B implements IK { public void k() { System.out.println("C:k"); } }
Interface references. To make use of interfaces, Java introduces interface references , which are like object references, except that an interface reference of type I is allowed to point to objects of any type C such that the class C implements the interface I. For example, the interface reference t of type IK (introduced above) is allowed to point to an object of type A or C but not of type B, even though B happens to contain a method k():
IK t; t = new A(); // LEGAL t = new B(); // ILLEGAL t = new C(); // LEGAL
t.k(); // LEGAL (regardless of dynamic type of t) t.m(); // ILLEGAL (regardless of dynamic type of t)
Compiling interfaces. Compiling Java interfaces boils down to supporting a new kind of method call, named interface method call. This call is like the (non-static) virtual method call that you im- plemented in PA5, except that the object on which you invoke a method comes from an interface reference, as opposed to an object reference.
Example (continued). The code below makes both kinds of calls.
B b; // b can point to any object of type B or subclass of B IK ik; // ik can point to any object that implements interface IK
if (x==1) { b = new B(); ik = new A(); } else { b = new C(); ik = new C(); } b.k(); // virtual call ik.k(); // interface call
When x==1, the program outputs
B:k A:k
Turn over.
ik A
k m
ik C
k m
Questions on this page will take you some time.
The questions.
Reading from a reference variable p: (denote the value being read r)
Writing to a reference variable p (denote the value being written r)
B orig; A tmp1 = orig.a1; B bad = tmp1.b;
4 A Language for Developing GUI Windows
This question comprehensively tests your knowledge from the entire semester. You will imple- ment a small language for specifying GUI windows with dialog boxes and buttons. You can think of the language as a simple, convenient layer over a rather complicated GUI library.
Your test-taking strategy. Leave this problem until after you are done with the other questions. If you run out of time, answer as many parts as possible, while trying to convince us that you’d know how to finish each part.
Assumptions. This question is intentionally specified in less detail than a typical exam question. Ask the proctors if you don’t understand anything; however, if you merely need to make a design choice, then make the decision on your own, state your assumptions, and go on. We are prepared for the fact that there are multiple good solutions.
Now, the language you’ll need to compile. The following program specifies a GUI window shown below it. (In other words, this is the window that will be drawn if you run the program.) The description of the language on the following page will help you understand the structure of the example program, which you should study very carefully before proceeding.
window "Find" { "Find what:" <------------------> ["Find next"], window "" { x "Match whole word only", X "Match case" } window framed "Direction" { o "Up" O "Down" } ["Cancel"] }
The target language. You will compile the language into a sequence of calls to a hypothetical object-oriented GUI library. The running example could be compiled to the following code. Use these calls to implement your compiler.
// the constructor’s argument is always the parent window; Window top = new Window(null); // top-level window is parentless top.setTitle(‘‘Find’’);
// The first row of the top-level window
Text t = new Text(top); t.setPosition(0,0); // sets position within the parent window, given as x,y coord. // position is relative to top left corner of parent window // values are in percent of the parent size t.setLabel("Find what:");
Dialog d = new Dialog(top); d.setPosition(20,0); d.setWidth(18*someConstant); // there are 18 dashes in <--...-->
Button f = new Button(top); f.setType(REGULAR_BUTTON); f.setPosition(80,0); f.setLabel("Find Next");
// Second row of the top level window // Left nested window Window w1 = new Window(top); w1.setPosition(0,50);
Selection s1 = new Selection(w1); s1.setPosition(0,0); s1.setLabel("Match whole word only");
Selection s2 = new Selection(w1); s2.setPosition(0,50); s2.setLabel("Match case"); s2.setSelected(true); // this selection is checked
// Right nested window Window w2 = new Window(top); w2.setPosition(45,50); w2.setTitle("Direction"); w2.setFramed(true);
Button r1 = new Button(w2); r1.setType(RADIO); r1.setPosition(0,0); r1.setLabel("Up");
Button r2 = new Button(w2); r2.setType(RADIO); r2.setPosition(50,0); r2.setLabel("Down"); r2.setSelected(true); // this button is checked
// The very last element Button c = new Button(top); c.setType(REGULAR_BUTTON); c.setPosition(80,50); c.setLabel("Cancel");
// Finally, draw the entire window (it draws its subwindows, too, of course) top.draw();
The questions
lexeme token attribute, (regular expression) (symbolic constant) if any “framed” FRAMED none (a keyword)
E → E + E if E 2 .trans == E 3 .trans then E 1 .trans := true
.