[Vm-dev] [Fwd: Image file loading]

Andreas Raab andreas.raab at gmx.de
Tue Jan 19 23:39:59 UTC 2010


John M McIntosh wrote:
> For anonymous mmap I need 
>  fread(imageFile, memStart, fsize(imageFile));
> to mmap allocate and read the file into the anonymous mmap
> 
> readImageFromHeapSize does nothing. 
> 
> or for file based mmap I need 
>  fread(imageFile, memStart, fsize(imageFile));
> to mmap the image file. 
> 
> So I need the readImageFromHeapSize for?

To tell the VM where your memory is located (replacement of sqAlloc*), 
and how much you've pre-allocated. Like I wrote in the original post:

"The VMs would generally use this along the lines of:

   memStart = malloc(heapSize);
   fread(imageFile, memStart, fsize(imageFile));
   readImageFromHeapSize(memStart, heapSize);

etc."

Cheers,
   - Andreas

> On 2010-01-19, at 3:09 PM, Andreas Raab wrote:
> 
>> John M McIntosh wrote:
>>> On 2010-01-19, at 2:30 PM, Andreas Raab wrote:
>>>> b) It trivially allows mmap()ing the entire image into memory (I think
>>>> John does that on the iPhone).
>>> So how is this different that what happens now? 
>> That it removes hundreds of lines of completely unnecessary code. Yes, one can implement the same logic with the current interfaces, I just did that on Android :-) But at some point one must question the approach if the end result is only adding additional complexity.
>>
>> That's why I'm saying move all of this out so that the interpreter doesn't have to deal with it. The task of allocating the initial amount of memory and loading the image into said memory should be done by support code *before* calling the interpreter the first time. Then, give the interpreter one entry point and then remove all the extra complexity. Which means:
>>
>>> #ifndef allocateMemoryMinimumImageFileHeaderSize
>> Gets removed.
>>
>>> /* Called by Interpreter>>allocateMemory:minimum:imageFile:headerSize: */
>>> #define allocateMemoryMinimumImageFileHeaderSize(heapSize, minimumMemory, fileStream, headerSize)  sqAllocateMemory(minimumMemory, heapSize)
>> Gets removed.
>>
>>> #ifndef sqImageFileReadEntireImage
>> Gets removed.
>>
>>> #define sqImageFileReadEntireImage(memoryAddress, elementSize,  length, fileStream)  sqImageFileRead(memoryAddress, elementSize,  length, fileStream)
>> Gets removed.
>>
>>> In platform specfic I change that usqInt sqAllocateMemoryMac(sqInt minHeapSize, sqInt *desiredHeapSize, FILE * f,usqInt headersize);
>> Gets removed.
>>
>>> #ifdef BUILD_FOR_OSX
>>> size_t sqImageFileReadEntireImage(void *ptr, size_t elementSize, size_t count, FILE * f);
>>> #define sqImageFileReadEntireImage(memoryAddress, elementSize,  length, fileStream)  sqImageFileReadEntireImage(memoryAddress, elementSize, length, fileStream)
>>> #else
>>> #define sqImageFileReadEntireImage(memoryAddress, elementSize,  length, fileStream) length #endif
>> Gets removed.
>>
>> Some more things that get removed is in CCodeGenerator>>writeDefaultMacrosOn: a whole bunch of sqImageFile* definitions in sq.h and more.
>>
>> Cheers,
>>  - Andreas
> 
> --
> ===========================================================================
> John M. McIntosh <johnmci at smalltalkconsulting.com>   Twitter:  squeaker68882
> Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
> ===========================================================================
> 
> 
> 
> 


More information about the Vm-dev mailing list