当前位置: 首页>>代码示例>>Java>>正文


Java LWJGLUtil.getPrivilegedInteger方法代码示例

本文整理汇总了Java中org.lwjgl.LWJGLUtil.getPrivilegedInteger方法的典型用法代码示例。如果您正苦于以下问题:Java LWJGLUtil.getPrivilegedInteger方法的具体用法?Java LWJGLUtil.getPrivilegedInteger怎么用?Java LWJGLUtil.getPrivilegedInteger使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.lwjgl.LWJGLUtil的用法示例。


在下文中一共展示了LWJGLUtil.getPrivilegedInteger方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCacheLineSize

import org.lwjgl.LWJGLUtil; //导入方法依赖的package包/类
static int getCacheLineSize() {
	final int THREADS = 2;
	final int REPEATS = 100000 * THREADS;
	final int LOCAL_REPEATS = REPEATS / THREADS;

	// Detection will start from CacheLineMaxSize bytes.
	final int MAX_SIZE = LWJGLUtil.getPrivilegedInteger("org.lwjgl.util.mapped.CacheLineMaxSize", 1024) / 4; // in # of integers
	// Detection will stop when the execution time increases by more than CacheLineTimeThreshold %.
	final double TIME_THRESHOLD = 1.0 + LWJGLUtil.getPrivilegedInteger("org.lwjgl.util.mapped.CacheLineTimeThreshold", 50) / 100.0;

	final ExecutorService executorService = Executors.newFixedThreadPool(THREADS);
	final ExecutorCompletionService<Long> completionService = new ExecutorCompletionService<Long>(executorService);

	try {
		// We need to use a NIO buffer in order to guarantee memory alignment.
		final IntBuffer memory = getMemory(MAX_SIZE);

		// -- WARMUP --

		final int WARMUP = 10;
		for ( int i = 0; i < WARMUP; i++ )
			doTest(THREADS, LOCAL_REPEATS, 0, memory, completionService);

		// -- CACHE LINE SIZE DETECTION --

		long totalTime = 0;
		int count = 0;
		int cacheLineSize = 64; // fallback to the most common size these days
		boolean found = false;
		for ( int i = MAX_SIZE; i >= 1; i >>= 1 ) {
			final long time = doTest(THREADS, LOCAL_REPEATS, i, memory, completionService);
			if ( totalTime > 0 ) { // Ignore first run
				final long avgTime = totalTime / count;
				if ( (double)time / (double)avgTime > TIME_THRESHOLD ) { // Try to detect a noticeable jump in execution time
					cacheLineSize = (i << 1) * 4;
					found = true;
					break;
				}
			}
			totalTime += time;
			count++;
		}

		if ( LWJGLUtil.DEBUG ) {
			if ( found )
				LWJGLUtil.log("Cache line size detected: " + cacheLineSize + " bytes");
			else
				LWJGLUtil.log("Failed to detect cache line size, assuming " + cacheLineSize + " bytes");
		}

		return cacheLineSize;
	} finally {
		executorService.shutdown();
	}
}
 
开发者ID:Superloup10,项目名称:Wolf_game,代码行数:56,代码来源:CacheLineSize.java


注:本文中的org.lwjgl.LWJGLUtil.getPrivilegedInteger方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。