]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' into new_gc
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Thu, 22 Oct 2009 10:40:57 +0000 (05:40 -0500)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Thu, 22 Oct 2009 10:40:57 +0000 (05:40 -0500)
1  2 
basis/cpu/x86/x86.factor
vm/errors.cpp
vm/mach_signal.cpp
vm/vm.hpp

diff --combined basis/cpu/x86/x86.factor
index e061ea5d9570a0d4f4b24fb6a02ebebe143f2668,d19a9b0c8c2400c549e89fd0d8d339cd4ca951dd..938bb3a8df95a8b53bd62d920095c40ebe24b19c
@@@ -388,7 -388,7 +388,7 @@@ M: x86 %vm-field-ptr ( dst field -- 
      [ drop "nursery" %vm-field-ptr ] [ swap [] MOV ] 2bi ;
  
  : inc-allot-ptr ( nursery-ptr n -- )
 -    [ [] ] dip 8 align ADD ;
 +    [ [] ] dip data-alignment get align ADD ;
  
  : store-header ( temp class -- )
      [ [] ] [ type-number tag-fixnum ] bi* MOV ;
@@@ -888,12 -888,12 +888,12 @@@ M: x86 %compare-vector ( dst src1 src2 
      {
          { sse? { float-4-rep } }
          { sse2? { double-2-rep char-16-rep short-8-rep int-4-rep } }
-         { sse4.1? { longlong-2-rep } }
+         { sse4.2? { longlong-2-rep } }
      } available-reps ;
  
  M: x86 %compare-vector-reps
      {
-         { [ dup { cc= cc/= } memq? ] [ drop %compare-vector-eq-reps ] }
+         { [ dup { cc= cc/= cc/<>= cc<>= } memq? ] [ drop %compare-vector-eq-reps ] }
          [ drop %compare-vector-ord-reps ]
      } cond ;
  
@@@ -1098,7 -1098,7 +1098,7 @@@ M: x86 %min-vector ( dst src1 src2 rep 
  M: x86 %min-vector-reps
      {
          { sse? { float-4-rep } }
-         { sse2? { uchar-16-rep short-8-rep double-2-rep short-8-rep uchar-16-rep } }
+         { sse2? { uchar-16-rep short-8-rep double-2-rep } }
          { sse4.1? { char-16-rep ushort-8-rep int-4-rep uint-4-rep } }
      } available-reps ;
  
@@@ -1118,7 -1118,7 +1118,7 @@@ M: x86 %max-vector ( dst src1 src2 rep 
  M: x86 %max-vector-reps
      {
          { sse? { float-4-rep } }
-         { sse2? { uchar-16-rep short-8-rep double-2-rep short-8-rep uchar-16-rep } }
+         { sse2? { uchar-16-rep short-8-rep double-2-rep } }
          { sse4.1? { char-16-rep ushort-8-rep int-4-rep uint-4-rep } }
      } available-reps ;
  
diff --combined vm/errors.cpp
index 6268ca695da41b7f2d1f991666bc6c48397257d2,c587fa723a32d1a2a603a3c0e3cffe9415e98d88..148799446aa62b54456cd62a24f2bf3edcf8ee7d
@@@ -5,24 -5,22 +5,24 @@@ namespace facto
  
  void fatal_error(const char *msg, cell tagged)
  {
 -      print_string("fatal_error: "); print_string(msg);
 -      print_string(": "); print_cell_hex(tagged); nl();
 +      std::cout << "fatal_error: " << msg;
 +      std::cout << ": " << std::hex << tagged << std::dec;
 +      std::cout << std::endl;
        exit(1);
  }
  
  void critical_error(const char *msg, cell tagged)
  {
 -      print_string("You have triggered a bug in Factor. Please report.\n");
 -      print_string("critical_error: "); print_string(msg);
 -      print_string(": "); print_cell_hex(tagged); nl();
 +      std::cout << "You have triggered a bug in Factor. Please report.\n";
 +      std::cout << "critical_error: " << msg;
 +      std::cout << ": " << std::hex << tagged << std::dec;
 +      std::cout << std::endl;
        tls_vm()->factorbug();
  }
  
  void out_of_memory()
  {
 -      print_string("Out of memory\n\n");
 +      std::cout << "Out of memory\n\n";
        tls_vm()->dump_generations();
        exit(1);
  }
@@@ -61,10 -59,10 +61,10 @@@ void factor_vm::throw_error(cell error
        crash. */
        else
        {
 -              print_string("You have triggered a bug in Factor. Please report.\n");
 -              print_string("early_error: ");
 +              std::cout << "You have triggered a bug in Factor. Please report.\n";
 +              std::cout << "early_error: ";
                print_obj(error);
 -              nl();
 +              std::cout << std::endl;
                factorbug();
        }
  }
@@@ -114,7 -112,7 +114,7 @@@ void factor_vm::memory_protection_error
  
  void factor_vm::signal_error(int signal, stack_frame *native_stack)
  {
-       general_error(ERROR_SIGNAL,tag_fixnum(signal),false_object,native_stack);
+       general_error(ERROR_SIGNAL,allot_cell(signal),false_object,native_stack);
  }
  
  void factor_vm::divide_by_zero_error()
diff --combined vm/mach_signal.cpp
index d733e6b3bc9efad6e7ebc7af621d65c5324df6e6,d05942ff7efe3c6cff315a9d888713639ed79110..3fa7dcbf078c3aa9534a7b83eaa3a0472015d86b
@@@ -47,7 -47,7 +47,7 @@@ void factor_vm::call_fault_handler
        else
                signal_callstack_top = NULL;
  
-       MACH_STACK_POINTER(thread_state) = fix_stack_pointer(MACH_STACK_POINTER(thread_state));
+       MACH_STACK_POINTER(thread_state) = align_stack_pointer(MACH_STACK_POINTER(thread_state));
  
        /* Now we point the program counter at the right handler function. */
        if(exception == EXC_BAD_ACCESS)
        }
        else
        {
-               signal_number = (exception == EXC_ARITHMETIC ? SIGFPE : SIGABRT);
+               switch(exception)
+               {
+               case EXC_ARITHMETIC: signal_number = SIGFPE; break;
+               case EXC_BAD_INSTRUCTION: signal_number = SIGILL; break;
+               default: signal_number = SIGABRT; break;
+               }
                MACH_PROGRAM_COUNTER(thread_state) = (cell)factor::misc_signal_handler_impl;
        }
  }
@@@ -78,7 -84,7 +84,7 @@@ static void call_fault_handler
  {
        THREADHANDLE thread_id = pthread_from_mach_thread_np(thread);
        assert(thread_id);
 -      unordered_map<THREADHANDLE, factor_vm*>::const_iterator vm = thread_vms.find(thread_id);
 +      std::map<THREADHANDLE, factor_vm*>::const_iterator vm = thread_vms.find(thread_id);
        if (vm != thread_vms.end())
            vm->second->call_fault_handler(exception,code,exc_state,thread_state,float_state);
  }
@@@ -226,7 -232,7 +232,7 @@@ void mach_initialize (
                fatal_error("mach_port_insert_right() failed",0);
  
        /* The exceptions we want to catch. */
-       mask = EXC_MASK_BAD_ACCESS | EXC_MASK_ARITHMETIC;
+       mask = EXC_MASK_BAD_ACCESS | EXC_MASK_BAD_INSTRUCTION | EXC_MASK_ARITHMETIC;
  
        /* Create the thread listening on the exception port.  */
        start_thread(mach_exception_thread,NULL);
diff --combined vm/vm.hpp
index 40dcb4f3bc05567f46d0aad17fd52c8fb14582f1,2c85b8ec490dd15f626cf009972e79de29e7e49d..78efc915d71b5d938e5b72ea7d61d3e7cb75cded
+++ b/vm/vm.hpp
@@@ -11,7 -11,7 +11,7 @@@ struct factor_v
        context *ctx;
        
        /* New objects are allocated here */
 -      zone nursery;
 +      nursery_space nursery;
  
        /* Add this to a shifted address to compute write barrier offsets */
        cell cards_offset;
@@@ -39,6 -39,9 +39,6 @@@
        unsigned int signal_fpu_status;
        stack_frame *signal_callstack_top;
  
 -      /* Zeroes out deallocated memory; set by the -securegc command line argument */
 -      bool secure_gc;
 -
        /* A heap walk allows useful things to be done, like finding all
           references to an object for debugging purposes. */
        cell heap_scan_ptr;
@@@ -46,9 -49,6 +46,9 @@@
        /* GC is off during heap walking */
        bool gc_off;
  
 +      /* GC logging */
 +      bool verbosegc;
 +
        /* Data heap */
        data_heap *data;
  
  
        //data heap
        void init_card_decks();
 -      void clear_cards(old_space *gen);
 -      void clear_decks(old_space *gen);
 -      void reset_generation(old_space *gen);
        void set_data_heap(data_heap *data_);
 -      void init_data_heap(cell young_size, cell aging_size, cell tenured_size, bool secure_gc_);
 -      cell untagged_object_size(object *pointer);
 -      cell unaligned_object_size(object *pointer);
 +      void init_data_heap(cell young_size, cell aging_size, cell tenured_size);
        void primitive_size();
        cell binary_payload_start(object *pointer);
        void primitive_data_room();
        #endif
        }
  
 -      inline void check_tagged_pointer(cell tagged)
 -      {
 -      #ifdef FACTOR_DEBUG
 -              if(!immediate_p(tagged))
 -              {
 -                      object *obj = untag<object>(tagged);
 -                      check_data_pointer(obj);
 -                      obj->h.hi_tag();
 -              }
 -      #endif
 -      }
 -
        // generic arrays
 -      template<typename Array> Array *allot_array_internal(cell capacity);
 +      template<typename Array> Array *allot_uninitialized_array(cell capacity);
        template<typename Array> bool reallot_array_in_place_p(Array *array, cell capacity);
        template<typename Array> Array *reallot_array(Array *array_, cell capacity);
  
        void print_callstack();
        void dump_cell(cell x);
        void dump_memory(cell from, cell to);
 -      void dump_zone(const char *name, zone *z);
 +      template<typename Generation> void dump_generation(const char *name, Generation *gen);
        void dump_generations();
        void dump_objects(cell type);
        void find_data_references_step(cell *scan);
        inline void set_array_nth(array *array, cell slot, cell value);
  
        //strings
 -      cell string_nth(string* str, cell index);
 +      cell string_nth(const string *str, cell index);
        void set_string_nth_fast(string *str, cell index, cell ch);
        void set_string_nth_slow(string *str_, cell index, cell ch);
        void set_string_nth(string *str, cell index, cell ch);
        inline double untag_float_check(cell tagged);
        inline fixnum float_to_fixnum(cell tagged);
        inline double fixnum_to_float(cell tagged);
 +
 +      // tagged
        template<typename Type> Type *untag_check(cell value);
 -      template<typename Type> Type *untag(cell value);
  
        //io
        void init_c_io();
        void update_literal_references(code_block *compiled);
        void relocate_code_block_step(relocation_entry rel, cell index, code_block *compiled);
        void update_word_references(code_block *compiled);
 -      void update_code_block_for_full_gc(code_block *compiled);
 +      void update_code_block_words_and_literals(code_block *compiled);
        void check_code_address(cell address);
        void relocate_code_block(code_block *compiled);
        void fixup_labels(array *labels, code_block *compiled);
 -      code_block *allot_code_block(cell size, cell type);
 -      code_block *add_code_block(cell type, cell code_, cell labels_, cell owner_, cell relocation_, cell literals_);
 +      code_block *allot_code_block(cell size, code_block_type type);
 +      code_block *add_code_block(code_block_type type, cell code_, cell labels_, cell owner_, cell relocation_, cell literals_);
  
        //code heap
        inline void check_code_pointer(cell ptr)
        bool in_code_heap_p(cell ptr);
        void jit_compile_word(cell word_, cell def_, bool relocate);
        void update_code_heap_words();
 +      void update_code_heap_words_and_literals();
 +      void relocate_code_heap();
        void primitive_modify_code_heap();
        void primitive_code_room();
        void forward_object_xts();
        void primitive_strip_stack_traces();
  
        /* Apply a function to every code block */
 -      template<typename Iterator> void iterate_code_heap(Iterator &iter)
 -      {
 -              heap_block *scan = code->first_block();
 -
 -              while(scan)
 +      template<typename Iterator> struct code_heap_iterator {
 +              Iterator &iter;
 +              explicit code_heap_iterator(Iterator &iter_) : iter(iter_) {}
 +              void operator()(heap_block *block, cell size)
                {
 -                      if(scan->type() != FREE_BLOCK_TYPE)
 -                              iter((code_block *)scan);
 -                      scan = code->next_block(scan);
 +                      iter((code_block *)block,size);
                }
 +      };
 +
 +      template<typename Iterator> void iterate_code_heap(Iterator &iter_)
 +      {
 +              code_heap_iterator<Iterator> iter(iter_);
 +              code->allocator->iterate(iter);
        }
  
        //callbacks
        void primitive_callstack();
        void primitive_set_callstack();
        code_block *frame_code(stack_frame *frame);
 -      cell frame_type(stack_frame *frame);
 +      code_block_type frame_type(stack_frame *frame);
        cell frame_executing(stack_frame *frame);
        stack_frame *frame_successor(stack_frame *frame);
        cell frame_scan(stack_frame *frame);
        void windows_image_path(vm_char *full_path, vm_char *temp_path, unsigned int length);
        bool windows_stat(vm_char *path);
  
-    #if defined(WINNT)
+   #if defined(WINNT)
        void open_console();
        LONG exception_handler(PEXCEPTION_POINTERS pe);
-       // next method here:
-    #endif
+   #endif
    #else  // UNIX
-       void memory_signal_handler(int signal, siginfo_t *siginfo, void *uap);
-       void misc_signal_handler(int signal, siginfo_t *siginfo, void *uap);
-       void fpe_signal_handler(int signal, siginfo_t *siginfo, void *uap);
-       stack_frame *uap_stack_pointer(void *uap);
+       void dispatch_signal(void *uap, void (handler)());
    #endif
  
    #ifdef __APPLE__
  
  };
  
 -extern unordered_map<THREADHANDLE, factor_vm *> thread_vms;
 +extern std::map<THREADHANDLE, factor_vm *> thread_vms;
  
  }