Tuesday, March 4, 2008

Customizable Closure with OpenJDK MLVM and javac

The customizable closure code listed below, take advantage of following,
  1. Closure data types are converted to inner classes at compile time.
  2. AnnonymousClassLoader in MLVM, allows us to load multiple definitions of same class in the same instance of the class loader at run time.
Code:
import java.dyn.AnonymousClassLoader;

public class CustomizableClosure {

static private {String => void} welcomeClosure =
{ String name => System.out.println(name + ", " + shortWelcome);};

static String shortWelcome = " Welcome to closure...";
static String detailedWelcome =
" Welcome to MLVM closure customization..Experience the power of AnonymousClassLoader...";

public static void main(String[] args) throws Exception {
CustomizableClosure.testSimpleClosure();
CustomizableClosure.testCustomizableClosure();
}

static void testSimpleClosure() {
System.out.println("=================");
System.out.println("Before customization..");
welcomeClosure.invoke("Dear bob");
System.out.println("=================");
}

static void testCustomizableClosure() throws Exception {
AnonymousClassLoader acl = new AnonymousClassLoader();

acl.setClassFile(welcomeClosure.getClass());
Class hostClass = CustomizableClosure.class;

Class acls = welcomeClosure.getClass();
acl.putSymbolPatch("shortWelcome", "detailedWelcome");
acls = acl.loadClass();

{String => void} obj = ({String => void}) acls.newInstance();
System.out.println("================");
System.out.println("After customization..");
obj.invoke("Dear bob");
System.out.println("================");
}
}
Output:

=================
Before customization..
Dear bob, Welcome to closure...
=================
================
After customization..
Dear bob, Welcome to MLVM closure customization..Experience the power of AnonymousClassLoader...
=================

OK, what's going on?
  1. {String => void} welcomeClosure = { String name => System.out.println(name + ", " + shortWelcome);} this closure snippet is converted to inner class at compile time.
  2. In method "testSimpleClosure", we are executing closure code as is.
  3. In method "testCustomizableClosure", we take closure (compiled inner class) as base template, customize it (by changing welcome text) at run time and execute it.
Step by step instructions on how to build and run Customizable Closure code.
  1. Build OpenJDK and Hotspot.
  2. Apply MLVM patch and rebuild Hotspot.
  3. Download javac for closures from javac.info
  4. Prepend MLVM AnonymousClassLoader.class and javac.jar to bootclasspath of java and javac. In my local machine, i used following commands for compilation and execution.
  • javac -J-Xbootclasspath/p:/share/software/OpenJDK/closures-2008-02-12/lib/javac.jar:/share/software/OpenJDK/mlvm/bootcp -source 7 -d classes/ CustomizableClosure.java
  • java -Xbootclasspath/p:/share/software/OpenJDK/closures-2008-02-12/lib/javac.jar:/share/software/OpenJDK/mlvm/bootcp -cp classes CustomizableClosure

    37 comments:

    Anonymous said...

    [B]NZBsRus.com[/B]
    Forget Sluggish Downloads With NZB Downloads You Can Quickly Search HD Movies, Console Games, MP3s, Software and Download Them @ Accelerated Rates

    [URL=http://www.nzbsrus.com][B]Usenet Search[/B][/URL]

    Anonymous said...

    Infatuation casinos? into this unripened [url=http://www.realcazinoz.com]casino[/url] advisor and spurious online casino games like slots, blackjack, roulette, baccarat and more at www.realcazinoz.com .
    you can also pore finished our untrained [url=http://freecasinogames2010.webs.com]casino[/url] guide at http://freecasinogames2010.webs.com and seize dedicated folding bread !
    another lone [url=http://www.ttittancasino.com]casino spiele[/url] district is www.ttittancasino.com , because german gamblers, rebel at authorization online casino bonus.

    Anonymous said...

    Message27, http://www.arlo.net/massacree/ buy viagra online, txmu0, http://www.arlo.net/fccgb/ viagra without prescriptions, pkrx3, http://www.arlo.net/fccgb/notes/ generic viagra online, yoyt1, http://www.arlo.net/bytes/ cheap viagra, olsj9, http://www.arlo.net/live/ viagra sale online

    Anonymous said...

    buy viagra online buy viagra super active - like viagra for women

    Anonymous said...

    generic viagra forum for generic viagra - where to buy viagra online us

    Anonymous said...

    viagra online without prescription is the viagra you buy online real - order viagra london

    Anonymous said...

    discount viagra buy viagra online us no prescription - viagra online from us generic

    Anonymous said...

    [url=http://www.onlinecasinos.gd]online casino[/url], also known as accepted casinos or Internet casinos, are online versions of commonplace ("chunk and mortar") casinos. Online casinos support gamblers to get ingredient in and wager on casino games from start to empty the Internet.
    Online casinos typically invite odds and payback percentages that are comparable to land-based casinos. Some online casinos contend higher payback percentages in the servicing of stake defender games, and some kind-hearted special-interest group payout consequence profit audits on their websites. Assuming that the online casino is using an aptly programmed unsystematically congregate generator, substance games like blackjack preoccupy an established forebears edge. The payout sculpt up on account of without looking at these games are established gone and forgotten the rules of the game.
    Uncounted online casinos take on in non-performance or get hold of their software from companies like Microgaming, Realtime Gaming, Playtech, Worldwide Shift Technology and CryptoLogic Inc.

    Anonymous said...

    buy soma online soma medication for migraines - buy soma online mastercard

    Anonymous said...

    cheap soma soma bras usanapolis - soma food trucks

    Anonymous said...

    buy soma soma drug breastfeeding - will soma show 10 panel drug test

    Anonymous said...

    top [url=http://www.001casino.com/]online casino[/url] brake the latest [url=http://www.realcazinoz.com/]casino online[/url] free no consign hand-out at the best [url=http://www.baywatchcasino.com/]www.baywatchcasino.com
    [/url].

    Anonymous said...

    buy cialis online buy cialis online legal - cialis daily basis

    Anonymous said...

    buy tramadol no prescription overnight tramadol for dogs cough - tramadol 50 mg is it a narcotic

    Anonymous said...

    generic tadalafil cialis 20 coupon - get cialis online usa

    Anonymous said...

    buy tramadol online tramadol dogs dosage dogs tramadol - tramadol hcl 50 mg migraines

    Anonymous said...

    buy tramadol online tramadol hcl 75mg - buy tramadol online in australia

    Anonymous said...

    generic xanax xanax junkie - is 1 mg of xanax a lot

    Anonymous said...

    generic xanax xanax overdose while pregnant - xanax bars

    Anonymous said...

    buy tramadol next day tramadol discount - tramadol withdrawal fatigue

    Anonymous said...

    aev doxycycline no prescription - buy doxycycline online http://www.doxycyclineonlinerx.net/#buy-doxycycline-online , [url=http://www.doxycyclineonlinerx.net/#doxycycline-antibiotic ]doxycycline antibiotic [/url]

    Anonymous said...

    buy carisoprodol carisoprodol usp 350 mg - carisoprodol generic for soma

    Anonymous said...

    cheap cialis 20mg ho comprato cialis online - cialis tolerance

    Anonymous said...

    20000 :) Buy Neurontin - buy gabapentin 300mg http://www.neurontinonlinecheap.net/#Buy-Neurontin, [url=http://www.neurontinonlinecheap.net/#Generic-Gabapentin]Neurontin 300mg[/url]

    Anonymous said...

    buy klonopin online klonopin wafers dosage forms - klonopin for depression

    Anonymous said...

    buy tramadol cod tramadol 50 mg for humans - tramadol dosage greyhounds

    Anonymous said...

    http://landvoicelearning.com/#74967 buy tramadol online without prescriptions usa - is ordering tramadol online illegal

    Anonymous said...

    http://landvoicelearning.com/#74967 buy tramadol online mastercard overnight - ordering tramadol online legal

    Anonymous said...

    http://landvoicelearning.com/#62431 tramadol buy online no prescription - ultram tramadol ingredients

    Anonymous said...

    klonopin mg klonopin side effects for women - klonopin anti anxiety

    Anonymous said...

    tramadol buy tramadol 100mg - tramadol online no prescription needed

    Anonymous said...

    klonopin no prescription klonopin withdrawal success stories - klonopin xanax high

    Anonymous said...

    http://www.integrativeonc.org/adminsio/buyklonopinonline/#8491 2mg klonopin compared 2mg xanax - 2mg klonopin suboxone

    Anonymous said...

    order tramadol online overnight tramadol withdrawal method - tramadol legal to order online

    Anonymous said...

    generic carisoprodol carisoprodol 350 mg tablets information - carisoprodol 350 mg picture

    Anonymous said...

    Researching for the best lender is obviously present fast financial loan approval, 6 months for you to 10 years. The lender can transfer your money in your bank account within One day. They need to come up with the particular deleveraging of the plan, and must function as the implementation of your program". instant payday loans uk It had become a thing with past to satisfy various difficult procedures to secure of cash after you needed badly!

    Anonymous said...

    So in lieu of strolling at a constant speed for say an hour,
    you would change items up by alternating short bursts
    of intense walking for say a minute followed by a recovery time period with
    slower strolling right after each and every extreme
    period. Just continue to keep alternating for
    20 minutes to start and add time as you grow to
    be far more match. It is possible to use interval education with all
    phases from thegreen coffee bean extract to enhance your success.


    Also once you do any kind of work out it is actually strongly suggested that you drink
    lots of water in advance of for the duration of and right after to maintain your whole body effectively hydrated.