When we build project for clients based on number of open source libraries, we typically look into licensing policy of each open source library and analyze how well they fit with client policies. While analyzing one such policy of open source library, I was asked by my colleague what was the interesting licensing policy you have come across?, without second thought i replied back, policy of SQLite. Here is extracted license text from SQLite
“ The author disclaims copyright to this source code. In place of a legal notice, here is a blessing:
May you do good and not evil.
May you find forgiveness for yourself and forgive others.
May you share freely, never taking more than you give. “
Isn't it interesting?.
Wednesday, March 26, 2008
Tuesday, March 4, 2008
Customizable Closure with OpenJDK MLVM and javac
The customizable closure code listed below, take advantage of following,
=================
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?
- Closure data types are converted to inner classes at compile time.
- AnnonymousClassLoader in MLVM, allows us to load multiple definitions of same class in the same instance of the class loader at run time.
import java.dyn.AnonymousClassLoader;Output:
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("================");
}
}
=================
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?
- {String => void} welcomeClosure = { String name => System.out.println(name + ", " + shortWelcome);} this closure snippet is converted to inner class at compile time.
- In method "testSimpleClosure", we are executing closure code as is.
- In method "testCustomizableClosure", we take closure (compiled inner class) as base template, customize it (by changing welcome text) at run time and execute it.
- Build OpenJDK and Hotspot.
- Apply MLVM patch and rebuild Hotspot.
- Download javac for closures from javac.info
- 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
Wednesday, February 13, 2008
AnonymousClassLoader in OpenJDK Mlti-Language VM (MLVM)
When we implement JIT interpreter for dynamic languages on JVM, we typically deal with set of data (Environment) and Operations (Methods, Lambda etc).
Design and loading of class definition for data and operations on JVM, has following challenges (pains),
a) We can't define a light weight / anonymous methods in JVM on the fly.
Method definition must live in a class. (Relationship between class that defines method and data could be composition or inheritance).
b) We can't load multiple class definitions of same class / overwrite previously loaded class definition with new one, in the same class loader.
Class loader keeps track of all loaded class in its System Dictionary. When we try to reload class definition (even though class definition is changed after first load), class loader checks for any entry in System dictionary for a given class name. If so, it will return class definition of system dictionary entry.
To circumvent above issue, we instantiate (custom) new class loader every time when class definition changes.
c) Garbage collection issue
Class loader is another Java class in JDK. When a class (Let's call host class) instantiates our custom class loader; say CL1, class loader of host class (could be system class loader or ext class loader or another custom class loader) can reach CL1 class loader. Make sure custom class loaders like CL1 are eligible for GC (there by all classes loaded by that class loader) when they are no longer useful.
OpenJDK Mlti-Language VM, introduces java.dyn.AnonymousClassLoader that alleviates above pain points,
1) No System Dictionary in AnonymousClassLoader and AnonymousClassLoader is independent of existing class loaders in JDK. (Refer AnonymousClassLoader.java)
2) We can load multiple definition of same class using same instance of AnonymousClassLoader and it is responsibility of the user to choose preferred class definition among loaded class definitions to create instance. (Refer testAPI method of DVMTest.java)
3) Classes defined by AnonymousClassLoader are not reachable by class loader of host class. Making not-in-use class definitions available for GC is simple.
Above points are not theory, we have tested and working prototype ready. If you want to try yourself, refer my previous post on building MLVM.
QR code for building MLVM :
Design and loading of class definition for data and operations on JVM, has following challenges (pains),
a) We can't define a light weight / anonymous methods in JVM on the fly.
Method definition must live in a class. (Relationship between class that defines method and data could be composition or inheritance).
b) We can't load multiple class definitions of same class / overwrite previously loaded class definition with new one, in the same class loader.
Class loader keeps track of all loaded class in its System Dictionary. When we try to reload class definition (even though class definition is changed after first load), class loader checks for any entry in System dictionary for a given class name. If so, it will return class definition of system dictionary entry.
To circumvent above issue, we instantiate (custom) new class loader every time when class definition changes.
c) Garbage collection issue
Class loader is another Java class in JDK. When a class (Let's call host class) instantiates our custom class loader; say CL1, class loader of host class (could be system class loader or ext class loader or another custom class loader) can reach CL1 class loader. Make sure custom class loaders like CL1 are eligible for GC (there by all classes loaded by that class loader) when they are no longer useful.
OpenJDK Mlti-Language VM, introduces java.dyn.AnonymousClassLoader that alleviates above pain points,
1) No System Dictionary in AnonymousClassLoader and AnonymousClassLoader is independent of existing class loaders in JDK. (Refer AnonymousClassLoader.java)
2) We can load multiple definition of same class using same instance of AnonymousClassLoader and it is responsibility of the user to choose preferred class definition among loaded class definitions to create instance. (Refer testAPI method of DVMTest.java)
3) Classes defined by AnonymousClassLoader are not reachable by class loader of host class. Making not-in-use class definitions available for GC is simple.
Above points are not theory, we have tested and working prototype ready. If you want to try yourself, refer my previous post on building MLVM.
QR code for building MLVM :
Sunday, February 3, 2008
Building OpenJDK Multi-Language VM aka The Da Vinci Machine
Life is more exciting with multi-language support on JVM. Recently john rose @ sun, created patch for loading anonymous classes in the VM ( read carefully, we are not talking about anonymous classes in JDK, we are talking about loading anonymous classes at VM level ). JVM wouldn't not allow someone to change structure of a class once it loaded. Though this security feature brings-in stability to JVM, dynamic language implementors for JVM are forced to write lots of boiler plate code to simulate dynamism on top of JVM (Ex: In Ruby, methods can be added, removed, modified at runtime, even class structure can be changed @ runtime too). The recent patch added by john for OpenJDK allows us to load an arbitrary class from a block of bytecodes and associate the new class with a pre-existing host class, inheriting its access, linkage, and permission characteristics. Very interesting thing is, a block of bytecodes can be template class file and this template class can be customized at runtime using various constant pool patching methods in java.dyn.AnonymousClassLoader, just before loaded by AnonymousClassLoader class loader. This patch not only alienate pain of other language implementers to a greater extent but accentuate complete JDK and Hotspot with new way of loading and linking anonymous classes in JVM, thereby opening up developers mind in yet another innovative direction. Read john's blog on anonymous classes in the vm for more details on this feature. Pretty exciting ha?, Wanna try it out yourself?. Here is the step by step instruction for applying multi-language path to Open JDK Hotspot VM and building mlvm aka The Davinci VM.
If you haven't successfully built Open JDK and Hotspot VM, go through simonis blog on building Open JDK and hotspot on linux. Once you successfully built OpenJDK and Hotspot, follow
below instructions for building and running mlvm,
http://homepage.mac.com/rose00/work/webrev/6653858/anonk.patch
http://homepage.mac.com/rose00/work/webrev/6653858/DVMTest.zip/jdk7/hotspot
patch -p1 --backup-if-mismatch < /home/tselvan/mlvm/patches/wkk.patch
patch -p1 --backup-if-mismatch < /home/tselvan/mlvm/patches/anonk.patch LANG=C \
ALT_BOOTDIR=/share/software/jdk1.6.0_04/ \ HOTSPOT_BUILD_JOBS=1 \ ALT_OUTPUTDIR=../../build/hotspot_debug \ make jvmg 2>&1 | tee ../../build/hotspot_debug.log chcon -t texrel_shlib_t /share/software/OpenJDK/jdk7/build/openjdk_full_debug/lib/i386/*.so
chcon -t texrel_shlib_t /share/software/OpenJDK/jdk7/build/openjdk_full_debug/j2sdk-image/jre/lib/i386/*.so export PATH=/share/software/OpenJDK/jdk7/build/openjdk_full_debug/bin:$PATH
export JAVA_HOME=/share/software/OpenJDK/jdk7/build/openjdk_full_debug Unzip DVMTest.zip, ( i have locally unziped to /share/software/OpenJDK/mlvm)
Run Make.sh
java -esa -ea -Xbootclasspath/p:/share/software/OpenJDK/mlvm/bootcp -cp /share/software/OpenJDK/mlvm DVMTest
If you like to have discussion on mlvm, leave your comments or lets catch up during DevCamp. Watch this space for more experiment with mlvm in coming weeks.
If you haven't successfully built Open JDK and Hotspot VM, go through simonis blog on building Open JDK and hotspot on linux. Once you successfully built OpenJDK and Hotspot, follow
below instructions for building and running mlvm,
- Download mlvm paths and related files
http://homepage.mac.com/rose00/work/webrev/6653858/anonk.patch
http://homepage.mac.com/rose00/work/webrev/6653858/DVMTest.zip
- Applying patchs
Build OpenJDK Hotspot VM
ALT_BOOTDIR=/share/software/jdk1.6.0_04/ \ HOTSPOT_BUILD_JOBS=1 \ ALT_OUTPUTDIR=../../build/hotspot_debug \ make jvmg 2>&1 | tee ../../build/hotspot_debug.log
Give necessary permissions to libjvm.so under linux,
set PATH and JAVA_HOME
Running sample mlvm program
Sunday, August 12, 2007
Static Language Runtime
Disclaimer: ** Just for fun**
Sunday, July 22, 2007
My Small Observations as DEV
- Production Environment: Is a place, where only limited people are allowed to make mistakes.
- Java Dev's belief
- Carl Sagan : Number of stars is more than sum of all grains of sand on all beaches in earth.
- Java Dev's belief : Number of java frameworks should be more than number of stars.
- It is not very difficult to master a framework compared to understanding the fundamentals.
- Every offshore vendor has two kinds of developers,
- 1) Excite about technology, innovate at work, and generate revenue for the company
- 2) Work at Center of Excellence and/or Technology practice
- The only benefit of CMM certification is exercised at first by every offshore vendor when things go wrong in a project. "Blame process at client end". It was difficult to find reason(s) for a failure when client too CMM certified. Solution? Have more certifications apart from CMM. Execution capability of offshore vendor grows with number of certification it acquires.
Subscribe to:
Comments (Atom)