@@ -290,19 +290,24 @@ private LocalVariableHelper instrumentorFor(
290290 case ARRAY_GET :
291291 // <editor-fold defaultstate="collapsed" desc="Array Get Instrumentor">
292292 return new ArrayAccessInstrumentor (mv , className , superName , access , name , desc ) {
293- int [] argsIndex = new int []{- 1 , - 1 };
294- final private int INSTANCE_PTR = 0 ;
295- final private int INDEX_PTR = 1 ;
293+ int [] argsIndex = new int []{Integer . MIN_VALUE , Integer . MIN_VALUE };
294+ final private int INDEX_PTR = 0 ;
295+ final private int INSTANCE_PTR = 1 ;
296296
297297 @ Override
298298 protected void onBeforeArrayLoad (int opcode ) {
299299 Type arrtype = TypeUtils .getArrayType (opcode );
300300 Type retType = TypeUtils .getElementType (opcode );
301+
302+ if (!locationTypeMatches (loc , arrtype , retType )) return ;
303+
301304 addExtraTypeInfo (om .getSelfParameter (), Type .getObjectType (className ));
305+ addExtraTypeInfo (om .getTargetInstanceParameter (), arrtype );
306+
302307 if (where == Where .AFTER ) {
303308 addExtraTypeInfo (om .getReturnParameter (), retType );
304309 }
305- ValidationResult vr = validateArguments (om , isStatic (), actionArgTypes , new Type []{arrtype , Type .INT_TYPE });
310+ ValidationResult vr = validateArguments (om , isStatic (), actionArgTypes , new Type []{Type .INT_TYPE });
306311 if (vr .isValid ()) {
307312 if (!vr .isAny ()) {
308313 asm .dup2 ();
@@ -313,7 +318,7 @@ protected void onBeforeArrayLoad(int opcode) {
313318 if (where == Where .BEFORE ) {
314319 loadArguments (
315320 localVarArg (vr .getArgIdx (INDEX_PTR ), Type .INT_TYPE , argsIndex [INDEX_PTR ]),
316- localVarArg (vr . getArgIdx ( INSTANCE_PTR ), arrtype , argsIndex [INSTANCE_PTR ]),
321+ localVarArg (om . getTargetInstanceParameter ( ), TypeUtils . objectType , argsIndex [INSTANCE_PTR ]),
317322 constArg (om .getClassNameParameter (), className .replace ("/" , "." )),
318323 constArg (om .getMethodParameter (), getName (om .isMethodFqn ())),
319324 localVarArg (om .getSelfParameter (), Type .getObjectType (className ), 0 ));
@@ -331,24 +336,31 @@ protected void onAfterArrayLoad(int opcode) {
331336 if (where == Where .AFTER ) {
332337 Type arrtype = TypeUtils .getArrayType (opcode );
333338 Type retType = TypeUtils .getElementType (opcode );
339+
340+ if (!locationTypeMatches (loc , arrtype , retType )) return ;
341+
334342 addExtraTypeInfo (om .getSelfParameter (), Type .getObjectType (className ));
343+ addExtraTypeInfo (om .getTargetInstanceParameter (), arrtype );
335344 addExtraTypeInfo (om .getReturnParameter (), retType );
336- ValidationResult vr = validateArguments (om , isStatic (), actionArgTypes , new Type []{arrtype , Type .INT_TYPE });
345+ ValidationResult vr = validateArguments (om , isStatic (), actionArgTypes , new Type []{Type .INT_TYPE });
337346 if (vr .isValid ()) {
338347 Label l = levelCheckAfter (om , btraceClassName );
339348
340349 int retValIndex = -1 ;
350+ Type actionArgRetType = om .getReturnParameter () != -1 ?
351+ actionArgTypes [om .getReturnParameter ()] :
352+ Type .VOID_TYPE ;
341353 if (om .getReturnParameter () != -1 ) {
342354 asm .dupArrayValue (opcode );
343355 retValIndex = storeNewLocal (retType );
344356 }
345357
346358 loadArguments (
347359 localVarArg (vr .getArgIdx (INDEX_PTR ), Type .INT_TYPE , argsIndex [INDEX_PTR ]),
348- localVarArg (vr . getArgIdx ( INSTANCE_PTR ), arrtype , argsIndex [INSTANCE_PTR ]),
360+ localVarArg (om . getTargetInstanceParameter ( ), TypeUtils . objectType , argsIndex [INSTANCE_PTR ]),
349361 constArg (om .getClassNameParameter (), className .replace ("/" , "." )),
350362 constArg (om .getMethodParameter (), getName (om .isMethodFqn ())),
351- localVarArg (om .getReturnParameter (), retType , retValIndex ),
363+ localVarArg (om .getReturnParameter (), retType , retValIndex , TypeUtils . isAnyType ( actionArgRetType ) ),
352364 localVarArg (om .getSelfParameter (), Type .getObjectType (className ), 0 ));
353365 invokeBTraceAction (asm , om );
354366
@@ -363,18 +375,28 @@ protected void onAfterArrayLoad(int opcode) {
363375 case ARRAY_SET :
364376 // <editor-fold defaultstate="collapsed" desc="Array Set Instrumentor">
365377 return new ArrayAccessInstrumentor (mv , className , superName , access , name , desc ) {
366- int [] argsIndex = new int []{-1 , -1 , -1 };
367- final private int INSTANCE_PTR = 0 , INDEX_PTR = 1 , VALUE_PTR = 2 ;
378+ int [] argsIndex = new int []{-1 , -1 , -1 , - 1 };
379+ final private int INDEX_PTR = 0 , VALUE_PTR = 1 , INSTANCE_PTR = 2 ;
368380
369381 @ Override
370382 protected void onBeforeArrayStore (int opcode ) {
371383 Type elementType = TypeUtils .getElementType (opcode );
372384 Type arrayType = TypeUtils .getArrayType (opcode );
373385
386+ if (!locationTypeMatches (loc , arrayType , elementType )) return ;
387+
374388 addExtraTypeInfo (om .getSelfParameter (), Type .getObjectType (className ));
375- ValidationResult vr = validateArguments (om , isStatic (), actionArgTypes , new Type []{arrayType , Type .INT_TYPE , elementType });
389+ addExtraTypeInfo (om .getTargetInstanceParameter (), arrayType );
390+
391+ ValidationResult vr = validateArguments (om , isStatic (), actionArgTypes , new Type []{Type .INT_TYPE , elementType });
376392 if (vr .isValid ()) {
393+ Type argElementType = Type .VOID_TYPE ;
394+
377395 if (!vr .isAny ()) {
396+ int elementIdx = vr .getArgIdx (VALUE_PTR );
397+ argElementType = elementIdx > -1 ?
398+ actionArgTypes [elementIdx ] :
399+ Type .VOID_TYPE ;
378400 argsIndex [VALUE_PTR ] = storeNewLocal (elementType );
379401 asm .dup2 ();
380402 argsIndex [INDEX_PTR ] = storeNewLocal (Type .INT_TYPE );
@@ -386,9 +408,9 @@ protected void onBeforeArrayStore(int opcode) {
386408
387409 if (where == Where .BEFORE ) {
388410 loadArguments (
389- localVarArg (vr . getArgIdx ( INSTANCE_PTR ), arrayType , argsIndex [INSTANCE_PTR ]),
411+ localVarArg (om . getTargetInstanceParameter ( ), arrayType , argsIndex [INSTANCE_PTR ]),
390412 localVarArg (vr .getArgIdx (INDEX_PTR ), Type .INT_TYPE , argsIndex [INDEX_PTR ]),
391- localVarArg (vr .getArgIdx (VALUE_PTR ), elementType , argsIndex [VALUE_PTR ]),
413+ localVarArg (vr .getArgIdx (VALUE_PTR ), elementType , argsIndex [VALUE_PTR ], TypeUtils . isAnyType ( argElementType ) ),
392414 constArg (om .getClassNameParameter (), className .replace ("/" , "." )),
393415 constArg (om .getMethodParameter (), getName (om .isMethodFqn ())),
394416 localVarArg (om .getSelfParameter (), Type .getObjectType (className ), 0 ));
@@ -407,15 +429,24 @@ protected void onAfterArrayStore(int opcode) {
407429 Type elementType = TypeUtils .getElementType (opcode );
408430 Type arrayType = TypeUtils .getArrayType (opcode );
409431
432+ if (!locationTypeMatches (loc , arrayType , elementType )) return ;
433+
410434 addExtraTypeInfo (om .getSelfParameter (), Type .getObjectType (className ));
411- ValidationResult vr = validateArguments (om , isStatic (), actionArgTypes , new Type []{arrayType , Type .INT_TYPE , elementType });
435+ addExtraTypeInfo (om .getTargetInstanceParameter (), arrayType );
436+
437+ ValidationResult vr = validateArguments (om , isStatic (), actionArgTypes , new Type []{Type .INT_TYPE , elementType });
412438 if (vr .isValid ()) {
439+ int elementIdx = vr .getArgIdx (VALUE_PTR );
440+ Type argElementType = elementIdx > -1 ?
441+ actionArgTypes [elementIdx ] :
442+ Type .VOID_TYPE ;
443+
413444 Label l = levelCheckAfter (om , btraceClassName );
414445
415446 loadArguments (
416- localVarArg (vr . getArgIdx ( INSTANCE_PTR ), arrayType , argsIndex [INSTANCE_PTR ]),
447+ localVarArg (om . getTargetInstanceParameter ( ), arrayType , argsIndex [INSTANCE_PTR ]),
417448 localVarArg (vr .getArgIdx (INDEX_PTR ), Type .INT_TYPE , argsIndex [INDEX_PTR ]),
418- localVarArg (vr .getArgIdx (VALUE_PTR ), elementType , argsIndex [VALUE_PTR ]),
449+ localVarArg (vr .getArgIdx (VALUE_PTR ), elementType , argsIndex [VALUE_PTR ], TypeUtils . isAnyType ( argElementType ) ),
419450 constArg (om .getClassNameParameter (), className .replace ("/" , "." )),
420451 constArg (om .getMethodParameter (), getName (om .isMethodFqn ())),
421452 localVarArg (om .getSelfParameter (), Type .getObjectType (className ), 0 ));
0 commit comments