Skip to content
This repository was archived by the owner on Nov 1, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/ILToNative/src/Compiler/AsmWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ void OutputCode()

OutputEETypes();

Out.WriteLine();
Out.WriteLine(".data");

OutputStatics();

Out.Dispose();
}

Expand Down Expand Up @@ -222,6 +227,13 @@ void OutputReadyToHelpers()
Out.WriteLine("jmp __castclass_class");
break;

case ReadyToRunHelperId.GetNonGCStaticBase:
Out.Write("leaq __NonGCStaticBase_");
Out.Write(GetMangledTypeName((TypeDesc)helper.Target));
Out.WriteLine("(%rip), %rax");
Out.WriteLine("ret");
break;

default:
throw new NotImplementedException();
}
Expand Down Expand Up @@ -260,6 +272,33 @@ void OutputEETypes()
}
}

void OutputStatics()
{
foreach (var t in _registeredTypes.Values)
{
if (!t.IncludedInCompilation)
continue;

var type = t.Type as MetadataType;
if (type == null)
continue;

if (type.NonGCStaticFieldSize > 0)
{
Out.Write(".align ");
Out.WriteLine(type.NonGCStaticFieldAlignment);
Out.Write("__NonGCStaticBase_");
Out.Write(GetMangledTypeName(type));
Out.WriteLine(":");
Out.Write(".rept ");
Out.WriteLine(type.NonGCStaticFieldSize);
Out.WriteLine(".byte 0");
Out.WriteLine(".endr");
Out.WriteLine();
}
}
}

void OutputVirtualSlots(TypeDesc implType, TypeDesc declType)
{
var baseType = declType.BaseType;
Expand Down
3 changes: 3 additions & 0 deletions src/ILToNative/src/Compiler/ReadyToRunHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public enum ReadyToRunHelperId
VirtualCall,
IsInstanceOf,
CastClass,
GetNonGCStaticBase,
}

class ReadyToRunHelper
Expand Down Expand Up @@ -48,6 +49,8 @@ public string MangledName
return "__IsInstanceOf_" + _compilation.GetMangledTypeName((TypeDesc)this.Target);
case ReadyToRunHelperId.CastClass:
return "__CastClass_" + _compilation.GetMangledTypeName((TypeDesc)this.Target);
case ReadyToRunHelperId.GetNonGCStaticBase:
return "__GetNonGCStaticBase_" + _compilation.GetMangledTypeName((TypeDesc)this.Target);
default:
throw new NotImplementedException();
}
Expand Down
31 changes: 27 additions & 4 deletions src/JitInterface/src/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,10 @@ CorInfoIsAccessAllowedResult canAccessClass(IntPtr _this, ref CORINFO_RESOLVED_T
}

CORINFO_CLASS_STRUCT_* getFieldClass(IntPtr _this, CORINFO_FIELD_STRUCT_* field)
{ throw new NotImplementedException(); }
{
var fieldDesc = HandleToObject(field);
return ObjectToHandle(fieldDesc.OwningType);
}

CorInfoType getFieldType(IntPtr _this, CORINFO_FIELD_STRUCT_* field, ref CORINFO_CLASS_STRUCT_* structType, CORINFO_CLASS_STRUCT_* memberParent)
{
Expand Down Expand Up @@ -825,10 +828,30 @@ void getFieldInfo(IntPtr _this, ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORIN
if (field.IsStatic)
{
fieldFlags |= CORINFO_FIELD_FLAGS.CORINFO_FLG_FIELD_STATIC;
fieldAccessor = CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_STATIC_ADDRESS;

// TODO: Shared statics/HasFieldRVA
throw new NotImplementedException();
if (field.HasRva)
{
throw new NotSupportedException();
}

// Make sure to include the type in the compilation
_compilation.AddType(field.OwningType);

fieldAccessor = CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_STATIC_SHARED_STATIC_HELPER;
pResult.helper = CorInfoHelpFunc.CORINFO_HELP_READYTORUN_STATIC_BASE;

ReadyToRunHelperId helperId;
if (field.IsThreadStatic || field.HasGCStaticBase)
{
throw new NotImplementedException();
}
else
{
helperId = ReadyToRunHelperId.GetNonGCStaticBase;
}

pResult.fieldLookup.addr = (void*)ObjectToHandle(_compilation.GetReadyToRunHelper(helperId, field.OwningType));
pResult.fieldLookup.accessType = InfoAccessType.IAT_VALUE;
}
else
{
Expand Down
12 changes: 12 additions & 0 deletions src/TypeSystem/src/Common/FieldDesc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System;
using System.Runtime.CompilerServices;

using Debug = System.Diagnostics.Debug;

namespace Internal.TypeSystem
{
public abstract partial class FieldDesc
Expand Down Expand Up @@ -54,6 +56,16 @@ public abstract bool IsInitOnly
get;
}

public abstract bool IsThreadStatic
{
get;
}

public abstract bool HasRva
{
get;
}

public virtual FieldDesc GetTypicalFieldDefinition()
{
return this;
Expand Down
16 changes: 16 additions & 0 deletions src/TypeSystem/src/Common/FieldForInstantiatedType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ public override bool IsInitOnly
}
}

public override bool IsThreadStatic
{
get
{
return _fieldDef.IsThreadStatic;
}
}

public override bool HasRva
{
get
{
return _fieldDef.HasRva;
}
}

public override FieldDesc GetTypicalFieldDefinition()
{
return _fieldDef;
Expand Down
Loading