Download ppt - Gulfstream

Transcript
Page 1: Gulfstream

Gulfstream

Salvatore GuarnieriUniversity of Washington

Ben LivshitsMicrosoft Research

Staged Static Analysis for Streaming JavaScript Applications

Page 2: Gulfstream

2

Third Party Server

Web application

widget.js

Web page

Page 3: Gulfstream

Safe Code Inclusion In JavaScript

Runtime Enforcement• Conscript [Oakland 10]• BrowserShield [OSDI 06]• Caja

Static Analysis• Gatekeeper [USENIX Sec 09]• Staged Information flow for

JavaScript [PLDI 09]

3

Whole program analysis approaches require the entire program

Whole program analysis approaches require the entire program

Page 4: Gulfstream

4

Page 5: Gulfstream

5

JavaScript programs are streamingJavaScript programs are streaming

Page 6: Gulfstream

<HTML> <HEAD> <SCRIPT> function foo(){...} var f = foo; </SCRIPT> <SCRIPT> function bar(){...} if (...) f = bar; </SCRIPT> </HEAD> <BODY onclick="f();"> ...</BODY></HTML>

Script Creation

6

What does f refer to?

What does f refer to?

Page 7: Gulfstream

Incremental Loading in Facebook

7

71%

Page 8: Gulfstream

✔✔

Gulfstream In Action

8

Offline Online

✔✔✔✔

Page 9: Gulfstream

Outline

9

Page 10: Gulfstream

Queries

• We want to determine something about the program

• Example– What does f() refer to– Detect alert calls– Does this program use setTimeout

10

Page 11: Gulfstream

Points-To Analysis

• Provides deep program understanding

• Can be used to construct call graphs

• Is the foundation of further analyses

• Answers a simple question: What heap locations does variable x point to

11

Page 12: Gulfstream

Points-To Example

12

Page 13: Gulfstream

Implementation Strategies

Datalog with bddbddb+ Fast for large programs+ Highly tuned- Large startup cost- Difficult to implement in the

browser

• Used in Gatekeeper [USENIX Sec 09]

Graph-based flow analysis+ Very small startup cost+ Customized to work with

Gulfstream- Does not scale well

13

Page 14: Gulfstream

Implementation

• Normalize JavaScript– Turn program into a series of simple statements– Introduce temporaries as necessary

• Create flow graph – Use normalized program to generate flow constraints

• Serialize flow graph – Encode the flow-graph so online analysis can use it to update results

14

Page 15: Gulfstream

Implementation Continued

• Perform points-to analysis– Traverse flow graph to find all aliases– Follow flow through method boundaries– Generate points-to map for queries to use

• Queries – Use points-to data and flow graph to answer queries

15

Page 16: Gulfstream

Evaluation• Question – Is Gulfstream faster than non-staged

analysis

• Benchmarks– Synthetically generated– Scraped from Google code– Scraped from Facebook

• Simulate diverse environments– CPU speed and network properties– Cell phone, laptop, desktop, etc.

16

Page 17: Gulfstream

Laptop Running Time Comparison

17

After 30KB of updates, Gulfstream is no longer

faster

After 30KB of updates, Gulfstream is no longer

faster

Page 18: Gulfstream

Simulated Devices

• Low power mobile

• High power

18

Page 19: Gulfstream

Lessons Learned

• Slow devices benefit from Gulfstream

• A slow network can negate the benefits of the staged analysis

• Large page updates don’t benefit from Gulfstream

19

Page 20: Gulfstream

Facebook Experiment

• Visit 4 pages– Home– Friends– Inbox– Profile

• Each page loads additional JavaScript

20

Page 21: Gulfstream

Gulfstream Savings: Slow Devices

21

Page 22: Gulfstream

Gulfstream Savings: Fast Devices

22

10 seconds saved

10 seconds saved

Page 23: Gulfstream

Conclusion

• Gulfstream, staged analysis for JavaScript

• Staged analysis– Offline on the server– Online in the browser

• Wide range of experiments– For small updates, Gulfstream is faster– Devices with slow CPU benefit most

23

Page 24: Gulfstream

The End

• Contact: [email protected]

24