Beispiel #1
0
void Squeak_Image_Reader::read_image() {
/*

readImageFromFile: f HeapSize: desiredHeapSize StartingAt: imageOffset
   "Read an image from the given file stream, allocating the given amount of
    memory to its object heap. Fail if the image has an unknown format or
    requires more than the given amount of memory."
    
   "Details: This method detects when the image was stored on a machine with
    the opposite byte ordering from this machine and swaps the bytes
    automatically. Furthermore, it allows the header information to start 512
    bytes into the file, since some file transfer programs for the Macintosh
    apparently prepend a Mac-specific header of this size. Note that this same
    512 bytes of prefix area could also be used to store an exec command on
    Unix systems, allowing one to launch Smalltalk by invoking the image name
    as a command."
    
   "This code is based on C code by Ian Piumarta and Smalltalk code by Tim
    Rowledge. Many thanks to both of you!!"
*/

  Object::verify_constants();

  read_header();

  fprintf(stdout, "allocating memory for snapshot\n");

  // "allocate a contiguous block of memory for the Squeak heap"
  memory = (char*)Memory_Semantics::shared_malloc(dataSize);
  assert_always(memory != NULL);

  /*
	memStart := self startOfMemory.
	memoryLimit := (memStart + heapSize) - 24.  "decrease memoryLimit a tad for safety"
	endOfMemory := memStart + dataSize.
  */

  // "position file after the header"
  fprintf(stdout, "reading objects in snapshot\n");
  if ( fseek(image_file, headerStart + headerSize, SEEK_SET))
    perror("seek"), fatal();

  // "read in the image in bulk, then swap the bytes if necessary"
  xfread(memory, 1, dataSize, image_file);

  // "First, byte-swap every word in the image. This fixes objects headers."
  if (swap_bytes) reverseBytes((int32*)&memory[0], (int32*)&memory[dataSize]);

  // "Second, return the bytes of bytes-type objects to their orginal order."
  if (swap_bytes) byteSwapByteObjects();
  
  Safepoint_Ability sa(false); // for distributing objects and putting image name
  distribute_objects();
  imageNamePut_on_all_cores(file_name, strlen(file_name));
  
  // we need to reoder floats if the image was a Cog image
  if (is_cog_image_with_reodered_floats()) {
    normalize_float_ordering_in_image();
  }
}
Beispiel #2
0
void Squeak_Image_Reader::fake_read(char* fileName, Memory_System* ms, Squeak_Interpreter* i) {
  Squeak_Image_Reader* sir = new Squeak_Image_Reader(fileName, ms, i);
  sir->read_header();

  //mimic reader
  Memory_Semantics::shared_malloc(sir->dataSize);
  malloc(sir->dataSize);

  i->restore_all_from_checkpoint(sir->dataSize, sir->lastHash, sir->savedWindowSize, sir->fullScreenFlag);
  imageNamePut_on_all_cores(sir->file_name, strlen(sir->file_name));
}