All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.firefly.utils.concurrent.MemoryUtils Maven / Gradle / Ivy

There is a newer version: 5.0.2
Show newest version
package com.firefly.utils.concurrent;

import java.security.AccessController;
import java.security.PrivilegedAction;

/**
 * MemoryUtils provides an abstraction over memory properties and operations.
 */
public class MemoryUtils {
	private static final int cacheLineBytes;

	static {
		final int defaultValue = 64;
		int value = defaultValue;
		try {
			value = Integer.parseInt(AccessController.doPrivileged(new PrivilegedAction() {
				@Override
				public String run() {
					return System.getProperty("com.fireflysource.utils.cacheLineBytes", String.valueOf(defaultValue));
				}
			}));
		} catch (Exception ignored) {
		}
		cacheLineBytes = value;
	}

	private MemoryUtils() {
	}

	public static int getCacheLineBytes() {
		return cacheLineBytes;
	}

	public static int getIntegersPerCacheLine() {
		return getCacheLineBytes() >> 2;
	}

	public static int getLongsPerCacheLine() {
		return getCacheLineBytes() >> 3;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy