More Related Content Similar to Java scriptcore brief introduction (20) Java scriptcore brief introduction7. id win = [webView windowScriptObject];
id location = [win valueForKey:@"location"];
NSString *href = [location valueForKey:@"href"];
JavaScript in Objective-C
42. VM
• Register-Based
[ 0] enter
[ 1] mov r0, Cell: 0133FC40(@k0)
[ 4] put_by_id r0, a(@id0), Int32:
100(@k1)
[ 13] mov r0, Cell: 0133FC40(@k0)
[ 16] put_by_id r0, b(@id1), Int32:
200(@k2)
[ 25] mov r0, Cell: 0133FC40(@k0)
[ 28] put_by_id r0, c(@id2), Int32:
300(@k3)
[ 37] resolve_global r0, a(@id0)
[ 43] resolve_global r1, b(@id1)
[ 49] add r0, r0, r1
[ 54] resolve_global r1, c(@id2)
[ 60] mul r0, r0, r1
[ 65] ret r0
43. VM
• Stack Based 0: bipush 100
2: istore_1
3: sipush 200
6: istore_2
7: sipush 300
10: istore_3
11: iload_1
12: iload_2
13: iadd
14: iload_3
15: imul
16: ireturn
44. function sub(a,b)
{
return a-b;
}
function add(a,b)
{
return a+b;
}
i=0;
while(i<3000)
{
value = add(i,i+2);
i=i+1;
}
value = value + 1;
[ 0] enter
[ 1] mov r0, Undefined(@k0)
[ 4] resolve_base r1, i(@id0), 20975696, 20978944
[ 11] mov r0, Int32: 0(@k1)
[ 14] put_to_base r1, i(@id0), r0, 20978944
[ 19] resolve r1, i(@id0), 20975712
[ 24] jnless r1, Int32: 3000(@k2), 78(->102)
[ 28] loop_hint
[ 0] enter
[ 1] add r0, r-8, r-9
[ 6] ret r0
47. Bytecode
[ 32] put_to_base r1, s(@id0), r0, 35719584
[ 37] resolve_base r1, i(@id2), 35719328, 35719616
[ 44] mov r0, Int32: 0(@k3)
[ 47] put_to_base r1, i(@id2), r0, 35719616
[ 52] resolve r1, i(@id2), 35719344
[ 57] jnless r1, Int32: 3000(@k4), 78(->135)
[ 61] loop_hint
[ 62] resolve_base r1, value(@id3), 35719360, 35719648
[ 69] resolve_with_this r5, r2, add(@id4), 35719376
[ 75] resolve r4, i(@id2), 35719344
[ 80] resolve r6, i(@id2), 35719344
[ 0] enter
[ 1] sub r0, r-8, r-9
[ 6] ret r0
50. JIT - Interpreter
• Classic Interpreter
– Implementation
• while(1) { switch(…) …}
– Easy implementation
– Performance limitation
• Obsoleted in WebKit.
51. JIT
• ◮ Compiler generates machine code from bytecode (jit/*)
• ◮ Big switch with emit-calls
• ◮ Uses target specific macro assembler and assembler classes
• ◮ Target specific assember constructs instruction words
• ◮ Register allocation
68. Generational GC
• Card marking Write Barriers
Tracer:
Marks and traces
Java Mutator:
Modifies Blue and Green objects
Write barrier on objects
Tracer:
Traces rest of graph
Tracer:
Clean blue object
70. • LLVM IR to JavaScript (Emscripten)
– Python,Ruby,Lua for WebBrowser
– C++ to JavaScript
• JavaScript on LLVM
– Farbic Engine
VM/JIT
72. Garbage Collection
• Pause time
• Pause predictability
• CPU usage
• Memory footprint
• Virtual memory interaction
• Cache interaction
• Effects on program locality
• Compiler and runtime impact