3131import static org .graalvm .compiler .replacements .StandardGraphBuilderPlugins .registerInvocationPlugins ;
3232
3333import java .io .IOException ;
34+ import java .io .PrintWriter ;
3435import java .lang .annotation .Annotation ;
3536import java .lang .reflect .Method ;
3637import java .lang .reflect .Modifier ;
5556import java .util .concurrent .atomic .AtomicBoolean ;
5657import java .util .function .BooleanSupplier ;
5758
59+ import com .oracle .graal .pointsto .reports .ReportUtils ;
5860import org .graalvm .collections .EconomicMap ;
5961import org .graalvm .collections .EconomicSet ;
6062import org .graalvm .collections .MapCursor ;
@@ -1735,63 +1737,70 @@ public Map<ArtifactType, List<Path>> getBuildArtifacts() {
17351737 }
17361738
17371739 private void printTypes () {
1740+ String reportsPath = SubstrateOptions .reportsPath ();
1741+ ReportUtils .report ("print types" , reportsPath , "universe_analysis" , "txt" ,
1742+ writer -> printTypes (writer ));
1743+ }
1744+
1745+ private void printTypes (PrintWriter writer ) {
1746+
17381747 for (HostedType type : hUniverse .getTypes ()) {
1739- System . out .format ("%8d %s " , type .getTypeID (), type .toJavaName (true ));
1748+ writer .format ("%8d %s " , type .getTypeID (), type .toJavaName (true ));
17401749 if (type .getSuperclass () != null ) {
1741- System . out .format ("extends %d %s " , type .getSuperclass ().getTypeID (), type .getSuperclass ().toJavaName (false ));
1750+ writer .format ("extends %d %s " , type .getSuperclass ().getTypeID (), type .getSuperclass ().toJavaName (false ));
17421751 }
17431752 if (type .getInterfaces ().length > 0 ) {
1744- System . out .print ("implements " );
1753+ writer .print ("implements " );
17451754 String sep = "" ;
17461755 for (HostedInterface interf : type .getInterfaces ()) {
1747- System . out .format ("%s%d %s" , sep , interf .getTypeID (), interf .toJavaName (false ));
1756+ writer .format ("%s%d %s" , sep , interf .getTypeID (), interf .toJavaName (false ));
17481757 sep = ", " ;
17491758 }
1750- System . out .print (" " );
1759+ writer .print (" " );
17511760 }
17521761
17531762 if (type .getWrapped ().isInstantiated ()) {
1754- System . out .print ("instantiated " );
1763+ writer .print ("instantiated " );
17551764 }
17561765 if (type .getWrapped ().isReachable ()) {
1757- System . out .print ("reachable " );
1766+ writer .print ("reachable " );
17581767 }
17591768
1760- System . out .format ("type check start %d range %d slot # %d " , type .getTypeCheckStart (), type .getTypeCheckRange (), type .getTypeCheckSlot ());
1761- System . out .format ("type check slots %s " , slotsToString (type .getTypeCheckSlots ()));
1769+ writer .format ("type check start %d range %d slot # %d " , type .getTypeCheckStart (), type .getTypeCheckRange (), type .getTypeCheckSlot ());
1770+ writer .format ("type check slots %s " , slotsToString (type .getTypeCheckSlots ()));
17621771 // if (type.findLeafConcreteSubtype() != null) {
1763- // System.out .format("unique %d %s ", type.findLeafConcreteSubtype().getTypeID(),
1772+ // writer .format("unique %d %s ", type.findLeafConcreteSubtype().getTypeID(),
17641773 // type.findLeafConcreteSubtype().toJavaName(false));
17651774 // }
17661775
17671776 int le = type .getHub ().getLayoutEncoding ();
17681777 if (LayoutEncoding .isPrimitive (le )) {
1769- System . out .print ("primitive " );
1778+ writer .print ("primitive " );
17701779 } else if (LayoutEncoding .isInterface (le )) {
1771- System . out .print ("interface " );
1780+ writer .print ("interface " );
17721781 } else if (LayoutEncoding .isAbstract (le )) {
1773- System . out .print ("abstract " );
1782+ writer .print ("abstract " );
17741783 } else if (LayoutEncoding .isPureInstance (le )) {
1775- System . out .format ("instance size %d " , LayoutEncoding .getPureInstanceAllocationSize (le ).rawValue ());
1784+ writer .format ("instance size %d " , LayoutEncoding .getPureInstanceAllocationSize (le ).rawValue ());
17761785 } else if (LayoutEncoding .isArrayLike (le )) {
17771786 String arrayType = LayoutEncoding .isHybrid (le ) ? "hybrid" : "array" ;
17781787 String elements = LayoutEncoding .isArrayLikeWithPrimitiveElements (le ) ? "primitives" : "objects" ;
1779- System . out .format ("%s containing %s, base %d shift %d scale %d " , arrayType , elements , LayoutEncoding .getArrayBaseOffset (le ).rawValue (), LayoutEncoding .getArrayIndexShift (le ),
1788+ writer .format ("%s containing %s, base %d shift %d scale %d " , arrayType , elements , LayoutEncoding .getArrayBaseOffset (le ).rawValue (), LayoutEncoding .getArrayIndexShift (le ),
17801789 LayoutEncoding .getArrayIndexScale (le ));
17811790
17821791 } else {
17831792 throw VMError .shouldNotReachHereUnexpectedInput (le ); // ExcludeFromJacocoGeneratedReport
17841793 }
17851794
1786- System . out .println ();
1795+ writer .println ();
17871796
17881797 for (HostedType sub : type .getSubTypes ()) {
1789- System . out .format (" s %d %s%n" , sub .getTypeID (), sub .toJavaName (false ));
1798+ writer .format (" s %d %s%n" , sub .getTypeID (), sub .toJavaName (false ));
17901799 }
17911800 if (type .isInterface ()) {
17921801 for (HostedMethod method : hUniverse .getMethods ()) {
17931802 if (method .getDeclaringClass ().equals (type )) {
1794- printMethod (method , -1 );
1803+ printMethod (writer , method , -1 );
17951804 }
17961805 }
17971806
@@ -1801,41 +1810,42 @@ private void printTypes() {
18011810 fields = Arrays .copyOf (fields , fields .length );
18021811 Arrays .sort (fields , Comparator .comparing (HostedField ::toString ));
18031812 for (HostedField field : fields ) {
1804- System . out .println (" f " + field .getLocation () + ": " + field .format ("%T %n" ));
1813+ writer .println (" f " + field .getLocation () + ": " + field .format ("%T %n" ));
18051814 }
18061815 HostedMethod [] vtable = type .getVTable ();
18071816 for (int i = 0 ; i < vtable .length ; i ++) {
18081817 if (vtable [i ] != null ) {
1809- printMethod (vtable [i ], i );
1818+ printMethod (writer , vtable [i ], i );
18101819 }
18111820 }
18121821 for (HostedMethod method : hUniverse .getMethods ()) {
18131822 if (method .getDeclaringClass ().equals (type ) && !method .hasVTableIndex ()) {
1814- printMethod (method , -1 );
1823+ printMethod (writer , method , -1 );
18151824 }
18161825 }
18171826 }
18181827 }
1828+
18191829 }
18201830
1821- private static void printMethod (HostedMethod method , int vtableIndex ) {
1831+ private static void printMethod (PrintWriter writer , HostedMethod method , int vtableIndex ) {
18221832 if (vtableIndex != -1 ) {
1823- System . out .print (" v " + vtableIndex + " " );
1833+ writer .print (" v " + vtableIndex + " " );
18241834 } else {
1825- System . out .print (" m " );
1835+ writer .print (" m " );
18261836 }
18271837 if (method .hasVTableIndex ()) {
1828- System . out .print (method .getVTableIndex () + " " );
1838+ writer .print (method .getVTableIndex () + " " );
18291839 }
1830- System . out .print (method .format ("%r %n(%p)" ) + ": " + method .getImplementations ().length + " [" );
1840+ writer .print (method .format ("%r %n(%p)" ) + ": " + method .getImplementations ().length + " [" );
18311841 if (method .getImplementations ().length <= 10 ) {
18321842 String sep = "" ;
18331843 for (HostedMethod impl : method .getImplementations ()) {
1834- System . out .print (sep + impl .getDeclaringClass ().toJavaName (false ));
1844+ writer .print (sep + impl .getDeclaringClass ().toJavaName (false ));
18351845 sep = ", " ;
18361846 }
18371847 }
1838- System . out .println ("]" );
1848+ writer .println ("]" );
18391849 }
18401850
18411851 private static String slotsToString (short [] slots ) {
0 commit comments