Java HPROF堆转储丢失字段?

时间:2016-03-03 10:02:55

标签: java heap-dump hprof

我正在使用Eclipse Memory Analyzer来查看HPROF文件。它为同一个类的不同实例显示不同数量的字段:

似乎永远不会分配丢失的字段,但缺少字段的价值是多少?他们是"零"值或字段初始化的值?

编辑:

JVM是Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)

编辑2:

似乎缺少的字段不是"零" (通过调试确认),但可能从未分配给。

下面的OQL查询显示Eclipse Memory Analyzer实际上知道这些字段中的实际值,但只是选择不显示它们......

2 个答案:

答案 0 :(得分:2)

根据HProf format documentation,对象的所有字段都存储在转储中,因此MAT可以知道对象的所有字段的值。

OQL窗口

对于OQL,除了那些具有空值的引用外,都会显示所有引用。

myWorkspaceMap is null for the object with 9 attributes

支配树窗口 对我来说,MAT显示了支配树窗口中对象的所有属性。

Attributes window

由于idea of the dominator tree是非循环图MAT确定closeController自己的URLJarFile对象并且在主窗口中没有显示该属性。

此外,它意味着,如果对特定对象有多个强引用,并且无法识别对象的所有者,则对象将不会显示在支配树中。

考虑URLJarFile中的name属性:

Name is not shown in the dominator tree

如果我们选择“List object - > with incoming references”,我们可以看到,这个String是从几个对象引用的:

String is referenced from several objects

答案 1 :(得分:0)

问题是我看到的视图只应列出对象引用,因此不会显示 #include "mainwindow.h" #include "ui_mainwindow.h" ///*********** STARTING THE CLASS **************************/// MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); MainWindow::plotting(); //********************* Read File **************************// QFile inputFile("ECG_Data.txt"); if (inputFile.open(QIODevice::ReadOnly)) { QTextStream in(&inputFile); int i=0; while (!in.atEnd()) { QString line = in.readLine(); fileData[i]=line.toDouble(); i++; } inputFile.close(); } } ///**************** START BUTTON *************************/// void MainWindow::on_pushButton_clicked() { stop= true; } ///***************** STOP BUTTON **************************/// void MainWindow::on_pushButton_2_clicked() { stop = false; } ///**************** PLOTTING *******************************/// void MainWindow::plotting() { //***** set plot parameters *******************************// ui->customPlot->addGraph(); ui->customPlot->graph(0)->setPen(QPen(Qt::yellow)); //set plot line color ui->customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime); ui->customPlot->xAxis->setDateTimeFormat("hh:mm:ss"); ui->customPlot->xAxis->setAutoTickStep(false); ui->customPlot->xAxis->setTickStep(2); ui->customPlot->axisRect()->setupFullAxesBox(); //***** set plot background color ****************************// QLinearGradient plotGradient; plotGradient.setStart(0, 0); //set start point plotGradient.setFinalStop(0, 350); //set final point plotGradient.setColorAt(1, QColor(100, 100, 100)); // set background color ui->customPlot->setBackground(plotGradient); //***** creat connection for plot Axes *************************// // make left and bottom axes transfer their ranges to right and top axes: connect(ui->customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->customPlot->xAxis2, SLOT(setRange(QCPRange))); connect(ui->customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->customPlot->yAxis2, SLOT(setRange(QCPRange))); //***** creat connection for plot founction *********************// // setup a timer that repeatedly calls MainWindow::realtimeDataSlot(); connect(&dataTimer, SIGNAL(timeout()), this, SLOT(readResponse())); dataTimer.start(10); // Interval 0 means to refresh as fast as possible } ///**************** REAL TIME PLOTTING SLOT *********************/// void MainWindow::readResponse() { if(j==500){j=0;} double value0 = fileData[j]; if (stop) {j++; //***** calculate two new data points: **************************// double key = QDateTime::currentDateTime().toMSecsSinceEpoch()/1000.0; //first data point of plot from time static double lastPointKey = 0; if (key-lastPointKey > 0.01) // at most add point every 10 ms { //emit plottingData(rx); // double value0 = rxplot; // convert string data of serial port to Double to be the second data point of plot //***** add data to lines: *****************************// ui->customPlot->graph(0)->addData(key, value0); // remove data of lines that's outside visible range: ui->customPlot->graph(0)->removeDataBefore(key-2); ui->customPlot->graph(0)->rescaleValueAxis(); lastPointKey = key; } //make key axis range scroll with the data (at a constant range size of 8): ui->customPlot->xAxis->setRange(key+0.25, 2, Qt::AlignRight); ui->customPlot->replot(); //***** calculate frames per second: *********************************// static double lastFpsKey; static int frameCount; ++frameCount; if (key-lastFpsKey > 2) // average fps over 2 seconds { ui->statusBar->showMessage(QString("%1 FPS, Total Data points: %2").arg(frameCount/(key-lastFpsKey), 0, 'f', 0).arg(ui->customPlot->graph(0)->data()->count()), 0 ); lastFpsKey = key; frameCount = 0; } } } ///****************** DESTRUCTOR ****************************/// MainWindow::~MainWindow() { delete ui; } 字段或原始值。

解决方案是添加“Inspector”视图或切换到专用的“Memory Analysis”透视图,该透视图将显示所选实例的实际字段,如@ Taky的截图所示。