use of org.apache.bcel.generic.INVOKESTATIC in project jop by jop-devel.
the class DFATool method buildPrologue.
private MethodInfo buildPrologue(MethodInfo mainMethod, List<InstructionHandle> statements, Flow flow, List<ClassInfo> clinits) {
// we use a prologue sequence for startup
InstructionList prologue = new InstructionList();
ConstantPoolGen prologueCP = mainMethod.getConstantPoolGen();
Instruction instr;
int idx;
// add magic initializers to prologue sequence
if (!analyzeBootMethod) {
instr = new ICONST(0);
prologue.append(instr);
instr = new ICONST(0);
prologue.append(instr);
idx = prologueCP.addMethodref("com.jopdesign.sys.GC", "init", "(II)V");
instr = new INVOKESTATIC(idx);
prologue.append(instr);
}
// add class initializers
for (ClassInfo clinit : clinits) {
MemberID cSig = appInfo.getClinitSignature(clinit.getClassName());
idx = prologueCP.addMethodref(cSig.getClassName(), cSig.getMemberName(), cSig.getDescriptor().toString());
instr = new INVOKESTATIC(idx);
prologue.append(instr);
}
if (analyzeBootMethod) {
// Let's just analyze the full boot method, so that the callgraph-builder is happy.
// Doing this after clinit, so that we have DFA infos on fields in JVMHelp.init()
idx = prologueCP.addMethodref("com.jopdesign.sys.Startup", "boot", "()V");
instr = new INVOKESTATIC(idx);
prologue.append(instr);
}
// add main method
instr = new ACONST_NULL();
prologue.append(instr);
idx = prologueCP.addMethodref(mainMethod.getClassName(), mainMethod.getShortName(), mainMethod.getDescriptor().toString());
instr = new INVOKESTATIC(idx);
prologue.append(instr);
// // invoke startMission() to ensure analysis of threads
// idx = prologueCP.addMethodref("joprt.RtThread", "startMission", "()V");
// instr = new INVOKESTATIC(idx);
// prologue.append(instr);
instr = new NOP();
prologue.append(instr);
prologue.setPositions(true);
// add prologue to program structure
for (Iterator l = prologue.iterator(); l.hasNext(); ) {
InstructionHandle handle = (InstructionHandle) l.next();
statements.add(handle);
if (handle.getInstruction() instanceof GOTO) {
GOTO g = (GOTO) handle.getInstruction();
flow.addEdge(new FlowEdge(handle, g.getTarget(), FlowEdge.NORMAL_EDGE));
} else if (handle.getNext() != null) {
flow.addEdge(new FlowEdge(handle, handle.getNext(), FlowEdge.NORMAL_EDGE));
}
}
MemberID pSig = new MemberID(prologueName, Descriptor.parse(prologueSig));
MethodInfo mi = mainMethod.getClassInfo().createMethod(pSig, null, prologue);
mi.setAccessType(AccessType.ACC_PRIVATE);
return mi;
}
use of org.apache.bcel.generic.INVOKESTATIC in project jop by jop-devel.
the class JOPModel method getNativeOpCode.
/* performance hot spot */
public int getNativeOpCode(MethodInfo context, Instruction instr) {
if (isSpecialInvoke(context, instr)) {
INVOKESTATIC isi = (INVOKESTATIC) instr;
String methodName = isi.getMethodName(context.getConstantPoolGen());
return JopInstr.getNative(methodName);
} else if (instr instanceof FieldInstruction) {
FieldInstruction finstr = (FieldInstruction) instr;
Type ftype = finstr.getFieldType(context.getConstantPoolGen());
boolean isRef = ftype instanceof ReferenceType;
boolean isLong = ftype == BasicType.LONG || ftype == BasicType.DOUBLE;
if (finstr instanceof GETSTATIC) {
if (isRef) {
return JopInstr.get("getstatic_ref");
} else if (isLong) {
return JopInstr.get("getstatic_long");
}
} else if (finstr instanceof PUTSTATIC) {
if (isRef) {
if (!com.jopdesign.build.JOPizer.USE_RTTM) {
/* FIXME: This should not be hardcoded? */
return JopInstr.get("putstatic_ref");
}
} else if (isLong) {
return JopInstr.get("putstatic_long");
}
} else if (finstr instanceof GETFIELD) {
if (isRef) {
return JopInstr.get("getfield_ref");
} else if (isLong) {
return JopInstr.get("getfield_long");
}
} else if (finstr instanceof PUTFIELD) {
if (isRef) {
if (!com.jopdesign.build.JOPizer.USE_RTTM) {
/* FIXME: This should not be hardcoded? */
return JopInstr.get("putfield_ref");
}
} else if (isLong) {
return JopInstr.get("putfield_long");
}
}
return instr.getOpcode();
} else {
return instr.getOpcode();
}
}
use of org.apache.bcel.generic.INVOKESTATIC in project jop by jop-devel.
the class JOPModel method isSpecialInvoke.
public boolean isSpecialInvoke(MethodInfo context, Instruction i) {
if (!(i instanceof INVOKESTATIC))
return false;
INVOKESTATIC isi = (INVOKESTATIC) i;
ReferenceType refTy = isi.getReferenceType(context.getConstantPoolGen());
if (refTy instanceof ObjectType) {
ObjectType objTy = (ObjectType) refTy;
String className = objTy.getClassName();
return (className.equals(JOP_NATIVE));
} else {
return false;
}
}
use of org.apache.bcel.generic.INVOKESTATIC in project servicemix-bundles by apache.
the class FunctionCall method translate.
/**
* Translate a function call. The compiled code will leave the function's
* return value on the JVM's stack.
*/
public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
final int n = argumentCount();
final ConstantPoolGen cpg = classGen.getConstantPool();
final InstructionList il = methodGen.getInstructionList();
final boolean isSecureProcessing = classGen.getParser().getXSLTC().isSecureProcessing();
int index;
// Translate calls to methods in the BasisLibrary
if (isStandard() || isExtension()) {
for (int i = 0; i < n; i++) {
final Expression exp = argument(i);
exp.translate(classGen, methodGen);
exp.startIterator(classGen, methodGen);
}
// append "F" to the function's name
final String name = _fname.toString().replace('-', '_') + "F";
String args = Constants.EMPTYSTRING;
// Special precautions for some method calls
if (name.equals("sumF")) {
args = DOM_INTF_SIG;
il.append(methodGen.loadDOM());
} else if (name.equals("normalize_spaceF")) {
if (_chosenMethodType.toSignature(args).equals("()Ljava/lang/String;")) {
args = "I" + DOM_INTF_SIG;
il.append(methodGen.loadContextNode());
il.append(methodGen.loadDOM());
}
}
// Invoke the method in the basis library
index = cpg.addMethodref(BASIS_LIBRARY_CLASS, name, _chosenMethodType.toSignature(args));
il.append(new INVOKESTATIC(index));
} else // run-time error message for unsupported external functions
if (unresolvedExternal) {
index = cpg.addMethodref(BASIS_LIBRARY_CLASS, "unresolved_externalF", "(Ljava/lang/String;)V");
il.append(new PUSH(cpg, _fname.toString()));
il.append(new INVOKESTATIC(index));
} else if (_isExtConstructor) {
if (isSecureProcessing)
translateUnallowedExtension(cpg, il);
final String clazz = _chosenConstructor.getDeclaringClass().getName();
Class[] paramTypes = _chosenConstructor.getParameterTypes();
LocalVariableGen[] paramTemp = new LocalVariableGen[n];
for (int i = 0; i < n; i++) {
final Expression exp = argument(i);
Type expType = exp.getType();
exp.translate(classGen, methodGen);
// Convert the argument to its Java type
exp.startIterator(classGen, methodGen);
expType.translateTo(classGen, methodGen, paramTypes[i]);
paramTemp[i] = methodGen.addLocalVariable("function_call_tmp" + i, expType.toJCType(), null, null);
paramTemp[i].setStart(il.append(expType.STORE(paramTemp[i].getIndex())));
}
il.append(new NEW(cpg.addClass(_className)));
il.append(InstructionConstants.DUP);
for (int i = 0; i < n; i++) {
final Expression arg = argument(i);
paramTemp[i].setEnd(il.append(arg.getType().LOAD(paramTemp[i].getIndex())));
}
final StringBuffer buffer = new StringBuffer();
buffer.append('(');
for (int i = 0; i < paramTypes.length; i++) {
buffer.append(getSignature(paramTypes[i]));
}
buffer.append(')');
buffer.append("V");
index = cpg.addMethodref(clazz, "<init>", buffer.toString());
il.append(new INVOKESPECIAL(index));
// Convert the return type back to our internal type
(Type.Object).translateFrom(classGen, methodGen, _chosenConstructor.getDeclaringClass());
} else // Invoke function calls that are handled in separate classes
{
if (isSecureProcessing)
translateUnallowedExtension(cpg, il);
final String clazz = _chosenMethod.getDeclaringClass().getName();
Class[] paramTypes = _chosenMethod.getParameterTypes();
// Push "this" if it is an instance method
if (_thisArgument != null) {
_thisArgument.translate(classGen, methodGen);
}
for (int i = 0; i < n; i++) {
final Expression exp = argument(i);
exp.translate(classGen, methodGen);
// Convert the argument to its Java type
exp.startIterator(classGen, methodGen);
exp.getType().translateTo(classGen, methodGen, paramTypes[i]);
}
final StringBuffer buffer = new StringBuffer();
buffer.append('(');
for (int i = 0; i < paramTypes.length; i++) {
buffer.append(getSignature(paramTypes[i]));
}
buffer.append(')');
buffer.append(getSignature(_chosenMethod.getReturnType()));
if (_thisArgument != null && _clazz.isInterface()) {
index = cpg.addInterfaceMethodref(clazz, _fname.getLocalPart(), buffer.toString());
il.append(new INVOKEINTERFACE(index, n + 1));
} else {
index = cpg.addMethodref(clazz, _fname.getLocalPart(), buffer.toString());
il.append(_thisArgument != null ? (InvokeInstruction) new INVOKEVIRTUAL(index) : (InvokeInstruction) new INVOKESTATIC(index));
}
// Convert the return type back to our internal type
_type.translateFrom(classGen, methodGen, _chosenMethod.getReturnType());
}
}
use of org.apache.bcel.generic.INVOKESTATIC in project servicemix-bundles by apache.
the class FunctionCall method translateUnallowedExtension.
/**
* Translate code to call the BasisLibrary.unallowed_extensionF(String)
* method.
*/
private void translateUnallowedExtension(ConstantPoolGen cpg, InstructionList il) {
int index = cpg.addMethodref(BASIS_LIBRARY_CLASS, "unallowed_extension_functionF", "(Ljava/lang/String;)V");
il.append(new PUSH(cpg, _fname.toString()));
il.append(new INVOKESTATIC(index));
}
Aggregations