10.26.05

Java Bytecode BCEL vs ASM

Posted in PL Research at 3:25 pm by site admin

My research on the NextGen Generic Java Compiler has progressed on to supporting mixins. A Mixin is a parametric class that extends its parametric type parameter, for example “Mixin extends T”. One advantage of Mixins is that they provide an abstract mechanism to specifiy uniform class extensions. For example I can define a class TimeStamped<T> that can extend any given class, provide additional functionality, but still preserve the same functionality as its parent.

One of the most interesting issues with Mixins in Java concerns what kind of mechanism is used to instantiate Mixins. In Java, there is no uniform way to instantaniate classes. As a result, it is not straightfoward to create a Mixin that satisfies all the possible constructor types in its super class. In otherwords, the set of constructors must be determined based on its parent class.

Now with that basic introduction, I would like to discuss how I create a Mixin instantiation. Basically, I take a Mixin template and instantiate with respect to its parent class. Wihle this process is a straightfoward “fill-in the holes”, the main difficulty I have encountered is preserving the constructor methods. What I needed to do was create a constructor in the sub class for each constructor in the parent. In addition to “bridging”, the constructor must initialize any additional state from the template. Now to do this I would normally use BCEL. However, I know development on BCEL has waned. So I did some research and discovered that it is kind of in maintence mode. In the mailing list I found a Comparison between ASM and BCEL, as well as a few other comparisons between ASM, BCEL, JavaAssist, etc. On the ASM homepage, they boast a 700% performance gain over BCEL. This seemed too good to be true, so I decided to test the performance of ASM vs BCEL in my task of creating Mixins. I am providing a copy of my source asm_vs_bcel.tgz.

Now my simple test shows that ASM is about 350% faster than BCEl. My test does the following:
1. read both the Mixin template and the new super class (used for the mixin)
2. Parse out the available constructors in the parent
3. Use the init method found in the mixin as a template to generate the appropriate ‘bridge’ constructors found in 3. After each super call, I then append all the remaining initialization necessary for the mixin (found in the mixin’s init method)
4. Write out the newly instantiated class.

The bcel code follows a very procedural methodology. While there are some annoyances resulting from using JavaClass vs ClassGen and Method vs MethodGen, a top-down read can easily explain the method.

Now the ASM code is different. At first the ASM Tutorial did not seem to stick. It is however, very correct. The two intersting points of ASM are:

* ASM works through a series of visitors.
* ASM follows a SAX model for traversing a java class.

So a ClassVisitor works through a series of sequential calls:

visit [ visitSource ] [ visitOuterClass ] ( visitAnnotation | visitAttribute )* (visitInnerClass | visitField | visitMethod )* visitEnd.

Thus to perform any code manipulation, it is necessary to define a new ClassVisitor (and probably MethodVisitor). The ASM developers have conviently provided a ClassAdapter and MethodAdapter to faciliate development. Now the use of Visitors in Java is not very new. What is kinda weird is how the SAX-ish design of ASM plays in to everything. For example, to parse a class, the class reader must accept a subclass a ClassVisitor, namely ClassNode. ClassNode represents a class tree in ASM. Naturally, ClassNode also has an __visit__ method for ClassVisitors.


ClassReader super_cr = new ClassReader(super_class);
ClassNode cn = new ClassNode();
super_cr.accept(cn, true);

And then to add a method to parsed tree, I follow a similiar pattern:

newMethod.accept (cn);

Check out the provided source code if you are interested in how ASM code and BCEL code compare, or simply need an example how to write a small class transformation using either of these two languages. For my purposes, ASM is faster and smaller and thus is my choice for the job. I will however, be performing future metrics comparing ASM, BCEl, and also down and dirty manual byte hacking for the purpose of changing the Constant Pool. The issue of course, is that ASM does not provide direct access to the constant pool. The ASM SAX model seems cumbersome, and unintuitive, in this case. I leave this task for another day.

08.17.05

Creatures of habit

Posted in health, PL Research at 5:22 pm by James

I have been busily working on my research for the NextGen Generic Java compiler. I have spend the last couple days starting on this paper for SAC 2006. I was reviewing the list of type dependent operations supported by NextGen. In particular, I was double checking if NextGen currently handles casting correctly. I proceeded to create the following test case:

public class A {
   static class Box < T> { }
   public static void main(String[] args) {
        Box < String> s = new Box< String>();
        Box< ?> a1 = (Box< ?>) (Object)s;
        Box< Object> a2 = (Box< Object>) (Object) s;
    }
}

After executing this code, I inspected the resulting bytecode and discovered that casting was not working properly. So after some fiddling, I found the segment of code I need to modify. At the top of this section, I also found the following comment:


//TODO: cant cast Object to Box< String>
//will need to fix this case to support
//generic casts

So I’ve returned to fix a problem that I had skimmed over before, using the same basic names and types. Well I guess I like using Box< T> as an example. Still kinda funny though.

01.18.05

Paying for the name….

Posted in PL Research at 7:07 pm by James

I found this article on slate about Who Needs Harvard?. Basically talks about how the percentage of Ivy League graduates are declining in US corporations. They attribute this to both the improvement of other schools and also the necessity of the rich to work.

My 2c is that the these days there is a extreme level of diversity among different fields. A small private university cannot offer a premier education for the great diversity in careers. On the other hand, larger public universities not only have the critical mass to offer specialized education in many diverse fields, but also can pool the resources necessary for each field.

A professor at school told me that university is derivied from the two roots: “uni” means everything, and “versity” meaning knowledge. What he was trying to tell me is that in a university, you have to learn a little bit of everything. I can see how this applies in a specialized sense. For example, learning computer science is ok, but if you have the opportunity to learn CS and business, or CS and something else, it gives you a better level of understanding how one topic of knowledge can relate to others.

10.12.04

Lazinyess is a Virtue

Posted in PL Research, Religion/Philosophy at 1:10 pm by James

Lazyiness pays off. Yesterday, my advisor Corky casually mentioned a Professor would be coming to Rice today. He casual asked if i wanted to meet with him, and I casually responded ok. Today i was busy working on my research. I checked my email at 2pm and found out that I was scheduled a appointment at 11:45 (without my knowledge… so much for casual). So I hurried home to eat lunch and then to school to make a presence. Turns out the visitor arrived late and the whole schedule was out of wack. So I didnt miss anything, didnt piss any one off, and i was actually basically on time for the guys presentation. And now I think it would matter even if i missed the presentation… not as formal as it was beginning to seem. Score 1 for casually late.

09.03.04

Attack the Attack

Posted in Daoism, health, PL Research, Religion/Philosophy at 2:49 pm by James

Wing Chun is not just a martial art, its a way of life. The foundations of Wing Chun are rooted in daoist philosophy. One of the precepts of Wing Chun is the notion of “Attack the Attack”. So in fighting this means to always stay on the offensive and never think defensively. This doesnt mean that you should trade punches or just take hits. What this means is to think offensively and always look for openings.

I kinda get this, yet I don’t. But now, I’m getting there. I am a teaching assistant for a class at school. I had to sit and listen to a Professor tell me to (1.) Do all the class assignments by myself to have an answer key ready for the class, (2.) That after I finished, he didnt think what I did was correct, and (3) When I explained to him why, he basically told me what I was doing (which was logical) was wrong, and to add a little bit of icing on the cake (4) That I was to grade everything (grading is a bit automated, but that doesnt mean its a walk in the park). So after all of this, I was a bit bummed out.

So before our next meeting (with the other 2 teaching assistants presents), I did my homework. I talked it over with my advisor, and got these issues straightened out. He told me everything I was thinking was right. So I walked into the meeting with my plan.

Prof: So can TA #1 you can help with the grading. Wait you only know Java.
TA #1: And Scheme. but theres only 1 group.
Prof: Ok well thats about half. That might be ok
Me: We really should split the grading evenly. He needs to be familiar with all the different languages because someone might ask him for help. [Attack the Attack!]

Me: Well we also need to talk about the datatypes that are in question
Prof: Well we can do that just between the two of us
Me: I think everyone here should know.. just in case there are questions.. (everyone is a teaching assistant) [Attack the attack!]
Prof: Ok, does everyone want to work on it?
Everyone: Ok.

Then while we looked at the stuff, I made my points, and sat back and let the other TAs support my claims.

“Attack the attack” is a very subtle technique. I think it requires:
1. Objectives
2. Preparation
3. Subterfuge

08.16.04

Python Paradox

Posted in internet, linux, PL Research, Unfiled at 8:48 pm by James

I like the sound of that.. Well its not really much of a paradox.. While python is not a language pressed by the education system, it does have its home in the land of scripting, the web, and unix. And it does have a more theoretical basis… lambda! I use python a decent amount. However, for me its a struggle between python and php (with the stabilization of php-cgi). Because the Python db 2.0 APIs are too Java-ish, i prefer php for all my more complex tasks. php has the ability to get results in associative arrays, uses ” for empty string and null. I can deal with ‘None’ popping up everywhere, but I gotta have associative arrays. I just cant see myself doing row[ 23 ] and being correct. I stand corrected!! ADOdb for python! Here is the full article.

04.07.04

Nextgen Compiler Model Constraints

Posted in PL Research at 9:21 am by James

A java compiler must follow the existing Java Compiler Model:

1. Write once, read most places
2. Modular compilation
3. Compilation of child classes cannot affect parents
4. Compilation of parent classes may break child classes
5. Two steps: compilation & execution

04.16.03

javac compiler and visitor pattern issues

Posted in PL Research at 6:24 pm by James

I’m currently trying to augment the java compiler to support auto-boxing of primitives. The problem I’m currently facing is that there is no OO way to mutate objects in the visitor pattern. In the visitor pattern, you can call obj.visit(this), and then it will call the appropriate method. Once inside this method, its impossible to mutate the type of the parameter you have passed in. This is an inherent benefit/problem with recursive decent design. So of course the correct approach is to modify the code one level up. However, the design of sun’s java compiler doesnt make this easy without a moderate amount of modification to the code.

03.03.03

Currrent Java Research Interests

Posted in PL Research at 3:43 pm by James

This semester in school I will be researching the following: 1) Getting up to speed with JavaPLT’s nextgen compiler, and 2) exploring mechanisms to unify the java type system.

The other ideas currently on the back burner is type inference of java byte code. For this I was thinking about using the becl library.

order generic Flomax online download zen v plus software discount mountain software buy generic Prednisone online windows xp live eddition pdf creator prtable purchase online prescription Lasix without buy autocad software accounting software pricing sas software clinical trials price cheap wp x3 software cheap internet security software ipaq software downloads buy rtg software final cut software download student price language software download software for making price comparison chart buy software at academic prices discount financial software pda software download online purchase prednisone 40 mg Lasix diskwarrior software download xenical online perscription xenical non rx fedex overnight free Zithromax non prescription for next day delivery Maxalt espana order generic Maxalt Zithromax cheap mexican where to purchase Valtrex no prescription no fees buy Valtrex from india no prescription valtrex with fedex valtrex propecia online gt buy valtrex tablets (no prescriptions needed for Buspar|buy Buspar with no prescription|online pharmacies Buspar|Buspar cheap|buy Buspar without rx|purchase rx Buspar without|Buspar purchase online|purchase Buspar online without rx|purchase Buspar free consultation|buy Buspar Online|buy Buspar american express|buy Buspar Online|buy cheap Buspar with dr. prescription|Buspar side effects|fedex Buspar without priscription|overnight Buspar without a rx|order cheap overnight Buspar|Buspar toronto|uk order Buspar|Buspar no doctors prescription|Buspar mexico|Buspar order|no prescription Buspar with fedex|order generic Buspar|buy Buspar without rx from us pharmacy|prezzo Buspar|Buspar 10mg|Buspar from canada|purchasing Buspar without a script|buy Buspar australia|purchase Buspar visa without prescription|online purchase Buspar|buy Buspar no perscription cod|buy Buspar drugs|buy Buspar with visa|buy Buspar without rx needed|buy Buspar without prescription|buy Buspar no prescription low cost|purchase buy Buspar in the uk diskeeper2010 pro premier can you buy synthroid from boots buy cheap Nolvadex cod buy synthroid synthroid mumbai generic Nolvadex online buy Nolvadex in internet mastercard in Kentucky Stanton buy Accutane with without rx Accutane 20mg mexico delivered zithromax purchase zithromax without prescription pay cod zithromax overnight delivery fed ex buy zithromax paypal without rx cheap zithromax next day shipping overnight zithromax without a rx zithromax No Prescription Overnight COD Delivery buy Nolvadex 10 mg buy zithromax overnight fedex zithromax Cheap C.O.D buy 20mg Nolvadex fast delivery Nolvadex without persription where can i buy Nolvadex without a rx free Nolvadex purchase Nolvadex pay pal online without rx order Paxil cheap overnight cheap Paxil no rx buy Paxil online cod order Paxil amex online without prescription Paxil online overnight delivery cod Paxil from canada Paxil non rx fedex overnight free buy discount Paxil online buy Paxil mastercard buy Paxil without rx Paxil u.p.s shipping cod order cheap overnight Paxil purchase cheap Paxil cod free fedex cheapest Paxil available online how to order Paxil online without a prescription purchase Paxil without rx needed buy prednisone amex online without rx buy prednisone 40 mg on-line prednisone delivered overnight fedex prednisone overnight without a rx purchase prednisone without prescription to ship overnight watson prednisone cod overnigh how to buy prednisone online without a rx prednisone cheap overnight fedex buy no perscription prednisone prednisone no rx needed where to buy generic prednisone online without a rx online accutane buy 40 mg prednisone fast delivery prednisone with cod purchase cheap Flomax online buy Lasix pay cod apple itunes download software reader rabbit math 6 9 discount software non generic Nolvadex no prescription Lasix buy cod Flomax buy generic Crestor canada where can i buy Orlistat without prescription order generic finpecia buy generic Orlistat pills Orlistat online purchase where can i buy Valtrex without a rx no prescription Orlistat buy maxalt without rx from us pharmacy buy genuine Maxalt online buy cheap Finpecia under without rx finpecia with overnight fedex purchase finpecia overnight purchase finpecia free consultation buy Valtrex without rx needed buy generic Buspar online Buspirone 10 mg how to buy prednisone online without a rx prednisone no script fedex buy valtrex shipped cod Valtrex online without prescription purchase Valtrex online without prescription Zithromax free consultation fedex overnight delivery buy Zithromax tablets without rx purchase Buspar without prescription buy Arimidex online cheap buy 200 mcg Cytotec online can you buy Cytotec from boots buy 10 mg Crestor teacher software discount Autocad 2011 Demo adobe premiere denoise adobe indesign plugins where to buy Proscar buy windows xp software adobe systems incorporated no rx Crestor purchase accutane 40 mg no scams window in chicago Learning Microsoft Word And Excel Adobe Creative Suite 2.0 buy generic Tamsulosin online adobe buy valtrex without doctor purchase Buspar without prescription needed adobe photoshop elements v6 no prescription finpecia cod delivery online pharmacy Crestor Crestor cheap purchase Crestor without a rx online Fincar tablets adobe acrobat publishing purchase Orlistat online without rx how to purchase Buspar online without rx adobe photoshop fx Microsoft Office 2010 Genuine Windows 7 Premium 64 Bit descargar autocad 9 Flomax wholesale avg interne Windows 7 Drivers purchase Valtrex online with overnight delivery buy cheap Crestor no prescription how to order Prednisone online without prescription purchase cheap prescription Orlistat adobe reader for windows millenium order generic Flomax online Buspar uk buy Buspar legally Valtrex buy on line buy generic Buspar from india getdataback ntfs legacy download buy Flomax online without prescription super cheap software additional license for indesign cs4 ashampoo uninstaller 4 tom tom maps australia cost oem adobe creative suite 5.5 design premium software Flomax rezept mcafee siteadvisor for google chrome buspar fedex download adobe page maker 7.0 portabel buy cheap Valtrex online free consult student discount for norton ghost microsoft visual studio 2005 serial valtrex buy adobe x professional military buy Flomax now portal half price logic pro 9 best Prednisone online pill herman cain wiki adobe premiere pro cs3 ftp buy Tamsulosin online no prescription buy cheap Valtrex line buy Valtrex online cod Bupropion best buy buy Amitriptyline online now order online Zithromax without prescription prednisone without a perscription buy prednisone without rx Valacyclovir 1000 mg cheap adobe flash builder 4.5 premium oem cad electrical editor Program Word 2007 adobe flash cs3 professional video studio Windows Server 2003 64 Bit Microsoft Windows Update Auto Update buy Orlistat epharmacist purchase Valtrex usa cod Buy Windows 7 Upgrade Online buy Valtrex without a rx overnight shipping Microsoft Computers order Buspar overnight prescription Prednisone non rx cheap Zithromax accutane 40 mg fedex no prescription adobe acrobat 8 adobe slide show adobe x pro full microsoft office student and home edition carpentry all furniture coreldraw software ns virtual dj 6.0 oem software distribution license agreements buy in Valtrex uk order rx free Cytotec prednisone on line no perscription purchase Buspar amex online without prescription where can i buy valtrex online without a prescription Discount Microsoft WindowsLightroom 2 Windows 7Ms Office StandardPhotoshop Cs5 UpgradeComputer Monitors For SaleWindows Xp InstallSuite Microsoft OfficeAutocad Version 2007Adobe Acrobat 9.0 Standard DownloadIe8 Download For Windows 7Adobe Paint ShopMicrosoft Service Pack 2Free Download Adobe AcrobatStudent And Teacher EditionManage ImageAdobe Acrobat 7 Pro DownloadVista Home Premium To Windows 7 UltimateWindows 7 Home Premium Upgrade OemAdobe Creative Suite 5 Master Collection Student And Teacher EditionBuy Adobe Photoshop Lightroom 3Ms Office 2010 Home And StudentCompare Photo SoftwareMicrosoft Office Word Viewer 2010Windows 7 Upgrade Student Discount ProfessionalWindows 7 Updates DownloadCreative Suite WebAdobe Reader VistaMicrosoft Windows 7 Home Premium Upgrade 64 BitPhotoshop 2Ie8 Download For Windows 7Photoshop 2009Suite Microsoft OfficeMicrosoft Office 2007 VersionUpgrade Windows Vista To 7Autocad Lt 2010Autocad 2010 Best PriceDownload Acrobat Reader 8 purchase Valtrex money purchase Valtrex side effects buy Buspar without a prescription overnight delivery buy Valtrex c o d what does Valtrex look like buy Proscar amex Proscar buy cod Cytotec prices buy Cytotec money buy where can i buy Prednisone online buy Prednisone no prescription Proscar online no rx overnight buy Cytotec online from canada buy Cytotec over the counter cod overnight buying finpecia online without rx buy finpecia no visa online without prescription buy finpecia us Buy Finpecia fda approved canada windows xp codec audio open in new window html microsoft lifecam discount locked out windows xp buy finpecia cheap software dreamweaver 8 bank software discount tax act software dreamweaver cs3 serial code window frosting buy cheap online pharmacy prednisone no prescription Lasix with fedex dscount software prices roxio purchase no perscription Cytotec victorian window windows 7 wallpaper dreamweaver validate Rosuvastatin no prescription overnight online Orlistat purchase buy Zithromax discount windows antique windows hacker microsoft window update recording software