60
60
*/
61
61
public final class EventInstrumentation {
62
62
63
- record SettingInfo (String fieldName , int index , Type paramType , String methodName , SettingControl settingControl ) {
64
- /**
65
- * A malicious user must never be able to run a callback in the wrong
66
- * context. Methods on SettingControl must therefore never be invoked directly
67
- * by JFR, instead use jdk.jfr.internal.Control.
68
- */
69
- public SettingControl settingControl () {
70
- return this .settingControl ;
71
- }
63
+ record SettingInfo (Type paramType , String methodName ) {
72
64
}
73
65
74
- record FieldInfo (String fieldName , String fieldDescriptor , String internalClassName ) {
66
+ record FieldInfo (String name , String descriptor ) {
75
67
}
76
68
77
69
public static final String FIELD_EVENT_THREAD = "eventThread" ;
@@ -136,8 +128,8 @@ record FieldInfo(String fieldName, String fieldDescriptor, String internalClassN
136
128
public static Method findStaticCommitMethod (ClassNode classNode , List <FieldInfo > fields ) {
137
129
StringBuilder sb = new StringBuilder ();
138
130
sb .append ("(" );
139
- for (FieldInfo v : fields ) {
140
- sb .append (v . fieldDescriptor );
131
+ for (FieldInfo field : fields ) {
132
+ sb .append (field . descriptor );
141
133
}
142
134
sb .append (")V" );
143
135
Method m = new Method ("commit" , sb .toString ());
@@ -244,10 +236,8 @@ private static List<SettingInfo> buildSettingInfos(Class<?> superClass, ClassNod
244
236
Type [] args = Type .getArgumentTypes (m .desc );
245
237
if (args .length == 1 ) {
246
238
Type paramType = args [0 ];
247
- String fieldName = EventControl .FIELD_SETTING_PREFIX + settingInfos .size ();
248
- int index = settingInfos .size ();
249
239
methodSet .add (m .name );
250
- settingInfos .add (new SettingInfo (fieldName , index , paramType , m .name , null ));
240
+ settingInfos .add (new SettingInfo (paramType , m .name ));
251
241
}
252
242
}
253
243
}
@@ -263,10 +253,8 @@ private static List<SettingInfo> buildSettingInfos(Class<?> superClass, ClassNod
263
253
if (method .getParameterCount () == 1 ) {
264
254
Parameter param = method .getParameters ()[0 ];
265
255
Type paramType = Type .getType (param .getType ());
266
- String fieldName = EventControl .FIELD_SETTING_PREFIX + settingInfos .size ();
267
- int index = settingInfos .size ();
268
256
methodSet .add (method .getName ());
269
- settingInfos .add (new SettingInfo (fieldName , index , paramType , method .getName (), null ));
257
+ settingInfos .add (new SettingInfo (paramType , method .getName ()));
270
258
}
271
259
}
272
260
}
@@ -285,11 +273,11 @@ private static List<FieldInfo> buildFieldInfos(Class<?> superClass, ClassNode cl
285
273
// control in which order they occur and we can add @Name, @Description
286
274
// in Java, instead of in native. It also means code for adding implicit
287
275
// fields for native can be reused by Java.
288
- fieldInfos .add (new FieldInfo ("startTime" , Type .LONG_TYPE .getDescriptor (), classNode . name ));
289
- fieldInfos .add (new FieldInfo ("duration" , Type .LONG_TYPE .getDescriptor (), classNode . name ));
276
+ fieldInfos .add (new FieldInfo ("startTime" , Type .LONG_TYPE .getDescriptor ()));
277
+ fieldInfos .add (new FieldInfo ("duration" , Type .LONG_TYPE .getDescriptor ()));
290
278
for (FieldNode field : classNode .fields ) {
291
279
if (!fieldSet .contains (field .name ) && isValidField (field .access , Type .getType (field .desc ).getClassName ())) {
292
- FieldInfo fi = new FieldInfo (field .name , field .desc , classNode . name );
280
+ FieldInfo fi = new FieldInfo (field .name , field .desc );
293
281
fieldInfos .add (fi );
294
282
fieldSet .add (field .name );
295
283
}
@@ -303,7 +291,7 @@ private static List<FieldInfo> buildFieldInfos(Class<?> superClass, ClassNode cl
303
291
if (!fieldSet .contains (fieldName )) {
304
292
Type fieldType = Type .getType (field .getType ());
305
293
String internalClassName = ASMToolkit .getInternalName (c .getName ());
306
- fieldInfos .add (new FieldInfo (fieldName , fieldType .getDescriptor (), internalClassName ));
294
+ fieldInfos .add (new FieldInfo (fieldName , fieldType .getDescriptor ()));
307
295
fieldSet .add (fieldName );
308
296
}
309
297
}
@@ -574,7 +562,7 @@ private void makeInstrumented() {
574
562
// stack: [EW] [EW]
575
563
methodVisitor .visitVarInsn (Opcodes .ALOAD , 0 );
576
564
// stack: [EW] [EW] [this]
577
- methodVisitor .visitFieldInsn (Opcodes .GETFIELD , getInternalClassName (), field .fieldName , field .fieldDescriptor );
565
+ methodVisitor .visitFieldInsn (Opcodes .GETFIELD , getInternalClassName (), field .name , field .descriptor );
578
566
// stack: [EW] [EW] <T>
579
567
EventWriterMethod eventMethod = EventWriterMethod .lookupMethod (field );
580
568
invokeVirtual (methodVisitor , TYPE_EVENT_WRITER , eventMethod .asmMethod );
@@ -633,8 +621,8 @@ private void makeInstrumented() {
633
621
methodVisitor .visitFieldInsn (Opcodes .GETFIELD , getInternalClassName (), FIELD_DURATION , "J" );
634
622
invokeVirtual (methodVisitor , TYPE_EVENT_CONFIGURATION , METHOD_EVENT_CONFIGURATION_SHOULD_COMMIT );
635
623
methodVisitor .visitJumpInsn (Opcodes .IFEQ , fail );
636
- int index = 0 ;
637
- for ( SettingInfo si : settingInfos ) {
624
+ for ( int index = 0 ; index < settingInfos . size (); index ++) {
625
+ SettingInfo si = settingInfos . get ( index );
638
626
// if (!settingsMethod(eventConfiguration.settingX)) goto fail;
639
627
methodVisitor .visitIntInsn (Opcodes .ALOAD , 0 );
640
628
if (untypedEventConfiguration ) {
@@ -648,7 +636,6 @@ private void makeInstrumented() {
648
636
methodVisitor .visitTypeInsn (Opcodes .CHECKCAST , si .paramType ().getInternalName ());
649
637
methodVisitor .visitMethodInsn (Opcodes .INVOKEVIRTUAL , getInternalClassName (), si .methodName , "(" + si .paramType ().getDescriptor () + ")Z" , false );
650
638
methodVisitor .visitJumpInsn (Opcodes .IFEQ , fail );
651
- index ++;
652
639
}
653
640
// return true
654
641
methodVisitor .visitInsn (Opcodes .ICONST_1 );
0 commit comments