Пример #1
0
        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);
        }
Пример #2
0
        public int ReserveTableEntry(long ownerAddress, long address, bool isJump)
        {
            int entry = Interlocked.Increment(ref _tableEnd);

            ExpandIfNeededJumpTable(entry);

            // 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 = DirectCallStubs.DirectCallStub(isJump).ToInt64();

            if (Targets.TryGetValue((ulong)address, out TranslatedFunction func))
            {
                value = func.FuncPtr.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 = GetEntryAddressJumpTable(entry);

            Marshal.WriteInt64(addr, 0, address);
            Marshal.WriteInt64(addr, 8, value);

            return(entry);
        }
Пример #3
0
        public Translator(MemoryManager memory)
        {
            _memory = memory;

            _funcs = new ConcurrentDictionary <ulong, TranslatedFunction>();

            _jumpTable = JumpTable.Instance;

            _backgroundQueue = new PriorityQueue <RejitRequest>(2);

            _backgroundTranslatorEvent = new AutoResetEvent(false);

            DirectCallStubs.InitializeStubs();
        }
Пример #4
0
        public Translator(IJitMemoryAllocator allocator, IMemoryManager memory)
        {
            _allocator = allocator;
            _memory    = memory;

            _funcs    = new ConcurrentDictionary <ulong, TranslatedFunction>();
            _oldFuncs = new ConcurrentQueue <KeyValuePair <ulong, IntPtr> >();

            _backgroundStack           = new ConcurrentStack <RejitRequest>();
            _backgroundTranslatorEvent = new AutoResetEvent(false);
            _backgroundTranslatorLock  = new ReaderWriterLock();

            JitCache.Initialize(allocator);

            DirectCallStubs.InitializeStubs();
        }
Пример #5
0
        public int ReserveDynamicEntry(bool isJump)
        {
            int entry = Interlocked.Increment(ref _dynTableEnd);

            ExpandIfNeededDynamicTable(entry);

            // Initialize all host function pointers to the indirect call stub.
            IntPtr addr    = GetEntryAddressDynamicTable(entry);
            long   stubPtr = DirectCallStubs.IndirectCallStub(isJump).ToInt64();

            for (int i = 0; i < DynamicTableElems; i++)
            {
                Marshal.WriteInt64(addr, i * JumpTableStride + 8, stubPtr);
            }

            return(entry);
        }
Пример #6
0
        public Translator(IJitMemoryAllocator allocator, IMemoryManager memory)
        {
            _memory = memory;

            _funcs = new ConcurrentDictionary <ulong, TranslatedFunction>();

            _backgroundStack = new ConcurrentStack <RejitRequest>();

            _backgroundTranslatorEvent = new AutoResetEvent(false);

            _jumpTable = new JumpTable(allocator);

            JitCache.Initialize(allocator);

            DirectCallStubs.InitializeStubs();

            if (Ptc.State == PtcState.Enabled)
            {
                Ptc.LoadTranslations(_funcs, memory.PageTablePointer, _jumpTable);
            }
        }
Пример #7
0
        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);
        }