Towards Dynamic Interprocedural Analysis in JVMs Feng Qian and - - PowerPoint PPT Presentation

towards dynamic interprocedural analysis in jvms
SMART_READER_LITE
LIVE PREVIEW

Towards Dynamic Interprocedural Analysis in JVMs Feng Qian and - - PowerPoint PPT Presentation

Towards Dynamic Interprocedural Analysis in JVMs Feng Qian and Laurie Hendren { fqian,hendren } @cs.mcgill.ca. School of Computer Science, McGill University http://www.sable.mcgill.ca VM 2004 p.1/23 Motivation Goal: do interprocedural


slide-1
SLIDE 1

Towards Dynamic Interprocedural Analysis in JVMs

Feng Qian and Laurie Hendren {fqian,hendren}@cs.mcgill.ca.

School of Computer Science, McGill University

http://www.sable.mcgill.ca

VM 2004 – p.1/23

slide-2
SLIDE 2

Motivation

Goal:

  • do interprocedural analysis supporting speculative
  • ptimizations in a JIT compiler

VM 2004 – p.2/23

slide-3
SLIDE 3

Motivation

Goal:

  • do interprocedural analysis supporting speculative
  • ptimizations in a JIT compiler

Problems:

  • construct a high quality call graph efficiently
  • deal with dynamic class loading
  • handle unresolved symbolic references
  • . . . . . .

VM 2004 – p.2/23

slide-4
SLIDE 4

Dynamic call graphs

A call graph is a representation of call relations between methods. A dynamic call graph

  • is constructed incrementally
  • is conservative w.r.t. executed code
  • supports speculative optimizations

VM 2004 – p.3/23

slide-5
SLIDE 5

Road map

  • Motivation
  • Constructing call graphs using profiling stubs
  • Constructing call graphs using type analysis
  • Evaluation
  • Dynamic XTA
  • Related work and conclusion

VM 2004 – p.4/23

slide-6
SLIDE 6

Background: virtual method calls in JikesRVM

method instruction address class A’s TIB virtual method table

  • bject pointer

TIB = * (ptr + TIB_OFFSET); INSTR = TIB[method_offset]; JMP INSTR *The method_offset is a runtime constant.

VM 2004 – p.5/23

slide-7
SLIDE 7

Incorporating call graph profiling stubs

method instruction address

CTB array

indexed by method_offset indexed by caller_index class A’s TIB

TIB = * (ptr + TIB_OFFSET); CTB = TIB[method_offset]; // load CTB array from TIB INSTR = CTB[caller_index]; // load code address JMP INSTR *The caller_index is a runtime constant.

VM 2004 – p.6/23

slide-8
SLIDE 8

CTB arrays

  • an entry of a CTB array
  • is initialized to the address of a profi ling code stub
  • contains real method code address after executing the

code stub

  • caller_index assignment
  • handles polymorphism and symbolic references

properly

  • may waste some space in CTBs

VM 2004 – p.7/23

slide-9
SLIDE 9

Call graph profiling code stubs

A call graph profiling code stub

  • generates a call edge event
  • triggers the compilation of the method if necessary
  • patches the instruction address into the CTB entry

Note: a call edge only triggers the profiling stub once (at its first invocation).

VM 2004 – p.8/23

slide-10
SLIDE 10

Optimizations

  • Majority of methods have a small number of callers
  • Inlining fi rst few CTB elements into TIBs eliminates the

extra load

2 4 8 compress 97.26% 99.99% 99.99% javac 21.62% 64.25% 83.53% jack 48.51% 77.82% 86.01%

  • Type analysis can be used for non-virtual and interface

calls

  • Runtime overhead ranges from -2% to 3% for our set of

benchmarks

VM 2004 – p.9/23

slide-11
SLIDE 11

Road map

  • Motivation
  • Constructing call graphs using profiling stubs
  • Constructing call graphs using type analysis
  • Evaluation
  • Dynamic XTA
  • Related work and conclusion

VM 2004 – p.10/23

slide-12
SLIDE 12

Dynamic type analysis

During the execution of a program P, define

initialized types(P) the set of initialized classes

(built by class loaders)

rapid types(P) the set of initialized classes having

allocation sites (built by JIT compilers)

instantiated types(P) the set of classes having instances

(built by allocators) Sets are dynamically expanded as program runs.

VM 2004 – p.11/23

slide-13
SLIDE 13

Dynamic CHA, RTA, and ITA

Let hierarchy_types(C) be the set of types including C and its subclasses. When compiling a resolved call C.m(), the following type set is used for computing call targets:

Class hierarchy analysis :

hierarchy_types(C) ∩ initialized_types(P)

Rapid type analysis :

hierarchy_types(C) ∩ rapid_types(P)

Instantiation-based type analysis :

hierarchy_types(C) ∩ instantiated_types(P)

VM 2004 – p.12/23

slide-14
SLIDE 14

Handle dynamic expansion of type sets

Maintain a database of RESOLVED_CALLSITES

resolved (callee) method ⇒ { call sites }

Let C be a new member of the type set,

for each virtual method m of C for each m’ overridden by m for each resolved call site s calling m’ generate a call edge from s to m

A similar approach is used to handle unresolved method calls.

VM 2004 – p.13/23

slide-15
SLIDE 15

Road map

  • Motivation
  • Constructing call graphs using profiling stubs
  • Constructing call graphs using type analysis
  • Evaluation
  • Dynamic XTA
  • Related work and conclusion

VM 2004 – p.14/23

slide-16
SLIDE 16

Call graph sizes

benchmarks CHA RTA ITA Prof compress 458 432 (94%) 380 (83%) 240 (52%) javac 8141 7706 (95%) 6376 (78%) 2775 (34%) jack 1131 1062 (94%) 997 (88%) 785 (69%) jbb 2802 2663 (95%) 2379 (85%) 1734 (64%)

Table 0: the number of call edges from invokevirtual calls at the end of benchmark runs.

VM 2004 – p.15/23

slide-17
SLIDE 17

Call graph sizes at runtime (jbb)

500 1000 1500 2000 2500 3000 50 100 150 200 250 300 the number of call edges from invokevirtuals (jbb) virtual time (the number of opt compiled methods) Dynamic CHA Dynamic RTA ITA Profile

VM 2004 – p.16/23

slide-18
SLIDE 18

Road map

  • Motivation
  • Constructing call graphs using profiling stubs
  • Constructing call graphs using type analysis
  • Evaluation
  • Dynamic XTA
  • Related work and conclusion

VM 2004 – p.17/23

slide-19
SLIDE 19

Static XTA (Tip & Palsberg 2000)

  • models method calls, field and array accesses
  • ignores intraprocedural data-flows

foo(): Set s = new MySet(); it = s.iterator(); it.hasNext() it.next() MySet.iterator(): return new MyIterator(); foo MySet MySet.init MySet.iterator MyIterator.hasNext MyIterator.next MyIterator MyIterator.init MySet MySet MyIterator MyIterator MyIterator MyIterator

VM 2004 – p.18/23

slide-20
SLIDE 20

Dynamic XTA

compilers constructors call graph classloader analysis dependency databases XTA graphs 1 2 3 4 5 6

  • the dynamic XTA is event-driven
  • unresolved field/array references are handled by

dependency databases

  • results are optimistic

VM 2004 – p.19/23

slide-21
SLIDE 21

Related Work

  • Static call graph construction algorithms (CHA, RTA,

VTA, etc.)

  • Dynamic optimistic interprocedural analysis (DOIT by

Perchtchanski & Sarkar OOPSLA 2001)

  • Pointer analysis in the presence of dynamic class

loading (Hirzel et.al. ECOOP 2004)

  • Online shape analysis (Bogda et. al. JVM 2001)

VM 2004 – p.20/23

slide-22
SLIDE 22

Conclusion

  • Proposed a new, inexpensive, call graph profiling

mechanism

  • Studied several dynamic type analysis for call graph

construction

  • Presented a model of dynamic interprocedural

analysis

  • Working on more advanced interprocedural analysis
  • How to use the analysis results? and what kind of

speculative optimizations can we do?

VM 2004 – p.21/23

slide-23
SLIDE 23

Questions

?

VM 2004 – p.22/23