From a11a8c0a93575a094bb84e17b5b47e3bd6c65ffb Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 15 Oct 2009 21:37:34 -0500 Subject: [PATCH 1/8] fix compiler warnings in vm --- vm/debug.cpp | 2 +- vm/vm.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/vm/debug.cpp b/vm/debug.cpp index 3a8e847f14..1d2edbbf46 100755 --- a/vm/debug.cpp +++ b/vm/debug.cpp @@ -211,7 +211,7 @@ void factor_vm::dump_memory(cell from, cell to) dump_cell(from); } -void factor_vm::dump_zone(char *name, zone *z) +void factor_vm::dump_zone(const char *name, zone *z) { print_string(name); print_string(": "); print_string("Start="); print_cell(z->start); diff --git a/vm/vm.hpp b/vm/vm.hpp index 73a423ccf4..ce2acfab45 100755 --- a/vm/vm.hpp +++ b/vm/vm.hpp @@ -301,7 +301,7 @@ struct factor_vm void print_callstack(); void dump_cell(cell x); void dump_memory(cell from, cell to); - void dump_zone(char *name, zone *z); + void dump_zone(const char *name, zone *z); void dump_generations(); void dump_objects(cell type); void find_data_references_step(cell *scan); From f29055c6aa998c2eebeca710056fa75f17f8514c Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 15 Oct 2009 21:42:01 -0500 Subject: [PATCH 2/8] fix compiler warning --- vm/old_space.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vm/old_space.cpp b/vm/old_space.cpp index 6bd8d6db0a..06e13a77ba 100644 --- a/vm/old_space.cpp +++ b/vm/old_space.cpp @@ -68,7 +68,7 @@ cell old_space::next_object_after(factor_vm *myvm, cell scan) if(scan + size < here) return scan + size; else - return NULL; + return 0; } } From 55079bb17e211d09ec42e0e77b8af24f8769dcae Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 15 Oct 2009 21:43:19 -0500 Subject: [PATCH 3/8] add psapi stub to windows.nt --- basis/windows/nt/nt.factor | 1 + basis/windows/psapi/authors.txt | 1 + basis/windows/psapi/psapi.factor | 12 ++++++++++++ 3 files changed, 14 insertions(+) create mode 100755 basis/windows/psapi/authors.txt create mode 100755 basis/windows/psapi/psapi.factor diff --git a/basis/windows/nt/nt.factor b/basis/windows/nt/nt.factor index e05a409e67..abc728ed19 100644 --- a/basis/windows/nt/nt.factor +++ b/basis/windows/nt/nt.factor @@ -14,4 +14,5 @@ USING: alien sequences alien.libraries ; { "glu" "glu32.dll" "stdcall" } { "ole32" "ole32.dll" "stdcall" } { "usp10" "usp10.dll" "stdcall" } + { "psapi" "psapi.dll" "stdcall" } } [ first3 add-library ] each diff --git a/basis/windows/psapi/authors.txt b/basis/windows/psapi/authors.txt new file mode 100755 index 0000000000..b4bd0e7b35 --- /dev/null +++ b/basis/windows/psapi/authors.txt @@ -0,0 +1 @@ +Doug Coleman \ No newline at end of file diff --git a/basis/windows/psapi/psapi.factor b/basis/windows/psapi/psapi.factor new file mode 100755 index 0000000000..b45928f615 --- /dev/null +++ b/basis/windows/psapi/psapi.factor @@ -0,0 +1,12 @@ +! Copyright (C) 2009 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: alien.syntax windows.types ; +IN: windows.psapi + +LIBRARY: psapi + +FUNCTION: BOOL EnumDeviceDrivers ( LPVOID* lpImageBase, DWORD cb, LPDWORD lpcbNeeded ) ; + +FUNCTION: DWORD GetDeviceDriverBaseNameW ( LPVOID ImageBase, LPTSTR lpBaseName, DWORD nSize ) ; + +ALIAS: GetDeviceDriverBaseName GetDeviceDriverBaseNameW From 0cc3a2c0ff62cf3397b95c8b2edf9ccd8f237021 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 15 Oct 2009 22:00:46 -0500 Subject: [PATCH 4/8] fix io.directories.search on windows --- basis/io/directories/search/search.factor | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/basis/io/directories/search/search.factor b/basis/io/directories/search/search.factor index 93d4d0146c..0c947e5bc6 100755 --- a/basis/io/directories/search/search.factor +++ b/basis/io/directories/search/search.factor @@ -6,11 +6,11 @@ locals math sequences sorting system unicode.case vocabs.loader ; IN: io.directories.search : qualified-directory-entries ( path -- seq ) - normalize-path + (normalize-path) dup directory-entries [ [ append-path ] change-name ] with map ; : qualified-directory-files ( path -- seq ) - normalize-path + (normalize-path) dup directory-files [ append-path ] with map ; : with-qualified-directory-files ( path quot -- ) From 9314e8cdf22c0980a9cb9433a029daf51212e65a Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Thu, 15 Oct 2009 22:06:43 -0500 Subject: [PATCH 5/8] vm: remove some dead code --- vm/aging_space.hpp | 4 ---- vm/copying_collector.hpp | 16 +++++----------- vm/tenured_space.hpp | 4 ---- 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/vm/aging_space.hpp b/vm/aging_space.hpp index 743363b10c..c2ec2a645e 100644 --- a/vm/aging_space.hpp +++ b/vm/aging_space.hpp @@ -3,10 +3,6 @@ namespace factor struct aging_space : old_space { aging_space(cell size, cell start) : old_space(size,start) {} - - bool is_nursery_p() { return false; } - bool is_aging_p() { return true; } - bool is_tenured_p() { return false; } }; } diff --git a/vm/copying_collector.hpp b/vm/copying_collector.hpp index 654b84f3ae..297e70e687 100644 --- a/vm/copying_collector.hpp +++ b/vm/copying_collector.hpp @@ -153,19 +153,13 @@ end: this->myvm->gc_stats.card_scan_time += (current_micros() - start_time); for(; iter != end; iter++) trace_literal_references(*iter); } - template - void trace_objects_between(SourceGeneration *gen, cell scan, cell *end) - { - while(scan && scan < *end) - { - this->trace_slots((object *)scan); - scan = gen->next_object_after(this->myvm,scan); - } - } - void cheneys_algorithm() { - trace_objects_between(this->target,scan,&this->target->here); + while(scan && scan < this->target->here) + { + this->trace_slots((object *)scan); + scan = this->target->next_object_after(this->myvm,scan); + } } }; diff --git a/vm/tenured_space.hpp b/vm/tenured_space.hpp index a05b272fb6..f9f584b200 100644 --- a/vm/tenured_space.hpp +++ b/vm/tenured_space.hpp @@ -3,10 +3,6 @@ namespace factor struct tenured_space : old_space { tenured_space(cell size, cell start) : old_space(size,start) {} - - bool is_nursery_p() { return false; } - bool is_aging_p() { return false; } - bool is_tenured_p() { return true; } }; } From 0726ec30f096c49a12263e20a0215c13dd8f9fa7 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Thu, 15 Oct 2009 22:07:03 -0500 Subject: [PATCH 6/8] cpu.x86: eliminate 2 instructions form write barrier on x86-32 --- basis/cpu/x86/32/32.factor | 12 ++++++++++++ basis/cpu/x86/64/64.factor | 14 ++++++++++++++ basis/cpu/x86/x86.factor | 20 +++++--------------- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/basis/cpu/x86/32/32.factor b/basis/cpu/x86/32/32.factor index c095f5493c..60d2a42c01 100755 --- a/basis/cpu/x86/32/32.factor +++ b/basis/cpu/x86/32/32.factor @@ -25,6 +25,18 @@ M: x86.32 rs-reg EDI ; M: x86.32 stack-reg ESP ; M: x86.32 temp-reg ECX ; +M: x86.32 %mark-card + drop HEX: ffffffff [+] card-mark MOV + building get pop + rc-absolute-cell rel-cards-offset + building get push ; + +M: x86.32 %mark-deck + drop HEX: ffffffff [+] card-mark MOV + building get pop + rc-absolute-cell rel-decks-offset + building get push ; + M:: x86.32 %dispatch ( src temp -- ) ! Load jump table base. temp src HEX: ffffffff [+] LEA diff --git a/basis/cpu/x86/64/64.factor b/basis/cpu/x86/64/64.factor index c15169dd89..4674413e75 100644 --- a/basis/cpu/x86/64/64.factor +++ b/basis/cpu/x86/64/64.factor @@ -21,6 +21,20 @@ M: x86.64 ds-reg R14 ; M: x86.64 rs-reg R15 ; M: x86.64 stack-reg RSP ; +: load-cards-offset ( dst -- ) + 0 MOV rc-absolute-cell rel-cards-offset ; + +M: x86.64 %mark-card + dup load-cards-offset + [+] card-mark MOV ; + +: load-decks-offset ( dst -- ) + 0 MOV rc-absolute-cell rel-decks-offset ; + +M: x86.64 %mark-deck + dup load-cards-offset + [+] card-mark MOV ; + M:: x86.64 %dispatch ( src temp -- ) building get length :> start ! Load jump table base. diff --git a/basis/cpu/x86/x86.factor b/basis/cpu/x86/x86.factor index abe6d308b8..60d47b78ff 100644 --- a/basis/cpu/x86/x86.factor +++ b/basis/cpu/x86/x86.factor @@ -387,31 +387,21 @@ M: x86 %vm-field-ptr ( dst field -- ) : store-tagged ( dst tag -- ) tag-number OR ; -: load-cards-offset ( dst -- ) - 0 MOV rc-absolute-cell rel-cards-offset ; - -: load-decks-offset ( dst -- ) - 0 MOV rc-absolute-cell rel-decks-offset ; - M:: x86 %allot ( dst size class nursery-ptr -- ) nursery-ptr dst load-allot-ptr dst class store-header dst class store-tagged nursery-ptr size inc-allot-ptr ; +HOOK: %mark-card cpu ( card temp -- ) +HOOK: %mark-deck cpu ( card temp -- ) + :: (%write-barrier) ( src slot temp1 temp2 -- ) - ! Compute slot address. temp1 src slot [+] LEA - - ! Mark the card temp1 card-bits SHR - temp2 load-cards-offset - temp2 temp1 [+] card-mark MOV - - ! Mark the card deck + temp1 temp2 %mark-card temp1 deck-bits card-bits - SHR - temp2 load-decks-offset - temp2 temp1 [+] card-mark MOV ; + temp1 temp2 %mark-deck ; M: x86 %write-barrier ( src slot temp1 temp2 -- ) (%write-barrier) ; From 3f550bacf6b114b1088b7dc03766562131af5a25 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Thu, 15 Oct 2009 22:08:16 -0500 Subject: [PATCH 7/8] alien.libraries: fix dlsym docs --- basis/alien/libraries/libraries-docs.factor | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/basis/alien/libraries/libraries-docs.factor b/basis/alien/libraries/libraries-docs.factor index bface7f45a..245565d9ed 100755 --- a/basis/alien/libraries/libraries-docs.factor +++ b/basis/alien/libraries/libraries-docs.factor @@ -31,9 +31,8 @@ HELP: dlopen ( path -- dll ) { $notes "This is the low-level facility used to implement " { $link load-library } ". Use the latter instead." } ; HELP: dlsym ( name dll -- alien ) -{ $values { "name" "a C symbol name" } { "dll" "a DLL handle" } { "alien" "an alien pointer" } } -{ $description "Looks up a symbol in a native library. If " { $snippet "dll" } " is " { $link f } " looks for the symbol in the runtime executable." } -{ $errors "Throws an error if the symbol could not be found." } ; +{ $values { "name" "a C symbol name" } { "dll" "a DLL handle" } { "alien" { $maybe alien } } } +{ $description "Looks up a symbol in a native library. If " { $snippet "dll" } " is " { $link f } " looks for the symbol in the runtime executable. If the symbol was not found, outputs " { $link f } "." } ; HELP: dlclose ( dll -- ) { $values { "dll" "a DLL handle" } } From 78f3f0e90d7ddb725706f9864e98cb64ee810cac Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Thu, 15 Oct 2009 22:31:41 -0500 Subject: [PATCH 8/8] vm: don't flush instruction cache twice per code block on a major GC on PowerPC --- vm/aging_collector.cpp | 2 +- vm/code_block.cpp | 35 +++++++++++++++++++++++++++++++++++ vm/full_collector.cpp | 26 ++++++++++++++------------ vm/gc.cpp | 2 +- vm/nursery_collector.cpp | 2 +- vm/to_tenured_collector.cpp | 2 +- vm/vm.hpp | 5 +++-- 7 files changed, 56 insertions(+), 18 deletions(-) diff --git a/vm/aging_collector.cpp b/vm/aging_collector.cpp index 9a856374f6..7437273649 100644 --- a/vm/aging_collector.cpp +++ b/vm/aging_collector.cpp @@ -38,7 +38,7 @@ void factor_vm::collect_aging() collector.trace_contexts(); collector.trace_code_heap_roots(&code->points_to_aging); collector.cheneys_algorithm(); - update_dirty_code_blocks(&code->points_to_aging); + update_code_heap_for_minor_gc(&code->points_to_aging); nursery.here = nursery.start; code->points_to_nursery.clear(); diff --git a/vm/code_block.cpp b/vm/code_block.cpp index 7214aa235e..bb05fe8933 100755 --- a/vm/code_block.cpp +++ b/vm/code_block.cpp @@ -356,6 +356,41 @@ void factor_vm::update_word_references(code_block *compiled) } } +/* This runs after a full collection */ +struct literal_and_word_references_updater { + factor_vm *myvm; + + explicit literal_and_word_references_updater(factor_vm *myvm_) : myvm(myvm_) {} + + void operator()(relocation_entry rel, cell index, code_block *compiled) + { + relocation_type type = myvm->relocation_type_of(rel); + switch(type) + { + case RT_IMMEDIATE: + case RT_XT: + case RT_XT_PIC: + case RT_XT_PIC_TAIL: + myvm->relocate_code_block_step(rel,index,compiled); + break; + default: + break; + } + } +}; + +void factor_vm::update_code_block_for_full_gc(code_block *compiled) +{ + if(code->needs_fixup_p(compiled)) + relocate_code_block(compiled); + else + { + literal_and_word_references_updater updater(this); + iterate_relocations(compiled,updater); + flush_icache_for(compiled); + } +} + void factor_vm::check_code_address(cell address) { #ifdef FACTOR_DEBUG diff --git a/vm/full_collector.cpp b/vm/full_collector.cpp index db3d1dcc53..64d83df3f5 100644 --- a/vm/full_collector.cpp +++ b/vm/full_collector.cpp @@ -97,10 +97,12 @@ void full_collector::cheneys_algorithm() } } -struct full_updater { +/* After growing the heap, we have to perform a full relocation to update +references to card and deck arrays. */ +struct after_growing_heap_updater { factor_vm *myvm; - full_updater(factor_vm *myvm_) : myvm(myvm_) {} + after_growing_heap_updater(factor_vm *myvm_) : myvm(myvm_) {} void operator()(heap_block *block) { @@ -108,29 +110,29 @@ struct full_updater { } }; -struct literal_and_word_reference_updater { +/* After a full GC that did not grow the heap, we have to update references +to literals and other words. */ +struct after_full_updater { factor_vm *myvm; - literal_and_word_reference_updater(factor_vm *myvm_) : myvm(myvm_) {} + after_full_updater(factor_vm *myvm_) : myvm(myvm_) {} void operator()(heap_block *block) { - code_block *compiled = (code_block *)block; - myvm->update_literal_references(compiled); - myvm->update_word_references(compiled); + myvm->update_code_block_for_full_gc((code_block *)block); } }; -void factor_vm::free_unmarked_code_blocks(bool growing_data_heap) +void factor_vm::update_code_heap_for_full_gc(bool growing_data_heap) { if(growing_data_heap) { - full_updater updater(this); + after_growing_heap_updater updater(this); code->free_unmarked(updater); } else { - literal_and_word_reference_updater updater(this); + after_full_updater updater(this); code->free_unmarked(updater); } @@ -160,7 +162,7 @@ void factor_vm::collect_growing_heap(cell requested_bytes, bool trace_contexts_p data_heap *old = data; set_data_heap(data->grow(requested_bytes)); collect_full_impl(trace_contexts_p); - free_unmarked_code_blocks(true); + update_code_heap_for_full_gc(true); delete old; } @@ -169,7 +171,7 @@ void factor_vm::collect_full(bool trace_contexts_p) std::swap(data->tenured,data->tenured_semispace); reset_generation(data->tenured); collect_full_impl(trace_contexts_p); - free_unmarked_code_blocks(false); + update_code_heap_for_full_gc(false); } } diff --git a/vm/gc.cpp b/vm/gc.cpp index c4e8d25e20..a087a49b1c 100755 --- a/vm/gc.cpp +++ b/vm/gc.cpp @@ -7,7 +7,7 @@ gc_state::gc_state(gc_op op_) : op(op_), start_time(current_micros()) {} gc_state::~gc_state() {} -void factor_vm::update_dirty_code_blocks(std::set *remembered_set) +void factor_vm::update_code_heap_for_minor_gc(std::set *remembered_set) { /* The youngest generation that any code block can now reference */ std::set::const_iterator iter = remembered_set->begin(); diff --git a/vm/nursery_collector.cpp b/vm/nursery_collector.cpp index 85f04dbb2d..0cb231417e 100644 --- a/vm/nursery_collector.cpp +++ b/vm/nursery_collector.cpp @@ -24,7 +24,7 @@ void factor_vm::collect_nursery() simple_unmarker(card_mark_mask)); collector.trace_code_heap_roots(&code->points_to_nursery); collector.cheneys_algorithm(); - update_dirty_code_blocks(&code->points_to_nursery); + update_code_heap_for_minor_gc(&code->points_to_nursery); nursery.here = nursery.start; code->points_to_nursery.clear(); diff --git a/vm/to_tenured_collector.cpp b/vm/to_tenured_collector.cpp index 6689411684..68038703c5 100644 --- a/vm/to_tenured_collector.cpp +++ b/vm/to_tenured_collector.cpp @@ -21,7 +21,7 @@ void factor_vm::collect_to_tenured() dummy_unmarker()); collector.trace_code_heap_roots(&code->points_to_aging); collector.cheneys_algorithm(); - update_dirty_code_blocks(&code->points_to_aging); + update_code_heap_for_minor_gc(&code->points_to_aging); nursery.here = nursery.start; reset_generation(data->aging); diff --git a/vm/vm.hpp b/vm/vm.hpp index ce2acfab45..e2fc589cd2 100755 --- a/vm/vm.hpp +++ b/vm/vm.hpp @@ -234,11 +234,11 @@ struct factor_vm } // gc - void update_dirty_code_blocks(std::set *remembered_set); + void update_code_heap_for_minor_gc(std::set *remembered_set); void collect_nursery(); void collect_aging(); void collect_to_tenured(); - void free_unmarked_code_blocks(bool growing_data_heap); + void update_code_heap_for_full_gc(bool growing_data_heap); void collect_full_impl(bool trace_contexts_p); void collect_growing_heap(cell requested_bytes, bool trace_contexts_p); void collect_full(bool trace_contexts_p); @@ -479,6 +479,7 @@ struct factor_vm 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 check_code_address(cell address); void relocate_code_block(code_block *compiled); void fixup_labels(array *labels, code_block *compiled);