15.01.2015 Views

4th International Conference on Principles and Practices ... - MADOC

4th International Conference on Principles and Practices ... - MADOC

4th International Conference on Principles and Practices ... - MADOC

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

3.1 Our JikesRVM extensi<strong>on</strong><br />

When the programmer wants to endow her threads with the<br />

capability to migrate or be made persistent <strong>on</strong> disk, the first<br />

simple thing to do is to import the mobility package, which<br />

exposes the MobileThread class. The latter inherits directly from<br />

the java.lang.Thread class <strong>and</strong> has to be sub-classed by userdefined<br />

threads.<br />

The c<strong>on</strong>figurati<strong>on</strong> of the scheduler, when our JikesRVM<br />

extensi<strong>on</strong> is installed, is reported in Figure 2: the idea is that now,<br />

with mobility, threads can enter <strong>and</strong> exit the local envir<strong>on</strong>ment<br />

through some migrati<strong>on</strong> channels. These channels are represented<br />

in Figure 2 using the classical notati<strong>on</strong> of queuing networks. The<br />

software comp<strong>on</strong>ents added by our infrastructure are highlighted<br />

with boxes <strong>and</strong> it can be clearly seen how these parts are<br />

dynamically integrated into JikesRVM scheduler, when the<br />

programmer enables the migrati<strong>on</strong> services.<br />

The single output channel is implemented through a regular<br />

thread, which runs in a loop, performing the following acti<strong>on</strong>s:<br />

1) extract a mobile thread from the migrati<strong>on</strong> queue, where<br />

these threads wait to be transferred;<br />

2) establish a TCP socket c<strong>on</strong>necti<strong>on</strong> with the destinati<strong>on</strong><br />

specified by the extracted thread;<br />

3) if the previous step is successful, then capture the<br />

complete thread state data (i.e. the MobileThread<br />

object <strong>and</strong> the sequence of frames into its call stack, as<br />

better explained in Subsecti<strong>on</strong> 3.3);<br />

4) serialize those data into the socket stream<br />

(java.io.ObjectOutputStream);<br />

5) close the c<strong>on</strong>necti<strong>on</strong> with the other end-point.<br />

Figure 2. Adding migrati<strong>on</strong> channels to JikesRVM scheduler<br />

One or more input channels are implemented by means of regular<br />

threads listening <strong>on</strong> specific TCP ports. When a c<strong>on</strong>necti<strong>on</strong><br />

request is issued from the network, they simply do the followings:<br />

1) open the c<strong>on</strong>necti<strong>on</strong> with the requesting host;<br />

2) read thread state data from the socket stream<br />

(java.io.ObjectInputStream);<br />

3) re-establish a local instance of the arrived thread <strong>and</strong><br />

resume it;<br />

4) close the c<strong>on</strong>necti<strong>on</strong> socket.<br />

A first observati<strong>on</strong> is that n<strong>on</strong>-mobile (“stati<strong>on</strong>ary” as in Figure 2)<br />

threads in the system are not influenced at all by the infrastructure<br />

built up<strong>on</strong> the scheduler. Only those threads that inherit from our<br />

enhanced MobileThread class are interested in the added<br />

migrati<strong>on</strong> services.<br />

3.2 Proactive migrati<strong>on</strong> vs. reactive migrati<strong>on</strong><br />

There are two ways for a MobileThread to get queued into the<br />

migrati<strong>on</strong> queue, waiting for the output channel to transfer it [11]:<br />

• the mobile thread aut<strong>on</strong>omously determines the time<br />

<strong>and</strong> destinati<strong>on</strong> for its migrati<strong>on</strong>, calling the<br />

MobileThread.migrate(URL destinati<strong>on</strong>)<br />

method (proactive migrati<strong>on</strong>);<br />

• its movement is triggered by a different thread that can<br />

have some kind of relati<strong>on</strong>ship with the thread to be<br />

migrated, e.g. acting as a manager of roaming threads<br />

(reactive migrati<strong>on</strong>).<br />

Exploiting JikesRVM features, we successfully implemented both<br />

migrati<strong>on</strong> types, in particular the reactive migrati<strong>on</strong>. As<br />

anticipated in Subsecti<strong>on</strong> 2.1, an applicati<strong>on</strong>, in which reactive<br />

migrati<strong>on</strong> can be essential, is a load-balancing facility in a<br />

distributed system. If the virtual machine provides such<br />

functi<strong>on</strong>ality to authorized threads, a load m<strong>on</strong>itor thread may<br />

want to suspend the executi<strong>on</strong> of a worker thread A, assign it to<br />

the least overloaded machine <strong>and</strong> resume its executi<strong>on</strong> from the<br />

next instructi<strong>on</strong> in A’s code. This form of transparent externallyrequested<br />

migrati<strong>on</strong> is harder to implement with respect to the<br />

proactive case, mainly because of its asynchr<strong>on</strong>ous nature.<br />

Proactive migrati<strong>on</strong> raises, in fact, less semantic issues than the<br />

reactive <strong>on</strong>e, though identical to the latter from the<br />

technological/implementati<strong>on</strong> point of view: in both cases we<br />

have to walk back the call stack of the thread, extract the<br />

meaningful frames <strong>and</strong> send the entire thread data to destinati<strong>on</strong><br />

(see the following two subsecti<strong>on</strong>s for more details). The<br />

fundamental difference is that proactive migrati<strong>on</strong> is synchr<strong>on</strong>ized<br />

by its own nature (the thread invokes migrate() when it means<br />

to migrate), while for reactive migrati<strong>on</strong> the time when the thread<br />

has to be interrupted could be unpredictable (the requester thread<br />

notifies the migrati<strong>on</strong> request to the destinati<strong>on</strong> thread, but the<br />

operati<strong>on</strong> is not supposed to be instantaneous). Therefore, in the<br />

latter case, the critical design-level decisi<strong>on</strong> is about the degree of<br />

asynchr<strong>on</strong>ism to provide. In a few words, the questi<strong>on</strong> is: should<br />

the designated thread be interruptible anywhere in its code or just<br />

in specific safe migrati<strong>on</strong> points<br />

We chose to provide a more coarse-grained migrati<strong>on</strong> in the<br />

reactive case. Our choice has a twofold motivati<strong>on</strong>: (i) designing<br />

the migrati<strong>on</strong> facility is simpler; (ii) decreasing migrati<strong>on</strong><br />

granularity reduces inc<strong>on</strong>sistency risks. Although these<br />

motivati<strong>on</strong>s can be c<strong>on</strong>sidered general rules-of-thumb, they are<br />

indeed related to the VM we adopted. In fact, the scheduling of<br />

the threads in JikesRVM has been defined as quasi-preemptive<br />

[1], since it is driven by JikesRVM compilers. In JikesRVM, Java<br />

threads are objects that can be executed <strong>and</strong> scheduled by several<br />

kernel-level threads, called virtual processors, each <strong>on</strong>e running<br />

<strong>on</strong> a physical processor. What happens is that the compiler<br />

introduces, within each compiled method body, special code<br />

(yieldpoints) that causes the thread to request its virtual processor<br />

if it can c<strong>on</strong>tinue the executi<strong>on</strong> or not. If the virtual processor<br />

grants the executi<strong>on</strong>, the virtual thread c<strong>on</strong>tinues until a new<br />

yieldpoint is reached, otherwise it suspends itself so that the<br />

virtual processor can execute another virtual thread. In particular,<br />

when the thread reaches a certain yieldpoint (e.g. because its time<br />

slice is expired), it prepares itself to dismiss the scheduler <strong>and</strong> let<br />

65

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!