Next: , Up: objects codes   [Index]


13.23.1 Memory layout of code objects

A code object is a memory block, of variable size, referenced by machine words tagged as vectors; the memory is allocated with mmap() and is given read, write and execution protection. The layout of a code object is as follows:

|-----------|-----------------------------------| code object
  meta data                 data area

the data area is filled with executable machine code.

The first machine word of a code memory block is tagged has code in its least significant bits and it has the most significant bits set to zero.

|------------------------|-------------| reference to code
    memory pointer         vector tag

|------------------------|-------------| code first word
   all set to zero          code tag

Boot image code objects

Scheme code objects which are part of the boot image are of 2 categories:

  1. Small code objects whose size fits in a single Vicare page. Small code objects are allocated in the “current code page” while the boot image is loaded: a Vicare page marked as used “for code”, in which code objects are stored one after the other, with size aligned to exact multiples of 16 bytes:
                        current code page
    |..........................................................|
    
      code object   code object   code object       free
    |.............|.............|.............|++++++++++++++++|
    |----------------------------------------------------------|
    

    the free room at the end of the sequence of code objects is lost.

  2. Large code objects whose size fits in a sequence of adjacent Vicare pages.
        page        page        page        page        page
    |...........|...........|...........|...........|...........|
    
                    large code object                     free
    |---------------------------------------------------|+++++++|
    

    the free room at the end of the sequence of pages is lost. Large code objects are never moved by the garbage collector.

Meta data in a code memory block

The first words of a code memory block hold meta data:

  1. The first word contains the secondary tag needed to recognise a Scheme object as code object.
  2. The second word contains a non–negative fixnum representing the number of used bytes in the data area.
  3. The third word contains the reference to a Scheme vector used as relocation vector.
  4. The fourth word contains a non–negative fixnum representing the number of free variables in the contained code. If such value is zero: the code is a thunk, otherwise it is a closure.
  5. The fifth word contains a code annotation; it is initialised to #f.
  6. The sixth word is currently unused; it is initialised to the fixnum zero.

the subsequent words in the memory block are the code object’s data area.


Next: , Up: objects codes   [Index]