2
2
3
3
import static net .bytebuddy .jar .asm .Opcodes .ALOAD ;
4
4
import static net .bytebuddy .jar .asm .Opcodes .F_SAME ;
5
- import static net .bytebuddy .jar .asm .Opcodes .GOTO ;
6
5
import static net .bytebuddy .jar .asm .Opcodes .H_INVOKESTATIC ;
6
+ import static net .bytebuddy .jar .asm .Opcodes .IFEQ ;
7
7
import static net .bytebuddy .jar .asm .Opcodes .IFNE ;
8
8
import static net .bytebuddy .jar .asm .Opcodes .INVOKESTATIC ;
9
9
import static net .bytebuddy .jar .asm .Opcodes .INVOKEVIRTUAL ;
@@ -275,6 +275,7 @@ public void visitMethodInsn(
275
275
return ;
276
276
}
277
277
278
+ // TODO Could be moved to #checkDispatchMethodState
278
279
DelayCertainInsMethodVisitor .GetStaticFieldInsn getStaticFieldInsn =
279
280
(DelayCertainInsMethodVisitor .GetStaticFieldInsn ) savedVisitations .get (1 );
280
281
if ((!getStaticFieldInsn .owner .equals ("javax/servlet/DispatcherType" )
@@ -284,9 +285,26 @@ public void visitMethodInsn(
284
285
return ;
285
286
}
286
287
287
- Label doBlockLabel = new Label ();
288
+ // Label doBlockLabel = new Label();
288
289
Label beforeRegularDispatch = new Label ();
289
- Label afterRegularDispatch = new Label ();
290
+ // Label afterRegularDispatch = new Label();
291
+
292
+ // Add current context to the stack
293
+ super .visitMethodInsn (
294
+ INVOKESTATIC ,
295
+ Type .getInternalName (Java8BytecodeBridge .class ),
296
+ "getCurrentContext" ,
297
+ "()Ldatadog/context/Context;" ,
298
+ false );
299
+ // Call JettyBlockingHelper.hasRequestBlockingAction(context)
300
+ super .visitMethodInsn (
301
+ INVOKESTATIC ,
302
+ Type .getInternalName (JettyBlockingHelper .class ),
303
+ "hasRequestBlockingAction" ,
304
+ "(" + Type .getDescriptor (Context .class ) + ")Z" ,
305
+ false );
306
+ // If no request blocking action, jump befor the regular dispatch
307
+ super .visitJumpInsn (IFEQ , beforeRegularDispatch );
290
308
291
309
// super.visitVarInsn(ALOAD, CONTEXT_VAR);
292
310
// super.visitJumpInsn(Opcodes.IFNULL, beforeRegularDispatch);
@@ -300,14 +318,13 @@ public void visitMethodInsn(
300
318
// super.visitJumpInsn(Opcodes.IFNONNULL, doBlockLabel);
301
319
// super.visitJumpInsn(GOTO, beforeRegularDispatch);
302
320
303
- super .visitLabel (doBlockLabel );
304
- super .visitFrame (F_SAME , 0 , null , 0 , null );
321
+ // super.visitLabel(doBlockLabel);
322
+ // super.visitFrame(F_SAME, 0, null, 0, null);
305
323
// dispatch with a Dispatchable created from JettyBlockingHelper::block
306
324
// first set up the first two arguments to dispatch (this and DispatcherType.REQUEST)
307
325
List <Runnable > loadThisAndEnum = new ArrayList <>(savedVisitations .subList (0 , 2 ));
308
326
mv .commitVisitations (loadThisAndEnum );
309
- // set up the arguments to the method underlying the lambda (Request, Response,
310
- // RequestBlockingAction, AgentSpan)
327
+ // set up the arguments to the method underlying the lambda (Request, Response, Context)
311
328
super .visitVarInsn (ALOAD , 0 );
312
329
super .visitMethodInsn (
313
330
INVOKEVIRTUAL ,
@@ -369,14 +386,14 @@ public void visitMethodInsn(
369
386
// invoke the dispatch method
370
387
super .visitMethodInsn (opcode , owner , name , descriptor , isInterface );
371
388
372
- super .visitJumpInsn (GOTO , afterRegularDispatch );
389
+ // super.visitJumpInsn(GOTO, afterRegularDispatch);
373
390
374
391
super .visitLabel (beforeRegularDispatch );
375
392
super .visitFrame (F_SAME , 0 , null , 0 , null );
376
393
mv .commitVisitations (savedVisitations );
377
394
super .visitMethodInsn (opcode , owner , name , descriptor , isInterface );
378
- super .visitLabel (afterRegularDispatch );
379
- super .visitFrame (F_SAME , 0 , null , 0 , null );
395
+ // super.visitLabel(afterRegularDispatch);
396
+ // super.visitFrame(F_SAME, 0, null, 0, null);
380
397
this .success = true ;
381
398
return ;
382
399
}
0 commit comments