1
1
package datadog .trace .instrumentation .jetty9 ;
2
2
3
3
import static net .bytebuddy .jar .asm .Opcodes .ALOAD ;
4
- import static net .bytebuddy .jar .asm .Opcodes .ASTORE ;
5
4
import static net .bytebuddy .jar .asm .Opcodes .F_SAME ;
6
5
import static net .bytebuddy .jar .asm .Opcodes .GOTO ;
7
6
import static net .bytebuddy .jar .asm .Opcodes .H_INVOKESTATIC ;
10
9
import static net .bytebuddy .jar .asm .Opcodes .INVOKEVIRTUAL ;
11
10
12
11
import datadog .context .Context ;
13
- import datadog .trace .api .gateway .Flow ;
14
- import datadog .trace .bootstrap .instrumentation .api .AgentSpan ;
15
12
import datadog .trace .bootstrap .instrumentation .api .Java8BytecodeBridge ;
16
13
import datadog .trace .instrumentation .jetty .JettyBlockingHelper ;
17
14
import java .io .BufferedWriter ;
@@ -107,9 +104,9 @@ public class HandleVisitor extends MethodVisitor {
107
104
private static final int CONTEXT_VAR = 1000 ;
108
105
109
106
/** Whether the next store is supposed to store the Context variable. */
110
- private boolean lookForStore ;
107
+ // private boolean lookForStore;
111
108
/** Whether the Context variable was stored to local index {@link #CONTEXT_VAR}. */
112
- private boolean contextStored ;
109
+ // private boolean contextStored;
113
110
// private int contextVarIndex = -1;
114
111
/** Whether the handle() method injection was successful .*/
115
112
private boolean success ;
@@ -155,19 +152,20 @@ DelayCertainInsMethodVisitor delayVisitorDelegate() {
155
152
public void visitMethodInsn (
156
153
int opcode , String owner , String name , String descriptor , boolean isInterface ) {
157
154
debug ("visitMethodInsn" );
158
- debug (">> contextStored: " + contextStored );
155
+ // debug(">> contextStored: " + contextStored);
159
156
debug (">> success: " + success );
160
157
debug (">> opcode: " + opcode + ", owner: " + owner + ", name: " + name + ", descriptor: " + descriptor );
161
- if (!contextStored ) {
162
- lookForStore =
163
- !lookForStore
164
- && opcode == INVOKEVIRTUAL
165
- && name .equals ("startSpan" )
166
- && descriptor .endsWith ("Ldatadog/context/Context;" );
167
- if (lookForStore ) {
168
- debug ("Found store" );
169
- }
170
- } else if (!success
158
+ // if (!contextStored) {
159
+ // lookForStore =
160
+ // !lookForStore
161
+ // && opcode == INVOKEVIRTUAL
162
+ // && name.equals("startSpan")
163
+ // && descriptor.endsWith("Ldatadog/context/Context;");
164
+ // if (lookForStore) {
165
+ // debug("Found store");
166
+ // }
167
+ // } else
168
+ if (!success
171
169
&& opcode == INVOKEVIRTUAL
172
170
&& owner .equals ("org/eclipse/jetty/server/Server" )
173
171
&& name .equals ("handle" )
@@ -267,17 +265,17 @@ public void visitMethodInsn(
267
265
Label beforeRegularDispatch = new Label ();
268
266
Label afterRegularDispatch = new Label ();
269
267
270
- super .visitVarInsn (ALOAD , CONTEXT_VAR );
271
- super .visitJumpInsn (Opcodes .IFNULL , beforeRegularDispatch );
272
- super .visitVarInsn (ALOAD , CONTEXT_VAR );
273
- super .visitMethodInsn (
274
- Opcodes .INVOKEINTERFACE ,
275
- "datadog/trace/bootstrap/instrumentation/api/AgentSpan" ,
276
- "getRequestBlockingAction" ,
277
- "()" + Type .getDescriptor (Flow .Action .RequestBlockingAction .class ),
278
- true );
279
- super .visitJumpInsn (Opcodes .IFNONNULL , doBlockLabel );
280
- super .visitJumpInsn (GOTO , beforeRegularDispatch );
268
+ // super.visitVarInsn(ALOAD, CONTEXT_VAR);
269
+ // super.visitJumpInsn(Opcodes.IFNULL, beforeRegularDispatch);
270
+ // super.visitVarInsn(ALOAD, CONTEXT_VAR);
271
+ // super.visitMethodInsn(
272
+ // Opcodes.INVOKEINTERFACE,
273
+ // "datadog/trace/bootstrap/instrumentation/api/AgentSpan",
274
+ // "getRequestBlockingAction",
275
+ // "()" + Type.getDescriptor(Flow.Action.RequestBlockingAction.class),
276
+ // true);
277
+ // super.visitJumpInsn(Opcodes.IFNONNULL, doBlockLabel);
278
+ // super.visitJumpInsn(GOTO, beforeRegularDispatch);
281
279
282
280
super .visitLabel (doBlockLabel );
283
281
super .visitFrame (F_SAME , 0 , null , 0 , null );
@@ -301,21 +299,29 @@ public void visitMethodInsn(
301
299
"getResponse" ,
302
300
"()Lorg/eclipse/jetty/server/Response;" ,
303
301
false );
304
- super .visitVarInsn (ALOAD , CONTEXT_VAR );
302
+ // super.visitVarInsn(ALOAD, CONTEXT_VAR);
303
+ // super.visitMethodInsn(
304
+ // Opcodes.INVOKEINTERFACE,
305
+ // "datadog/trace/bootstrap/instrumentation/api/AgentSpan",
306
+ // "getRequestBlockingAction",
307
+ // "()" + Type.getDescriptor(Flow.Action.RequestBlockingAction.class),
308
+ // true);
305
309
super .visitMethodInsn (
306
- Opcodes .INVOKEINTERFACE ,
307
- "datadog/trace/bootstrap/instrumentation/api/AgentSpan" ,
308
- "getRequestBlockingAction" ,
309
- "()" + Type .getDescriptor (Flow .Action .RequestBlockingAction .class ),
310
- true );
311
- super .visitVarInsn (ALOAD , CONTEXT_VAR );
310
+ INVOKESTATIC ,
311
+ Type .getInternalName (Java8BytecodeBridge .class ),
312
+ "getCurrentContext" ,
313
+ "()Ldatadog/context/Context;" ,
314
+ false
315
+ );
316
+ // super.visitVarInsn(ALOAD, CONTEXT_VAR);
312
317
313
318
// create the lambda
314
319
super .visitInvokeDynamicInsn (
315
320
"dispatch" ,
316
321
"(Lorg/eclipse/jetty/server/Request;Lorg/eclipse/jetty/server/Response;"
317
- + Type .getDescriptor (Flow .Action .RequestBlockingAction .class )
318
- + Type .getDescriptor (AgentSpan .class )
322
+ // + Type.getDescriptor(Flow.Action.RequestBlockingAction.class)
323
+ // + Type.getDescriptor(AgentSpan.class)
324
+ + Type .getDescriptor (Context .class )
319
325
+ ")Lorg/eclipse/jetty/server/HttpChannel$Dispatchable;" ,
320
326
new Handle (
321
327
H_INVOKESTATIC ,
@@ -330,8 +336,9 @@ public void visitMethodInsn(
330
336
Type .getInternalName (JettyBlockingHelper .class ),
331
337
"blockAndThrowOnFailure" ,
332
338
"(Lorg/eclipse/jetty/server/Request;Lorg/eclipse/jetty/server/Response;"
333
- + Type .getDescriptor (Flow .Action .RequestBlockingAction .class )
334
- + Type .getDescriptor (AgentSpan .class )
339
+ // + Type.getDescriptor(Flow.Action.RequestBlockingAction.class)
340
+ // + Type.getDescriptor(AgentSpan.class)
341
+ + Type .getDescriptor (Context .class )
335
342
+ ")V" ,
336
343
false ),
337
344
Type .getType ("()V" )
@@ -387,19 +394,19 @@ private boolean checkDispatchMethodState(final List<Runnable> savedVisitations)
387
394
return last instanceof DelayCertainInsMethodVisitor .GetFieldInsn ;
388
395
}
389
396
390
- @ Override
391
- public void visitVarInsn (int opcode , int varIndex ) {
392
- if (lookForStore && opcode == ASTORE ) {
393
- debug ("Found context" );
394
- contextStored = true ;
395
- lookForStore = false ;
396
- // contextVarIndex = varIndex;
397
- // Duplicate on stack and store to its own local var
398
- // super.visitInsn(DUP);
399
- // super.visitVarInsn(ASTORE, CONTEXT_VAR);
400
- }
401
- super .visitVarInsn (opcode , varIndex );
402
- }
397
+ // @Override
398
+ // public void visitVarInsn(int opcode, int varIndex) {
399
+ // if (lookForStore && opcode == ASTORE) {
400
+ // debug("Found context");
401
+ // contextStored = true;
402
+ // lookForStore = false;
403
+ //// contextVarIndex = varIndex;
404
+ // // Duplicate on stack and store to its own local var
405
+ //// super.visitInsn(DUP);
406
+ //// super.visitVarInsn(ASTORE, CONTEXT_VAR);
407
+ // }
408
+ // super.visitVarInsn(opcode, varIndex);
409
+ // }
403
410
404
411
// @Override
405
412
// public void visitMaxs(int maxStack, int maxLocals) {
0 commit comments