1010import  com .oracle .truffle .api .CompilerAsserts ;
1111import  com .oracle .truffle .api .CompilerDirectives ;
1212import  com .oracle .truffle .api .CompilerDirectives .CompilationFinal ;
13+ import  com .oracle .truffle .api .frame .FrameDescriptor ;
14+ import  com .oracle .truffle .api .frame .FrameSlotKind ;
1315import  com .oracle .truffle .api .frame .VirtualFrame ;
1416import  com .oracle .truffle .api .nodes .ExplodeLoop ;
1517import  com .oracle .truffle .api .nodes .NodeInfo ;
2931import  de .hpi .swa .trufflesqueak .nodes .interrupts .CheckForInterruptsQuickNode ;
3032import  de .hpi .swa .trufflesqueak .shared .SqueakLanguageConfig ;
3133import  de .hpi .swa .trufflesqueak .util .FrameAccess ;
34+ import  de .hpi .swa .trufflesqueak .util .MiscUtils ;
3235
3336@ NodeInfo (language  = SqueakLanguageConfig .ID )
3437public  final  class  StartContextRootNode  extends  AbstractRootNode  {
3538    @ CompilationFinal  private  int  initialPC ;
3639    @ CompilationFinal  private  int  initialSP ;
37-     @ CompilationFinal  private  int  numArgs ;
40+     @ CompilationFinal  private  byte  numTempSlots ;
41+     @ CompilationFinal  private  byte  tempStackSlotStartIndex ;
3842    @ CompilationFinal  private  Assumption  doesNotNeedThisContext ;
3943
4044    @ Child  private  CheckForInterruptsQuickNode  interruptHandlerNode ;
@@ -76,7 +80,7 @@ public Object execute(final VirtualFrame frame) {
7680    private  void  ensureInitialized (final  VirtualFrame  frame ) {
7781        if  (doesNotNeedThisContext  == null ) {
7882            CompilerDirectives .transferToInterpreterAndInvalidate ();
79-             numArgs  = FrameAccess .getNumArguments (frame );
83+             final   int   numArgs  = FrameAccess .getNumArguments (frame );
8084            final  CompiledCodeObject  code  = getCode ();
8185            doesNotNeedThisContext  = code .getDoesNotNeedThisContextAssumption ();
8286            if  (!FrameAccess .hasClosure (frame )) {
@@ -89,6 +93,8 @@ private void ensureInitialized(final VirtualFrame frame) {
8993                initialSP  = closure .getNumTemps ();
9094                assert  numArgs  == closure .getNumArgs () + closure .getNumCopied ();
9195            }
96+             numTempSlots  = MiscUtils .toByteExact (initialSP  - numArgs );
97+             tempStackSlotStartIndex  = MiscUtils .toByteExact (FrameAccess .toStackSlotIndex (frame , numArgs ));
9298        }
9399    }
94100
@@ -102,9 +108,11 @@ private void initializeFrame(final VirtualFrame frame) {
102108
103109        // TODO: avoid nilling out of temp slots to allow slot specializations 
104110        // Initialize remaining temporary variables with nil in newContext. 
105-         for  (int  i  = 0 ; i  < initialSP  - numArgs ; i ++) {
106-             final  int  stackSlotIndex  = FrameAccess .toStackSlotIndex (frame , numArgs  + i );
107-             frame .setObject (stackSlotIndex , NilObject .SINGLETON );
111+         final  FrameDescriptor  descriptor  = frame .getFrameDescriptor ();
112+         for  (int  i  = 0 ; i  < numTempSlots ; i ++) {
113+             final  int  slotIndex  = tempStackSlotStartIndex  + i ;
114+             descriptor .setSlotKind (slotIndex , FrameSlotKind .Object );
115+             frame .setObject (slotIndex , NilObject .SINGLETON );
108116        }
109117    }
110118
0 commit comments