]> gitweb.factorcode.org Git - factor.git/blob - vm/vm.hpp
VM: get_entry_point is unused
[factor.git] / vm / vm.hpp
1 using namespace std;
2
3 namespace factor {
4
5 struct growable_array;
6 struct code_root;
7
8 struct factor_vm {
9   //
10   // vvvvvv
11   // THESE FIELDS ARE ACCESSED DIRECTLY FROM FACTOR. See:
12   //   basis/vm/vm.factor
13   //   basis/compiler/constants/constants.factor
14
15   /* Current context */
16   context* ctx;
17
18   /* Spare context -- for callbacks */
19   context* spare_ctx;
20
21   /* New objects are allocated here, use the data->nursery reference
22      instead from c++ code. */
23   bump_allocator nursery;
24
25   /* Add this to a shifted address to compute write barrier offsets */
26   cell cards_offset;
27   cell decks_offset;
28
29   /* cdecl signal handler address, used by signal handler subprimitives */
30   cell signal_handler_addr;
31
32   /* are we handling a memory error? used to detect double faults */
33   cell faulting_p;
34
35   /* Various special objects, accessed by special-object and
36         set-special-object primitives */
37   cell special_objects[special_object_count];
38
39   // THESE FIELDS ARE ACCESSED DIRECTLY FROM FACTOR.
40   // ^^^^^^
41   //
42
43   /* Handle to the main thread we run in */
44   THREADHANDLE thread;
45
46   /* Data stack and retain stack sizes */
47   cell datastack_size, retainstack_size, callstack_size;
48
49   /* Stack of callback IDs */
50   std::vector<int> callback_ids;
51
52   /* Next callback ID */
53   int callback_id;
54
55   /* List of callback function descriptors for PPC */
56   std::list<void**> function_descriptors;
57
58   /* Pooling unused contexts to make context allocation cheaper */
59   std::list<context*> unused_contexts;
60
61   /* Active contexts, for tracing by the GC */
62   std::set<context*> active_contexts;
63
64   /* Canonical truth value. In Factor, 't' */
65   cell true_object;
66
67   /* External entry points */
68   c_to_factor_func_type c_to_factor_func;
69
70   /* Is profiling enabled? */
71   volatile cell sampling_profiler_p;
72   fixnum samples_per_second;
73
74   /* Global variables used to pass fault handler state from signal handler
75      to VM */
76   bool signal_resumable;
77   cell signal_number;
78   cell signal_fault_addr;
79   cell signal_fault_pc;
80   unsigned int signal_fpu_status;
81
82   /* Pipe used to notify Factor multiplexer of signals */
83   int signal_pipe_input, signal_pipe_output;
84
85   /* State kept by the sampling profiler */
86   std::vector<profiling_sample> samples;
87   std::vector<cell> sample_callstacks;
88
89   /* GC is off during heap walking */
90   bool gc_off;
91
92   /* Data heap */
93   data_heap* data;
94
95   /* Code heap */
96   code_heap* code;
97
98   /* Pinned callback stubs */
99   callback_heap* callbacks;
100
101   /* Only set if we're performing a GC */
102   gc_state* current_gc;
103   volatile cell current_gc_p;
104
105   /* Set if we're in the jit */
106   volatile fixnum current_jit_count;
107
108   /* Mark stack */
109   std::vector<cell> mark_stack;
110
111   /* If not NULL, we push GC events here */
112   std::vector<gc_event>* gc_events;
113
114   /* If a runtime function needs to call another function which potentially
115      allocates memory, it must wrap any references to the data and code
116      heaps with data_root and code_root smart pointers, which register
117      themselves here. See data_roots.hpp and code_roots.hpp */
118
119   std::vector<cell*> data_roots;
120   std::vector<code_root*> code_roots;
121
122   /* Debugger */
123   bool fep_p;
124   bool fep_help_was_shown;
125   bool fep_disabled;
126   bool full_output;
127
128   /* Canonical bignums */
129   cell bignum_zero;
130   cell bignum_pos_one;
131   cell bignum_neg_one;
132
133   /* Method dispatch statistics */
134   dispatch_statistics dispatch_stats;
135
136   /* Number of entries in a polymorphic inline cache */
137   cell max_pic_size;
138
139   /* Incrementing object counter for identity hashing */
140   cell object_counter;
141
142   /* Sanity check to ensure that monotonic counter doesn't decrease */
143   uint64_t last_nano_count;
144
145   /* Stack for signal handlers, only used on Unix */
146   segment* signal_callstack_seg;
147
148   /* Are we already handling a fault? Used to catch double memory faults */
149   static bool fatal_erroring_p;
150
151   /* Safepoint state */
152   volatile safepoint_state safepoint;
153
154   // contexts
155   context* new_context();
156   void init_context(context* ctx);
157   void delete_context();
158   void init_contexts(cell datastack_size_, cell retainstack_size_,
159                      cell callstack_size_);
160   void delete_contexts();
161   cell begin_callback(cell quot);
162   void end_callback();
163   void primitive_current_callback();
164   void primitive_context_object();
165   void primitive_context_object_for();
166   void primitive_set_context_object();
167   cell stack_to_array(cell bottom, cell top, vm_error_type error);
168   cell datastack_to_array(context* ctx);
169   void primitive_datastack();
170   void primitive_datastack_for();
171   cell retainstack_to_array(context* ctx);
172   void primitive_retainstack();
173   void primitive_retainstack_for();
174   cell array_to_stack(array* array, cell bottom);
175   void set_datastack(context* ctx, array* array);
176   void primitive_set_datastack();
177   void set_retainstack(context* ctx, array* array);
178   void primitive_set_retainstack();
179   void primitive_check_datastack();
180   void primitive_load_locals();
181
182   // run
183   void primitive_exit();
184   void primitive_nano_count();
185   void primitive_sleep();
186   void primitive_set_slot();
187
188   // objects
189   void primitive_special_object();
190   void primitive_set_special_object();
191   void primitive_identity_hashcode();
192   void compute_identity_hashcode(object* obj);
193   void primitive_compute_identity_hashcode();
194   cell object_size(cell tagged);
195   cell clone_object(cell obj_);
196   void primitive_clone();
197   void primitive_become();
198
199   // sampling_profiler
200   void clear_samples();
201   void record_sample(bool prolog_p);
202   void record_callstack_sample(cell* begin, cell* end, bool prolog_p);
203   void start_sampling_profiler(fixnum rate);
204   void end_sampling_profiler();
205   void set_sampling_profiler(fixnum rate);
206   void primitive_sampling_profiler();
207   void primitive_get_samples();
208   void primitive_clear_samples();
209
210   // errors
211   void general_error(vm_error_type error, cell arg1, cell arg2);
212   void type_error(cell type, cell tagged);
213   void not_implemented_error();
214   void verify_memory_protection_error(cell addr);
215   void memory_protection_error(cell pc, cell addr);
216   void signal_error(cell signal);
217   void divide_by_zero_error();
218   void fp_trap_error(unsigned int fpu_status);
219   void primitive_unimplemented();
220   void memory_signal_handler_impl();
221   void synchronous_signal_handler_impl();
222   void fp_signal_handler_impl();
223
224   // bignum
225   int bignum_equal_p(bignum* x, bignum* y);
226   enum bignum_comparison bignum_compare(bignum* x, bignum* y);
227   bignum* bignum_add(bignum* x, bignum* y);
228   bignum* bignum_subtract(bignum* x, bignum* y);
229   bignum* bignum_square(bignum* x_);
230   bignum* bignum_multiply(bignum* x, bignum* y);
231   void bignum_divide(bignum* numerator, bignum* denominator, bignum** quotient,
232                      bignum** remainder);
233   bignum* bignum_quotient(bignum* numerator, bignum* denominator);
234   bignum* bignum_remainder(bignum* numerator, bignum* denominator);
235   fixnum bignum_to_fixnum_strict(bignum* bn);
236   bignum* double_to_bignum(double x);
237   int bignum_equal_p_unsigned(bignum* x, bignum* y);
238   enum bignum_comparison bignum_compare_unsigned(bignum* x, bignum* y);
239   bignum* bignum_add_unsigned(bignum* x_, bignum* y_, int negative_p);
240   bignum* bignum_subtract_unsigned(bignum* x_, bignum* y_);
241   bignum* bignum_multiply_unsigned(bignum* x_, bignum* y_, int negative_p);
242   bignum* bignum_multiply_unsigned_small_factor(bignum* x, bignum_digit_type y,
243                                                 int negative_p);
244   void bignum_destructive_add(bignum* bn, bignum_digit_type n);
245   void bignum_destructive_scale_up(bignum* bn, bignum_digit_type factor);
246   void bignum_divide_unsigned_large_denominator(
247       bignum* numerator_, bignum* denominator_, bignum** quotient,
248       bignum** remainder, int q_negative_p, int r_negative_p);
249   void bignum_divide_unsigned_normalized(bignum* u, bignum* v, bignum* q);
250   bignum_digit_type bignum_divide_subtract(bignum_digit_type* v_start,
251                                            bignum_digit_type* v_end,
252                                            bignum_digit_type guess,
253                                            bignum_digit_type* u_start);
254   void bignum_divide_unsigned_medium_denominator(
255       bignum* numerator_, bignum_digit_type denominator, bignum** quotient,
256       bignum** remainder, int q_negative_p, int r_negative_p);
257   void bignum_destructive_normalization(bignum* source, bignum* target,
258                                         int shift_left);
259   void bignum_destructive_unnormalization(bignum* bn, int shift_right);
260   bignum_digit_type bignum_digit_divide(
261       bignum_digit_type uh, bignum_digit_type ul, bignum_digit_type v,
262       bignum_digit_type* q) /* return value */;
263   bignum_digit_type bignum_digit_divide_subtract(bignum_digit_type v1,
264                                                  bignum_digit_type v2,
265                                                  bignum_digit_type guess,
266                                                  bignum_digit_type* u);
267   void bignum_divide_unsigned_small_denominator(
268       bignum* numerator_, bignum_digit_type denominator, bignum** quotient,
269       bignum** remainder, int q_negative_p, int r_negative_p);
270   bignum_digit_type bignum_destructive_scale_down(
271       bignum* bn, bignum_digit_type denominator);
272   bignum* bignum_remainder_unsigned_small_denominator(bignum* n,
273                                                       bignum_digit_type d,
274                                                       int negative_p);
275   bignum* bignum_digit_to_bignum(bignum_digit_type digit, int negative_p);
276   bignum* allot_bignum(bignum_length_type length, int negative_p);
277   bignum* allot_bignum_zeroed(bignum_length_type length, int negative_p);
278   bignum* bignum_shorten_length(bignum* bn, bignum_length_type length);
279   bignum* bignum_trim(bignum* bn);
280   bignum* bignum_new_sign(bignum* x_, int negative_p);
281   bignum* bignum_maybe_new_sign(bignum* x_, int negative_p);
282   void bignum_destructive_copy(bignum* source, bignum* target);
283   bignum* bignum_bitwise_not(bignum* x_);
284   bignum* bignum_arithmetic_shift(bignum* arg1, fixnum n);
285   bignum* bignum_bitwise_and(bignum* arg1, bignum* arg2);
286   bignum* bignum_bitwise_ior(bignum* arg1, bignum* arg2);
287   bignum* bignum_bitwise_xor(bignum* arg1, bignum* arg2);
288   bignum* bignum_magnitude_ash(bignum* arg1_, fixnum n);
289   bignum* bignum_pospos_bitwise_op(int op, bignum* arg1_, bignum* arg2_);
290   bignum* bignum_posneg_bitwise_op(int op, bignum* arg1_, bignum* arg2_);
291   bignum* bignum_negneg_bitwise_op(int op, bignum* arg1_, bignum* arg2_);
292   void bignum_negate_magnitude(bignum* arg);
293   bignum* bignum_integer_length(bignum* x_);
294   int bignum_logbitp(int shift, bignum* arg);
295   int bignum_unsigned_logbitp(int shift, bignum* bn);
296   bignum* bignum_gcd(bignum* a_, bignum* b_);
297
298   //data heap
299   void init_card_decks();
300   void set_data_heap(data_heap* data_);
301   void init_data_heap(cell young_size, cell aging_size, cell tenured_size);
302   void primitive_size();
303   data_heap_room data_room();
304   void primitive_data_room();
305   void begin_scan();
306   void end_scan();
307   cell instances(cell type);
308   void primitive_all_instances();
309
310   template <typename Generation, typename Iterator>
311   inline void each_object(Generation* gen, Iterator& iterator) {
312     cell obj = gen->first_object();
313     while (obj) {
314       iterator((object*)obj);
315       obj = gen->next_object_after(obj);
316     }
317   }
318
319   template <typename Iterator> inline void each_object(Iterator& iterator) {
320
321     /* The nursery can't be iterated because there may be gaps between
322        the objects (see factor_vm::reallot_array) so we require it to
323        be empty first. */
324     FACTOR_ASSERT(data->nursery->occupied_space() == 0);
325
326     gc_off = true;
327     each_object(data->tenured, iterator);
328     each_object(data->aging, iterator);
329     gc_off = false;
330   }
331
332   /* the write barrier must be called any time we are potentially storing a
333      pointer from an older generation to a younger one */
334   inline void write_barrier(cell* slot_ptr) {
335     *(char*)(cards_offset + ((cell)slot_ptr >> card_bits)) = card_mark_mask;
336     *(char*)(decks_offset + ((cell)slot_ptr >> deck_bits)) = card_mark_mask;
337   }
338
339   inline void write_barrier(object* obj, cell size) {
340     cell start = (cell)obj & (~card_size + 1);
341     cell end = ((cell)obj + size + card_size - 1) & (~card_size + 1);
342
343     for (cell offset = start; offset < end; offset += card_size)
344       write_barrier((cell*)offset);
345   }
346
347   // data heap checker
348   void check_data_heap();
349
350   // gc
351   void end_gc();
352   void set_current_gc_op(gc_op op);
353   void start_gc_again();
354   void collect_nursery();
355   void collect_aging();
356   void collect_to_tenured();
357   void update_code_roots_for_sweep();
358   void update_code_roots_for_compaction();
359   void collect_mark_impl();
360   void collect_sweep_impl();
361   void collect_full();
362   void collect_compact_impl();
363   void collect_compact_code_impl();
364   void collect_compact();
365   void collect_growing_heap(cell requested_size);
366   void gc(gc_op op, cell requested_size);
367   void primitive_minor_gc();
368   void primitive_full_gc();
369   void primitive_compact_gc();
370   void primitive_enable_gc_events();
371   void primitive_disable_gc_events();
372   object* allot_object(cell type, cell size);
373   object* allot_large_object(cell type, cell size);
374
375   /* Allocates memory */
376   template <typename Type> Type* allot(cell size) {
377     return (Type*)allot_object(Type::type_number, size);
378   }
379
380   // generic arrays
381   template <typename Array> Array* allot_uninitialized_array(cell capacity);
382   template <typename Array>
383   bool reallot_array_in_place_p(Array* array, cell capacity);
384   template <typename Array> Array* reallot_array(Array* array_, cell capacity);
385
386   // debug
387   void print_chars(ostream& out, string* str);
388   void print_word(ostream& out, word* word, cell nesting);
389   void print_factor_string(ostream& out, string* str);
390   void print_array(ostream& out, array* array, cell nesting);
391   void print_byte_array(ostream& out, byte_array* array, cell nesting);
392   void print_tuple(ostream& out, tuple* tuple, cell nesting);
393   void print_alien(ostream& out, alien* alien, cell nesting);
394   void print_nested_obj(ostream& out, cell obj, fixnum nesting);
395   void print_obj(ostream& out, cell obj);
396   void print_objects(ostream& out, cell* start, cell* end);
397   void print_datastack(ostream& out);
398   void print_retainstack(ostream& out);
399   void print_callstack(ostream& out);
400   void print_callstack_object(ostream& out, callstack* obj);
401   void dump_cell(ostream& out, cell x);
402   void dump_memory(ostream& out, cell from, cell to);
403   template <typename Generation>
404   void dump_generation(ostream& out, const char* name, Generation* gen);
405   void dump_generations(ostream& out);
406   void dump_objects(ostream& out, cell type);
407   void dump_edges(ostream& out);
408   void find_data_references(ostream& out, cell look_for_);
409   void dump_code_heap(ostream& out);
410   void factorbug_usage(bool advanced_p);
411   void factorbug();
412   void primitive_die();
413
414   // arrays
415   inline void set_array_nth(array* array, cell slot, cell value);
416   array* allot_array(cell capacity, cell fill_);
417   void primitive_array();
418   cell allot_array_4(cell v1_, cell v2_, cell v3_, cell v4_);
419   void primitive_resize_array();
420   cell std_vector_to_array(std::vector<cell>& elements);
421
422   // strings
423   string* allot_string_internal(cell capacity);
424   void fill_string(string* str_, cell start, cell capacity, cell fill);
425   string* allot_string(cell capacity, cell fill);
426   void primitive_string();
427   bool reallot_string_in_place_p(string* str, cell capacity);
428   string* reallot_string(string* str_, cell capacity);
429   void primitive_resize_string();
430   void primitive_set_string_nth_fast();
431
432   // booleans
433   cell tag_boolean(cell untagged) {
434     return (untagged ? true_object : false_object);
435   }
436
437   // byte arrays
438   byte_array* allot_byte_array(cell size);
439   void primitive_byte_array();
440   void primitive_uninitialized_byte_array();
441   void primitive_resize_byte_array();
442
443   template <typename Type> byte_array* byte_array_from_value(Type* value);
444
445   // tuples
446   void primitive_tuple();
447   void primitive_tuple_boa();
448
449   // words
450   word* allot_word(cell name_, cell vocab_, cell hashcode_);
451   void primitive_word();
452   void primitive_word_code();
453   void primitive_optimized_p();
454   void primitive_wrapper();
455   void jit_compile_word(cell word_, cell def_, bool relocating);
456   cell find_all_words();
457   void compile_all_words();
458
459   // math
460   void primitive_bignum_to_fixnum();
461   void primitive_bignum_to_fixnum_strict();
462   void primitive_float_to_fixnum();
463   void primitive_fixnum_divint();
464   void primitive_fixnum_divmod();
465   bignum* fixnum_to_bignum(fixnum);
466   bignum* cell_to_bignum(cell);
467   bignum* long_long_to_bignum(int64_t n);
468   bignum* ulong_long_to_bignum(uint64_t n);
469   inline fixnum sign_mask(fixnum x);
470   inline fixnum branchless_max(fixnum x, fixnum y);
471   inline fixnum branchless_abs(fixnum x);
472   void primitive_fixnum_shift();
473   void primitive_fixnum_to_bignum();
474   void primitive_float_to_bignum();
475   void primitive_bignum_eq();
476   void primitive_bignum_add();
477   void primitive_bignum_subtract();
478   void primitive_bignum_multiply();
479   void primitive_bignum_divint();
480   void primitive_bignum_divmod();
481   void primitive_bignum_mod();
482   void primitive_bignum_gcd();
483   void primitive_bignum_and();
484   void primitive_bignum_or();
485   void primitive_bignum_xor();
486   void primitive_bignum_shift();
487   void primitive_bignum_less();
488   void primitive_bignum_lesseq();
489   void primitive_bignum_greater();
490   void primitive_bignum_greatereq();
491   void primitive_bignum_not();
492   void primitive_bignum_bitp();
493   void primitive_bignum_log2();
494   inline cell unbox_array_size();
495   void primitive_fixnum_to_float();
496   void primitive_format_float();
497   void primitive_float_eq();
498   void primitive_float_add();
499   void primitive_float_subtract();
500   void primitive_float_multiply();
501   void primitive_float_divfloat();
502   void primitive_float_less();
503   void primitive_float_lesseq();
504   void primitive_float_greater();
505   void primitive_float_greatereq();
506   void primitive_float_bits();
507   void primitive_bits_float();
508   void primitive_double_bits();
509   void primitive_bits_double();
510   fixnum to_fixnum(cell tagged);
511   fixnum to_fixnum_strict(cell tagged);
512   cell to_cell(cell tagged);
513   cell from_signed_8(int64_t n);
514   int64_t to_signed_8(cell obj);
515   cell from_unsigned_8(uint64_t n);
516   uint64_t to_unsigned_8(cell obj);
517   float to_float(cell value);
518   double to_double(cell value);
519   inline void overflow_fixnum_add(fixnum x, fixnum y);
520   inline void overflow_fixnum_subtract(fixnum x, fixnum y);
521   inline void overflow_fixnum_multiply(fixnum x, fixnum y);
522   inline cell from_signed_cell(fixnum x);
523   inline cell from_unsigned_cell(cell x);
524   inline cell allot_float(double n);
525   inline bignum* float_to_bignum(cell tagged);
526   inline double untag_float(cell tagged);
527   inline double untag_float_check(cell tagged);
528   inline fixnum float_to_fixnum(cell tagged);
529   inline double fixnum_to_float(cell tagged);
530
531   // tagged
532   template <typename Type> Type* untag_check(cell value);
533
534   // io
535   void init_c_io();
536   void io_error_if_not_EINTR();
537   FILE* safe_fopen(char* filename, char* mode);
538   int safe_fgetc(FILE* stream);
539   size_t safe_fread(void* ptr, size_t size, size_t nitems, FILE* stream);
540   void safe_fputc(int c, FILE* stream);
541   size_t safe_fwrite(void* ptr, size_t size, size_t nitems, FILE* stream);
542   int safe_ftell(FILE* stream);
543   void safe_fseek(FILE* stream, off_t offset, int whence);
544   void safe_fflush(FILE* stream);
545   void safe_fclose(FILE* stream);
546   void primitive_fopen();
547   FILE* pop_file_handle();
548   FILE* peek_file_handle();
549   void primitive_fgetc();
550   void primitive_fread();
551   void primitive_fputc();
552   void primitive_fwrite();
553   void primitive_ftell();
554   void primitive_fseek();
555   void primitive_fflush();
556   void primitive_fclose();
557
558   // code_block
559   cell compute_entry_point_address(cell obj);
560   cell compute_entry_point_pic_address(word* w, cell tagged_quot);
561   cell compute_entry_point_pic_address(cell w_);
562   cell compute_entry_point_pic_tail_address(cell w_);
563   cell code_block_owner(code_block* compiled);
564   void update_word_references(code_block* compiled, bool reset_inline_caches);
565   void undefined_symbol();
566   cell compute_dlsym_address(array* literals, cell index);
567 #ifdef FACTOR_PPC
568   cell compute_dlsym_toc_address(array* literals, cell index);
569 #endif
570   cell compute_vm_address(cell arg);
571   void store_external_address(instruction_operand op);
572   cell lookup_external_address(relocation_type rel_type,
573                                code_block* compiled,
574                                array* parameters,
575                                cell index);
576   cell compute_here_address(cell arg, cell offset, code_block* compiled);
577   void initialize_code_block(code_block* compiled, cell literals);
578   void initialize_code_block(code_block* compiled);
579   void fixup_labels(array* labels, code_block* compiled);
580   code_block* allot_code_block(cell size, code_block_type type);
581   code_block* add_code_block(code_block_type type, cell code_, cell labels_,
582                              cell owner_, cell relocation_, cell parameters_,
583                              cell literals_, cell frame_size_untagged);
584
585   //code heap
586   template <typename Iterator> void each_code_block(Iterator& iter) {
587     code->allocator->iterate(iter);
588   }
589
590   void init_code_heap(cell size);
591   void update_code_heap_words(bool reset_inline_caches);
592   void initialize_code_blocks();
593   void primitive_modify_code_heap();
594   void primitive_code_room();
595   void primitive_strip_stack_traces();
596   cell code_blocks();
597   void primitive_code_blocks();
598
599   // callbacks
600   void init_callbacks(cell size);
601   void primitive_free_callback();
602   void primitive_callback();
603   void primitive_callback_room();
604
605   // image
606   void init_objects(image_header* h);
607   void load_data_heap(FILE* file, image_header* h, vm_parameters* p);
608   void load_code_heap(FILE* file, image_header* h, vm_parameters* p);
609   bool save_image(const vm_char* saving_filename, const vm_char* filename);
610   void primitive_save_image();
611   void primitive_save_image_and_exit();
612   void fixup_data(cell data_offset, cell code_offset);
613   void fixup_code(cell data_offset, cell code_offset);
614   FILE* open_image(vm_parameters* p);
615   void load_image(vm_parameters* p);
616   bool read_embedded_image_footer(FILE* file, embedded_image_footer* footer);
617   bool embedded_image_p();
618
619   template <typename Iterator, typename Fixup>
620   void iterate_callstack_object(callstack* stack_, Iterator& iterator,
621                                 Fixup& fixup);
622   template <typename Iterator>
623   void iterate_callstack_object(callstack* stack_, Iterator& iterator);
624
625   callstack* allot_callstack(cell size);
626   cell second_from_top_stack_frame(context* ctx);
627   cell capture_callstack(context* ctx);
628   void primitive_callstack();
629   void primitive_callstack_for();
630   cell frame_predecessor(cell frame_top);
631   void primitive_callstack_to_array();
632   void primitive_innermost_stack_frame_executing();
633   void primitive_innermost_stack_frame_scan();
634   void primitive_set_innermost_stack_frame_quot();
635   void primitive_callstack_bounds();
636
637   template <typename Iterator, typename Fixup>
638   void iterate_callstack(context* ctx, Iterator& iterator, Fixup& fixup);
639   template <typename Iterator>
640   void iterate_callstack(context* ctx, Iterator& iterator);
641
642   // cpu-*
643   void dispatch_signal_handler(cell* sp, cell* pc, cell newpc);
644
645   // alien
646   char* pinned_alien_offset(cell obj);
647   cell allot_alien(cell delegate_, cell displacement);
648   cell allot_alien(void* address);
649   void primitive_displaced_alien();
650   void primitive_alien_address();
651   void* alien_pointer();
652   void primitive_dlopen();
653   void primitive_dlsym();
654   void primitive_dlsym_raw();
655   void primitive_dlclose();
656   void primitive_dll_validp();
657   char* alien_offset(cell obj);
658
659   // quotations
660   void primitive_jit_compile();
661   cell lazy_jit_compile_entry_point();
662   void primitive_array_to_quotation();
663   void primitive_quotation_code();
664   code_block* jit_compile_quot(cell owner_, cell quot_, bool relocating);
665   void jit_compile_quot(cell quot_, bool relocating);
666   fixnum quot_code_offset_to_scan(cell quot_, cell offset);
667   cell lazy_jit_compile(cell quot);
668   bool quot_compiled_p(quotation* quot);
669   void primitive_quot_compiled_p();
670   cell find_all_quotations();
671   void initialize_all_quotations();
672
673   // dispatch
674   cell search_lookup_alist(cell table, cell klass);
675   cell search_lookup_hash(cell table, cell klass, cell hashcode);
676   cell nth_superclass(tuple_layout* layout, fixnum echelon);
677   cell nth_hashcode(tuple_layout* layout, fixnum echelon);
678   cell lookup_tuple_method(cell obj, cell methods);
679   cell lookup_method(cell obj, cell methods);
680   void primitive_lookup_method();
681   cell object_class(cell obj);
682   cell method_cache_hashcode(cell klass, array* array);
683   void update_method_cache(cell cache, cell klass, cell method);
684   void primitive_mega_cache_miss();
685   void primitive_reset_dispatch_stats();
686   void primitive_dispatch_stats();
687
688   // inline cache
689   void init_inline_caching(int max_size);
690   void deallocate_inline_cache(cell return_address);
691   cell determine_inline_cache_type(array* cache_entries);
692   void update_pic_count(cell type);
693   code_block* compile_inline_cache(fixnum index, cell generic_word_,
694                                    cell methods_, cell cache_entries_,
695                                    bool tail_call_p);
696   cell inline_cache_size(cell cache_entries);
697   cell add_inline_cache_entry(cell cache_entries_, cell klass_, cell method_);
698   void update_pic_transitions(cell pic_size);
699   cell inline_cache_miss(cell return_address);
700
701   // entry points
702   void c_to_factor(cell quot);
703   void unwind_native_frames(cell quot, cell to);
704   cell get_fpu_state();
705   void set_fpu_state(cell state);
706
707   // factor
708   void default_parameters(vm_parameters* p);
709   bool factor_arg(const vm_char* str, const vm_char* arg, cell* value);
710   void init_parameters_from_args(vm_parameters* p, int argc, vm_char** argv);
711   void prepare_boot_image();
712   void init_factor(vm_parameters* p);
713   void pass_args_to_factor(int argc, vm_char** argv);
714   void start_factor(vm_parameters* p);
715   void stop_factor();
716   void start_embedded_factor(vm_parameters* p);
717   void start_standalone_factor(int argc, vm_char** argv);
718   char* factor_eval_string(char* string);
719   void factor_eval_free(char* result);
720   void factor_yield();
721   void factor_sleep(long us);
722
723   // os-*
724   void primitive_existsp();
725   void move_file(const vm_char* path1, const vm_char* path2);
726   void init_ffi();
727   void ffi_dlopen(dll* dll);
728   void* ffi_dlsym(dll* dll, symbol_char* symbol);
729   void* ffi_dlsym_raw(dll* dll, symbol_char* symbol);
730 #ifdef FACTOR_PPC
731   void* ffi_dlsym_toc(dll* dll, symbol_char* symbol);
732 #endif
733   void ffi_dlclose(dll* dll);
734   void c_to_factor_toplevel(cell quot);
735   void init_signals();
736   void start_sampling_profiler_timer();
737   void end_sampling_profiler_timer();
738   static void open_console();
739   static void close_console();
740   static void lock_console();
741   static void unlock_console();
742   static void ignore_ctrl_c();
743   static void handle_ctrl_c();
744
745 // os-windows
746 #if defined(WINDOWS)
747   HANDLE sampler_thread;
748   void sampler_thread_loop();
749
750   const vm_char* vm_executable_path();
751   const vm_char* default_image_path();
752   void windows_image_path(vm_char* full_path, vm_char* temp_path,
753                           unsigned int length);
754   BOOL windows_stat(vm_char* path);
755
756   LONG exception_handler(PEXCEPTION_RECORD e, void* frame, PCONTEXT c,
757                          void* dispatch);
758
759 #else  // UNIX
760   void dispatch_signal(void* uap, void(handler)());
761   void unix_init_signals();
762 #endif
763
764 #ifdef __APPLE__
765   void call_fault_handler(exception_type_t exception,
766                           exception_data_type_t code,
767                           MACH_EXC_STATE_TYPE* exc_state,
768                           MACH_THREAD_STATE_TYPE* thread_state,
769                           MACH_FLOAT_STATE_TYPE* float_state);
770 #endif
771
772   factor_vm(THREADHANDLE thread_id);
773   ~factor_vm();
774 };
775
776 }