1 / 92

Yue Li , Tian Tan, Yulei Sui, Jingling Xue

Self- Inferencing Reflection Resolution for Java. Yue Li , Tian Tan, Yulei Sui, Jingling Xue. Complier Research Group @ UNSW, Australia. July 30, 2014. Static analysis for OO in practice ?. Static analysis for OO in practice ?. re re re … reflection !. Class Person {.

boone
Download Presentation

Yue Li , Tian Tan, Yulei Sui, Jingling Xue

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Self-Inferencing Reflection Resolution for Java Yue Li, Tian Tan, Yulei Sui, Jingling Xue Complier Research Group @ UNSW, Australia July 30, 2014

  2. Static analysis for OO in practice ?

  3. Static analysis for OO in practice ? re re re … reflection !

  4. Class Person { String name; void setName(String nm) {…}; } … … Person p = new Person(); p.setName(“John”);

  5. Class Person { String name; void setName(String nm) {…}; } … … Person p = new Person(); p.setName(“John”);

  6. Class Person { String name; void setName(String nm) {…}; } … … Person p = new Person(); p.setName(“John”);

  7. Class Person { String name; void setName(String nm) {…}; } … … Person p = new Person(); p.setName(“John”); class field method

  8. Class Person { String name; void setName(String nm) {…}; } … … Person p = new Person(); p.setName(“John”); Metaobject ! Class Method Field class field method

  9. Class Person { String name; void setName(String nm) {…}; } … … Person p = new Person(); p.setName(“John”); Metaobject ! Class Method Classc = Class.forName(“Person”); Field Methodm = c.getMethod(“setName”, …); class Object p = c.newInstance(); field method m.invoke(p, “John”);

  10. Classc = Class.forName(“Person”); Class Person { Methodm = c.getMethod(“setName”, …); String name; Fieldf = c.getField(“name”); void setName(String nm) {…}; Object p = c.newInstance(); } … … m.invoke(p, “John”); Person p = new Person(); p.setName(“John”); Metaobject ! Class Method Field class field method

  11. Classc = Class.forName(“Person”); Class Person { Methodm = c.getMethod(“setName”, …); String name; Fieldf = c.getField(“name”); void setName(String nm) {…}; Object p = c.newInstance(); } … … m.invoke(p, “John”); f.set(p, xx); / s = (String) f.get(p); Person p = new Person(); p.setName(“John”); Metaobject ! Class Method Field class field method

  12. Class Person { String name; void setName(String nm) {…}; Runtime } … … Person p = new Person(); p.setName(“John”); Metaobject ! Class Method Compile Time Classc = Class.forName(“Person”); Field Methodm = c.getMethod(“setName”, …); Fieldf = c.getField(“name”); class Object p = c.newInstance(); field method m.invoke(p, “John”); f.set(p, xx); / s = (String) f.get(p);

  13. Classc = Class.forName(cName); Bug Detection Methodm = c.getMethod(mName, …); A a = new A(); Call graph edge m.invoke(a, …); method 1 method 3 method 2 B b = new B(); Fieldf = c.getField(“fld”); Not Safe Bug f.set(a, a); // a.fld = a a.fld = b; B b2 = (B) a.fld; Optimization

  14. How existing work handle reflection ?

  15. How existing work handle reflection ? (APLAS 2005) Benjamin Livshits, John Whaley, and Monica S. Lam Reflection Analysis for Java

  16. How existing work handle reflection ? (APLAS 2005) Benjamin Livshits, John Whaley, and Monica S. Lam Reflection Analysis for Java

  17. How existing work handle reflection ? (APLAS 2005) Benjamin Livshits, John Whaley, and Monica S. Lam Classc = Class.forName(“Person”); Reflection Analysis for Java Methodm = c.getMethod(“setName”, …); Fieldf = c.getField(“name”); Analyzing the string values of the arguments !

  18. How existing work handle reflection ? (APLAS 2005) Benjamin Livshits, John Whaley, and Monica S. Lam Classc = Class.forName(“Person”); Reflection Analysis for Java Methodm = c.getMethod(“setName”, …); Fieldf = c.getField(“name”); Configuration Files Analyzing the string values of the arguments !

  19. How existing work handle reflection ? (APLAS 2005) Benjamin Livshits, John Whaley, and Monica S. Lam Classc = Class.forName(“Person”); Reflection Analysis for Java Command Lines Methodm = c.getMethod(“setName”, …); Fieldf = c.getField(“name”); Configuration Files Analyzing the string values of the arguments !

  20. How existing work handle reflection ? (APLAS 2005) Benjamin Livshits, John Whaley, and Monica S. Lam Classc = Class.forName(“Person”); Reflection Analysis for Java Command Lines Methodm = c.getMethod(“setName”, …); Fieldf = c.getField(“name”); Complicated String Operations Configuration Files Analyzing the string values of the arguments !

  21. How existing work handle reflection ? (APLAS 2005) Benjamin Livshits, John Whaley, and Monica S. Lam Can we do better ? Reflection Analysis for Java

  22. GOAL: Analyze reflection in a better way

  23. GOAL: ? Analyze reflection in a better way

  24. GOAL: ? Analyze reflection in a better way 191 methods (Java Reflection API)

  25. Three kinds of methods Entry Methods Member-introspecting Methods Side-Effect Methods

  26. Three kinds of methods Entry Methods Classc = Class.forName(“Person”); Member-introspecting Methods Side-Effect Methods

  27. Three kinds of methods Entry Methods Classc = Class.forName(“Person”); Member-introspecting Methods Methodm = c.getMethod(“setName”, …); Fieldf = c.getField(“name”); Side-Effect Methods

  28. Three kinds of methods Entry Methods Classc = Class.forName(“Person”); Member-introspecting Methods Methodm = c.getMethod(“setName”, …); Fieldf = c.getField(“name”); Side-Effect Methods Object p = c.newInstance(); m.invoke(p, “John”); f.set(p, xx); / s = (String) f.get(p);

  29. Study

  30. Empirical Study DaCapo (2006-10-MR2) javac (1.7.0) Eclipse (4.2.2) jEdit (5.1.0) Tomcat (7.0.42) Jetty (9.0.5)

  31. Empirical Study DaCapo (2006-10-MR2) javac (1.7.0) Side-Effect Methods Eclipse (4.2.2) Demand-driven jEdit (5.1.0) Tomcat (7.0.42) Manually Jetty (9.0.5)

  32. Empirical Study DaCapo (2006-10-MR2) javac (1.7.0) Side-Effect Methods Eclipse (4.2.2) Demand-driven jEdit (5.1.0) Tomcat (7.0.42) Manually Jetty (9.0.5) Side-Effect callsites: 609 Member-Introspecting callsites: 304 Entry callsites: 501

  33. Empirical Study DaCapo (2006-10-MR2) javac (1.7.0) Side-Effect Methods Eclipse (4.2.2) Useful findings Demand-driven jEdit (5.1.0) Tomcat (7.0.42) Manually Jetty (9.0.5) Side-Effect callsites: 609 Member-Introspecting callsites: 304 Entry callsites: 501

  34. Entry Methods

  35. Side-Effect Methods

  36. String Arguments

  37. Self-Inferencing Property

  38. Self-Inferencing Property Class Person { String name; void setName(String nm) {…}; } Person p = new Person(); Classc = Class.forName(“Person”); Fieldf = c.getField(“name”); String s = (String) f.get(p); // s = p.f

  39. Self-Inferencing Property Class Person { String name; void setName(String nm) {…}; } Person p = new Person(); Classc = Class.forName( ? ); Fieldf = c.getField(“name”); String s = (String) f.get(p); // s = p.f

  40. Self-Inferencing Property Class Person { String name; void setName(String nm) {…}; } Person p = new Person(); Classc = Class.forName( ? ); Fieldf = c.getField(”name”); String s = (String) f.get(p); // s = p.f

  41. Self-Inferencing Property Class Person { String name; void setName(String nm) {…}; } Person p = new Person(); Classc = Class.forName( ? ); Fieldf = c.getField(”name”); String s = (String) f.get(p); // s = p.f

  42. Self-Inferencing Property Class Person { String name; void setName(String nm) {…}; } Person p = new Person(); Classc = Class.forName(“Person”); Fieldf = c.getField( ? ); String s = (String) f.get(p); // s = p.f

  43. Self-Inferencing Property Class Person { String name; void setName(String nm) {…}; } Person p = new Person(); Classc = Class.forName(“Person”); Fieldf = c.getField( ? ); String s = (String) f.get(p); // s = p.f

  44. Self-Inferencing Property Class Person { String name; void setName(String nm) {…}; } Person p = new Person(); Classc = Class.forName(“Person”); Fieldf = c.getField( ? ); String s = (String) f.get(p); // s = p.f

  45. ELF Self-inferencing Reflection Resolution for Java

  46. Intuition When string arguments cannot be resolved statically Infer the reflective targets at their usage points

  47. ELF

  48. ELF

  49. ELF class name known

  50. ELF class name known

More Related