/* (non-Javadoc)
  * @see org.xtreemfs.babudb.api.dev.SnapshotManagerInternal#shutdown()
  */
 @Override
 public void shutdown() throws BabuDBException {
   for (Map<String, Snapshot> snapshots : snapshotDBs.values())
     for (Snapshot snapshot : snapshots.values()) snapshot.shutdown();
   Logging.logMessage(
       Logging.LEVEL_DEBUG, Category.babudb, this, "snapshot manager shut down successfully");
 }
  @Test
  public void calculatesAStdDevOfZeroForAnEmptySnapshot() throws Exception {
    final Snapshot emptySnapshot =
        new WeightedSnapshot(WeightedArray(new long[] {}, new double[] {}));

    assertThat(emptySnapshot.getStdDev()).isZero();
  }
  @Test
  public void calculatesAStdDevOfZeroForASingletonSnapshot() throws Exception {
    final Snapshot singleItemSnapshot =
        new WeightedSnapshot(WeightedArray(new long[] {1}, new double[] {1.0}));

    assertThat(singleItemSnapshot.getStdDev()).isZero();
  }
示例#4
0
 /*.................................................................................................................*/
 public Snapshot getSnapshot(MesquiteFile file) {
   Snapshot temp = new Snapshot();
   temp.addLine(
       "setColor "
           + ColorDistribution.getStandardColorName(
               ColorDistribution.getStandardColor((int) currentColor)));
   temp.addLine("removeColor " + removeColor.toOffOnString());
   return temp;
 }
示例#5
0
 @Test
 public void canExtractSnapshotFromEntityManager()
     throws SQLException, DatabaseUnitException, IOException {
   createEntityManager();
   populateDataBase("backup.dbunit.xml");
   Snapshot snapshot = Snapshot.create();
   assertNotNull(snapshot.getCaptureDate());
   System.out.println(snapshot);
 }
示例#6
0
  @Test
  public void canValidateBackUp() {
    Snapshot backUp = Fixture.createSnapshot();

    assertValid(backUp);
    // make member first name invalid.
    backUp.getMembers().get(3).setFirstName("");
    assertInvalid(backUp, "members[3].firstName");
  }
  @Test
  public void worksWithOverestimatedCollections() throws Exception {
    final List<WeightedSample> items =
        spy(WeightedArray(new long[] {5, 1, 2, 3, 4}, new double[] {1, 2, 3, 2, 2}));
    when(items.size()).thenReturn(6, 5);

    final Snapshot other = new WeightedSnapshot(items);

    assertThat(other.getValues()).containsOnly(1, 2, 3, 4, 5);
  }
示例#8
0
 @Test
 public void canPopulateEntityManagerFromSnapshot() throws Exception {
   EntityManager manager = createEntityManager();
   Snapshot source = Fixture.createSnapshot();
   manager.getTransaction().begin();
   source.persistTo(manager);
   manager.flush();
   manager.getTransaction().commit();
   assertDataAsExpected("backup.dbunit.xml");
 }
  @Test
  public void expectNoOverflowForLowWeights() throws Exception {
    final Snapshot scatteredSnapshot =
        new WeightedSnapshot(
            WeightedArray(
                new long[] {1, 2, 3},
                new double[] {Double.MIN_VALUE, Double.MIN_VALUE, Double.MIN_VALUE}));

    assertThat(scatteredSnapshot.getMean()).isEqualTo(2);
  }
 /*.................................................................................................................*/
 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;
 }
示例#11
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;
 }
示例#12
0
 @Test
 public void testToStringTest() throws Exception {
   Snapshot snap = new Snapshot(field, 'b', 2, '0');
   String exp1 =
       "{\'status\':\'snapshot\',\'next\':\'0\',\'color\':\'b\',\'field\':[[\'black\', "
           + "\'nothing\'], [\'black\', \'white\']],\'king\':[[\'true\', \'false\'], [\'false\', \'true\']]}";
   Assert.assertEquals(snap.toStringTest(), exp1);
   snap = new Snapshot(field, 'w', 2, '0');
   String exp2 =
       "{\'status\':\'snapshot\',\'next\':\'0\',\'color\':\'w\',\'field\':[[\'black\', "
           + "\'nothing\'], [\'black\', \'white\']],\'king\':[[\'true\', \'false\'], [\'false\', \'true\']]}";
   Assert.assertEquals(snap.toStringTest(), exp2);
 }
示例#13
0
 @Test
 public void testToString() throws Exception {
   Snapshot snap = new Snapshot(field, 'b', 2, '0');
   String exp1 =
       "{\"status\":\"snapshot\",\"next\":\"0\",\"color\":\"b\",\"field\":[[\"black\", "
           + "\"nothing\"], [\"black\", \"white\"]],\"king\":[[\"true\", \"false\"], [\"false\", \"true\"]]}";
   Assert.assertEquals(snap.toString(), exp1);
   snap = new Snapshot(field, 'w', 2, '0');
   String exp2 =
       "{\"status\":\"snapshot\",\"next\":\"0\",\"color\":\"w\",\"field\":[[\"black\", "
           + "\"nothing\"], [\"black\", \"white\"]],\"king\":[[\"true\", \"false\"], [\"false\", \"true\"]]}";
   Assert.assertEquals(snap.toString(), exp2);
 }
示例#14
0
 private int getNumPorts(NodeProtoId nodeProtoId) {
   if (nodeProtoId instanceof CellId) {
     return snapshot.getCell((CellId) nodeProtoId).cellRevision.exports.size();
   } else {
     return techPool.getPrimitiveNode((PrimitiveNodeId) nodeProtoId).getNumPorts();
   }
 }
示例#15
0
 private PortProtoId getPortIdByIndex(NodeProtoId nodeProtoId, int portIndex) {
   if (nodeProtoId instanceof CellId) {
     return snapshot.getCell((CellId) nodeProtoId).cellRevision.exports.get(portIndex).exportId;
   } else {
     return techPool.getPrimitiveNode((PrimitiveNodeId) nodeProtoId).getPort(portIndex).getId();
   }
 }
  @Test
  public void dumpsToAStream() throws Exception {
    final ByteArrayOutputStream output = new ByteArrayOutputStream();

    snapshot.dump(output);

    assertThat(output.toString()).isEqualTo(String.format("1%n2%n3%n4%n5%n"));
  }
示例#17
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);
 }
示例#18
0
  @Test
  public void usage() throws Exception {
    dir = testDir("usage");
    File headFile = new File(dir, "HEAD");
    File pagesDir = new File(dir, "pages");

    IndexCodec indexCodec = mock(IndexCodec.class);
    Codec<Entry<Key, Integer>> entryCodec = mock(Codec.class);

    Snapshot<Integer> snapshot = new Snapshot<Integer>(dir, indexCodec, entryCodec);

    snapshot.updateAndCleanUp();

    String snapshotFileName = Files.readFirstLine(headFile, Charset.defaultCharset());
    assertThat(snapshotFileName, is(not("null.s")));
    assertThat(new File(pagesDir, snapshotFileName).exists(), is(true));

    assertThat(new File(pagesDir, "null.s").exists(), is(false));
  }
示例#19
0
  /* (non-Javadoc)
   * @see org.xtreemfs.babudb.api.dev.SnapshotManagerInternal#snapshotComplete(java.lang.String,
   *          org.xtreemfs.babudb.snapshots.SnapshotConfig)
   */
  @Override
  public void snapshotComplete(String dbName, SnapshotConfig snap) throws BabuDBException {

    // as soon as the snapshot has been completed, replace the entry in the
    // snapshot DB map with a disk index-based BabuDB instance if necessary
    synchronized (snapshotDBs) {
      DatabaseInternal db = dbs.getDatabaseManager().getDatabase(dbName);
      boolean compressed = db.getLSMDB().getIndex(0).isCompressed();
      boolean mmaped = db.getLSMDB().getIndex(0).isMMapEnabled();

      Snapshot s = snapshotDBs.get(dbName).get(snap.getName());
      s.setView(
          new DiskIndexView(
              getSnapshotDir(dbName, snap.getName()),
              dbs.getDatabaseManager().getDatabase(dbName).getComparators(),
              compressed,
              mmaped));
    }
  }
示例#20
0
  public CreateVolumeResponseType CreateVolume(final CreateVolumeType request)
      throws EucalyptusCloudException, AuthException {
    Context ctx = Contexts.lookup();
    Long volSize = request.getSize() != null ? Long.parseLong(request.getSize()) : null;
    final String snapId = request.getSnapshotId();
    String partition = request.getAvailabilityZone();

    if ((request.getSnapshotId() == null && request.getSize() == null)) {
      throw new EucalyptusCloudException("One of size or snapshotId is required as a parameter.");
    }

    if (snapId != null) {
      try {
        Transactions.find(Snapshot.named(null, snapId));
      } catch (ExecutionException ex) {
        throw new EucalyptusCloudException(
            "Failed to create volume because the referenced snapshot id is invalid: " + snapId);
      }
    }
    final Integer newSize = new Integer(request.getSize() != null ? request.getSize() : "-1");
    Exception lastEx = null;
    for (int i = 0; i < VOL_CREATE_RETRIES; i++) {
      try {
        final ServiceConfiguration sc =
            Topology.lookup(Storage.class, Partitions.lookupByName(partition));
        final UserFullName owner = ctx.getUserFullName();
        Function<Long, Volume> allocator =
            new Function<Long, Volume>() {

              @Override
              public Volume apply(Long size) {
                try {
                  return Volumes.createStorageVolume(
                      sc, owner, snapId, Ints.checkedCast(size), request);
                } catch (ExecutionException ex) {
                  throw Exceptions.toUndeclared(ex);
                }
              }
            };
        Volume newVol = RestrictedTypes.allocateMeasurableResource(newSize.longValue(), allocator);
        CreateVolumeResponseType reply = request.getReply();
        reply.setVolume(newVol.morph(new edu.ucsb.eucalyptus.msgs.Volume()));
        return reply;
      } catch (RuntimeException ex) {
        LOG.error(ex, ex);
        if (!(ex.getCause() instanceof ExecutionException)) {
          throw ex;
        } else {
          lastEx = ex;
        }
      }
    }
    throw new EucalyptusCloudException(
        "Failed to create volume after " + VOL_CREATE_RETRIES + " because of: " + lastEx, lastEx);
  }
示例#21
0
 private int getPortIndex(PortProtoId portId) {
   if (portId instanceof ExportId) {
     ExportId exportId = (ExportId) portId;
     return snapshot
         .getCell(exportId.getParentId())
         .cellRevision
         .getExportIndexByExportId(exportId);
   } else {
     return techPool.getPrimitivePort((PrimitivePortId) portId).getPortIndex();
   }
 }
示例#22
0
 /**
  * Method to tell whether this NodeInst is an icon of its parent. Electric does not allow
  * recursive circuit hierarchies (instances of Cells inside of themselves). However, it does allow
  * one exception: a schematic may contain its own icon for documentation purposes. This method
  * determines whether this NodeInst is such an icon.
  *
  * @return true if this NodeInst is an icon of its parent.
  */
 private boolean isIconOfParent(ImmutableNodeInst n) {
   if (!(n.protoId instanceof CellId)) {
     return false;
   }
   CellBackup subCell = snapshot.getCell((CellId) n.protoId);
   CellId subCellId = subCell.cellRevision.d.cellId;
   return subCellId.isIcon()
       && cellId.isSchematic()
       && subCellId.libId == cellId.libId
       && subCell.cellRevision.d.groupName.equals(cellRevision.d.groupName);
 }
示例#23
0
 private Response getResponse(MissionInfo info) {
   QueryResponse response = new QueryResponse();
   Snapshot snapshot = info.getSnapshot();
   response.setTime(snapshot.getTimestamp());
   response.setVersion(snapshot.getVersion());
   response.setMinVersion(snapshot.getMinVersion());
   response.setMaxVersion(snapshot.getMaxVersion());
   Report report = snapshot.getReport();
   response.setRunning(info.getState().equals(LAUNCHED));
   response.setReport(Arrays.asList(report.getAllMetrics()));
   return response;
 }
 /*.................................................................................................................*/
 public Snapshot getSnapshot(MesquiteFile file) {
   Snapshot temp = new Snapshot();
   temp.addLine("getTreeFiller ", fillerTask);
   if (enableNumTreesChoice()) temp.addLine("setNumberTrees " + numTrees);
   return temp;
 }
示例#25
0
 @Override
 public int compareTo(Snapshot o) {
   return Long.compare(id, o.id());
 }
示例#26
0
 @Override
 public void close() {
   snapshot.closeWriter(this);
   buffer.close();
 }
示例#27
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;
  }
示例#28
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.");
   }
 }
示例#29
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;
  }
示例#30
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;
  }