Sunday, November 18, 2007

Compiling Firefox with tcmalloc

Here's how I compile firefox with tcmalloc to experiment if it helps with the fragmentation problem.

Follow the standard firefox build instructions here: http://developer.mozilla.org/en/docs/Build_Documentation

My .mozconfig:

. $topsrcdir/browser/config/mozconfig

# Options for client.mk.
mk_add_options MOZ_CO_PROJECT=browser
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/obj-@CONFIG_GUESS@

# Options for 'configure' (same as command-line options).
ac_add_options --with-pthreads
ac_add_options --enable-application=browser


Patch to disable zone allocator because I want it to allocate everything, even small objects, directly via tcmalloc. There's probably a better way, but this was quick and dirty.

Index: nsprpub/pr/include/private/primpl.h
===================================================================
RCS file: /cvsroot/mozilla/nsprpub/pr/include/private/primpl.h,v
retrieving revision 3.87
diff -r3.87 primpl.h
1867c1867
< #define _PR_ZONE_ALLOCATOR
---
> /* # define _PR_ZONE_ALLOCATOR */


Build command to link tcalloc in:

LDFLAGS=-ltcmalloc make -f client.mk build


To run with the heap profiler I do:

HEAPPROFILE=/tmp/firefox ./firefox


This creates heap dumps in /tmp like firefox.0001.heap. By default it does it whenever the usage increases by 100MB and when a total of 1G of objects have been alloced (regardless how much is still in use). See http://google-perftools.googlecode.com/svn/trunk/doc/heapprofile.html for which env vars to set to change this, as well as how to examine the heap in pprof.

I don't really have any results to report yet. It would be cool to figure out how to instrument something like the images Pavlov has created showing the fragmentation. It shouldn't be that hard to do with tcmalloc or a malloc wrapper. A malloc wrapper would make it easier to compare different implementations, but might be harder to implement without adding a lot of overhead.

Tuesday, March 06, 2007

Building JDK 7 from source on ubuntu feisty

  1. Download sources from http://jdk7.dev.java.net.

  2. Several additional ubuntu packages are required:
    • apt-get install sun-java6-jdk libasound-dev libcupsys2-dev xutils-dev m4 libxt-dev x11proto-xext-dev libxext-dev libxtst-dev libxi-dev libxp-dev libxmu-dev
    • Note: if it breaks because of a missing system header or lib, go to packages.ubuntu.com and search for the missing file to find out what package to install.

  3. I had to edit one Makefile to fix a compile error (will submit this patch to Sun).
    • vi j2se/make/sun/jdbc/Makefile
    • add -fPIC to the compile commands under the make_libs target (after $(CC))

  4. Copy resources from a previous JDK binary release because they aren't included with the source:
    cd jdk1.7.0-b07/jre/lib
    mkdir resources ; cd resources ; jar -xf ../resources.jar
    ( cd com/sun/java/swing/plaf/motif/icons/ ; cp *.gif ~/src/jdk/jdk7/trunk/j2se/src/share/classes/com/sun/java/swing/plaf/motif/icons )
    ( cd com/sun/java/swing/plaf/windows/icons ; cp *.gif ~/src/jdk/jdk7/trunk/j2se/src/share/classes/com/sun/java/swing/plaf/windows/icons )
    ( cd javax/swing/plaf/metal/icons ; cp *.gif ~/src/jdk/jdk7/trunk/j2se/src/share/classes/javax/swing/plaf/metal/icons )
    ( cd javax/swing/plaf/metal ; cp -r sounds ~/src/jdk/jdk7/trunk/j2se/src/share/classes/javax/swing/plaf/metal )
    ( cd ../lib ; cp -r audio ~/src/jdk/jdk7/trunk/j2se/src/share/lib )
  5. Create build-linux.sh script:
    #!/bin/sh
    export ALT_BOOTDIR=/usr/lib/jvm/java-6-sun
    export ALT_DEVTOOLS_PATH=/usr/bin
    export FULL_VERSION="$(basename $(pwd))-$(date +'%Y''%m''%d''.''%H''%M')"
    export HOTSPOT_BUILD_JOBS=2
    export PARALLEL_COMPILE_JOBS=2
    cd control/make && /usr/bin/make MAKE_VERBOSE="" ECHO="echo" dev
  6. time ./build-linux.sh

  7. Go get lunch

  8. If it works, you should have a jdk in control/build/linux-amd64 (or linux-i386 depending on your platform)

  9. Run bin/java -version:
    java version "1.7.0"
    Java(TM) SE Runtime Environment (1.7.0-internal-fastdebug-kellyc_06_mar_2007_22_32-b00-fastdebug)
    Java HotSpot(TM) 64-Bit Server VM (build 1.7.0-internal-fastdebug-kellyc_06_mar_2007_22_32-b00-fastdebug, mixed mode)

Wednesday, January 10, 2007

my iPhone thoughts

Several other folks have been blogging about the iPhone, but so far it seems to be all gushing praise, and yes, alot of that is deserved. It's a beautiful product, as Apple almost always produces. As for some of the lacking features (3G), yes, Apple should have added those, but remember this is a first gen product. Does anyone remember the first gen iPod? You have to make tradeoffs and pick features in a first gen product.

There are a few things I think they missed though, and some nagging questions which their marketing materials don't answer yet:
  1. One handed operation? One of the key advantages I see for blackberry users is the scroll wheel. I do not have a crackberry, but when I have checked them out, that is really the killer feature, not the full qwerty keyboard. Most people read alot more email than they compose on it.
  2. Replaceable battery? C'mon Apple. You've dealt with enough iPod battery problems that you should have a clear answer for that issue on this product. Who is going to want to send in their primary means of communication to get a battery fixed for a couple weeks?
  3. Charging, especially mobile. I have an iPod nano, and I don't think the connector is particularly easy to connect normally (figuring out if it's right side up from a screen printed icon is not the best, especially if the icon has worn off). With my motorola phone (non-Razr) I can pretty much plug it into the charger in my car single handed without looking, something very nice if I'm on a call and it does the low power beep. I suppose they expect you to dock it in your car before you start driving. Similar for unplugging it. When I'm trying to catch a train to work, I want to be able to unplug my phone single handedly without looking.
  4. What kind of CPU? I know it runs macos X, but what kind of horsepower does it have?
  5. I'm sure the screen will get smudged up especially holding it up to your ear.
  6. How much non-talk time battery life is there? Especially if you use it for video playback?
I expect the 2nd gen iPhone to already be in the works and probably ready for release by the end of the year or Q1 2008. I don't remember how long it took for the 2G iPod to come out, but like the iPod this is a revolutionary product that will continue to evolve into something better. I love the nano so much more than my old 2G iPod, so I'm looking forward to the 3rd and 4th gen iPhones (and what nokia, etc. do to answer it)