/*.................................................................................................................*/
 public Snapshot getSnapshot(MesquiteFile file) {
   Snapshot temp = new Snapshot();
   temp.addLine("setRunningFilePath " + ParseUtil.tokenize(runningFilePath));
   if (outputFilePaths != null) {
     String files = " ";
     for (int i = 0; i < outputFilePaths.length; i++) {
       files += " " + ParseUtil.tokenize(outputFilePaths[i]);
     }
     temp.addLine("setOutputFilePaths " + files);
   }
   return temp;
 }
Esempio n. 2
0
 //
 // Handle a HPROF_GC_INSTANCE_DUMP
 // Return number of bytes read
 //
 private int readInstance() throws IOException {
   long start = in.position();
   long id = readID();
   StackTrace stackTrace = getStackTraceFromSerial(in.readInt());
   long classID = readID();
   int bytesFollowing = in.readInt();
   int bytesRead = (2 * identifierSize) + 8 + bytesFollowing;
   JavaObject jobj = new JavaObject(classID, start);
   skipBytes(bytesFollowing);
   snapshot.addHeapObject(id, jobj);
   snapshot.setSiteTrace(jobj, stackTrace);
   return bytesRead;
 }
Esempio n. 3
0
 private void handleEOF(EOFException exp, Snapshot snapshot) {
   if (debugLevel > 0) {
     exp.printStackTrace();
   }
   warn("Unexpected EOF. Will miss information...");
   // we have EOF, we have to tolerate missing references
   snapshot.setUnresolvedObjectsOK(true);
 }
Esempio n. 4
0
  //
  // Handle a HPROF_GC_OBJ_ARRAY_DUMP or HPROF_GC_PRIM_ARRAY_DUMP
  // Return number of bytes read
  //
  private int readArray(boolean isPrimitive) throws IOException {
    long start = in.position();
    long id = readID();
    StackTrace stackTrace = getStackTraceFromSerial(in.readInt());
    int num = in.readInt();
    int bytesRead = identifierSize + 8;
    long elementClassID;
    if (isPrimitive) {
      elementClassID = in.readByte();
      bytesRead++;
    } else {
      elementClassID = readID();
      bytesRead += identifierSize;
    }

    // Check for primitive arrays:
    byte primitiveSignature = 0x00;
    int elSize = 0;
    if (isPrimitive || version < VERSION_JDK12BETA4) {
      switch ((int) elementClassID) {
        case T_BOOLEAN:
          {
            primitiveSignature = (byte) 'Z';
            elSize = 1;
            break;
          }
        case T_CHAR:
          {
            primitiveSignature = (byte) 'C';
            elSize = 2;
            break;
          }
        case T_FLOAT:
          {
            primitiveSignature = (byte) 'F';
            elSize = 4;
            break;
          }
        case T_DOUBLE:
          {
            primitiveSignature = (byte) 'D';
            elSize = 8;
            break;
          }
        case T_BYTE:
          {
            primitiveSignature = (byte) 'B';
            elSize = 1;
            break;
          }
        case T_SHORT:
          {
            primitiveSignature = (byte) 'S';
            elSize = 2;
            break;
          }
        case T_INT:
          {
            primitiveSignature = (byte) 'I';
            elSize = 4;
            break;
          }
        case T_LONG:
          {
            primitiveSignature = (byte) 'J';
            elSize = 8;
            break;
          }
      }
      if (version >= VERSION_JDK12BETA4 && primitiveSignature == 0x00) {
        throw new IOException("Unrecognized typecode:  " + elementClassID);
      }
    }
    if (primitiveSignature != 0x00) {
      int size = elSize * num;
      bytesRead += size;
      JavaValueArray va = new JavaValueArray(primitiveSignature, start);
      skipBytes(size);
      snapshot.addHeapObject(id, va);
      snapshot.setSiteTrace(va, stackTrace);
    } else {
      int sz = num * identifierSize;
      bytesRead += sz;
      JavaObjectArray arr = new JavaObjectArray(elementClassID, start);
      skipBytes(sz);
      snapshot.addHeapObject(id, arr);
      snapshot.setSiteTrace(arr, stackTrace);
    }
    return bytesRead;
  }
Esempio n. 5
0
  //
  // Handle a HPROF_GC_CLASS_DUMP
  // Return number of bytes read
  //
  private int readClass() throws IOException {
    long id = readID();
    StackTrace stackTrace = getStackTraceFromSerial(in.readInt());
    long superId = readID();
    long classLoaderId = readID();
    long signersId = readID();
    long protDomainId = readID();
    long reserved1 = readID();
    long reserved2 = readID();
    int instanceSize = in.readInt();
    int bytesRead = 7 * identifierSize + 8;

    int numConstPoolEntries = in.readUnsignedShort();
    bytesRead += 2;
    for (int i = 0; i < numConstPoolEntries; i++) {
      int index = in.readUnsignedShort(); // unused
      bytesRead += 2;
      bytesRead += readValue(null); // We ignore the values
    }

    int numStatics = in.readUnsignedShort();
    bytesRead += 2;
    JavaThing[] valueBin = new JavaThing[1];
    JavaStatic[] statics = new JavaStatic[numStatics];
    for (int i = 0; i < numStatics; i++) {
      long nameId = readID();
      bytesRead += identifierSize;
      byte type = in.readByte();
      bytesRead++;
      bytesRead += readValueForType(type, valueBin);
      String fieldName = getNameFromID(nameId);
      if (version >= VERSION_JDK12BETA4) {
        type = signatureFromTypeId(type);
      }
      String signature = "" + ((char) type);
      JavaField f = new JavaField(fieldName, signature);
      statics[i] = new JavaStatic(f, valueBin[0]);
    }

    int numFields = in.readUnsignedShort();
    bytesRead += 2;
    JavaField[] fields = new JavaField[numFields];
    for (int i = 0; i < numFields; i++) {
      long nameId = readID();
      bytesRead += identifierSize;
      byte type = in.readByte();
      bytesRead++;
      String fieldName = getNameFromID(nameId);
      if (version >= VERSION_JDK12BETA4) {
        type = signatureFromTypeId(type);
      }
      String signature = "" + ((char) type);
      fields[i] = new JavaField(fieldName, signature);
    }
    String name = classNameFromObjectID.get(new Long(id));
    if (name == null) {
      warn("Class name not found for " + toHex(id));
      name = "unknown-name@" + toHex(id);
    }
    JavaClass c =
        new JavaClass(
            id,
            name,
            superId,
            classLoaderId,
            signersId,
            protDomainId,
            fields,
            statics,
            instanceSize);
    snapshot.addClass(id, c);
    snapshot.setSiteTrace(c, stackTrace);

    return bytesRead;
  }
Esempio n. 6
0
 private void readHeapDump(long bytesLeft, long posAtEnd) throws IOException {
   while (bytesLeft > 0) {
     int type = in.readUnsignedByte();
     if (debugLevel > 0) {
       System.out.println(
           "    Read heap sub-record type "
               + type
               + " at position "
               + toHex(posAtEnd - bytesLeft));
     }
     bytesLeft--;
     switch (type) {
       case HPROF_GC_ROOT_UNKNOWN:
         {
           long id = readID();
           bytesLeft -= identifierSize;
           snapshot.addRoot(new Root(id, 0, Root.UNKNOWN, ""));
           break;
         }
       case HPROF_GC_ROOT_THREAD_OBJ:
         {
           long id = readID();
           int threadSeq = in.readInt();
           int stackSeq = in.readInt();
           bytesLeft -= identifierSize + 8;
           threadObjects.put(new Integer(threadSeq), new ThreadObject(id, stackSeq));
           break;
         }
       case HPROF_GC_ROOT_JNI_GLOBAL:
         {
           long id = readID();
           long globalRefId = readID(); // Ignored, for now
           bytesLeft -= 2 * identifierSize;
           snapshot.addRoot(new Root(id, 0, Root.NATIVE_STATIC, ""));
           break;
         }
       case HPROF_GC_ROOT_JNI_LOCAL:
         {
           long id = readID();
           int threadSeq = in.readInt();
           int depth = in.readInt();
           bytesLeft -= identifierSize + 8;
           ThreadObject to = getThreadObjectFromSequence(threadSeq);
           StackTrace st = getStackTraceFromSerial(to.stackSeq);
           if (st != null) {
             st = st.traceForDepth(depth + 1);
           }
           snapshot.addRoot(new Root(id, to.threadId, Root.NATIVE_LOCAL, "", st));
           break;
         }
       case HPROF_GC_ROOT_JAVA_FRAME:
         {
           long id = readID();
           int threadSeq = in.readInt();
           int depth = in.readInt();
           bytesLeft -= identifierSize + 8;
           ThreadObject to = getThreadObjectFromSequence(threadSeq);
           StackTrace st = getStackTraceFromSerial(to.stackSeq);
           if (st != null) {
             st = st.traceForDepth(depth + 1);
           }
           snapshot.addRoot(new Root(id, to.threadId, Root.JAVA_LOCAL, "", st));
           break;
         }
       case HPROF_GC_ROOT_NATIVE_STACK:
         {
           long id = readID();
           int threadSeq = in.readInt();
           bytesLeft -= identifierSize + 4;
           ThreadObject to = getThreadObjectFromSequence(threadSeq);
           StackTrace st = getStackTraceFromSerial(to.stackSeq);
           snapshot.addRoot(new Root(id, to.threadId, Root.NATIVE_STACK, "", st));
           break;
         }
       case HPROF_GC_ROOT_STICKY_CLASS:
         {
           long id = readID();
           bytesLeft -= identifierSize;
           snapshot.addRoot(new Root(id, 0, Root.SYSTEM_CLASS, ""));
           break;
         }
       case HPROF_GC_ROOT_THREAD_BLOCK:
         {
           long id = readID();
           int threadSeq = in.readInt();
           bytesLeft -= identifierSize + 4;
           ThreadObject to = getThreadObjectFromSequence(threadSeq);
           StackTrace st = getStackTraceFromSerial(to.stackSeq);
           snapshot.addRoot(new Root(id, to.threadId, Root.THREAD_BLOCK, "", st));
           break;
         }
       case HPROF_GC_ROOT_MONITOR_USED:
         {
           long id = readID();
           bytesLeft -= identifierSize;
           snapshot.addRoot(new Root(id, 0, Root.BUSY_MONITOR, ""));
           break;
         }
       case HPROF_GC_CLASS_DUMP:
         {
           int bytesRead = readClass();
           bytesLeft -= bytesRead;
           break;
         }
       case HPROF_GC_INSTANCE_DUMP:
         {
           int bytesRead = readInstance();
           bytesLeft -= bytesRead;
           break;
         }
       case HPROF_GC_OBJ_ARRAY_DUMP:
         {
           int bytesRead = readArray(false);
           bytesLeft -= bytesRead;
           break;
         }
       case HPROF_GC_PRIM_ARRAY_DUMP:
         {
           int bytesRead = readArray(true);
           bytesLeft -= bytesRead;
           break;
         }
       default:
         {
           throw new IOException("Unrecognized heap dump sub-record type:  " + type);
         }
     }
   }
   if (bytesLeft != 0) {
     warn(
         "Error reading heap dump or heap dump segment:  Byte count is "
             + bytesLeft
             + " instead of 0");
     skipBytes(bytesLeft);
   }
   if (debugLevel > 0) {
     System.out.println("    Finished heap sub-records.");
   }
 }
Esempio n. 7
0
  public Snapshot read() throws IOException {
    currPos = 4; // 4 because of the magic number
    version = readVersionHeader();
    identifierSize = in.readInt();
    snapshot.setIdentifierSize(identifierSize);
    if (version >= VERSION_JDK12BETA4) {
      snapshot.setNewStyleArrayClass(true);
    } else {
      snapshot.setNewStyleArrayClass(false);
    }

    currPos += 4;
    if (identifierSize != 4 && identifierSize != 8) {
      throw new IOException(
          "I'm sorry, but I can't deal with an identifier size of "
              + identifierSize
              + ".  I can only deal with 4 or 8.");
    }
    System.out.println("Dump file created " + (new Date(in.readLong())));
    currPos += 8;

    for (; ; ) {
      int type;
      try {
        type = in.readUnsignedByte();
      } catch (EOFException ignored) {
        break;
      }
      in.readInt(); // Timestamp of this record
      // Length of record: readInt() will return negative value for record
      // length >2GB.  so store 32bit value in long to keep it unsigned.
      long length = in.readInt() & 0xffffffffL;
      if (debugLevel > 0) {
        System.out.println(
            "Read record type " + type + ", length " + length + " at position " + toHex(currPos));
      }
      if (length < 0) {
        throw new IOException(
            "Bad record length of " + length + " at byte " + toHex(currPos + 5) + " of file.");
      }
      currPos += 9 + length;
      switch (type) {
        case HPROF_UTF8:
          {
            long id = readID();
            byte[] chars = new byte[(int) length - identifierSize];
            in.readFully(chars);
            names.put(new Long(id), new String(chars));
            break;
          }
        case HPROF_LOAD_CLASS:
          {
            int serialNo = in.readInt(); // Not used
            long classID = readID();
            int stackTraceSerialNo = in.readInt();
            long classNameID = readID();
            Long classIdI = new Long(classID);
            String nm = getNameFromID(classNameID).replace('/', '.');
            classNameFromObjectID.put(classIdI, nm);
            if (classNameFromSerialNo != null) {
              classNameFromSerialNo.put(new Integer(serialNo), nm);
            }
            break;
          }

        case HPROF_HEAP_DUMP:
          {
            if (dumpsToSkip <= 0) {
              try {
                readHeapDump(length, currPos);
              } catch (EOFException exp) {
                handleEOF(exp, snapshot);
              }
              if (debugLevel > 0) {
                System.out.println("    Finished processing instances in heap dump.");
              }
              return snapshot;
            } else {
              dumpsToSkip--;
              skipBytes(length);
            }
            break;
          }

        case HPROF_HEAP_DUMP_END:
          {
            if (version >= VERSION_JDK6) {
              if (dumpsToSkip <= 0) {
                skipBytes(length); // should be no-op
                return snapshot;
              } else {
                // skip this dump (of the end record for a sequence of dump segments)
                dumpsToSkip--;
              }
            } else {
              // HPROF_HEAP_DUMP_END only recognized in >= 1.0.2
              warn("Ignoring unrecognized record type " + type);
            }
            skipBytes(length); // should be no-op
            break;
          }

        case HPROF_HEAP_DUMP_SEGMENT:
          {
            if (version >= VERSION_JDK6) {
              if (dumpsToSkip <= 0) {
                try {
                  // read the dump segment
                  readHeapDump(length, currPos);
                } catch (EOFException exp) {
                  handleEOF(exp, snapshot);
                }
              } else {
                // all segments comprising the heap dump will be skipped
                skipBytes(length);
              }
            } else {
              // HPROF_HEAP_DUMP_SEGMENT only recognized in >= 1.0.2
              warn("Ignoring unrecognized record type " + type);
              skipBytes(length);
            }
            break;
          }

        case HPROF_FRAME:
          {
            if (stackFrames == null) {
              skipBytes(length);
            } else {
              long id = readID();
              String methodName = getNameFromID(readID());
              String methodSig = getNameFromID(readID());
              String sourceFile = getNameFromID(readID());
              int classSer = in.readInt();
              String className = classNameFromSerialNo.get(new Integer(classSer));
              int lineNumber = in.readInt();
              if (lineNumber < StackFrame.LINE_NUMBER_NATIVE) {
                warn("Weird stack frame line number:  " + lineNumber);
                lineNumber = StackFrame.LINE_NUMBER_UNKNOWN;
              }
              stackFrames.put(
                  new Long(id),
                  new StackFrame(methodName, methodSig, className, sourceFile, lineNumber));
            }
            break;
          }
        case HPROF_TRACE:
          {
            if (stackTraces == null) {
              skipBytes(length);
            } else {
              int serialNo = in.readInt();
              int threadSeq = in.readInt(); // Not used
              StackFrame[] frames = new StackFrame[in.readInt()];
              for (int i = 0; i < frames.length; i++) {
                long fid = readID();
                frames[i] = stackFrames.get(new Long(fid));
                if (frames[i] == null) {
                  throw new IOException("Stack frame " + toHex(fid) + " not found");
                }
              }
              stackTraces.put(new Integer(serialNo), new StackTrace(frames));
            }
            break;
          }
        case HPROF_UNLOAD_CLASS:
        case HPROF_ALLOC_SITES:
        case HPROF_START_THREAD:
        case HPROF_END_THREAD:
        case HPROF_HEAP_SUMMARY:
        case HPROF_CPU_SAMPLES:
        case HPROF_CONTROL_SETTINGS:
        case HPROF_LOCKSTATS_WAIT_TIME:
        case HPROF_LOCKSTATS_HOLD_TIME:
          {
            // Ignore these record types
            skipBytes(length);
            break;
          }
        default:
          {
            skipBytes(length);
            warn("Ignoring unrecognized record type " + type);
          }
      }
    }

    return snapshot;
  }
Esempio n. 8
0
 /*.................................................................................................................*/
 public Snapshot getSnapshot(MesquiteFile file) {
   Snapshot temp = super.getSnapshot(file);
   temp.addLine("setExternalProcessRunner", externalProcRunner);
   return temp;
 }
 /*.................................................................................................................*/
 public Snapshot getSnapshot(MesquiteFile file) {
   Snapshot temp = new Snapshot();
   temp.addLine("setUsername " + ParseUtil.tokenize(username));
   return temp;
 }