ClassInlines.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #pragma once
  2. //This file should not include anything from VM. This is included by both libil2cpp and the codegen headers
  3. #include "il2cpp-config.h"
  4. #include "il2cpp-class-internals.h"
  5. #include "il2cpp-object-internals.h"
  6. namespace il2cpp
  7. {
  8. namespace vm
  9. {
  10. class LIBIL2CPP_CODEGEN_API ClassInlines
  11. {
  12. public:
  13. // we assume that the Il2CppClass's have already been initialized in this case, like in code generation
  14. static inline bool HasParentUnsafe(const Il2CppClass* klass, const Il2CppClass* parent) { return klass->typeHierarchyDepth >= parent->typeHierarchyDepth && klass->typeHierarchy[parent->typeHierarchyDepth - 1] == parent; }
  15. // This function is critical for performance, before optimization it
  16. // caused up to 20% of all CPU usage in code generated by il2cpp
  17. static IL2CPP_FORCE_INLINE bool InitFromCodegen(Il2CppClass *klass)
  18. {
  19. if (klass->initialized_and_no_error)
  20. return true;
  21. return InitFromCodegenSlow(klass);
  22. }
  23. static IL2CPP_NO_INLINE bool InitFromCodegenSlow(Il2CppClass *klass);
  24. //internal
  25. static IL2CPP_FORCE_INLINE const VirtualInvokeData& GetInterfaceInvokeDataFromVTable(Il2CppObject* obj, const Il2CppClass* itf, Il2CppMethodSlot slot)
  26. {
  27. const Il2CppClass* klass = obj->klass;
  28. IL2CPP_ASSERT(klass->initialized);
  29. IL2CPP_ASSERT(slot < itf->method_count);
  30. for (uint16_t i = 0; i < klass->interface_offsets_count; i++)
  31. {
  32. if (klass->interfaceOffsets[i].interfaceType == itf)
  33. {
  34. int32_t offset = klass->interfaceOffsets[i].offset;
  35. IL2CPP_ASSERT(offset != -1);
  36. IL2CPP_ASSERT(offset + slot < klass->vtable_count);
  37. return klass->vtable[offset + slot];
  38. }
  39. }
  40. return GetInterfaceInvokeDataFromVTableSlowPath(obj, itf, slot);
  41. }
  42. static IL2CPP_FORCE_INLINE const VirtualInvokeData* GetInterfaceInvokeDataFromVTable(const Il2CppClass* klass, const Il2CppClass* itf, Il2CppMethodSlot slot)
  43. {
  44. IL2CPP_ASSERT(klass->initialized);
  45. IL2CPP_ASSERT(slot < itf->method_count);
  46. for (uint16_t i = 0; i < klass->interface_offsets_count; i++)
  47. {
  48. if (klass->interfaceOffsets[i].interfaceType == itf)
  49. {
  50. int32_t offset = klass->interfaceOffsets[i].offset;
  51. IL2CPP_ASSERT(offset != -1);
  52. IL2CPP_ASSERT(offset + slot < klass->vtable_count);
  53. return &klass->vtable[offset + slot];
  54. }
  55. }
  56. return GetInterfaceInvokeDataFromVTableSlowPath(klass, itf, slot);
  57. }
  58. // we don't want this method to get inlined because that makes GetInterfaceInvokeDataFromVTable method itself very large and performance suffers
  59. static IL2CPP_NO_INLINE const VirtualInvokeData& GetInterfaceInvokeDataFromVTableSlowPath(Il2CppObject* obj, const Il2CppClass* itf, Il2CppMethodSlot slot);
  60. static IL2CPP_NO_INLINE const VirtualInvokeData* GetInterfaceInvokeDataFromVTableSlowPath(const Il2CppClass* klass, const Il2CppClass* itf, Il2CppMethodSlot slot);
  61. };
  62. }
  63. }