1
1
/*
2
- * Copyright (c) 2019, 2025 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2019, 2021 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -317,13 +317,9 @@ private static boolean getSigners(JNIEnvironment jni, JNIObjectHandle thread, Br
317
317
return handleGetClasses (jni , thread , bp , state );
318
318
}
319
319
320
- private static boolean handleGetClasses (JNIEnvironment jni , JNIObjectHandle thread , AbstractBreakpoint <?> bp , InterceptedState state ) {
321
- JNIObjectHandle self = getReceiver (thread );
322
- return handleGetClassesWithReceiver (jni , self , bp , state );
323
- }
324
-
325
- private static boolean handleGetClassesWithReceiver (JNIEnvironment jni , JNIObjectHandle self , AbstractBreakpoint <?> bp , InterceptedState state ) {
320
+ private static boolean handleGetClasses (JNIEnvironment jni , JNIObjectHandle thread , Breakpoint bp , InterceptedState state ) {
326
321
JNIObjectHandle callerClass = state .getDirectCallerClass ();
322
+ JNIObjectHandle self = getReceiver (thread );
327
323
traceReflectBreakpoint (jni , self , nullHandle (), callerClass , bp .specification .methodName , null , state .getFullStackTraceOrNull ());
328
324
return true ;
329
325
}
@@ -370,10 +366,10 @@ private interface AllocateInstanceFunctionPointer extends CFunctionPointer {
370
366
@ CEntryPoint
371
367
@ CEntryPointOptions (prologue = AgentIsolate .Prologue .class )
372
368
static long nativeAllocateInstance (JNIEnvironment jni , JNIObjectHandle self , JNIObjectHandle clazz ) {
373
- NativeBreakpoint breakpoint = NATIVE_ALLOCATE_INSTANCE_BREAKPOINT_SPEC .installed ;
374
- VMError . guarantee ( breakpoint != null && breakpoint .replacedFunction .isNonNull (), "incompletely installed" );
369
+ VMError . guarantee ( NATIVE_ALLOCATE_INSTANCE_BREAKPOINT_SPEC .installed != null &&
370
+ NATIVE_ALLOCATE_INSTANCE_BREAKPOINT_SPEC . installed .replacedFunction .isNonNull (), "incompletely installed" );
375
371
376
- AllocateInstanceFunctionPointer original = (AllocateInstanceFunctionPointer ) breakpoint .replacedFunction ;
372
+ AllocateInstanceFunctionPointer original = (AllocateInstanceFunctionPointer ) NATIVE_ALLOCATE_INSTANCE_BREAKPOINT_SPEC . installed .replacedFunction ;
377
373
long result = original .invoke (jni , self , clazz );
378
374
if (!Support .isInitialized ()) { // in case of a (very) late call
379
375
return result ;
@@ -396,36 +392,6 @@ private static void traceAllocateInstance(JNIEnvironment jni, JNIObjectHandle cl
396
392
}
397
393
}
398
394
399
- private static final CEntryPointLiteral <AllocateInstanceFunctionPointer > nativeGetSigners = CEntryPointLiteral .create (
400
- BreakpointInterceptor .class , "nativeGetSigners" , JNIEnvironment .class , JNIObjectHandle .class );
401
- private static final NativeBreakpointSpecification NATIVE_GET_SIGNERS_BREAKPOINT_SPEC = new NativeBreakpointSpecification (
402
- "java/lang/Class" , "getSigners" , "()[Ljava/lang/Object;" , nativeGetSigners );
403
-
404
- private interface GetSignersFunctionPointer extends CFunctionPointer {
405
- @ InvokeCFunctionPointer
406
- JNIObjectHandle invoke (JNIEnvironment jni , JNIObjectHandle self );
407
- }
408
-
409
- /**
410
- * Before Java 24, {@code java/lang/Class#getSigners} was declared as a native method, so we use
411
- * a native breakpoint to trace it. Either this breakpoint or the Java breakpoint will be set
412
- * (but not both).
413
- */
414
- @ CEntryPoint
415
- @ CEntryPointOptions (prologue = AgentIsolate .Prologue .class )
416
- static JNIObjectHandle nativeGetSigners (JNIEnvironment jni , JNIObjectHandle self ) {
417
- NativeBreakpoint breakpoint = NATIVE_GET_SIGNERS_BREAKPOINT_SPEC .installed ;
418
- VMError .guarantee (breakpoint != null && breakpoint .replacedFunction .isNonNull (), "incompletely installed" );
419
- GetSignersFunctionPointer original = (GetSignersFunctionPointer ) breakpoint .replacedFunction ;
420
- JNIObjectHandle result = original .invoke (jni , self );
421
- if (!Support .isInitialized ()) {
422
- return result ;
423
- }
424
- InterceptedState state = interceptedStateSupplier .get ();
425
- handleGetClassesWithReceiver (jni , self , breakpoint , state );
426
- return result ;
427
- }
428
-
429
395
private static boolean objectFieldOffsetByName (JNIEnvironment jni , JNIObjectHandle thread , Breakpoint bp , InterceptedState state ) {
430
396
JNIObjectHandle callerClass = state .getDirectCallerClass ();
431
397
JNIObjectHandle self = getReceiver (thread );
@@ -1360,13 +1326,17 @@ public static void onLoad(JvmtiEnv jvmti, JvmtiEventCallbacks callbacks, Tracer
1360
1326
BreakpointInterceptor .experimentalClassDefineSupport = exptlClassDefineSupport ;
1361
1327
BreakpointInterceptor .experimentalUnsafeAllocationSupport = exptlUnsafeAllocationSupport ;
1362
1328
BreakpointInterceptor .trackReflectionMetadata = trackReflectionData ;
1363
- BreakpointInterceptor .boundNativeMethods = new HashMap <>();
1364
1329
1365
1330
JvmtiCapabilities capabilities = UnmanagedMemory .calloc (SizeOf .get (JvmtiCapabilities .class ));
1366
1331
check (jvmti .getFunctions ().GetCapabilities ().invoke (jvmti , capabilities ));
1367
1332
capabilities .setCanGenerateBreakpointEvents (1 );
1368
1333
capabilities .setCanAccessLocalVariables (1 );
1369
- capabilities .setCanGenerateNativeMethodBindEvents (1 );
1334
+
1335
+ if (exptlUnsafeAllocationSupport ) {
1336
+ capabilities .setCanGenerateNativeMethodBindEvents (1 );
1337
+ callbacks .setNativeMethodBind (onNativeMethodBindLiteral .getFunctionPointer ());
1338
+ BreakpointInterceptor .boundNativeMethods = new HashMap <>();
1339
+ }
1370
1340
1371
1341
if (exptlClassLoaderSupport ) {
1372
1342
capabilities .setCanGetBytecodes (1 );
@@ -1378,10 +1348,8 @@ public static void onLoad(JvmtiEnv jvmti, JvmtiEventCallbacks callbacks, Tracer
1378
1348
}
1379
1349
check (jvmti .getFunctions ().AddCapabilities ().invoke (jvmti , capabilities ));
1380
1350
UnmanagedMemory .free (capabilities );
1381
- check (jvmti .getFunctions ().SetEventNotificationMode ().invoke (jvmti , JvmtiEventMode .JVMTI_ENABLE , JVMTI_EVENT_NATIVE_METHOD_BIND , nullHandle ()));
1382
1351
1383
1352
callbacks .setBreakpoint (onBreakpointLiteral .getFunctionPointer ());
1384
- callbacks .setNativeMethodBind (onNativeMethodBindLiteral .getFunctionPointer ());
1385
1353
1386
1354
if (exptlClassDefineSupport ) {
1387
1355
callbacks .setClassFileLoadHook (onClassFileLoadHookLiteral .getFunctionPointer ());
@@ -1391,6 +1359,9 @@ public static void onLoad(JvmtiEnv jvmti, JvmtiEventCallbacks callbacks, Tracer
1391
1359
callbacks .setClassPrepare (onClassPrepareLiteral .getFunctionPointer ());
1392
1360
}
1393
1361
1362
+ if (exptlUnsafeAllocationSupport ) {
1363
+ Support .check (jvmti .getFunctions ().SetEventNotificationMode ().invoke (jvmti , JvmtiEventMode .JVMTI_ENABLE , JVMTI_EVENT_NATIVE_METHOD_BIND , nullHandle ()));
1364
+ }
1394
1365
}
1395
1366
1396
1367
public static void onVMInit (JvmtiEnv jvmti , JNIEnvironment jni ) {
@@ -1441,7 +1412,9 @@ public static void onVMInit(JvmtiEnv jvmti, JNIEnvironment jni) {
1441
1412
}
1442
1413
installedBreakpoints = breakpoints ;
1443
1414
1444
- setupNativeBreakpoints (jni , lastClass , lastClassName );
1415
+ if (experimentalUnsafeAllocationSupport ) {
1416
+ setupNativeBreakpoints (jni , lastClass , lastClassName );
1417
+ }
1445
1418
1446
1419
if (experimentalClassDefineSupport ) {
1447
1420
setupClassLoadEvent (jvmti , jni );
@@ -1458,12 +1431,8 @@ private static void setupNativeBreakpoints(JNIEnvironment jni, JNIObjectHandle p
1458
1431
String lastClassName = previousClassName ;
1459
1432
nativeBreakpointsInitLock .lock ();
1460
1433
try {
1461
- List <NativeBreakpointSpecification > nativeBreakpointsList = new ArrayList <>(Arrays .asList (NATIVE_BREAKPOINT_SPECIFICATIONS ));
1462
- if (experimentalUnsafeAllocationSupport ) {
1463
- nativeBreakpointsList .addAll (Arrays .asList (EXPERIMENTAL_UNSAFE_ALLOCATION_NATIVE_BREAKPOINT_SPECIFICATIONS ));
1464
- }
1465
- nativeBreakpoints = new HashMap <>(nativeBreakpointsList .size ());
1466
- for (NativeBreakpointSpecification br : nativeBreakpointsList ) {
1434
+ nativeBreakpoints = new HashMap <>(NATIVE_BREAKPOINT_SPECIFICATIONS .length );
1435
+ for (NativeBreakpointSpecification br : NATIVE_BREAKPOINT_SPECIFICATIONS ) {
1467
1436
JNIObjectHandle clazz ;
1468
1437
if (lastClassName != null && lastClassName .equals (br .className )) {
1469
1438
clazz = lastClass ;
@@ -1477,8 +1446,7 @@ private static void setupNativeBreakpoints(JNIEnvironment jni, JNIObjectHandle p
1477
1446
NativeBreakpoint bp = new NativeBreakpoint (br , clazz , method );
1478
1447
nativeBreakpoints .put (method .rawValue (), bp );
1479
1448
Long original = boundNativeMethods .get (method .rawValue ());
1480
- // only bind a native breakpoint if method was bound as a native method
1481
- if (original != null ) {
1449
+ if (original != null ) { // already bound, replace
1482
1450
bindNativeBreakpoint (jni , bp , WordFactory .pointer (original ), nullPointer ());
1483
1451
}
1484
1452
}
@@ -1742,7 +1710,7 @@ private interface BreakpointHandler {
1742
1710
optionalBrk ("java/lang/Class" , "getNestMembers" , "()[Ljava/lang/Class;" ,
1743
1711
BreakpointInterceptor ::getNestMembers ),
1744
1712
optionalBrk ("java/lang/Class" , "getSigners" , "()[Ljava/lang/Object;" ,
1745
- BreakpointInterceptor ::getSigners ),
1713
+ BreakpointInterceptor ::getSigners )
1746
1714
};
1747
1715
1748
1716
private static boolean allocateInstance (JNIEnvironment jni , JNIObjectHandle thread , @ SuppressWarnings ("unused" ) Breakpoint bp , InterceptedState state ) {
@@ -1756,10 +1724,6 @@ private static boolean allocateInstance(JNIEnvironment jni, JNIObjectHandle thre
1756
1724
"(Ljava/lang/String;)Ljava/lang/Class;" , BreakpointInterceptor ::loadClass );
1757
1725
1758
1726
private static final NativeBreakpointSpecification [] NATIVE_BREAKPOINT_SPECIFICATIONS = {
1759
- NATIVE_GET_SIGNERS_BREAKPOINT_SPEC ,
1760
- };
1761
-
1762
- private static final NativeBreakpointSpecification [] EXPERIMENTAL_UNSAFE_ALLOCATION_NATIVE_BREAKPOINT_SPECIFICATIONS = {
1763
1727
NATIVE_ALLOCATE_INSTANCE_BREAKPOINT_SPEC
1764
1728
};
1765
1729
0 commit comments