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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:03:31+00:00 2026-06-16T03:03:31+00:00

I am trying to write a Java agent library that is loaded dynamically via

  • 0

I am trying to write a Java agent library that is loaded dynamically via attach api to retransform some methods (those that appear in stack traces of certain threads) for recording method entry/exit. The method entry/exit information is then exported via a custom MBean.

My current “prototype” works so far, as long as the instrumented methods are not native.

According to the documentation of java.lang.instrument.Instrumentation#setNativeMethodPrefix(), it should be possible for java agents to replace the native method with a non-native stub method and add another native method with that prefix in its name which is then bound to the original native method’s native code.

However, when implementing this, I get this error:

java.lang.UnsupportedOperationException: class redefinition failed: attempted to add a method

which is right since I added the new native method.

Only replacing the native method with a non-native one works, but then I cannot delegate the call back to the original native method. Defining the native method in another class does nor work since native methods are looked up by class name and method name and there is no nativeMethodClassSuffix or similar. Defining another class with the same name in another new classloader would work, and I think it might be possible with some indirections to delegate the call to the new class, but one native library can only be linked to native methods loaded by classes of only one class loader, so I won’t get the native methods linked properly.

Is there anything obvious I’m missing here? My code is a bit too long to post here, if anyone thinks it helps I can try to build a small example java agent that shows the problem and link to it here.

  • 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-16T03:03:33+00:00Added an answer on June 16, 2026 at 3:03 am

    Is there anything obvious I’m missing here? My code is a bit too long to post here, if anyone thinks it helps I can try to build a small example java agent that shows the problem and link to it here.

    No. If you mask out a native method, there is no longer any way to call it from JNI. You need to call the method using native code. (I have not idea what that is, but I would be surprised if it is not possible)

    Another option is to change all the references to the native method instead of mask it out. That way you can still call the original method when you choose to.

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

Sidebar

Related Questions

Hi I am trying to write a java applet that will get some hard
I'm trying to write a Java app in GAE that consumes some 3rd party
I'm trying to write Java code that executes some terminal commands. The code should
I am trying at write a java program that hits a url over ssl,
I am trying to write a Java program that reads an input file consisting
I'm trying to write a Java UDF that will rank tuples in a bag
I am trying to write a small Java application that will let me run
I am trying to write a simple Java function that will take a list
I'm trying to write a Java app that imports a data file. The process
I am trying to write a java program that will automatically download and name

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.