public static ObjectInstance AllocateObject(MethodTable methodTable, CorInfoType type = CorInfoType.Class) { var newObject = PetitClrRuntime.Current.GCHeap.Alloc(); newObject.MethodTable = methodTable; newObject.Type = type; newObject.FieldInstances = new ObjectInstance[methodTable.EEClass.NumInstanceFields]; for (var i = 0; i < newObject.FieldInstances.Length; i++) { newObject.FieldInstances[i] = ObjectInstance.Null; } // TODO: implements type assertion //Debug.Assert(methodTable.EEClass.IsValueType == (newObject.Type == CorInfoType.ValueClass)); return newObject; }
public MethodTable BuildMethodTable() { _halfBakedMethodTable = new MethodTable() { MdToken = _typeDefinition.MetadataToken, ClassName = _typeDefinition.FullName, ParentMethodTable = (_typeDefinition.BaseType != null) ? _classLoader.LoadTypeFromTypeRef(_typeDefinition.BaseType) : null, EEClass = null, Interfaces = CreateInterfacesFromTypeDef(), MethodSlots = CreateMethodSlotsFromTypeDef(_typeDefinition), InterfaceMethodSlotMap = _typeDefinition.HasInterfaces ? new Dictionary <MethodReference, int>() : null, }; _halfBakedMethodTable.EEClass = new EEClass() { ParentMethodTable = ParentMethodTable, }; if (_typeDefinition.HasInterfaces) { CreateInterfaceVtableMap(); } // Go thru all fields and initialize their FieldDescs. InitializeFieldDescs(); // Place regular static fields PlaceRegularStaticFields(); // Place thread static fields PlaceThreadStaticFields(); // Create static field slots _halfBakedMethodTable.StaticFields = new ObjectInstance[HalfBakedClass.NumStaticFields + HalfBakedClass.NumThreadStaticFields]; for (var i = 0; i < _halfBakedMethodTable.StaticFields.Length; i++) { _halfBakedMethodTable.StaticFields[i] = ObjectInstance.Null; } if (false /* IsBlittable || IsManagedSequential */) { // TODO: not implemented yet } else { // HandleExplicitLayout fails for the GenericTypeDefinition when // it will succeed for some particular instantiations. // Thus we only do explicit layout for real instantiations, e.g. C<int>, not // the open types such as the GenericTypeDefinition C<!0> or any // of the "fake" types involving generic type variables which are // used for reflection and verification, e.g. C<List<!0>>. // if (false /* !bmtGenerics->fContainsGenericVariables && HasExplicitFieldOffsetLayout */) { //HandleExplicitLayout(pByValueClassCache); // TODO: not implemented yet } else { // Place instance fields PlaceInstanceFields(); } } return(_halfBakedMethodTable); }
public MethodTable BuildMethodTable() { _halfBakedMethodTable = new MethodTable() { MdToken = _typeDefinition.MetadataToken, ClassName = _typeDefinition.FullName, ParentMethodTable = (_typeDefinition.BaseType != null) ? _classLoader.LoadTypeFromTypeRef(_typeDefinition.BaseType) : null, EEClass = null, Interfaces = CreateInterfacesFromTypeDef(), MethodSlots = CreateMethodSlotsFromTypeDef(_typeDefinition), InterfaceMethodSlotMap = _typeDefinition.HasInterfaces ? new Dictionary<MethodReference, int>() : null, }; _halfBakedMethodTable.EEClass = new EEClass() { ParentMethodTable = ParentMethodTable, }; if (_typeDefinition.HasInterfaces) { CreateInterfaceVtableMap(); } // Go thru all fields and initialize their FieldDescs. InitializeFieldDescs(); // Place regular static fields PlaceRegularStaticFields(); // Place thread static fields PlaceThreadStaticFields(); // Create static field slots _halfBakedMethodTable.StaticFields = new ObjectInstance[HalfBakedClass.NumStaticFields + HalfBakedClass.NumThreadStaticFields]; for (var i = 0; i < _halfBakedMethodTable.StaticFields.Length; i++) { _halfBakedMethodTable.StaticFields[i] = ObjectInstance.Null; } if (false /* IsBlittable || IsManagedSequential */) { // TODO: not implemented yet } else { // HandleExplicitLayout fails for the GenericTypeDefinition when // it will succeed for some particular instantiations. // Thus we only do explicit layout for real instantiations, e.g. C<int>, not // the open types such as the GenericTypeDefinition C<!0> or any // of the "fake" types involving generic type variables which are // used for reflection and verification, e.g. C<List<!0>>. // if (false /* !bmtGenerics->fContainsGenericVariables && HasExplicitFieldOffsetLayout */) { //HandleExplicitLayout(pByValueClassCache); // TODO: not implemented yet } else { // Place instance fields PlaceInstanceFields(); } } return _halfBakedMethodTable; }