Permalink
Browse files

Handle allocation on the stack of the valuetype (add ObjectHeader siz…

…e) + handle codegen of methodtable initialization for class as valuetype
  • Loading branch information...
xoofx committed Oct 1, 2015
1 parent ea30a55 commit 92252c1326daeb1d1067df3444f0675486eb4304
Showing with 31 additions and 0 deletions.
  1. +22 −0 src/jit/codegencommon.cpp
  2. +9 −0 src/jit/lclvars.cpp
@@ -6466,6 +6466,28 @@ void CodeGen::genZeroInitFrame(int untrLclHi,
}
}
}

// ClassAsValue: Generates the proper code to setup the methodtable on all local variable that are declared as class used as valuetype.
LclVarDsc* varDsc;
unsigned i;
for (i = 0, varDsc = compiler->lvaTable; i < compiler->lvaCount; i++, varDsc++)
{
// Initialize method table
if (varDsc->lvType == TYP_STRUCT && varDsc->IsReferenceType())
{
// We are going to use the init register to load the address of the MethodTable
*pInitRegZeroed = false;
/* lea eax, [MethodTable]*/
getEmitter()->emitIns_R_AI(INS_lea, EA_PTRSIZE, initReg, (ssize_t)(varDsc->lvReferenceTypeMethodTable));

/* mov [ebp - stackoffs], eax */
getEmitter()->emitIns_AR_R(ins_Store(TYP_I_IMPL),
EA_PTRSIZE,
initReg,
genFramePointerReg(),
varDsc->lvStkOffs);
}
}
}


@@ -4897,6 +4897,15 @@ void Compiler::lvaAssignVirtualFrameOffsetsToLocals()

// Reserve the stack space for this variable
stkOffs = lvaAllocLocalAndSetVirtualOffset(lclNum, lvaLclSize(lclNum), stkOffs);

// ClassAsValue: If we have a reference type allocated on the stack, add a bit
// more space for the object header
// TODO: we should calculate the real space of the object header (OBJHEADER)
if (lvaTable[lclNum].lvType == TYP_STRUCT && lvaTable[lclNum].IsReferenceType())
{
lvaIncrementFrameSize(TARGET_POINTER_SIZE);
stkOffs -= TARGET_POINTER_SIZE;
}
}
}

0 comments on commit 92252c1

Please sign in to comment.