Search in sources :

Example 1 with Variables

use of com.newrelic.agent.util.asm.Variables in project newrelic-java-agent by newrelic.

the class TraceMethodVisitor method startTracer.

/**
 * Tracer t = null;<br/>
 * t = AgentBridge.instrumentation.createTracer(...);
 */
protected void startTracer() {
    visitInsn(Opcodes.ACONST_NULL);
    storeLocal(tracerLocal, TraceMethodVisitor.TRACER_TYPE);
    visitLabel(startFinallyLabel);
    Label start = new Label();
    Label end = new Label();
    Label handler = new Label();
    visitTryCatchBlock(start, end, handler, TraceMethodVisitor.THROWABLE_TYPE.getInternalName());
    visitLabel(start);
    super.getStatic(BridgeUtils.AGENT_BRIDGE_TYPE, BridgeUtils.INSTRUMENTATION_FIELD_NAME, BridgeUtils.INSTRUMENTATION_TYPE);
    String metricName = traceDetails.getFullMetricName(className, method.getName());
    String tracerFactory = traceDetails.tracerFactoryName();
    BytecodeGenProxyBuilder<Instrumentation> builder = BytecodeGenProxyBuilder.newBuilder(Instrumentation.class, this, true);
    Variables loader = builder.getVariables();
    Instrumentation instrumentation = builder.build();
    if (tracerFactory == null) {
        int tracerFlags = getTracerFlags();
        if (noticeSql) {
            instrumentation.createSqlTracer(loader.loadThis(this.access), signatureId, metricName, tracerFlags);
        } else {
            instrumentation.createTracer(loader.loadThis(this.access), signatureId, metricName, tracerFlags);
        }
    } else {
        Object[] loadArgs = loader.load(Object[].class, new Runnable() {

            @Override
            public void run() {
                loadArgArray();
            }
        });
        instrumentation.createTracer(loader.loadThis(this.access), signatureId, traceDetails.dispatcher(), metricName, tracerFactory, loadArgs);
    }
    storeLocal(tracerLocal, TraceMethodVisitor.TRACER_TYPE);
    goTo(end);
    visitLabel(handler);
    // toss the exception on the stack
    pop();
    visitLabel(end);
}
Also used : Variables(com.newrelic.agent.util.asm.Variables) Label(org.objectweb.asm.Label) Instrumentation(com.newrelic.agent.bridge.Instrumentation)

Example 2 with Variables

use of com.newrelic.agent.util.asm.Variables in project newrelic-java-agent by newrelic.

the class FlyweightTraceMethodVisitor method onEveryExit.

/**
 * This code is injected at every exit instruction, whether a return or an ATHROW.
 *
 * @see Transaction#finishFlyweightTracer(TracedMethod, long, long, String, String, String, String, String[])
 */
private void onEveryExit() {
    Label skip = super.newLabel();
    super.loadLocal(parentTracerLocal);
    super.ifNull(skip);
    BridgeUtils.getCurrentTransactionOrNull(this);
    super.ifNull(skip);
    BridgeUtils.getCurrentTransaction(this);
    BytecodeGenProxyBuilder<Transaction> builder = BytecodeGenProxyBuilder.newBuilder(Transaction.class, this, true);
    Variables loader = builder.getVariables();
    String[] rollupMetricNames;
    if (rollupMetricNamesCacheId >= 0) {
        rollupMetricNames = loader.load(String[].class, new Runnable() {

            @Override
            public void run() {
                getStatic(BridgeUtils.AGENT_BRIDGE_TYPE, BridgeUtils.INSTRUMENTATION_FIELD_NAME, BridgeUtils.INSTRUMENTATION_TYPE);
                BytecodeGenProxyBuilder.newBuilder(Instrumentation.class, FlyweightTraceMethodVisitor.this, true).build().getCachedObject(rollupMetricNamesCacheId);
                checkCast(Type.getType(String[].class));
            }
        });
    } else {
        rollupMetricNames = null;
    }
    // -1 and -2 are identifiers that tell the ApiBuilder's proxy to (-1) load a local variable and (-2) call
    // System.nanoTime when those values are
    // encountered
    long startTime = loader.loadLocal(startTimeLocal, Type.LONG_TYPE, -1L);
    long loadEndTime = loader.load(-2l, new Runnable() {

        @Override
        public void run() {
            invokeStatic(Type.getType(System.class), new Method("nanoTime", Type.LONG_TYPE, new Type[0]));
        }
    });
    Transaction transactionApi = builder.build();
    transactionApi.finishFlyweightTracer(loader.loadLocal(parentTracerLocal, TracedMethod.class), startTime, loadEndTime, className, this.method.getName(), this.methodDesc, loader.loadLocal(metricNameLocal, String.class), rollupMetricNames);
    super.visitLabel(skip);
}
Also used : Variables(com.newrelic.agent.util.asm.Variables) Transaction(com.newrelic.agent.bridge.Transaction) Label(org.objectweb.asm.Label) TracedMethod(com.newrelic.agent.bridge.TracedMethod) Method(org.objectweb.asm.commons.Method) TracedMethod(com.newrelic.agent.bridge.TracedMethod)

Aggregations

Variables (com.newrelic.agent.util.asm.Variables)2 Label (org.objectweb.asm.Label)2 Instrumentation (com.newrelic.agent.bridge.Instrumentation)1 TracedMethod (com.newrelic.agent.bridge.TracedMethod)1 Transaction (com.newrelic.agent.bridge.Transaction)1 Method (org.objectweb.asm.commons.Method)1