/** * Add a call to the given constructor to the body. * * @param self the "this" to call the constructor on * @param ctor the constructor to call * @param ctorParams parameters to the ctor _without_ implicit this */ private void addCallCtor(SSAValue self, MethodReference ctor, List<SSAValue> ctorParams) { final int pc = this.body.getNextProgramCounter(); final SSAValue exception = pm.getException(); final CallSiteReference site = CallSiteReference.make(pc, ctor, IInvokeInstruction.Dispatch.SPECIAL); final List<SSAValue> params = new ArrayList<>(1 + ctorParams.size()); params.add(self); params.addAll(ctorParams); final SSAInstruction ctorCall = instructionFactory.InvokeInstruction(pc, params, exception, site); body.addStatement(ctorCall); }
/** * Add a call to the given constructor to the body. * * @param self the "this" to call the constructor on * @param ctor the constructor to call * @param ctorParams parameters to the ctor _without_ implicit this */ protected void addCallCtor(SSAValue self, MethodReference ctor, List<SSAValue> ctorParams) { final int pc = this.body.getNextProgramCounter(); final SSAValue exception = pm.getException(); final CallSiteReference site = CallSiteReference.make(pc, ctor, IInvokeInstruction.Dispatch.SPECIAL); final List<SSAValue> params = new ArrayList<>(1 + ctorParams.size()); params.add(self); params.addAll(ctorParams); final SSAInstruction ctorCall = instructionFactory.InvokeInstruction(pc, params, exception, site); body.addStatement(ctorCall); }
/** * Add a call to the given constructor to the body. * * @param self the "this" to call the constructor on * @param ctor the constructor to call * @param ctorParams parameters to the ctor _without_ implicit this */ protected void addCallCtor(SSAValue self, MethodReference ctor, List<SSAValue> ctorParams) { final int pc = this.body.getNextProgramCounter(); final SSAValue exception = pm.getException(); final CallSiteReference site = CallSiteReference.make(pc, ctor, IInvokeInstruction.Dispatch.SPECIAL); final List<SSAValue> params = new ArrayList<>(1 + ctorParams.size()); params.add(self); params.addAll(ctorParams); final SSAInstruction ctorCall = instructionFactory.InvokeInstruction(pc, params, exception, site); body.addStatement(ctorCall); }
/** * Add a call to the given constructor to the body. * * @param self the "this" to call the constructor on * @param ctor the constructor to call * @param ctorParams parameters to the ctor _without_ implicit this */ private void addCallCtor(SSAValue self, MethodReference ctor, List<SSAValue> ctorParams) { final int pc = this.body.getNextProgramCounter(); final SSAValue exception = pm.getException(); final CallSiteReference site = CallSiteReference.make(pc, ctor, IInvokeInstruction.Dispatch.SPECIAL); final List<SSAValue> params = new ArrayList<>(1 + ctorParams.size()); params.add(self); params.addAll(ctorParams); final SSAInstruction ctorCall = instructionFactory.InvokeInstruction(pc, params, exception, site); body.addStatement(ctorCall); }
/** * Add an instruction to invoke the default constructor on the object of value number alloc of type t. */ protected void addCtorInvokeInstruction(final TypeReference t, int alloc) { MethodReference init = MethodReference.findOrCreate(t, MethodReference.initAtom, MethodReference.defaultInitDesc); CallSiteReference site = CallSiteReference.make(getCallSiteForType(t), init, IInvokeInstruction.Dispatch.SPECIAL); int[] params = new int[1]; params[0] = alloc; int exc = getExceptionsForType(t); SSAInvokeInstruction s = insts.InvokeInstruction(allInstructions.size(), params, exc, site, null); calls.add(s); allInstructions.add(s); } }
/** * Add an instruction to invoke the default constructor on the object of value number alloc of type t. */ protected void addCtorInvokeInstruction(final TypeReference t, int alloc) { MethodReference init = MethodReference.findOrCreate(t, MethodReference.initAtom, MethodReference.defaultInitDesc); CallSiteReference site = CallSiteReference.make(getCallSiteForType(t), init, IInvokeInstruction.Dispatch.SPECIAL); int[] params = new int[1]; params[0] = alloc; int exc = getExceptionsForType(t); SSAInvokeInstruction s = insts.InvokeInstruction(allInstructions.size(), params, exc, site, null); calls.add(s); allInstructions.add(s); } }
/** * Set up a method summary which allocates and returns an instance of concrete type T. */ private void addStatementsForConcreteType(final TypeReference T) { int alloc = addStatementsForConcreteSimpleType(T); if (alloc == -1) { return; } if (T.isArrayType()) { MethodReference init = MethodReference.findOrCreate(T, MethodReference.initAtom, MethodReference.defaultInitDesc); CallSiteReference site = CallSiteReference.make(getCallSiteForType(T), init, IInvokeInstruction.Dispatch.SPECIAL); int[] params = new int[1]; params[0] = alloc; int exc = getExceptionsForType(T); SSAInvokeInstruction s = insts.InvokeInstruction(allInstructions.size(), params, exc, site, null); calls.add(s); allInstructions.add(s); } }
/** * Set up a method summary which allocates and returns an instance of concrete type T. */ private void addStatementsForConcreteType(final TypeReference T) { int alloc = addStatementsForConcreteSimpleType(T); if (alloc == -1) { return; } if (T.isArrayType()) { MethodReference init = MethodReference.findOrCreate(T, MethodReference.initAtom, MethodReference.defaultInitDesc); CallSiteReference site = CallSiteReference.make(getCallSiteForType(T), init, IInvokeInstruction.Dispatch.SPECIAL); int[] params = new int[1]; params[0] = alloc; int exc = getExceptionsForType(T); SSAInvokeInstruction s = insts.InvokeInstruction(allInstructions.size(), params, exc, site, null); calls.add(s); allInstructions.add(s); } }
/** * @return the invoke instructions added by this operation * @throws IllegalArgumentException if site is null */ public SSAAbstractInvokeInstruction addInvocation(int[] params, CallSiteReference site) { if (site == null) { throw new IllegalArgumentException("site is null"); } CallSiteReference newSite = CallSiteReference.make(statements.size(), site.getDeclaredTarget(), site.getInvocationCode()); SSAAbstractInvokeInstruction s = null; if (newSite.getDeclaredTarget().getReturnType().equals(TypeReference.Void)) { s = insts.InvokeInstruction(statements.size(), params, nextLocal++, newSite, null); } else { s = insts.InvokeInstruction(statements.size(), nextLocal++, params, nextLocal++, newSite, null); } statements.add(s); cache.invalidate(this, Everywhere.EVERYWHERE); return s; }
/** * @return the invoke instructions added by this operation * @throws IllegalArgumentException if site is null */ public SSAAbstractInvokeInstruction addInvocation(int[] params, CallSiteReference site) { if (site == null) { throw new IllegalArgumentException("site is null"); } CallSiteReference newSite = CallSiteReference.make(statements.size(), site.getDeclaredTarget(), site.getInvocationCode()); SSAAbstractInvokeInstruction s = null; if (newSite.getDeclaredTarget().getReturnType().equals(TypeReference.Void)) { s = insts.InvokeInstruction(statements.size(), params, nextLocal++, newSite, null); } else { s = insts.InvokeInstruction(statements.size(), nextLocal++, params, nextLocal++, newSite, null); } statements.add(s); cache.invalidate(this, Everywhere.EVERYWHERE); return s; }
@SuppressWarnings("deprecation") public AbstractRootMethod getLanguageRoot(Atom language){ if (!languageRoots.containsKey(language)) { AbstractRootMethod languageRoot = roots.get(language, this); CGNode languageRootNode = null; try { languageRootNode = findOrCreateNode(languageRoot, Everywhere.EVERYWHERE); } catch (CancelException e) { e.printStackTrace(); Assertions.UNREACHABLE(); } languageRootNodes.add(languageRootNode); CallSiteReference site = CallSiteReference.make(1, languageRoot.getReference(), IInvokeInstruction.Dispatch.STATIC); CGNode fakeRootNode = getFakeRootNode(); CrossLanguageFakeRoot fakeRootMethod = (CrossLanguageFakeRoot) fakeRootNode.getMethod(); site = fakeRootMethod.addInvocationInternal(new int[0], site).getCallSite(); fakeRootNode.addTarget(site, languageRootNode); languageRoots.put(language, languageRoot); } return (AbstractRootMethod) languageRoots.get(language); }
@Override public void visitInvoke(IInvokeInstruction instruction) { IClassLoader loader = getDeclaringClass().getClassLoader(); MethodReference m = MethodReference.findOrCreate(loader.getLanguage(), loader.getReference(), instruction.getClassType(), instruction.getMethodName(), instruction.getMethodSignature()); int programCounter = 0; programCounter = getProgramCounter(); CallSiteReference site = null; site = CallSiteReference.make(programCounter, m, instruction.getInvocationCode()); callSites.add(site); }
@Override public void visitInvoke(IInvokeInstruction instruction) { IClassLoader loader = getDeclaringClass().getClassLoader(); MethodReference m = MethodReference.findOrCreate(loader.getLanguage(), loader.getReference(), instruction.getClassType(), instruction.getMethodName(), instruction.getMethodSignature()); int programCounter = 0; programCounter = getProgramCounter(); CallSiteReference site = null; site = CallSiteReference.make(programCounter, m, instruction.getInvocationCode()); callSites.add(site); }
@Override @SuppressWarnings("deprecation") public CGNode findOrCreateNode(IMethod method, Context C) throws CancelException { assert C.equals(Everywhere.EVERYWHERE); assert !method.isAbstract(); CGNode n = getNode(method, C); if (n == null) { assert !isInitialized; n = makeNewNode(method, C); IMethod clinit = method.getDeclaringClass().getClassInitializer(); if (clinit != null && getNode(clinit, Everywhere.EVERYWHERE) == null) { CGNode cln = makeNewNode(clinit, Everywhere.EVERYWHERE); CGNode clinits = getFakeWorldClinitNode(); clinits.addTarget(CallSiteReference.make(clinitPC++, clinit.getReference(), IInvokeInstruction.Dispatch.STATIC), cln); } } return n; }
@Override @SuppressWarnings("deprecation") public CGNode findOrCreateNode(IMethod method, Context C) throws CancelException { assert C.equals(Everywhere.EVERYWHERE); assert !method.isAbstract(); CGNode n = getNode(method, C); if (n == null) { assert !isInitialized; n = makeNewNode(method, C); IMethod clinit = method.getDeclaringClass().getClassInitializer(); if (clinit != null && getNode(clinit, Everywhere.EVERYWHERE) == null) { CGNode cln = makeNewNode(clinit, Everywhere.EVERYWHERE); CGNode clinits = getFakeWorldClinitNode(); clinits.addTarget(CallSiteReference.make(clinitPC++, clinit.getReference(), IInvokeInstruction.Dispatch.STATIC), cln); } } return n; }
public SSAAbstractInvokeInstruction addInvocation(int[] params, CallSiteReference site) { if (site == null) { throw new IllegalArgumentException("site is null"); } CallSiteReference newSite = CallSiteReference.make(methodSummary.getNumberOfStatements(), site.getDeclaredTarget(), site.getInvocationCode()); SSAAbstractInvokeInstruction s = null; if (newSite.getDeclaredTarget().getReturnType().equals(TypeReference.Void)) { s = insts.InvokeInstruction(methodSummary.getNumberOfStatements(), params, nextLocal++, newSite, null); } else { s = insts.InvokeInstruction(methodSummary.getNumberOfStatements(), nextLocal++, params, nextLocal++, newSite, null); } methodSummary.addStatement(s); // cache.invalidate(this, Everywhere.EVERYWHERE); return s; }
@Override protected void doCall(WalkContext context, CAstNode call, int result, int exception, CAstNode name, int receiver, int[] arguments) { assert name.getKind() == CAstNode.CONSTANT; CallSiteReference dummySiteRef = (CallSiteReference) name.getValue(); int pc = context.cfg().getCurrentInstruction(); boolean isStatic = (receiver == -1); int[] realArgs = isStatic ? arguments : new int[arguments.length + 1]; if (!isStatic) { realArgs[0] = receiver; System.arraycopy(arguments, 0, realArgs, 1, arguments.length); } CallSiteReference realSiteRef = CallSiteReference.make(pc, dummySiteRef.getDeclaredTarget(), dummySiteRef.getInvocationCode()); if (realSiteRef.getDeclaredTarget().getReturnType().equals(TypeReference.Void)) context.cfg().addInstruction(new AstJavaInvokeInstruction(context.cfg().getCurrentInstruction(), realArgs, exception, realSiteRef)); else context.cfg().addInstruction(new AstJavaInvokeInstruction(context.cfg().getCurrentInstruction(), result, realArgs, exception, realSiteRef)); processExceptions(call, context); }
@Override protected void doCall(WalkContext context, CAstNode call, int result, int exception, CAstNode name, int receiver, int[] arguments) { assert name.getKind() == CAstNode.CONSTANT; CallSiteReference dummySiteRef = (CallSiteReference) name.getValue(); int pc = context.cfg().getCurrentInstruction(); boolean isStatic = (receiver == -1); int[] realArgs = isStatic ? arguments : new int[arguments.length + 1]; if (!isStatic) { realArgs[0] = receiver; System.arraycopy(arguments, 0, realArgs, 1, arguments.length); } CallSiteReference realSiteRef = CallSiteReference.make(pc, dummySiteRef.getDeclaredTarget(), dummySiteRef.getInvocationCode()); if (realSiteRef.getDeclaredTarget().getReturnType().equals(TypeReference.Void)) context.cfg().addInstruction(new AstJavaInvokeInstruction(context.cfg().getCurrentInstruction(), realArgs, exception, realSiteRef)); else context.cfg().addInstruction(new AstJavaInvokeInstruction(context.cfg().getCurrentInstruction(), result, realArgs, exception, realSiteRef)); processExceptions(call, context); }
@SuppressWarnings("deprecation") public void init() throws CancelException { fakeRoot = makeFakeRootNode(); Key k = new Key(fakeRoot.getMethod(), fakeRoot.getContext()); registerNode(k, fakeRoot); fakeWorldClinit = makeFakeWorldClinitNode(); if (fakeWorldClinit != null) { k = new Key(fakeWorldClinit.getMethod(), fakeWorldClinit.getContext()); registerNode(k, fakeWorldClinit); // add a call from fakeRoot to fakeWorldClinit CallSiteReference site = CallSiteReference.make(1, fakeWorldClinit.getMethod().getReference(), IInvokeInstruction.Dispatch.STATIC); // note that the result of addInvocation is a different site, with a different program counter! site = ((AbstractRootMethod) fakeRoot.getMethod()).addInvocation(null, site).getCallSite(); fakeRoot.addTarget(site, fakeWorldClinit); } }
@SuppressWarnings("deprecation") public void init() throws CancelException { fakeRoot = makeFakeRootNode(); Key k = new Key(fakeRoot.getMethod(), fakeRoot.getContext()); registerNode(k, fakeRoot); fakeWorldClinit = makeFakeWorldClinitNode(); if (fakeWorldClinit != null) { k = new Key(fakeWorldClinit.getMethod(), fakeWorldClinit.getContext()); registerNode(k, fakeWorldClinit); // add a call from fakeRoot to fakeWorldClinit CallSiteReference site = CallSiteReference.make(1, fakeWorldClinit.getMethod().getReference(), IInvokeInstruction.Dispatch.STATIC); // note that the result of addInvocation is a different site, with a different program counter! site = ((AbstractRootMethod) fakeRoot.getMethod()).addInvocation(null, site).getCallSite(); fakeRoot.addTarget(site, fakeWorldClinit); } }