hotspot/agent/src/share/classes/sun/jvm/hotspot/utilities/ReversePtrsAnalysis.java
author never
Wed, 30 Mar 2011 07:47:19 -0700
changeset 8878 a6283814032c
parent 5547 f4b087cbb361
child 13728 882756847a04
permissions -rw-r--r--
7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue Reviewed-by: kvn, dcubed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
8878
a6283814032c 7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents: 5547
diff changeset
     2
 * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 670
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 670
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 670
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
package sun.jvm.hotspot.utilities;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
import java.io.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
import sun.jvm.hotspot.debugger.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
import sun.jvm.hotspot.gc_interface.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
import sun.jvm.hotspot.memory.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
import sun.jvm.hotspot.oops.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
import sun.jvm.hotspot.runtime.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
import sun.jvm.hotspot.utilities.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
/** For a set of known roots, descends recursively into the object
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
    graph, for each object recording those objects (and their fields)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
    which point to it. NOTE: currently only a subset of the roots
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
    known to the VM is exposed to the SA: objects on the stack, static
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
    fields in classes, and JNI handles. These should be most of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
    user-level roots keeping objects alive. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
public class ReversePtrsAnalysis {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  // Used for debugging this code
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  private static final boolean DEBUG = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  public ReversePtrsAnalysis() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  /** Sets an optional progress thunk */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  public void setHeapProgressThunk(HeapProgressThunk thunk) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    progressThunk = thunk;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  /** Runs the analysis algorithm */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    if (VM.getVM().getRevPtrs() != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
      return; // Assume already done
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    VM vm = VM.getVM();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    rp = new ReversePtrs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    vm.setRevPtrs(rp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    Universe universe = vm.getUniverse();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    CollectedHeap collHeap = universe.heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    usedSize = collHeap.used();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    visitedSize = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    // Note that an experiment to iterate the heap linearly rather
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    // than in recursive-descent order has been done. It turns out
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    // that the recursive-descent algorithm is nearly twice as fast
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    // due to the fact that it scans only live objects and (currently)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    // only a fraction of the perm gen, namely the static fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    // contained in instanceKlasses. (Iterating the heap linearly
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    // would also change the semantics of the result so that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    // ReversePtrs.get() would return a non-null value even for dead
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    // objects.) Nonetheless, the reverse pointer computation is still
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    // quite slow and optimization in field iteration of objects
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    // should be done.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    if (progressThunk != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
      // Get it started
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
      progressThunk.heapIterationFractionUpdate(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    // Allocate mark bits for heap
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    markBits = new MarkBits(collHeap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    // Get a hold of the object heap
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    heap = vm.getObjectHeap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    // Do each thread's roots
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    for (JavaThread thread = VM.getVM().getThreads().first();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
         thread != null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
         thread = thread.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
      thread.printThreadIDOn(new PrintStream(bos));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
      String threadDesc =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
        " in thread \"" + thread.getThreadName() +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
        "\" (id " + bos.toString() + ")";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
      doStack(thread,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
              new RootVisitor("Stack root" + threadDesc));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
      doJNIHandleBlock(thread.activeHandles(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
                       new RootVisitor("JNI handle root" + threadDesc));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    // Do global JNI handles
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    JNIHandles handles = VM.getVM().getJNIHandles();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    doJNIHandleBlock(handles.globalHandles(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
                     new RootVisitor("Global JNI handle root"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    doJNIHandleBlock(handles.weakGlobalHandles(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
                     new RootVisitor("Weak global JNI handle root"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    // Do Java-level static fields in perm gen
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    heap.iteratePerm(new DefaultHeapVisitor() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
        public boolean doObj(Oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
          if (obj instanceof InstanceKlass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
            final InstanceKlass ik = (InstanceKlass) obj;
8878
a6283814032c 7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents: 5547
diff changeset
   120
            ik.iterateStaticFields(
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
               new DefaultOopVisitor() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
                   public void doOop(OopField field, boolean isVMField) {
8878
a6283814032c 7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents: 5547
diff changeset
   123
                     Oop next = field.getValue(getObj());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
                     LivenessPathElement lp = new LivenessPathElement(null,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
                             new NamedFieldIdentifier("Static field \"" +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
                                                field.getID().getName() +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
                                                "\" in class \"" +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
                                                ik.getName().asString() + "\""));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
                     rp.put(lp, next);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
                     try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
                       markAndTraverse(next);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
                     } catch (AddressException e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
                       System.err.print("RevPtrs analysis: WARNING: AddressException at 0x" +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
                                        Long.toHexString(e.getAddress()) +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
                                        " while traversing static fields of InstanceKlass ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
                       ik.printValueOn(System.err);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
                       System.err.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
                     } catch (UnknownOopException e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
                       System.err.println("RevPtrs analysis: WARNING: UnknownOopException while " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
                                          "traversing static fields of InstanceKlass ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
                       ik.printValueOn(System.err);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
                       System.err.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
                     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
                   }
8878
a6283814032c 7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents: 5547
diff changeset
   145
                 });
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
                  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
      });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    if (progressThunk != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
      progressThunk.heapIterationComplete();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    // Clear out markBits
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    markBits = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  //---------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  // Internals only below this point
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  private HeapProgressThunk   progressThunk;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  private long                usedSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  private long                visitedSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  private double              lastNotificationFraction;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  private static final double MINIMUM_NOTIFICATION_FRACTION = 0.01;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  private ObjectHeap          heap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  private MarkBits            markBits;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  private int                 depth; // Debugging only
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  private ReversePtrs         rp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  private void markAndTraverse(OopHandle handle) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
      markAndTraverse(heap.newOop(handle));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    } catch (AddressException e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
      System.err.println("RevPtrs analysis: WARNING: AddressException at 0x" +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
                         Long.toHexString(e.getAddress()) +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
                         " while traversing oop at " + handle);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    } catch (UnknownOopException e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
      System.err.println("RevPtrs analysis: WARNING: UnknownOopException for " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
                         "oop at " + handle);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  private void printHeader() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    for (int i = 0; i < depth; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
      System.err.print(" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  private void markAndTraverse(final Oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    // End of path
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    if (obj == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    // Visited object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    if (!markBits.mark(obj)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    // Root of work list for objects to be visited.  A simple
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    // stack for saving new objects to be analyzed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    final Stack workList = new Stack();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    // Next object to be visited.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    Oop next = obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
      // Node in the list currently being visited.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
      while (true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
        final Oop currObj = next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
        // For the progress meter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
        if (progressThunk != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
          visitedSize += currObj.getObjectSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
          double curFrac = (double) visitedSize / (double) usedSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
          if (curFrac >
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
              lastNotificationFraction + MINIMUM_NOTIFICATION_FRACTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
            progressThunk.heapIterationFractionUpdate(curFrac);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
            lastNotificationFraction = curFrac;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
        if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
          ++depth;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
          printHeader();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
          System.err.println("ReversePtrs.markAndTraverse(" +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
              currObj.getHandle() + ")");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
        // Iterate over the references in the object.  Do the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
        // reverse pointer analysis for each reference.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
        // Add the reference to the work-list so that its
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
        // references will be visited.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
        currObj.iterate(new DefaultOopVisitor() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
          public void doOop(OopField field, boolean isVMField) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
            // "field" refers to a reference in currObj
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
            Oop next = field.getValue(currObj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
            rp.put(new LivenessPathElement(currObj, field.getID()), next);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
            if ((next != null) && markBits.mark(next)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
              workList.push(next);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
        }, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
        if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
          --depth;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
        // Get the next object to visit.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
        next = (Oop) workList.pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
    } catch (EmptyStackException e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
      // Done
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    } catch (NullPointerException e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
      System.err.println("ReversePtrs: WARNING: " + e +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
        " during traversal");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
    } catch (Exception e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
      System.err.println("ReversePtrs: WARNING: " + e +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
        " during traversal");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  class RootVisitor implements AddressVisitor {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    RootVisitor(String baseRootDescription) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
      this.baseRootDescription = baseRootDescription;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
    public void visitAddress(Address addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
      Oop next = heap.newOop(addr.getOopHandleAt(0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
      LivenessPathElement lp = new LivenessPathElement(null,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
                                        new NamedFieldIdentifier(baseRootDescription +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
                                                                 " @ " + addr));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
      rp.put(lp, next);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
      markAndTraverse(next);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   284
    public void visitCompOopAddress(Address addr) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   285
      Oop next = heap.newOop(addr.getCompOopHandleAt(0));
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   286
      LivenessPathElement lp = new LivenessPathElement(null,
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   287
                                        new NamedFieldIdentifier(baseRootDescription +
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   288
                                                                 " @ " + addr));
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   289
      rp.put(lp, next);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   290
      markAndTraverse(next);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   291
    }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   292
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
    private String baseRootDescription;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  // Traverse the roots on a given thread's stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  private void doStack(JavaThread thread, AddressVisitor oopVisitor) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
    for (StackFrameStream fst = new StackFrameStream(thread); !fst.isDone(); fst.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
      fst.getCurrent().oopsDo(oopVisitor, fst.getRegisterMap());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  // Traverse a JNIHandleBlock
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  private void doJNIHandleBlock(JNIHandleBlock handles, AddressVisitor oopVisitor) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    handles.oopsDo(oopVisitor);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
}