Presentation is loading. Please wait.

Presentation is loading. Please wait.

OOPSLA’06: Cohen, Gil, Maman JTL – The Java Tools Language Intuitively querying Java programs Itay Maman The Technion – Israel Institute of Technology.

Similar presentations


Presentation on theme: "OOPSLA’06: Cohen, Gil, Maman JTL – The Java Tools Language Intuitively querying Java programs Itay Maman The Technion – Israel Institute of Technology."— Presentation transcript:

1 OOPSLA’06: Cohen, Gil, Maman JTL – The Java Tools Language Intuitively querying Java programs Itay Maman The Technion – Israel Institute of Technology Joint work with Tal Cohen and Yossi Gil October 24, 2006 OOPSLA’06, Portland

2 OOPSLA’06: Cohen, Gil, Maman 2/16 Wanted: A class with a static method returning float The regular expression approach: static float static.*float.*\(.*\) –(Inaccurate) The XQuery approach: /class/method[./return/@type="float" and @modifiers="static"] –(Too complicated to be used interactively) There’s also a JTL way…

3 OOPSLA’06: Cohen, Gil, Maman 3/16 In this Talk Motivation, Design considerations JTL 101 Evaluation algorithm

4 OOPSLA’06: Cohen, Gil, Maman 4/16 Usage scenarios Existing solutions: CodeQuest, BDDBDDB, XIRC, JQuery, ALPHA, … Software engineering tools –Code lookup, (anti) pattern detection, … Programming languages –Static pointcuts in aspect-oriented programming –Mixins (Jam) –Concepts (ConceptC++) –Pluggable type systems (JavaCOP)

5 OOPSLA’06: Cohen, Gil, Maman 5/16 Queries embedded in the Program Java 5 already provides code queries –Syntax close to Java –Limited expressive power A hypothetical alternative (SQL) –Syntax significantly diverts from Java –Difficult to write/read public void f(T ts) {... } public void f(T ts) { … }

6 OOPSLA’06: Cohen, Gil, Maman 6/16 Mission Statement Define a logic language (over Java programs) which: A. Is as powerful as Datalog B. Has an intuitive, readable syntax C. Has a simple data model  Other solutions fall short

7 OOPSLA’06: Cohen, Gil, Maman 7/16 JTL: Unary Predicates A simple predicate: –Three sub-queries –Space (and comma) denotes conjunction The subject variable –The hash symbol, #, denotes the subject variable –A variable in a prefix position => becomes the subject of the callee If not specified, defaults to # (the subject)  static, final, etc. are library predicates, not keywords. const := static final field; const := #static #final #field;

8 OOPSLA’06: Cohen, Gil, Maman 8/16 JTL: Binary Predicates Binary predicates –Accept a subject + an additional parameter (in a postfix position) –(Names of Variables/Parameters must begin with a capital letter) Subject chaining: Repeatedly using a variable as a subject –Can be rewritten using the ampersand operator: has_static_member X := class declares X, X static; extends+ Y := extends Y | extends Y', Y' extends+ Y; my_generic_method T := method, T extends Serializeable & Cloneable; my_generic_method T := method, T extends Serializeable, T extends Cloneable;

9 OOPSLA’06: Cohen, Gil, Maman 9/16 JTL: Quantification { } Quantifying the members of a class –Subject variable iterates over a set –Each condition must hold –Quantifiers: Unary: exists, all, no, one, many Binary: => (implies) Quantifying with a generator Default generator for classes: members: Default quantifier: exists no_abstract_super := class extends+: { no abstract; } some_class := class { static int field; field => private; many method; } Generator

10 OOPSLA’06: Cohen, Gil, Maman 10/16 Other Features sortable_list := class extends /java.util.ArrayList { static final long field 'SerialVersionUID; public void sort(); } Type literal Method signature pattern Name matching (Regular expression) Type system –MEMBER: constructors, methods, fields –TYPE: interfaces, classes, primitive types, enum types, annotation types

11 OOPSLA’06: Cohen, Gil, Maman 11/16 Delving into methods The idea: Symbolically name intermediate results The SCRATCH type –Constants –Values passed to parameters –Values pushed onto the stack by JVM instructions Represent code sites Library predicates for checking whether a scratch is: –Copied –Used in a calculation –Written/Read from a field –Stored/loaded from the local variable array –...

12 OOPSLA’06: Cohen, Gil, Maman 12/16 Scratches in Action  Default generator expression for a method is: scratches: –Generates all scratches of the method copy* S := is S | copy S | copy S', S' copy* S; chain_method := !void method { returned => copy* S, S this; }; getter_method := !void method declared_by C, C declares F { returned => copy* V, V getfield [I,F], I copy* S, S this; };

13 OOPSLA’06: Cohen, Gil, Maman 13/16 Evaluation scheme JTL is translated into Datalog The Datalog program is evaluated top-down “need to know basis” –The JTL evaluation algorithm does not see more information than it needs –Only necessary facts are extracted from the native predicates => No database setup is needed - Which is a bottleneck in similar applications

14 OOPSLA’06: Cohen, Gil, Maman 14/16 Q: What’s special about p2? A: Result of p2 is infinite –Result of p3 may be infinite (depending on the definition of p4 ) Consequences 1.Use exhaustive iteration –Assume a closed world, usually: the classpath –Performance penalty 2.Beware: Fragile results!! p1 := # extends A, A abstract; p2 := A extends #, A abstract; p3 := A extends #, A abstract, # p4 A; p4 :=... (Suppose we invoke p1, p2, p3 with some type passed in as a subject)

15 OOPSLA’06: Cohen, Gil, Maman 15/16 Fragility Can we determine whether a query is fragile? –In the general case: No –In JTL’s case: Yes Requires the native predicates to maintain a simple property Recently proven by Gil and Zarivach JTL’s current implementation is more conservative –Subject is not known => a runtime error –Works well in most practical situations

16 OOPSLA’06: Cohen, Gil, Maman 16/16 Contributions JTL: A powerful language, intuitive notation, simple data model – Java-like clauses become Datalog queries – Queries on behavior – Efficient implementation

17 OOPSLA’06: Cohen, Gil, Maman 17/16 http://www.cs.technion.ac.il/jtl


Download ppt "OOPSLA’06: Cohen, Gil, Maman JTL – The Java Tools Language Intuitively querying Java programs Itay Maman The Technion – Israel Institute of Technology."

Similar presentations


Ads by Google