text:
package tr.com.serkanozal.mysafe.impl;

import org.apache.log4j.Logger;
import sun.misc.Unsafe;
import tr.com.serkanozal.mysafe.*;
import tr.com.serkanozal.mysafe.impl.accessor.UnsafeMemoryAccessor;
import tr.com.serkanozal.mysafe.impl.accessor.UnsafeMemoryAccessorFactory;
import tr.com.serkanozal.mysafe.impl.allocpath.AllocationPath;
import tr.com.serkanozal.mysafe.impl.allocpath.AllocationPathAllocatedMemory;
import tr.com.serkanozal.mysafe.impl.allocpath.manager.AllocationPathManager;
import tr.com.serkanozal.mysafe.impl.allocpath.manager.instrument.InstrumentationBasedAllocationPathManager;
import tr.com.serkanozal.mysafe.impl.allocpath.storage.AllocationPathStorage;
import tr.com.serkanozal.mysafe.impl.allocpath.storage.DefaultAllocationPathStorage;
import tr.com.serkanozal.mysafe.impl.allocpath.storage.ThreadLocalAwareAllocationPathStorage;
import tr.com.serkanozal.mysafe.impl.allocpath.storage.ThreadLocalDefaultAllocationPathStorage;
import tr.com.serkanozal.mysafe.impl.storage.*;
import tr.com.serkanozal.mysafe.impl.util.HeapMemoryBackedLong2LongHashMap;
import tr.com.serkanozal.mysafe.impl.util.Long2LongMap;
import tr.com.serkanozal.mysafe.impl.util.Long2LongMap.LongLongCursor;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicLong;

import static tr.com.serkanozal.mysafe.AllocatedMemoryStorage.INVALID;
import static tr.com.serkanozal.mysafe.IllegalMemoryAccessListener.MemoryAccessType.*;

public final class MySafeDelegator {

    private static final Logger LOGGER = Logger.getLogger(MySafeDelegator.class);

    private static final AllocatedMemoryStorage ALLOCATED_MEMORY_STORAGE;
    private static volatile IllegalMemoryAccessListener ILLEGAL_MEMORY_ACCESS_LISTENER;
    private static final Unsafe DEFAULT_UNSAFE;
    private static final UnsafeMemoryAccessor UNSAFE_MEMORY_ACCESSOR;
    private static final MemoryAccessLock MEMORY_ACCESS_LOCK;
    private static Set<MemoryListener> LISTENERS =
            Collections.newSetFromMap(new ConcurrentHashMap<MemoryListener, Boolean>());
    private static final AllocationPathStorage ALLOCATION_PATH_STORAGE;
    private static final AllocationPathManager ALLOCATION_PATH_MANAGER;
    private static final AtomicLong ALLOCATED_MEMORY = new AtomicLong(0L);
    private static final int OBJECT_REFERENCE_SIZE;
    private static final ScheduledExecutorService SCHEDULER =
            Executors.newScheduledThreadPool(1, new ThreadFactory() {
                private final ThreadFactory delegatedThreadFactory = Executors.defaultThreadFactory();
                @Override
                public Thread newThread(Runnable r) {
                    Thread thread = delegatedThreadFactory.newThread(r);
                    thread.setDaemon(true);
                    return thread;
                }
            });

    private static final boolean SAFE_MEMORY_MANAGEMENT_MODE_ENABLED =
            Boolean.getBoolean("mysafe.enableSafeMemoryManagementMode");
    private static final boolean SAFE_MEMORY_ACCESS_MODE_ENABLED;
    private static final boolean ALLOCATION_PATH_MONITORING_MODE_ENABLED =
            Boolean.getBoolean("mysafe.enableAllocationPathMonitoringMode");
    private static final boolean THREAD_LOCAL_MEMORY_USAGE_PATTERN_EXIST =
            Boolean.getBoolean("mysafe.threadLocalMemoryUsagePatternExist");
    private static volatile boolean REGISTERED_LISTENER_EXIST = false;

    static {
        MySafe.initialize();

        boolean safeMemoryAccessModeEnabled = Boolean.getBoolean("mysafe.enableSafeMemoryAccessMode");
        if (Boolean.getBoolean("mysafe.useCustomMemoryManagement")) {
            if (safeMemoryAccessModeEnabled) {
                LOGGER.warn("`Custom Memory Management` and `Safe Memory Access Mode` features cannot be used together. " +
                            "Since `Custom Memory Management` feature is enabled, " +
                            "`Safe Memory Access Mode` feature is being skipped ...");
            }
            SAFE_MEMORY_ACCESS_MODE_ENABLED = false;
        } else {
            SAFE_MEMORY_ACCESS_MODE_ENABLED = safeMemoryAccessModeEnabled;
        }

        DEFAULT_UNSAFE = MySafe.getUnsafe();

        UNSAFE_MEMORY_ACCESSOR = UnsafeMemoryAccessorFactory.createUnsafeMemoryAccessor(DEFAULT_UNSAFE);
        OBJECT_REFERENCE_SIZE = DEFAULT_UNSAFE.arrayIndexScale(Object[].class);

        boolean concurrentMemoryAccessCheckEnabled;
        if (SAFE_MEMORY_ACCESS_MODE_ENABLED) {
            concurrentMemoryAccessCheckEnabled = Boolean.getBoolean("mysafe.enableConcurrentMemoryAccessCheck");
        } else {
            concurrentMemoryAccessCheckEnabled = false;
        }
        if (concurrentMemoryAccessCheckEnabled) {
            MEMORY_ACCESS_LOCK = new MemoryAccessLock(DEFAULT_UNSAFE);
        } else {
            MEMORY_ACCESS_LOCK = null;
        }

        ThreadLocalMemoryUsageDecider threadLocalMemoryUsageDecider = null;
        String threadLocalMemoryUsageDeciderConfig = System.getProperty("mysafe.threadLocalMemoryUsageDeciderImpl");
        if (threadLocalMemoryUsageDeciderConfig != null) {
            String[] threadLocalMemoryUsageDeciderConfigParts = threadLocalMemoryUsageDeciderConfig.split(":");
            String threadLocalMemoryUsageDeciderImplClassName = threadLocalMemoryUsageDeciderConfigParts[0];
            try {
                @SuppressWarnings("unchecked")
                Class<? extends ThreadLocalMemoryUsageDecider> threadLocalMemoryUsageDeciderImplClass =
                        (Class<? extends ThreadLocalMemoryUsageDecider>) ClassLoader.getSystemClassLoader().
                            loadClass(threadLocalMemoryUsageDeciderImplClassName);
                threadLocalMemoryUsageDecider = threadLocalMemoryUsageDeciderImplClass.newInstance();
                if (threadLocalMemoryUsageDecider instanceof ParametricThreadLocalMemoryUsageDecider) {
                    String[] params = new String[threadLocalMemoryUsageDeciderConfigParts.length - 1];
                    System.arraycopy(threadLocalMemoryUsageDeciderConfigParts, 1,
                                     params, 0,
                                     params.length);
                    ((ParametricThreadLocalMemoryUsageDecider) threadLocalMemoryUsageDecider).initWithParameters(params);
                }
            } catch (Exception e) {
                throw new IllegalStateException(
                        "Couldn't create instance of custom 'ThreadLocalMemoryUsageDecider' implementation: " +
                        threadLocalMemoryUsageDeciderImplClassName, e);
            }
        }

        String allocatedMemoryStorageImplClassName = System.getProperty("mysafe.allocatedMemoryStorageImpl");
        if (allocatedMemoryStorageImplClassName != null) {
            try {
                @SuppressWarnings("unchecked")
                Class<? extends AllocatedMemoryStorage> ALLOCATED_MEMORYStorageImplClass =
                        (Class<? extends AllocatedMemoryStorage>) ClassLoader.getSystemClassLoader().
                            loadClass(allocatedMemoryStorageImplClassName);
                ALLOCATED_MEMORY_STORAGE = ALLOCATED_MEMORYStorageImplClass.newInstance();
            } catch (Exception e) {
                throw new IllegalStateException(
                        "Couldn't create instance of custom 'AllocatedMemoryStorage' implementation: " +
                                allocatedMemoryStorageImplClassName, e);
            }
        } else {
            if (THREAD_LOCAL_MEMORY_USAGE_PATTERN_EXIST) {
                AllocatedMemoryStorage threadLocalAllocatedMemoryStorage = null;
                if (safeMemoryAccessModeEnabled) {
                    threadLocalAllocatedMemoryStorage =
                            new ThreadLocalNavigatableAllocatedMemoryStorage(DEFAULT_UNSAFE, SCHEDULER);
                } else {
                    threadLocalAllocatedMemoryStorage =
                            new ThreadLocalDefaultAllocatedMemoryStorage(DEFAULT_UNSAFE, SCHEDULER);
                }
                if (threadLocalMemoryUsageDecider != null) {
                    AllocatedMemoryStorage globalAllocatedMemoryStorage;
                    if (safeMemoryAccessModeEnabled) {
                        globalAllocatedMemoryStorage = new NavigatableAllocatedMemoryStorage();
                    } else {
                        globalAllocatedMemoryStorage = new DefaultAllocatedMemoryStorage();
                    }
                    ALLOCATED_MEMORY_STORAGE =
                            new ThreadLocalAwareAllocatedMemoryStorage(
                                    globalAllocatedMemoryStorage,
                                    threadLocalAllocatedMemoryStorage,
                                    threadLocalMemoryUsageDecider);
                } else {
                    ALLOCATED_MEMORY_STORAGE = threadLocalAllocatedMemoryStorage;
                }
            } else {
                if (safeMemoryAccessModeEnabled) {
                    ALLOCATED_MEMORY_STORAGE = new NavigatableAllocatedMemoryStorage();
                } else {
                    ALLOCATED_MEMORY_STORAGE = new DefaultAllocatedMemoryStorage();
                }
            }
        }

        String illegalMemoryAccessListenerImplClassName = System.getProperty("mysafe.illegalMemoryAccessListenerImpl");
        if (illegalMemoryAccessListenerImplClassName != null) {
            try {
                @SuppressWarnings("unchecked")
                Class<? extends IllegalMemoryAccessListener> illegalMemoryAccessListenerImplClass =
                        (Class<? extends IllegalMemoryAccessListener>) ClassLoader.getSystemClassLoader().
                            loadClass(illegalMemoryAccessListenerImplClassName);
                ILLEGAL_MEMORY_ACCESS_LISTENER = illegalMemoryAccessListenerImplClass.newInstance();
            } catch (Exception e) {
                throw new IllegalStateException(
                        "Couldn't create instance of custom 'IllegalMemoryAccessListener' implementation: " +
                        illegalMemoryAccessListenerImplClassName, e);
            }
        } else {
            ILLEGAL_MEMORY_ACCESS_LISTENER = null;
        }

        if (ALLOCATION_PATH_MONITORING_MODE_ENABLED) {
            if (THREAD_LOCAL_MEMORY_USAGE_PATTERN_EXIST) {
                if (threadLocalMemoryUsageDecider != null) {
                    ALLOCATION_PATH_STORAGE =
                            new ThreadLocalAwareAllocationPathStorage(DEFAULT_UNSAFE, threadLocalMemoryUsageDecider, SCHEDULER);
                } else {
                    ALLOCATION_PATH_STORAGE = new ThreadLocalDefaultAllocationPathStorage(DEFAULT_UNSAFE, SCHEDULER);
                }
            } else {
                ALLOCATION_PATH_STORAGE = new DefaultAllocationPathStorage();
            }
        } else {
            ALLOCATION_PATH_STORAGE = null;
        }

        String allocationPathManagerImplClassName = System.getProperty("mysafe.allocatipnPathManagerImpl");
        if (allocationPathManagerImplClassName != null) {
            try {
                @SuppressWarnings("unchecked")
                Class<? extends AllocationPathManager> allocationPathManagerImplClass =
                        (Class<? extends AllocationPathManager>) ClassLoader.getSystemClassLoader().
                                loadClass(allocationPathManagerImplClassName);
                ALLOCATION_PATH_MANAGER = allocationPathManagerImplClass.newInstance();
            } catch (Exception e) {
                throw new IllegalStateException(
                        "Couldn't create instance of custom 'AllocationPathManager' implementation: " +
                        allocationPathManagerImplClassName, e);
            }
        } else {
            ALLOCATION_PATH_MANAGER = new InstrumentationBasedAllocationPathManager();
        }
    }

    private MySafeDelegator() {
        throw new UnsupportedOperationException("Not avaiable for instantiation!");
    }

    private static class MemoryAccessLock {

        private final Unsafe UNSAFE;
        private final long MEMORY_STATE_FIELD_OFFSET;
        private final long WAITERS_FOR_ACCESS_FIELD_OFFSET;
        private final long WAITERS_FOR_FREE_FIELD_OFFSET;

        private volatile int memoryState = 0;
        private volatile int waitersForAccess = 0;
        private volatile int waitersForFree = 0;

        private MemoryAccessLock(Unsafe unsafe) {
            try {
                UNSAFE = unsafe;
                MEMORY_STATE_FIELD_OFFSET =
                        UNSAFE.objectFieldOffset(MemoryAccessLock.class.getDeclaredField("memoryState"));
                WAITERS_FOR_ACCESS_FIELD_OFFSET =
                        UNSAFE.objectFieldOffset(MemoryAccessLock.class.getDeclaredField("waitersForAccess"));
                WAITERS_FOR_FREE_FIELD_OFFSET =
                        UNSAFE.objectFieldOffset(MemoryAccessLock.class.getDeclaredField("waitersForFree"));
            } catch (Throwable t) {
                throw new IllegalStateException(t);
            }
        }

        private void operateOnWaitersForAccess(int operation) {
            for (;;) {
                int currentWaitersForAccess = waitersForAccess;
                if (UNSAFE.compareAndSwapInt(this, WAITERS_FOR_ACCESS_FIELD_OFFSET,
                                             currentWaitersForAccess, currentWaitersForAccess + operation)) {
                    break;
                }
            }
        }

        private void acquireAccessLock() {
            operateOnWaitersForAccess(+1);
            for (;;) {
                if (waitersForFree > 0) {
                    while (memoryState > 0);
                }
                int currentState = memoryState;
                if (currentState >= 0) {
                    if (UNSAFE.compareAndSwapInt(this, MEMORY_STATE_FIELD_OFFSET,
                                                 currentState, currentState + 1)) {
                        break;
                    }
                }
            }
            operateOnWaitersForAccess(-1);
        }

        private void operateOnWaitersForFree(int operation) {
            for (;;) {
                int currentWaitersForFree = waitersForFree;
                if (UNSAFE.compareAndSwapInt(this, WAITERS_FOR_FREE_FIELD_OFFSET,
                                             currentWaitersForFree, currentWaitersForFree + operation)) {
                    break;
                }
            }
        }

        private void acquireFreeLock() {
            operateOnWaitersForFree(+1);
            for (;;) {
                if (waitersForAccess > 0) {
                    while (memoryState < 0);
                }
                int currentState = memoryState;
                if (currentState <= 0) {
                    if (UNSAFE.compareAndSwapInt(this, MEMORY_STATE_FIELD_OFFSET,
                                                 currentState, currentState - 1)) {
                        break;
                    }
                }
            }
            operateOnWaitersForFree(-1);
        }

        private void releaseAccessLock() {
            for (;;) {
                int currentState = memoryState;
                assert currentState > 0 : "Current state must be negative while releasing access lock but it is " + currentState;
                if (UNSAFE.compareAndSwapInt(this, MEMORY_STATE_FIELD_OFFSET,
                                             currentState, currentState - 1)) {
                    break;
                }
            }
        }

        private void releaseFreeLock() {
            for (;;) {
                int currentState = memoryState;
            	assert currentState < 0 : "Current state must be negative while releasing free lock but it is " + currentState;
                if (UNSAFE.compareAndSwapInt(this, MEMORY_STATE_FIELD_OFFSET,
                                             currentState, currentState + 1)) {
                    break;
                }
            }
        }
    }

    //////////////////////////////////////////////////////////////////////////

    //////////////////////////////////////////////////////////////////////////

    public static boolean isSafeMemoryManagementModeEnabled() {
        return SAFE_MEMORY_MANAGEMENT_MODE_ENABLED;
    }

    public static boolean isSafeMemoryAccessModeEnabled() {
        return SAFE_MEMORY_ACCESS_MODE_ENABLED;
    }

    //////////////////////////////////////////////////////////////////////////

    public static void beforeAllocateMemory(long size) {
        if (REGISTERED_LISTENER_EXIST) {
            for (MemoryListener listener : LISTENERS) {
                listener.beforeAllocateMemory(size);
            }
        }
    }

    private static long doAllocateMemory(Unsafe unsafe, long size) {
        return unsafe.allocateMemory(size);
    }

    public static void afterAllocateMemory(long size, long address) {
        ALLOCATED_MEMORY_STORAGE.put(address, size);
        ALLOCATED_MEMORY.addAndGet(size);
        if (ALLOCATION_PATH_MONITORING_MODE_ENABLED) {
            ALLOCATION_PATH_MANAGER.saveAllocationPathOnAllocation(ALLOCATION_PATH_STORAGE, address, 2);
        }
        if (REGISTERED_LISTENER_EXIST) {
            for (MemoryListener listener : LISTENERS) {
                listener.afterAllocateMemory(address, size);
            }
        }
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Allocated memory at address " +
                         String.format("0x%016x", address) + " with size " + size);
        }
    }

    public static long allocateMemory(Unsafe unsafe, long size) {
        beforeAllocateMemory(size);
        long address = doAllocateMemory(unsafe, size);
        afterAllocateMemory(size, address);
        return address;
    }

    //////////////////////////////////////////////////////////////////////////

    public static long beforeFreeMemory(long address) {
        if (REGISTERED_LISTENER_EXIST) {
            for (MemoryListener listener : LISTENERS) {
                listener.beforeFreeMemory(address);
            }
        }
        return ALLOCATED_MEMORY_STORAGE.remove(address);
    }

    private static void doFreeMemory(Unsafe unsafe, long address) {
        if (SAFE_MEMORY_ACCESS_MODE_ENABLED && MEMORY_ACCESS_LOCK != null) {
            MEMORY_ACCESS_LOCK.acquireFreeLock();
        }
        try {
            unsafe.freeMemory(address);
        } finally {
            if (SAFE_MEMORY_ACCESS_MODE_ENABLED && MEMORY_ACCESS_LOCK != null) {
                MEMORY_ACCESS_LOCK.releaseFreeLock();
            }
        }
    }

    public static void afterFreeMemory(long address, long size) {
        if (size != INVALID) {
            ALLOCATED_MEMORY.addAndGet(-size);
            if (ALLOCATION_PATH_MONITORING_MODE_ENABLED) {
                ALLOCATION_PATH_MANAGER.deleteAllocationPathOnFree(ALLOCATION_PATH_STORAGE, address);
            }
            if (REGISTERED_LISTENER_EXIST) {
                for (MemoryListener listener : LISTENERS) {
                    listener.afterFreeMemory(address, size, true);
                }
            }
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Free memory at address " + String.format("0x%016x", address));
            }
        } else {
            if (SAFE_MEMORY_MANAGEMENT_MODE_ENABLED) {
                String msg = "Tried to free unallocated (or out of the record) memory at address " +
                        String.format("0x%016x", address);
                if (REGISTERED_LISTENER_EXIST) {
                    for (MemoryListener listener : LISTENERS) {
                        listener.afterFreeMemory(address, INVALID, false);
                    }
                }
                if (ILLEGAL_MEMORY_ACCESS_LISTENER != null) {
                    ILLEGAL_MEMORY_ACCESS_LISTENER.onIllegalMemoryAccess(address, INVALID, FREE);
                }
                LOGGER.error(msg);
                throw new IllegalArgumentException(msg);
            } else {
                if (REGISTERED_LISTENER_EXIST) {
                    for (MemoryListener listener : LISTENERS) {
                        listener.afterFreeMemory(address, INVALID, false);
                    }
                }
            }
        }
    }

    public static void freeMemory(Unsafe unsafe, long address) {
        long size = beforeFreeMemory(address);
        if (size != INVALID) {
            doFreeMemory(unsafe, address);
            afterFreeMemory(address, size);
        } else {
            if (!SAFE_MEMORY_MANAGEMENT_MODE_ENABLED) {
                String msg = "Trying to free unallocated (or out of the record) memory at address " +
                             String.format("0x%016x", address);
                LOGGER.warn(msg);
                doFreeMemory(unsafe, address);
            } else {
                afterFreeMemory(address, size);
            }
        }
    }

    //////////////////////////////////////////////////////////////////////////

    public static long beforeReallocateMemory(long oldAddress) {
        long oldSize = ALLOCATED_MEMORY_STORAGE.remove(oldAddress);
        if (oldSize != INVALID) {
            if (REGISTERED_LISTENER_EXIST) {
                for (MemoryListener listener : LISTENERS) {
                    listener.beforeReallocateMemory(oldAddress, oldSize);
                }
            }
        }
        return oldSize;
    }

    private static long doReallocateMemory(Unsafe unsafe, long oldAddress, long newSize) {
        if (SAFE_MEMORY_ACCESS_MODE_ENABLED && MEMORY_ACCESS_LOCK != null) {
            MEMORY_ACCESS_LOCK.acquireFreeLock();
        }
        try {
            return unsafe.reallocateMemory(oldAddress, newSize);
        } finally {
            if (SAFE_MEMORY_ACCESS_MODE_ENABLED && MEMORY_ACCESS_LOCK != null) {
                MEMORY_ACCESS_LOCK.releaseFreeLock();
            }
        }
    }

    public static void afterReallocateMemory(long oldAddress, long oldSize,
                                             long newAddress, long newSize) {
        if (oldSize != INVALID) {
            ALLOCATED_MEMORY_STORAGE.put(newAddress, newSize);
            ALLOCATED_MEMORY.addAndGet(newSize - oldSize);
            if (ALLOCATION_PATH_MONITORING_MODE_ENABLED) {
                ALLOCATION_PATH_MANAGER.deleteAllocationPathOnFree(ALLOCATION_PATH_STORAGE, oldAddress);
                ALLOCATION_PATH_MANAGER.saveAllocationPathOnAllocation(ALLOCATION_PATH_STORAGE, newAddress, 2);
            }
            if (REGISTERED_LISTENER_EXIST) {
                for (MemoryListener listener : LISTENERS) {
                    listener.afterReallocateMemory(oldAddress, oldSize, newAddress, newSize, true);
                }
            }
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Reallocate memory from address " +
                             String.format("0x%016x", oldAddress) + " with size of " + oldSize +
                             " to address " + String.format("0x%016x", newAddress) + " with size of " + newSize);
            }
        }  else {
            if (SAFE_MEMORY_MANAGEMENT_MODE_ENABLED) {
                String msg = "Tried to reallocate unallocated (or out of the record) memory at address " +
                             String.format("0x%016x", oldAddress) + " with new size " + newSize;
                if (REGISTERED_LISTENER_EXIST) {
                    for (MemoryListener listener : LISTENERS) {
                        listener.beforeReallocateMemory(oldAddress, INVALID);
                    }
                }
                if (ILLEGAL_MEMORY_ACCESS_LISTENER != null) {
                    ILLEGAL_MEMORY_ACCESS_LISTENER.onIllegalMemoryAccess(oldAddress, INVALID, REALLOCATE);
                }
                LOGGER.error(msg);
                throw new IllegalArgumentException(msg);
            } else {
                if (REGISTERED_LISTENER_EXIST) {
                    for (MemoryListener listener : LISTENERS) {
                        listener.afterReallocateMemory(oldAddress, INVALID, newAddress, newSize, false);
                    }
                }
            }
        }
    }

    public static long reallocateMemory(Unsafe unsafe, long oldAddress, long newSize) {
        long oldSize = beforeReallocateMemory(oldAddress);
        long newAddress = INVALID;
        if (oldSize != INVALID) {
            newAddress = doReallocateMemory(unsafe, oldAddress, newSize);
            afterReallocateMemory(oldAddress, oldSize, newAddress, newSize);

        } else {
            if (!SAFE_MEMORY_MANAGEMENT_MODE_ENABLED) {
                String msg = "Trying to reallocate unallocated (or out of the record) memory at address " +
                             String.format("0x%016x", oldAddress) + " with new size " + newSize;
                LOGGER.warn(msg);
                newAddress = doReallocateMemory(unsafe, oldAddress, newSize);
            } else {
                afterReallocateMemory(oldAddress, oldSize, newAddress, newSize);
            }
        }
        return newAddress;
    }

    //////////////////////////////////////////////////////////////////////////

    public static long getAllocatedMemorySize() {
        return ALLOCATED_MEMORY.get();
    }

    public static void iterateOnAllocatedMemories(AllocatedMemoryIterator iterator) {
        ALLOCATED_MEMORY_STORAGE.iterate(iterator);
    }

    public static void dumpAllocatedMemories(final PrintStream ps, final Unsafe unsafe) {
        ALLOCATED_MEMORY_STORAGE.iterate(new AllocatedMemoryIterator() {
            @Override
            public void onAllocatedMemory(long address, long size) {
                ps.println("Address         : " + String.format("0x%016x", address));
                ps.println("Size            : " + size + " bytes");
                ps.println("Dump            :");
                dump(ps, unsafe, address, size);
                if (ALLOCATION_PATH_MONITORING_MODE_ENABLED) {
                    ps.println("Allocation Path :");
                    AllocationPath allocationPath = ALLOCATION_PATH_MANAGER.getAllocationPath(ALLOCATION_PATH_STORAGE, address);
                    if (allocationPath == null) {
                        ps.println("\tNo related allocation path!");
                    } else {
                        for (String callPoint : allocationPath.callPoints) {
                            ps.println("\t|- " + callPoint);
                        }
                    }
                }
                ps.println();
                ps.print("========================================");
                ps.print("========================================");
                ps.println();
                ps.println();
            }
        });
    }

    private static void dump(PrintStream ps, Unsafe unsafe, long address, long size) {
        for (int i = 0; i < size; i++) {
            if (i % 16 == 0) {
                ps.print(String.format("\t[0x%016x]: ", i));
            }
            ps.print(String.format("%02x ", unsafe.getByte(address + i)));
            if ((i + 1) % 16 == 0) {
                ps.println();
            }
        }
        if (size % 16 != 0) {
            ps.println();
        }
    }

    public static void dumpAllocationPaths(final PrintStream ps) {
        if (ALLOCATION_PATH_MONITORING_MODE_ENABLED) {
            ALLOCATED_MEMORY_STORAGE.iterate(new AllocatedMemoryIterator() {
                @Override
                public void onAllocatedMemory(long address, long size) {
                    ps.println("Allocated memory : " + size + " bytes");
                    ps.println("Allocation path  :");
                    AllocationPath allocationPath = ALLOCATION_PATH_MANAGER.getAllocationPath(ALLOCATION_PATH_STORAGE, address);
                    if (allocationPath == null) {
                        ps.println("\tNo related allocation path!");
                    } else {
                        for (String callPoint : allocationPath.callPoints) {
                            ps.println("\t|- " + callPoint);
                        }
                    }
                    ps.println();
                    ps.print("========================================");
                    ps.print("========================================");
                    ps.println();
                    ps.println();
                }
            });
        } else {
            ps.println("Allocation path monitoring is not enabled. " +
                       "Please enable it with 'mysafe.enableAllocationPathMonitoringMode' system property");
        }
    }

    public static void generateAllocationPathDiagrams() {
        generateAllocationPathDiagrams(AllocationPathDiagramGenerator.DEFAULT_DIAGRAM_NANE);
    }

    public static void generateAllocationPathDiagrams(String diagramName) {
        if (ALLOCATION_PATH_MONITORING_MODE_ENABLED) {
            final Long2LongMap allocationPathMemoryUsageMap = new HeapMemoryBackedLong2LongHashMap(0);
            ALLOCATED_MEMORY_STORAGE.iterate(new AllocatedMemoryIterator() {
                @Override
                public void onAllocatedMemory(long address, long size) {
                    long allocationPathKey = ALLOCATION_PATH_STORAGE.getAllocationPathKey(address);
                    addAllocationPathMemoryUsage(allocationPathMemoryUsageMap, allocationPathKey, size);
                }
            });

            LongLongCursor cursor = allocationPathMemoryUsageMap.cursor();
            List<AllocationPathAllocatedMemory> allocationPathAllocatedMemories =
                    new ArrayList<AllocationPathAllocatedMemory>((int) allocationPathMemoryUsageMap.size());
            while (cursor.advance()) {
                long allocationPathKey = cursor.key();
                long allocatedMemory = cursor.value();
                AllocationPath allocationPath = ALLOCATION_PATH_MANAGER.getAllocationPath(allocationPathKey);
                allocationPathAllocatedMemories.add(new AllocationPathAllocatedMemory(allocationPath, allocatedMemory));
            }
            AllocationPathDiagramGenerator.generateAllocationPathDiagram(diagramName, allocationPathAllocatedMemories);
        } else {
            throw new IllegalStateException(
                       "Allocation path monitoring is not enabled. " +
                       "Please enable it with 'mysafe.enableAllocationPathMonitoringMode' system property");
        }
    }

    private static void addAllocationPathMemoryUsage(Long2LongMap allocationPathMemoryUsageMap,
                                                     long allocationPathKey,
                                                     long size) {
        long allocatedMemory = allocationPathMemoryUsageMap.get(allocationPathKey);
        allocatedMemory += size;
        allocationPathMemoryUsageMap.put(allocationPathKey, allocatedMemory);
    }

    //////////////////////////////////////////////////////////////////////////

    public static synchronized void registerMemoryListener(MemoryListener listener) {
        LISTENERS.add(listener);
        REGISTERED_LISTENER_EXIST = true;
    }

    public static synchronized void deregisterMemoryListener(MemoryListener listener) {
        LISTENERS.remove(listener);
        REGISTERED_LISTENER_EXIST = !LISTENERS.isEmpty();
    }

    //////////////////////////////////////////////////////////////////////////

    public static IllegalMemoryAccessListener getIllegalMemoryAccessListener() {
        return ILLEGAL_MEMORY_ACCESS_LISTENER;
    }

    public static void setIllegalMemoryAccessListener(IllegalMemoryAccessListener illegalMemoryAccessListener) {
        ILLEGAL_MEMORY_ACCESS_LISTENER = illegalMemoryAccessListener;
    }

    //////////////////////////////////////////////////////////////////////////

    private static void checkMemoryAccess(long address, long size,
            IllegalMemoryAccessListener.MemoryAccessType memoryAccessType) {
        if (SAFE_MEMORY_ACCESS_MODE_ENABLED) {
            if (MEMORY_ACCESS_LOCK != null) {
                MEMORY_ACCESS_LOCK.acquireAccessLock();
            }
            if (!ALLOCATED_MEMORY_STORAGE.contains(address, size)) {
                if (MEMORY_ACCESS_LOCK != null) {
                    MEMORY_ACCESS_LOCK.releaseAccessLock();
                }
                if (ILLEGAL_MEMORY_ACCESS_LISTENER != null) {
                    ILLEGAL_MEMORY_ACCESS_LISTENER.onIllegalMemoryAccess(
                            address, size,  memoryAccessType);
                }
                throw new IllegalArgumentException(
                            "Trying to access (" + memoryAccessType + ") unallocated (or out of the record) memory " +
                            "at address " + String.format("0x%016x", address) + " with size " + size);
            }
        }
    }

    private static void checkMemoryAccess(long sourceAddress, long destinationAddress, long size) {
        if (SAFE_MEMORY_ACCESS_MODE_ENABLED) {
            if (MEMORY_ACCESS_LOCK != null) {
                MEMORY_ACCESS_LOCK.acquireAccessLock();
            }
            if (!ALLOCATED_MEMORY_STORAGE.contains(sourceAddress, size)) {
                if (MEMORY_ACCESS_LOCK != null) {
                    MEMORY_ACCESS_LOCK.releaseAccessLock();
                }
                if (ILLEGAL_MEMORY_ACCESS_LISTENER != null) {
                    ILLEGAL_MEMORY_ACCESS_LISTENER.onIllegalMemoryAccess(
                            sourceAddress, size,  READ);
                }
                throw new IllegalArgumentException(
                            "Trying to access (" + READ + ") unallocated (or out of the record) memory " +
                            "at address " + String.format("0x%016x", sourceAddress) + " with size " + size);

            }
            if (!ALLOCATED_MEMORY_STORAGE.contains(destinationAddress, size)) {
                if (MEMORY_ACCESS_LOCK != null) {
                    MEMORY_ACCESS_LOCK.releaseAccessLock();
                }
                if (ILLEGAL_MEMORY_ACCESS_LISTENER != null) {
                    ILLEGAL_MEMORY_ACCESS_LISTENER.onIllegalMemoryAccess(
                            destinationAddress, size,  WRITE);
                }
                throw new IllegalArgumentException(
                            "Trying to access (" + WRITE + ") unallocated (or out of the record) memory " +
                            "at address " + String.format("0x%016x", destinationAddress) + " with size " + size);
            }
        }
    }

    private static void onReturnMemoryAccess() {
        if (SAFE_MEMORY_ACCESS_MODE_ENABLED && MEMORY_ACCESS_LOCK != null) {
            MEMORY_ACCESS_LOCK.releaseAccessLock();
        }
    }

    private static void checkMemoryAccess(Object o, long offset, long size,
            IllegalMemoryAccessListener.MemoryAccessType memoryAccessType) {
        if (SAFE_MEMORY_ACCESS_MODE_ENABLED && o == null) {
            if (MEMORY_ACCESS_LOCK != null) {
                MEMORY_ACCESS_LOCK.acquireAccessLock();
            }
            if (!ALLOCATED_MEMORY_STORAGE.contains(offset, size)) {
                if (MEMORY_ACCESS_LOCK != null) {
                    MEMORY_ACCESS_LOCK.releaseAccessLock();
                }
                if (ILLEGAL_MEMORY_ACCESS_LISTENER != null) {
                    ILLEGAL_MEMORY_ACCESS_LISTENER.onIllegalMemoryAccess(
                            offset, size, memoryAccessType);
                }
                throw new IllegalArgumentException(
                            "Trying to access (" + memoryAccessType + ") unallocated (or out of the record) memory " +
                            "at address " + String.format("0x%016x", offset) + " with size " + size);
            }
        }
    }

    private static void onReturnMemoryAccess(Object o) {
        if (SAFE_MEMORY_ACCESS_MODE_ENABLED && MEMORY_ACCESS_LOCK != null && o == null) {
            MEMORY_ACCESS_LOCK.releaseAccessLock();
        }
    }

    private static void checkMemoryAccess(Object sourceObject, long sourceOffset,
            Object destinationObject, long destinationOffset, long size) {
        if (SAFE_MEMORY_ACCESS_MODE_ENABLED && sourceObject == null && destinationObject == null) {
            if (MEMORY_ACCESS_LOCK != null) {
                MEMORY_ACCESS_LOCK.acquireAccessLock();
            }
            if (!ALLOCATED_MEMORY_STORAGE.contains(sourceOffset, size)) {
                if (MEMORY_ACCESS_LOCK != null) {
                    MEMORY_ACCESS_LOCK.releaseAccessLock();
                }
                if (ILLEGAL_MEMORY_ACCESS_LISTENER != null) {
                    ILLEGAL_MEMORY_ACCESS_LISTENER.onIllegalMemoryAccess(
                            sourceOffset, size, READ);
                }
                throw new IllegalArgumentException(
                            "Trying to access (" + READ + ") unallocated (or out of the record) memory " +
                            "at address " + String.format("0x%016x", sourceOffset) + " with size " + size);
            }
            if (!ALLOCATED_MEMORY_STORAGE.contains(destinationOffset, size)) {
                if (MEMORY_ACCESS_LOCK != null) {
                    MEMORY_ACCESS_LOCK.releaseAccessLock();
                }
                if (ILLEGAL_MEMORY_ACCESS_LISTENER != null) {
                    ILLEGAL_MEMORY_ACCESS_LISTENER.onIllegalMemoryAccess(
                            destinationOffset, size, WRITE);
                }
                throw new IllegalArgumentException(
                            "Trying to access (" + WRITE + ") unallocated (or out of the record) memory " +
                            "at address " + String.format("0x%016x", destinationOffset) + " with size " + size);
            }
        }
    }

    private static void onReturnMemoryAccess(Object sourceObject, Object destinationObject) {
        if (SAFE_MEMORY_ACCESS_MODE_ENABLED && MEMORY_ACCESS_LOCK != null &&
                sourceObject == null && destinationObject == null) {
            MEMORY_ACCESS_LOCK.releaseAccessLock();
        }
    }

    //////////////////////////////////////////////////////////////////////////

    @Deprecated
    public static boolean getBoolean(Unsafe unsafe, Object o, int offset) {
        checkMemoryAccess(o, offset, 1, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getBoolean(unsafe, o, offset);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    @Deprecated
    public static void putBoolean(Unsafe unsafe, Object o, int offset, boolean x) {
        checkMemoryAccess(o, offset, 1, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putBoolean(unsafe, o, offset, x);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    @Deprecated
    public static byte getByte(Unsafe unsafe, Object o, int offset) {
        checkMemoryAccess(o, offset, 1, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getByte(unsafe, o, offset);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    @Deprecated
    public static void putByte(Unsafe unsafe, Object o, int offset, byte x) {
        checkMemoryAccess(o, offset, 1, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putByte(unsafe, o, offset, x);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    @Deprecated
    public static char getChar(Unsafe unsafe, Object o, int offset) {
        checkMemoryAccess(o, offset, 2, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getChar(unsafe, o, offset);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    @Deprecated
    public static void putChar(Unsafe unsafe, Object o, int offset, char x) {
        checkMemoryAccess(o, offset, 2, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putChar(unsafe, o, offset, x);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    @Deprecated
    public static short getShort(Unsafe unsafe, Object o, int offset) {
        checkMemoryAccess(o, offset, 2, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getShort(unsafe, o, offset);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    @Deprecated
    public static void putShort(Unsafe unsafe, Object o, int offset, short x) {
        checkMemoryAccess(o, offset, 2, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putShort(unsafe, o, offset, x);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    @Deprecated
    public static int getInt(Unsafe unsafe, Object o, int offset) {
        checkMemoryAccess(o, offset, 4, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getInt(unsafe, o, (long)offset);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    @Deprecated
    public static void putInt(Unsafe unsafe, Object o, int offset, int x) {
        checkMemoryAccess(o, offset, 4, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putInt(unsafe, o, offset, x);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    @Deprecated
    public static float getFloat(Unsafe unsafe, Object o, int offset) {
        checkMemoryAccess(o, offset, 4, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getFloat(unsafe, o, offset);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    @Deprecated
    public static void putFloat(Unsafe unsafe, Object o, int offset, float x) {
        checkMemoryAccess(o, offset, 4, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putFloat(unsafe, o, offset, x);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    @Deprecated
    public static long getLong(Unsafe unsafe, Object o, int offset) {
        checkMemoryAccess(o, offset, 8, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getLong(unsafe, o, offset);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    @Deprecated
    public static void putLong(Unsafe unsafe, Object o, int offset, long x) {
        checkMemoryAccess(o, offset, 8, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putLong(unsafe, o, offset, x);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    @Deprecated
    public static double getDouble(Unsafe unsafe, Object o, int offset) {
        checkMemoryAccess(o, offset, 8, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getDouble(unsafe, o, offset);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    @Deprecated
    public static void putDouble(Unsafe unsafe, Object o, int offset, double x) {
        checkMemoryAccess(o, offset, 8, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putDouble(unsafe, o, offset, x);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    @Deprecated
    public static Object getObject(Unsafe unsafe, Object o, int offset) {
        checkMemoryAccess(o, offset, OBJECT_REFERENCE_SIZE, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getObject(unsafe, o, offset);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    @Deprecated
    public static void putObject(Unsafe unsafe, Object o, int offset, Object x) {
        checkMemoryAccess(o, offset, OBJECT_REFERENCE_SIZE, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putObject(unsafe, o, offset, x);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    //////////////////////////////////////////////////////////////////////////

    public static boolean getBoolean(Unsafe unsafe, Object o, long offset) {
        checkMemoryAccess(o, offset, 1, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getBoolean(unsafe, o, offset);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static void putBoolean(Unsafe unsafe, Object o, long offset, boolean x) {
        checkMemoryAccess(o, offset, 1, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putBoolean(unsafe, o, offset, x);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static byte getByte(Unsafe unsafe, Object o, long offset) {
        checkMemoryAccess(o, offset, 1, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getByte(unsafe, o, offset);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static void putByte(Unsafe unsafe, Object o, long offset, byte x) {
        checkMemoryAccess(o, offset, 1, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putByte(unsafe, o, offset, x);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static char getChar(Unsafe unsafe, Object o, long offset) {
        checkMemoryAccess(o, offset, 2, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getChar(unsafe, o, offset);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static void putChar(Unsafe unsafe, Object o, long offset, char x) {
        checkMemoryAccess(o, offset, 2, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putChar(unsafe, o, offset, x);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static short getShort(Unsafe unsafe, Object o, long offset) {
        checkMemoryAccess(o, offset, 2, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getShort(unsafe, o, offset);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static void putShort(Unsafe unsafe, Object o, long offset, short x) {
        checkMemoryAccess(o, offset, 2, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putShort(unsafe, o, offset, x);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static int getInt(Unsafe unsafe, Object o, long offset) {
        checkMemoryAccess(o, offset, 4, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getInt(unsafe, o, offset);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static void putInt(Unsafe unsafe, Object o, long offset, int x) {
        checkMemoryAccess(o, offset, 4, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putInt(unsafe, o, offset, x);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static float getFloat(Unsafe unsafe, Object o, long offset) {
        checkMemoryAccess(o, offset, 4, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getFloat(unsafe, o, offset);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static void putFloat(Unsafe unsafe, Object o, long offset, float x) {
        checkMemoryAccess(o, offset, 4, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putFloat(unsafe, o, offset, x);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static long getLong(Unsafe unsafe, Object o, long offset) {
        checkMemoryAccess(o, offset, 8, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getLong(unsafe, o, offset);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static void putLong(Unsafe unsafe, Object o, long offset, long x) {
        checkMemoryAccess(o, offset, 8, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putLong(unsafe, o, offset, x);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static double getDouble(Unsafe unsafe, Object o, long offset) {
        checkMemoryAccess(o, offset, 8, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getDouble(unsafe, o, offset);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static void putDouble(Unsafe unsafe, Object o, long offset, double x) {
        checkMemoryAccess(o, offset, 8, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putDouble(unsafe, o, offset, x);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static Object getObject(Unsafe unsafe, Object o, long offset) {
        checkMemoryAccess(o, offset, OBJECT_REFERENCE_SIZE, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getObject(unsafe, o, offset);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static void putObject(Unsafe unsafe, Object o, long offset, Object x) {
        checkMemoryAccess(o, offset, OBJECT_REFERENCE_SIZE, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putObject(unsafe, o, offset, x);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    //////////////////////////////////////////////////////////////////////////

    public static boolean getBooleanVolatile(Unsafe unsafe, Object o, long offset) {
        checkMemoryAccess(o, offset, 1, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getBooleanVolatile(unsafe, o, offset);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static void putBooleanVolatile(Unsafe unsafe, Object o, long offset, boolean x) {
        checkMemoryAccess(o, offset, 1, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putBooleanVolatile(unsafe, o, offset, x);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static byte getByteVolatile(Unsafe unsafe, Object o, long offset) {
        checkMemoryAccess(o, offset, 1, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getByteVolatile(unsafe, o, offset);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static void putByteVolatile(Unsafe unsafe, Object o, long offset, byte x) {
        checkMemoryAccess(o, offset, 1, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putByteVolatile(unsafe, o, offset, x);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static char getCharVolatile(Unsafe unsafe, Object o, long offset) {
        checkMemoryAccess(o, offset, 2, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getCharVolatile(unsafe, o, offset);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static void putCharVolatile(Unsafe unsafe, Object o, long offset, char x) {
        checkMemoryAccess(o, offset, 2, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putCharVolatile(unsafe, o, offset, x);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static short getShortVolatile(Unsafe unsafe, Object o, long offset) {
        checkMemoryAccess(o, offset, 2, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getShortVolatile(unsafe, o, offset);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static void putShortVolatile(Unsafe unsafe, Object o, long offset, short x) {
        checkMemoryAccess(o, offset, 2, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putShortVolatile(unsafe, o, offset, x);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static int getIntVolatile(Unsafe unsafe, Object o, long offset) {
        checkMemoryAccess(o, offset, 4, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getIntVolatile(unsafe, o, offset);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static void putIntVolatile(Unsafe unsafe, Object o, long offset, int x) {
        checkMemoryAccess(o, offset, 4, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putIntVolatile(unsafe, o, offset, x);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static float getFloatVolatile(Unsafe unsafe, Object o, long offset) {
        checkMemoryAccess(o, offset, 4, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getFloatVolatile(unsafe, o, offset);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static void putFloatVolatile(Unsafe unsafe, Object o, long offset, float x) {
        checkMemoryAccess(o, offset, 4, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putFloatVolatile(unsafe, o, offset, x);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static long getLongVolatile(Unsafe unsafe, Object o, long offset) {
        checkMemoryAccess(o, offset, 8, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getLongVolatile(unsafe, o, offset);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static void putLongVolatile(Unsafe unsafe, Object o, long offset, long x) {
        checkMemoryAccess(o, offset, 8, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putLongVolatile(unsafe, o, offset, x);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static double getDoubleVolatile(Unsafe unsafe, Object o, long offset) {
        checkMemoryAccess(o, offset, 8, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getDoubleVolatile(unsafe, o, offset);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static void putDoubleVolatile(Unsafe unsafe, Object o, long offset, double x) {
        checkMemoryAccess(o, offset, 8, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putDoubleVolatile(unsafe, o, offset, x);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static Object getObjectVolatile(Unsafe unsafe, Object o, long offset) {
        checkMemoryAccess(o, offset, OBJECT_REFERENCE_SIZE, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getObjectVolatile(unsafe, o, offset);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static void putObjectVolatile(Unsafe unsafe, Object o, long offset, Object x) {
        checkMemoryAccess(o, offset, OBJECT_REFERENCE_SIZE, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putObjectVolatile(unsafe, o, offset, x);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    //////////////////////////////////////////////////////////////////////////

    public static boolean getBoolean(Unsafe unsafe, long address) {
        checkMemoryAccess(address, 1, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getByte(unsafe, address) == 0 ? false : true;
        } finally {
            onReturnMemoryAccess();
        }
    }

    public static void putBoolean(Unsafe unsafe, long address, boolean x) {
        checkMemoryAccess(address, 1, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putByte(unsafe, address, x ? (byte) 0x01 : (byte) 0x00);
        } finally {
            onReturnMemoryAccess();
        }
    }

    public static byte getByte(Unsafe unsafe, long address) {
        checkMemoryAccess(address, 1, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getByte(unsafe, address);
        } finally {
            onReturnMemoryAccess();
        }
    }

    public static void putByte(Unsafe unsafe, long address, byte x) {
        checkMemoryAccess(address, 1, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putByte(unsafe, address, x);
        } finally {
            onReturnMemoryAccess();
        }
    }

    public static char getChar(Unsafe unsafe, long address) {
        checkMemoryAccess(address, 2, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getChar(unsafe, address);
        } finally {
            onReturnMemoryAccess();
        }
    }

    public static void putChar(Unsafe unsafe, long address, char x) {
        checkMemoryAccess(address, 2, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putChar(unsafe, address, x);
        } finally {
            onReturnMemoryAccess();
        }
    }

    public static short getShort(Unsafe unsafe, long address) {
        checkMemoryAccess(address, 2, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getShort(unsafe, address);
        } finally {
            onReturnMemoryAccess();
        }
    }

    public static void putShort(Unsafe unsafe, long address, short x) {
        checkMemoryAccess(address, 2, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putShort(unsafe, address, x);
        } finally {
            onReturnMemoryAccess();
        }
    }

    public static int getInt(Unsafe unsafe, long address) {
        checkMemoryAccess(address, 4, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getInt(unsafe, address);
        } finally {
            onReturnMemoryAccess();
        }
    }

    public static void putInt(Unsafe unsafe, long address, int x) {
        checkMemoryAccess(address, 4, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putInt(unsafe, address, x);
        } finally {
            onReturnMemoryAccess();
        }
    }

    public static float getFloat(Unsafe unsafe, long address) {
        checkMemoryAccess(address, 4, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getFloat(unsafe, address);
        } finally {
            onReturnMemoryAccess();
        }
    }

    public static void putFloat(Unsafe unsafe, long address, float x) {
        checkMemoryAccess(address, 4, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putFloat(unsafe, address, x);
        } finally {
            onReturnMemoryAccess();
        }
    }

    public static long getLong(Unsafe unsafe, long address) {
        checkMemoryAccess(address, 8, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getLong(unsafe, address);
        } finally {
            onReturnMemoryAccess();
        }
    }

    public static void putLong(Unsafe unsafe, long address, long x) {
        checkMemoryAccess(address, 8, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putLong(unsafe, address, x);
        } finally {
            onReturnMemoryAccess();
        }
    }

    public static double getDouble(Unsafe unsafe, long address) {
        checkMemoryAccess(address, 8, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getDouble(unsafe, address);
        } finally {
            onReturnMemoryAccess();
        }
    }

    public static void putDouble(Unsafe unsafe, long address, double x) {
        checkMemoryAccess(address, 8, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putDouble(unsafe, address, x);
        } finally {
            onReturnMemoryAccess();
        }
    }

    //////////////////////////////////////////////////////////////////////////

    public static long getAddress(Unsafe unsafe, long address) {
        checkMemoryAccess(address, OBJECT_REFERENCE_SIZE, READ);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getAddress(unsafe, address);
        } finally {
            onReturnMemoryAccess();
        }
    }

    public static void putAddress(Unsafe unsafe, long address, long x) {
        checkMemoryAccess(address, OBJECT_REFERENCE_SIZE, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putAddress(unsafe, address, x);
        } finally {
            onReturnMemoryAccess();
        }
    }

    //////////////////////////////////////////////////////////////////////////

    public static void setMemory(Unsafe unsafe, long address, long bytes, byte value) {
        checkMemoryAccess(address, bytes, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.setMemory(unsafe, address, bytes, value);
        } finally {
            onReturnMemoryAccess();
        }
    }

    /**
     * @since 1.7
     */
    public static void setMemory(Unsafe unsafe, Object o, long offset, long bytes, byte value) {
        checkMemoryAccess(o, offset, bytes, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.setMemory(unsafe, o, offset, bytes, value);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static void copyMemory(Unsafe unsafe, long srcAddress, long destAddress, long bytes) {
        checkMemoryAccess(srcAddress, destAddress, bytes);
        try {
            UNSAFE_MEMORY_ACCESSOR.copyMemory(unsafe, srcAddress, destAddress, bytes);
        } finally {
            onReturnMemoryAccess();
        }
    }

    /**
     * @since 1.7
     */
    public static void copyMemory(Unsafe unsafe, Object srcBase, long srcOffset,
                                  Object destBase, long destOffset, long bytes) {
        checkMemoryAccess(srcBase, srcOffset, destBase, destOffset, bytes);
        try {
            UNSAFE_MEMORY_ACCESSOR.copyMemory(unsafe, srcBase, srcOffset, destBase, destOffset, bytes);
        } finally {
            onReturnMemoryAccess(srcBase, destBase);
        }
    }

    //////////////////////////////////////////////////////////////////////////

    public static boolean compareAndSwapInt(Unsafe unsafe, Object o, long offset,
                                            int expected, int x) {
        checkMemoryAccess(o, offset, 4, READ_WRITE);
        try {
            return UNSAFE_MEMORY_ACCESSOR.compareAndSwapInt(unsafe, o, offset, expected, x);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static boolean compareAndSwapLong(Unsafe unsafe, Object o, long offset,
                                             long expected, long x) {
        checkMemoryAccess(o, offset, 8, READ_WRITE);
        try {
            return UNSAFE_MEMORY_ACCESSOR.compareAndSwapLong(unsafe, o, offset, expected, x);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static boolean compareAndSwapObject(Unsafe unsafe, Object o, long offset,
                                               Object expected, Object x) {
        checkMemoryAccess(o, offset, OBJECT_REFERENCE_SIZE, READ_WRITE);
        try {
            return UNSAFE_MEMORY_ACCESSOR.compareAndSwapObject(unsafe, o, offset, expected, x);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    //////////////////////////////////////////////////////////////////////////

    public static void putOrderedInt(Unsafe unsafe, Object o, long offset, int x) {
        checkMemoryAccess(o, offset, 4, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putOrderedInt(unsafe, o, offset, x);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static void putOrderedLong(Unsafe unsafe, Object o, long offset, long x) {
        checkMemoryAccess(o, offset, 8, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putOrderedLong(unsafe, o, offset, x);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    public static void putOrderedObject(Unsafe unsafe, Object o, long offset, Object x) {
        checkMemoryAccess(o, offset, OBJECT_REFERENCE_SIZE, WRITE);
        try {
            UNSAFE_MEMORY_ACCESSOR.putOrderedObject(unsafe, o, offset, x);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    //////////////////////////////////////////////////////////////////////////

    /**
     * @since 1.8
     */
    public static int getAndAddInt(Unsafe unsafe, Object o, long offset, int delta) {
        checkMemoryAccess(o, offset, 4, READ_WRITE);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getAndAddInt(unsafe, o, offset, delta);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    /**
     * @since 1.8
     */
    public static long getAndAddLong(Unsafe unsafe, Object o, long offset, long delta) {
        checkMemoryAccess(o, offset, 8, READ_WRITE);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getAndAddLong(unsafe, o, offset, delta);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    /**
     * @since 1.8
     */
    public static int getAndSetInt(Unsafe unsafe, Object o, long offset, int newValue) {
        checkMemoryAccess(o, offset, 4, READ_WRITE);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getAndSetInt(unsafe, o, offset, newValue);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    /**
     * @since 1.8
     */
    public static long getAndSetLong(Unsafe unsafe, Object o, long offset, long newValue) {
        checkMemoryAccess(o, offset, 8, READ_WRITE);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getAndSetLong(unsafe, o, offset, newValue);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    /**
     * @since 1.8
     */
    public static Object getAndSetObject(Unsafe unsafe, Object o, long offset, Object newValue) {
        checkMemoryAccess(o, offset, OBJECT_REFERENCE_SIZE, READ_WRITE);
        try {
            return UNSAFE_MEMORY_ACCESSOR.getAndSetObject(unsafe, o, offset, newValue);
        } finally {
            onReturnMemoryAccess(o);
        }
    }

    //////////////////////////////////////////////////////////////////////////

}


text:
/*global QUnit*/

sap.ui.define([
	"sap/ui/test/opaQunit",
	"sap/ui/thirdparty/sinon",
	"sap/ui/core/library",
	"../data/presetUtil",
	"../SupportAssistantOpaConfig"
], function(opaTest, sinon, library, presetUtil) {
	"use strict";

	// shortcut for sap.ui.core.ValueState
	var ValueState = library.ValueState;
	var testPresetExample = presetUtil.loadExamplePreset(presetUtil.titles.EXAMPLE_PRESET_1);

	QUnit.module("Support Assistant Rule Presets - Export");

	opaTest("Should see Support Assistant rules loaded", function(Given, When, Then) {
		Given.iDeletePersistedData()
			.and.iStartMyApp();

		Then.onTheRulesPage.iShouldSeeRulesTreeTable();
	});

	opaTest("Should see default presets loaded", function(Given, When, Then) {
		When.onThePresetsPage.iOpenPresetsPopover();
		Then.onThePresetsPage.iShouldSeePresetInPopover(presetUtil.titles.MY_SELECTION_TITLE);
	});

	opaTest("Should see validation messages when required inputs are not filled", function(Given, When, Then) {
		When.onThePresetsPage.iPressExport();

		When.onThePresetsPage.iEnterExportData("title", "")
			.and.iEnterExportData("presetId", "")
			.and.iEnterExportData("description", "");
		When.onThePresetsPage.iPressExportFinalize();
		Then.onThePresetsPage.iShouldSeeExportDialog();
		Then.onThePresetsPage.iShouldSeeCorrectValueState("title", ValueState.Error)
			.and.iShouldSeeCorrectValueState("presetId", ValueState.None)
			.and.iShouldSeeCorrectValueState("description", ValueState.None);

	});

	opaTest("Should see validation messages when inputs with constraints have invalid values", function(Given, When, Then) {

		When.onThePresetsPage.iEnterExportData("title", "Title")
			.and.iEnterExportData("description", "Description")
			.and.iEnterExportData("presetId", "id+with+invalid+characters");

		When.onThePresetsPage.iPressExportFinalize();

		Then.onThePresetsPage.iShouldSeeExportDialog();

		Then.onThePresetsPage.iShouldSeeCorrectValueState("presetId", ValueState.Error)
			.and.iShouldSeeCorrectValueState("title", ValueState.None)
			.and.iShouldSeeCorrectValueState("description", ValueState.None);

	});

	opaTest("Should be able to export after inputs are filled with valid values", function(Given, When, Then) {

		When.onThePresetsPage.iEnterExportData("presetId", "valid_id");

		When.onThePresetsPage.iPressExportFinalize();

		Then.onThePresetsPage.iShouldReceiveOneExportFile()
			.and.iShouldReceiveCorrectExportFile({
				"id": "valid_id",
				"title": "Title",
				"description": "Description"
			});
	});

	opaTest("Should have a generated id if left empty on export", function(Given, When, Then) {

		When.onThePresetsPage.iOpenPresetsPopover();

		When.onThePresetsPage.iPressExport();

		When.onThePresetsPage.iEnterExportData("presetId", "");

		When.onThePresetsPage.iPressExportFinalize();

		Then.onThePresetsPage.iShouldReceiveOneExportFile()
			.and.iShouldReceiveCorrectExportFile({
				"id": sinon.match.truthy
			});
	});

	opaTest("Should be able to export example preset", function(Given, When, Then) {
		When.onThePresetsPage.iOpenImportDialog();
		When.onThePresetsPage.iUploadExamplePreset(presetUtil.titles.EXAMPLE_PRESET_1);
		When.onThePresetsPage.iPressImportFinalize();

		When.onThePresetsPage.iOpenPresetsPopover();
		When.onThePresetsPage.iPressPresetInPopover(testPresetExample.title);

		When.onThePresetsPage.iOpenPresetsPopover();

		When.onThePresetsPage.iPressExport();

		Then.onThePresetsPage.iShouldSeeExportDialog()
			.and.iShouldSeeExportData("title", testPresetExample.title)
			.and.iShouldSeeExportData("description", testPresetExample.description)
			.and.iShouldSeeExportData("presetId", testPresetExample.id);

		When.onThePresetsPage.iPressExportFinalize();

		Then.onThePresetsPage.iShouldReceiveOneExportFile();

		Then.onThePresetsPage.and.iShouldReceiveCorrectExportFile({
			"id": testPresetExample.id,
			"title": testPresetExample.title,
			"description": testPresetExample.description,
			"selections": testPresetExample.selections
		});

		Then.iTeardownSupportAssistantFrame();

	});

});

redpajama_set_name: RedPajamaGithub


text:
package org.orekit.data;

import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.hipparchus.exception.DummyLocalizable;
import org.orekit.errors.OrekitException;

/** Provider for data files defined in a list.
 *

 * All {@link FiltersManager#addFilter(DataFilter) registered}
 * {@link DataFilter filters} are applied.
 *

 *

 * Zip archives entries are supported recursively.
 *

 * @since 10.1
 * @see DataProvidersManager
 * @see NetworkCrawler
 * @see FilesListCrawler
 * @author Luc Maisonobe
 * @param <T> The type of resource, e.g. File or URL.
 */
public abstract class AbstractListCrawler<T> implements DataProvider {

    /** Inputs list. */
    private final List<T> inputs;

    /** Build a data classpath crawler.
     * @param inputs list of inputs (may be empty if {@link #addInput(Object) addInput} is called later)
     */
    @SafeVarargs
    protected AbstractListCrawler(final T... inputs) {
        this.inputs = Arrays.stream(inputs).collect(Collectors.toList());
    }

    /** Add an input to the supported list.
     * @param input input to add
     */
    public void addInput(final T input) {
        inputs.add(input);
    }

    /** Get the list of inputs supported by the instance.
     * @return unmodifiable view of the list of inputs supported by the instance
     */
    public List<T> getInputs() {
        return Collections.unmodifiableList(inputs);
    }

    /** Get the complete name of a input.
     * @param input input to consider
     * @return complete name of the input
     */
    protected abstract String getCompleteName(T input);

    /** Get the base name of an input.
     * @param input input to consider
     * @return base name of the input
     */
    protected abstract String getBaseName(T input);

    /** Get a zip/jar crawler for an input.
     * @param input input to consider
     * @return zip/jar crawler for an input
     */
    protected abstract ZipJarCrawler getZipJarCrawler(T input);

    /** Get the stream to read from an input.
     * @param input input to read from
     * @return stream to read the content of the input
     * @throws IOException if the input cannot be opened for reading
     */
    protected abstract InputStream getStream(T input) throws IOException;

    /** {@inheritDoc} */
    @Override
    public boolean feed(final Pattern supported,
                        final DataLoader visitor,
                        final DataProvidersManager manager) {

        try {
            OrekitException delayedException = null;
            boolean loaded = false;
            for (T input : inputs) {
                try {

                    if (visitor.stillAcceptsData()) {
                        final String name     = getCompleteName(input);
                        final String fileName = getBaseName(input);
                        if (ZIP_ARCHIVE_PATTERN.matcher(fileName).matches()) {

                            // browse inside the zip/jar file
                            getZipJarCrawler(input).feed(supported, visitor, manager);
                            loaded = true;

                        } else {

                            // apply all registered filters
                            DataSource data = new DataSource(fileName, () -> getStream(input));
                            data = manager.getFiltersManager().applyRelevantFilters(data);

                            if (supported.matcher(data.getName()).matches()) {
                                // visit the current file
                                try (InputStream is = data.getOpener().openStreamOnce()) {
                                    visitor.loadData(is, name);
                                    loaded = true;
                                }
                            }

                        }
                    }

                } catch (OrekitException oe) {
                    // maybe the next path component will be able to provide data
                    // wait until all components have been tried
                    delayedException = oe;
                }
            }

            if (!loaded && delayedException != null) {
                throw delayedException;
            }

            return loaded;

        } catch (IOException | ParseException e) {
            throw new OrekitException(e, new DummyLocalizable(e.getMessage()));
        }

    }

}


text:
package ztls

import (
	"crypto/rsa"
	"encoding/binary"
	"encoding/json"
	"math/big"

	"github.com/dadrian/downgrade-check/ztools/x509"
)

type TLSVersion uint16

type ServerHello struct {
	Version             TLSVersion  `json:"version"`
	Random              []byte      `json:"random"`
	SessionID           []byte      `json:"session_id"`
	CipherSuite         CipherSuite `json:"cipher_suite"`
	CompressionMethod   uint8       `json:"compression_method"`
	OcspStapling        bool        `json:"ocsp_stapling"`
	TicketSupported     bool        `json:"ticket"`
	SecureRenegotiation bool        `json:"secure_renegotiation"`
	HeartbeatSupported  bool        `json:"heartbeat"`
}

// ServerCertificates represents a TLS certificates message in a format friendly to the golang JSON library.
// ValidationError should be non-nil whenever Valid is false.
type Certificates struct {
	Certificates       [][]byte
	ParsedCertificates []*x509.Certificate
}

// ServerKeyExchange represents the raw key data sent by the server in TLS key exchange message
type ServerKeyExchange struct {
	Key []byte `json:"key"`
}

// Finished represents a TLS Finished message
type Finished struct {
	VerifyData []byte `json:"verify_data"`
}

// ServerHandshake stores all of the messages sent by the server during a standard TLS Handshake.
// It implements zgrab.EventData interface
type ServerHandshake struct {
	ServerHello        *ServerHello       `json:"server_hello"`
	ServerCertificates *Certificates      `json:"server_certificates"`
	ServerKeyExchange  *ServerKeyExchange `json:"server_key_exchange"`
	RSAExportParams    *RSAExportParams   `json:"rsa_export_params,omitempty"`
	DHExportParams     *DHExportParams    `json:"dh_export_params,omitempty"`
	ServerFinished     *Finished          `json:"server_finished"`
}

func (c *Conn) GetHandshakeLog() *ServerHandshake {
	return c.handshakeLog
}

func (m *serverHelloMsg) MakeLog() *ServerHello {
	sh := new(ServerHello)
	sh.Version = TLSVersion(m.vers)
	sh.Random = make([]byte, len(m.random))
	copy(sh.Random, m.random)
	sh.SessionID = make([]byte, len(m.sessionId))
	copy(sh.SessionID, m.sessionId)
	sh.CipherSuite = CipherSuite(m.cipherSuite)
	sh.CompressionMethod = m.compressionMethod
	sh.OcspStapling = m.ocspStapling
	sh.TicketSupported = m.ticketSupported
	sh.SecureRenegotiation = m.secureRenegotiation
	sh.HeartbeatSupported = m.heartbeatEnabled
	return sh
}

func (m *certificateMsg) MakeLog() *Certificates {
	sc := new(Certificates)
	sc.Certificates = make([][]byte, len(m.certificates))
	for idx, cert := range m.certificates {
		sc.Certificates[idx] = make([]byte, len(cert))
		copy(sc.Certificates[idx], cert)
	}
	return sc
}

func (m *serverKeyExchangeMsg) MakeLog() *ServerKeyExchange {
	skx := new(ServerKeyExchange)
	skx.Key = make([]byte, len(m.key))
	copy(skx.Key, m.key)
	return skx
}

func (m *finishedMsg) MakeLog() *Finished {
	sf := new(Finished)
	sf.VerifyData = make([]byte, len(m.verifyData))
	copy(sf.VerifyData, m.verifyData)
	return sf
}

type ExportSignatureAlgorithm uint16

var exportHashes = []string{
	"MD5",
	"SHA-1",
	"SHA-224",
	"SHA-256",
	"SHA-384",
	"SHA-512",
}

var exportAlgorithms = []string{
	"anon",
	"RSA",
	"DSA",
	"ECDSA",
}

func (esa *ExportSignatureAlgorithm) MarshalJSON() ([]byte, error) {
	value := uint16(*esa)
	hash := int(byte(value >> 8))
	alg := int(byte(value))

	var aux struct {
		Value    uint16 `json:"value"`
		HashName string `json:"hash_name,omitempty"`
		HashID   int    `json:"hash_id"`
		AlgName  string `json:"algorithm_name,omitempty"`
		AlgID    int    `json:"algorithm_id"`
	}
	if hash < len(exportHashes) {
		aux.HashName = exportHashes[hash]
	}
	if alg < len(exportAlgorithms) {
		aux.AlgName = exportAlgorithms[alg]
	}
	aux.Value = value
	aux.HashID = hash
	aux.AlgID = alg
	return json.Marshal(&aux)
}

type RSAExportParams struct {
	PublicKey rsa.PublicKey `json:"-"`
	Modulus   []byte        `json:"modulus"`
	Exponent  uint32        `json:"exponent"`
}

type DHExportParams struct {
	P  []byte `json:"p"`
	G  []byte `json:"g"`
	Ys []byte `json:"ys"`
}

func (p *rsaExportParams) MakeLog() *RSAExportParams {
	out := new(RSAExportParams)
	exponent := uint32(0)
	for _, b := range p.rawExponent {
		exponent <<= 8
		exponent |= uint32(b)
	}
	modulus := big.NewInt(0)
	modulus.SetBytes(p.rawModulus)
	key := rsa.PublicKey{
		N: modulus,
		E: int(exponent),
	}
	out.PublicKey = key
	out.Modulus = modulus.Bytes()
	out.Exponent = exponent
	return out
}

func (p *DHExportParams) unmarshal(buf []byte) bool {
	if len(buf) < 2 {
		return false
	}
	pLength := binary.BigEndian.Uint16(buf)
	buf = buf[2:]

	if len(buf) < int(pLength) {
		return false
	}
	p.P = buf[0:pLength]
	buf = buf[pLength:]

	if len(buf) < 2 {
		return false
	}
	gLength := binary.BigEndian.Uint16(buf)
	buf = buf[2:]

	if len(buf) < int(gLength) {
		return false
	}
	p.G = buf[0:gLength]
	buf = buf[gLength:]

	if len(buf) < 2 {
		return false
	}
	ysLength := binary.BigEndian.Uint16(buf)
	buf = buf[2:]

	if len(buf) < int(ysLength) {
		return false
	}
	p.Ys = buf[0:ysLength]

	return true
}


text:
package security

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func Test_EnsureRoles(t *testing.T) {
	roles := EnsureRoles([]string{"admin"}, "admin", "editor", "reviewer")

	assert.Equal(t, roles, []string{"admin", "editor", "reviewer"})
}

func Test_EnsureRoles_Empty(t *testing.T) {
	roles := EnsureRoles([]string{})

	assert.Equal(t, roles, []string{})
}


text:
package com.ait.toolkit.sencha.ext.ux.calendar.client.events;

import com.ait.toolkit.sencha.ext.ux.calendar.client.CalendarPanel;
import com.ait.toolkit.sencha.shared.client.core.EventObject;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.event.dom.client.DomEvent.Type;

public class InitDragEvent extends EventObject {

    public static String EVENT_NAME = "inidrag";

    private CalendarPanel source;

    /**
     * UiBinder implementations
     */
    private static Type<InitDragHandler> TYPE = new Type<InitDragHandler>( EVENT_NAME, null );

    public static Type<InitDragHandler> getType() {
        return TYPE;
    }

    public static Type<InitDragHandler> getAssociatedType() {
        return TYPE;
    }

    public InitDragEvent( JavaScriptObject jsObj ) {
        super( jsObj );
    }

    public InitDragEvent( CalendarPanel source, JavaScriptObject nativeEvent ) {
        super( nativeEvent );
        this.source = source;
    }

    /**
     * @return the source
     */
    public CalendarPanel getPanel() {
        return source;
    }

    public CalendarPanel getSource() {
        return source;
    }

}


text:
using System;

namespace TeaDriven.Graphology.Visualization
{
    public class DefaultGetNodeString : IGetNodeString
    {
        #region Dependencies

        private readonly IGetDepthString _getDepthString;
        private readonly IGetMemberTypesString _getMemberTypesString;

        #endregion Dependencies

        #region Constructors

        public DefaultGetNodeString(IGetDepthString getDepthString, IGetMemberTypesString getMemberTypesString)
        {
            if (getDepthString == null) throw new ArgumentNullException("getDepthString");
            if (getMemberTypesString == null) throw new ArgumentNullException("getMemberTypesString");

            this._getDepthString = getDepthString;
            this._getMemberTypesString = getMemberTypesString;
        }

        #endregion Constructors

        #region IGetNodeString Members

        public string For(GraphNode graphNode, int depth)
        {
            if (graphNode == null) throw new ArgumentNullException("graphNode");

            string depthString = this._getDepthString.For(depth);
            string memberTypesString = this._getMemberTypesString.For(graphNode);

            string nodeString = string.Format(this._format, depthString, memberTypesString);

            if (graphNode.IsRecursionStart)
            {
                nodeString += " (recursed)";
            }

            return nodeString;
        }

        #endregion IGetNodeString Members

        private string _format = "{0}{1}";

        public string Format
        {
            get { return this._format; }
            set { this._format = value; }
        }
    }
}


text:
// Qt includes
#include <QThread>

// CTK includes
#include "ctkITKErrorLogMessageHandler.h"
#include "ctkUtils.h"

#ifdef __GNUC__
// Disable warnings related to 'itkSmartPointer.h' file
// See http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html
// Note: Ideally the incriminated functions and macros should be fixed upstream ...
# pragma GCC diagnostic ignored "-Wold-style-cast"
#endif

// ITK includes
#include <itkObjectFactory.h>
#include <itkOutputWindow.h>

namespace itk
{

// --------------------------------------------------------------------------
// ctkITKOutputWindow

// --------------------------------------------------------------------------
class ctkITKOutputWindow : public OutputWindow
{
public:
  /** Standard class typedefs. */
  typedef ctkITKOutputWindow       Self;
  typedef OutputWindow             Superclass;
  typedef SmartPointer<Self>       Pointer;
  typedef SmartPointer<const Self> ConstPointer;

  /** Standard New method. */
  itkNewMacro(ctkITKOutputWindow);

  /** Run-time type information (and related methods). */
  itkTypeMacro(ctkITKOutputWindow, OutputWindow);

  ctkITKOutputWindow():MessageHandler(0){}
  ~ctkITKOutputWindow(){}

  virtual void DisplayText(const char*);
  virtual void DisplayErrorText(const char*);
  virtual void DisplayWarningText(const char*);
  virtual void DisplayGenericWarningText(const char*);

  virtual void DisplayDebugText(const char*);

  ctkErrorLogAbstractMessageHandler * MessageHandler;
};

// --------------------------------------------------------------------------
// ctkITKOutputWindow methods

//----------------------------------------------------------------------------
void ctkITKOutputWindow::DisplayText(const char* text)
{
  Q_ASSERT(this->MessageHandler);
  this->MessageHandler->handleMessage(
        ctk::qtHandleToString(QThread::currentThreadId()),
        ctkErrorLogLevel::Info,
        this->MessageHandler->handlerPrettyName(), text);
}

//----------------------------------------------------------------------------
void ctkITKOutputWindow::DisplayErrorText(const char* text)
{
  Q_ASSERT(this->MessageHandler);
  this->MessageHandler->handleMessage(
        ctk::qtHandleToString(QThread::currentThreadId()),
        ctkErrorLogLevel::Error,
        this->MessageHandler->handlerPrettyName(), text);
}

//----------------------------------------------------------------------------
void ctkITKOutputWindow::DisplayWarningText(const char* text)
{
  Q_ASSERT(this->MessageHandler);
  this->MessageHandler->handleMessage(
        ctk::qtHandleToString(QThread::currentThreadId()),
        ctkErrorLogLevel::Warning,
        this->MessageHandler->handlerPrettyName(), text);
}

//----------------------------------------------------------------------------
void ctkITKOutputWindow::DisplayGenericWarningText(const char* text)
{
  this->DisplayWarningText(text);
}

//----------------------------------------------------------------------------
void ctkITKOutputWindow::DisplayDebugText(const char* text)
{
  Q_ASSERT(this->MessageHandler);
  this->MessageHandler->handleMessage(
        ctk::qtHandleToString(QThread::currentThreadId()),
        ctkErrorLogLevel::Debug,
        this->MessageHandler->handlerPrettyName(), text);
}

} // End of itk namespace

// --------------------------------------------------------------------------
// ctkITKErrorLogMessageHandlerPrivate

// --------------------------------------------------------------------------
class ctkITKErrorLogMessageHandlerPrivate
{
  Q_DECLARE_PUBLIC(ctkITKErrorLogMessageHandler);
protected:
  ctkITKErrorLogMessageHandler* const q_ptr;
public:
  ctkITKErrorLogMessageHandlerPrivate(ctkITKErrorLogMessageHandler& object);
  ~ctkITKErrorLogMessageHandlerPrivate();

  itk::OutputWindow::Pointer SavedITKOutputWindow;
  itk::ctkITKOutputWindow::Pointer CTKITKOutputWindow;

};

// --------------------------------------------------------------------------
// ctkITKErrorLogMessageHandlerPrivate methods

// --------------------------------------------------------------------------
ctkITKErrorLogMessageHandlerPrivate::
ctkITKErrorLogMessageHandlerPrivate(ctkITKErrorLogMessageHandler& object) : q_ptr(&object)
{
  Q_Q(ctkITKErrorLogMessageHandler);
  this->SavedITKOutputWindow = 0;
  this->CTKITKOutputWindow = itk::ctkITKOutputWindow::New();
  this->CTKITKOutputWindow->MessageHandler = q;
}

// --------------------------------------------------------------------------
ctkITKErrorLogMessageHandlerPrivate::~ctkITKErrorLogMessageHandlerPrivate()
{
  this->SavedITKOutputWindow = 0;
  this->CTKITKOutputWindow = 0;
}

// --------------------------------------------------------------------------
// ctkITKErrorLogMessageHandler methods

// --------------------------------------------------------------------------
QString ctkITKErrorLogMessageHandler::HandlerName = QLatin1String("ITK");

//----------------------------------------------------------------------------
ctkITKErrorLogMessageHandler::ctkITKErrorLogMessageHandler() :
  Superclass(), d_ptr(new ctkITKErrorLogMessageHandlerPrivate(*this))
{
}

//----------------------------------------------------------------------------
ctkITKErrorLogMessageHandler::~ctkITKErrorLogMessageHandler()
{
}

//----------------------------------------------------------------------------
QString ctkITKErrorLogMessageHandler::handlerName()const
{
  return ctkITKErrorLogMessageHandler::HandlerName;
}

//----------------------------------------------------------------------------
void ctkITKErrorLogMessageHandler::setEnabledInternal(bool value)
{
  Q_D(ctkITKErrorLogMessageHandler);
  if (value)
    {
    d->SavedITKOutputWindow = itk::OutputWindow::GetInstance();
    itk::OutputWindow::SetInstance(d->CTKITKOutputWindow);
    }
  else
    {
    Q_ASSERT(d->SavedITKOutputWindow.IsNotNull());
    itk::OutputWindow::SetInstance(d->SavedITKOutputWindow);
    d->SavedITKOutputWindow = 0;
    }
}


text:
Creating and Managing Persistent Disks
######################################

As described in the previous section, you can specify the boot disk when launching a VM from
the Console and from the command-line.  There are times when you may want to create and attach
additional disks to an instance.  There are three main steps in this process:  you must first
**create** the disk, then you must **attach** it to the instance, and finally you must **format** it.
When you are finished, you may want to **detach** the disk and when you are done with it, you
will want to **delete** it.  We will describe each of these steps in a bit more detail below.
You may also want to see the Google documentation on
`Adding Persistent Disks <https://cloud.google.com/compute/docs/disks/persistent-disks>`_.

Create a Persistent Disk
========================
The **gcloud** command for creating a persistent disk is ``gcloud compute disks create``.
The most common options you'll probably use are ``--size``, ``--type``, and ``--zone``
(see `this <https://cloud.google.com/sdk/gcloud/reference/compute/disks/create>`_ page for
more details).  For example::

    gcloud compute disks create disk-1 --size 500GB

will create a 500 GB disk named "disk-1", using default settings (*eg* the type will be pd-standard).

Attach a Persistent Disk
========================
The **gcloud** command to attach a newly created disk to a previously created instance looks like this:

    gcloud compute instances attach-disk  --disk disk-1  --device-name  my-instance

Note that this command is part of the **gcloud compute instances** group rather than the
**gcloud compute disks** group.  Details about additional options can be found in the
`documentation <https://cloud.google.com/sdk/gcloud/reference/compute/instances/attach-disk>`_.
For example the default mode is **rw** (read-write), but you can also specify that a
disk be attached **ro** (read-only).

Format a Persistent Disk
========================
In order to format a disk that you've attached to an instance, you need to first log on to that instance::

    gcloud compute ssh  my-instance

For complete details, please refer to the Google documentation on
`formatting <https://cloud.google.com/compute/docs/disks/persistent-disks#formatting>`_
and mounting non-root persistent disks;
but there are two main steps:  first you must format the disk using the **mkfs** tool
(note that this will delete any *existing* data on the disk), and second you must use
the **mount** tool to mount the disk at a specified mount-point::

    sudo mkfs.ext4 -F /dev/disk/by-id/disk-1
    sudo mkdir /mnt/pd1
    sudo mount -o discard,defaults /dev/disk/by-id/disk-1 /mnt/pd1

Detach a Persistent Disk
========================
Detaching a disk is a two step process: first you unmount the disk (using the **umount** command,
*from* the instance to which it is attached), and then (after logging out from that instance)
you use the **gcloud** tool::

    $sudo umount /dev/disk/by-id/disk-1
    $exit

    gcloud compute instances detach-disk my-instance --disk disk-1

Delete a Persistent Disk
========================
Note that a boot disk will be deleted if you delete the instance that it is attached to (as long
as the auto-delete property for the disk was set to "yes" (the default) when it was created).  In all
other cases, you will need to
`delete <https://cloud.google.com/sdk/gcloud/reference/compute/disks/delete>`_
the disk manually using the ``gcloud compute disks delete``
command.  Note that disks can be deleted only if they are *not* being used by any VM instances.

You can also see and manage persistent disks from the Console on the Compute Engine > Disks page.


text:
package jsdl;

public class SDLEstimator extends SDLReference
{
	public  SDLEstimator(String name)
	{
		super("estimator", name);
	}

}


text:
create index IX_BE46908E on Workflow_Qux (uuid_[$COLUMN_LENGTH:75$], companyId);
create unique index IX_536F8417 on Workflow_Qux (uuid_[$COLUMN_LENGTH:75$], groupId);


text:
Battlestar Galactica

Parts

Click on the link to download the appropriate part.

								 PDF
								 JPEG

								Alto Sax 1
								Click Here
								Click Here

								Alto Sax 2
								Click Here
								Click Here

								Bari Sax
								Click Here
								Click Here

								Clarinet 1
								Click Here
								Click Here

								Clarinet 2
								Click Here
								Click Here

								Clarinet 3
								Click Here
								Click Here

								Flute
								Click Here
								Click Here

								Horn in F
								Click Here
								Click Here

								Percussion - Bass Drums
								Click Here
								Click Here

								Percussion - Bells
								Click Here
								Click Here

								Percussion - Cymbals
								Click Here
								Click Here

								Percussion - Snare Drum
								Click Here
								Click Here

								Tenor Sax 1
								Click Here
								Click Here

								Tenor Sax 2
								Click Here
								Click Here

								Trombone 1
								Click Here
								Click Here

								Trombone 2
								Click Here
								Click Here

								Trombone 3
								Click Here
								Click Here

								Trumpet 1
								Click Here
								Click Here

								Trumpet 2
								Click Here
								Click Here

								Trumpet 3
								Click Here
								Click Here

								Tuba
								Click Here
								Click Here

Roadmap

						<?php
							$root = realpath($_SERVER["DOCUMENT_ROOT"]);
							$roadmapFile = $root . "/music/Battlestar Galactica/roadmap.txt";
							$handler = fopen($roadmapFile, 'r');
							$roadmap = fread($handler, filesize($roadmapFile));
							echo $roadmap;
						?>

Recordings / Media

No media available.

Revisions

						<?php
							$root = realpath($_SERVER["DOCUMENT_ROOT"]);
							$revisionsFile = $root . "/music/Battlestar Galactica/revisions.txt";
							$handler = fopen($revisionsFile, 'r');
							$revisions = fread($handler, filesize($revisionsFile));
							echo $revisions;
						?>


text:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.10"/>
<title>RC CAR: CMFunctionalDescriptor Struct Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>

<link href="search/search.css" rel="stylesheet" type="text/css"/>

<link href="doxygen.css" rel="stylesheet" type="text/css" />

RC CAR

Main Page

Data Structures

Files

          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)"
               onblur="searchBox.OnSearchFieldFocus(false)"
               onkeyup="searchBox.OnSearchFieldChange(event)"/>

Data Structures

Data Structure Index

Class Hierarchy

Data Fields

Data Fields

CMFunctionalDescriptor Struct Reference

#include <USBCore.h>

Data Fields

u8 	len

u8 	dtype

u8 	subtype

u8 	bmCapabilities

u8 	bDataInterface

Detailed Description

Definition at line 217 of file USBCore.h.

Field Documentation

          u8 bDataInterface

Definition at line 223 of file USBCore.h.

          u8 bmCapabilities

Definition at line 222 of file USBCore.h.

          u8 dtype

Definition at line 220 of file USBCore.h.

          u8 len

Definition at line 219 of file USBCore.h.

          u8 subtype

Definition at line 221 of file USBCore.h.

The documentation for this struct was generated from the following file:

ArduinoUNO/src/arduino/cores/arduino/USBCore.h

<address class="footer">
Generated by

 1.8.10
</address>


text:
<?php

use Pagekit\Application as App;
use Pagekit\Application\Console\Application as Console;
use Pagekit\Module\Loader\AutoLoader;
use Pagekit\Module\Loader\ConfigLoader;

$loader = require $path.'/autoload.php';

$app = new App($config);
$app['autoloader'] = $loader;

$app['module']->register([
    'packages/*/*/index.php',
    'app/modules/*/index.php',
    'app/installer/index.php',
    'app/system/index.php',
    'app/console/index.php'
], $path);

$app['module']->addLoader(new AutoLoader($app['autoloader']));
$app['module']->addLoader(new ConfigLoader(require $path.'/app/system/config.php'));

if ($app['config.file']) {
    $app['module']->addLoader(new ConfigLoader(require $app['config.file']));
    $app['module']->load('system');
}
$app['module']->load('console');

$console = new Console($app, 'Rimbo',$app->version());
$console->run();


text:
class C {
    void foo(Object o) {
        String s = "";
        switch (o) {
            case null<caret>, Number n -> s = "x";
            default -> throw new IllegalStateException("Unexpected value: " + o);
        }
    }
}


text:
package ml.shifu.guagua.mapreduce;

import java.io.IOException;

import ml.shifu.guagua.mapreduce.GuaguaOutputCommitter;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class GuaguaOutputCommitterTest {

    private GuaguaOutputCommitter guaguaOutputCommitter;

    @Before
    public void setUp() {
        guaguaOutputCommitter = new GuaguaOutputCommitter();
    }

    @Test
    public void testCheckOutputSpecs() {
        try {
            guaguaOutputCommitter.abortTask(null);
            guaguaOutputCommitter.setupJob(null);
            guaguaOutputCommitter.setupTask(null);
            guaguaOutputCommitter.commitJob(null);
            guaguaOutputCommitter.commitTask(null);
            Assert.assertFalse(guaguaOutputCommitter.needsTaskCommit(null));
        } catch (IOException e) {
        }
    }

    @After
    public void tearDown() {
        guaguaOutputCommitter = null;
    }

}


text:
/*

Template:  AppTech
Author:bootexperts.com
Version: 1
Developed by: bootexperts.com

NOTE: This is Style customizer stylesheet of template.

*/

#main-menu.stick {
    background: #673AB7 none repeat scroll 0 0;
}
.bg-oapcity-40::before {
    background: #673AB7 none repeat scroll 0 0;
}
.single-item:hover i {
    background-color: #673AB7;
}
.about-icon li a i:hover {
    color: #673AB7;
}
.single-features-list:hover .feature-list-icon i,
.single-features-list2:hover .feature-list-icon2 i {
    background-color: #673AB7;
}
.video-popup:hover {
    border: 5px solid #673AB7;
}
.video-popup:hover i {
    color: #673AB7;
}
.sauget-accordion .panel-heading h4 a {
    background: #673AB7 none repeat scroll 0 0;
}
.slick-dots li.slick-active button {
    border: 3px solid #673AB7;
}
.slider-2 .slick-dots li.slick-active button {
    border: 3px solid #673AB7;
}
.single-price-package:hover .button,
.single-price-package:hover .price,
.single-price-package.active .button,
.single-price-package.active .price {
    background-color: #673AB7;
}
.counter:hover .icon-coun i {
    background-color: #673AB7;
}
.subscribe-form form button i {
    color: #673AB7;
}
input.submit:hover {
    background-color: #673AB7;
    border: 1px solid #673AB7;
}
.contact-from input:focus,
.contact-from textarea:focus {
    border-color: #673AB7;
}
.single-contact-info:hover .contact-icon {
    border: 1px solid #673AB7;
    background-color: #673AB7;
}
.footer-icon a:hover {
    border: 1px solid #673AB7;
    background-color: #673AB7;
}
.footer-text span a:hover {
    color: #673AB7;
}
#toTop i:hover {
    background-color: #673AB7;
}
.contact-text > span a:hover {
  color: #673AB7;
}