]> gitweb.factorcode.org Git - factor.git/commitdiff
VM: get rid of the odd RT_EXCEPTION_HANDLER relocation
authorBjörn Lindqvist <bjourne@gmail.com>
Sun, 30 Aug 2015 10:21:20 +0000 (12:21 +0200)
committerBjörn Lindqvist <bjourne@gmail.com>
Wed, 2 Sep 2015 19:54:30 +0000 (21:54 +0200)
The address to the win32 relocation handler can be stored in a special
object and be accessed by jit-install-seh. Doing it that way is better
because you can remove a lot of special code related to that relocation
type.

basis/bootstrap/assembler/x86.32.windows.factor
basis/compiler/codegen/relocation/relocation.factor
basis/compiler/constants/constants.factor
vm/callbacks.cpp
vm/callbacks.hpp
vm/code_blocks.cpp
vm/factor.cpp
vm/instruction_operands.hpp

index 30c02eccc9d3b11560708dea00c8a489d854da47..6f2ade1ebecbdc89e365357784d77d3925b11c15 100644 (file)
@@ -11,13 +11,15 @@ IN: bootstrap.x86
 << "vocab:bootstrap/assembler/x86.windows.factor" parse-file suffix! >> call
 
 : jit-install-seh ( -- )
+    ! VM pointer must be in vm-reg already
     ! Create a new exception record and store it in the TIB.
     ! Clobbers tib-temp.
     ! Align stack
     ESP 3 bootstrap-cells ADD
-    ! Exception handler address filled in by callback.cpp
-    tib-temp 0 MOV rc-absolute-cell rel-exception-handler
+    tib-temp EBX 50 vm-special-object-offset [+] MOV
+    tib-temp tib-temp alien-offset [+] MOV
     tib-temp PUSH
+
     ! No next handler
     0 PUSH
     ! This is the new exception handler
index 50b0726d4d010a9dfef2ced0ab0cc630c3b96c6a..6d4b49de1b06d08969b42190d7d5cc2b6942ea61 100644 (file)
@@ -89,9 +89,6 @@ MEMO: cached-string>symbol ( symbol -- obj ) string>symbol ;
 : rel-megamorphic-cache-hits ( class -- )
     rt-megamorphic-cache-hits add-relocation ;
 
-: rel-exception-handler ( class -- )
-    rt-exception-handler add-relocation ;
-
 : rel-inline-cache-miss ( class -- )
     rt-inline-cache-miss add-relocation ;
 
index 33cfba2e7a59e2d26cd6961c9902f66a3e831d1a..cb5202a167acdc8b4dd0f0a27c91daf53ae4fdf3 100644 (file)
@@ -20,10 +20,6 @@ CONSTANT: deck-bits 18
 : array-start-offset ( -- n ) 2 array type-number slot-offset ; inline
 : callstack-length-offset ( -- n ) 1 \ callstack type-number slot-offset ; inline
 : callstack-top-offset ( -- n ) 2 \ callstack type-number slot-offset ; inline
-: vm-context-offset ( -- n ) 0 bootstrap-cells ; inline
-: vm-spare-context-offset ( -- n ) 1 bootstrap-cells ; inline
-: vm-signal-handler-addr-offset ( -- n ) 8 bootstrap-cells ; inline
-: vm-fault-flag-offset ( -- n ) 9 bootstrap-cells ; inline
 : context-callstack-top-offset ( -- n ) 0 bootstrap-cells ; inline
 : context-callstack-bottom-offset ( -- n ) 1 bootstrap-cells ; inline
 : context-datastack-offset ( -- n ) 2 bootstrap-cells ; inline
@@ -33,6 +29,15 @@ CONSTANT: deck-bits 18
 : segment-start-offset ( -- n ) 0 bootstrap-cells ; inline
 : segment-end-offset ( -- n ) 2 bootstrap-cells ; inline
 
+! Offsets in vm struct
+: vm-context-offset ( -- n ) 0 bootstrap-cells ; inline
+: vm-spare-context-offset ( -- n ) 1 bootstrap-cells ; inline
+: vm-signal-handler-addr-offset ( -- n ) 8 bootstrap-cells ; inline
+: vm-fault-flag-offset ( -- n ) 9 bootstrap-cells ; inline
+: vm-special-object-offset ( n -- offset )
+    ! Can't reuse the one in compiler.cfg.intrinsics.misc :(
+    bootstrap-cells 10 bootstrap-cells + ;
+
 ! Relocation classes
 CONSTANT: rc-absolute-cell 0
 CONSTANT: rc-absolute 1
@@ -58,7 +63,6 @@ CONSTANT: rt-megamorphic-cache-hits 8
 CONSTANT: rt-vm 9
 CONSTANT: rt-cards-offset 10
 CONSTANT: rt-decks-offset 11
-CONSTANT: rt-exception-handler 12
 CONSTANT: rt-dlsym-toc 13
 CONSTANT: rt-inline-cache-miss 14
 CONSTANT: rt-safepoint 15
index a4700c3912f068d7115a673378582980c5cd2a74..85e74d24579c76edebf8f5b776bf6b806f702299 100644 (file)
@@ -23,14 +23,6 @@ void factor_vm::init_callbacks(cell size) {
   callbacks = new callback_heap(size, this);
 }
 
-bool callback_heap::setup_seh_p() {
-#if defined(WINDOWS) && defined(FACTOR_X86)
-  return true;
-#else
-  return false;
-#endif
-}
-
 bool callback_heap::return_takes_param_p() {
 #if defined(FACTOR_X86) || defined(FACTOR_AMD64)
   return true;
@@ -49,23 +41,23 @@ instruction_operand callback_heap::callback_operand(code_block* stub,
   return instruction_operand(entry, stub, 0);
 }
 
-void callback_heap::store_callback_operand(code_block* stub, cell index) {
-  instruction_operand op = callback_operand(stub, index);
-  op.store_value(parent->compute_external_address(op));
-}
-
 void callback_heap::store_callback_operand(code_block* stub, cell index,
                                            cell value) {
-  callback_operand(stub, index).store_value(value);
+  instruction_operand op = callback_operand(stub, index);
+  op.store_value(value);
 }
 
 void callback_heap::update(code_block* stub) {
-  store_callback_operand(stub, setup_seh_p() ? 2 : 1,
-                         callback_entry_point(stub));
+  store_callback_operand(stub, 1, callback_entry_point(stub));
   stub->flush_icache();
 }
 
 code_block* callback_heap::add(cell owner, cell return_rewind) {
+
+  /* code_template is a 2-tuple where the first element contains the
+     relocations and the second a byte array of compiled assembly
+     code. The code assumes that there are four relocations on x86 and
+     three on ppc. */
   tagged<array> code_template(parent->special_objects[CALLBACK_STUB]);
   tagged<byte_array> insns(array_nth(code_template.untagged(), 1));
   cell size = array_capacity(insns.untagged());
@@ -88,21 +80,13 @@ code_block* callback_heap::add(cell owner, cell return_rewind) {
   /* Store VM pointer */
   store_callback_operand(stub, 0, (cell)parent);
 
-  cell index;
-
-  if (setup_seh_p()) {
-    store_callback_operand(stub, 1);
-    index = 1;
-  } else
-    index = 0;
-
   /* Store VM pointer */
-  store_callback_operand(stub, index + 2, (cell) parent);
+  store_callback_operand(stub, 2, (cell) parent);
 
   /* On x86, the RET instruction takes an argument which depends on
      the callback's calling convention */
   if (return_takes_param_p())
-    store_callback_operand(stub, index + 3, return_rewind);
+    store_callback_operand(stub, 3, return_rewind);
 
   update(stub);
 
index e712521ee3b04aa76b9c8b392c3848630cb0e3ba..421c1f07a719e73ba009e3e85f655aed4985a016 100644 (file)
@@ -36,16 +36,11 @@ struct callback_heap {
     return w->entry_point;
   }
 
-  bool setup_seh_p();
   bool return_takes_param_p();
   instruction_operand callback_operand(code_block* stub, cell index);
-  void store_callback_operand(code_block* stub, cell index);
   void store_callback_operand(code_block* stub, cell index, cell value);
-
   void update(code_block* stub);
-
   code_block* add(cell owner, cell return_rewind);
-
   void update();
 };
 
index ee594635682fbbe7fbd71e2f3bf57c800e2c6318..d3a2f88f4d43f3392955a7971d7d59426154ba38 100644 (file)
@@ -201,10 +201,6 @@ cell factor_vm::lookup_external_address(relocation_type rel_type,
       return cards_offset;
     case RT_DECKS_OFFSET:
       return decks_offset;
-#ifdef WINDOWS
-    case RT_EXCEPTION_HANDLER:
-      return (cell)&factor::exception_handler;
-#endif
 #ifdef FACTOR_PPC
     case RT_DLSYM_TOC:
       return compute_dlsym_address(parameters, index, true);
index bf8c55fb288aa493d52de67a2e9cda803ba60d38..eb96d0da8d44f04120d24d5ec8c73890dd2e176d 100644 (file)
@@ -153,7 +153,10 @@ void factor_vm::init_factor(vm_parameters* p) {
     {OBJ_VM_COMPILE_TIME, (cell)FACTOR_COMPILE_TIME},
     {OBJ_VM_COMPILER,     (cell)FACTOR_COMPILER_VERSION},
     {OBJ_VM_GIT_LABEL,    (cell)FACTOR_STRINGIZE(FACTOR_GIT_LABEL)},
-    {OBJ_VM_VERSION,      (cell)FACTOR_STRINGIZE(FACTOR_VERSION)}
+    {OBJ_VM_VERSION,      (cell)FACTOR_STRINGIZE(FACTOR_VERSION)},
+#if defined(WINDOWS)
+    {UNUSED1,              (cell)&factor::exception_handler}
+#endif
   };
   int n_items = sizeof(aliens) / sizeof(cell[2]);
   for (int n = 0; n < n_items; n++) {
index 8cd65f8c923793927186e159d6de6d3af7d65095..4883d7f3cf6cb29e070e8937a5f6c552d9061f98 100644 (file)
@@ -111,7 +111,6 @@ struct relocation_entry {
       case RT_MEGAMORPHIC_CACHE_HITS:
       case RT_CARDS_OFFSET:
       case RT_DECKS_OFFSET:
-      case RT_EXCEPTION_HANDLER:
       case RT_INLINE_CACHE_MISS:
       case RT_SAFEPOINT:
         return 0;