codehacker.java

来自「This is a resource based on j2me embedde」· Java 代码 · 共 498 行 · 第 1/2 页

JAVA
498
字号
		    //		    // no danger of lookup failure here,		    // so don't even examine the referenced object.		    //		    constObj = c[(int)code[loc+1]&0xff];		    if (constObj instanceof StringConstant) {			code[loc] = (byte)Const.opc_aldc_quick;		    } else if (!(constObj instanceof ClassConstant)) {			code[loc] = (byte)Const.opc_ldc_quick;		    }		    constObj.incLdcReference();		    break;		default:		    throw new DataFormatException( "unexpected opcode in ldc="+			((int)code[loc]&0xff)+" at loc="+loc+			" in "+m.qualifiedName() );		}	    }	}	list = m.getWideConstantRefInstructions();	if ( list != null ){	    MethodInfo[] tList = null;	    int tListIndex = 0;		// index into tList	    if (VMMethodInfo.SAVE_TARGET_METHODS) {		tList = new MethodInfo[list.length];	    }	    for ( int i = 0; i < list.length; i++ ){		int loc = list[i];		if ( loc < 0 ) continue;		constObj = c[getUnsignedShort(code, loc+1)];		if (!constObj.isResolved()) {		    //		    // don't try to quicken unresolved references.		    // this is not fatal!		    //		    if (verbose){			log.println(Localizer.getString(			    "codehacker.could_not_quicken",			     m.qualifiedName(), constObj));		    }		    continue;		}		switch( (int)code[loc]&0xff ){		case Const.opc_ldc_w:		    if (constObj instanceof StringConstant) {			code[loc] = (byte)Const.opc_aldc_w_quick;		    } else if (!(constObj instanceof ClassConstant)) {			code[loc] = (byte)Const.opc_ldc_w_quick;		    }		    constObj.incLdcReference();		    break;		case Const.opc_ldc2_w:		    code[loc] = (byte)Const.opc_ldc2_w_quick;		    break;		case Const.opc_getstatic:		    // All the accesses to static field are done using 		    // checkinit version of opcodes.		    quickenFieldAccess( m, me, code, loc, true, c,			Const.opc_getstatic_quick,			Const.opc_getstatic2_quick,			Const.opc_agetstatic_quick, 0,			Const.opc_getstatic_checkinit_quick,			Const.opc_getstatic2_checkinit_quick,			Const.opc_agetstatic_checkinit_quick);		    break;		case Const.opc_putstatic:		    // All the accesses to static field are done using 		    // checkinit version of opcodes.		    quickenFieldAccess( m, me, code, loc, true, c,			Const.opc_putstatic_quick,			Const.opc_putstatic2_quick,			Const.opc_aputstatic_quick, 0,			Const.opc_putstatic_checkinit_quick,			Const.opc_putstatic2_checkinit_quick,			Const.opc_aputstatic_checkinit_quick);		    break;		case Const.opc_getfield:		    if (quickenFieldAccess( m, me, code, loc, false, c,			Const.opc_getfield_quick,			Const.opc_getfield2_quick,			Const.opc_agetfield_quick,			Const.opc_getfield_quick_w, 0, 0, 0) ){			// doesn't reference constant pool any more			list[i] = -1;		    }		    break;		case Const.opc_putfield:		    if (quickenFieldAccess( m, me, code, loc, false, c,			Const.opc_putfield_quick,			Const.opc_putfield2_quick,			Const.opc_aputfield_quick,			Const.opc_putfield_quick_w, 0, 0, 0) ){			// doesn't reference constant pool any more			list[i] = -1;		    }		    break;		case Const.opc_invokevirtual:		    mc = (MethodConstant)constObj;		    mi = mc.find(); // must succeed, if isResolved succeeded!		    int x = -1;		    if (mi.parent.isFinal() || mi.isFinalMember()) {			code[loc] = (byte)Const.opc_invokenonvirtual_quick;		    } else if (!jitOn && (x=mi.methodTableIndex )<= 255 && 				! useLosslessOpcodes ){			// Do really quick quickening, but only if the JIT			// is not on			if ( mi.parent == java_lang_Object ){			    newopcode = (byte)Const.opc_invokevirtualobject_quick;			} else {			    String sig = mc.sig.type.string;			    new SignatureIterator(sig) {				public void do_array(int d, int st, int end) {				    newopcode =				        (byte)Const.opc_ainvokevirtual_quick;				}				public void do_object(int st, int end) {				    newopcode =				        (byte)Const.opc_ainvokevirtual_quick;				}				public void do_scalar(char c) {				    switch(c) {					case Const.SIGC_LONG:					case Const.SIGC_DOUBLE:					    newopcode = (byte)						Const.opc_dinvokevirtual_quick;					    break;					case Const.SIGC_VOID:					    newopcode = (byte)						Const.opc_vinvokevirtual_quick;					    break;					default:					    newopcode = (byte)						Const.opc_invokevirtual_quick;					    break;				    }				}			    }.iterate_returntype();			}			code[loc] = newopcode;			code[loc+1] = (byte) x;			code[loc+2] = (byte)mi.argsSize;			list[i] = -1; // doesn't reference constant pool any more			if (VMMethodInfo.SAVE_TARGET_METHODS) {			    // Save the target method info for inlining			    tList[tListIndex++] = mi;			}		    } else {			//			// big index OR useLosslessOpcodes OR jit			//			code[loc] = (byte)Const.opc_invokevirtual_quick_w;		    }		    break;		case Const.opc_invokeinterface:		    code[loc] = (byte)Const.opc_invokeinterface_quick;		    break;		case Const.opc_invokestatic:		    mc = (MethodConstant)constObj;		    mi = mc.find(); // must succeed, if isResolved succeeded!		    if (mi.parent.vmClass.hasStaticInitializer) {			CodeHacker.checkinitQuickenings++;			m.hasCheckinits = true;		    }		    CodeHacker.quickenings++;		    code[loc] = (byte)((mi.parent.vmClass.hasStaticInitializer)				? Const.opc_invokestatic_checkinit_quick				: Const.opc_invokestatic_quick);		    break;		case Const.opc_new:		    /*		     * If the class to be instantiated has a static		     * initializer, we must quicken opc_new into		     * opc_new_checkinit_quick rather than		     * opc_new_quick.		     */		    classConst = (ClassConstant)constObj;                    // must succeed, if isResolved succeeded!		    classInfo = classConst.find();		    if (classInfo.vmClass.hasStaticInitializer) {			CodeHacker.checkinitQuickenings++;			m.hasCheckinits = true;		    }		    CodeHacker.quickenings++;		    code[loc] = (byte)((classInfo.vmClass.hasStaticInitializer)				       ? Const.opc_new_checkinit_quick				       : Const.opc_new_quick);		    break;		case Const.opc_anewarray:		    code[loc] = (byte)Const.opc_anewarray_quick;		    break;		case Const.opc_checkcast:		    code[loc] = (byte)Const.opc_checkcast_quick;		    break;		case Const.opc_instanceof:		    code[loc] = (byte)Const.opc_instanceof_quick;		    break;		case Const.opc_multianewarray:		    code[loc] = (byte)Const.opc_multianewarray_quick;		    break;		case Const.opc_invokespecial:		    mc = (MethodConstant)constObj;		    mi = mc.find(); // must succeed.		    byte newop;		    if ( false ){			newop = (byte)Const.opc_invokesuper_quick;		    } else {			newop = (byte)Const.opc_invokenonvirtual_quick;		    }		    code[loc] = newop;		    break;		default: 		    throw new DataFormatException( "unexpected opcode in wideConstantRef="+			((int)code[loc]&0xff)+" at loc="+loc+			" in "+m.qualifiedName() );		}	    }	    // Alloc and copy to new targetMethods array	    if (VMMethodInfo.SAVE_TARGET_METHODS) {		m.targetMethods = new MethodInfo[tListIndex];		System.arraycopy(tList, 0, m.targetMethods, 0, tListIndex);	    }	}	return success;    }    public boolean    quickenAllMethodsInClass(ClassInfo c) {	ConstantObject constants[] = c.getConstantPool().getConstants();	MethodInfo     methods[]= c.methods;	int numberOfMethods = methods.length;	int i = 0;	boolean result = true;	try {	    for (i = 0; i < numberOfMethods; i++) {		if (!quickenMethod(methods[i], constants)) {		    result = false;                }	    }	} catch (DataFormatException e) {	    System.err.println("Quickening "+methods[i].qualifiedName()+                               " got exception:");	    e.printStackTrace();	    return false;	}	return result;    }}

⌨️ 快捷键说明

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