dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnet/engine cvm.h,1.43,1.44 cvm_dasm.c,1.49,


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnet/engine cvm.h,1.43,1.44 cvm_dasm.c,1.49,1.50 cvm_format.h,1.7,1.8 cvm_lengths.c,1.12,1.13 cvm_ptr.c,1.37,1.38 cvmc_gen.h,1.6,1.7 cvmc_obj.c,1.16,1.17 engine.h,1.70,1.71 layout.c,1.24,1.25 process.c,1.42,1.43 thread.c,1.14,1.15
Date: Fri, 18 Apr 2003 05:15:56 -0400

Update of /cvsroot/dotgnu-pnet/pnet/engine
In directory subversions:/tmp/cvs-serv6025/engine

Modified Files:
        cvm.h cvm_dasm.c cvm_format.h cvm_lengths.c cvm_ptr.c 
        cvmc_gen.h cvmc_obj.c engine.h layout.c process.c thread.c 
Log Message:


add support for thread-static fields to the runtime engine.


Index: cvm.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/cvm.h,v
retrieving revision 1.43
retrieving revision 1.44
diff -C2 -r1.43 -r1.44
*** cvm.h       16 Apr 2003 00:39:34 -0000      1.43
--- cvm.h       18 Apr 2003 09:15:52 -0000      1.44
***************
*** 509,512 ****
--- 509,517 ----
  
  /*
+  * Thread static handling.
+  */
+ #define       COP_PREFIX_THREAD_STATIC        0x58
+ 
+ /*
   * Definition of a CVM stack word which can hold
   * either 32-bit quantities or pointers.

Index: cvm_dasm.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/cvm_dasm.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -C2 -r1.49 -r1.50
*** cvm_dasm.c  16 Apr 2003 00:39:34 -0000      1.49
--- cvm_dasm.c  18 Apr 2003 09:15:52 -0000      1.50
***************
*** 57,60 ****
--- 57,61 ----
  #define       CVM_OPER_PACK_VARARGS           26
  #define       CVM_OPER_CUSTOM                         27
+ #define       CVM_OPER_TWO_UINT32                     28
  
  /*
***************
*** 564,570 ****
  
        /*
         * Reserved opcodes.
         */
-       {"preserved_58",        CVM_OPER_NONE},
        {"preserved_59",        CVM_OPER_NONE},
        {"preserved_5A",        CVM_OPER_NONE},
--- 565,575 ----
  
        /*
+        * Thread static handling.
+        */
+       {"thread_static",       CVM_OPER_TWO_UINT32},
+ 
+       /*
         * Reserved opcodes.
         */
        {"preserved_59",        CVM_OPER_NONE},
        {"preserved_5A",        CVM_OPER_NONE},
***************
*** 968,971 ****
--- 973,985 ----
                                                   (unsigned)(IL_READ_UINT32(pc 
+ 2)), stream);
                                        putc('"', stream);
+                               }
+                               break;
+ 
+                               case CVM_OPER_TWO_UINT32:
+                               {
+                                       fprintf(stream, "%lu, %lu",
+                                                       (unsigned 
long)(IL_READ_UINT32(pc + 2)),
+                                                       (unsigned 
long)(IL_READ_UINT32(pc + 6)));
+                                       pc += 10;
                                }
                                break;

Index: cvm_format.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/cvm_format.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** cvm_format.h        17 Feb 2003 05:20:31 -0000      1.7
--- cvm_format.h        18 Apr 2003 09:15:52 -0000      1.8
***************
*** 59,62 ****
--- 59,63 ----
  #define       CVMP_LEN_BYTE                                   3
  #define       CVMP_LEN_WORD                                   6
+ #define       CVMP_LEN_WORD2                                  10
  #define       CVMP_LEN_PTR                                    (2 + 
sizeof(void *))
  #define       CVMP_LEN_WORD_PTR                               (6 + 
sizeof(void *))
***************
*** 152,155 ****
--- 153,157 ----
  #define       CVMP_LEN_BYTE                                   
_CVM_LEN_FROM_WORDS(2)
  #define       CVMP_LEN_WORD                                   
_CVM_LEN_FROM_WORDS(2)
+ #define       CVMP_LEN_WORD2                                  
_CVM_LEN_FROM_WORDS(3)
  #define       CVMP_LEN_PTR                                    
_CVM_LEN_FROM_WORDS(2)
  #define       CVMP_LEN_WORD_PTR                               
_CVM_LEN_FROM_WORDS(3)

Index: cvm_lengths.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/cvm_lengths.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -r1.12 -r1.13
*** cvm_lengths.c       16 Apr 2003 00:39:34 -0000      1.12
--- cvm_lengths.c       18 Apr 2003 09:15:52 -0000      1.13
***************
*** 520,528 ****
         */
        /* profile_count */             CVMP_LEN_NONE,
        
        /*
         * Reserved opcodes.
         */
-       /* preserved_58 */              CVMP_LEN_NONE,
        /* preserved_59 */              CVMP_LEN_NONE,
        /* preserved_5a */              CVMP_LEN_NONE,
--- 520,532 ----
         */
        /* profile_count */             CVMP_LEN_NONE,
+ 
+       /*
+        * Thread static handling.
+        */
+       /* thread_static */             CVMP_LEN_WORD,
        
        /*
         * Reserved opcodes.
         */
        /* preserved_59 */              CVMP_LEN_NONE,
        /* preserved_5a */              CVMP_LEN_NONE,

Index: cvm_ptr.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/cvm_ptr.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -C2 -r1.37 -r1.38
*** cvm_ptr.c   16 Apr 2003 04:51:28 -0000      1.37
--- cvm_ptr.c   18 Apr 2003 09:15:52 -0000      1.38
***************
*** 96,99 ****
--- 96,151 ----
  }
  
+ /*
+  * Get a thread-static value from the current thread.
+  */
+ static void *GetThreadStatic(ILExecThread *thread,
+                                                        ILUInt32 slot, 
ILUInt32 size)
+ {
+       void **array;
+       ILUInt32 used;
+       void *ptr;
+ 
+       /* Determine if we need to allocate space for a new slot */
+       if(slot >= thread->threadStaticSlotsUsed)
+       {
+               used = (slot + 8) & ~7;
+               array = (void **)ILGCAlloc(sizeof(void *) * used);
+               if(!array)
+               {
+                       ILExecThreadThrowOutOfMemory(thread);
+                       return 0;
+               }
+               if(thread->threadStaticSlotsUsed > 0)
+               {
+                       ILMemMove(array, thread->threadStaticSlots,
+                                         sizeof(void *) * 
thread->threadStaticSlotsUsed);
+               }
+               thread->threadStaticSlots = array;
+               thread->threadStaticSlotsUsed = used;
+       }
+ 
+       /* Fetch the current value in the slot */
+       ptr = thread->threadStaticSlots[slot];
+       if(ptr)
+       {
+               return ptr;
+       }
+ 
+       /* Allocate a new value and write it to the slot */
+       if(!size)
+       {
+               /* Sanity check, just in case */
+               size = sizeof(unsigned long);
+       }
+       ptr = ILGCAlloc((unsigned long)size);
+       if(!ptr)
+       {
+               ILExecThreadThrowOutOfMemory(thread);
+               return 0;
+       }
+       thread->threadStaticSlots[slot] = ptr;
+       return ptr;
+ }
+ 
  #elif defined(IL_CVM_LOCALS)
  
***************
*** 3453,3456 ****
--- 3505,3537 ----
  }
  VMBREAK(COP_PREFIX_REFANYTYPE);
+ 
+ /**
+  * <opcode name="thread_static" group="Object handling">
+  *   <operation>Get a pointer to the thread-static data area</operation>
+  *
+  *   <format>prefix<fsep/>thread_static<fsep/>slot[4]<fsep/>size[4]</format>
+  *   <dformat>{thread_static}<fsep/>slot<fsep/>size</dformat>
+  *
+  *   <form name="thread_static" code="COP_PREFIX_THREAD_STATIC"/>
+  *
+  *   <before>...</before>
+  *   <after>..., ptr</after>
+  *
+  *   <description>Push a pointer to the current thread's static
+  *   data area onto the stack.  The value <i>slot</i> indicates which
+  *   slot to retrieve the pointer from.  The value <i>size</i> indicates
+  *   the size of the data object if the slot is currently empty.</description>
+  * </opcode>
+  */
+ VMCASE(COP_PREFIX_THREAD_STATIC):
+ {
+       /* Get a pointer to the thread-static data area */
+       COPY_STATE_TO_THREAD();
+       stacktop[0].ptrValue = GetThreadStatic
+               (thread, CVMP_ARG_WORD, CVMP_ARG_WORD2);
+       RESTORE_STATE_FROM_THREAD();
+       MODIFY_PC_AND_STACK(CVMP_LEN_WORD2, 1);
+ }
+ VMBREAK(COP_PREFIX_THREAD_STATIC);
  
  #endif /* IL_CVM_PREFIX */

Index: cvmc_gen.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/cvmc_gen.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** cvmc_gen.h  17 Feb 2003 05:20:31 -0000      1.6
--- cvmc_gen.h  18 Apr 2003 09:15:52 -0000      1.7
***************
*** 221,224 ****
--- 221,231 ----
                                _CVM_WORD((value2)); \
                        } while (0)
+ #define       CVMP_OUT_WORD2(opcode,value1,value2)    \
+                       do { \
+                               _CVM_BYTE(COP_PREFIX); \
+                               _CVM_BYTE((opcode)); \
+                               _CVM_WORD((value1)); \
+                               _CVM_WORD((value2)); \
+                       } while (0)
  
  /*
***************
*** 722,725 ****
--- 729,738 ----
                        do { \
                                _CVM_OPCODE((opcode)); \
+                               _CVM_WORD((value1)); \
+                               _CVM_WORD((value2)); \
+                       } while (0)
+ #define       CVMP_OUT_WORD2(opcode,value1,value2)    \
+                       do { \
+                               _CVMP_OPCODE((opcode)); \
                                _CVM_WORD((value1)); \
                                _CVM_WORD((value2)); \

Index: cvmc_obj.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/cvmc_obj.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -r1.16 -r1.17
*** cvmc_obj.c  4 Jun 2002 03:23:22 -0000       1.16
--- cvmc_obj.c  18 Apr 2003 09:15:52 -0000      1.17
***************
*** 335,345 ****
                CallStaticConstructor(coder, classInfo, 1);
  
!               /* Push a pointer to the class's static data area */
!               CVM_OUT_PTR(COP_GET_STATIC, classInfo);
!               CVM_ADJUST(1);
  
!               /* Load the field relative to the pointer */
!               CVMLoadField(coder, ILEngineType_M, 0, field,
!                                        fieldType, field->offset, 0);
        }
        else
--- 335,359 ----
                CallStaticConstructor(coder, classInfo, 1);
  
!               /* Regular or thread-static field? */
!               if(!ILFieldIsThreadStatic(field))
!               {
!                       /* Push a pointer to the class's static data area */
!                       CVM_OUT_PTR(COP_GET_STATIC, classInfo);
!                       CVM_ADJUST(1);
! 
!                       /* Load the field relative to the pointer */
!                       CVMLoadField(coder, ILEngineType_M, 0, field,
!                                                fieldType, field->offset, 0);
!               }
!               else
!               {
!                       /* Extract the pointer from a thread-static data slot */
!                       CVMP_OUT_WORD2(COP_PREFIX_THREAD_STATIC,
!                                                  field->offset, 
field->nativeOffset);
!                       CVM_ADJUST(1);
  
!                       /* Load the field relative to the pointer */
!                       CVMLoadField(coder, ILEngineType_M, 0, field, 
fieldType, 0, 0);
!               }
        }
        else
***************
*** 396,402 ****
        if((field->member.attributes & IL_META_FIELDDEF_HAS_FIELD_RVA) == 0)
        {
!               /* Push a pointer to the class's static data area */
!               CVM_OUT_PTR(COP_GET_STATIC, classInfo);
!               CVM_ADJUST(1);
  
                /* Add the offset to the pointer */
--- 410,428 ----
        if((field->member.attributes & IL_META_FIELDDEF_HAS_FIELD_RVA) == 0)
        {
!               /* Regular or thread-static field? */
!               if(!ILFieldIsThreadStatic(field))
!               {
!                       /* Push a pointer to the class's static data area */
!                       CVM_OUT_PTR(COP_GET_STATIC, classInfo);
!                       CVM_ADJUST(1);
!               }
!               else
!               {
!                       /* Extract the pointer from a thread-static data slot */
!                       CVMP_OUT_WORD2(COP_PREFIX_THREAD_STATIC,
!                                                  field->offset, 
field->nativeOffset);
!                       CVM_ADJUST(1);
!                       return;
!               }
  
                /* Add the offset to the pointer */
***************
*** 723,732 ****
        if((field->member.attributes & IL_META_FIELDDEF_HAS_FIELD_RVA) == 0)
        {
!               /* Push a pointer to the class's static data area */
!               CVM_OUT_PTR(COP_GET_STATIC, classInfo);
!               CVM_ADJUST(1);
  
!               /* Store the field relative to the pointer */
!               CVMStoreFieldReverse(coder, field, fieldType, field->offset, 0);
        }
        else
--- 749,772 ----
        if((field->member.attributes & IL_META_FIELDDEF_HAS_FIELD_RVA) == 0)
        {
!               /* Regular or thread-static field? */
!               if(!ILFieldIsThreadStatic(field))
!               {
!                       /* Push a pointer to the class's static data area */
!                       CVM_OUT_PTR(COP_GET_STATIC, classInfo);
!                       CVM_ADJUST(1);
  
!                       /* Store the field relative to the pointer */
!                       CVMStoreFieldReverse(coder, field, fieldType, 
field->offset, 0);
!               }
!               else
!               {
!                       /* Extract the pointer from a thread-static data slot */
!                       CVMP_OUT_WORD2(COP_PREFIX_THREAD_STATIC,
!                                                  field->offset, 
field->nativeOffset);
!                       CVM_ADJUST(1);
! 
!                       /* Store the field relative to the pointer */
!                       CVMStoreFieldReverse(coder, field, fieldType, 0, 0);
!               }
        }
        else

Index: engine.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/engine.h,v
retrieving revision 1.70
retrieving revision 1.71
diff -C2 -r1.70 -r1.71
*** engine.h    31 Mar 2003 05:49:34 -0000      1.70
--- engine.h    18 Apr 2003 09:15:52 -0000      1.71
***************
*** 158,161 ****
--- 158,164 ----
        int                                     randomCount;
  
+       /* Size of the global thread-static allocation */
+       ILUInt32                        numThreadStaticSlots;
+ 
  };
  
***************
*** 213,216 ****
--- 216,223 ----
        ILUInt32                numFrames;
        ILUInt32                maxFrames;
+ 
+       /* Thread-static values for this thread */
+       void              **threadStaticSlots;
+       ILUInt32                threadStaticSlotsUsed;
  
  };

Index: layout.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/layout.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -r1.24 -r1.25
*** layout.c    8 Dec 2002 11:05:06 -0000       1.24
--- layout.c    18 Apr 2003 09:15:52 -0000      1.25
***************
*** 689,692 ****
--- 689,711 ----
                                }
  
+                               /* Thread-static variables are allocated slots 
from the
+                                  ILExecProcess record.  We assume that some 
higher level
+                                  function has acquired the metadata lock on 
the process */
+                               if(ILFieldIsThreadStatic(field))
+                               {
+                                       ILExecThread *thread = 
ILExecThreadCurrent();
+                                       if(!thread)
+                                       {
+                                               /* This shouldn't happen if the 
engine has
+                                                  been initialized correctly */
+                                               continue;
+                                       }
+                                       /* Store the slot number in the 
"offset" field and
+                                          the field size in the "nativeOffset" 
field */
+                                       field->offset = 
(thread->process->numThreadStaticSlots)++;
+                                       field->nativeOffset = typeLayout.size;
+                                       continue;
+                               }
+ 
                                /* Align the field on an appropriate boundary */
                                if((layout->staticSize % typeLayout.alignment) 
!= 0)

Index: process.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/process.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -C2 -r1.42 -r1.43
*** process.c   22 Feb 2003 12:02:57 -0000      1.42
--- process.c   18 Apr 2003 09:15:52 -0000      1.43
***************
*** 78,81 ****
--- 78,82 ----
        process->randomLastTime = 0;
        process->randomCount = 0;
+       process->numThreadStaticSlots = 0;
  
        /* Initialize the image loading context */

Index: thread.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/thread.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -r1.14 -r1.15
*** thread.c    11 Jun 2002 00:58:57 -0000      1.14
--- thread.c    18 Apr 2003 09:15:52 -0000      1.15
***************
*** 70,73 ****
--- 70,75 ----
        thread->thrownException = 0;
        thread->securityManager = 0;
+       thread->threadStaticSlots = 0;
+       thread->threadStaticSlotsUsed = 0;
  
        /* Attach the thread to the process */





reply via email to

[Prev in Thread] Current Thread [Next in Thread]