hotspot/agent/src/share/classes/sun/jvm/hotspot/memory/Universe.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1 489c9b5090e2
child 360 21d113ecbf6a
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2000-2006 Sun Microsystems, Inc.  All Rights Reserved.
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.memory;
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.gc_implementation.parallelScavenge.*;
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.types.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
import sun.jvm.hotspot.runtime.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
public class Universe {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  private static AddressField collectedHeapField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  private static VirtualConstructor heapConstructor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  private static sun.jvm.hotspot.types.OopField mainThreadGroupField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  private static sun.jvm.hotspot.types.OopField systemThreadGroupField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  // single dimensional primitive array klasses
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  private static sun.jvm.hotspot.types.OopField boolArrayKlassObjField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  private static sun.jvm.hotspot.types.OopField byteArrayKlassObjField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  private static sun.jvm.hotspot.types.OopField charArrayKlassObjField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  private static sun.jvm.hotspot.types.OopField intArrayKlassObjField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  private static sun.jvm.hotspot.types.OopField shortArrayKlassObjField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  private static sun.jvm.hotspot.types.OopField longArrayKlassObjField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  private static sun.jvm.hotspot.types.OopField singleArrayKlassObjField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  private static sun.jvm.hotspot.types.OopField doubleArrayKlassObjField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  // system obj array klass object
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  private static sun.jvm.hotspot.types.OopField systemObjArrayKlassObjField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  static {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    VM.registerVMInitializedObserver(new Observer() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
        public void update(Observable o, Object data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
          initialize(VM.getVM().getTypeDataBase());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
      });
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  private static synchronized void initialize(TypeDataBase db) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    Type type = db.lookupType("Universe");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    collectedHeapField = type.getAddressField("_collectedHeap");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    heapConstructor = new VirtualConstructor(db);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    heapConstructor.addMapping("GenCollectedHeap", GenCollectedHeap.class);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    heapConstructor.addMapping("ParallelScavengeHeap", ParallelScavengeHeap.class);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    mainThreadGroupField   = type.getOopField("_main_thread_group");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    systemThreadGroupField = type.getOopField("_system_thread_group");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    boolArrayKlassObjField = type.getOopField("_boolArrayKlassObj");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    byteArrayKlassObjField = type.getOopField("_byteArrayKlassObj");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    charArrayKlassObjField = type.getOopField("_charArrayKlassObj");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    intArrayKlassObjField = type.getOopField("_intArrayKlassObj");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    shortArrayKlassObjField = type.getOopField("_shortArrayKlassObj");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    longArrayKlassObjField = type.getOopField("_longArrayKlassObj");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    singleArrayKlassObjField = type.getOopField("_singleArrayKlassObj");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    doubleArrayKlassObjField = type.getOopField("_doubleArrayKlassObj");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    systemObjArrayKlassObjField = type.getOopField("_systemObjArrayKlassObj");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  public Universe() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  public CollectedHeap heap() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
      return (CollectedHeap) heapConstructor.instantiateWrapperFor(collectedHeapField.getValue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    } catch (WrongTypeException e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
      return new CollectedHeap(collectedHeapField.getValue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  /** Returns "TRUE" iff "p" points into the allocated area of the heap. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  public boolean isIn(Address p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    return heap().isIn(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  /** Returns "TRUE" iff "p" points into the reserved area of the heap. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  public boolean isInReserved(Address p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    return heap().isInReserved(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  private Oop newOop(OopHandle handle) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    return VM.getVM().getObjectHeap().newOop(handle);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  public Oop mainThreadGroup() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    return newOop(mainThreadGroupField.getValue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  public Oop systemThreadGroup() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    return newOop(systemThreadGroupField.getValue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  public Oop systemObjArrayKlassObj() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    return newOop(systemObjArrayKlassObjField.getValue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  // iterate through the single dimensional primitive array klasses
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  // refer to basic_type_classes_do(void f(klassOop)) in universe.cpp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  public void basicTypeClassesDo(SystemDictionary.ClassVisitor visitor) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    visitor.visit((Klass)newOop(boolArrayKlassObjField.getValue()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    visitor.visit((Klass)newOop(byteArrayKlassObjField.getValue()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    visitor.visit((Klass)newOop(charArrayKlassObjField.getValue()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    visitor.visit((Klass)newOop(intArrayKlassObjField.getValue()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    visitor.visit((Klass)newOop(shortArrayKlassObjField.getValue()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    visitor.visit((Klass)newOop(longArrayKlassObjField.getValue()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    visitor.visit((Klass)newOop(singleArrayKlassObjField.getValue()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    visitor.visit((Klass)newOop(doubleArrayKlassObjField.getValue()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  public void print() { printOn(System.out); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  public void printOn(PrintStream tty) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    heap().printOn(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  // Check whether an element of a typeArrayOop with the given type must be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  // aligned 0 mod 8.  The typeArrayOop itself must be aligned at least this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  // strongly.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  public static boolean elementTypeShouldBeAligned(BasicType type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
    return type == BasicType.T_DOUBLE || type == BasicType.T_LONG;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  // Check whether an object field (static/non-static) of the given type must be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  // aligned 0 mod 8.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  public static boolean fieldTypeShouldBeAligned(BasicType type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    return type == BasicType.T_DOUBLE || type == BasicType.T_LONG;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
}