public int ReserveTableEntry(long ownerAddress, long address, bool isJump) { int entry = Interlocked.Increment(ref _tableEnd); if (entry >= JumpTableSize) { throw new OutOfMemoryException("JIT Direct Jump Table exhausted."); } _jumpRegion.ExpandIfNeeded((ulong)((entry + 1) * JumpTableStride)); // Is the address we have already registered? If so, put the function address in the jump table. // If not, it will point to the direct call stub. long value = (long)DirectCallStubs.DirectCallStub(isJump); if (_targets.TryGetValue((ulong)address, out TranslatedFunction func)) { value = func.GetPointer().ToInt64(); } // Make sure changes to the function at the target address update this jump table entry. LinkedList <int> targetDependants = _dependants.GetOrAdd((ulong)address, (addr) => new LinkedList <int>()); lock (targetDependants) { targetDependants.AddLast(entry); } IntPtr addr = _jumpRegion.Pointer + entry * JumpTableStride; Marshal.WriteInt64(addr, 0, address); Marshal.WriteInt64(addr, 8, value); return(entry); }
public void ExpandIfNeededJumpTable(int entries) { Debug.Assert(entries > 0); if (entries < JumpTableSize) { _jumpRegion.ExpandIfNeeded((ulong)((entries + 1) * JumpTableStride)); } else { throw new OutOfMemoryException("JIT Direct Jump Table exhausted."); } }
public void ExpandIfNeededDynamicTable(int entries) { Debug.Assert(entries > 0); if (entries < DynamicTableSize) { _dynamicRegion.ExpandIfNeeded((ulong)((entries + 1) * DynamicTableStride)); } else { throw new OutOfMemoryException("JIT Dynamic Jump Table exhausted."); } }
private static uint Allocate(uint codeSize) { codeSize = AlignCodeSize(codeSize); if (!_cacheAllocator.TryAllocate(codeSize, out uint allocOffset)) { throw new OutOfMemoryException("JIT Cache exhausted."); } _jitRegion.ExpandIfNeeded(allocOffset + codeSize); return(allocOffset); }
private static int Allocate(int codeSize) { codeSize = AlignCodeSize(codeSize); int allocOffset = _cacheAllocator.Allocate(codeSize); if (allocOffset < 0) { throw new OutOfMemoryException("JIT Cache exhausted."); } _jitRegion.ExpandIfNeeded((ulong)allocOffset + (ulong)codeSize); return(allocOffset); }
private static int Allocate(int codeSize) { codeSize = checked(codeSize + (CodeAlignment - 1)) & ~(CodeAlignment - 1); int allocOffset = _offset; _offset += codeSize; if (_offset > CacheSize) { throw new OutOfMemoryException("JIT Cache exhausted."); } _jitRegion.ExpandIfNeeded((ulong)_offset); return allocOffset; }
private static int Allocate(int codeSize) { codeSize = checked (codeSize + (CodeAlignment - 1)) & ~(CodeAlignment - 1); int allocOffset = _offset; _offset += codeSize; _jitRegion.ExpandIfNeeded((ulong)_offset); if ((ulong)(uint)_offset > CacheSize) { throw new OutOfMemoryException(); } return(allocOffset); }
static JitCache() { _jitRegion = new ReservedRegion(CacheSize); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { _jitRegion.ExpandIfNeeded(PageSize); JitUnwindWindows.InstallFunctionTableHandler(_basePointer, CacheSize); // The first page is used for the table based SEH structs. _offset = PageSize; } _cacheEntries = new List <JitCacheEntry>(); _lock = new object(); }
public static void Initialize(IJitMemoryAllocator allocator) { if (_initialized) return; lock (_lock) { if (_initialized) return; _jitRegion = new ReservedRegion(allocator, CacheSize); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { _jitRegion.ExpandIfNeeded(PageSize); JitUnwindWindows.InstallFunctionTableHandler(_jitRegion.Pointer, CacheSize); // The first page is used for the table based SEH structs. _offset = PageSize; } _initialized = true; } }
public int ReserveDynamicEntry(bool isJump) { int entry = Interlocked.Increment(ref _dynTableEnd); if (entry >= DynamicTableSize) { throw new OutOfMemoryException("JIT Dynamic Jump Table exhausted."); } _dynamicRegion.ExpandIfNeeded((ulong)((entry + 1) * DynamicTableStride)); // Initialize all host function pointers to the indirect call stub. IntPtr addr = _dynamicRegion.Pointer + entry * DynamicTableStride; long stubPtr = (long)DirectCallStubs.IndirectCallStub(isJump); for (int i = 0; i < DynamicTableElems; i++) { Marshal.WriteInt64(addr, i * JumpTableStride + 8, stubPtr); } return(entry); }