Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8469893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:21:32+00:00 2026-06-10T16:21:32+00:00

In dynamic languages, how is dynamically typed code JIT compiled into machine code? More

  • 0

In dynamic languages, how is dynamically typed code JIT compiled into machine code? More specifically: does the compiler infer the types at some point? Or is it strictly interpreted in these cases?

For example, if I have something like the following pseuocode

def func(arg)
    if (arg)
        return 6
    else
        return "Hi"

How can the execution platform know before running the code what the return type of the function is?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T16:21:33+00:00Added an answer on June 10, 2026 at 4:21 pm

    In general, it doesn’t. However, it can assume either type, and optimize for that. The details depend on what kind of JIT it is.

    The so-called tracing JIT compilers interpret and observe the program, and record types, branches, etc. for a single run (e.g. loop iteration). They record these observations, insert a (quite fast) check that these assumptions are still true when the code is executed, and then optimize the heck out of the following code based on these assuptions. For example, if your function is called in a loop with a constantly true argument and adds one to it, the JIT compiler first records instructions like this (we’ll ignore call frame management, memory allocation, variable indirection, etc. not because those aren’t important, but because they take a lot of code and are optimized away too):

    ; calculate arg
    guard_true(arg)
    boxed_object o1 = box_int(6)
    guard_is_boxed_int(o1)
    int i1 = unbox_int(o1)
    int i2 = 1
    i3 = add_int(res2, res3)
    

    and then optimizes it like this:

    ; calculate arg
    ; may even be elided, arg may be constant without you realizing it
    guard_true(arg)
    ; guard_is_boxed_int constant-folded away
    ; unbox_int constant-folded away
    ; add_int constant-folded away
    int i3 = 7
    

    Guards can also be moved to allow optimizing earlier code, combined to have fewer guards, elided if they are redundant, strengthened to allow more optimizations, etc.
    If guards fail too frequently, or some code is otherwise rendered useless, it can be discarded, or at least patched to jump to a different version on guard failure.

    Other JITs take a more static approach. For instance, you can do quick, inaccurate type inference to at least recognize a few operations. Some JIT compilers only operate on function scope (they are thus called method JIT compilers by some), so they probably can’t make much of your code snippet (one reason tracing JIT compilers are very popular for). Nevertheless, they exist — an example is the latest revision of Mozilla’s JavaScript engine, Ion Monkey, although it apparently takes inspiration from tracing JITs as well. You can also insert add not-always-valid optimizations (e.g. inline a function that may be changed later) and remove them when they become wrong.

    When all else fails, you can do what interpreters do, box objects, use pointers to them, tag the data, and select code based on the tag. But this is extremely inefficient, the whole purpose of JIT compilers is getting rid of that overhead, so they will only do that when there is no reasonable alternative (or when they are still warming up).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm studying JIT design with regard to dynamic languages VM implementation. I haven't done
I recently got into Java. I have a background in dynamic languages and I'm
Dynamic languages are on the rise and there are plenty of them: e.g. Ruby,
Perhaps I am limited by my experience with dynamic languages (Ruby on Netbeans and
Possible Duplicate: What’s with the love of dynamic Languages I have already read this
Preamble To build dynamic web-sites, we have to master at least four languages: HTML
I used code from http://viralpatel.net/blogs/dynamic-add-textbox-input-button-radio-element-html-javascript/ html-javascript/ .my code is this: <HTML> <HEAD> <TITLE>Dynamically add
I created a TabPanel on my aspx file. In my code behind, I dynamically
I use e-texteditor as my primary editor, in which you can execute dynamic languages
The following code block allows the user creates textbox controls dynamically. However, on each

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.