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


Java VM.maxDirectMemory方法代码示例

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


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

示例1: reserveMemory

import sun.misc.VM; //导入方法依赖的package包/类
static void reserveMemory(long size, int cap) {
    synchronized (Bits.class) {
        if (!memoryLimitSet && VM.isBooted()) {
            maxMemory = VM.maxDirectMemory();
            memoryLimitSet = true;
        }
        // -XX:MaxDirectMemorySize limits the total capacity rather than the
        // actual memory usage, which will differ when buffers are page
        // aligned.
        if (cap <= maxMemory - totalCapacity) {
            reservedMemory += size;
            totalCapacity += cap;
            count++;
            return;
        }
    }

    System.gc();
    try {
        Thread.sleep(100);
    } catch (InterruptedException x) {
        // Restore interrupt status
        Thread.currentThread().interrupt();
    }
    synchronized (Bits.class) {
        if (totalCapacity + cap > maxMemory)
            throw new OutOfMemoryError("Direct buffer memory");
        reservedMemory += size;
        totalCapacity += cap;
        count++;
    }

}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:34,代码来源:Bits.java

示例2: reserveMemory

import sun.misc.VM; //导入方法依赖的package包/类
static void reserveMemory(long size) {

	synchronized (Bits.class) {
	    if (!memoryLimitSet && VM.isBooted()) {
		maxMemory = VM.maxDirectMemory();
		memoryLimitSet = true;
	    }
	    if (size <= maxMemory - reservedMemory) {
		reservedMemory += size;
		return;
	    }
	}

	System.gc();
	try {
	    Thread.sleep(100);
	} catch (InterruptedException x) {
	    // Restore interrupt status
	    Thread.currentThread().interrupt();
	}
	synchronized (Bits.class) {
	    if (reservedMemory + size > maxMemory)
		throw new OutOfMemoryError("Direct buffer memory");
	    reservedMemory += size;
	}

    }
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:28,代码来源:Bits.java

示例3: reserveMemory

import sun.misc.VM; //导入方法依赖的package包/类
static void reserveMemory(long size, int cap) {

        if (!memoryLimitSet && VM.isBooted()) {
            maxMemory = VM.maxDirectMemory();
            memoryLimitSet = true;
        }

        // optimist!
        if (tryReserveMemory(size, cap)) {
            return;
        }

        final JavaLangRefAccess jlra = SharedSecrets.getJavaLangRefAccess();

        // retry while helping enqueue pending Reference objects
        // which includes executing pending Cleaner(s) which includes
        // Cleaner(s) that free direct buffer memory
        while (jlra.tryHandlePendingReference()) {
            if (tryReserveMemory(size, cap)) {
                return;
            }
        }

        // trigger VM's Reference processing
        System.gc();

        // a retry loop with exponential back-off delays
        // (this gives VM some time to do it's job)
        boolean interrupted = false;
        try {
            long sleepTime = 1;
            int sleeps = 0;
            while (true) {
                if (tryReserveMemory(size, cap)) {
                    return;
                }
                if (sleeps >= MAX_SLEEPS) {
                    break;
                }
                if (!jlra.tryHandlePendingReference()) {
                    try {
                        Thread.sleep(sleepTime);
                        sleepTime <<= 1;
                        sleeps++;
                    } catch (InterruptedException e) {
                        interrupted = true;
                    }
                }
            }

            // no luck
            throw new OutOfMemoryError("Direct buffer memory");

        } finally {
            if (interrupted) {
                // don't swallow interrupts
                Thread.currentThread().interrupt();
            }
        }
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:61,代码来源:Bits.java


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