/** * Inserts bytecode at the end of the body. * The bytecode is inserted just before every return insturction. * It is not executed when an exception is thrown. * * @param src the source code representing the inserted bytecode. * It must be a single statement or block. */ public void insertAfter(String src) throws CannotCompileException { insertAfter(src, false); }
/** * Inserts bytecode at the end of the body. * The bytecode is inserted just before every return insturction. * It is not executed when an exception is thrown. * * @param src the source code representing the inserted bytecode. * It must be a single statement or block. */ public void insertAfter(String src) throws CannotCompileException { insertAfter(src, false); }
/** * Utility method to inserts callback at the end of the body. * The callback is inserted just before every return instruction. * It is not executed when an exception is thrown. * * @param behavior The behaviour to insert callback in * @param callback The callback * * @see CtBehavior#insertAfter(String, boolean) */ public static void insertAfter(CtBehavior behavior,Callback callback) throws CannotCompileException { behavior.insertAfter(callback.toString(), false); }
/** * Utility method to inserts callback at the end of the body. * The callback is inserted just before every return instruction. * It is not executed when an exception is thrown. * * @param behavior The behaviour to insert callback in * @param callback The callback representing the inserted. * @param asFinally True if the inserted is executed * Not only when the control normally returns * but also when an exception is thrown. * If this parameter is true, the inserted code cannot * access local variables. * * @see CtBehavior#insertAfter(String, boolean) */ public static void insertAfter(CtBehavior behavior, Callback callback, boolean asFinally) throws CannotCompileException { behavior.insertAfter(callback.toString(), asFinally); }
/** * Utility method to inserts callback at the end of the body. * The callback is inserted just before every return instruction. * It is not executed when an exception is thrown. * * @param behavior The behaviour to insert callback in * @param callback The callback * * @see CtBehavior#insertAfter(String, boolean) */ public static void insertAfter(CtBehavior behavior,Callback callback) throws CannotCompileException { behavior.insertAfter(callback.toString(), false); }
/** * Utility method to inserts callback at the end of the body. * The callback is inserted just before every return instruction. * It is not executed when an exception is thrown. * * @param behavior The behaviour to insert callback in * @param callback The callback representing the inserted. * @param asFinally True if the inserted is executed * Not only when the control normally returns * but also when an exception is thrown. * If this parameter is true, the inserted code cannot * access local variables. * * @see CtBehavior#insertAfter(String, boolean) */ public static void insertAfter(CtBehavior behavior, Callback callback, boolean asFinally) throws CannotCompileException { behavior.insertAfter(callback.toString(), asFinally); }
insertBefore(fname + ".enter();", false); String src = fname + ".exit();"; insertAfter(src, true);
insertBefore(fname + ".enter();", false); String src = fname + ".exit();"; insertAfter(src, true);
/** * Inserts bytecode at the end of the body. * The bytecode is inserted just before every return insturction. * It is not executed when an exception is thrown. * * @param src the source code representing the inserted bytecode. * It must be a single statement or block. */ public void insertAfter(String src) throws CannotCompileException { insertAfter(src, false); }
/** * Inserts bytecode at the end of the body. * The bytecode is inserted just before every return insturction. * It is not executed when an exception is thrown. * * @param src the source code representing the inserted bytecode. * It must be a single statement or block. */ public void insertAfter(String src) throws CannotCompileException { insertAfter(src, false); }
/** * Inserts bytecode at the end of the body. * The bytecode is inserted just before every return insturction. * It is not executed when an exception is thrown. * * @param src the source code representing the inserted bytecode. * It must be a single statement or block. */ public void insertAfter(String src) throws CannotCompileException { insertAfter(src, false); }
/** * Inserts bytecode at the end of the body. * The bytecode is inserted just before every return insturction. * It is not executed when an exception is thrown. * * @param src the source code representing the inserted bytecode. * It must be a single statement or block. */ public void insertAfter(String src) throws CannotCompileException { insertAfter(src, false); }
/** * Inserts bytecode at the end of the body. * The bytecode is inserted just before every return insturction. * It is not executed when an exception is thrown. * * @param src the source code representing the inserted bytecode. * It must be a single statement or block. */ public void insertAfter(String src) throws CannotCompileException { insertAfter(src, false); }
private static void wrapMethodInvocation(CtBehavior ctMethodOrConstructor, boolean isStatic) throws CannotCompileException { ctMethodOrConstructor.insertAfter(RobolectricInternals.class.getName() + ".onMethodInvocationFinish(" + (isStatic ? ctMethodOrConstructor.getDeclaringClass().getName() + ".class" : "this") + ");", true); }
private void injectAllocationCallPoint(CtBehavior ctBehavior, short callPointId) throws CannotCompileException { LOGGER.info("Injecting call point to " + ctBehavior.getLongName() + " ..."); ctBehavior.insertBefore(InstrumentationBasedAllocationPathManager.class.getName() + ".pushThreadLocalAllocationCallPoint(" + "(short) " + callPointId + ");"); ctBehavior.insertAfter(InstrumentationBasedAllocationPathManager.class.getName() + ".popThreadLocalAllocationCallPoint(" + "(short) " + callPointId + ");", true); }
private void instrument(CtBehavior ctBehavior) throws CannotCompileException { final String longName = ctBehavior.getLongName(); final Integer id = ProfilerManager.register(longName); ctBehavior.insertBefore("ProfilerManager.methodEnter(" + id + ");"); final ProfilerDefinition.Sleeper sleeper = sleepers == null ? null : sleepers.get(longName); if (sleeper != null && (sleeper.min != null || sleeper.max != null)) { final int min = sleeper.min == null ? sleeper.max : sleeper.min; final int max = sleeper.max == null ? sleeper.min : sleeper.max; final String call = min == max ? "ProfilerManager.sleep(" + min + ");" : "ProfilerManager.randomSleep(" + min + "," + max + ");"; ctBehavior.insertAfter(call); } ctBehavior.insertAfter("ProfilerManager.methodExit(" + id + ");"); }
public static void insertAfter(CtBehavior ctBehavior, String statement) { try { ctBehavior.insertAfter(statement); } catch (CannotCompileException e) { throw new CheckedExceptionSuppressorException(e.getMessage(), e); } }
public void extend(String body, boolean asFinally) { try { _method.insertAfter(body, asFinally); } catch (Exception ex) { throw new ApplicationRuntimeException(ServiceMessages.unableToExtendMethod( _signature, _method.getDeclaringClass().getName(), ex), ex); } _descriptionBody.append("\n"); if (asFinally) _descriptionBody.append("finally\n"); _descriptionBody.append(body); }
protected void handle(CtBehavior behavior) { try { if (debug) System.err.println("instrumenting " + behavior.getClass().getName() + "." + behavior.getName()); if (behavior.isEmpty()) return; behavior.addLocalVariable("memoryBefore", CtClass.longType); behavior.insertBefore("memoryBefore = fiji.MemoryProfiler.get();"); behavior.insertAfter("fiji.MemoryProfiler.report(memoryBefore);"); } catch (CannotCompileException e) { if (!e.getMessage().equals("no method body")) e.printStackTrace(); } }
@Override void createBody(CtBehavior behavior) { try { behavior.insertAfter(getBody()); } catch (CannotCompileException e) { throw new org.jboss.reflect.spi.CannotCompileException(e.getMessage()); } }