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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:03:58+00:00 2026-05-27T18:03:58+00:00

I am working on a small java bytecode instrumentation tool. The general idea is

  • 0

I am working on a small java bytecode instrumentation tool.

The general idea is to have all of a class methods renamed with a _CONGU suffix, creating then proxy methods with the original method names that will call their _CONGU counterparts.

For instance, if a class C contains a int m() { return 1; } method, the instrumented C class will have a int m_CONGU() { return 1; } method and a int m() { return m_CONGU(); } method.

Later on I’ll add some extra logic on int m() that will do some checks before calling m_CONGU().

At the moment, I am in the process of instrumenting all constructor invocation calls to a method of mine with the _CONGU suffix.

Bellow you can see both the instrumented and non-instrumented versions of the inverse() method of a Fraction class.
enter image description here

When trying to run this code

Fraction fraction = new Fraction(4, 1);

I get the following exception which is puzzling me for the last couple of hours:

Exception in thread “main” java.lang.VerifyError: (class:
jorgeTestes/system/fraction/Fraction, method: inverse_CONGU signature:
()LjorgeTestes/system/fraction/Fraction;) Expecting to find
object/array on stack at
jorgeTestes.system.fraction.XyzTest.main(XyzTest.java:9)

I guess this must be a dead obvious mistake, but I can’t get what the problem might be. It looks to be in some way related to having the wrong number of data in the stack, but it looks to me that the number of elements in the stack is the same both on the original and instrumented code (at least that’s what should be happening). Any ideas?

Some more info:

1) here are the descriptors of both <init> and Fraction_CONGU(which are the same, as one would expect!):
enter image description here

2) I’m wondering if the color of [0] Code being different in Bytecode Viewer could mean there’s some other problem with my instrumented code? Maybe there is some metadata that’s being broken in the process, so that could be the reason the code looks alright and there’s still a problem when trying to run the code?

  • 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-27T18:03:59+00:00Added an answer on May 27, 2026 at 6:03 pm

    It looks like the code on the first screenshot is fundamentally broken. Object construction in JVM bytecode can be split into two phass: allocating memory on the heap and calling a constructor (with optional parameters) against that allocated memory:

    new #1 <Fraction>  //allocate memory
    dup                //duplicate to not loose the object after calling constructor
                       //push c-tor args onto the stack here
    invokespecial <Fraction.<init>>  //constructor, second `this` is lost
    areturn            //returns first `this`
    

    What you are basically doing is: allocate some raw (probably zeroed) memory on the heap and invoke virtual method Fraction_congu against that memory block. You haven’t yet called the constructor!

    Also there should be invokevirtual, I guess this generated methods are private.

    UPDATE: I assume you want to transform the following class:

    class Fraction {
    
        public Fraction(float den, float num) {
            //original constructor code here
        }
    
        public int m() {
            return 1;
        }
    }
    

    Into:

    class Fraction {
    
        public Fraction(float den, float num) {
            //proxy method
            //place for extra logic 
            Fraction_CONGU(den, num);
        }
    
        private Fraction_CONGU(float den, float num) {
            //original constructor code here
        }
    
        public int m() {
            //proxy method
            //place for extra logic 
            return m_CONGU
        }
    
        private int m_CONGU() {
            return 1;
        }
    }
    

    As you can see it is perfectly possible (if I get your idea correctly). Just compile this Java code and see how compiler implemented this.

    Which begs a question: can’t you just use AspectJ with compile time-weaving?

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

Sidebar

Related Questions

Im working on a small application to try out an idea that I have.
I have been working for two weeks on JamVM, a small but powerful Java
Working on a small Java tool to get a set of files based on
I now have a small java script server working correctly, called by: <?php $handle
I'm working on a small Java project that now connects to a MS SQL
I'm working on a small (java) project where a website needs to maintain a
I'm working on a small UML editor project, in Java, that I started a
I'm working on a small application in Java that takes a directory structure and
I'm working on as small game for class and was wondering what is a
I just started working on upgrading a small component in a distributed java application.

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.