/** * Expects a real on the stack and pushes a truncated integer value * * @see org.apache.xalan.xsltc.compiler.util.Type#translateTo */ public void translateTo(ClassGenerator classGen, MethodGenerator methodGen, IntType type) { final ConstantPoolGen cpg = classGen.getConstantPool(); final InstructionList il = methodGen.getInstructionList(); il.append(new INVOKESTATIC(cpg.addMethodref(BASIS_LIBRARY_CLASS, "realToInt","(D)I"))); }
private boolean isSleep(INVOKESTATIC ins, ConstantPoolGen cpg) { String className = ins.getClassName(cpg); if (!"java.lang.Thread".equals(className)) { return false; } String methodName = ins.getMethodName(cpg); String signature = ins.getSignature(cpg); return "sleep".equals(methodName) && ("(J)V".equals(signature) || "(JI)V".equals(signature)); }
@Override public void visitINVOKESTATIC(INVOKESTATIC ins) { // Find calls to System.exit(), since this effectively terminates the // basic block. String className = ins.getClassName(constPoolGen); String methodName = ins.getName(constPoolGen); String methodSig = ins.getSignature(constPoolGen); if ("java.lang.System".equals(className) && "exit".equals(methodName) && "(I)V".equals(methodSig)) { isExit = true; } }
/** * Get the inner class access object for given invokestatic instruction. * Returns null if the called method is not an inner class access. * * @param inv * the invokestatic instruction * @param cpg * the ConstantPoolGen for the method * @return the InnerClassAccess, or null if the call is not an inner class * access */ public InnerClassAccess getInnerClassAccess(INVOKESTATIC inv, ConstantPoolGen cpg) throws ClassNotFoundException { String methodName = inv.getMethodName(cpg); if (methodName.startsWith("access$")) { String className = inv.getClassName(cpg); return getInnerClassAccess(className, methodName); } return null; }
/** Checks if the constraints of operands of the said instruction(s) are satisfied. */ public void visitINVOKESTATIC(INVOKESTATIC o){ // INVOKESTATIC is a LoadClass; the Class where the referenced method is declared in, // is therefore resolved/verified. // INVOKESTATIC is an InvokeInstruction, the argument and return types are resolved/verified, // too. So are the allowed method names. String classname = o.getClassName(cpg); JavaClass jc = Repository.lookupClass(classname); Method[] ms = jc.getMethods(); Method m = null; for (int i=0; i<ms.length; i++){ if ( (ms[i].getName().equals(o.getMethodName(cpg))) && (Type.getReturnType(ms[i].getSignature()).equals(o.getReturnType(cpg))) && (objarrayequals(Type.getArgumentTypes(ms[i].getSignature()), o.getArgumentTypes(cpg))) ){ m = ms[i]; break; } } if (m == null){ constraintViolated(o, "Referenced method '"+o.getMethodName(cpg)+"' with expected signature not found in class '"+jc.getClassName()+"'. The native verifier possibly allows the method to be declared in some superclass or implemented interface, which the Java Virtual Machine Specification, Second Edition does not."); } if (! (m.isStatic())){ // implies it's not abstract, verified in pass 2. constraintViolated(o, "Referenced method '"+o.getMethodName(cpg)+"' has ACC_STATIC unset."); } }
if ("java.security.KeyPairGenerator".equals(invoke.getClassName(cpg)) && "getInstance".equals(invoke.getMethodName(cpg))) { final List<Type> argumentTypes = Arrays.asList(invoke.getArgumentTypes(cpg)); String value = null; if (argumentTypes.size() == 1 || argumentTypes.contains(Type.getType(Provider.class))) {
@Override public void visitINVOKESTATIC(INVOKESTATIC obj) { if (returnsString(obj)) { consumeStack(obj); String className = obj.getClassName(getCPG()); if ("java.lang.String".equals(className)) { pushValue(dynamicStringTypeInstance); } else { pushReturnType(obj); } } else { super.visitINVOKESTATIC(obj); } }
String name = is.getMethodName(cpg); String signature = is.getSignature(cpg); if (name.startsWith("access$")) { XMethod invoked = XFactory.createXMethod(is, cpg);
} else if (ins instanceof InvokeInstruction) { if (ins instanceof INVOKESTATIC && ((INVOKESTATIC) ins).getMethodName(classContext.getConstantPoolGen()).startsWith("new")) { sawNEW = true;
/** Symbolically executes the corresponding Java Virtual Machine instruction. */ public void visitINVOKESTATIC(INVOKESTATIC o){ for (int i=0; i<o.getArgumentTypes(cpg).length; i++){ stack().pop(); } // We are sure the invoked method will xRETURN eventually // We simulate xRETURNs functionality here because we // don't really "jump into" and simulate the invoked // method. if (o.getReturnType(cpg) != Type.VOID){ Type t = o.getReturnType(cpg); if ( t.equals(Type.BOOLEAN) || t.equals(Type.CHAR) || t.equals(Type.BYTE) || t.equals(Type.SHORT) ) t = Type.INT; stack().push(t); } } /** Symbolically executes the corresponding Java Virtual Machine instruction. */
Type t = o.getType(cpg); if (t instanceof ObjectType){ String name = ((ObjectType)t).getClassName(); Type[] argtypes = o.getArgumentTypes(cpg); int nargs = argtypes.length;
INVOKESTATIC inv = (INVOKESTATIC) ins; InnerClassAccess access = icam.getInnerClassAccess(inv, cpg); if (access != null && access.getMethodSignature().equals(inv.getSignature(cpg))) { xfield = access.getField(); isWrite = !access.isLoad();
public static Type[] getCallArgTypes(Instruction ins, ConstantPoolGen cp) { if (ins instanceof INVOKESTATIC) { INVOKESTATIC invst = (INVOKESTATIC) ins; return invst.getArgumentTypes(cp); } else if (ins instanceof INVOKEVIRTUAL) { INVOKEVIRTUAL invst = (INVOKEVIRTUAL) ins; return invst.getArgumentTypes(cp); } else if (ins instanceof INVOKEINTERFACE) { INVOKEINTERFACE invst = (INVOKEINTERFACE) ins; return invst.getArgumentTypes(cp); } else if (ins instanceof INVOKESPECIAL) { INVOKESPECIAL invst = (INVOKESPECIAL) ins; return invst.getArgumentTypes(cp); } else { return null; } }
public static String getCallReturnType(Instruction ins, ConstantPoolGen cp) { if (ins instanceof INVOKESTATIC) { INVOKESTATIC invst = (INVOKESTATIC) ins; return invst.getReturnType(cp).toString(); } else if (ins instanceof INVOKEVIRTUAL) { INVOKEVIRTUAL invst = (INVOKEVIRTUAL) ins; return invst.getReturnType(cp).toString(); } else if (ins instanceof INVOKEINTERFACE) { INVOKEINTERFACE invst = (INVOKEINTERFACE) ins; return invst.getReturnType(cp).toString(); } else if (ins instanceof INVOKESPECIAL) { INVOKESPECIAL invst = (INVOKESPECIAL) ins; return invst.getReturnType(cp).toString(); } else { return null; } }
/** * Determine whether the given INVOKESTATIC instruction is an inner-class * field accessor method. * * @param inv * the INVOKESTATIC instruction * @param cpg * the ConstantPoolGen for the method * @return true if the instruction is an inner-class field accessor, false * if not */ public static boolean isInnerClassAccess(INVOKESTATIC inv, ConstantPoolGen cpg) { String methodName = inv.getName(cpg); return methodName.startsWith("access$"); }
if ("java.lang.Integer".equals(invoke.getClassName(cpg)) && "toHexString".equals(invoke.getMethodName(cpg))) { invokeToHexString = true;
public INVOKESTATIC nextInvokeStatic(String className) { for (; index < handles.length; index++) { if (index > -1) { if (handles[index].getInstruction() instanceof INVOKESTATIC) { INVOKESTATIC methodCall = (INVOKESTATIC) handles[index].getInstruction(); if (methodCall.getClassName(cpg).equals(className)) { return methodCall; } } } } return null; }
String name = is.getMethodName(cpg); String signature = is.getSignature(cpg); if (name.startsWith("access$")) { XMethod invoked = XFactory.createXMethod(is, cpg);
if (next != null && next.getInstruction() instanceof INVOKESTATIC) { INVOKESTATIC is = (INVOKESTATIC) next.getInstruction(); if ("assertFalse".equals(is.getMethodName(cpg))) { return;
/** Symbolically executes the corresponding Java Virtual Machine instruction. */ @Override public void visitINVOKESTATIC(final INVOKESTATIC o) { for (int i=0; i<o.getArgumentTypes(cpg).length; i++) { stack().pop(); } // We are sure the invoked method will xRETURN eventually // We simulate xRETURNs functionality here because we // don't really "jump into" and simulate the invoked // method. if (o.getReturnType(cpg) != Type.VOID) { Type t = o.getReturnType(cpg); if ( t.equals(Type.BOOLEAN) || t.equals(Type.CHAR) || t.equals(Type.BYTE) || t.equals(Type.SHORT) ) { t = Type.INT; } stack().push(t); } } /** Symbolically executes the corresponding Java Virtual Machine instruction. */