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