Redefine symbol TLS slot indices.
authorAlastair Bridgewater <nyef_sbcl@lisphacker.com>
Mon, 28 Dec 2009 21:31:02 +0000 (16:31 -0500)
committerAlastair Bridgewater <nyef@virtdev-1.lisphacker.com>
Wed, 19 Oct 2011 19:49:32 +0000 (15:49 -0400)
  * Instead of having symbol TLS slots be fixnum indices treat them as
byte offsets from the base of the thread structure.

  * This has no effect on the compiler or backends.

  * TLS slot allocation must now be done in terms of words, not fixnums.

  * In %{set-,}symbol-value-in-thread, use get-lisp-obj-address instead
of scaling the TLS index.

  * Use explicit WORD_SHIFT instead of make_fixnum() / fixnum_value() in
the runtime.

src/assembly/x86-64/alloc.lisp
src/assembly/x86/alloc.lisp
src/code/target-thread.lisp
src/runtime/dynbind.c
src/runtime/gencgc.c
src/runtime/thread.c
src/runtime/thread.h

index 7fd309b..35af80a 100644 (file)
                (load-symbol-value target *free-tls-index*)
                (let ((not-error (gen-label))
                      (error (generate-error-code nil 'tls-exhausted-error)))
-                 (inst cmp target (fixnumize tls-size))
+                 (inst cmp target (ash tls-size word-shift))
                  (inst jmp :l not-error)
                  (%clear-pseudo-atomic)
                  (inst jmp error)
                  (emit-label not-error))
                (inst add (make-ea-for-symbol-value *free-tls-index*)
-                     (fixnumize 1))
+                     n-word-bytes)
                (storew target other symbol-tls-index-slot other-pointer-lowtag)
                (emit-label release-tls-index-lock)
                ;; No need for barriers on x86/x86-64 on unlock.
index ef7a026..84d49c5 100644 (file)
                (load-symbol-value target *free-tls-index*)
                (let ((not-error (gen-label))
                      (error (generate-error-code nil 'tls-exhausted-error)))
-                 (inst cmp target (fixnumize tls-size))
+                 (inst cmp target (ash tls-size word-shift))
                  (inst jmp :l not-error)
                  (%clear-pseudo-atomic)
                  (inst jmp error)
                  (emit-label not-error))
                (inst add (make-ea-for-symbol-value *free-tls-index*)
-                     (fixnumize 1))
+                     n-word-bytes)
                (storew target other symbol-tls-index-slot other-pointer-lowtag)
                (emit-label release-tls-index-lock)
                ;; No need for barriers on x86/x86-64 on unlock.
index 038dad0..16b5a2d 100644 (file)
@@ -1296,8 +1296,8 @@ SB-EXT:QUIT - the usual cleanup forms will be evaluated"
       (loop
         (if (thread-alive-p thread)
             (let* ((epoch sb!kernel::*gc-epoch*)
-                   (offset (* sb!vm:n-word-bytes
-                              (sb!vm::symbol-tls-index symbol)))
+                   (offset (sb!kernel:get-lisp-obj-address
+                            (sb!vm::symbol-tls-index symbol)))
                    (tl-val (sap-ref-word (%thread-sap thread) offset)))
               (cond ((zerop offset)
                      (return (values nil :no-tls-value)))
@@ -1331,8 +1331,8 @@ SB-EXT:QUIT - the usual cleanup forms will be evaluated"
       ;; area...
       (with-all-threads-lock
         (if (thread-alive-p thread)
-            (let ((offset (* sb!vm:n-word-bytes
-                             (sb!vm::symbol-tls-index symbol))))
+            (let ((offset (sb!kernel:get-lisp-obj-address
+                           (sb!vm::symbol-tls-index symbol))))
               (cond ((zerop offset)
                      (values nil :no-tls-value))
                     (t
index 1d62ee0..9acc23b 100644 (file)
@@ -44,9 +44,8 @@ void bind_variable(lispobj symbol, lispobj value, void *th)
             get_spinlock(tls_index_lock,(long)th);
             if(!sym->tls_index) {
                 sym->tls_index=SymbolValue(FREE_TLS_INDEX,0);
-                SetSymbolValue(FREE_TLS_INDEX,
-                               make_fixnum(fixnum_value(sym->tls_index)+1),0);
-                if(fixnum_value(sym->tls_index)>=TLS_SIZE) {
+                SetSymbolValue(FREE_TLS_INDEX, sym->tls_index+N_WORD_BYTES, 0);
+                if((sym->tls_index)>=(TLS_SIZE << WORD_SHIFT)) {
                     lose("Thread local storage exhausted.");
                 }
             }
index a6737ee..6bfa494 100644 (file)
@@ -4138,7 +4138,7 @@ garbage_collect_generation(generation_index_t generation, int raise)
             scavenge((lispobj *) th->binding_stack_start,len);
 #ifdef LISP_FEATURE_SB_THREAD
             /* do the tls as well */
-            len=fixnum_value(SymbolValue(FREE_TLS_INDEX,0)) -
+            len=(SymbolValue(FREE_TLS_INDEX,0) >> WORD_SHIFT) -
                 (sizeof (struct thread))/(sizeof (lispobj));
             scavenge((lispobj *) (th+1),len);
 #endif
index ca265b8..ac1ed79 100644 (file)
@@ -393,12 +393,12 @@ create_thread_struct(lispobj initial_function) {
         per_thread->dynamic_values[i] = NO_TLS_VALUE_MARKER_WIDETAG;
     if (all_threads == 0) {
         if(SymbolValue(FREE_TLS_INDEX,0)==UNBOUND_MARKER_WIDETAG) {
-            SetSymbolValue(FREE_TLS_INDEX,make_fixnum(tls_index_start),0);
+            SetSymbolValue(FREE_TLS_INDEX,tls_index_start << WORD_SHIFT,0);
             SetSymbolValue(TLS_INDEX_LOCK,make_fixnum(0),0);
         }
 #define STATIC_TLS_INIT(sym,field) \
   ((struct symbol *)(sym-OTHER_POINTER_LOWTAG))->tls_index= \
-  make_fixnum(THREAD_SLOT_OFFSET_WORDS(field))
+  (THREAD_SLOT_OFFSET_WORDS(field) << WORD_SHIFT)
 
         STATIC_TLS_INIT(BINDING_STACK_START,binding_stack_start);
 #ifdef BINDING_STACK_POINTER
index 3de5415..249d226 100644 (file)
@@ -95,7 +95,7 @@ SymbolValueAddress(u64 tagged_symbol_pointer, void *thread)
 #ifdef LISP_FEATURE_SB_THREAD
     if(thread && sym->tls_index) {
         lispobj *r = &(((union per_thread_data *)thread)
-                       ->dynamic_values[fixnum_value(sym->tls_index)]);
+                       ->dynamic_values[(sym->tls_index) >> WORD_SHIFT]);
         if((*r)!=NO_TLS_VALUE_MARKER_WIDETAG) return r;
     }
 #endif
@@ -111,7 +111,7 @@ SymbolValue(u64 tagged_symbol_pointer, void *thread)
     if(thread && sym->tls_index) {
         lispobj r=
             ((union per_thread_data *)thread)
-            ->dynamic_values[fixnum_value(sym->tls_index)];
+            ->dynamic_values[(sym->tls_index) >> WORD_SHIFT];
         if(r!=NO_TLS_VALUE_MARKER_WIDETAG) return r;
     }
 #endif
@@ -125,7 +125,7 @@ SymbolTlValue(u64 tagged_symbol_pointer, void *thread)
         (pointer_sized_uint_t)(tagged_symbol_pointer-OTHER_POINTER_LOWTAG);
 #ifdef LISP_FEATURE_SB_THREAD
     return ((union per_thread_data *)thread)
-        ->dynamic_values[fixnum_value(sym->tls_index)];
+        ->dynamic_values[(sym->tls_index) >> WORD_SHIFT];
 #else
     return sym->value;
 #endif
@@ -139,7 +139,7 @@ SetSymbolValue(u64 tagged_symbol_pointer,lispobj val, void *thread)
 #ifdef LISP_FEATURE_SB_THREAD
     if(thread && sym->tls_index) {
         lispobj *pr= &(((union per_thread_data *)thread)
-                       ->dynamic_values[fixnum_value(sym->tls_index)]);
+                       ->dynamic_values[(sym->tls_index) >> WORD_SHIFT]);
         if(*pr!=NO_TLS_VALUE_MARKER_WIDETAG) {
             *pr=val;
             return;
@@ -156,7 +156,7 @@ SetTlSymbolValue(u64 tagged_symbol_pointer,lispobj val, void *thread)
     struct symbol *sym= (struct symbol *)
         (pointer_sized_uint_t)(tagged_symbol_pointer-OTHER_POINTER_LOWTAG);
     ((union per_thread_data *)thread)
-        ->dynamic_values[fixnum_value(sym->tls_index)]
+        ->dynamic_values[(sym->tls_index) >> WORD_SHIFT]
         =val;
 #else
     SetSymbolValue(tagged_symbol_pointer,val,thread) ;