Skip to content

Commit f631371

Browse files
committed
Add function headers, clean up
1 parent 1ca1a94 commit f631371

File tree

2 files changed

+88
-15
lines changed

2 files changed

+88
-15
lines changed

src/coreclr/jit/layout.cpp

Lines changed: 85 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "layout.h"
66
#include "compiler.h"
77

8+
// Key used in ClassLayoutTable's hash table for custom layouts.
89
struct CustomLayoutKey
910
{
1011
unsigned Size;
@@ -413,6 +414,16 @@ ClassLayout* Compiler::typGetBlkLayout(unsigned blockSize)
413414
return typGetCustomLayout(ClassLayoutBuilder(this, blockSize));
414415
}
415416

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+
//
416427
ClassLayout* ClassLayout::Create(Compiler* compiler, CORINFO_CLASS_HANDLE classHandle)
417428
{
418429
bool isValueClass = compiler->eeIsValueClass(classHandle);
@@ -469,6 +480,16 @@ ClassLayout* ClassLayout::Create(Compiler* compiler, CORINFO_CLASS_HANDLE classH
469480
return layout;
470481
}
471482

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+
//
472493
ClassLayout* ClassLayout::Create(Compiler* compiler, const ClassLayoutBuilder& builder)
473494
{
474495
ClassLayout* newLayout = new (compiler, CMK_ClassLayout) ClassLayout(builder.m_size);
@@ -640,17 +661,26 @@ bool ClassLayout::AreCompatible(const ClassLayout* layout1, const ClassLayout* l
640661
return true;
641662
}
642663

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+
//
643672
ClassLayoutBuilder::ClassLayoutBuilder(Compiler* compiler, unsigned size)
644673
: m_compiler(compiler)
645674
, m_size(size)
646675
{
647676
}
648677

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+
//
654684
BYTE* ClassLayoutBuilder::GetOrCreateGCPtrs()
655685
{
656686
assert(m_size % TARGET_POINTER_SIZE == 0);
@@ -663,10 +693,23 @@ BYTE* ClassLayoutBuilder::GetOrCreateGCPtrs()
663693
return m_gcPtrs;
664694
}
665695

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+
//
666707
void ClassLayoutBuilder::SetGCPtr(unsigned slot, CorInfoGCType type)
667708
{
668-
assert(slot < GetSlotCount());
669709
BYTE* ptrs = GetOrCreateGCPtrs();
710+
711+
assert(slot * TARGET_POINTER_SIZE < m_size);
712+
670713
if (ptrs[slot] != TYPE_GC_NONE)
671714
{
672715
m_gcPtrCount--;
@@ -680,6 +723,17 @@ void ClassLayoutBuilder::SetGCPtr(unsigned slot, CorInfoGCType type)
680723
}
681724
}
682725

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+
//
683737
void ClassLayoutBuilder::SetGCPtrType(unsigned slot, var_types type)
684738
{
685739
switch (type)
@@ -694,21 +748,41 @@ void ClassLayoutBuilder::SetGCPtrType(unsigned slot, var_types type)
694748
SetGCPtr(slot, TYPE_GC_NONE);
695749
break;
696750
default:
697-
assert(!"Invalid var_types passed to ClassLayoutBuilder::SetGCPtrType");
751+
assert(!"Invalid type passed to ClassLayoutBuilder::SetGCPtrType");
698752
break;
699753
}
700754
}
701755

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)
703764
{
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)
706768
{
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+
}
708775
}
709776
}
710777

711778
#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+
//
712786
void ClassLayoutBuilder::SetName(const char* name, const char* shortName)
713787
{
714788
m_name = name;

src/coreclr/jit/layout.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,15 @@ class ClassLayoutBuilder
2323
const char* m_shortName = "UNNAMED";
2424
#endif
2525

26-
unsigned GetSlotCount();
27-
BYTE* GetOrCreateGCPtrs();
28-
void SetGCPtr(unsigned slot, CorInfoGCType type);
26+
BYTE* GetOrCreateGCPtrs();
27+
void SetGCPtr(unsigned slot, CorInfoGCType type);
2928
public:
3029
// Create a class layout builder.
3130
//
3231
ClassLayoutBuilder(Compiler* compiler, unsigned size);
3332

3433
void SetGCPtrType(unsigned slot, var_types type);
35-
void SetGCPtrs(unsigned startSlot, ClassLayout* layout);
34+
void CopyInfoFrom(unsigned offset, ClassLayout* layout);
3635

3736
#ifdef DEBUG
3837
void SetName(const char* name, const char* shortName);

0 commit comments

Comments
 (0)