Пример #1
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;
 }
Пример #2
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;
  }