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 9018333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:30:00+00:00 2026-06-16T04:30:00+00:00

Possible Duplicate: What makes JNI calls slow? First let me say that this questions

  • 0

Possible Duplicate:
What makes JNI calls slow?

First let me say that this questions is born more out of curiosity than real necessity.

I’m curious to know what is the overhead in doing a JNI call from Java, with say, System.arraycopy versus allocating the array and copying the elements over with a for loop.

If the overhead is substantial, then there is probably a rough “magic number” of elements up to which it compensates to simply use a for loop, instead of using the System call. And also, what exactly is involved in the System call that causes this overhead?
I’m guessing the stack must be pushed to the context of the call, and that might take a while, but I can’t find a good explanation for the whole process.

Let me clarify my question:

I know that using arraycopy is the fastest way to copy an array in Java.

That being said, let’s say I’m using it to copy an array of only one element. Since I’m calling the underlying OS to do so, there has to be an overhead in this call. I’m interested in knowing what this overhead is and what happens in the process of the call.

I’m sorry if using arraycopy misled you from the purpose of my question. I’m interested to know the overhead of a JNI call, and what’s involved in the actual call.

  • 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-16T04:30:01+00:00Added an answer on June 16, 2026 at 4:30 am

    Since I’m calling the underlying OS to do so…

    You are right that system calls are fairly expensive. However, the System in System.arraycopy() is a bit of a misnomer. There are no system calls involved.

    …there has to be an overhead in this call. I’m interested in knowing what this overhead is and what happens in the process of the call.

    When you look at the definition of System.arraycopy(), it’s declared as native. This means that the method is implemented in C++. If you were so inclined, you could look at the JDK source code, and find the C++ function. In OpenJDK 7, it’s called JVM_ArrayCopy() and lives in hotspot/src/share/vm/prims/jvm.cpp. The implementation is surprisingly complicated, but deep down it’s essentially a memcpy().

    If arraycopy() is being used as a normal native function, there’s overhead to calling it. There’s further overhead caused by argument checking etc.

    However, it’s very likely that the JIT compiler knows about System.arraycopy(). This means that, instead of calling the C++ function, the compiler knows how to generate specially-crafted machine code to carry out the array copy. I don’t know about other JVMs, but HotSpot does have such “intrinsic” support for System.arraycopy().

    Let’s say I’m using it to copy an array of only one element

    If your array is tiny, you may be able to beat System.arraycopy() with a hand-crafted loop. You can probably do even better if the size is known at compile time, since then you can also unroll the loop. However, all of that is not really relevant except in the narrowest of circumstances.

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

Sidebar

Related Questions

Possible Duplicate: Make error: missing separator I am so stressed out by this silly
Possible Duplicate: Currying subtraction I started my first haskell project that is not from
Possible Duplicate: CSS Sprites and repeating backgrounds Are there any tricks that makes it
Possible Duplicate: Java REPL shell Is there a project that makes a command prompt
Possible Duplicate: Threads synchronization. How exactly lock makes access to memory 'correct'? This question
Possible Duplicate: What makes more sense - char* string or char *string? Sorry if
Possible Duplicates: What makes more sense - char* string or char *string? Pointer declarations
Possible Duplicate: jQuery voting system I've been using this tutorial to create a voting
Possible Duplicate: file_put_contents permission denied I have recently transferred server, and it seems that
Possible Duplicate: Do write-only properties have practical applications? A getter without a setter makes

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.