simpleinlineoracle.java

来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 71 行

JAVA
71
字号
/*
 * $Id: SimpleInlineOracle.java,v 1.1 2003/11/25 11:42:13 epr Exp $
 */
package org.jnode.vm.bytecode;

import org.jnode.vm.classmgr.VmByteCode;
import org.jnode.vm.classmgr.VmMethod;
import org.jnode.vm.classmgr.VmType;

/**
 * @author Ewout Prangsma (epr@users.sourceforge.net)
 */
public class SimpleInlineOracle implements InlineOracle {

	/** Maximum overhead in bytes of inlining a method (very rough estimation) */
	private static final int INLINE_OVERHEAD = 64;
	
	/** Maximum size of a method that should be inlined */
	private static final int INLINE_SIZE_MAX = 64;
	
	/**
	 * @param caller
	 * @param callee
	 * @param invokeType
	 * @see org.jnode.vm.bytecode.InlineOracle#shouldInline(org.jnode.vm.classmgr.VmByteCode, org.jnode.vm.classmgr.VmMethod, int)
	 * @return boolean
	 */
	public boolean shouldInline(VmByteCode caller, VmMethod callee, int invokeType) {
		final VmType callerClass = caller.getMethod().getDeclaringClass();
		final VmType calleeClass = callee.getDeclaringClass();
		// Method must be in the same class
		if (callerClass != calleeClass) {
			return false;
		}
		// Callee must have bytecode
		if (callee.getBytecode() == null) {
			return false;
		}
		// Method must be final, static or private
		boolean ok = false;
		if (callee.isStatic()) {
			ok |= !callee.isSynchronized();
		} else {
			ok |= callee.isFinal();
			ok |= callee.isPrivate();
			ok |= calleeClass.isFinal();
		}
		
		if (!ok) {
			return false;
		}
		
		// Inlined method must not be too big
		final int calleeSize = callee.getBytecodeSize();
		final int callerSize = caller.getLength();
		
		if (callerSize + calleeSize + INLINE_OVERHEAD >= 64*1024) {
			// Combination too long
			return false;
		}
		
		if (calleeSize >= INLINE_SIZE_MAX) {
			// Callee method is too long
			return false;
		}
		
		return true;
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?