hotspot/agent/src/share/classes/sun/jvm/hotspot/utilities/PointerFinder.java
author twisti
Thu, 20 May 2010 06:34:23 -0700
changeset 5686 5435e77aa3df
parent 1 489c9b5090e2
child 5702 201c5cde25bb
permissions -rw-r--r--
6951083: oops and relocations should part of nmethod not CodeBlob Summary: This moves the oops from Codeblob to nmethod. Reviewed-by: kvn, never
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5686
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
     2
 * Copyright 2000-2010 Sun Microsystems, Inc.  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
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
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 sun.jvm.hotspot.code.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
import sun.jvm.hotspot.debugger.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
import sun.jvm.hotspot.gc_interface.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
import sun.jvm.hotspot.interpreter.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
import sun.jvm.hotspot.runtime.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
import sun.jvm.hotspot.memory.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
/** This class, only intended for use in the debugging system,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
    provides the functionality of find() in the VM. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
public class PointerFinder {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  public static PointerLocation find(Address a) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
    PointerLocation loc = new PointerLocation(a);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
    CollectedHeap heap = VM.getVM().getUniverse().heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
    if (heap instanceof GenCollectedHeap) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
      GenCollectedHeap genheap = (GenCollectedHeap) heap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
      if (genheap.isIn(a)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
        for (int i = 0; i < genheap.nGens(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
          Generation g = genheap.getGen(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
          if (g.isIn(a)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
            loc.gen = g;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
        if (loc.gen == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
          // Should be in perm gen
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
          Generation permGen = genheap.permGen();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
          if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
            Assert.that(permGen.isIn(a), "should have been in ordinary or perm gens if it's in the heap");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
          loc.permGen = permGen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
        if (VM.getVM().getUseTLAB()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
          // Try to find thread containing it
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
          for (JavaThread t = VM.getVM().getThreads().first(); t != null; t = t.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
            ThreadLocalAllocBuffer tlab = t.tlab();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
            if (tlab.contains(a)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
              loc.inTLAB = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
              loc.tlabThread = t;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
              loc.tlab = tlab;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
              break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
        return loc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
      if (heap.isIn(a)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
        loc.heap = heap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
        return loc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    Interpreter interp = VM.getVM().getInterpreter();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    if (interp.contains(a)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
      loc.inInterpreter = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
      loc.interpreterCodelet = interp.getCodeletContaining(a);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
      return loc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    if (!VM.getVM().isCore()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
      CodeCache c = VM.getVM().getCodeCache();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
      if (c.contains(a)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
        loc.inCodeCache = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
        loc.blob = c.findBlobUnsafe(a);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
        if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
          Assert.that(loc.blob != null, "Should have found CodeBlob");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
        loc.inBlobInstructions = loc.blob.instructionsContains(a);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
        loc.inBlobData         = loc.blob.dataContains(a);
5686
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   101
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   102
        if (loc.blob.isNMethod()) {
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   103
            NMethod nm = (NMethod) loc.blob;
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   104
            loc.inBlobOops = nm.oopsContains(a);
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   105
        }
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   106
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
        loc.inBlobUnknownLocation = (!(loc.inBlobInstructions ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
                                       loc.inBlobData ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
                                       loc.inBlobOops));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
        return loc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    // Check JNIHandles; both local and global
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    JNIHandles handles = VM.getVM().getJNIHandles();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    JNIHandleBlock handleBlock = handles.globalHandles();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    if (handleBlock != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
      handleBlock = handleBlock.blockContainingHandle(a);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    if (handleBlock != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
      loc.inStrongGlobalJNIHandleBlock = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
      loc.handleBlock = handleBlock;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
      return loc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
      handleBlock = handles.weakGlobalHandles();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
      if (handleBlock != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
        handleBlock = handleBlock.blockContainingHandle(a);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
        if (handleBlock != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
          loc.inWeakGlobalJNIHandleBlock = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
          loc.handleBlock = handleBlock;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
          return loc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
          // Look in thread-local handles
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
          for (JavaThread t = VM.getVM().getThreads().first(); t != null; t = t.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
            handleBlock = t.activeHandles();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
            if (handleBlock != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
              handleBlock = handleBlock.blockContainingHandle(a);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
              if (handleBlock != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
                loc.inLocalJNIHandleBlock = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
                loc.handleBlock = handleBlock;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
                loc.handleThread = t;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
                return loc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
      }
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
    // Fall through; have to return it anyway.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    return loc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
}