+
+ // we always need to stop the world to make threads save the CPU registers
+ // in the stack and prepare themselves for thread_scanAll()
+ thread_suspendAll();
+ gc.stats.world_stopped();
+
+ if (opts.options.fork) {
+ os.pid_t child_pid = os.fork();
+ assert (child_pid != -1); // don't accept errors in non-release mode
+ switch (child_pid) {
+ case -1: // if fork() fails, fallback to stop-the-world
+ opts.options.fork = false;
+ break;
+ case 0: // child process (i.e. the collectors mark phase)
+ mark(stackTop);
+ cstdlib.exit(0);
+ break; // bogus, will never reach here
+ default: // parent process (i.e. the mutator)
+ // start the world again and wait for the mark phase to finish
+ thread_resumeAll();
+ gc.stats.world_started();
+ int status = void;
+ os.pid_t wait_pid = os.waitpid(child_pid, &status, 0);
+ assert (wait_pid == child_pid);
+ return sweep();
+ }
+
+ }
+
+ // if we reach here, we are using the standard stop-the-world collection