Skip to content

Commit

Permalink
Merge branch 'safer-gc' into devel
Browse files Browse the repository at this point in the history
  • Loading branch information
kekyo committed Apr 10, 2019
2 parents eb9a4f9 + baf143c commit 058fc7f
Show file tree
Hide file tree
Showing 14 changed files with 759 additions and 1,134 deletions.
42 changes: 39 additions & 3 deletions IL2C.Core/ILConveters/NewConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ public override Func<IExtractContext, string[]> Apply(
type.FriendlyName);
}

if (!(ctor.Parameters.Length == 2) &&
(ctor.Parameters[0].TargetType.IsObjectType) &&
(ctor.Parameters[0].TargetType.IsIntPtrType))
if ((ctor.Parameters.Length != 3) ||
!ctor.Parameters[1].TargetType.IsObjectType ||
!ctor.Parameters[2].TargetType.IsIntPtrType)
{
throw new InvalidProgramSequenceException(
"Invalid delegate constructor: Location={0}, Method={1}",
Expand All @@ -135,6 +135,42 @@ public override Func<IExtractContext, string[]> Apply(
};
}

// Specialized the thread type:
if (type.UniqueName == "System.Threading.Thread")
{
if (!type.IsClass || !type.IsSealed)
{
throw new InvalidProgramSequenceException(
"Invalid thread type: Location={0}, Method={1}",
codeInformation.RawLocation,
type.FriendlyName);
}

if ((ctor.Parameters.Length != 2) ||
((ctor.Parameters[1].TargetType.UniqueName != "System.Threading.ThreadStart") &&
(ctor.Parameters[1].TargetType.UniqueName != "System.Threading.ParameterizedThreadStart")))
{
throw new InvalidProgramSequenceException(
"Invalid thread constructor: Location={0}, Method={1}",
codeInformation.RawLocation,
ctor.FriendlyName);
}

return extractContext =>
{
var parameterString = Utilities.GetGivenParameterDeclaration(
pairParameters.Skip(1).ToArray(), extractContext, codeInformation);

return new[]
{
string.Format(
"{0} = il2c_new_thread({1})",
extractContext.GetSymbolName(thisSymbol),
parameterString)
};
};
}

var overloadIndex = ctor.OverloadIndex;

return extractContext =>
Expand Down
19 changes: 9 additions & 10 deletions IL2C.Runtime/include/System/Threading/Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,28 @@ struct System_Threading_Thread
{
System_Threading_Thread_VTABLE_DECL__* vptr0__;
System_Delegate* start__;
System_Object* parameter__;

/* IL2C_THREAD_CONTEXT: Important field order! */
IL2C_EXECUTION_FRAME* pFrame__;
IL2C_EXCEPTION_FRAME* pUnwindTarget__;
volatile intptr_t rawHandle__;
int32_t id__;
};

extern System_Threading_Thread_VTABLE_DECL__ System_Threading_Thread_VTABLE__;

IL2C_DECLARE_RUNTIME_TYPE(System_Threading_Thread);

extern void System_Threading_Thread__ctor(System_Threading_Thread* this__, System_Threading_ThreadStart* start);
extern void System_Threading_Thread__ctor_1(System_Threading_Thread* this__, System_Threading_ParameterizedThreadStart* start);
extern void System_Threading_Thread_Finalize(System_Threading_Thread* this__);
extern void System_Threading_Thread_Start(System_Threading_Thread* this__);
extern void System_Threading_Thread_Start_2(System_Threading_Thread* this__, System_Object* parameter);
extern void System_Threading_Thread_Join(System_Threading_Thread* this__);
#define System_Threading_Thread_get_ManagedThreadId(this__) ((int32_t)(this__->id__))
extern int32_t System_Threading_Thread_get_ManagedThreadId(System_Threading_Thread* this__);
extern /* static */ System_Threading_Thread* System_Threading_Thread_get_CurrentThread(void);
extern /* static */ void System_Threading_Thread_Sleep(int millisecondsTimeout);

#if defined(IL2C_USE_LINE_INFORMATION)
extern System_Threading_Thread* il2c_new_thread__(System_Delegate* start, const char* pFile, int line);
#define il2c_new_thread(start) il2c_new_thread__(start, __FILE__, __LINE__)
#else
extern System_Threading_Thread* il2c_new_thread__(System_Delegate* start);
#define il2c_new_thread(start) il2c_new_thread__(start)
#endif

#ifdef __cplusplus
}
#endif
Expand Down
9 changes: 6 additions & 3 deletions IL2C.Runtime/src/System/Array.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,14 @@ System_Array* il2c_new_array__(
const uintptr_t size = (uintptr_t)sizeof(System_Array) + ((uintptr_t)length) * elementSize;

#if defined(IL2C_USE_LINE_INFORMATION)
IL2C_THREAD_CONTEXT* pThreadContext = il2c_acquire_thread_context__(
pFile, line);
IL2C_REF_HEADER* pHeader = il2c_get_uninitialized_object_internal__(
il2c_typeof(System_Array), size, pFile, line);
il2c_typeof(System_Array), size, (void*)IL2C_THREAD_LOCK_TARGET(pThreadContext), pFile, line);
#else
IL2C_THREAD_CONTEXT* pThreadContext = il2c_acquire_thread_context__();
IL2C_REF_HEADER* pHeader = il2c_get_uninitialized_object_internal__(
il2c_typeof(System_Array), size);
il2c_typeof(System_Array), size, (void*)IL2C_THREAD_LOCK_TARGET(pThreadContext));
#endif

System_Array* arr = (System_Array*)(pHeader + 1);
Expand Down Expand Up @@ -126,7 +129,7 @@ static void System_Array_MarkHandler__(System_Array* arr)
IL2C_RUNTIME_TYPE_BEGIN(
System_Array,
"System.Array",
IL2C_TYPE_VARIABLE | IL2C_TYPE_WITH_MARK_HANDLER,
IL2C_TYPE_REFERENCE | IL2C_TYPE_VARIABLE | IL2C_TYPE_WITH_MARK_HANDLER,
0,
System_Object,
System_Array_MarkHandler__,
Expand Down
29 changes: 22 additions & 7 deletions IL2C.Runtime/src/System/Delegate.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,14 @@ System_Delegate* System_Delegate_Combine(System_Delegate* a, System_Delegate* b)
(uintptr_t)(count - 1 /* included System_Delegate */) * sizeof(IL2C_METHOD_TABLE);

#if defined(IL2C_USE_LINE_INFORMATION)
IL2C_REF_HEADER* pHeader = il2c_get_uninitialized_object_internal__(pHeaderA->type, size, __FILE__, __LINE__);
IL2C_THREAD_CONTEXT* pThreadContext = il2c_acquire_thread_context__(
__FILE__, __LINE__);
IL2C_REF_HEADER* pHeader = il2c_get_uninitialized_object_internal__(
pHeaderA->type, size, (void*)IL2C_THREAD_LOCK_TARGET(pThreadContext), __FILE__, __LINE__);
#else
IL2C_REF_HEADER* pHeader = il2c_get_uninitialized_object_internal__(pHeaderA->type, size);
IL2C_THREAD_CONTEXT* pThreadContext = il2c_acquire_thread_context__();
IL2C_REF_HEADER* pHeader = il2c_get_uninitialized_object_internal__(
pHeaderA->type, size, (void*)IL2C_THREAD_LOCK_TARGET(pThreadContext));
#endif

System_Delegate* dlg = (System_Delegate*)(pHeader + 1);
Expand Down Expand Up @@ -165,9 +170,14 @@ System_Delegate* System_Delegate_Remove(System_Delegate* source, System_Delegate
(uintptr_t)(count - 1 /* included System_Delegate */) * sizeof(IL2C_METHOD_TABLE);

#if defined(IL2C_USE_LINE_INFORMATION)
IL2C_REF_HEADER* pHeader = il2c_get_uninitialized_object_internal__(pHeaderSource->type, size, __FILE__, __LINE__);
IL2C_THREAD_CONTEXT* pThreadContext = il2c_acquire_thread_context__(
__FILE__, __LINE__);
IL2C_REF_HEADER* pHeader = il2c_get_uninitialized_object_internal__(
pHeaderSource->type, size, (void*)IL2C_THREAD_LOCK_TARGET(pThreadContext), __FILE__, __LINE__);
#else
IL2C_REF_HEADER* pHeader = il2c_get_uninitialized_object_internal__(pHeaderSource->type, size);
IL2C_THREAD_CONTEXT* pThreadContext = il2c_acquire_thread_context__();
IL2C_REF_HEADER* pHeader = il2c_get_uninitialized_object_internal__(
pHeaderSource->type, size, (void*)IL2C_THREAD_LOCK_TARGET(pThreadContext));
#endif

System_Delegate* dlg = (System_Delegate*)(pHeader + 1);
Expand Down Expand Up @@ -206,9 +216,14 @@ System_Delegate* il2c_new_delegate__(
il2c_assert(method != 0);

#if defined(IL2C_USE_LINE_INFORMATION)
IL2C_REF_HEADER* pHeader = il2c_get_uninitialized_object_internal__(delegateType, sizeof(System_Delegate), pFile, line);
IL2C_THREAD_CONTEXT* pThreadContext = il2c_acquire_thread_context__(
pFile, line);
IL2C_REF_HEADER* pHeader = il2c_get_uninitialized_object_internal__(
delegateType, sizeof(System_Delegate), (void*)IL2C_THREAD_LOCK_TARGET(pThreadContext), pFile, line);
#else
IL2C_REF_HEADER* pHeader = il2c_get_uninitialized_object_internal__(delegateType, sizeof(System_Delegate));
IL2C_THREAD_CONTEXT* pThreadContext = il2c_acquire_thread_context__();
IL2C_REF_HEADER* pHeader = il2c_get_uninitialized_object_internal__(
delegateType, sizeof(System_Delegate), (void*)IL2C_THREAD_LOCK_TARGET(pThreadContext));
#endif

System_Delegate* dlg = (System_Delegate*)(pHeader + 1);
Expand Down Expand Up @@ -263,7 +278,7 @@ System_Delegate_VTABLE_DECL__ System_Delegate_VTABLE__ = {
IL2C_RUNTIME_TYPE_BEGIN(
System_Delegate,
"System.Delegate",
IL2C_TYPE_VARIABLE | IL2C_TYPE_WITH_MARK_HANDLER,
IL2C_TYPE_REFERENCE | IL2C_TYPE_VARIABLE | IL2C_TYPE_WITH_MARK_HANDLER,
0,
System_Object,
System_Delegate_MarkHandler__,
Expand Down
9 changes: 6 additions & 3 deletions IL2C.Runtime/src/System/String.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,16 @@ static System_String* new_string_internal__(uintptr_t byteSize)
const uintptr_t bodySize = sizeof(System_String) + byteSize;

#if defined(IL2C_USE_LINE_INFORMATION)
IL2C_THREAD_CONTEXT* pThreadContext = il2c_acquire_thread_context__(
pFile, line);
IL2C_REF_HEADER* pHeader = il2c_get_uninitialized_object_internal__(
il2c_typeof(System_String),
bodySize, pFile, line);
bodySize, (void*)IL2C_THREAD_LOCK_TARGET(pThreadContext), pFile, line);
#else
IL2C_THREAD_CONTEXT* pThreadContext = il2c_acquire_thread_context__();
IL2C_REF_HEADER* pHeader = il2c_get_uninitialized_object_internal__(
il2c_typeof(System_String),
bodySize);
bodySize, (void*)IL2C_THREAD_LOCK_TARGET(pThreadContext));
#endif

System_String* pString = (System_String*)(pHeader + 1);
Expand Down Expand Up @@ -1107,7 +1110,7 @@ System_String_VTABLE_DECL__ System_String_VTABLE__ = {
IL2C_RUNTIME_TYPE_BEGIN(
System_String,
"System.String",
IL2C_TYPE_VARIABLE,
IL2C_TYPE_REFERENCE | IL2C_TYPE_VARIABLE,
0,
System_Object,
0, 0)
Expand Down
Loading

0 comments on commit 058fc7f

Please sign in to comment.