36
36
import static com .oracle .svm .jvmtiagentbase .Support .getClassNameOrNull ;
37
37
import static com .oracle .svm .jvmtiagentbase .Support .getMethodDeclaringClass ;
38
38
import static com .oracle .svm .jvmtiagentbase .Support .getObjectArgument ;
39
+ import static com .oracle .svm .jvmtiagentbase .Support .getReceiver ;
39
40
import static com .oracle .svm .jvmtiagentbase .Support .handleException ;
40
41
import static com .oracle .svm .jvmtiagentbase .Support .jniFunctions ;
41
42
import static com .oracle .svm .jvmtiagentbase .Support .jvmtiEnv ;
60
61
import java .util .concurrent .locks .ReentrantLock ;
61
62
import java .util .function .Supplier ;
62
63
63
- import com .oracle .svm .jni .nativeapi .JNINativeMethod ;
64
64
import org .graalvm .compiler .core .common .NumUtil ;
65
65
import org .graalvm .nativeimage .StackValue ;
66
66
import org .graalvm .nativeimage .UnmanagedMemory ;
76
76
import org .graalvm .nativeimage .c .type .CTypeConversion ;
77
77
import org .graalvm .nativeimage .c .type .CTypeConversion .CCharPointerHolder ;
78
78
import org .graalvm .nativeimage .c .type .WordPointer ;
79
+ import org .graalvm .word .WordFactory ;
79
80
80
81
import com .oracle .svm .agent .stackaccess .InterceptedState ;
81
82
import com .oracle .svm .agent .tracing .core .Tracer ;
86
87
import com .oracle .svm .jni .nativeapi .JNIEnvironment ;
87
88
import com .oracle .svm .jni .nativeapi .JNIFieldId ;
88
89
import com .oracle .svm .jni .nativeapi .JNIMethodId ;
90
+ import com .oracle .svm .jni .nativeapi .JNINativeMethod ;
89
91
import com .oracle .svm .jni .nativeapi .JNIObjectHandle ;
90
92
import com .oracle .svm .jni .nativeapi .JNIValue ;
91
93
import com .oracle .svm .jvmtiagentbase .AgentIsolate ;
99
101
import com .oracle .svm .jvmtiagentbase .jvmti .JvmtiEventMode ;
100
102
import com .oracle .svm .jvmtiagentbase .jvmti .JvmtiFrameInfo ;
101
103
import com .oracle .svm .jvmtiagentbase .jvmti .JvmtiLocationFormat ;
102
- import org .graalvm .word .WordFactory ;
103
104
104
105
/**
105
106
* Intercepts events of interest via breakpoints in Java code.
@@ -251,7 +252,7 @@ private static boolean getDeclaredFields(JNIEnvironment jni, Breakpoint bp, Inte
251
252
252
253
private static boolean handleGetFields (JNIEnvironment jni , Breakpoint bp , InterceptedState state ) {
253
254
JNIObjectHandle callerClass = state .getDirectCallerClass ();
254
- JNIObjectHandle self = getObjectArgument ( 0 );
255
+ JNIObjectHandle self = getReceiver ( );
255
256
traceReflectBreakpoint (jni , getClassOrSingleProxyInterface (jni , self ), nullHandle (), callerClass , bp .specification .methodName , null , state .getFullStackTraceOrNull ());
256
257
return true ;
257
258
}
@@ -274,7 +275,7 @@ private static boolean getDeclaredConstructors(JNIEnvironment jni, Breakpoint bp
274
275
275
276
private static boolean handleGetMethods (JNIEnvironment jni , Breakpoint bp , InterceptedState state ) {
276
277
JNIObjectHandle callerClass = state .getDirectCallerClass ();
277
- JNIObjectHandle self = getObjectArgument ( 0 );
278
+ JNIObjectHandle self = getReceiver ( );
278
279
traceReflectBreakpoint (jni , getClassOrSingleProxyInterface (jni , self ), nullHandle (), callerClass , bp .specification .methodName , null , state .getFullStackTraceOrNull ());
279
280
return true ;
280
281
}
@@ -293,7 +294,7 @@ private static boolean getPermittedSubclasses(JNIEnvironment jni, Breakpoint bp,
293
294
294
295
private static boolean handleGetClasses (JNIEnvironment jni , Breakpoint bp , InterceptedState state ) {
295
296
JNIObjectHandle callerClass = state .getDirectCallerClass ();
296
- JNIObjectHandle self = getObjectArgument ( 0 );
297
+ JNIObjectHandle self = getReceiver ( );
297
298
traceReflectBreakpoint (jni , self , nullHandle (), callerClass , bp .specification .methodName , null , state .getFullStackTraceOrNull ());
298
299
return true ;
299
300
}
@@ -308,7 +309,7 @@ private static boolean getDeclaredField(JNIEnvironment jni, Breakpoint bp, Inter
308
309
309
310
private static boolean handleGetField (JNIEnvironment jni , Breakpoint bp , boolean declaredOnly , InterceptedState state ) {
310
311
JNIObjectHandle callerClass = state .getDirectCallerClass ();
311
- JNIObjectHandle self = getObjectArgument ( 0 );
312
+ JNIObjectHandle self = getReceiver ( );
312
313
JNIObjectHandle name = getObjectArgument (1 );
313
314
JNIObjectHandle result = Support .callObjectMethodL (jni , self , bp .method , name );
314
315
if (clearException (jni )) {
@@ -369,7 +370,7 @@ private static void traceAllocateInstance(JNIEnvironment jni, JNIObjectHandle cl
369
370
370
371
private static boolean objectFieldOffsetByName (JNIEnvironment jni , Breakpoint bp , InterceptedState state ) {
371
372
JNIObjectHandle callerClass = state .getDirectCallerClass ();
372
- JNIObjectHandle self = getObjectArgument ( 0 );
373
+ JNIObjectHandle self = getReceiver ( );
373
374
JNIObjectHandle declaring = getObjectArgument (1 );
374
375
JNIObjectHandle name = getObjectArgument (2 );
375
376
Support .callLongMethodLL (jni , self , bp .method , declaring , name );
@@ -382,7 +383,7 @@ private static boolean objectFieldOffsetByName(JNIEnvironment jni, Breakpoint bp
382
383
383
384
private static boolean getConstructor (JNIEnvironment jni , Breakpoint bp , InterceptedState state ) {
384
385
JNIObjectHandle callerClass = state .getDirectCallerClass ();
385
- JNIObjectHandle self = getObjectArgument ( 0 );
386
+ JNIObjectHandle self = getReceiver ( );
386
387
JNIObjectHandle paramTypesHandle = getObjectArgument (1 );
387
388
JNIObjectHandle result = Support .callObjectMethodL (jni , self , bp .method , paramTypesHandle );
388
389
if (clearException (jni )) {
@@ -404,7 +405,7 @@ private static boolean getDeclaredMethod(JNIEnvironment jni, Breakpoint bp, Inte
404
405
405
406
private static boolean handleGetMethod (JNIEnvironment jni , Breakpoint bp , boolean declaredOnly , InterceptedState state ) {
406
407
JNIObjectHandle callerClass = state .getDirectCallerClass ();
407
- JNIObjectHandle self = getObjectArgument ( 0 );
408
+ JNIObjectHandle self = getReceiver ( );
408
409
JNIObjectHandle nameHandle = getObjectArgument (1 );
409
410
JNIObjectHandle paramTypesHandle = getObjectArgument (2 );
410
411
JNIObjectHandle result = Support .callObjectMethodLL (jni , self , bp .method , nameHandle , paramTypesHandle );
@@ -427,7 +428,7 @@ private static boolean handleGetMethod(JNIEnvironment jni, Breakpoint bp, boolea
427
428
428
429
private static boolean getEnclosingMethod (JNIEnvironment jni , Breakpoint bp , InterceptedState state ) {
429
430
JNIObjectHandle callerClass = state .getDirectCallerClass ();
430
- JNIObjectHandle self = getObjectArgument ( 0 );
431
+ JNIObjectHandle self = getReceiver ( );
431
432
Object result = Tracer .EXPLICIT_NULL ;
432
433
JNIObjectHandle enclosing = Support .callObjectMethod (jni , self , bp .method );
433
434
String name ;
@@ -514,7 +515,7 @@ private static boolean isClassNewInstance(JNIEnvironment jni, JNIObjectHandle de
514
515
}
515
516
516
517
private static boolean invokeConstructor (JNIEnvironment jni , Breakpoint bp , InterceptedState state ) {
517
- return handleInvokeConstructor (jni , bp , state , getObjectArgument ( 0 ));
518
+ return handleInvokeConstructor (jni , bp , state , getReceiver ( ));
518
519
}
519
520
520
521
private static boolean unreflectConstructor (JNIEnvironment jni , Breakpoint bp , InterceptedState state ) {
@@ -542,7 +543,7 @@ private static boolean handleInvokeConstructor(JNIEnvironment jni, @SuppressWarn
542
543
543
544
private static boolean newInstance (JNIEnvironment jni , Breakpoint bp , InterceptedState state ) {
544
545
JNIObjectHandle callerClass = state .getDirectCallerClass ();
545
- JNIObjectHandle self = getObjectArgument ( 0 );
546
+ JNIObjectHandle self = getReceiver ( );
546
547
JNIMethodId result = newInstanceMethodID (jni , self );
547
548
traceReflectBreakpoint (jni , self , nullHandle (), callerClass , bp .specification .methodName , result .notEqual (nullHandle ()), state .getFullStackTraceOrNull ());
548
549
return true ;
@@ -564,15 +565,13 @@ private static JNIMethodId newInstanceMethodID(JNIEnvironment jni, JNIObjectHand
564
565
}
565
566
566
567
private static boolean newArrayInstance (JNIEnvironment jni , Breakpoint bp , InterceptedState state ) {
567
- JNIObjectHandle componentClass = getObjectArgument (0 );
568
- CIntPointer lengthPtr = StackValue .get (CIntPointer .class );
569
- boolean lengthValid = (jvmtiFunctions ().GetLocalInt ().invoke (jvmtiEnv (), nullHandle (), 0 , 1 , lengthPtr ) == JvmtiError .JVMTI_ERROR_NONE );
570
-
571
568
JNIValue args = StackValue .get (2 , JNIValue .class );
572
- args .addressOf (0 ).setObject (componentClass );
573
- args .addressOf (1 ).setInt (lengthPtr .read ());
569
+ args .addressOf (0 ).setObject (getObjectArgument (0 ));
570
+ args .addressOf (1 ).setInt (0 );
571
+ // We ignore the actual array length because we have observed reading it to cause serious
572
+ // slowdowns in multithreaded programs because it requires full safepoint operations.
574
573
575
- return newArrayInstance0 (jni , bp , args , lengthValid , state );
574
+ return newArrayInstance0 (jni , bp , args , true , state );
576
575
}
577
576
578
577
private static boolean newArrayInstanceMulti (JNIEnvironment jni , Breakpoint bp , InterceptedState state ) {
@@ -617,7 +616,7 @@ private static boolean getResources(JNIEnvironment jni, Breakpoint bp, Intercept
617
616
618
617
private static boolean handleGetResources (JNIEnvironment jni , Breakpoint bp , boolean returnsEnumeration , InterceptedState state ) {
619
618
JNIObjectHandle callerClass = state .getDirectCallerClass ();
620
- JNIObjectHandle self = getObjectArgument ( 0 );
619
+ JNIObjectHandle self = getReceiver ( );
621
620
JNIObjectHandle name = getObjectArgument (1 );
622
621
boolean result ;
623
622
JNIObjectHandle returnValue = Support .callObjectMethodL (jni , self , bp .method , name );
@@ -657,7 +656,7 @@ private static boolean getSystemResources(JNIEnvironment jni, Breakpoint bp, Int
657
656
658
657
private static boolean handleGetSystemResources (JNIEnvironment jni , Breakpoint bp , boolean returnsEnumeration , InterceptedState state ) {
659
658
JNIObjectHandle callerClass = state .getDirectCallerClass ();
660
- JNIObjectHandle name = getObjectArgument ( 0 );
659
+ JNIObjectHandle name = getReceiver ( );
661
660
JNIObjectHandle returnValue = Support .callStaticObjectMethodL (jni , bp .clazz , bp .method , name );
662
661
boolean result = returnValue .notEqual (nullHandle ());
663
662
if (clearException (jni )) {
@@ -853,7 +852,7 @@ private static boolean loadClass(JNIEnvironment jni, Breakpoint bp, InterceptedS
853
852
observedExplicitLoadClassCallSites .put (location , Boolean .TRUE );
854
853
}
855
854
}
856
- JNIObjectHandle self = getObjectArgument ( 0 );
855
+ JNIObjectHandle self = getReceiver ( );
857
856
JNIObjectHandle name = getObjectArgument (1 );
858
857
String className = fromJniString (jni , name );
859
858
JNIObjectHandle clazz = Support .callObjectMethodL (jni , self , bp .method , name );
@@ -914,7 +913,7 @@ private static boolean isLoadClassInvocation(JNIObjectHandle clazz, JNIMethodId
914
913
915
914
private static boolean findMethodHandle (JNIEnvironment jni , Breakpoint bp , InterceptedState state ) {
916
915
JNIObjectHandle callerClass = state .getDirectCallerClass ();
917
- JNIObjectHandle lookup = getObjectArgument ( 0 );
916
+ JNIObjectHandle lookup = getReceiver ( );
918
917
JNIObjectHandle declaringClass = getObjectArgument (1 );
919
918
JNIObjectHandle methodName = getObjectArgument (2 );
920
919
JNIObjectHandle methodType = getObjectArgument (3 );
@@ -927,7 +926,7 @@ private static boolean findMethodHandle(JNIEnvironment jni, Breakpoint bp, Inter
927
926
928
927
private static boolean findSpecialHandle (JNIEnvironment jni , Breakpoint bp , InterceptedState state ) {
929
928
JNIObjectHandle callerClass = state .getDirectCallerClass ();
930
- JNIObjectHandle lookup = getObjectArgument ( 0 );
929
+ JNIObjectHandle lookup = getReceiver ( );
931
930
JNIObjectHandle declaringClass = getObjectArgument (1 );
932
931
JNIObjectHandle methodName = getObjectArgument (2 );
933
932
JNIObjectHandle methodType = getObjectArgument (3 );
@@ -941,7 +940,7 @@ private static boolean findSpecialHandle(JNIEnvironment jni, Breakpoint bp, Inte
941
940
942
941
private static boolean bindHandle (JNIEnvironment jni , Breakpoint bp , InterceptedState state ) {
943
942
JNIObjectHandle callerClass = state .getDirectCallerClass ();
944
- JNIObjectHandle lookup = getObjectArgument ( 0 );
943
+ JNIObjectHandle lookup = getReceiver ( );
945
944
JNIObjectHandle receiver = getObjectArgument (1 );
946
945
JNIObjectHandle methodName = getObjectArgument (2 );
947
946
JNIObjectHandle methodType = getObjectArgument (3 );
@@ -967,7 +966,7 @@ private static boolean methodMethodHandle(JNIEnvironment jni, JNIObjectHandle de
967
966
968
967
private static boolean findConstructorHandle (JNIEnvironment jni , Breakpoint bp , InterceptedState state ) {
969
968
JNIObjectHandle callerClass = state .getDirectCallerClass ();
970
- JNIObjectHandle lookup = getObjectArgument ( 0 );
969
+ JNIObjectHandle lookup = getReceiver ( );
971
970
JNIObjectHandle declaringClass = getObjectArgument (1 );
972
971
JNIObjectHandle methodType = getObjectArgument (2 );
973
972
@@ -989,7 +988,7 @@ private static JNIObjectHandle getParamTypes(JNIEnvironment jni, JNIObjectHandle
989
988
990
989
private static boolean findFieldHandle (JNIEnvironment jni , Breakpoint bp , InterceptedState state ) {
991
990
JNIObjectHandle callerClass = state .getDirectCallerClass ();
992
- JNIObjectHandle lookup = getObjectArgument ( 0 );
991
+ JNIObjectHandle lookup = getReceiver ( );
993
992
JNIObjectHandle declaringClass = getObjectArgument (1 );
994
993
JNIObjectHandle fieldName = getObjectArgument (2 );
995
994
JNIObjectHandle fieldType = getObjectArgument (3 );
@@ -1004,7 +1003,7 @@ private static boolean findFieldHandle(JNIEnvironment jni, Breakpoint bp, Interc
1004
1003
1005
1004
private static boolean findClass (JNIEnvironment jni , Breakpoint bp , InterceptedState state ) {
1006
1005
JNIObjectHandle callerClass = state .getDirectCallerClass ();
1007
- JNIObjectHandle lookup = getObjectArgument ( 0 );
1006
+ JNIObjectHandle lookup = getReceiver ( );
1008
1007
JNIObjectHandle className = getObjectArgument (1 );
1009
1008
1010
1009
JNIObjectHandle result = Support .callObjectMethodL (jni , lookup , bp .method , className );
@@ -1017,7 +1016,7 @@ private static boolean findClass(JNIEnvironment jni, Breakpoint bp, InterceptedS
1017
1016
1018
1017
private static boolean unreflectField (JNIEnvironment jni , Breakpoint bp , InterceptedState state ) {
1019
1018
JNIObjectHandle callerClass = state .getDirectCallerClass ();
1020
- JNIObjectHandle lookup = getObjectArgument ( 0 );
1019
+ JNIObjectHandle lookup = getReceiver ( );
1021
1020
JNIObjectHandle field = getObjectArgument (1 );
1022
1021
1023
1022
JNIObjectHandle result = Support .callObjectMethodL (jni , lookup , bp .method , field );
@@ -1138,7 +1137,7 @@ private static JNIObjectHandle shouldIncludeMethod(JNIEnvironment jni, JNIObject
1138
1137
* register it.
1139
1138
*/
1140
1139
private static boolean serializedLambdaReadResolve (JNIEnvironment jni , @ SuppressWarnings ("unused" ) Breakpoint bp , InterceptedState state ) {
1141
- JNIObjectHandle serializedLambdaInstance = getObjectArgument ( 0 );
1140
+ JNIObjectHandle serializedLambdaInstance = getReceiver ( );
1142
1141
JNIObjectHandle capturingClass = jniFunctions ().getGetObjectField ().invoke (jni , serializedLambdaInstance ,
1143
1142
agent .handles ().javaLangInvokeSerializedLambdaCapturingClass );
1144
1143
0 commit comments