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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:54:52+00:00 2026-06-07T03:54:52+00:00

I am developing a Java instrumentation engine with ASM and there is a situation

  • 0

I am developing a Java instrumentation engine with ASM and there is a situation where the evaluation stack has a certain value on the top and I want to insert a ref (which is the result of a getstatic) before the existing value. I.e. considering the stack with just one value: value ->, then after the getstatic I want the stack become like this: ref, value ->.

To perform this behavior I must insert the following bytecodes: getsatic and swap. With ASM I will do something like (consider mv of the type MethodVisitor):

mv.visitFieldInsn(Opcodes.GETSTATIC, ...);
mv.visitInsn(Opcodes.SWAP);

The problem is that the swap bytecode does not support long and double values. So the code above is fine for single word types, but it does not work correctly for long and double types.

Is there any simple solution to resolve this problem for long and double types and without requiring an auxiliary local value?

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

    Here you have an utility function for ASM that injects the bytecodes for swapping the operands of any type on the top of the stack:

    public static void swap(MethodVisitor mv, Type stackTop, Type belowTop) {
        if (stackTop.getNumberSlots() == 1) {
            if (belowTop.getNumberSlots() == 1) {
                // Top = 1, below = 1
                mv.visitInsn(Opcodes.SWAP);
            } else {
                // Top = 1, below = 2
                mv.visitInsn(Opcodes.DUP_X2);
                mv.visitInsn(Opcodes.POP);
            }
        } else {
            if (belowTop.getNumberSlots() == 1) {
                // Top = 2, below = 1
                mv.visitInsn(Opcodes.DUP2_X1);
            } else {
                // Top = 2, below = 2
                mv.visitInsn(Opcodes.DUP2_X2);
            }
            mv.visitInsn(Opcodes.POP2);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing java web services (JAX-WS) to insert data into mysql DB and
I am developing a Java application using Google App Engine that depends on a
We are busy developing a Java web service for a client. There are two
I am developing a java app for invoking sql stored procedures. There would be
I'm developing a Java EE app (JSF + Richfaces + Tomcat). What I want
I am developing a Java application which has some threads. I print in the
Is there any Eclipse-like (or just any) for developing Java programs from my iPhone?
I am Developing a Java ME Application, Here I want refresh my Form on
While developing a Java project, I place all of my jar files in a
I´m developing a Java EE application and I'm using Struts. When I use html

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.