«
February 2006
»
Soft References
The second Jeroen Frijters post that caught my attention this week mentioned soft references in Java. I posted about .NET weak references a long time ago but I'd not read about soft references which Java, and not .NET, has. The concept is similar except that whereas objects referred to by weak references can be reclaimed at the next garbage collection, those referred to by soft references survive garbage collections and are only reclaimed if memory is low. The Java 2 spec does not define exactly when objects with soft references will be reclaimed:
... no constraints are placed upon the time at which a soft reference will be cleared or the order in which a set of such references to different objects will be cleared. Virtual machine implementations are, however, encouraged to bias against clearing recently created or recently used soft references.
However the garbage collector is required to clear all soft references before it can throw an OutOfMemory exception.
Jeroen describes how IKVM.NET supports soft references:
Since .NET has no soft references and there is no way to determine if the managed heap is running low, I used a hack to always promote objects referenced by a soft reference to generation 2 and from there on treat them as weak references, which effectively means they will be collected the next time a full GC is run and there are no more strong references to the object.
VMWare Server Memory Management
A couple of posts by Jeroen Frijters caught my attention this week. The first was on the Win Tech Off Topic list. Jeroen pointed to a paper(pdf) by VMWare employee Carl Waldspurger which describes a technique for sharing pages of memory which have identical content, either similar pages within a single guest OS or similar pages across multiple guests OS's running under a single host. VMWare server scans pages in use and generates a 64-bit hash based on their contents. The hash value is used as a lookup key into a hash table for other pages that have already been scanned. If a match is detected a full comparison of the pages is then made in the extremely unlikely chance that pages with different content have the same hash value. A copy-on-write policy is then followed with only a single copy of the page being held in memory, until one of the guest OS's writes to the page in which case a fault is generated and a separate copy of the page is created for the guest OS writing to the page.
There are more details about this and other techniques in the Waldspurger's paper. Page sharing is non-invasive as far as the guest OS is concerned, whereas "ballooning" requires the installation of a driver in the guest OS. The driver communicate with VMWare server via a private channel and is used when VMWare wants to reclaim memory from the guest OS: the balloon driver allocates pinned pages with the guest OS causing the latter to page memory out to its own virtual disk. VMWare can then reclaim the corresponding machine page. The balloon driver polls VMWare once a second to query what action it should take. If the guest OS requires more memory, the balloon is "deflated" by freeing the pages that the driver had allocated.
imeem, Mono, and Mac OS X
Yesterday I installed a Mac client - imeem - which uses Mono. The snapshot here is from Kevin Lim's blog where he posted about the imeem Mac beta a few weeks ago. I came across imeem via a post by Miguel de Icaza in which he links to an interview with imeem founders Jan Jannink and Dalton Caldwell on Apple's Developer Connection site. Unfortunately I can't actually do much with the imeem client at the moment because unlike the Windows version the Mac beta does not support AIM, Yahoo, MSN, and GoogleTalk accounts and I don't know anyone on imeem.
Its unclear exactly how much of the Mac client is implemented in Mono. They implemented an open-source Mono/C# <-> Cocoa/Objective C bridge called Dumbarton after failing with Cocoa#.
Width-based layout
I moved my sidebar to a separate page to make enough room for wide blog posts without requiring a very wide browser window. Colly Logic uses a width-based layout which positions the third column according to the width of the browser window.
Blog on windbg and SOS
John Robbins points to Tess Fernandez' blog If broken it is, fix it you should. To quote Tess:
This blog is intended to help people that develop applications with the .net framework resolve issues on production system, mainly using Windbg.exe from http://www.microsoft.com/whdc/devtools/debugging/default.mspx along with sos.dll that ships with the debugging tools.
SOS - Son of Strike - is a debugger extension for debugging .NET problems. For an overview of .NET debugging there's the .NET Debugging Facilities(zip) presentation by Brian Long on the DevelopDeveloperDeveloper site.
CSS Overflow Property
One of the reasons I've got rid of the right-hand column in this blog and moved to a fixed width is to provide more space for code fragments so that I can have up to 80 characters per line, the line length I normally code to, without having to worry about how the reader resizes their browser. This works until the reader increases the browser text size. Then the <pre> text will overflow rightwards in different ways according to the browser, the ugliest way being when the text bleeds out of its container.
The solution is to use the CSS overflow property. The implicit default value of this is that the text is rendered outside the block, as I mentioned above. The "scroll" overflow setting, which displays a scrollbar, is useful for when the text overflows but the scrollbar appears even when the text does not overflow, which doesn't look right. Unfortunately the setting we want here - scrollbar appearing only when text overflows - is not guaranteed to be available: "The behavior of the 'auto' value is user agent-dependent, but should cause a scrolling mechanism to be provided for overflowing boxes". Firefox and Safari display a scrollbar but unsurprisingly IE6 and IE7 beta 2 do not.
For example, this code fragment:
public class Foo
{
public static void Main()
{
Console.Writeline("This will overflow block when text size increased.");
}
}
will look like this in Firefox when the browser text size is increased: