@@ -299,84 +299,81 @@ public AnalysisMethod addRootMethod(Executable method, boolean invokeSpecial) {
299299 @ SuppressWarnings ("try" )
300300 public AnalysisMethod addRootMethod (AnalysisMethod aMethod , boolean invokeSpecial ) {
301301 assert !universe .sealed () : "Cannot register root methods after analysis universe is sealed." ;
302- try (Indent indent = debug .logAndIndent ("add root method %s" , aMethod .getName ())) {
302+ AnalysisType declaringClass = aMethod .getDeclaringClass ();
303+ boolean isStatic = aMethod .isStatic ();
304+ WrappedSignature signature = aMethod .getSignature ();
305+ int paramCount = signature .getParameterCount (!isStatic );
306+ PointsToAnalysisMethod pointsToMethod = assertPointsToAnalysisMethod (aMethod );
303307
304- AnalysisType declaringClass = aMethod .getDeclaringClass ();
305- boolean isStatic = aMethod .isStatic ();
306- WrappedSignature signature = aMethod .getSignature ();
307- int paramCount = signature .getParameterCount (!isStatic );
308- PointsToAnalysisMethod pointsToMethod = assertPointsToAnalysisMethod (aMethod );
309-
310- if (isStatic ) {
311- /*
312- * For static methods trigger analysis in the empty context. This will trigger
313- * parsing and return the method flows graph. Then the method parameter type flows
314- * are initialized with the corresponding parameter declared type.
315- */
316- postTask (() -> {
317- pointsToMethod .registerAsDirectRootMethod ();
318- pointsToMethod .registerAsImplementationInvoked (null );
319- MethodFlowsGraph methodFlowsGraph = analysisPolicy .staticRootMethodGraph (this , pointsToMethod );
320- for (int idx = 0 ; idx < paramCount ; idx ++) {
321- AnalysisType declaredParamType = (AnalysisType ) signature .getParameterType (idx , declaringClass );
322- FormalParamTypeFlow parameter = methodFlowsGraph .getParameter (idx );
323- if (declaredParamType .getJavaKind () == JavaKind .Object && parameter != null ) {
324- TypeFlow <?> initialParameterFlow = declaredParamType .getTypeFlow (this , true );
325- initialParameterFlow .addUse (this , parameter );
326- }
308+ if (isStatic ) {
309+ /*
310+ * For static methods trigger analysis in the empty context. This will trigger parsing
311+ * and return the method flows graph. Then the method parameter type flows are
312+ * initialized with the corresponding parameter declared type.
313+ */
314+ postTask (() -> {
315+ pointsToMethod .registerAsDirectRootMethod ();
316+ pointsToMethod .registerAsImplementationInvoked (null );
317+ MethodFlowsGraph methodFlowsGraph = analysisPolicy .staticRootMethodGraph (this , pointsToMethod );
318+ for (int idx = 0 ; idx < paramCount ; idx ++) {
319+ AnalysisType declaredParamType = (AnalysisType ) signature .getParameterType (idx , declaringClass );
320+ FormalParamTypeFlow parameter = methodFlowsGraph .getParameter (idx );
321+ if (declaredParamType .getJavaKind () == JavaKind .Object && parameter != null ) {
322+ TypeFlow <?> initialParameterFlow = declaredParamType .getTypeFlow (this , true );
323+ initialParameterFlow .addUse (this , parameter );
327324 }
328- });
329- } else {
330- if (invokeSpecial && pointsToMethod .isAbstract ()) {
331- throw AnalysisError .userError ("Abstract methods cannot be registered as special invoke entry point." );
332325 }
326+ });
327+ } else {
328+ if (invokeSpecial && pointsToMethod .isAbstract ()) {
329+ throw AnalysisError .userError ("Abstract methods cannot be registered as special invoke entry point." );
330+ }
331+ /*
332+ * For special invoked methods trigger method resolution by using the
333+ * context-insensitive special invoke type flow. This will resolve the method in its
334+ * declaring class when the declaring class is instantiated.
335+ *
336+ * For virtual methods trigger method resolution by using the context-insensitive
337+ * virtual invoke type flow. Since the virtual invoke observes the receiver flow state
338+ * it will get notified for any future reachable subtypes and will resolve the method in
339+ * each subtype.
340+ *
341+ * In both cases the context-insensitive invoke parameters are initialized with the
342+ * corresponding declared type state. When a callee is resolved the method is parsed and
343+ * the actual parameter type state is propagated to the formal parameters. Then the
344+ * callee is linked and registered as implementation-invoked.
345+ */
346+ postTask (() -> {
347+ if (invokeSpecial ) {
348+ pointsToMethod .registerAsDirectRootMethod ();
349+ } else {
350+ pointsToMethod .registerAsVirtualRootMethod ();
351+ }
352+ InvokeTypeFlow invoke = pointsToMethod .initAndGetContextInsensitiveInvoke (PointsToAnalysis .this , null , invokeSpecial );
333353 /*
334- * For special invoked methods trigger method resolution by using the
335- * context-insensitive special invoke type flow. This will resolve the method in its
336- * declaring class when the declaring class is instantiated.
337- *
338- * For virtual methods trigger method resolution by using the context-insensitive
339- * virtual invoke type flow. Since the virtual invoke observes the receiver flow
340- * state it will get notified for any future reachable subtypes and will resolve the
341- * method in each subtype.
354+ * Initialize the type flow of the invoke's actual parameters with the corresponding
355+ * parameter declared type. Thus, when the invoke links callees it will propagate
356+ * the parameter types too.
342357 *
343- * In both cases the context-insensitive invoke parameters are initialized with the
344- * corresponding declared type state. When a callee is resolved the method is parsed
345- * and the actual parameter type state is propagated to the formal parameters. Then
346- * the callee is linked and registered as implementation-invoked.
358+ * The parameter iteration skips the primitive parameters, as these are not modeled.
359+ * The type flow of the receiver is set to the receiver type already when the invoke
360+ * is created.
347361 */
348- postTask (() -> {
349- if (invokeSpecial ) {
350- pointsToMethod .registerAsDirectRootMethod ();
351- } else {
352- pointsToMethod .registerAsVirtualRootMethod ();
353- }
354- InvokeTypeFlow invoke = pointsToMethod .initAndGetContextInsensitiveInvoke (PointsToAnalysis .this , null , invokeSpecial );
362+ for (int idx = 1 ; idx < paramCount ; idx ++) {
355363 /*
356- * Initialize the type flow of the invoke's actual parameters with the
357- * corresponding parameter declared type. Thus, when the invoke links callees it
358- * will propagate the parameter types too.
359- *
360- * The parameter iteration skips the primitive parameters, as these are not
361- * modeled. The type flow of the receiver is set to the receiver type already
362- * when the invoke is created.
364+ * Note: the Signature doesn't count the receiver of a virtual invoke as a
365+ * parameter whereas the MethodTypeFlow does, hence when accessing the parameter
366+ * type below we use idx-1 but when accessing the actual parameter flow we
367+ * simply use idx.
363368 */
364- for (int idx = 1 ; idx < paramCount ; idx ++) {
365- /*
366- * Note: the Signature doesn't count the receiver of a virtual invoke as a
367- * parameter whereas the MethodTypeFlow does, hence when accessing the
368- * parameter type below we use idx-1 but when accessing the actual parameter
369- * flow we simply use idx.
370- */
371- AnalysisType declaredParamType = (AnalysisType ) signature .getParameterType (idx - 1 , declaringClass );
372- TypeFlow <?> actualParameterFlow = invoke .getActualParameter (idx );
373- if (declaredParamType .getJavaKind () == JavaKind .Object && actualParameterFlow != null ) {
374- TypeFlow <?> initialParameterFlow = declaredParamType .getTypeFlow (this , true );
375- initialParameterFlow .addUse (this , actualParameterFlow );
376- }
369+ AnalysisType declaredParamType = (AnalysisType ) signature .getParameterType (idx - 1 , declaringClass );
370+ TypeFlow <?> actualParameterFlow = invoke .getActualParameter (idx );
371+ if (declaredParamType .getJavaKind () == JavaKind .Object && actualParameterFlow != null ) {
372+ TypeFlow <?> initialParameterFlow = declaredParamType .getTypeFlow (this , true );
373+ initialParameterFlow .addUse (this , actualParameterFlow );
377374 }
378- });
379- }
375+ }
376+ });
380377 }
381378 return aMethod ;
382379
@@ -397,24 +394,22 @@ public AnalysisType addRootClass(Class<?> clazz, boolean addFields, boolean addA
397394 @ SuppressWarnings ({"try" })
398395 @ Override
399396 public AnalysisType addRootClass (AnalysisType type , boolean addFields , boolean addArrayClass ) {
400- try (Indent indent = debug .logAndIndent ("add root class %s" , type .getName ())) {
401- for (AnalysisField field : type .getInstanceFields (false )) {
402- if (addFields ) {
403- field .registerAsAccessed ();
404- }
405- /*
406- * For system classes any instantiated (sub)type of the declared field type can be
407- * written to the field flow.
408- */
409- TypeFlow <?> fieldDeclaredTypeFlow = field .getType ().getTypeFlow (this , true );
410- fieldDeclaredTypeFlow .addUse (this , type .getContextInsensitiveAnalysisObject ().getInstanceFieldFlow (this , field , true ));
411- }
412- if (type .getSuperclass () != null ) {
413- addRootClass (type .getSuperclass (), addFields , addArrayClass );
414- }
415- if (addArrayClass ) {
416- addRootClass (type .getArrayClass (), false , false );
397+ for (AnalysisField field : type .getInstanceFields (false )) {
398+ if (addFields ) {
399+ field .registerAsAccessed ();
417400 }
401+ /*
402+ * For system classes any instantiated (sub)type of the declared field type can be
403+ * written to the field flow.
404+ */
405+ TypeFlow <?> fieldDeclaredTypeFlow = field .getType ().getTypeFlow (this , true );
406+ fieldDeclaredTypeFlow .addUse (this , type .getContextInsensitiveAnalysisObject ().getInstanceFieldFlow (this , field , true ));
407+ }
408+ if (type .getSuperclass () != null ) {
409+ addRootClass (type .getSuperclass (), addFields , addArrayClass );
410+ }
411+ if (addArrayClass ) {
412+ addRootClass (type .getArrayClass (), false , false );
418413 }
419414 return type ;
420415 }
@@ -425,15 +420,13 @@ public AnalysisType addRootField(Class<?> clazz, String fieldName) {
425420 AnalysisType type = addRootClass (clazz , false , false );
426421 for (AnalysisField field : type .getInstanceFields (true )) {
427422 if (field .getName ().equals (fieldName )) {
428- try (Indent indent = debug .logAndIndent ("add root field %s in class %s" , fieldName , clazz .getName ())) {
429- field .registerAsAccessed ();
430- /*
431- * For system classes any instantiated (sub)type of the declared field type can
432- * be written to the field flow.
433- */
434- TypeFlow <?> fieldDeclaredTypeFlow = field .getType ().getTypeFlow (this , true );
435- fieldDeclaredTypeFlow .addUse (this , type .getContextInsensitiveAnalysisObject ().getInstanceFieldFlow (this , field , true ));
436- }
423+ field .registerAsAccessed ();
424+ /*
425+ * For system classes any instantiated (sub)type of the declared field type can be
426+ * written to the field flow.
427+ */
428+ TypeFlow <?> fieldDeclaredTypeFlow = field .getType ().getTypeFlow (this , true );
429+ fieldDeclaredTypeFlow .addUse (this , type .getContextInsensitiveAnalysisObject ().getInstanceFieldFlow (this , field , true ));
437430 return field .getType ();
438431 }
439432 }
@@ -445,14 +438,12 @@ public AnalysisType addRootStaticField(Class<?> clazz, String fieldName) {
445438 addRootClass (clazz , false , false );
446439 Field reflectField ;
447440 try {
448- try (Indent indent = debug .logAndIndent ("add system static field %s in class %s" , fieldName , clazz .getName ())) {
449- reflectField = clazz .getField (fieldName );
450- AnalysisField field = metaAccess .lookupJavaField (reflectField );
451- field .registerAsAccessed ();
452- TypeFlow <?> fieldFlow = field .getType ().getTypeFlow (this , true );
453- fieldFlow .addUse (this , field .getStaticFieldFlow ());
454- return field .getType ();
455- }
441+ reflectField = clazz .getField (fieldName );
442+ AnalysisField field = metaAccess .lookupJavaField (reflectField );
443+ field .registerAsAccessed ();
444+ TypeFlow <?> fieldFlow = field .getType ().getTypeFlow (this , true );
445+ fieldFlow .addUse (this , field .getStaticFieldFlow ());
446+ return field .getType ();
456447 } catch (NoSuchFieldException e ) {
457448 throw shouldNotReachHere ("field not found: " + fieldName );
458449 }
0 commit comments