on the challenges in extracting metrics from java bytecode
play

On the Challenges in Extracting Metrics from Java Bytecode A/Prof. - PowerPoint PPT Presentation

On the Challenges in Extracting Metrics from Java Bytecode A/Prof. Jean-Guy Schneider jschneider@swin.edu.au Where it all began 12.7: 0.6973 .7 12.6: 0.6443 Gini Coefficient of Synthetic Fields .6 12.5: 0.5820 .5 4.7:


  1. On the Challenges in Extracting Metrics from Java Bytecode A/Prof. Jean-Guy Schneider jschneider@swin.edu.au

  2. Where ¡it ¡all ¡began… ¡ 12.7: 0.6973 .7 12.6: 0.6443 Gini Coefficient of Synthetic Fields .6 12.5: 0.5820 .5 4.7: 0.4664 .4 4.6: 0.3484 .3 0 20 40 60 80 100 RSN SCIENCE | TECHNOLOGY | INNOVATION ¡ 2

  3. Overview ¡ q Java ¡Class ¡File ¡ Ø Informa1on ¡that ¡can ¡be ¡extracted ¡ Ø … ¡and ¡some ¡“misconcep1ons” ¡ q Nested ¡Class ¡Extrac1on ¡ Ø Preliminaries ¡ ¡ Ø Problems ¡and ¡Consequences ¡ Ø Nested ¡Class ¡Graph ¡ q A ¡few ¡“surprises” ¡ Ø Mo1va1ng ¡example ¡revisited ¡ q Lessons ¡learnt ¡ 3 ¡ SCIENCE | TECHNOLOGY | INNOVATION

  4. Quick Overview of Class File Format … There ¡are ¡10 ¡basic ¡sec1ons ¡to ¡the ¡Java ¡Class ¡File ¡structure: ¡ 1. Magic ¡Number: ¡ 0xCAFEBABE ¡ 2. Version ¡of ¡Class ¡File ¡Format: ¡the ¡minor ¡and ¡major ¡versions ¡ of ¡the ¡class ¡file ¡ 3. Constant ¡Pool: ¡Pool ¡of ¡constants ¡for ¡the ¡class ¡ 4. Access ¡Flags ¡ 5. Name ¡of ¡the ¡class ¡ 6. Name ¡of ¡the ¡super ¡class ¡ 7. Interfaces: ¡any ¡interfaces ¡the ¡class ¡implements ¡ 8. Fields: ¡fields ¡the ¡class ¡defines ¡ 9. Methods: ¡methods ¡the ¡class ¡defines ¡ 10. AWributes: ¡aWributes ¡of ¡the ¡class ¡(e.g., ¡the ¡name ¡of ¡the ¡ sourcefile, ¡enclosing ¡method ¡etc.) ¡ ¡ ☞ Many ¡references ¡to ¡the ¡Constant ¡Pool ¡in ¡5 ¡-­‑ ¡10 ¡ 4 SCIENCE | TECHNOLOGY | INNOVATION

  5. Analysis ¡of ¡Java ¡Bytecode ¡ What ¡we ¡can ¡extract ¡from ¡Java ¡Bytecode ¡ q ¡Classes ¡and ¡Interfaces ¡ q ¡Visibility ¡ (and ¡other ¡access ¡modifiers) ¡ q ¡Deriva1ons ¡(inheritance, ¡interface ¡implementa1ons) ¡ q ¡Fields, ¡Methods ¡+ ¡Method ¡Signatures, ¡Excep1ons ¡ q ¡Instruc1ons ¡ q ¡Type ¡Dependencies ¡ q ¡Local ¡Variables ¡ q ¡Nested ¡Classes, ¡Enclosing ¡Classes/Methods ¡ 5 ¡ SCIENCE | TECHNOLOGY | INNOVATION

  6. Data ¡Sources ¡used… ¡ q Qualitas ¡Corpus: ¡hWp://qualitascorpus.com/ ¡ q Ant: ¡22 ¡versions ¡(1.1 ¡– ¡1.8.4) ¡ q Freecol: ¡31 ¡versions ¡(0.3.0 ¡– ¡0.10.7) ¡ q Helix ¡Data ¡Set: ¡ hWp://www.ict.swin.edu.au/research/projects/ helix/ ¡ q Kolmafia: ¡101 ¡versions ¡(4.0 ¡– ¡14.1) ¡ q Xalan: ¡13 ¡versions ¡(1.0.0 ¡– ¡2.7.1) ¡ q … ¡and ¡a ¡few ¡hand-­‑crahed ¡examples ¡ 6 ¡ SCIENCE | TECHNOLOGY | INNOVATION

  7. When ¡is ¡a ¡Java ¡Type ¡enclosed ¡in ¡another ¡type? ¡ ¡ q No ¡nested ¡types ¡in ¡Java ¡1.0 ¡ q General ¡assump1on: ¡ q From ¡Java ¡1.1: ¡‘$’ ¡indicates ¡nes1ng ¡of ¡a ¡type ¡ q For ¡example: ¡ q com/ice/tar/TarInputStream ¡is ¡ top-­‑level ¡ q com/ice/tar/TarInputStream$EntryAdapter ¡ is ¡ nested ¡ q Hence: ¡ q Test ¡for ¡‘$’ ¡in ¡type ¡name ¡will ¡suffice… ¡ ☞ ‘$’ ¡is ¡a ¡valid ¡character ¡for ¡any ¡Java ¡idenHfier, ¡including ¡ class ¡and ¡interface ¡names! ¡ ¡ 7 ¡ SCIENCE | TECHNOLOGY | INNOVATION

  8. Example ¡1 ¡ class Foo$Bar { private int a = 23; public int mFoo$Bar (int x) { int $y = x + a; int $z = 3; return $y + $z; } } ☞ Perfectly ¡well-­‑formed ¡class… ¡ ☞ But: ¡Bytecode ¡analysis ¡indicates ¡that ¡method ¡ mFoo$Bar ¡does ¡ not ¡have ¡any ¡local ¡variables! ¡ 8 ¡ SCIENCE | TECHNOLOGY | INNOVATION

  9. Example ¡2 ¡ public class Foo { private int x = 1; protected class Bar { int y = 2; public int mBar() { return new Object() { public int z = x + 3; }.z; } } } ☞ Top-­‑level ¡class ¡ Foo , ¡nested ¡class ¡ Bar ¡with ¡a ¡nested ¡ anonymous ¡class ¡that ¡extends ¡ Object ☞ Generated ¡ Bytecode ¡names: ¡ Foo , ¡ Foo$Bar , ¡ Foo$Bar$1 9 ¡ SCIENCE | TECHNOLOGY | INNOVATION

  10. Example ¡2 ¡– ¡Bytecode… ¡ [ public ] Foo$Bar -> (top-level: false) super: java/lang/Object implements: [ ] Enclosed in: Foo Member: true Local: false Anonymous: false #Methods 3 - #Fields 2 attributes: SourceFile InnerClasses InnerClasses: [ Foo$Bar, Foo, Bar, [ protected ] ] InnerClasses: [ Foo$Bar$1, #0, #0, [ ] ] Mismatch!! Inner Name, Outer Name, Simple Name, Access Flags 10 ¡ SCIENCE | TECHNOLOGY | INNOVATION

  11. Example ¡2 ¡(cont.) ¡ [ ] Foo$Bar$1 -> (top-level: false) super: java/lang/Object implements: [ ] Enclosed in: Foo$Bar -> mBar:()I Member: false Local: true Anonymous: true #Methods 1 - #Fields 2 attributes: SourceFile InnerClasses EnclosingMethod EnclosingMethodAttribute: Foo$Bar -> mBar:()I InnerClasses: [Foo$Bar, Foo, Bar, [ protected ] ] InnerClasses: [Foo$Bar$1, #0, #0, [ ] ] ☞ BTW: ¡which ¡ Foo$Bar ??? ¡ 11 ¡ SCIENCE | TECHNOLOGY | INNOVATION

  12. ObservaMon… ¡and ¡why ¡it ¡can ¡be ¡wrong… ¡ A ¡nested ¡class ¡with ¡ bytecode ¡name ¡ X$..$Y$Z ¡is ¡enclosed ¡in ¡class ¡ X$..$Y ¡ q Not ¡always ¡applicable ¡ L ¡(up ¡to ¡6% ¡error ¡rate) ¡ q Counter ¡examples ¡(from ¡Freecol ¡0.5.0): ¡ net/sf/freecol/client/control/InGameController$2 ¡ is ¡enclosed ¡in ¡ net/sf/freecol/client/control/InGameController$1 ¡ ¡ net/sf/freecol/client/gui/panel/Declara1onDialog$5 ¡ is ¡enclosed ¡in ¡ net/sf/freecol/client/gui/panel/Declara1onDialog$SignaturePanel ¡ q Another ¡example ¡(from ¡KoKmafia ¡4.0): ¡ net/sourceforge/kolmafia/KoLFrame$2 is enclosed in net/sourceforge/kolmafia/KoLFrame$ItemManagePanel$VerifyButtonPanel ¡ 12 ¡ SCIENCE | TECHNOLOGY | INNOVATION

  13. Nested ¡Classes ¡Graph ¡ starting from a top-level node, go through all inner class structures: exclude any 'self-defining' nested classes, that is, ones with Inner Name having the same string value as the current class C if the Outer Name of a nested class structure is zero -> a method M in the current class C is the defining scope for the nested local class -> record Inner Name as one of the directly nested classes of C (i.e. class Inner Name is directly enclosed by C) if the Outer Name is equal to the current class' name -> record Inner Name as one of the directly nested classes of C as it is a (static or non-static) member class of C proceed recursively with all recorded nested class names ¡ ¡ ¡ 13 ¡ SCIENCE | TECHNOLOGY | INNOVATION

  14. Example ¡2 ¡– ¡missing ¡InformaMon ¡ [ ] Foo$Bar$1 -> (top-level: false) super: java/lang/Object implements: [ ] Enclosed in: ??? -> ??? Member: false Local: false Anonymous: true #Methods 1 - #Fields 2 attributes: SourceFile InnerClasses InnerClasses: [Foo$Bar, Foo, Bar, [ protected ] ] InnerClasses: [Foo$Bar$1, #0, #0, [ ] ] ☞ Without ¡an ¡EnclosingMethod ¡aWribute, ¡the ¡defining ¡“context” ¡of ¡a ¡non-­‑ member ¡nested ¡class ¡cannot ¡be ¡uniquely ¡determined! ¡ ☞ In ¡case ¡of ¡missing ¡InnerClasses ¡informa1on, ¡the ¡enclosing ¡class ¡of ¡a ¡ “hidden” ¡nested ¡class ¡cannot ¡always ¡be ¡uniquely ¡determined, ¡either… ¡ 14 ¡ SCIENCE | TECHNOLOGY | INNOVATION

  15. Java ¡Classes ¡CategorizaMon ¡ What ¡is ¡ohen ¡published: ¡ q Top-­‑level ¡(package ¡level) ¡classes ¡ q Nested ¡classes ¡ q Member-­‑level ¡classes ¡ q “Inner ¡Classes” ¡ q Local ¡classes ¡(have ¡a ¡simple ¡name) ¡ q Anonymous ¡classes ¡(no ¡simple ¡name) ¡ ¡ ☞ Anonymous ¡classes ¡are ¡expressions ¡– ¡they ¡can ¡be ¡used ¡ anywhere ¡where ¡an ¡expression ¡is ¡allowed. ¡ ☞ Are ¡ohen ¡used ¡to ¡ini1alize ¡member ¡instances ¡ 15 ¡ SCIENCE | TECHNOLOGY | INNOVATION

  16. Java ¡Classes ¡CategorizaMon ¡(cont.) ¡ Corrected ¡classifica1on: ¡ q Top-­‑level ¡(package ¡level) ¡classes ¡ q Nested ¡classes ¡ q Member-­‑level ¡classes ¡ q Anonymous ¡classes ¡ q Local ¡classes ¡– ¡can ¡be ¡either ¡named ¡or ¡anonymous ¡ ☞ “Locality” ¡of ¡anonymous ¡classes ¡can ¡only ¡be ¡safely ¡ determined ¡if ¡EnclosingMethod ¡aWribute ¡is ¡present! ¡ ¡ ☞ Classifica1on ¡is ¡ not ¡orthogonal! ¡ 16 ¡ SCIENCE | TECHNOLOGY | INNOVATION

  17. Let’s have a look at some results … 17 SCIENCE | TECHNOLOGY | INNOVATION

  18. Ant ¡– ¡Gini ¡ .8 Gini - Percentage .6 .4 .2 0 0 5 10 15 20 25 RSN GiniSyntheticFields GiniSyntheticFields(Zero) %TopLevel SCIENCE | TECHNOLOGY | INNOVATION 18 ¡

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend