Engine.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "Engine.h"
  2. #include "codegen/il2cpp-codegen.h"
  3. #include "Interpreter.h"
  4. #include "MemoryUtil.h"
  5. namespace hybridclr
  6. {
  7. namespace interpreter
  8. {
  9. InterpFrame* InterpFrameGroup::EnterFrameFromInterpreter(const InterpMethodInfo* imi, StackObject* argBase)
  10. {
  11. #if IL2CPP_ENABLE_PROFILER
  12. il2cpp_codegen_profiler_method_enter(imi->method);
  13. #endif
  14. int32_t oldStackTop = _machineState.GetStackTop();
  15. StackObject* stackBasePtr = _machineState.AllocStackSlot(imi->maxStackSize - imi->argStackObjectSize);
  16. InterpFrame* newFrame = _machineState.PushFrame();
  17. *newFrame = { imi, argBase, oldStackTop, nullptr, nullptr, nullptr, 0, 0, _machineState.GetLocalPoolBottomIdx() };
  18. PUSH_STACK_FRAME(imi->method);
  19. return newFrame;
  20. }
  21. InterpFrame* InterpFrameGroup::EnterFrameFromNative(const InterpMethodInfo* imi, StackObject* argBase)
  22. {
  23. #if IL2CPP_ENABLE_PROFILER
  24. il2cpp_codegen_profiler_method_enter(imi->method);
  25. #endif
  26. int32_t oldStackTop = _machineState.GetStackTop();
  27. StackObject* stackBasePtr = _machineState.AllocStackSlot(imi->maxStackSize);
  28. InterpFrame* newFrame = _machineState.PushFrame();
  29. *newFrame = { imi, stackBasePtr, oldStackTop, nullptr, nullptr, nullptr, 0, 0, _machineState.GetLocalPoolBottomIdx() };
  30. // if not prepare arg stack. copy from args
  31. if (imi->args)
  32. {
  33. IL2CPP_ASSERT(imi->argCount == metadata::GetActualArgumentNum(imi->method));
  34. CopyStackObject(stackBasePtr, argBase, imi->argStackObjectSize);
  35. }
  36. PUSH_STACK_FRAME(imi->method);
  37. return newFrame;
  38. }
  39. InterpFrame* InterpFrameGroup::LeaveFrame()
  40. {
  41. IL2CPP_ASSERT(_machineState.GetFrameTopIdx() > _frameBaseIdx);
  42. POP_STACK_FRAME();
  43. InterpFrame* frame = _machineState.GetTopFrame();
  44. #if IL2CPP_ENABLE_PROFILER
  45. il2cpp_codegen_profiler_method_exit(frame->method->method);
  46. #endif
  47. if (frame->exFlowBase)
  48. {
  49. _machineState.SetExceptionFlowTop(frame->exFlowBase);
  50. }
  51. _machineState.PopFrame();
  52. _machineState.SetStackTop(frame->oldStackTop);
  53. _machineState.SetLocalPoolBottomIdx(frame->oldLocalPoolBottomIdx);
  54. return _machineState.GetFrameTopIdx() > _frameBaseIdx ? _machineState.GetTopFrame() : nullptr;
  55. }
  56. }
  57. }