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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:33:55+00:00 2026-05-23T07:33:55+00:00

I have been working for two weeks on JamVM, a small but powerful Java

  • 0

I have been working for two weeks on JamVM, a small but powerful Java Virtual Machine.

Now I am trying to figure how the memory is implemented and I am stuck on two C stupid problems:

char *mem = (char*)mmap(0, args->max_heap, PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON, -1, 0);

–> The -1 parameter stands for a file descriptor, what does that mean? (I have aleady read the mmap man, but haven’t found it, maybe I misunderstood…).

heapbase = (char*)(((uintptr_t)mem+HEADER_SIZE+OBJECT_GRAIN-1&)~(OBJECT_GRAIN-1)) HEADER_SIZE;

–> What is 1& ? I don’t find it in the C specification…

Thanks,

Yann

  • 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-23T07:33:56+00:00Added an answer on May 23, 2026 at 7:33 am

    You use the file descriptor when you have an open file that you want to map into memory. In this case, you’re creating an anonymous map (one not backed by a file) so the file descriptor isn’t needed. Some implementations ignore fd for anonymous maps, some require it to be -1.

    The second question is a syntax error (probably a typo). It probably should be something like:

    heapbase = (char*)(((uintptr_t)mem+HEADER_SIZE+OBJECT_GRAIN-1)
        &~(OBJECT_GRAIN-1)) - HEADER_SIZE;
    

    In that case, OBJECT_GRAIN will be a power of two and it’s a way to get alignment to that power. For example, if it were 8, then ~(OBJECT_GRAIN-1) would be ~7 (~00...001112, which is ~11...110002) which, when ANDed with a value, could be used to force that value to the multiple-of-8 less than or equal to it.

    In fact, it’s definitely a transcription error somewhere (not necessarily you) because, when I download the JamVM from here and look in src/alloc.c, I get:

    void initialiseAlloc(InitArgs *args) {
        char *mem = (char*)mmap(0, args->max_heap, PROT_READ|PROT_WRITE,
                                                   MAP_PRIVATE|MAP_ANON, -1, 0);
        :
        << a couple of irrelevant lines >>
        :    
        /* Align heapbase so that start of heap + HEADER_SIZE is object aligned */
        heapbase = (char*)(((uintptr_t)mem+HEADER_SIZE+OBJECT_GRAIN-1)&
                   ~(OBJECT_GRAIN-1))-HEADER_SIZE;
    

    (note that your version is also missing the - immediately before HEADER_SIZE, something else that points to transcription problems).

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

Sidebar

Related Questions

I have a Java application I've been working on for a year or two
I've been learning Android for about two weeks now (expert in as2/3). I have
I've been working with Android for just a couple of weeks now and have
I have been working with relational databases for sometime, but it only recently occurred
I have been working as a native C++ programmer for last few years. Now
I have been working with Struts for some time, but for a project I
These last two weeks have been my first experience with Castle ActiveRecord, and with
for the past two weeks I've been working on coming up with a collision
Hey peoples, I've been studying Java for a couple of weeks, and have decided
I've been working on this site for the past two weeks and everything has

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.