]> gitweb.factorcode.org Git - factor.git/commitdiff
VM: move the paths out of gc memory so that they arent unnecessarily
authorBjörn Lindqvist <bjourne@gmail.com>
Sun, 12 Jul 2015 04:37:54 +0000 (06:37 +0200)
committerBjörn Lindqvist <bjourne@gmail.com>
Sun, 12 Jul 2015 20:36:59 +0000 (22:36 +0200)
added to the image

vm/image.cpp

index f9757d1dd6407b8dbf40ac72a8d28efa52e2cc2c..2acaea86958bff944d3ab847518bcc61be15f150 100644 (file)
@@ -295,15 +295,19 @@ bool factor_vm::save_image(const vm_char* saving_filename,
 }
 
 void factor_vm::primitive_save_image() {
+  byte_array* path2 = tagged<byte_array>(ctx->pop()).untag_check(this);
+  byte_array* path1 = tagged<byte_array>(ctx->pop()).untag_check(this);
+
+  vm_char* path1_saved = safe_strdup(path1->data<vm_char>());
+  vm_char* path2_saved = safe_strdup(path2->data<vm_char>());
+
   /* do a full GC to push everything into tenured space */
   primitive_compact_gc();
 
-  data_root<byte_array> path2(ctx->pop(), this);
-  path2.untag_check(this);
-  data_root<byte_array> path1(ctx->pop(), this);
-  path1.untag_check(this);
-  save_image((vm_char*)(path1.untagged() + 1),
-             (vm_char*)(path2.untagged() + 1));
+  save_image(path1_saved, path2_saved);
+
+  free(path1_saved);
+  free(path2_saved);
 }
 
 /* Allocates memory */
@@ -311,10 +315,13 @@ void factor_vm::primitive_save_image_and_exit() {
   /* We unbox this before doing anything else. This is the only point
      where we might throw an error, so we have to throw an error here since
      later steps destroy the current image. */
-  data_root<byte_array> path2(ctx->pop(), this);
-  path2.untag_check(this);
-  data_root<byte_array> path1(ctx->pop(), this);
-  path1.untag_check(this);
+  byte_array* path2 = tagged<byte_array>(ctx->pop()).untag_check(this);
+  byte_array* path1 = tagged<byte_array>(ctx->pop()).untag_check(this);
+
+  /* Copy the paths to non-gc memory to avoid them hanging around in
+     the saved image. */
+  vm_char* path1_saved = safe_strdup(path1->data<vm_char>());
+  vm_char* path2_saved = safe_strdup(path2->data<vm_char>());
 
   /* strip out special_objects data which is set on startup anyway */
   for (cell i = 0; i < special_object_count; i++)
@@ -329,8 +336,7 @@ void factor_vm::primitive_save_image_and_exit() {
   gc(collect_compact_op, 0 /* requested size */);
 
   /* Save the image */
-  if (save_image((vm_char*)(path1.untagged() + 1),
-                 (vm_char*)(path2.untagged() + 1)))
+  if (save_image(path1_saved, path2_saved))
     exit(0);
   else
     exit(1);