< prev index next >

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/HeapHprofBinWriter.java

Print this page




 569             (currentRecordLength + headerSize + originalLengthInBytes) > MAX_U4_VALUE) {
 570             fillInHeapRecordLength();
 571             currentSegmentStart = 0;
 572             writeHeapRecordPrologue();
 573             currentRecordLength = 0;
 574         }
 575 
 576         // Calculate the max bytes we can use.
 577         long maxBytes = (MAX_U4_VALUE - (headerSize + currentRecordLength));
 578 
 579         if (originalLengthInBytes > maxBytes) {
 580             length = maxBytes/typeSize;
 581             System.err.println("WARNING: Cannot dump array of type " + typeName
 582                                + " with length " + originalArrayLength
 583                                + "; truncating to length " + length);
 584         }
 585         return (int) length;
 586     }
 587 
 588     private void writeClassDumpRecords() throws IOException {
 589         SystemDictionary sysDict = VM.getVM().getSystemDictionary();
 590         ClassLoaderDataGraph cldGraph = VM.getVM().getClassLoaderDataGraph();
 591         try {
 592             sysDict.allClassesDo(new SystemDictionary.ClassVisitor() {
 593                             public void visit(Klass k) {
 594                                 try {
 595                                     writeHeapRecordPrologue();
 596                                     writeClassDumpRecord(k);
 597                                     writeHeapRecordEpilogue();
 598                                 } catch (IOException e) {
 599                                     throw new RuntimeException(e);
 600                                 }
 601                             }
 602                         });
 603              // Add the anonymous classes also which are not present in the
 604              // System Dictionary
 605              cldGraph.allAnonymousKlassesDo(new ClassLoaderDataGraph.KlassVisitor() {
 606                             public void visit(Klass k) {
 607                                 try {
 608                                     writeHeapRecordPrologue();
 609                                     writeClassDumpRecord(k);
 610                                     writeHeapRecordEpilogue();
 611                                 } catch (IOException e) {
 612                                     throw new RuntimeException(e);
 613                                 }
 614                             }
 615                         });
 616         } catch (RuntimeException re) {
 617             handleRuntimeException(re);
 618         }
 619     }
 620 
 621     protected void writeClass(Instance instance) throws IOException {
 622         Klass reflectedKlass = java_lang_Class.asKlass(instance);
 623         // dump instance record only for primitive type Class objects.
 624         // all other Class objects are covered by writeClassDumpRecords.
 625         if (reflectedKlass == null) {


1071                             writeSymbol(sym);
1072                         } catch (IOException exp) {
1073                             throw new RuntimeException(exp);
1074                         }
1075                     }
1076                 });
1077         } catch (RuntimeException re) {
1078             handleRuntimeException(re);
1079         }
1080     }
1081 
1082     private void writeSymbol(Symbol sym) throws IOException {
1083         byte[] buf = sym.asString().getBytes("UTF-8");
1084         writeHeader(HPROF_UTF8, buf.length + OBJ_ID_SIZE);
1085         writeSymbolID(sym);
1086         out.write(buf);
1087     }
1088 
1089     private void writeClasses() throws IOException {
1090         // write class list (id, name) association
1091         SystemDictionary sysDict = VM.getVM().getSystemDictionary();
1092         ClassLoaderDataGraph cldGraph = VM.getVM().getClassLoaderDataGraph();
1093         try {
1094             sysDict.allClassesDo(new SystemDictionary.ClassVisitor() {
1095                 public void visit(Klass k) {
1096                     try {
1097                         Instance clazz = k.getJavaMirror();
1098                         writeHeader(HPROF_LOAD_CLASS, 2 * (OBJ_ID_SIZE + 4));
1099                         out.writeInt(serialNum);
1100                         writeObjectID(clazz);
1101                         KlassMap.add(serialNum - 1, k);
1102                         out.writeInt(DUMMY_STACK_TRACE_ID);
1103                         writeSymbolID(k.getName());
1104                         serialNum++;
1105                     } catch (IOException exp) {
1106                         throw new RuntimeException(exp);
1107                     }
1108                 }
1109             });
1110             cldGraph.allAnonymousKlassesDo(new ClassLoaderDataGraph.KlassVisitor() {
1111                 public void visit(Klass k) {
1112                     try {
1113                         Instance clazz = k.getJavaMirror();
1114                         writeHeader(HPROF_LOAD_CLASS, 2 * (OBJ_ID_SIZE + 4));
1115                         out.writeInt(serialNum);
1116                         writeObjectID(clazz);
1117                         KlassMap.add(serialNum - 1, k);
1118                         out.writeInt(DUMMY_STACK_TRACE_ID);
1119                         writeSymbolID(k.getName());
1120                         serialNum++;
1121                     } catch (IOException exp) {
1122                         throw new RuntimeException(exp);
1123                     }
1124                 }
1125             });
1126         } catch (RuntimeException re) {
1127             handleRuntimeException(re);
1128         }
1129     }
1130 




 569             (currentRecordLength + headerSize + originalLengthInBytes) > MAX_U4_VALUE) {
 570             fillInHeapRecordLength();
 571             currentSegmentStart = 0;
 572             writeHeapRecordPrologue();
 573             currentRecordLength = 0;
 574         }
 575 
 576         // Calculate the max bytes we can use.
 577         long maxBytes = (MAX_U4_VALUE - (headerSize + currentRecordLength));
 578 
 579         if (originalLengthInBytes > maxBytes) {
 580             length = maxBytes/typeSize;
 581             System.err.println("WARNING: Cannot dump array of type " + typeName
 582                                + " with length " + originalArrayLength
 583                                + "; truncating to length " + length);
 584         }
 585         return (int) length;
 586     }
 587 
 588     private void writeClassDumpRecords() throws IOException {

 589         ClassLoaderDataGraph cldGraph = VM.getVM().getClassLoaderDataGraph();
 590         try {
 591              cldGraph.classesDo(new ClassLoaderDataGraph.ClassVisitor() {













 592                             public void visit(Klass k) {
 593                                 try {
 594                                     writeHeapRecordPrologue();
 595                                     writeClassDumpRecord(k);
 596                                     writeHeapRecordEpilogue();
 597                                 } catch (IOException e) {
 598                                     throw new RuntimeException(e);
 599                                 }
 600                             }
 601                         });
 602         } catch (RuntimeException re) {
 603             handleRuntimeException(re);
 604         }
 605     }
 606 
 607     protected void writeClass(Instance instance) throws IOException {
 608         Klass reflectedKlass = java_lang_Class.asKlass(instance);
 609         // dump instance record only for primitive type Class objects.
 610         // all other Class objects are covered by writeClassDumpRecords.
 611         if (reflectedKlass == null) {


1057                             writeSymbol(sym);
1058                         } catch (IOException exp) {
1059                             throw new RuntimeException(exp);
1060                         }
1061                     }
1062                 });
1063         } catch (RuntimeException re) {
1064             handleRuntimeException(re);
1065         }
1066     }
1067 
1068     private void writeSymbol(Symbol sym) throws IOException {
1069         byte[] buf = sym.asString().getBytes("UTF-8");
1070         writeHeader(HPROF_UTF8, buf.length + OBJ_ID_SIZE);
1071         writeSymbolID(sym);
1072         out.write(buf);
1073     }
1074 
1075     private void writeClasses() throws IOException {
1076         // write class list (id, name) association

1077         ClassLoaderDataGraph cldGraph = VM.getVM().getClassLoaderDataGraph();
1078         try {
1079             cldGraph.classesDo(new ClassLoaderDataGraph.ClassVisitor() {
















1080                 public void visit(Klass k) {
1081                     try {
1082                         Instance clazz = k.getJavaMirror();
1083                         writeHeader(HPROF_LOAD_CLASS, 2 * (OBJ_ID_SIZE + 4));
1084                         out.writeInt(serialNum);
1085                         writeObjectID(clazz);
1086                         KlassMap.add(serialNum - 1, k);
1087                         out.writeInt(DUMMY_STACK_TRACE_ID);
1088                         writeSymbolID(k.getName());
1089                         serialNum++;
1090                     } catch (IOException exp) {
1091                         throw new RuntimeException(exp);
1092                     }
1093                 }
1094             });
1095         } catch (RuntimeException re) {
1096             handleRuntimeException(re);
1097         }
1098     }
1099 


< prev index next >