Sunday, March 31, 2013

MMTk mechanisms, policies, and plans

Class Diagram: MMTk Policies
MMTk is a flexible memory management utility written using java, for Jikes RVM. It is also ported to Rotor - the Microsoft's open C# runtime. Key Compositional Elements in MMTk are utilities, policies, and plans.

Bootstrapping
Jikes is meta-circular, as it is written in Java, the language it interprets as a JVM. Here, the functionality of the parent interpreter is applied directly to the source code being interpreted, without any additional implementation. Hence it requires a bootstrap VM to run upon, to create a boot image. However, it doesn't run on an external JVM. Rather, a small boot image runner written using C is responsible for loading the image files at run time, and it transfers the control to the native VM code that runs on the host [1].

Interruptibility
Compiler pragmas are used by MMTk to control the inlining and interruptibility, and scoped across methods and classes, where more specific pragma scopes such as method pragmas override the broader ones such as class pragmas. Classes annotated @Uninterruptible make the class uninterruptible. If most of the methods in a class are uninterruptible, annotating the class as uninterruptible is reasonable and preferred. All the policies and plans have the unintteruptible classes.


1) Mechanisms (utility)
MMTk comes with the utility classes that provides mechanism for the memory management, across multiple policies and plans that use those policies. An ideal example showing the usage of the utility package is, the interface Constants. All the classes either implement the Constants interface, or are sub classes of the classes that implement the interface.

1. Bump pointer allocation
2. Free list allocation
3. Large object allocation
4. Finalization

2) Policies (policy)
Spaces are contiguous regions of virtual memory, that is managed by a single policy. MMTk maps policies to spaces. In an address space, any given policy can manage multiple spaces.

Policies are implemented following the local/global pattern, and named XXXSpace and XXXLocal.
1. Copying Collector - CopySpace extends Space | CopyLocal extends BumpPointer
Class Diagram: MMTk Plans
2. Explicitly Managed Collector - ExplicitFreeListSpace extends SegregatedFreeListSpace | ExplicitFreeListLocal extends SegregatedFreeListLocal
3. ExplicitLargeObjectSpace extends BaseLargeObjectSpace |
4. Immortal Collector - ImmortalSpace extends Space | ImmortalLocal extends BumpPointer
5. Treadmill Collector - LargeObjectSpace extends BaseLargeObjectSpace | LargeObjectLocal extends LargeObjectAllocator
6. Mark-Compact Collector (MarkCompactCollector) - MarkCompactSpace extends Space | MarkCompactLocal extends BumpPointer
7. Mark-Sweep Collector - MarkSweepSpace extends SegregatedFreeListSpace | MarkSweepLocal extends SegregatedFreeListLocal
8. RawPageSpace extends Space
9. SegregatedFreeListSpace extends Space

Each instance of a policy space maps to a single virtual memory space, with P instances of the local class attached, where the collector is P-way parallel.


3) Plans (plan)
It is the highest level of composition, as it composes policies to build a memory management algorithm.
1. CMS (concurrent.marksweep)
2. CopyMS (copyms)
3. GenCopy (generational.copying)
4. GenMS (generational.marksweep)
5. GenImmix (generational.immix)
6. MC (markcompact)
7. MS (marksweep)
8. RC (refcount.fullheap)

9. GenRC (refcount.generational)
10. SS (semispace)
11. GCTrace (semispace.gctrace)
12. UsePrimitiveWriteBarriers (semispace.usePrimitiveWriteBarriers)
13. StickyImmix (stickyimmix)
14. StickyMS (stickyms)

Saturday, March 30, 2013

Lisbon - Weeks 30 & 31

Cooking in Lisboa!
[30/03/2013] - This week comes with the Easter vacation, which was not really a vacation, as we had projects to be completed for the checkpoint.

[29/03/2013] For the past few days this week, I have been cooking myself, and interestingly, it came out pretty well. Within 3 days since I started cooking, I have even started to cook without a recipe. So much win, and yet another mission successful of the year 2013. There is a Nepal restaurant (Restaurante Kathmandu) close to my apartment which has a good Chicken mango curry. So I decided to try and cook it. 

The mango recipe of Fish or Chicken are pretty simple. First you cook Chicken in Coconut milk without adding spices (no curry powder or chilli powder), except onion, garlic, turmeric, ginger etc, and eventually start adding Mango milkshake, as the chicken is cooked. Mango milkshake was made with one mango, two cups of yoghurt, some milk, a little salt, and a tablespoon lime juice as the ingredients. The final flavor of the sauce is mostly yummy mango. Cooking with coconut milk was just to cook the chicken long enough, without spoiling the mango flavor. So the only difference is, replacing the chilli powder/curry powder combination with the mango milkshake. Make sure the mango milkshake is not burnt. It easily gets burnt and sticks to the pan, as it is sugar. Adding it later to the pan helps avoiding this, while preserving the sweetness. I tried banana apple milkshake too. But Mango seems better. You should give a try to mango.
Obidos
Fish Mango curry, Leaves curry, Carrot mango curry, and Rice in the image above. It was a huge success for the 3rd night of my cooking. Fish mango curry was a dish inspired from the Chicken mango of the Restaurante Kathmandu. However, I guess, I am the first to invent Fish Mango in this way.. :D Recipe (my own recipe.. haha..)

[27/03/2013] - We paid a quick visit to Obidos. It is a lovely neighbourhood. Regular bus services are available from Campo Grande of Lisboa, operated by Rodo Tejo. (Return trip, 2* 7.55 Euro). Obidos is famous for its ginga (cherry wine) in small chocolate cups. We had some fine ginga and played chess at Pousado Do Castelo.

[18/03/2013] - Freeport is a huge open shopping centre (centro comercial) situated in Alcochete, across the Tagus river, which can be reached by the bus 431 from Oriente, and many other means, pretty easily. The shopping centre was not that interesting, though it is considered to be the largest outlet in Europe. However the bus travel over the Vasco da gama bridge, which is considered the longest bridge in the Europe, was interesting.

3 months have already passed this year (almost!). Happiness, Excitement, Craziness, Sadness, Depression, and Stupidity - everything that comes in a mixture, slightly overdose, and that is my year 2013.

Wednesday, March 13, 2013

Lisbon - Week29

A nightly walk at Entre Campos
[14/03/2013] The second semester is getting hotter. ;) We have received the project specifications for 3 out of the 4 modules. We have already submitted the project proposals for 2 of them. We are researching Jikes RVM for the Virtual Execution Environments module.

[13/03/2013] - These days, I was busy buying flight tickets. It was a good learning experience. I was not aware of the clause, "LOW COST FARE. CANNOT BE CHANGED OR CANCELLED" and this means, we can not change a flight or cancel it. I confirmed it from the two airlines concerned, and they mentioned that this can be changed only by the travel agents (eDreams), but the travel agent eDreams policy doesn't let changing the reservation of the "Economy Restricted" tickets. I find it interesting. I should note that TAP Portugal outlet at Marques De Pombal officers were pretty much helpful.

I am enjoying the nightly walks in Lisbon. 2013 is different. I should start writing a blog post on how the year 2013 is remarkably different. :)

Saturday, March 9, 2013

Lisbon - Weeks 27 & 28

From Cabo Ruivo to Parque das Nações..
[07/03/2013] - EMDC 2013 batch now received the official invitations, and they are being added to the Facebook group of EMDC. The group is getting more and more active. The excitement of the students remind me the early 2012, when I was expecting the day to join EMDC - good old days. ;)

[05/03/2013] - I have been elected as an Erasmus Mundus Course Representative for the EMDC, for the year 2013. However, since the GA is scheduled on the day of the AVExe exam, I had  to let one of my colleagues from UPC, Barcelona to represent EMDC in the General Assembly. I will miss the GA though.

[27/02/2013] - I bought a Sony Xperia J from fnac, and realized it was locked by Vodafone. It keeps asking "SIM Network Unlock PIN", when I start the phone with the MOCHE SIM, instead of the Vodafone SIM that came bundled with the phone, and without it, it was not working with the MOCHE SIM.

From Spain to Portugal - A boat of descubriter.
I visited fnac and asked whether they could unlock my phone, when I realized that I couldn't unlock it myself or via online services, without paying for their service. Fnac pointed me out that I should contact the service providers to unlock the phone. I reached Vodafone and paid 47.47 Euros to unlock the phone, which included the discount due to the bond with the service provider and the service charge + tax.

I was told I will be sent an sms with the unlock code, in 3 days, which is supposed to be a Saturday. I didn't get any. Assuming they may not work in weekends, I waited further, and eventually waited till the Monday. I still didn't get it! So I reached to them again on the Tuesday, where they unlocked my phone, by entering the unlock code themselves. Never mind, I got it sorted out, at least! :)

[22/02/2013] - Parque das Nações never fails to amuse me. It is full of interesting restaurants, seagulls, and cold wind. The small port of Parque das Nações provides a stay for the mini boats. Parque das Nações surely is a highlight of my year 2013.

Saturday, March 2, 2013

Building Jikes RVM on Ubuntu 12.04 / 64 bit from source

Jikes RVM is a research virtual machine, built using Java. Building Jikes RVM from the source (trunk) is pretty interesting.


Installing the pre-requisites

Mercurial is the version control system of Jikes RVM. (To learn the basics of Mercurial, please refer to this article.) Jikes RVM is built using Apache Ant. Make sure to install these.
sudo apt-get install mercurial ant

Install gcc, g++, gcc-multilib, and g++-multilib
sudo apt-get install gcc-multilib g++-multilib


Checking out the source

Checkout the source code of Jikes RVM.
hg clone http://hg.code.sourceforge.net/p/jikesrvm/code jikesrvm

Updating the source
If you have already checked out the source code sometime back, you may have to update it to reflect the later changes.
To view the information of the working directory, such as the version number, from the root directory,
hg log -l1


To update,
hg pull

hg update



Building using Ant
Find the target architecture of your system.
uname -m
x86_64


Build using Ant from jikesrvm (the root directory of Jikes RVM).
 ant -Dconfig.name=prototype -Dhost.name=x86_64-linux -Dtarget.name=x86_64-linux

Here,
1) host.name and target.name entries should match the names of the properties files present in the directory jikesrvm/build/hosts (without the suffix, .properties).

2) config.name entry should match the names of the properties files present in the directory jikesrvm/build/configs (without the suffix, .properties).

You may alternatively build Jikes using the buildit tool that is included in the project.
 bin/buildit -j $JAVA_HOME localhost production


Common Exceptions

1) You may encounter the below exceptions, if you have 32-bit GTK libraries installed on a 64-bit machine.
     [exec] checking for X... no
     [exec] configure: error: GTK+ peers requested but no X library available

BUILD FAILED
/home/pradeeban/jikesrvm/build.xml:266: The following error occurred while executing this line:
/home/pradeeban/jikesrvm/build.xml:272: The following error occurred while executing this line:
/home/pradeeban/jikesrvm/build/components/classpath.xml:305: The following error occurred while executing this line:
/home/pradeeban/jikesrvm/build/components/base.xml:70: The following error occurred while executing this line:
/home/pradeeban/jikesrvm/build/components/base.xml:76: The following error occurred while executing this line:
/home/pradeeban/jikesrvm/build/components/classpath.xml:254: exec returned: 1
Passing the flag -Dcp.enable.gtk-peer="--disable-gtk-peer" will fix this issue.

 ant -Dconfig.name=prototype -Dhost.name=x86_64-linux -Dtarget.name=x86_64-linux -Dcp.enable.gtk-peer="--disable-gtk-peer"

2) You may encounter the below exceptions, if you miss gcc-multilib and g++-multilib in your system.

build:
     [exec] checking build system type... Invalid configuration `x86_64-unknown-linux-': machine `x86_64-unknown-linux' not recognized
     [exec] configure: error: /bin/bash ./config.sub x86_64-unknown-linux- failed

BUILD FAILED
/home/pradeeban/jikesrvm/build.xml:266: The following error occurred while executing this line:
/home/pradeeban/jikesrvm/build.xml:272: The following error occurred while executing this line:
/home/pradeeban/jikesrvm/build/components/classpath.xml:305: The following error occurred while executing this line:
/home/pradeeban/jikesrvm/build/components/base.xml:70: The following error occurred while executing this line:
/home/pradeeban/jikesrvm/build/components/base.xml:76: The following error occurred while executing this line:
/home/pradeeban/jikesrvm/build/components/classpath.xml:254: exec returned: 1

Running Jikes RVM
Once built, you will find the complete rvm runtime directory at ${dist.dir}/${config.name}_${target.name} (For me, it was dist/prototype_x86_64-linux, as I built with 'prototype' configuration). Now you should be able to run the rvm from the directory. A Java class can be run as below.
javac HelloWorld.java
./rvm HelloWorld