5
5
#include " layout.h"
6
6
#include " compiler.h"
7
7
8
+ // Key used in ClassLayoutTable's hash table for custom layouts.
8
9
struct CustomLayoutKey
9
10
{
10
11
unsigned Size ;
@@ -413,6 +414,16 @@ ClassLayout* Compiler::typGetBlkLayout(unsigned blockSize)
413
414
return typGetCustomLayout (ClassLayoutBuilder (this , blockSize));
414
415
}
415
416
417
+ // ------------------------------------------------------------------------
418
+ // Create: Create a ClassLayout from an EE side class handle.
419
+ //
420
+ // Parameters:
421
+ // compiler - The Compiler object
422
+ // classHandle - The class handle
423
+ //
424
+ // Return value:
425
+ // New layout representing an EE side class.
426
+ //
416
427
ClassLayout* ClassLayout::Create (Compiler* compiler, CORINFO_CLASS_HANDLE classHandle)
417
428
{
418
429
bool isValueClass = compiler->eeIsValueClass (classHandle);
@@ -469,6 +480,16 @@ ClassLayout* ClassLayout::Create(Compiler* compiler, CORINFO_CLASS_HANDLE classH
469
480
return layout;
470
481
}
471
482
483
+ // ------------------------------------------------------------------------
484
+ // Create: Create a ClassLayout from a ClassLayoutBuilder.
485
+ //
486
+ // Parameters:
487
+ // compiler - The Compiler object
488
+ // builder - Builder representing the layout
489
+ //
490
+ // Return value:
491
+ // New layout representing a custom (JIT internal) class layout.
492
+ //
472
493
ClassLayout* ClassLayout::Create (Compiler* compiler, const ClassLayoutBuilder& builder)
473
494
{
474
495
ClassLayout* newLayout = new (compiler, CMK_ClassLayout) ClassLayout (builder.m_size );
@@ -640,17 +661,26 @@ bool ClassLayout::AreCompatible(const ClassLayout* layout1, const ClassLayout* l
640
661
return true ;
641
662
}
642
663
664
+ // ------------------------------------------------------------------------
665
+ // ClassLayoutbuilder: Construct a new builder for a class layout of the
666
+ // specified size.
667
+ //
668
+ // Arguments:
669
+ // compiler - Compiler instance
670
+ // size - Size of the layout
671
+ //
643
672
ClassLayoutBuilder::ClassLayoutBuilder (Compiler* compiler, unsigned size)
644
673
: m_compiler(compiler)
645
674
, m_size(size)
646
675
{
647
676
}
648
677
649
- unsigned ClassLayoutBuilder::GetSlotCount ()
650
- {
651
- return (m_size + TARGET_POINTER_SIZE - 1 ) / TARGET_POINTER_SIZE;
652
- }
653
-
678
+ // ------------------------------------------------------------------------
679
+ // GetOrCreateGCPtrs: Get or create the array indicating GC pointer types.
680
+ //
681
+ // Returns:
682
+ // The array of CorInfoGCType.
683
+ //
654
684
BYTE* ClassLayoutBuilder::GetOrCreateGCPtrs ()
655
685
{
656
686
assert (m_size % TARGET_POINTER_SIZE == 0 );
@@ -663,10 +693,23 @@ BYTE* ClassLayoutBuilder::GetOrCreateGCPtrs()
663
693
return m_gcPtrs;
664
694
}
665
695
696
+ // ------------------------------------------------------------------------
697
+ // SetGCPtr: Set a slot to have specified GC pointer type.
698
+ //
699
+ // Arguments:
700
+ // slot - The GC pointer slot. The slot number corresponds to offset slot * TARGET_POINTER_SIZE.
701
+ // type - Type of GC pointer that this slot contains.
702
+ //
703
+ // Remarks:
704
+ // GC pointer information can only be set in layouts of size divisible by
705
+ // TARGET_POINTER_SIZE.
706
+ //
666
707
void ClassLayoutBuilder::SetGCPtr (unsigned slot, CorInfoGCType type)
667
708
{
668
- assert (slot < GetSlotCount ());
669
709
BYTE* ptrs = GetOrCreateGCPtrs ();
710
+
711
+ assert (slot * TARGET_POINTER_SIZE < m_size);
712
+
670
713
if (ptrs[slot] != TYPE_GC_NONE)
671
714
{
672
715
m_gcPtrCount--;
@@ -680,6 +723,17 @@ void ClassLayoutBuilder::SetGCPtr(unsigned slot, CorInfoGCType type)
680
723
}
681
724
}
682
725
726
+ // ------------------------------------------------------------------------
727
+ // SetGCPtrType: Set a slot to have specified type.
728
+ //
729
+ // Arguments:
730
+ // slot - The GC pointer slot. The slot number corresponds to offset slot * TARGET_POINTER_SIZE.
731
+ // type - Type that this slot contains. Must be TYP_REF, TYP_BYREF or TYP_I_IMPL.
732
+ //
733
+ // Remarks:
734
+ // GC pointer information can only be set in layouts of size divisible by
735
+ // TARGET_POINTER_SIZE.
736
+ //
683
737
void ClassLayoutBuilder::SetGCPtrType (unsigned slot, var_types type)
684
738
{
685
739
switch (type)
@@ -694,21 +748,41 @@ void ClassLayoutBuilder::SetGCPtrType(unsigned slot, var_types type)
694
748
SetGCPtr (slot, TYPE_GC_NONE);
695
749
break ;
696
750
default :
697
- assert (!" Invalid var_types passed to ClassLayoutBuilder::SetGCPtrType" );
751
+ assert (!" Invalid type passed to ClassLayoutBuilder::SetGCPtrType" );
698
752
break ;
699
753
}
700
754
}
701
755
702
- void ClassLayoutBuilder::SetGCPtrs (unsigned startSlot, ClassLayout* layout)
756
+ // ------------------------------------------------------------------------
757
+ // CopyInfoFrom: Copy GC pointers from another layout.
758
+ //
759
+ // Arguments:
760
+ // offset - Offset in this builder to start copy information into.
761
+ // layout - Layout to get information from.
762
+ //
763
+ void ClassLayoutBuilder::CopyInfoFrom (unsigned offset, ClassLayout* layout)
703
764
{
704
- assert (startSlot + layout->GetSlotCount () <= m_size / TARGET_POINTER_SIZE);
705
- for (unsigned slot = 0 ; slot < layout->GetSlotCount (); slot++)
765
+ assert (offset + layout->GetSize () <= m_size);
766
+
767
+ if (layout->GetGCPtrCount () > 0 )
706
768
{
707
- SetGCPtr (startSlot + slot, layout->GetGCPtr (slot));
769
+ assert (offset % TARGET_POINTER_SIZE == 0 );
770
+ unsigned startSlot = offset / TARGET_POINTER_SIZE;
771
+ for (unsigned slot = 0 ; slot < layout->GetSlotCount (); slot++)
772
+ {
773
+ SetGCPtr (startSlot + slot, layout->GetGCPtr (slot));
774
+ }
708
775
}
709
776
}
710
777
711
778
#ifdef DEBUG
779
+ // ------------------------------------------------------------------------
780
+ // SetName: Set the long and short name of the layout.
781
+ //
782
+ // Arguments:
783
+ // name - The long name
784
+ // shortName - The short name
785
+ //
712
786
void ClassLayoutBuilder::SetName (const char * name, const char * shortName)
713
787
{
714
788
m_name = name;
0 commit comments