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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:04:48+00:00 2026-05-24T16:04:48+00:00

I want to know the location that JVM allocates to objects being placed in

  • 0

I want to know the location that JVM allocates to objects being placed in the system memory.

  • 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-24T16:04:48+00:00Added an answer on May 24, 2026 at 4:04 pm

    This is something you probably don’t want to do.

    If you really want to do this, something like this code might help:

    package test;
    
    import java.lang.reflect.Field;
    
    import sun.misc.Unsafe;
    
    public class Addresser
    {
        private static Unsafe unsafe;
    
        static
        {
            try
            {
                Field field = Unsafe.class.getDeclaredField("theUnsafe");
                field.setAccessible(true);
                unsafe = (Unsafe)field.get(null);
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
        }
    
        public static long addressOf(Object o)
        throws Exception
        {
            Object[] array = new Object[] {o};
    
            long baseOffset = unsafe.arrayBaseOffset(Object[].class);
            int addressSize = unsafe.addressSize();
            long objectAddress;
            switch (addressSize)
            {
                case 4:
                    objectAddress = unsafe.getInt(array, baseOffset);
                    break;
                case 8:
                    objectAddress = unsafe.getLong(array, baseOffset);
                    break;
                default:
                    throw new Error("unsupported address size: " + addressSize);
            }       
    
            return(objectAddress);
        }
    
    
        public static void main(String... args)
        throws Exception
        {   
            Object mine = "Hi there".toCharArray();
            long address = addressOf(mine);
            System.out.println("Addess: " + address);
    
            //Verify address works - should see the characters in the array in the output
            printBytes(address, 27);
    
        }
    
        public static void printBytes(long objectAddress, int num)
        {
            for (long i = 0; i < num; i++)
            {
                int cur = unsafe.getByte(objectAddress + i);
                System.out.print((char)cur);
            }
            System.out.println();
        }
    }
    

    But

    • not portable across JVMs or even different versions
    • objects can move because of GC at any time, and cannot synchronize across GCs so results might not make sense
    • not tested across all architectures, endianess, etc. might make this not work everywhere
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to know what exactly is the sequence of calls that occurs when
I want to know how to use variables for objects and function names in
I'm developing an iPhone application and I want to know the location on a
Using .net's setup project, I want to write the location that my software is
I know when reading from a location of memory which is written to by
I want to know if i can develop an app that would download books
i want to know if it's possible to implement following behaviors: take system app
What I know that window.location.hash = hash_url is used to hashify the URL. Suppose
I want to make an app that shows where is a location on screen.
I used to think that each memory location contains 8, 16, 32 or 64

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.