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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:53:45+00:00 2026-06-11T12:53:45+00:00

On my code I do a lot of reflection lookups, so I was trying

  • 0

On my code I do a lot of reflection lookups, so I was trying to improve it somehow.

This is a sample of my jni setter method:

JNIEXPORT jobject JNICALL 
Java_org_orman_mapper_Model_fieldSetFloat(JNIEnv * env, jobject  obj, jobject model, jstring field_name, jstring field_type, jfloat value, jclass clazz)
{
    const char* utf_string_name = (*env)->GetStringUTFChars (env, field_name, 0);
    const char* utf_string_type = (*env)->GetStringUTFChars (env, field_type, 0);

    jfieldID id = (*env)->GetFieldID(env, clazz, utf_string_name, utf_string_type);
    (*env)->SetFloatField(env, model, id, value);
    return model;
}

The intrisics of calls like SetFloatField, does it skip any java security checks?

I haven’t noticed any gain on performance.

  • 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-11T12:53:46+00:00Added an answer on June 11, 2026 at 12:53 pm

    Is it possible to enhance reflection performance with jni?

    Possibly, a bit. But while you can eliminate “unwanted” access checks, you lose some of that by the fact that you have to make JNI calls to access the object’s innards. By contrast, the implementation of the reflection methods and their calling sequences may be optimized in ways that are not available to a regular JNI method.

    (For instance, they may be implemented to directly access the relevant data structures rather than using the platform independent JNI API. Or the JIT compiler may treat native method calls to some “intrinsic” native methods as special cases … and use a faster calling sequence. Note that this is all hypothetical … but in some JVMs, the native implementations of some core methods have been given special treatment to make them faster.)


    But my advice is that you will get much better performance (by an order of magnitude or more) if you replace the reflective code with regular non-reflective Java code, whether it is hand-written code, code that is generated as source and compiled, or code that is generated as bytecodes. Once you have bytecodes, the JIT compiler will be able to produced optimized native code that will be far faster than using either reflection or JNI.

    So rather than replacing reflection with JNI code (and the its associated problems), replace it with something that that uses pure bytecodes.

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

Sidebar

Related Questions

I have lot of code in my Tornado app which looks like this: @tornado.web.asynchronous
In my project I have a lot of code like this: int[][] a =
I want to customize the reflection from the FlowCover (Cover Flow remake) sample code.
I write something similar to the following code a lot. It basically toggles an
In VB.NET, I could make my math code a lot cleaner by Importing System.Math
A lot of code in a current project is directly related to displaying things
I have just refactored a lot of code out of my AccountController into an
I am have a lot of code that I need to optimize and make
I see a lot of code similar to the following var customrs = MyDataContext.Customers.Where(...);
I'm working on a code with a lot of $(.blahblah).size()>0 conditions in it. I

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.