GUARINI NICOLAS — M. 918670 — [email protected]


Draw the control flow graph (CFG) of the method executePool(...) given below.

class ProcessHandler {
    public static final  int NUM_PHYSICAL_UNITS = 8;
    public static final  int MAX_POSTPONE = 2;
    private boolean isUsingVirtualUnits = false;

    public void executePool(List<Process> primaryP, List<Process> secondaryP) {
        for (Process p : primaryP) {
            p.setPriority(Process.HIGH_PRIORITY);
        }
        List<Process> toExec = new ArrayList<>();
        toExec.addAll(primaryP);
        if (primaryP.size() > NUM_PHYSICAL_UNITS) {
            switchToVirtualUnits();
            toExec.addAll(secondaryP);
        }
        for (Process p : toExec) {
            if (p.priority() >= Process.HIGH_PRIORITY) {
                exec(p);
            } else {
                int ttl = p.updTimeToLive();
                if (ttl > 0) {
                    handle_postponed(p);
                }
            }
        }
    }

    private void switchToVirtualUnits() { isUsingVirtualUnits = true; /* ... */ }
    private void exec(Process p) { /* ... */ }
    private void handle_postponed(Process p) { assert(isUsingVirtualUnits); /* ... */ }

}

public class Process {

    public static final int HIGH_PRIORITY = 10;

    private int priority = HIGH_PRIORITY;

    private int ttl = 1;

    public Process(int ttl) { if (ttl > 1) this.ttl = ttl; }

    public int priority() { return priority; }

    public void setPriority(int p) { priority = p; }

    public int updTimeToLive() { return --ttl; }

}

Untitled

Use the CFG to answer the following questions: