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

  • Home
  • SEARCH
  • 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 6575859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:26:22+00:00 2026-05-25T15:26:22+00:00

To what extent can a JIT replace platform independent code with processor-specific machine instructions?

  • 0

To what extent can a JIT replace platform independent code with processor-specific machine instructions?

For example, the x86 instruction set includes the BSWAP instruction to reverse a 32-bit integer’s byte order. In Java the Integer.reverseBytes() method is implemented using multiple bitwise masks and shifts, even though in x86 native code it could be implemented in a single instruction using BSWAP. Are JITs (or static compilers for that matter) able to make the change automatically or is it too complex or not worth it due to a poor speed/time tradeoff?

(I know that this is in most cases a micro-optimisation, but I’m interested none the less.)

  • 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-05-25T15:26:22+00:00Added an answer on May 25, 2026 at 3:26 pm

    For this case, yes, the hotspot server compiler could do this optimization. The reverseBytes() methods are registered as vmIntrinsics in hotspot. When jit compiler compile these methods, it will generate a special IR node, not compile the whole method. And this node will be translated into ‘bswap’ in x86. see src/share/vm/opto/library_call.cpp

    //----------------------------   inline_reverseBytes_int/long/char/short-------------------
    // inline Integer.reverseBytes(int)
    // inline Long.reverseBytes(long)
    // inline Character.reverseBytes(char)
    // inline Short.reverseBytes(short)
    bool LibraryCallKit::inline_reverseBytes(vmIntrinsics::ID id) {
      assert(id == vmIntrinsics::_reverseBytes_i || id == vmIntrinsics::_reverseBytes_l ||
             id == vmIntrinsics::_reverseBytes_c || id == vmIntrinsics::_reverseBytes_s,
             "not reverse Bytes");
      if (id == vmIntrinsics::_reverseBytes_i && !Matcher::has_match_rule(Op_ReverseBytesI))  return false;
      if (id == vmIntrinsics::_reverseBytes_l && !Matcher::has_match_rule(Op_ReverseBytesL))  return false;
      if (id == vmIntrinsics::_reverseBytes_c && !Matcher::has_match_rule(Op_ReverseBytesUS)) return false;
      if (id == vmIntrinsics::_reverseBytes_s && !Matcher::has_match_rule(Op_ReverseBytesS))  return false;
      _sp += arg_size();        // restore stack pointer
      switch (id) {
      case vmIntrinsics::_reverseBytes_i:
        push(_gvn.transform(new (C, 2) ReverseBytesINode(0, pop())));
        break;
      case vmIntrinsics::_reverseBytes_l:
        push_pair(_gvn.transform(new (C, 2) ReverseBytesLNode(0,pop_pair())));
        break;
      case vmIntrinsics::_reverseBytes_c:
        push(_gvn.transform(new (C, 2) ReverseBytesUSNode(0, pop())));
        break;
      case vmIntrinsics::_reverseBytes_s:
        push(_gvn.transform(new (C, 2) ReverseBytesSNode(0, pop())));
        break;
      default:
    ;
      }
      return true;
    }
    

    and src/cpu/x86/vm/x86_64.ad

    instruct bytes_reverse_int(rRegI dst) %{
      match(Set dst (ReverseBytesI dst));
    
      format %{ "bswapl  $dst" %}
      opcode(0x0F, 0xC8);  /*Opcode 0F /C8 */
      ins_incode( REX_reg(dst), OpcP, opc2_reg(dst) );
      ins_pipe( ialu_reg );
    %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi can someone point me to some Good Open Source Code to learn Web
Out of order execution in CPUs means that a CPU can reorder instructions to
I'm wondering to what extent I can use associations in Rails. Take into consideration
I'm not sure I quite understand the extent to which undefined behavior can jeopardize
I know that jQuery.extend can be used to add by own custom methods to
I was wondering whether or not I can extend the Enum type in C#
With C# 3.0, I know you can extend methods using the 'this' nomenclature. I'm
In Ruby, there's Modules and you can extend a class by mixing-in the module.
I want button in vertically, for that i can extend the height and shrink
How can I extend a builtin class in python? I would like to add

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.