Friday, July 19, 2013

Erasmus Mundus Presentation at the University of Moratuwa



Today I gave an introductory talk to the Erasmus Mundus program for the final year students of the Department of Computer Science and Engineering of the University of Moratuwa, Sri Lanka. The presentation slides which complimented the discussion are given above, though the presentation doesn't capture much of the topics discussed in the session. I enjoyed doing the talk and the students showed great interest and involvement. 

This was a quick introduction to the Erasmus Mundus program, based on my personal experience with Erasmus Mundus after completing the first year of EMDC (European Master in Distributed Computing) at Instituto Superior Tecnico, Lisbon. My blog posts on my stay in Lisbon can be found here. Feel free to drop me a line, if you require further information on this.

Sunday, July 7, 2013

Till I see you again..

Seagulls everywhere, just like our crows!
[29/06/2013] - We wanted to pay a quick visit to the south of Portugal following the visit to Porto, as we had initially planned a few weeks back. Since we were running out of time, we just wanted to make it a day trip. Our target was Lagos. Rede Express has a direct bus to Lagos, unlike the train which goes up to Faro, and requires changing to a urban train to Lagos. The bus went from Lisboa to Lagoa, Portimao, and finally reached Lagos. It took 3 hours and 45 minutes.

Lagos
Beaches of Algarve are really popular. We preferred Lagos over Faro, as Faro gets a bit overcrowded during the summer. First we had a boat trip of an hour to the caves and cliffs of the region by a small boat, starting from the Lagos beach, for 10 Euro. It offered us a picturesque view. Our initial plan was to go on a dolphin visit (which costs 25 Euro) for 1.5 hours by boat. We were feeling dizzy after the boat ride, and had to drop our plan. But we realized, had we gone by a bigger boat, we wouldn't have felt that much uncomfortable.

Cliffs of Lagos
Meia Praia
We spent the rest of the evening under the shade in Meia Praia (half beach). We had to pay 6 Euro per shade, from 4 p.m onwards. But it worths it. The beach was warm. But was full of algae, which made us avoid having a bath or swim. I never had realized that the summer in the Europe gets this hot, to 40 °C.

Finishing Touches
[30/06/2013] - This evening was a bit tiresome and full of mixed feelings. I had a lots of things to throw. I put the clothes and shoes that I don't want to take back with me into the Humana Portugal bin. I hope they will be useful to someone in need.

Destino

My last dinner before leaving Lisbon was at my most favourite Restaurante Destino of Restauradores, with some sparkling wine. I feel like, my brain had lately started to function to just a limited extend. I already started to miss Lisboa. However, I am happy that my 10 months stay in Portugal was just perfect, and had nothing to regret. I realize how fast the time has gone, since the most remarkable eve of the new year. We are now saying good bye to the first half of 2013.

This is NOT the end
[01/07/2013] - Lisbon - Week 45: This is going to be the last post on the series "Lisbon - Weekxx" till I get back to Lisbon for my thesis, end of this year. Today was not so easy. In fact, it was one of the most difficult days in my life. Many of the things are left unwritten, as they are beyond the scope of Llovizna. I feel like missing everything. The day was full of tears, that I have never experienced before. Good bye Lisboa, till I see you again!

Oporto

Sao Bento Railway Station
[28/06/2013] - Lisbon - Week 44: This week was full of farewells and tears as most of us have already started leaving Portugal, finishing our first year in EMDC. This week's highlight was the visit to Oporto (better known by its Portuguese name, Porto). The trip extended from the 25th to the 27th of June.

Porto
We reached Porto - Campanha on train by the noon. We got the andante card for 3 days (72 hours), so that we can freely travel around using the buses, metro, and the funicular. We could check in by 2 pm. We reached Trindade, by metro, and started walking to Aliados, and to Sao Bento, along the yellow line of Metro, visiting all the interests on our way. It seemed like all the cultural heritages of Porto are clustered between Aliados and Sao Bento. Having the lunch at Sao Bento, we took the metro to the station Marques, and checked in at Tropical Residences. The evening trip included a visit to Jardim do Morro in the yellow line. Unlike Lisbon, the metro in Porto was sometimes sharing the roads with the traffic, as it was going on the ground at some places. This was often imposing delays in the metro journey, and slow downs, unlike the uninterrupted underground metro of Lisbon. The bright side of this was, we were able enjoy some sceneries on our way, unlike the complete darkness of Lisbon. Unlike Lisbon, and similar to Barcelona and Madrid, the metro was going from left to right, and many lines shared the same platform in many stations, making the journey a bit more complicated for the first timers.

Rio Douro
Rio Douro and Ponte Dom Luis I
The cruise on the Douro river was remarkable for the 50 minutes, for the 10 Euro paid. It also included a free tasting of a chosen port from white, rose, ruby, or tawny, in a port cellars in Vila Nova de Gaia. We went towards Taylor's, which is one of the most popular ports. However, it was closed when we reached, as they close by 6 pm, except for the restaurant. We walked to the other side (Porto/Sao Bento side) of the Douro River from the Gaia side (down from Jardim Do Morro), by walking over the lower deck of the Ponte Dom Luis1 bridge. The upper deck holds the metro line, where the lower deck accommodates the pedestrians and the traffic. Though Ribeira looks beautiful by the river from Jardim do Morro, the dinner was not that extra-ordinary. We have had much better in Lisbon for the same price. Since the funicular that connects Batalha top of the hill with the river side Ribeira, had already stopped when we returned, we had to climb ourselves, which was not that easy, considering the vertical path.

Matosinhos Beach
Seagulls in the Matosinhos Beach
The second day started by travelling towards Matosinhos in the blue line. Matosinhos Sul has a beautiful beach. Water was still cold, regardless of the warm summer, preventing us from having a bath or swim. However, we didn't fail to notice that many others were already in the water! After the beach we visited Casa da Musica and Bolhao. We had some drinks at the Majestic Cafe, one of the oldest cafes in Porto. We paid a quick visit to the Dragon Stadium (Estadio do Dragao). We did some window shopping at Boa Vista, which is full of shopping centres. Many of the shops were having good discounts, and from the first look, it seems we could even buy some clothes back home. Realizing the weight limit imposed on us by the flight carriers, I decided not to buy anything but food and drinks to consume at the moment. Since we had explored the yellow line on the first day and the blue line on the second day, we decided to explore the red, orange, violet, and green lines on the third day, which is supposed to be our last day in Lisbon. We noted that orange line has nothing that induces our interest, and violet was just connecting the airport. Compared to green line, red line is longer, and was going towards Povoa de Varzim and Vila do Conde by the river Ave. But unfortunately, a quick check to the website of the Porto metro revealed us that there is a national strike of metro, train, and buses.

Strike!
The funicular descending from Batalha
The third day had to start with an altered plan due to the strike. Metro was still running only in the city center with blue line and yellow line, with a lesser frequency. Having everything explored in the blue line, we decided to get back to the yellow line, checking out from the hotel before 1 p.m. This time we didn't miss the Funicular dos Guindais. It was interesting to travel up and down and very convenient. We sat by the river for a while, and got back to Sao Bento, visited Se, had lunch, and got back to Vila Nova de Gaia. The sun had already started to burn us. Since the train was not functioning for the day, we had to return using the Rede Expressos from Sao Bento to Sete Rios - Lisbon. Rede Expressos provides cheap tickets to the students. It was just 15 Euros, which was half the price of the train tickets in the second class, which costs 32 Euros. Though I hate strikes, I admired how the unions coordinated their strike in a national scale. We spent the rest of the time at the nearest Elcorte Ingles before returning to Lisbon. If we could compare our first day at Porto with the visit to Obidos, and the second day with Setubal, the third day was just like a visit to São Sebastião

Though we were enjoying the trip, we could not hide our tears, fearing the distance of a thousands of miles in the upcoming days. We have learned much more than Distributed Computing during our ten months of stay in Lisboa.

Friday, June 21, 2013

Lisbon - Week43

My posts at the zones, after a break!
[21/06/2013] - It has been a while since I wrote a weekly blog post on my stay at Lisbon. The last post was on Lisbon - Week29. Later I started writing fortnightly posts, or even once in three weeks, as I got busier with studies. As I have got some free time and content to write after the exams, here comes this weekly update.

Campo Pequeno
This week was full of movies, eating out, frequent drinks at the Hard Rock Cafe - Restauradores, varieties of hamburgers at h3 new hamburgology at Campo Pequeno, and some parties. I specifically enjoyed the movies at the Cinema City - Campo Pequeno. The City bar, adjoining the cinema city is very stylish and unique. It was unfortunate that I haven't watched any movies here previously, considering that Campo Pequeno is next metro station to the one close to my apartment (Saldanha), and also in a walking distance from my apartment. 

Llovizna
During this week, I managed to update my blog with some technical blog posts on Jikes RVM, something I researched for our AVExe group project. Most of these posts managed to get into the Architects Zone and Javalobby of DZone. I hope these posts will be of use for a bigger audience. Without the technical blog posts, recently my blog hits was facing a downfall. This helped me realize the readers of my blog.

Cherries!
In Sri Lanka, I have never enjoyed the cherries. It always has reminded me "Lama Panadol" (The Paracitamol brand made for the kids). However, I have started to enjoy the cherries in Lisbon. They are much fresher and sweeter here, naturally.

MMTk utility classes

Class Diagram of Counters
High Level Language Virtual Machines is a core topic of interest for the researchers who are into virtual execution environments. As an open source virtual machine released to 16 universities, as early as 2001, Jikes RVM has been a major drive for many researches. Garbage Collectors for the Jikes RVM are constructed by the framework known as the Memory Management Toolkit (MMTk). Key Compositional Elements in MMTk are utilities, policies, and plans. Apart from these, package org.mmtk.harness contains the MMTk harness test cases. Sanity checks are included in the package org.mmtk.harness.sanity. GcSanity is the collection sanity checker, that takes snapshots before and after a collection to ensure that the live objects after a collection are the same that exist before the collection. Further options are implemented in the classes of org.mmtk.harness.options. We have looked at policies and plans. In this post, we will look at the MMTk utility package, which implements the MMTk mechanisms.

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. Allocation
The package org.mmtk.utility.alloc handles the allocation. Allocator is the base class providing the basis for the processor-local allocation. This provides the retry mechanism, to prevent the slow-path allocation causing a garbage collection, violating the assumption of uninterruptibility. Allocator also ensures that requests are aligned according to requests. This class is very crucial in garbage collection as the base class for all the allocator algorithms. Improper handling of this will make it hard to trace the bugs, where allocations may cause a garbage collection, or a garbage collection may immediately follow an allocation.

The method alignAllocation() accepts a region to be aligned, and aligns up the request, according to the requested alignment and offset, optimizing with the known alignment for the allocator algorithms. This method returns the aligned up address.

Consecutive allocation failure for the threads are counted by determineCollectionAttempts(). fillAlignmentGap() gets the start and end addresses, and fills the region with the alignment value. The minimum size guaranteeing the allocation of a given number of bytes at the specified alignment is calculated by getMaximumAlignedSize().

All allocators should use the final method,
allocSlowInline() for the slow path allocation. This method attempts the protected method allocSlowOnce() multiple times, which is defined in the subclasses. This method ensures safe execution by taking care of the thread/mutator context affinity changes, whilst allowing the collection to occur.

2. Bump Pointer Allocation
This is implemented by the BumpPointer class, which extends the abstract class Allocator. Bump Pointer scans through the allocated objects linearly. To achieve parallelism, this class maintains a header at a region of 1 or more blocks granularity. The minimum region size is 32678 bytes. Hence the 3 or 4 word overhead is less than 0.05% of all space. BumpPointer is initialized by providing the space to bump point into, indicating whether the linear scanning is allowed in the region. The method linearScan() performs a linear scan through the objects allocated by the bump pointer, and scanRegion() scans through a single contiguous region.

Intra-block allocation requires only a load, addition comparison and store, and hence is fast. The allocator will request more memory, if a block boundary is encountered. The scanned objects maintain affinity with the thread which allocated the objects in the region. This class relies on the supporting virtual machine implementing the getNextObject and related operations.

Space is allocated for a new object, by calling alloc(). This method is frequently executed, and is sensitive to the optimizing compiler. Whenever the bump pointer reaches the internal limit, allocSlow() is called. This method should never be inlined by the optimizing compiler, and hence is annotated with @NoInline, to force out of line.

Bump pointer can be re-associated to a different space by calling
rebind(), providing the new space to which the pointer to be associated to. The bump pointer will be reset such that it will use the new space for the next call to alloc().

Address
is a stub implementation of an Address type, used by the runtime system and collector to denote the machine addresses. An allocation unit is denoted as a card, which is marked by an address that lies within the card. Providing the address of the object creating a new card, the address that lies within the card, and the size of the pending allocation in bytes, createCardAnchor() creates a record, where the start of the card is relative to the start of the object. The start of the card corresponding to the given address can be retrieved by calling getCard(). Similarly, the address of the card metadata can be retrieved by providing an address from the card, calling getCardMetaData().

Next region from the linked list of regions can be retrieved using
getNextRegion(). Similarly, setNextRegion() is used to set the next region in the linked list. clearNextRegion() clears the next region pointer in the linked list.

The DATA_END address from the region header can be retrieved using
getDataEnd(), by providing the bump pointer region address. setDataEnd() is used to set the new DATA_END address from the header. Similarly, getRegionLimit() and setRegionLimit() return or store the end address of the given region, respectively. The lowest address where the data can be stored can be retrieved by getDataStart(), for the given region. updateMetaData() is used to update the metadata, reflecting the addition of a new region. Where a bump pointer region has been consumed, but the contiguous region is available, consumeNextRegion() consumes it and returns the start of the region satisfying the outstanding allocation request.

3. Block Allocation
Blocks are a unit of storage of 2 ^ n bytes, that are non-shared (thread-local) and coarse-grained. Virtual memory resource provides virtual memory space. Here, pages consumed by blocks are accountable for the memory resource. BlockAllocator implements various sizes of Block data structure. alloc() allocates a block and returns the first usable bytes of the block. A block is freed by calling free(). If the block is completely free, the block is returned to the virtual memory resource. Otherwise, if the block is just a sub-page block, the block is added to the free list.

4. GCspy Integration
GCspy 2.0 is a tool that helps to analyse the heap, that often is used to understand the memory usage and effectiveness of garbage collectors in our project. The development of GCspy however lags behind that of the Jikes RVM core [10]. The data for GCspy is gathered using gcspyGatherData() in the classes. The package org.mmtk.utility.gcspy contains the classes for the GCspy integration, and org.mmtk.utility.gcspy.drivers contains the GCspy drivers for the MMTk collectors.

5. Treadmill
Each instance of the Treadmill is a doubly linked list, where each node is a piece of memory. The words of each node,
[Forward Link | Backward Link | Treadmill | Payload ----->]
The Treadmill object must not be moved. Depending on the constructor argument, access to the instances may be synchronized.
 
This assumes that the implementation language, and the language being implemented are the same. This works well with Jikes RVM, as these are Java. However, for using with other VM implementations in other languages, the doubly linked list class, upon which Treadmill depends, should be rewritten.
 
If the created instance is to be shared between the threads, which is decided by the boolean parameter “shared” provided as a parameter in the constructor, the access will be synchronized with locks. A node is added to the treadmill during the allocation, using addToTreadmill().

6. Large Object Allocation
This is implemented in LargeObjectLocal, which extends the abstract class LargeObjectAllocator. Each instance provides a fast unsynchronized access to the treadmill, and bound to a single CPU. Hence this should not be shared across different CPUs, as they provide truly concurrent threads.
Given c CPUs, and t Treadmill spaces, there will be c * t instances of this class, for each {CPU, Treadmill} pair.

7. Page Resource
Allocation of pages for a space is managed by the abstract class PageResource. When a space request a page, page budget and the use of virtual address space are checked. If the request can not be satisfied, garbage collection is triggered. MonotonePageResource, which is a subclass of this class handles the monotonic space usage. Similarly, the other sub class, FreeListPageResource handles the ad hoc usage. Copying collectors allocate space monotonically before freeing the entire space. Hence, MonotonePageResource is useful for them. Though the MonotonePageResource is more restrictive, it is easier to manage.

8. Heap Growth Management
HeapGrowthManager observes the heap utilization and GC load, and grows and shrinks the heap size accordingly. This class, and all the other classes in the package org.mmtk.utility.heap contains the heap related mechanisms.

9. Sanity Checker
Sanity checks for the simple collectors are handled by the classes in the package org.mmtk.utility.sanitychecker. SanityChecker is the major class handling the sanity checking. SanityDataTable implements a simple hashtable to store and retrieve per object information on sanity checks.

10. Statistics
The package org.mmtk.utility.statistics contains a number of counters, implementing the abstract class Counter for multiple counting purposes. SizeCounter, aggregates two EventCounter objects, to count the number of events and the volume. Xml class writes the output in XML format.

11. Deque
Classes extending Deque
The package org.mmtk.utility.deque defines the doubly-linked, double-ended queue (deque). Though the double linking slightly increases the space demand, this is a worth trade off, as this provides an efficient buffer and operations such as sorting.
 
LocalSSB implements a local unsynchronized sequential store buffer. This is used in critical code such as garbage collection work queue and the write buffer used by many collectors. Hence, this is implemented as efficient as possible in space and time. Each instance has a bump pointer and a pointer to the sharedDeque. This class follows FIFO, though it doesn't implement dequeing. TraceBuffer supports enqueuing and dequeuing of tracing data and bulk processing of the buffer.
12. Log
Log class is used for trace and error logging. Message buffer size is intentionally kept large (3000 characters), as Lock class of Jikes RVM logs a considerable amount of information during a potential GC deadlock.