Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do scripting language interpreters reference their underlying functions?

When it comes to script interpreters, like Rhino, Google V8, Python, etc. - is there any general approach to determining the underlying native methods, given only a string of scripting language?

At some point, do these interpreters use hash maps with strings for keys? Or is there a lot of string equality testing and branches?

like image 362
Ralph Oreg Avatar asked Dec 13 '25 16:12

Ralph Oreg


1 Answers

They typically use hash maps with string keys, but the result of a function lookup is typically cached, to avoid having to do the exact same lookup again a few nanoseconds later.

Of course the cache must be cleared if something crazy happens, like the program assigns to or deletes the function.

JIT compilers can use inline caching to make predictable function calls run very fast once the cache is populated.

The compiler can even just spit out machine code that directly calls the underlying function. Again, if the program replaces or deletes that function, the compiled code would then become invalid; so the interpreter must have a way to detect that situation and update or discard the invalid JIT code.

like image 52
Jason Orendorff Avatar answered Dec 16 '25 20:12

Jason Orendorff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!